* added vcard support

git-svn-id: svn://netflint.net/xmpphp@71 ef36c318-a008-4979-b6e8-6b496270793b
This commit is contained in:
fritzy
2008-11-28 19:43:05 +00:00
parent b13761eb26
commit eaf949de88
3 changed files with 74 additions and 8 deletions

View File

@@ -45,12 +45,12 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream {
/**
* @var string
*/
protected $server;
public $server;
/**
* @var string
*/
protected $user;
public $user;
/**
* @var string
@@ -380,4 +380,41 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream {
stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
$this->reset();
}
/**
* Retrieves the vcard
*
*/
public function getVCard($jid = Null) {
$id = $this->getID();
$this->addIdHandler($id, 'vcard_get_handler');
if($jid) {
$this->send("<iq type='get' id='$id' to='$jid'><vCard xmlns='vcard-temp' /></iq>");
} else {
$this->send("<iq type='get' id='$id'><vCard xmlns='vcard-temp' /></iq>");
}
}
/**
* VCard retrieval handler
*
* @param XML Object $xml
*/
protected function vcard_get_handler($xml) {
$vcard_array = array();
$vcard = $xml->sub('vcard');
// go through all of the sub elements and add them to the vcard array
foreach ($vcard->subs as $sub) {
if ($sub->subs) {
$vcard_array[$sub->name] = array();
foreach ($sub->subs as $sub_child) {
$vcard_array[$sub->name][$sub_child->name] = $sub_child->data;
}
} else {
$vcard_array[$sub->name] = $sub->data;
}
}
$vcard_array['from'] = $xml->attrs['from'];
$this->event('vcard', $vcard_array);
}
}