move examples into own directory
This commit is contained in:
77
examples/cli_longrun_example.php
Normal file
77
examples/cli_longrun_example.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
// activate full error reporting
|
||||
//error_reporting(E_ALL & E_STRICT);
|
||||
|
||||
include 'XMPPHP/XMPP.php';
|
||||
|
||||
#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?
|
||||
$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'username', 'password', 'xmpphp', 'gmail.com', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO);
|
||||
$conn->autoSubscribe();
|
||||
|
||||
$vcard_request = array();
|
||||
|
||||
try {
|
||||
$conn->connect();
|
||||
while(!$conn->isDisconnected()) {
|
||||
$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start', 'vcard'));
|
||||
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']);
|
||||
$cmd = explode(' ', $pl['body']);
|
||||
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]);
|
||||
}
|
||||
break;
|
||||
case 'presence':
|
||||
print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";
|
||||
break;
|
||||
case 'session_start':
|
||||
print "Session Start\n";
|
||||
$conn->getRoster();
|
||||
$conn->presence($status="Cheese!");
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(XMPPHP_Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
43
examples/cli_longrun_example_bosh.php
Normal file
43
examples/cli_longrun_example_bosh.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
// activate full error reporting
|
||||
//error_reporting(E_ALL & E_STRICT);
|
||||
|
||||
include 'XMPPHP/BOSH.php';
|
||||
|
||||
#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?
|
||||
$conn = new XMPPHP_BOSH('server.tld', 5280, 'username', 'password', 'xmpphp', 'server.tld', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE);
|
||||
$conn->autoSubscribe();
|
||||
|
||||
try {
|
||||
$conn->connect('http://server.tld:5280/xmpp-httpbind');
|
||||
while(!$conn->isDisconnected()) {
|
||||
$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'));
|
||||
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']);
|
||||
if($pl['body'] == 'quit') $conn->disconnect();
|
||||
if($pl['body'] == 'break') $conn->send("</end>");
|
||||
break;
|
||||
case 'presence':
|
||||
print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";
|
||||
break;
|
||||
case 'session_start':
|
||||
print "Session Start\n";
|
||||
$conn->getRoster();
|
||||
$conn->presence($status="Cheese!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(XMPPHP_Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
20
examples/sendmessage_example.php
Normal file
20
examples/sendmessage_example.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
// activate full error reporting
|
||||
//error_reporting(E_ALL & E_STRICT);
|
||||
|
||||
include 'XMPPHP/XMPP.php';
|
||||
|
||||
#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?
|
||||
$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'username', 'password', 'xmpphp', 'gmail.com', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);
|
||||
|
||||
try {
|
||||
$conn->connect();
|
||||
$conn->processUntil('session_start');
|
||||
$conn->presence();
|
||||
$conn->message('someguy@someserver.net', 'This is a test message!');
|
||||
$conn->disconnect();
|
||||
} catch(XMPPHP_Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
56
examples/webclient_example.php
Normal file
56
examples/webclient_example.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
session_start();
|
||||
header('content-type', 'plain/text');
|
||||
// activate full error reporting
|
||||
//error_reporting(E_ALL & E_STRICT);
|
||||
|
||||
include 'XMPPHP/BOSH.php';
|
||||
print "<pre>";
|
||||
|
||||
#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?
|
||||
$conn = new XMPPHP_BOSH('server.tld', 5280, 'user', 'password', 'xmpphp', 'server.tld', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO);
|
||||
$conn->autoSubscribe();
|
||||
|
||||
try {
|
||||
if(isset($_SESSION['messages'])) {
|
||||
foreach($_SESSION['messages'] as $msg) {
|
||||
print $msg;
|
||||
flush();
|
||||
}
|
||||
}
|
||||
$conn->connect('http://server.tld:5280/xmpp-httpbind', 1, true);
|
||||
#while(true) {
|
||||
$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'));
|
||||
foreach($payloads as $event) {
|
||||
$pl = $event[1];
|
||||
switch($event[0]) {
|
||||
case 'message':
|
||||
if(!isset($_SESSION['messages'])) $_SESSION['message'] = Array();
|
||||
$msg = "---------------------------------------------------------------------------------\n{$pl['from']}: {$pl['body']}\n";
|
||||
print $msg;
|
||||
$_SESSION['messages'][] = $msg;
|
||||
flush();
|
||||
$conn->message($pl['from'], $body="Thanks for sending me \"{$pl['body']}\".", $type=$pl['type']);
|
||||
if($pl['body'] == 'quit') $conn->disconnect();
|
||||
if($pl['body'] == 'break') $conn->send("</end>");
|
||||
break;
|
||||
case 'presence':
|
||||
print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";
|
||||
break;
|
||||
case 'session_start':
|
||||
print "Session Start\n";
|
||||
$conn->getRoster();
|
||||
$conn->presence($status="Cheese!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#}
|
||||
} catch(XMPPHP_Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
||||
$conn->saveSession();
|
||||
|
||||
print "</pre>";
|
||||
print "<img src='http://xmpp.org/images/xmpp.png' onload='window.location.reload()' />";
|
||||
?>
|
Reference in New Issue
Block a user