public function test_xmpp_stanza_nested() { $xml = new JAXLXml('message', array('to' => '1@a.z', 'from' => '2@b.c')); $xml->c('body')->attrs(array('xml:lang' => 'en'))->t('hello')->up()->c('thread')->t('1234')->up()->c('nested')->c('nest')->t('nest1')->up()->c('nest')->t('nest2')->up()->c('nest')->t('nest3')->up()->up()->c('c')->attrs(array('hash' => '84jsdmnskd')); $stanza = new XMPPStanza($xml); $this->assertEquals('<message to="1@a.z" from="2@b.c"><body xml:lang="en">hello</body><thread>1234</thread><nested>' . '<nest>nest1</nest><nest>nest2</nest><nest>nest3</nest></nested><c hash="84jsdmnskd"></c></message>', $stanza->to_string()); }
public function __set($prop, $val) { switch ($prop) { // access to jaxl xml properties case 'name': case 'ns': case 'text': case 'attrs': case 'children': return $this->xml->{$prop} = $val; break; // access to common xml attributes // access to common xml attributes case 'to': case 'from': case 'id': case 'type': $this->xml->attrs[$prop] = $val; return true; break; // access to parts of common xml attributes // access to parts of common xml attributes case 'to_node': case 'to_domain': case 'to_resource': case 'from_node': case 'from_domain': case 'from_resource': list($attr, $key) = explode('_', $prop); $val1 = isset($this->xml->attrs[$attr]) ? $this->xml->attrs[$attr] : null; if (!$val1) { $val1 = ''; } $val1 = new XMPPJid($val1); $val1->{$key} = $val; $this->xml->attrs[$attr] = $val1->to_string(); return true; break; // access to first child element text // access to first child element text case 'status': case 'show': case 'priority': case 'body': case 'thread': case 'subject': $val1 = $this->xml->exists($prop); if (!$val1) { $this->xml->c($prop)->t($val)->up(); } else { $this->xml->update($prop, $val1->ns, $val1->attrs, $val); } return true; break; default: return null; break; } }
public function set_form($domain, $form) { $query = new JAXLXml('query', NS_INBAND_REGISTER); foreach ($form as $k => $v) { $query->c($k, null, array(), $v)->up(); } $pkt = $this->jaxl->get_iq_pkt(array('to' => $domain, 'type' => 'set'), $query); $this->jaxl->send($pkt); }
function on_auth_success_callback() { global $client; JAXLLogger::info("got on_auth_success cb, jid " . $client->full_jid->to_string()); // create node //$client->xeps['0060']->create_node('pubsub.localhost', 'dummy_node'); // publish $item = new JAXLXml('item', null, array('id' => time())); $item->c('entry', 'http://www.w3.org/2005/Atom'); $item->c('title')->t('Soliloquy')->up(); $item->c('summary')->t('To be, or not to be: that is the question')->up(); $item->c('link', null, array('rel' => 'alternate', 'type' => 'text/html', 'href' => 'http://denmark.lit/2003/12/13/atom03'))->up(); $item->c('id')->t('tag:denmark.lit,2003:entry-32397')->up(); $item->c('published')->t('2003-12-13T18:30:02Z')->up(); $item->c('updated')->t('2003-12-13T18:30:02Z')->up(); $client->xeps['0060']->publish_item('pubsub.localhost', 'dummy_node', $item); }
public function get_bind_pkt($resource) { $stanza = new JAXLXml('bind', NS_BIND); $stanza->c('resource')->t($resource); return $this->get_iq_pkt(array('type' => 'set'), $stanza); }
public function get_create_node_pkt($service, $node) { $child = new JAXLXml('pubsub', NS_PUBSUB); $child->c('create', null, array('node' => $node)); return $this->get_iq_pkt($service, $child); }
// initialize JAXL object with initial config // require_once 'jaxl.php'; $client = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'log_level' => JAXL_INFO)); $client->require_xep(array('0060')); // // add necessary event callbacks here // $client->add_cb('on_auth_success', function () { global $client; _info("got on_auth_success cb, jid " . $client->full_jid->to_string()); // create node //$client->xeps['0060']->create_node('pubsub.localhost', 'dummy_node'); // publish $item = new JAXLXml('item', null, array('id' => time())); $item->c('entry', 'http://www.w3.org/2005/Atom'); $item->c('title')->t('Soliloquy')->up(); $item->c('summary')->t('To be, or not to be: that is the question')->up(); $item->c('link', null, array('rel' => 'alternate', 'type' => 'text/html', 'href' => 'http://denmark.lit/2003/12/13/atom03'))->up(); $item->c('id')->t('tag:denmark.lit,2003:entry-32397')->up(); $item->c('published')->t('2003-12-13T18:30:02Z')->up(); $item->c('updated')->t('2003-12-13T18:30:02Z')->up(); $client->xeps['0060']->publish_item('pubsub.localhost', 'dummy_node', $item); }); $client->add_cb('on_auth_failure', function ($reason) { global $client; $client->send_end_stream(); _info("got on_auth_failure cb with reason {$reason}"); }); $client->add_cb('on_disconnect', function () { _info("got on_disconnect cb");