]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/IrcPlugin.php
Use original config class as readArray was added upstream
[quix0rs-gnu-social.git] / plugins / Irc / IrcPlugin.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    Luke Fitzgerald <lw.fitzgerald@googlemail.com>
26  * @copyright 2010 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 Phergie library...
37 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/phergie');
38 require 'Phergie/Autoload.php';
39 Phergie_Autoload::registerAutoloader();
40
41 /**
42  * Plugin for IRC
43  *
44  * @category  Plugin
45  * @package   StatusNet
46  * @author    Luke Fitzgerald <lw.fitzgerald@googlemail.com>
47  * @copyright 2010 StatusNet, Inc.
48  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
49  * @link      http://status.net/
50  */
51
52 class IrcPlugin extends ImPlugin {
53     public $user =  null;
54     public $password = null;
55     public $publicFeed = array();
56
57     public $transport = 'irc';
58
59     function getDisplayName() {
60         return _m('IRC');
61     }
62
63     function normalize($screenname) {
64                 $screenname = str_replace(" ","", $screenname);
65         return strtolower($screenname);
66     }
67
68     function daemon_screenname() {
69         return $this->user;
70     }
71
72     function validate($screenname) {
73         if (preg_match('/^[a-z]\w{2,15}$/i', $screenname)) {
74             return true;
75         } else {
76             return false;
77         }
78     }
79
80     /**
81      * Load related modules when needed
82      *
83      * @param string $cls Name of the class to be loaded
84      *
85      * @return boolean hook value; true means continue processing, false means stop.
86      */
87     function onAutoload($cls) {
88         $dir = dirname(__FILE__);
89
90         switch ($cls) {
91             case 'IrcManager':
92                 include_once $dir . '/'.strtolower($cls).'.php';
93                 return false;
94             case 'Fake_Irc':
95                 include_once $dir . '/'. $cls .'.php';
96                 return false;
97             default:
98                 return true;
99         }
100     }
101
102     function onStartImDaemonIoManagers(&$classes) {
103         parent::onStartImDaemonIoManagers(&$classes);
104         $classes[] = new IrcManager($this); // handles sending/receiving
105         return true;
106     }
107
108     function microiduri($screenname) {
109         return 'irc:' . $screenname;
110     }
111
112     function send_message($screenname, $body) {
113         $this->fake_irc->sendIm($screenname, $body);
114         $this->enqueue_outgoing_raw($this->fake_irc->would_be_sent);
115         return true;
116     }
117
118     /**
119      * Accept a queued input message.
120      *
121      * @return true if processing completed, false if message should be reprocessed
122      */
123     function receive_raw_message($message) {
124         $info=Aim::getMessageInfo($message);
125         $from = $info['from'];
126         $user = $this->get_user($from);
127         $notice_text = $info['message'];
128
129         $this->handle_incoming($from, $notice_text);
130
131         return true;
132     }
133
134     function initialize() {
135         if (!isset($this->user)) {
136             throw new Exception("must specify a user");
137         }
138         if (!isset($this->password)) {
139             throw new Exception("must specify a password");
140         }
141
142         $this->fake_irc = new Fake_Irc($this->user, $this->password, 4);
143         return true;
144     }
145
146     function onPluginVersion(&$versions) {
147         $versions[] = array('name' => 'IRC',
148                             'version' => STATUSNET_VERSION,
149                             'author' => 'Luke Fitzgerald',
150                             'homepage' => 'http://status.net/wiki/Plugin:IRC',
151                             'rawdescription' =>
152                             _m('The IRC plugin allows users to send and receive notices over an IRC network.'));
153         return true;
154     }
155 }