]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Aim/lib/aimmanager.php
plugins onAutoload now only overloads if necessary (extlibs etc.)
[quix0rs-gnu-social.git] / plugins / Aim / lib / aimmanager.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
21
22 /**
23  * AIM background connection manager for AIM-using queue handlers,
24  * allowing them to send outgoing messages on the right connection.
25  *
26  * Input is handled during socket select loop, keepalive pings during idle.
27  * Any incoming messages will be handled.
28  *
29  * In a multi-site queuedaemon.php run, one connection will be instantiated
30  * for each site being handled by the current process that has XMPP enabled.
31  */
32 class AimManager extends ImManager
33 {
34     public $conn = null;
35     /**
36      * Initialize connection to server.
37      * @return boolean true on success
38      */
39     public function start($master)
40     {
41         if(parent::start($master))
42         {
43             $this->connect();
44             return true;
45         }else{
46             return false;
47         }
48     }
49
50     public function getSockets()
51     {
52         $this->connect();
53         if($this->conn){
54             return array($this->conn->myConnection);
55         }else{
56             return array();
57         }
58     }
59
60     /**
61      * Process AIM events that have come in over the wire.
62      * @param resource $socket
63      */
64     public function handleInput($socket)
65     {
66         common_log(LOG_DEBUG, "Servicing the AIM queue.");
67         $this->stats('aim_process');
68         $this->conn->receive();
69     }
70
71     function connect()
72     {
73         if (!$this->conn) {
74             $this->conn=new Aim($this->plugin->user,$this->plugin->password,4);
75             $this->conn->registerHandler("IMIn",array($this,"handle_aim_message"));
76             $this->conn->myServer="toc.oscar.aol.com";
77             $this->conn->signon();
78             // @todo i18n FIXME: Update translator documentation, please.
79             // TRANS: No idea what the use case for this message is.
80             $this->conn->setProfile(_m('Send me a message to post a notice'),false);
81         }
82         return $this->conn;
83     }
84
85     function handle_aim_message($data)
86     {
87         $this->plugin->enqueueIncomingRaw($data);
88         return true;
89     }
90
91     function send_raw_message($data)
92     {
93         $this->connect();
94         if (!$this->conn) {
95             return false;
96         }
97         $this->conn->sflapSend($data[0],$data[1],$data[2],$data[3]);
98         return true;
99     }
100 }