]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Phergie/Plugin/Statusnet.php
Lots more work - Implemented nickname checking
[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     protected $regCallback;\r
38 \r
39     protected $tocheck = array();\r
40 \r
41     /**\r
42     * Load callback from config\r
43     */\r
44     public function onLoad() {\r
45         $messageCallback = $this->config['statusnet.messagecallback'];\r
46         if (is_callable($messageCallback)) {\r
47             $this->messageCallback = $messageCallback;\r
48         } else {\r
49             $this->messageCallback = NULL;\r
50         }\r
51 \r
52         $regCallback = $this->config['statusnet.regcallback'];\r
53         if (is_callable($regCallback)) {\r
54             $this->regCallback = $regCallback;\r
55         } else {\r
56             $this->regCallback = NULL;\r
57         }\r
58 \r
59         $this->unregRegexp = $this->config['statusnet.unregregexp'];\r
60         if (!$this->unregRegexp) {\r
61             $this->unregRegexp = '/\x02(.*?)\x02 (?:isn\'t|is not) registered/i';\r
62         }\r
63 \r
64         $this->regRegexp = $this->config['statusnet.regregexp'];\r
65         if (!$this->regRegexp) {\r
66             $this->regRegexp = '/(?:\A|\x02)(\w+?)\x02? (?:\(account|is \w+?\z)/i';\r
67         }\r
68     }\r
69 \r
70     /**\r
71      * Passes incoming messages to StatusNet\r
72      *\r
73      * @return void\r
74      */\r
75     public function onPrivmsg() {\r
76         if ($this->messageCallback !== NULL) {\r
77             $event = $this->getEvent();\r
78             $source = $event->getSource();\r
79             $message = trim($event->getText());\r
80 \r
81             call_user_func($this->messageCallback, array('sender' => $source, 'message' => $message));\r
82         }\r
83     }\r
84 \r
85     public function onNotice() {\r
86         $event = $this->getEvent();\r
87         if ($event->getNick() == 'NickServ') {\r
88             $message = $event->getArgument(1);\r
89             if (preg_match($this->unregRegexp, $message, $groups)) {\r
90                 $nick = $groups[1];\r
91                 call_user_func($this->regCallback, array('nick' => $nick, 'registered' => false));\r
92             } elseif (preg_match($this->regRegexp, $message, $groups)) {\r
93                 $nick = $groups[1];\r
94                 call_user_func($this->regCallback, array('nick' => $nick, 'registered' => true));\r
95             }\r
96         }\r
97     }\r
98 }\r