]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Aim/AimPlugin.php
More info for a proper, fancy-url lighttpd setup
[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         case 'AimManager':
100             include_once $dir . '/'.strtolower($cls).'.php';
101             return false;
102         case 'Fake_Aim':
103             include_once $dir . '/'. $cls .'.php';
104             return false;
105         default:
106             return true;
107         }
108     }
109
110     function onStartImDaemonIoManagers(&$classes)
111     {
112         parent::onStartImDaemonIoManagers($classes);
113         $classes[] = new AimManager($this); // handles sending/receiving
114         return true;
115     }
116
117     function microiduri($screenname)
118     {
119         return 'aim:' . $screenname;
120     }
121
122     function sendMessage($screenname, $body)
123     {
124         $this->fake_aim->sendIm($screenname, $body);
125             $this->enqueueOutgoingRaw($this->fake_aim->would_be_sent);
126         return true;
127     }
128
129     /**
130      * Accept a queued input message.
131      *
132      * @return true if processing completed, false if message should be reprocessed
133      */
134     function receiveRawMessage($message)
135     {
136         $info=Aim::getMessageInfo($message);
137         $from = $info['from'];
138         $user = $this->getUser($from);
139         $notice_text = $info['message'];
140
141         $this->handleIncoming($from, $notice_text);
142
143         return true;
144     }
145
146     function initialize(){
147         if(!isset($this->user)){
148             // TRANS: Exception thrown in AIM plugin when user has not been specified.
149             throw new Exception(_m('Must specify a user.'));
150         }
151         if(!isset($this->password)){
152             // TRANS: Exception thrown in AIM plugin when password has not been specified.
153             throw new Exception(_m('Must specify a password.'));
154         }
155
156         $this->fake_aim = new Fake_Aim($this->user,$this->password,4);
157         return true;
158     }
159
160     function onPluginVersion(&$versions)
161     {
162         $versions[] = array('name' => 'AIM',
163                             'version' => STATUSNET_VERSION,
164                             'author' => 'Craig Andrews',
165                             'homepage' => 'http://status.net/wiki/Plugin:AIM',
166                             'rawdescription' =>
167                             // TRANS: Plugin description.
168                             _m('The AIM plugin allows users to send and receive notices over the AIM network.'));
169         return true;
170     }
171 }