Tutorials Infos - Anleitungen - Hilfe - Dreamcodes
 

ICQ-Status&WebPager

Eine Klasse um den ICQ-Status zu ermitteln und/oder eine Message zu schicken

Code:

/*********************
* class.icq.php *
* - version: 1.0 *
* - last update: 2001-04-27 *
* *
* THIS SCRIPT IS FREE *
* Feel free to edit, modify and redistribute, *
* as long as this message is kept intact. *
* author: Yves Berkholz (Loopstar GbR) [Germany]
* *
*****************
* ClassDescription *
*****************
* cICQ *
* -> setUIN($UIN) *
* #UIN - set a new UIN *
* return TRUE by default *
* *
* -> getUIN() *
* return: *
* ICQ_NO_UIN - if no UIN was set *
* current UIN *
* *
* -> getErrorCode() *
* return current errornummer (check if ICQ_SOCKED_ERROR was returned) *
* *
* -> getErrorMessage() *
* return current errormessage (check if ICQ_SOCKED_ERROR was returned) *
* *
* -> sendWebMessage($from, $email, $subject, $message) *
* #from - who send the message *
* #email - email-address of person who send message *
* #subject - subject of message *
* #message - messagebody *
* returns: *
* ICQ_SOCKED_ERROR - if an socket error occured *
* ICQ_NO_UIN - if no UIN was set *
* ICQ_PAGER_OK - if message was send successfully *
* ICQ_SOCKED_ERROR - if an socket error occured *
* *
* -> getOnlineStatus() *
* returns: *
* ICQ_SOCKED_ERROR - if an socket error occured *
* ICQ_NO_UIN - if no UIN was set *
* ICQ_STATUS_ONLINE - if user is online *
* ICQ_STATUS_OFFLINE - if user is offline *
* ICQ_STATUS_DISABLED - if icq-account is disabled *
* *
*****************
* Usage *
*****************
include("class.icq.php");
$myICQ = new cICQ("1234567");
echo $myICQ -> getOnlineStatus();
echo $myICQ -> sendWebMessage("Pseudo", "test@test.net", "Subject-Bla", "Message-BlaBlaBlaBlaBla");
***************** /


if(!defined("ICQ_STATUS_ONLINE"))
define("ICQ_STATUS_ONLINE","online");

if(!defined("ICQ_STATUS_OFFLINE"))
define("ICQ_STATUS_OFFLINE","offline");

if(!defined("ICQ_STATUS_DISABLED"))
define("ICQ_STATUS_DISABLED","disabled");

if(!defined("ICQ_STATUS_UNKNOWN"))
define("ICQ_STATUS_UNKNOWN","unknown");

if(!defined("ICQ_PAGER_OK"))
define("ICQ_PAGER_OK","message was send");

if(!defined("ICQ_SOCKED_ERROR"))
define("ICQ_SOCKED_ERROR","error connecting host");

if(!defined("ICQ_NO_UIN"))
define("ICQ_NO_UIN","no UIN was set");

/* edit only if you realy know what you do :-) */
if(!defined("ICQ_PAGER_PATH"))
define("ICQ_PAGER_PATH","/scripts/WWPMsg.dll");
if(!defined("ICQ_STATUS_PATH"))
define("ICQ_STATUS_PATH","/scripts/online.dll");
if(!defined("ICQ_HOST"))
define("ICQ_HOST","wwp.icq.com");
if(!defined("ICQ_PORT"))
define("ICQ_PORT","80");


class cICQ
{
var $cmd;
var $UIN;
var $intErrNr;
var $strErrMsg;

/***************** /
function cICQ($UIN)
{
$this -> setUIN($UIN);
$this -> clearCMD();
}
/***************** /
function setUIN($UIN)
{
$this -> UIN = $UIN;
$this -> clearErr();
return TRUE;
}
function getUIN()
{
if(!empty($this -> UIN))
return $this -> UIN;
else
return ICQ_NO_UIN;
}
/***************** /
function clearCMD()
{
$this -> cmd = "";
}
/***************** /
function clearErr()
{
$this -> intErrNr = "";
$this -> strErrMsg = "";
}

function setErr($intErrNR, $strErrMsg)
{
$this -> intErrNr = $intErrNR;
$this -> strErrMsg = $strErrMsg;
}

function getErrorCode()
{
return $this -> intErrNr;
}

function getErrorMessage()
{
return $this -> strErrMsg;
}
/***************** /
function sendWebMessage($from, $email, $subject, $message)
{
if(!empty($this -> UIN))
{
$this -> clearCMD();
$this -> clearErr();

$this -> cmd = "POST " . ICQ_PAGER_PATH . " HTTP/1.1\r\n";
$this -> cmd .= "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*\r\n";
$this -> cmd .= "Accept-Language: en-us\r\n";
$this -> cmd .= "Content-Type: application/x-www-form-urlencoded\r\n";
$this -> cmd .= "Accept-Encoding: gzip, deflate\r\n";
$this -> cmd .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 95)\r\n";
$this -> cmd .= "Host: " . ICQ_HOST . "\r\n";

$command = "from=" . $from . "&fromemail=" . $email . "&subject=" . $subject . "&body=" . $message . "&to=" . $this -> UIN . "&Send=Send+Message";

$this -> cmd .= "Content-Length: " . strlen($command) . "\r\n";
$this -> cmd .= "Connection: Keep-Alive\r\n\r\n";
$this -> cmd .= $command . "\r\n\r\n";

$fp = fsockopen (ICQ_HOST, ICQ_PORT, &$errno, &$errstr, 30);
if (!$fp)
{
$this -> setErr($errno, $errstr);
return ICQ_SOCKED_ERROR;
}
else
{
fputs($fp, $this -> cmd);
return ICQ_PAGER_OK;
fclose($fp);
}
}
else
return ICQ_NO_UIN;
}

/***************** /

function getOnlineStatus()
{
if(!empty($this -> UIN))
{
$this -> clearCMD();
$this -> clearErr();

$this -> cmd = "GET " . ICQ_STATUS_PATH . "?icq=" . $this -> UIN . "&img=5 HTTP/1.0\n\n";
$fp = fsockopen (ICQ_HOST, ICQ_PORT, &$errno, &$errstr, 30);
if(!$fp)
{
$this -> setErr($errno, $errstr);
return ICQ_SOCKED_ERROR;
}
else
{
fputs($fp, $this -> cmd);
$do = FALSE;
while(!feof($fp))
{
$line = fgets($fp, 128);
$do = ($do) ? TRUE : (eregi("^GIF89", $line)) ? TRUE : FALSE;
if($do)
{
if(ereg("á7@ ±40", $line))
{
return ICQ_STATUS_ONLINE;
}
elseif(ereg("áw` ±40", $line))
{
return ICQ_STATUS_OFFLINE;
}
elseif(ereg("S³IѱèJ", $line))
{
return ICQ_STATUS_DISABLED;
}
}
}
fclose($fp);
}
}
else
return ICQ_NO_UIN;
}
}
?>

 
ID: 119
eingestellt am: 19.03.2003
Autor: Q
Status zum lesen: Gast
gelesen: 7336
Webseite: www.dreamcodes.com
[Drucken]