* @revision 03 * @license http://creativecommons.org/licenses/by-sa/2.0/de/ Creative Commons Attribution-Share Alike 2.0 Germany * @homepage http://oss.tiggerswelt.net/oscar/ * @copyright Copyright © 2008 tiggersWelt.net */ require_once ("oscar/tlv/helper/tlv.php"); require_once ("oscar/tlv/message/im/capability.php"); require_once ("oscar/tlv/message/im/text.php"); require_once ("oscar/tlv/message/im/mime.php"); class Oscar_TLV_Message extends Oscar_TLV_Helper_TLV { /* Type of this TLV */ const TYPE = 0x0002; private $tlvMessage = null; // {{{ __construct /** * Contructor of TLV-Object * * @param object $Parent (optional) * @param string $Message (optional) * @param enum $Encoding (optional) * * @access public * @return void */ public function __construct ($Parent = null, $Message = null, $Encoding = null) { parent::__construct ($Parent, self::TYPE, ""); if ($Message !== null) $this->setMessage ($Message, $Encoding); } // }}} // {{{ getTLVClasses /** * Retrive a list of prefered TLV-Types for this TLV * * @access protected * @return array */ protected function getTLVClasses () { return array ( "Oscar_TLV_Message_IM_Capability", "Oscar_TLV_Message_IM_Text", "Oscar_TLV_Message_IM_MIME", ); } // }}} // {{{ getMessage /** * Retrive content of this message * * @access public * @return string */ public function getMessage () { $buf = ""; foreach ($this->TLVs as $TLV) if ($TLV instanceof Oscar_TLV_Message_IM_Text) $buf .= $TLV->getMessage (); return $buf; } // }}} // {{{ getEncoding /** * Check if there is a common encoding on this tlv * * @access public * @return enum **/ public function getEncoding () { // Summarize encodings of text-tlvs $encs = array (); foreach ($this->TLVs as $TLV) if ($TLV instanceof Oscar_TLV_Message_IM_Text) $encs [$TLV->getEncoding ()] = true; // Generate the result if (count ($encs) == 1) return array_shift ($encs); elseif (count ($encs) == 0) return Oscar_TLV_Message_IM_Text::ENCODING_DEFAULT; return Oscar_TLV_Message_IM_Text::ENCODING_UNICODE; } // }}} // {{{ setMessage /** * Set Message on this TLV * * @param string $Message * @param enum $Encoding (optional) * * @access public * @return void */ public function setMessage ($Message, $Encoding = null) { // Remove all TLVs foreach ($this->TLVs as $ID=>$TLV) if (($TLV instanceof Oscar_TLV_Message_IM_Text) || ($TLV instanceof Oscar_TLV_Message_IM_Capability)) unset ($this->TLVs [$ID]); // At least pidgin needs this ^^ $TLV = $this->TLVs [] = new Oscar_TLV_Message_IM_Capability ($this->Parent); $TLV->Value = 0x0106; // Append the message itself $this->appendMessage ($Message, $Encoding); } // }}} // {{{ appendMessage /** * Append a message-bucket to this message * * @param string $Message * @param int $Encoding (optional) * * @access public * @return void **/ public function appendMessage ($Message, $Encoding = null) { // Check if message has already been started foreach ($this->TLVs as $ID=>$TLV) if ($f = ($TLV instanceof Oscar_TLV_Message_IM_Capability)) break; if (!$f) { $TLV = $this->TLVs [] = new Oscar_TLV_Message_IM_Capability ($this->Parent); $TLV->Value = 0x0106; } // Append new Message-Bucket $TLV = $this->TLVs [] = new Oscar_TLV_Message_IM_Text ($this->Parent); $TLV->setMessage ($Message); $TLV->setEncoding ($Encoding); } // }}} } ?>