2008-04-02 08:09:28 +01:00
|
|
|
<?php
|
2008-04-28 23:05:31 +01:00
|
|
|
|
2019-06-18 19:02:40 +01:00
|
|
|
/**
|
|
|
|
* @file: XMPPHP Cli example
|
|
|
|
*
|
|
|
|
* @info: If this script doesn't work, are you running 64-bit PHP with < 5.2.6?
|
|
|
|
*/
|
2008-04-28 23:05:31 +01:00
|
|
|
|
2019-06-18 19:02:40 +01:00
|
|
|
/**
|
|
|
|
* Activate full error reporting
|
|
|
|
* error_reporting(E_ALL & E_STRICT);
|
|
|
|
*
|
|
|
|
* XMPPHP Log levels:
|
|
|
|
*
|
|
|
|
* LEVEL_ERROR = 0;
|
|
|
|
* LEVEL_WARNING = 1;
|
|
|
|
* LEVEL_INFO = 2;
|
|
|
|
* LEVEL_DEBUG = 3;
|
|
|
|
* LEVEL_VERBOSE = 4;
|
|
|
|
*/
|
2008-05-05 20:50:02 +01:00
|
|
|
|
2019-06-18 19:02:40 +01:00
|
|
|
require '../vendor/autoload.php';
|
|
|
|
|
|
|
|
$conf = array(
|
|
|
|
'server' => 'talk.google.com',
|
|
|
|
'port' => 5222,
|
|
|
|
'username' => 'username',
|
|
|
|
'password' => 'password',
|
|
|
|
'proto' => 'xmpphp',
|
|
|
|
'domain' => 'gmail.com',
|
|
|
|
'printlog' => true,
|
|
|
|
'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Easy and simple for access to variables with their names
|
|
|
|
extract($conf);
|
|
|
|
|
|
|
|
$conn = new XMPPHP\XMPP($server, $port, $username, $password, $proto, $domain, $printlog, $loglevel);
|
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();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
|
|
|
while (!$conn->isDisconnected()) {
|
|
|
|
$events = array('message', 'presence', 'end_stream', 'session_start', 'vcard');
|
|
|
|
$payloads = $conn->processUntil($events);
|
|
|
|
|
|
|
|
foreach ($payloads as $result) {
|
|
|
|
list($event, $data) = $result;
|
|
|
|
|
|
|
|
if (isset($data)) {
|
|
|
|
extract($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($event) {
|
|
|
|
|
|
|
|
case 'message':
|
|
|
|
|
|
|
|
if (!$body) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo str_repeat('-', 80);
|
|
|
|
echo "Message from: $from";
|
|
|
|
|
|
|
|
if (isset($subject)) {
|
|
|
|
echo "Subject: $subject";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $body;
|
|
|
|
echo str_repeat('-', 80);
|
|
|
|
|
|
|
|
$cmd = explode(' ', $body);
|
|
|
|
$body = "Mi no entender! '$body'";
|
|
|
|
$conn->message($from, $body, $type);
|
|
|
|
|
|
|
|
if (isset($cmd[0])) {
|
|
|
|
if ($cmd[0] == 'quit') {
|
|
|
|
$conn->disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cmd[0] == 'break') {
|
|
|
|
$conn->send('</end>');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cmd[0] == 'vcard') {
|
|
|
|
if (!isset($cmd[1])) {
|
|
|
|
$cmd[1] = $conn->user;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Take a note which user requested which vcard
|
|
|
|
$vcard_request[$from] = $cmd[1];
|
|
|
|
// Request the vcard
|
|
|
|
$conn->getVCard($cmd[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'presence':
|
|
|
|
|
|
|
|
echo "Presence: $from [$show] $status\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'session_start':
|
|
|
|
|
|
|
|
echo "Session start\n";
|
|
|
|
$conn->getRoster();
|
|
|
|
$conn->presence('Quasar!');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'vcard':
|
|
|
|
|
|
|
|
$deliver = array_keys($vcard_request, $from);
|
|
|
|
$msg = '';
|
|
|
|
|
|
|
|
foreach ($data as $key => $item) {
|
|
|
|
$msg .= $key . ': ';
|
|
|
|
|
|
|
|
if (is_array($item)) {
|
|
|
|
$msg .= "\n";
|
|
|
|
foreach ($item as $subkey => $subitem) {
|
|
|
|
$msg .= ' ' . $subkey . ':' . $subitem . "\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$msg .= $item . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($deliver as $sendjid) {
|
|
|
|
unset($vcard_request[$sendjid]);
|
|
|
|
$conn->message($sendjid, $msg, 'chat');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-05 20:50:02 +01:00
|
|
|
}
|
2019-06-18 19:02:40 +01:00
|
|
|
} catch (XMPPHP\Exception $e) {
|
2008-05-05 20:50:02 +01:00
|
|
|
die($e->getMessage());
|
2008-06-03 22:00:38 +01:00
|
|
|
}
|