3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2009, StatusNet, Inc.
6 * Send and receive notices using the AIM network
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.
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.
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/>.
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/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
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();
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/
52 class IrcPlugin extends ImPlugin {
54 public $password = null;
55 public $publicFeed = array();
57 public $transport = 'irc';
59 function getDisplayName() {
63 function normalize($screenname) {
64 $screenname = str_replace(" ","", $screenname);
65 return strtolower($screenname);
68 function daemon_screenname() {
72 function validate($screenname) {
73 if (preg_match('/^[a-z]\w{2,15}$/i', $screenname)) {
81 * Load related modules when needed
83 * @param string $cls Name of the class to be loaded
85 * @return boolean hook value; true means continue processing, false means stop.
87 function onAutoload($cls) {
88 $dir = dirname(__FILE__);
92 include_once $dir . '/'.strtolower($cls).'.php';
95 include_once $dir . '/'. $cls .'.php';
102 function onStartImDaemonIoManagers(&$classes) {
103 parent::onStartImDaemonIoManagers(&$classes);
104 $classes[] = new IrcManager($this); // handles sending/receiving
108 function microiduri($screenname) {
109 return 'irc:' . $screenname;
112 function send_message($screenname, $body) {
113 $this->fake_irc->sendIm($screenname, $body);
114 $this->enqueue_outgoing_raw($this->fake_irc->would_be_sent);
119 * Accept a queued input message.
121 * @return true if processing completed, false if message should be reprocessed
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'];
129 $this->handle_incoming($from, $notice_text);
134 function initialize() {
135 if (!isset($this->user)) {
136 throw new Exception("must specify a user");
138 if (!isset($this->password)) {
139 throw new Exception("must specify a password");
142 $this->fake_irc = new Fake_Irc($this->user, $this->password, 4);
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',
152 _m('The IRC plugin allows users to send and receive notices over an IRC network.'));