2008-04-02 08:09:28 +01:00
|
|
|
<?php
|
2008-04-28 23:05:31 +01:00
|
|
|
|
|
|
|
// activate full error reporting
|
2008-07-17 00:07:01 +01:00
|
|
|
//error_reporting(E_ALL & E_STRICT);
|
2008-04-28 23:05:31 +01:00
|
|
|
|
2010-03-07 19:38:11 +00:00
|
|
|
include dirname(dirname(__FILE__)).'/XMPPHP/XMPP.php';
|
2008-05-05 20:50:02 +01:00
|
|
|
|
2008-07-17 00:07:01 +01:00
|
|
|
#Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports
|
|
|
|
#If this doesn't work, are you running 64-bit PHP with < 5.2.6?
|
2008-05-05 20:50:02 +01:00
|
|
|
$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'username', 'password', 'xmpphp', 'gmail.com', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO);
|
2008-06-03 22:00:38 +01:00
|
|
|
$conn->autoSubscribe();
|
2008-05-05 20:50:02 +01:00
|
|
|
|
2008-11-28 19:43:05 +00:00
|
|
|
$vcard_request = array();
|
|
|
|
|
2008-05-05 20:50:02 +01:00
|
|
|
try {
|
|
|
|
$conn->connect();
|
|
|
|
while(!$conn->isDisconnected()) {
|
2008-11-28 20:15:36 +00:00
|
|
|
$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start', 'vcard'));
|
2008-05-05 20:50:02 +01:00
|
|
|
foreach($payloads as $event) {
|
|
|
|
$pl = $event[1];
|
|
|
|
switch($event[0]) {
|
|
|
|
case 'message':
|
|
|
|
print "---------------------------------------------------------------------------------\n";
|
|
|
|
print "Message from: {$pl['from']}\n";
|
|
|
|
if($pl['subject']) print "Subject: {$pl['subject']}\n";
|
|
|
|
print $pl['body'] . "\n";
|
|
|
|
print "---------------------------------------------------------------------------------\n";
|
|
|
|
$conn->message($pl['from'], $body="Thanks for sending me \"{$pl['body']}\".", $type=$pl['type']);
|
2008-11-28 20:15:36 +00:00
|
|
|
$cmd = explode(' ', $pl['body']);
|
2008-11-28 19:43:05 +00:00
|
|
|
if($cmd[0] == 'quit') $conn->disconnect();
|
|
|
|
if($cmd[0] == 'break') $conn->send("</end>");
|
|
|
|
if($cmd[0] == 'vcard') {
|
|
|
|
if(!($cmd[1])) $cmd[1] = $conn->user . '@' . $conn->server;
|
|
|
|
// take a note which user requested which vcard
|
|
|
|
$vcard_request[$pl['from']] = $cmd[1];
|
|
|
|
// request the vcard
|
|
|
|
$conn->getVCard($cmd[1]);
|
|
|
|
}
|
2008-05-05 20:50:02 +01:00
|
|
|
break;
|
|
|
|
case 'presence':
|
|
|
|
print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";
|
|
|
|
break;
|
|
|
|
case 'session_start':
|
|
|
|
print "Session Start\n";
|
2008-06-03 22:00:38 +01:00
|
|
|
$conn->getRoster();
|
2008-05-05 20:50:02 +01:00
|
|
|
$conn->presence($status="Cheese!");
|
|
|
|
break;
|
2008-11-28 19:43:05 +00:00
|
|
|
case 'vcard':
|
|
|
|
// check to see who requested this vcard
|
|
|
|
$deliver = array_keys($vcard_request, $pl['from']);
|
|
|
|
// work through the array to generate a message
|
|
|
|
print_r($pl);
|
|
|
|
$msg = '';
|
|
|
|
foreach($pl as $key => $item) {
|
|
|
|
$msg .= "$key: ";
|
|
|
|
if(is_array($item)) {
|
|
|
|
$msg .= "\n";
|
|
|
|
foreach($item as $subkey => $subitem) {
|
|
|
|
$msg .= " $subkey: $subitem\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$msg .= "$item\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// deliver the vcard msg to everyone that requested that vcard
|
|
|
|
foreach($deliver as $sendjid) {
|
|
|
|
// remove the note on requests as we send out the message
|
|
|
|
unset($vcard_request[$sendjid]);
|
|
|
|
$conn->message($sendjid, $msg, 'chat');
|
|
|
|
}
|
|
|
|
break;
|
2008-05-05 20:50:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(XMPPHP_Exception $e) {
|
|
|
|
die($e->getMessage());
|
2008-06-03 22:00:38 +01:00
|
|
|
}
|