* @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 ("tiggerXMPP/extension.php"); class tiggerXMPP_XEP_0091_0203 extends tiggerXMPP_Extension { /* Our XML-Namespaces */ const NAMESPACE_0091 = "jabber:x:delay"; const NAMESPACE_0203 = "urn:xmpp:delay"; /* Internal message-information */ private $__DelayStorage = array (); // {{{ handle /** * Common handler for XEP 0091 and XEP 0203 * * @param object $Tag Packet to handle * * @access public * @return object */ public function handle ($Tag) { $this->__debug (tiggerXMPP_Stream::DEBUG_NOTICE, "called.", __FUNCTION__, __LINE__, __CLASS__, __FILE__); // Find most parent element $Parent = $Tag; while (is_object ($p = $Parent->getParent ())) $Parent = $p; // Verify that the parent got an ID if (!isset ($Parent->id)) { if (isset ($Parent->ID)) $Parent->id = $Parent->ID; elseif ($P = $this->getParent ()) $Parent->id = $P->getUniqueID (); } // Handle the incoming packet $this->__DelayStorage [$Parent->id] = array ( "time" => gmmktime (substr ($Tag->stamp, 9, 2), substr ($Tag->stamp, 12, 2), substr ($Tag->stamp, 15, 2), substr ($Tag->stamp, 4, 2), substr ($Tag->stamp, 6, 2), substr ($Tag->stamp, 0, 4)), "text" => $Tag->getValue (), ); } // }}} // {{{ getDelay /** * Get delay-information for a specific packet * * @param object $Tag * @param bool $Date (optional, default) Return a timestamp * * @access public * @return int */ public function getDelay ($Tag, $Date = true) { // Find most parent element $Parent = $Tag; while (is_object ($p = $Parent->getParent ())) $Parent = $p; // Verify that the parent got an ID if (!isset ($Parent->id)) return false; if (!isset ($this->__DelayStorage [$Parent->id])) return false; return ($Date ? $this->__DelayStorage [$Parent->id]["time"] : time () - $this->__DelayStorage [$Parent->id]["time"]); } // }}} // {{{ getNamespaces /** * Retrive a list of the namespaces we handle * * @access public * @return array **/ public function getNamespaces () { return array ( self::NAMESPACE_0091, self::NAMESPACE_0203, ); } // }}} // {{{ 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_0091: return array ("x"); case self::NAMESPACE_0203: return array ("delay"); } return parent::getTags ($NS); } // }}} } ?>