* @revision 05 * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons Attribution-Share Alike 3.0 Germany * @homepage http://oss.tiggerswelt.net/xmpp * @copyright Copyright © 2009 tiggersWelt.net */ require_once ('phpEvents/socket/stream/xml/tag.php'); require_once ('tiggerXMPP/extension.php'); /** * XEP-0090 / XEP-0202 Entity Time * * @package tiggerXMPP * @class XEP_0090_0202 */ class tiggerXMPP_XEP_0090_0202 extends tiggerXMPP_Extension { /* Our namespaces */ const NAMESPACE_0090 = "jabber:iq:time"; const NAMESPACE_0202 = "urn:xmpp:time"; // {{{ getNamespaces /** * Retrive a list of the namespaces we handle * * @access public * @return array **/ public function getNamespaces () { return array ( self::NAMESPACE_0090, self::NAMESPACE_0202, ); } // }}} // {{{ getTags /** * Retrive a list of all tags we handle for a given namespace * * @param string $Namespace * * @access public * @return array **/ public function getTags ($NS = "") { switch ($NS) { case self::NAMESPACE_0090: return array ("query"); case self::NAMESPACE_0202: return array ("time"); } return parent::getTags ($NS); } // }}} // {{{ handle public function handle ($Tag) { $this->__debug (tiggerXMPP_Stream::DEBUG_NOTICE, "called.", __FUNCTION__, __LINE__, __CLASS__, __FILE__); switch ($Tag->getNamespace ()) { // XEP-0090 Entity Time case self::NAMESPACE_0090: $Resp = new phpEvents_Socket_Stream_XML_Tag ('query'); $Resp->setNamespace ($Tag->getNamespace ()); $tagUTC = new phpEvents_Socket_Stream_XML_Tag ('utc', $Resp, gmdate ('Ymd') . 'T' . date ('H:i:s')); $tagTZ = new phpEvents_Socket_Stream_XML_Tag ('tz', $Resp, date ('T')); $tagDisplay = new phpEvents_Socket_Stream_XML_Tag ('display', $Resp, date ('D M d H:i:s Y')); return $Resp; // XEP-0202 Entity Time case self::NAMESPACE_0202: $Resp = new phpEvents_Socket_Stream_XML_Tag ('time'); $Resp->setNamespace ($Tag->getNamespace ()); $tagTZO = new phpEvents_Socket_Stream_XML_Tag ('tzo', $Resp, date ('P')); $tagUTC = new phpEvents_Socket_Stream_XML_Tag ('utc', $Resp, gmdate ('Ymd') . 'T' . date ('H:i:s')); return $Resp; } } // }}} // {{{ getTime_XEP0090 /** * Request the time of an entity according to XEP-0090 * * @param string $JID JID of entity * * @access public * @return int */ public function getTime_XEP0090 ($JID) { if (!is_object ($P = $this->getParent ())) return false; $Resp = new phpEvents_Socket_Stream_XML_Tag ('iq'); $Resp->setOriginator ($P->getJID ()); $Resp->setDestination ($JID); $Resp->setAttribute ('id', $P->getUniqueID ()); $Resp->setAttribute ('type', 'get'); $tagQuery = new phpEvents_Socket_Stream_XML_Tag ('query', $Resp); $tagQuery->setNamespace (self::NAMESPACE_0090); $P->sendXML ($Resp); $Resp = $P->waitBlock (array (), $Resp->getAttribute ('id')); if ($Resp->haveSubtags ("error") || !$Resp->haveSubtags ("utc")) return false; if (!is_object ($tagUTC = $Resp->getSubtagByName ('utc'))) return false; $UTC = $tagUTC->getValue (); # $TZ = $Resp->Subtags ["query"][0]->Subtags ["tz"][0]->getValue (); # $Disp = $Resp->Subtags ["query"][0]->Subtags ["display"][0]->getValue (); return gmmktime (substr ($UTC, 9, 2), substr ($UTC, 12, 2), substr ($UTC, 15, 2), substr ($UTC, 4, 2), substr ($UTC, 6, 2), substr ($UTC, 0, 4)); } // }}} // {{{ getTime_XEP0202 /** * Request the time of an entity according to XEP-0202 * * @param string $JID JID of entity * * @access public * @return int */ public function getTime_XEP0202 ($JID) { if (!is_object ($P = $this->getParent ())) return false; $Resp = new phpEvents_Socket_Stream_XML_Tag ('iq'); $Resp->setOriginator ($P->getJID ()); $Resp->setDestination ($JID); $Resp->setAttribute ('id', $P->getUniqueID ()); $Resp->setAttribute ('type', 'get'); $tagTime = new phpEvents_Socket_Stream_XML_Tag ('time', $Resp); $tagTime->setNamespace (self::NAMESPACE_0202); $P->sendXML ($Resp); $Resp = $P->waitBlock (array (), $Resp->id); if ($Resp->haveSubtags ("error") || !$Resp->haveSubtags ("utc")) return false; if (!is_object ($tagUTC = $Resp->getSubtagByName ("utc"))) return false; # $Tzo = $Resp->Subtags ["query"][0]->Subtags ["tzo"][0]->getValue (); $UTC = $tagUTC->getValue (); return gmmktime (substr ($UTC, 9, 2), substr ($UTC, 12, 2), substr ($UTC, 15, 2), substr ($UTC, 4, 2), substr ($UTC, 6, 2), substr ($UTC, 0, 4)); } // }}} // {{{ getTime /** * Try to get time at an entity * * @param string $JID JID of entity * * @access public * @return int */ public function getTime () { if (!($rc = self::getTime_XEP0202 ($JID))) return self::getTime_XEP0090 ($JID); return $rc; } // }}} } ?>