]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Msn/MsnPlugin.php
91c67f5f799d2f669b49a4699f04dc258f5b25a9
[quix0rs-gnu-social.git] / plugins / Msn / MsnPlugin.php
1 <?php\r
2 /**\r
3  * StatusNet - the distributed open-source microblogging tool\r
4  * Copyright (C) 2009, StatusNet, Inc.\r
5  *\r
6  * Send and receive notices using the MSN network\r
7  *\r
8  * PHP version 5\r
9  *\r
10  * This program is free software: you can redistribute it and/or modify\r
11  * it under the terms of the GNU Affero General Public License as published by\r
12  * the Free Software Foundation, either version 3 of the License, or\r
13  * (at your option) any later version.\r
14  *\r
15  * This program is distributed in the hope that it will be useful,\r
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
18  * GNU Affero General Public License for more details.\r
19  *\r
20  * You should have received a copy of the GNU Affero General Public License\r
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
22  *\r
23  * @category  IM\r
24  * @package   StatusNet\r
25  * @author    Luke Fitzgerald <lw.fitzgerald@googlemail.com>\r
26  * @copyright 2010 StatusNet, Inc.\r
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0\r
28  * @link      http://status.net/\r
29  */\r
30 \r
31 if (!defined('STATUSNET')) {\r
32     // This check helps protect against security problems;\r
33     // your code file can't be executed directly from the web.\r
34     exit(1);\r
35 }\r
36 // We bundle the phpmsnclass library...\r
37 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/phpmsnclass');\r
38 \r
39 /**\r
40  * Plugin for MSN\r
41  *\r
42  * @category  Plugin\r
43  * @package   StatusNet\r
44  * @author    Luke Fitzgerald <lw.fitzgerald@googlemail.com>\r
45  * @copyright 2010 StatusNet, Inc.\r
46  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0\r
47  * @link      http://status.net/\r
48  */\r
49 class MsnPlugin extends ImPlugin {\r
50     public $user = null;\r
51     public $password = null;\r
52     public $nickname = null;\r
53     public $transport = 'msn';\r
54 \r
55     /**\r
56      * Get the internationalized/translated display name of this IM service\r
57      *\r
58      * @return string Name of service\r
59      */\r
60     public function getDisplayName() {\r
61         // TRANS: Display name of the MSN instant messaging service.\r
62         return _m('MSN');\r
63     }\r
64 \r
65     /**\r
66      * Normalize a screenname for comparison\r
67      *\r
68      * @param string $screenname screenname to normalize\r
69      * @return string an equivalent screenname in normalized form\r
70      */\r
71     public function normalize($screenname) {\r
72         $screenname = str_replace(" ","", $screenname);\r
73         return strtolower($screenname);\r
74     }\r
75 \r
76     /**\r
77      * Get the screenname of the daemon that sends and receives messages\r
78      *\r
79      * @return string Screenname\r
80      */\r
81     public function daemonScreenname() {\r
82         return $this->user;\r
83     }\r
84 \r
85     /**\r
86      * Validate (ensure the validity of) a screenname\r
87      *\r
88      * @param string $screenname screenname to validate\r
89      * @return boolean\r
90      */\r
91     public function validate($screenname) {\r
92         return Validate::email($screenname, common_config('email', 'check_domain'));\r
93     }\r
94 \r
95     /**\r
96      * Load related modules when needed\r
97      *\r
98      * @param string $cls Name of the class to be loaded\r
99      * @return boolean hook value; true means continue processing, false means stop.\r
100      */\r
101     public function onAutoload($cls) {\r
102         $dir = dirname(__FILE__);\r
103 \r
104         switch ($cls) {\r
105             case 'MSN':\r
106                 require_once(INSTALLDIR.'/plugins/Msn/extlib/phpmsnclass/msn.class.php');\r
107                 return false;\r
108         }\r
109 \r
110         return parent::onAutoload($cls);\r
111     }\r
112 \r
113     /*\r
114      * Start manager on daemon start\r
115      *\r
116      * @return boolean\r
117      */\r
118     public function onStartImDaemonIoManagers(&$classes) {\r
119         parent::onStartImDaemonIoManagers($classes);\r
120         $classes[] = new MsnManager($this); // handles sending/receiving\r
121         return true;\r
122     }\r
123 \r
124     /**\r
125     * Ensure the database table is present\r
126     *\r
127     */\r
128     public function onCheckSchema() {\r
129         $schema = Schema::get();\r
130 \r
131         // For storing messages while sessions become ready\r
132         $schema->ensureTable('msn_waiting_message', Msn_waiting_message::schemaGet());\r
133         return true;\r
134     }\r
135 \r
136     /**\r
137     * Get a microid URI for the given screenname\r
138     *\r
139     * @param string $screenname\r
140     * @return string microid URI\r
141     */\r
142     public function microiduri($screenname) {\r
143         return 'msnim:' . $screenname;\r
144     }\r
145 \r
146     /**\r
147      * Send a message to a given screenname\r
148      *\r
149      * @param string $screenname Screenname to send to\r
150      * @param string $body Text to send\r
151      * @return boolean success value\r
152      */\r
153     public function sendMessage($screenname, $body) {\r
154         $this->enqueueOutgoingRaw(array('to' => $screenname, 'message' => $body));\r
155         return true;\r
156     }\r
157 \r
158     /**\r
159      * Accept a queued input message.\r
160      *\r
161      * @param array $data Data\r
162      * @return true if processing completed, false if message should be reprocessed\r
163      */\r
164     public function receiveRawMessage($data) {\r
165         $this->handleIncoming($data['sender'], $data['message']);\r
166         return true;\r
167     }\r
168 \r
169     /**\r
170     * Initialize plugin\r
171     *\r
172     * @return boolean\r
173     */\r
174     public function initialize() {\r
175         if (!isset($this->user)) {\r
176             // TRANS: Exception thrown when configuration for the MSN plugin is incomplete.\r
177             throw new Exception(_m('Must specify a user.'));\r
178         }\r
179         if (!isset($this->password)) {\r
180             // TRANS: Exception thrown when configuration for the MSN plugin is incomplete.\r
181             throw new Exception(_m('Must specify a password.'));\r
182         }\r
183         if (!isset($this->nickname)) {\r
184             // TRANS: Exception thrown when configuration for the MSN plugin is incomplete.\r
185             throw new Exception(_m('Must specify a nickname.'));\r
186         }\r
187 \r
188         return true;\r
189     }\r
190 \r
191     /**\r
192      * Get plugin information\r
193      *\r
194      * @param array $versions array to insert information into\r
195      * @return void\r
196      */\r
197     public function onPluginVersion(&$versions) {\r
198         $versions[] = array(\r
199             'name' => 'MSN',\r
200             'version' => STATUSNET_VERSION,\r
201             'author' => 'Luke Fitzgerald',\r
202             'homepage' => 'http://status.net/wiki/Plugin:MSN',\r
203             'rawdescription' =>\r
204             // TRANS: Plugin description.\r
205             _m('The MSN plugin allows users to send and receive notices over the MSN network.')\r
206         );\r
207         return true;\r
208     }\r
209 }\r