]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Aim/AimPlugin.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / Aim / AimPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2009, StatusNet, Inc.
5  *
6  * Send and receive notices using the AIM network
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  IM
24  * @package   StatusNet
25  * @author    Craig Andrews <candrews@integralblue.com>
26  * @copyright 2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36 // We bundle the phptoclib library...
37 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/phptoclib');
38
39 /**
40  * Plugin for AIM
41  *
42  * @category  Plugin
43  * @package   StatusNet
44  * @author    Craig Andrews <candrews@integralblue.com>
45  * @copyright 2009 StatusNet, Inc.
46  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
47  * @link      http://status.net/
48  */
49 class AimPlugin extends ImPlugin
50 {
51     public $user =  null;
52     public $password = null;
53     public $publicFeed = array();
54
55     public $transport = 'aim';
56
57     function getDisplayName()
58     {
59         // TRANS: Display name.
60         return _m('AIM');
61     }
62
63     function normalize($screenname)
64     {
65                 $screenname = str_replace(" ","", $screenname);
66         return strtolower($screenname);
67     }
68
69     function daemonScreenname()
70     {
71         return $this->user;
72     }
73
74     function validate($screenname)
75     {
76         if(preg_match('/^[a-z]\w{2,15}$/i', $screenname)) {
77             return true;
78         }else{
79             return false;
80         }
81     }
82
83     /**
84      * Load related modules when needed
85      *
86      * @param string $cls Name of the class to be loaded
87      *
88      * @return boolean hook value; true means continue processing, false means stop.
89      */
90     function onAutoload($cls)
91     {
92         $dir = dirname(__FILE__);
93
94         switch ($cls)
95         {
96         case 'Aim':
97             require_once(INSTALLDIR.'/plugins/Aim/extlib/phptoclib/aimclassw.php');
98             return false;
99         }
100
101         return parent::onAutoload($cls);
102     }
103
104     function onStartImDaemonIoManagers(&$classes)
105     {
106         parent::onStartImDaemonIoManagers($classes);
107         $classes[] = new AimManager($this); // handles sending/receiving
108         return true;
109     }
110
111     function microiduri($screenname)
112     {
113         return 'aim:' . $screenname;
114     }
115
116     function sendMessage($screenname, $body)
117     {
118         $this->fake_aim->sendIm($screenname, $body);
119             $this->enqueueOutgoingRaw($this->fake_aim->would_be_sent);
120         return true;
121     }
122
123     /**
124      * Accept a queued input message.
125      *
126      * @return true if processing completed, false if message should be reprocessed
127      */
128     function receiveRawMessage($message)
129     {
130         $info=Aim::getMessageInfo($message);
131         $from = $info['from'];
132         $user = $this->getUser($from);
133         $notice_text = $info['message'];
134
135         $this->handleIncoming($from, $notice_text);
136
137         return true;
138     }
139
140     function initialize(){
141         if(!isset($this->user)){
142             // TRANS: Exception thrown in AIM plugin when user has not been specified.
143             throw new Exception(_m('Must specify a user.'));
144         }
145         if(!isset($this->password)){
146             // TRANS: Exception thrown in AIM plugin when password has not been specified.
147             throw new Exception(_m('Must specify a password.'));
148         }
149
150         $this->fake_aim = new Fake_Aim($this->user,$this->password,4);
151         return true;
152     }
153
154     function onPluginVersion(array &$versions)
155     {
156         $versions[] = array('name' => 'AIM',
157                             'version' => GNUSOCIAL_VERSION,
158                             'author' => 'Craig Andrews',
159                             'homepage' => 'http://status.net/wiki/Plugin:AIM',
160                             'rawdescription' =>
161                             // TRANS: Plugin description.
162                             _m('The AIM plugin allows users to send and receive notices over the AIM network.'));
163         return true;
164     }
165 }