* @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 © 2008 tiggersWelt.net */ require_once ('tiggerXMPP/packet.php'); /** * XMPP Prescene Paket * * @package tiggerXMPP * @class tiggerXMPP_Presence * @revision 01 * @author Bernd Holzmueller */ class tiggerXMPP_Presence extends tiggerXMPP_Packet { const TAG_NAME = 'presence'; const TYPE_ONLINE = ''; const TYPE_AWAY = 'away'; const TYPE_CHAT = 'chat'; const TYPE_DND = 'dnd'; const TYPE_XA = 'xa'; const TYPE_OFFLINE = 'unavailable'; const TYPE_ERROR = 'error'; const TYPE_PROBE = 'probe'; const TYPE_SUBSCRIBE = 'subscribe'; // Basic properties of this packet public $Type = ''; // {{{ __construct /** * Setup this presence-packet * * @access friendly * @return void **/ function __construct ($Name = '', $Parent = null, $Value = null, $To = '', $From = null) { parent::__construct ('presence', $Parent, $Value); $this->setNamespace ('jabber:client'); $this->setOriginator ($From); $this->setDestination ($To); } // }}} public static function newTag ($To = '', $From = null) { return new tiggerXMPP_Presence (null, null, null, $To, $From); } public function setReceiver ($To) { $this->setDestination ($To); } // {{{ setType /** * Set the type of this presence-packet * * @param enum $Type * * @access public * @return bool **/ public function setType ($Type) { // Validate the type if (!in_array ($Type, array (self::TYPE_ONLINE, self::TYPE_AWAY, self::TYPE_CHAT, self::TYPE_DND, self::TYPE_XA, self::TYPE_OFFLINE, self::TYPE_ERROR, self::TYPE_PROBE, self::TYPE_SUBSCRIBE))) return false; // Append "show"-Subtag if (!in_array ($Type, array (self::TYPE_ONLINE, self::TYPE_OFFLINE, self::TYPE_ERROR, self::TYPE_PROBE, self::TYPE_SUBSCRIBE))) $Show = $this->createSubtag ('show', null, true, $Type); $this->Type = $Type; return true; } // }}} // {{{ setMessage /** * Set a message for this presence-packet * * @param string $Message * * @access public * @return bool **/ public function setMessage ($Message) { // Remove all statuses $this->removeSubtagsByName ('status'); if (strlen ($Message) == 0) return true; return is_object ($this->createSubtag ('status', null, true, $Message)); } // }}} // {{{ getAttributes /** * Retrive a list of attributes for this tag * * @access public * @return array **/ public function getAttributes () { // Set default attributes $Attribs = array ( 'to' => $this->getDestination (), ); if (strlen ($this->getOriginator ()) > 0) $Attribs ['from'] = $this->getOriginator (); if (($this->Type == self::TYPE_OFFLINE) || ($this->Type == self::TYPE_ERROR) || ($this->Type == self::TYPE_PROBE) || ($this->Type == self::TYPE_SUBSCRIBE)) $Attribs ['type'] = $this->Type; return $Attribs; } // }}} // {{{ appendError /** * Set an error-status for this packet * * @access public * @return void **/ public function appendError ($Error, $Text = '') { // Force an error-type on this packet $this->Type = self::TYPE_ERROR; // Inherit to our parent parent::appendError ($Error, $Text = ''); } // }}} } ?>