* @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 © 2008 tiggersWelt.net **/ // Load the Oscar-Client require_once ("oscar/client.php"); /** * Oscar Transport * --------------- * Some abstraction around the OSCAR-Library * * @package tiggerXMPP * @class Oscar_Transport * @revision 02 * @author Bernd Holzmueller **/ class Oscar_Transport extends Oscar_Client { // XMPP-Informations about our subscriber public $XMPP = null; public $JID = ""; // Login-Informations for OSCAR private $OscarID = ""; private $Password = ""; // {{{ __construct /** * Create a new instance * * @param string $JID * @param object $XMPP * @param string $OscarID * @param string $Password * @param bool $Login * * @access friendly * @return void */ function __construct ($JID, $XMPP, $OscarID, $Password, $Login) { // Do not forget our parent ;-) parent::__construct (); $this->XMPP = $XMPP; $this->JID = $JID; $this->OscarID = $OscarID; $this->Password = $Password; if (is_object ($Roster = $this->getRoster ())) { require_once ("libs/oscar_client.php"); $Roster->setContactClass ("Oscar_Transport_Contact"); } if ($Login) self::login (); } // }}} // {{{ getXMPP /** * Retrive handle of our assigned XMPP-Component * * @access public * @return object **/ public function getXMPP () { return $this->XMPP; } // }}} // {{{ login /** * Try to connect this instance to OSCAR * * @access public * @return bool */ public function login () { return parent::login ($this->OscarID, $this->Password); } // }}} public function createEnvelope ($From) { require_once ("tiggerXMPP/message.php"); // Create a basic message $Message = new tiggerXMPP_Message; $Message->setOriginator ($From . "@" . $this->XMPP->Domain); $Message->setDestination ($this->JID); $Message->setType (tiggerXMPP_Message::TYPE_CHAT); return $Message; } // {{{ receiveMessage /** * Receive a message from OSCAR * * @param string $From * @param string $Message * * @access protected * @return void */ public function receiveMessage ($From, $Message) { // Make sure that we have a parent if (!is_object ($this->XMPP)) return false; // Create new XMPP-Message $xmppMessage = $this->createEnvelope ($From); $xmppMessage->setMessage ($Message); // Append typing notification $Event = new tiggerXMPP_XML_Tag ("active", $xmppMessage); $Event->setNamespace ("http://jabber.org/protocol/chatstates"); // Forward the message over XMPP-wire $this->XMPP->sendXML ($xmppMessage); } // }}} // {{{ contactOnline /** * Handle online-information from OSCAR * * @param string $From * @param int $Status * * @access protected * @return void */ public function contactOnline ($From, $Status) { return self::contactStatus ($From, $Status); } // }}} // {{{ contactOffline /** * Handle offline-information from OSCAR * * @param string $From * * @access protected * @return void */ public function contactOffline ($From) { return self::contactStatus ($From, Oscar_TLV_Status::STATUS_OFFLINE); } // }}} // {{{ contactStatus /** * Handle presence-information from OSCAR * * @param string $From * @param int $Status * * @access protected * @return void */ public function contactStatus ($From, $Status) { // Map OSCAR-Status-Codes to XMPP-Status-Codes $Map = array ( Oscar_TLV_Status::STATUS_OFFLINE => tiggerXMPP_Stream::PRESENCE_OFFLINE, Oscar_TLV_Status::STATUS_ONLINE => tiggerXMPP_Stream::PRESENCE_ONLINE, Oscar_TLV_Status::STATUS_AWAY => tiggerXMPP_Stream::PRESENCE_AWAY, Oscar_TLV_Status::STATUS_NA => tiggerXMPP_Stream::PRESENCE_XA, Oscar_TLV_Status::STATUS_OCCUPIED => tiggerXMPP_Stream::PRESENCE_DND, Oscar_TLV_Status::STATUS_DND => tiggerXMPP_Stream::PRESENCE_DND, Oscar_TLV_Status::STATUS_FREEFORCHAT => tiggerXMPP_Stream::PRESENCE_CHAT, Oscar_TLV_Status::STATUS_INVISIBLE => tiggerXMPP_Stream::PRESENCE_ONLINE, ); // Retrive away-message if (is_object ($Roster = $this->getRoster ()) && is_object ($User = $Roster->getContact ($From))) $Message = $User->getAwaymessage (); else $Message = null; if (!isset ($Map [$Status])) { trigger_error ("Unknown/unmapped OSCAR-Status $Status"); $Status = Oscar_TLV_Status::STATUS_FREEFORCHAT; } // Forward this event to XMPP $this->XMPP->setPresence ($Map [$Status], $Message, null, $this->JID, $From . "@" . $this->XMPP->Domain); } // }}} // {{{ authorizationRequest /** * This callback is invoked when someone else wants to add us * * @param string $From * @param string $Reason * * @access public * @return bool */ public function authorizationRequest ($From, $Reason) { // Forward the event $this->XMPP->subscribeContact ($this->JID, $From . "@" . $this->XMPP->Domain); return null; } // }}} } define ("OSCAR_DEBUG_OUT", 1); define ("OSCAR_DEBUG_OUT_VERBOSE", 1); define ("OSCAR_DEBUG_IN", 1); define ("OSCAR_DEBUG_IN_VERBOSE", 1); ?>