Browse Source

Small refactor in MAM

Allow Vcards to be set with a destination
pull/652/head
Timothée Jaussoin 8 years ago
parent
commit
71ead352e2
  1. 22
      src/Moxl/Stanza/MAM.php
  2. 53
      src/Moxl/Stanza/Vcard.php
  3. 10
      src/Moxl/Xec/Action/MAM/Get.php
  4. 11
      src/Moxl/Xec/Action/Vcard/Set.php

22
src/Moxl/Stanza/MAM.php

@ -27,7 +27,7 @@ class MAM
static function get(
$to = null, $id, $jid = false,
$start = false, $end = false,
$limit = false, $after = false, $version = '1')
$limit = false, $after = false, $before = false, $version = '1')
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$query = $dom->createElementNS('urn:xmpp:mam:'.$version, 'query');
@ -43,14 +43,14 @@ class MAM
$field_type->appendChild($dom->createElement('value', 'urn:xmpp:mam:'.$version));
$x->appendChild($field_type);
if($jid) {
if ($jid) {
$field_with = $dom->createElement('field');
$field_with->setAttribute('var', 'with');
$field_with->appendChild($dom->createElement('value', $jid));
$x->appendChild($field_with);
}
if($start) {
if ($start) {
$field_start = $dom->createElement('field');
$field_start->setAttribute('var', 'start');
$field_start->appendChild(
@ -62,7 +62,7 @@ class MAM
$x->appendChild($field_start);
}
if($end) {
if ($end) {
$field_end = $dom->createElement('field');
$field_end->setAttribute('var', 'end');
$field_end->appendChild(
@ -74,18 +74,26 @@ class MAM
$x->appendChild($field_end);
}
if($limit || $after) {
if ($limit || $after) {
$set_limit = $dom->createElement('set');
$set_limit->setAttribute('xmlns', 'http://jabber.org/protocol/rsm');
if($limit) {
if ($limit) {
$set_limit->appendChild($dom->createElement('max', $limit));
}
if($after) {
if ($after) {
$set_limit->appendChild($dom->createElement('after', $after));
}
if ($before) {
$set_limit->appendChild(
($before == true)
? $dom->createElement('before')
: $dom->createElement('before', $before)
);
}
$query->appendChild($set_limit);
}

53
src/Moxl/Stanza/Vcard.php

@ -12,33 +12,40 @@ class Vcard
\Moxl\API::request($xml);
}
static function set($data)
static function set($to = false, $data)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$vcard = $dom->createElementNS('vcard-temp', 'vCard');
$vcard->appendChild($dom->createElement('FN', $data->fn->value));
$vcard->appendChild($dom->createElement('NICKNAME', $data->name->value));
$vcard->appendChild($dom->createElement('URL', $data->url->value));
$vcard->appendChild($dom->createElement('BDAY', $data->date->value));
$email = $dom->createElement('EMAIL');
$email->appendChild($dom->createElement('USERID', $data->email->value));
$vcard->appendChild($email);
$adr = $dom->createElement('ADR');
$adr->appendChild($dom->createElement('LOCALITY', $data->locality->value));
$adr->appendChild($dom->createElement('PCODE', $data->postalcode->value));
$adr->appendChild($dom->createElement('CTRY', $data->country->value));
$vcard->appendChild($adr);
$vcard->appendChild($dom->createElement('DESC', $data->desc->value));
$photo = $dom->createElement('PHOTO');
$photo->appendChild($dom->createElement('TYPE', $data->phototype->value));
$photo->appendChild($dom->createElement('BINVAL', $data->photobin->value));
$vcard->appendChild($photo);
$xml = \Moxl\API::iqWrapper($vcard, false, 'set');
if ($data->fn) $vcard->appendChild($dom->createElement('FN', $data->fn->value));
if ($data->name) $vcard->appendChild($dom->createElement('NICKNAME', $data->name->value));
if ($data->url) $vcard->appendChild($dom->createElement('URL', $data->url->value));
if ($data->date) $vcard->appendChild($dom->createElement('BDAY', $data->date->value));
if ($data->email) {
$email = $dom->createElement('EMAIL');
$email->appendChild($dom->createElement('USERID', $data->email->value));
$vcard->appendChild($email);
}
if ($data->country || $data->locality || $data->postalcode) {
$adr = $dom->createElement('ADR');
$adr->appendChild($dom->createElement('LOCALITY', $data->locality->value));
$adr->appendChild($dom->createElement('PCODE', $data->postalcode->value));
$adr->appendChild($dom->createElement('CTRY', $data->country->value));
$vcard->appendChild($adr);
}
if ($data->desc) $vcard->appendChild($dom->createElement('DESC', $data->desc->value));
if ($data->photobin && $data->phototype) {
$photo = $dom->createElement('PHOTO');
$photo->appendChild($dom->createElement('TYPE', $data->phototype->value));
$photo->appendChild($dom->createElement('BINVAL', $data->photobin->value));
$vcard->appendChild($photo);
}
$xml = \Moxl\API::iqWrapper($vcard, $to, 'set');
\Moxl\API::request($xml);
}
}

10
src/Moxl/Xec/Action/MAM/Get.php

@ -16,6 +16,7 @@ class Get extends Action
private $_end;
private $_limit;
private $_after;
private $_before;
private $_version = '2';
public function request()
@ -29,7 +30,8 @@ class Get extends Action
MAM::get($this->_to, $this->_queryid, $this->_jid,
$this->_start, $this->_end,
$this->_limit, $this->_after, $this->_version);
$this->_limit, $this->_after, $this->_before,
$this->_version);
}
public function setTo($to)
@ -62,6 +64,12 @@ class Get extends Action
return $this;
}
public function setBefore($before = true)
{
$this->_before = $before;
return $this;
}
public function setLimit($limit)
{
$this->_limit = $limit;

11
src/Moxl/Xec/Action/Vcard/Set.php

@ -28,12 +28,13 @@ use Moxl\Stanza\Vcard;
class Set extends Action
{
private $_to;
private $_data;
public function request()
{
$this->store();
Vcard::set($this->_data);
Vcard::set($this->_to, $this->_data);
}
public function setData($data)
@ -42,7 +43,15 @@ class Set extends Action
return $this;
}
public function setTo($to)
{
$this->_to = $to;
return $this;
}
public function handle($stanza, $parent = false)
{
$this->pack($this->_to);
$this->deliver();
}
}
Loading…
Cancel
Save