Difference between revisions of "XMPPHP"

From JaWiki (Jabber/XMPP wiki)
Jump to: navigation, search
m (Reverted edits by 5.228.4.83 (talk) to last revision by Cblp.su)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{stub}}
 
{{stub}}
 
{{Library
 
{{Library
|            name=XMPPPHP
+
|            name=XMPPHP
 
|              url=http://code.google.com/p/xmpphp/
 
|              url=http://code.google.com/p/xmpphp/
|          author=[http://nathan.fritzclan.com/ Nathan Fritz]
+
|          author=[[Nathan Fritz]] (fritzy)
 
|        language={{Lang|l|PHP}}
 
|        language={{Lang|l|PHP}}
|          license=GNU General Public License v2
+
|          license={{GPL}} v2
|          roster=поддерживается
+
|          roster=да
 
}}
 
}}
  
XMPPHP - класс на PHP5, являющийся наследником [[Class.jabber.php]].  
+
XMPPHP класс на [[PHP]], являющийся наследником [[Class.jabber.php]].
  
{{fixme|так есть там или нет поддержка ростера? я что-то не понял. [[User:Vindicar|Vindicar]] 13:55, 11 April 2009 (GMT)}}
+
Простой пример кода для отправки сообщений:
  
class Roster {
+
  <?php
/**
+
    include("xmpp.php");
* Roster array, handles contacts and presence. Indexed by jid.
+
    $conn = new XMPP('talk.google.com', 5222, 'username', 'password', 'xmpphp',
* Contains array with potentially two indexes 'contact' and 'presence'
+
        'gmail.com', $printlog=False, $loglevel=LOGGING_INFO);
* @var array
+
    $conn->connect();
*/
+
    $conn->processUntil('session_start');
protected $roster_array = array();
+
    $conn->message('someguy@someserver.net', 'This is a test message!');
/**
+
    $conn->disconnect();
* Constructor
+
?>
*
+
*/
+
public function __construct($roster_array = array()) {
+
if ($this->verifyRoster($roster_array)) {
+
$this->roster_array = $roster_array; //Allow for prepopulation with existing roster
+
} else {
+
$this->roster_array = array();
+
}
+
}
+
 
+
/**
+
*
+
* Check that a given roster array is of a valid structure (empty is still valid)
+
*
+
* @param array $roster_array
+
*/
+
protected function verifyRoster($roster_array) {
+
#TODO once we know *what* a valid roster array looks like
+
return True;
+
}
+
 
+
/**
+
*
+
* Add given contact to roster
+
*
+
* @param string $jid
+
* @param string $subscription
+
* @param string $name
+
* @param array $groups
+
*/
+
public function addContact($jid, $subscription, $name='', $groups=array()) {
+
$contact = array('jid' => $jid, 'subscription' => $subscription, 'name' => $name, 'groups' => $groups);
+
if ($this->isContact($jid)) {
+
$this->roster_array[$jid]['contact'] = $contact;
+
} else {
+
$this->roster_array[$jid] = array('contact' => $contact);
+
}
+
}
+
 
+
/**
+
*
+
* Retrieve contact via jid
+
*
+
* @param string $jid
+
*/
+
public function getContact($jid) {
+
if ($this->isContact($jid)) {
+
return $this->roster_array[$jid]['contact'];
+
}
+
}
+
 
+
/**
+
*
+
* Discover if a contact exists in the roster via jid
+
*
+
* @param string $jid
+
*/
+
public function isContact($jid) {
+
return (array_key_exists($jid, $this->roster_array));
+
}
+
 
+
/**
+
*
+
* Set presence
+
*
+
* @param string $presence
+
* @param integer $priority
+
* @param string $show
+
* @param string $status
+
*/
+
public function setPresence($presence, $priority, $show, $status) {
+
list($jid, $resource) = split("/", $presence);
+
if ($show != 'unavailable') {
+
if (!$this->isContact($jid)) {
+
$this->addContact($jid, 'not-in-roster');
+
}
+
$resource = $resource ? $resource : '';
+
$this->roster_array[$jid]['presence'][$resource] = array('priority' => $priority, 'show' => $show, 'status' => $status);
+
} else { //Nuke unavailable resources to save memory
+
unset($this->roster_array[$jid]['resource'][$resource]);
+
}
+
}
+
 
+
/*
+
*
+
* Return best presence for jid
+
*
+
* @param string $jid
+
*/
+
public function getPresence($jid) {
+
$split = split("/", $jid);
+
$jid = $split[0];
+
if($this->isContact($jid)) {
+
$current = array('resource' => '', 'active' => '', 'priority' => -129, 'show' => '', 'status' => ''); //Priorities can only be -128 = 127
+
foreach($this->roster_array[$jid]['presence'] as $resource => $presence) {
+
//Highest available priority or just highest priority
+
if ($presence['priority'] > $current['priority'] and (($presence['show'] == "chat" or $presence['show'] == "available") or ($current['show'] != "chat" or $current['show'] != "available"))) {
+
$current = $presence;
+
$current['resource'] = $resource;
+
}
+
}
+
return $current;
+
}
+
}
+
/**
+
*
+
* Get roster
+
*
+
*/
+
public function getRoster() {
+
return $this->roster_array;
+
}
+

Latest revision as of 10:34, 28 January 2017

Информации мало или она отсутствует

Пока в данной статье мало информации. Приносим извинения.

Если вы хотите написать по теме, — сделайте это.

XMPPHP
Информация
Адрес: http://code.google.com/p/xmpphp/
Автор: Nathan Fritz (fritzy)
Язык: PHP
Лицензия: GPL v2
Реализация стандартов
Ростер: да
Использование
Программы, использующие XMPPHP

XMPPHP — класс на PHP, являющийся наследником Class.jabber.php.

Простой пример кода для отправки сообщений:

<?php
    include("xmpp.php");
    $conn = new XMPP('talk.google.com', 5222, 'username', 'password', 'xmpphp',
        'gmail.com', $printlog=False, $loglevel=LOGGING_INFO);
    $conn->connect();
    $conn->processUntil('session_start');
    $conn->message('someguy@someserver.net', 'This is a test message!');
    $conn->disconnect();
?>