]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Phergie/Plugin/Statusnet.php
Added some missing comments
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Phergie / Plugin / Statusnet.php
1 <?php\r
2 /**\r
3  * StatusNet - the distributed open-source microblogging tool\r
4  *\r
5  * This program is free software: you can redistribute it and/or modify\r
6  * it under the terms of the GNU Affero General Public License as published by\r
7  * the Free Software Foundation, either version 3 of the License, or\r
8  * (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU Affero General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU Affero General Public License\r
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
17  *\r
18  * Calls the given Statusnet IM architecture enqueuing method to enqueue\r
19  * a new incoming message\r
20  *\r
21  * @category  Phergie\r
22  * @package   Phergie_Plugin_Statusnet\r
23  * @author    Luke Fitzgerald <lw.fitzgerald@googlemail.com>\r
24  * @copyright 2010 StatusNet, Inc.\r
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0\r
26  * @link      http://status.net/\r
27  */\r
28 \r
29 class Phergie_Plugin_Statusnet extends Phergie_Plugin_Abstract {\r
30     /**\r
31     * Message callback details\r
32     *\r
33     * @var array\r
34     */\r
35     protected $messageCallback;\r
36 \r
37     /**\r
38     * Registration check callback details\r
39     *\r
40     * @var array\r
41     */\r
42     protected $regCallback;\r
43 \r
44     /**\r
45     * Load callback from config\r
46     */\r
47     public function onLoad() {\r
48         $messageCallback = $this->config['statusnet.messagecallback'];\r
49         if (is_callable($messageCallback)) {\r
50             $this->messageCallback = $messageCallback;\r
51         } else {\r
52             $this->messageCallback = NULL;\r
53         }\r
54 \r
55         $regCallback = $this->config['statusnet.regcallback'];\r
56         if (is_callable($regCallback)) {\r
57             $this->regCallback = $regCallback;\r
58         } else {\r
59             $this->regCallback = NULL;\r
60         }\r
61 \r
62         $this->unregRegexp = $this->config['statusnet.unregregexp'];\r
63         if (!$this->unregRegexp) {\r
64             $this->unregRegexp = '/\x02(.*?)\x02 (?:isn\'t|is not) registered/i';\r
65         }\r
66 \r
67         $this->regRegexp = $this->config['statusnet.regregexp'];\r
68         if (!$this->regRegexp) {\r
69             $this->regRegexp = '/(?:\A|\x02)(\w+?)\x02? (?:\(account|is \w+?\z)/i';\r
70         }\r
71     }\r
72 \r
73     /**\r
74      * Passes incoming messages to StatusNet\r
75      *\r
76      * @return void\r
77      */\r
78     public function onPrivmsg() {\r
79         if ($this->messageCallback !== NULL) {\r
80             $event = $this->getEvent();\r
81             $source = $event->getSource();\r
82             $message = trim($event->getText());\r
83 \r
84             call_user_func($this->messageCallback, array('sender' => $source, 'message' => $message));\r
85         }\r
86     }\r
87 \r
88     public function onNotice() {\r
89         $event = $this->getEvent();\r
90         if ($event->getNick() == 'NickServ') {\r
91             $message = $event->getArgument(1);\r
92             if (preg_match($this->unregRegexp, $message, $groups)) {\r
93                 $nick = $groups[1];\r
94                 call_user_func($this->regCallback, array('nick' => $nick, 'registered' => false));\r
95             } elseif (preg_match($this->regRegexp, $message, $groups)) {\r
96                 $nick = $groups[1];\r
97                 call_user_func($this->regCallback, array('nick' => $nick, 'registered' => true));\r
98             }\r
99         }\r
100     }\r
101 }\r