[COMPOSER] update
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file: XMPPHP Cli example
|
||||
*
|
||||
@@ -19,18 +18,16 @@
|
||||
* LEVEL_VERBOSE = 4;
|
||||
*/
|
||||
|
||||
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,
|
||||
);
|
||||
$conf = [
|
||||
'server' => 'im.server.tld',
|
||||
'port' => 5222,
|
||||
'username' => 'username',
|
||||
'password' => 'password',
|
||||
'proto' => 'xmpphp',
|
||||
'domain' => 'domain.net',
|
||||
'printlog' => true,
|
||||
'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
|
||||
];
|
||||
|
||||
// Easy and simple for access to variables with their names
|
||||
extract($conf);
|
||||
@@ -38,13 +35,13 @@ extract($conf);
|
||||
$conn = new XMPPHP\XMPP($server, $port, $username, $password, $proto, $domain, $printlog, $loglevel);
|
||||
$conn->autoSubscribe();
|
||||
|
||||
$vcard_request = array();
|
||||
$vcard_request = [];
|
||||
|
||||
try {
|
||||
$conn->connect();
|
||||
|
||||
while (!$conn->isDisconnected()) {
|
||||
$events = array('message', 'presence', 'end_stream', 'session_start', 'vcard');
|
||||
$events = ['message', 'presence', 'end_stream', 'session_start', 'vcard'];
|
||||
$payloads = $conn->processUntil($events);
|
||||
|
||||
foreach ($payloads as $result) {
|
||||
@@ -56,84 +53,84 @@ try {
|
||||
|
||||
switch ($event) {
|
||||
|
||||
case 'message':
|
||||
case 'message':
|
||||
|
||||
if (!$body) {
|
||||
break;
|
||||
}
|
||||
if (!$body) {
|
||||
break;
|
||||
}
|
||||
|
||||
echo str_repeat('-', 80);
|
||||
echo "Message from: $from";
|
||||
echo str_repeat('-', 80);
|
||||
echo "Message from: $from";
|
||||
|
||||
if (isset($subject)) {
|
||||
echo "Subject: $subject";
|
||||
}
|
||||
if (isset($subject)) {
|
||||
echo "Subject: $subject";
|
||||
}
|
||||
|
||||
echo $body;
|
||||
echo str_repeat('-', 80);
|
||||
echo $body;
|
||||
echo str_repeat('-', 80);
|
||||
|
||||
$cmd = explode(' ', $body);
|
||||
$body = "Mi no entender! '$body'";
|
||||
$conn->message($from, $body, $type);
|
||||
$cmd = explode(' ', $body);
|
||||
$body = "Mi no entender! '$body'";
|
||||
$conn->message($from, $body, $type);
|
||||
|
||||
if (isset($cmd[0])) {
|
||||
if ($cmd[0] == 'quit') {
|
||||
$conn->disconnect();
|
||||
}
|
||||
if (isset($cmd[0])) {
|
||||
if ($cmd[0] == 'quit') {
|
||||
$conn->disconnect();
|
||||
}
|
||||
|
||||
if ($cmd[0] == 'break') {
|
||||
$conn->send('</end>');
|
||||
}
|
||||
if ($cmd[0] == 'break') {
|
||||
$conn->send('</end>');
|
||||
}
|
||||
|
||||
if ($cmd[0] == 'vcard') {
|
||||
if (!isset($cmd[1])) {
|
||||
$cmd[1] = $conn->user;
|
||||
}
|
||||
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;
|
||||
// Take a note which user requested which vcard
|
||||
$vcard_request[$from] = $cmd[1];
|
||||
// Request the vcard
|
||||
$conn->getVCard($cmd[1]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'presence':
|
||||
case 'presence':
|
||||
|
||||
echo "Presence: $from [$show] $status\n";
|
||||
break;
|
||||
echo "Presence: $from [$show] $status\n";
|
||||
break;
|
||||
|
||||
case 'session_start':
|
||||
case 'session_start':
|
||||
|
||||
echo "Session start\n";
|
||||
$conn->getRoster();
|
||||
$conn->presence('Quasar!');
|
||||
break;
|
||||
echo "Session start\n";
|
||||
$conn->getRoster();
|
||||
$conn->presence('Quasar!');
|
||||
break;
|
||||
|
||||
case 'vcard':
|
||||
case 'vcard':
|
||||
|
||||
$deliver = array_keys($vcard_request, $from);
|
||||
$msg = '';
|
||||
$deliver = array_keys($vcard_request, $from);
|
||||
$msg = '';
|
||||
|
||||
foreach ($data as $key => $item) {
|
||||
$msg .= $key . ': ';
|
||||
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";
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
foreach ($deliver as $sendjid) {
|
||||
unset($vcard_request[$sendjid]);
|
||||
$conn->message($sendjid, $msg, 'chat');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (XMPPHP\Exception $e) {
|
||||
|
Reference in New Issue
Block a user