123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- <?php
- if (!defined('STATUSNET')) {
-
-
- exit(1);
- }
- set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/phergie');
- class IrcPlugin extends ImPlugin {
- public $host = null;
- public $port = null;
- public $username = null;
- public $realname = null;
- public $nick = null;
- public $password = null;
- public $nickservidentifyregexp = null;
- public $nickservpassword = null;
- public $channels = null;
- public $transporttype = null;
- public $encoding = null;
- public $pinginterval = null;
- public $regcheck = null;
- public $unregregexp = null;
- public $regregexp = null;
- public $transport = 'irc';
- protected $whiteList;
- protected $fake_irc;
-
- public function getDisplayName() {
-
- return _m('IRC');
- }
-
- public function normalize($screenname) {
- $screenname = str_replace(" ","", $screenname);
- return strtolower($screenname);
- }
-
- public function daemonScreenname() {
- return $this->nick;
- }
-
- public function validate($screenname) {
- if (preg_match('/\A[a-z0-9\-_]{1,1000}\z/i', $screenname)) {
- return true;
- } else {
- return false;
- }
- }
-
- public function onAutoload($cls) {
-
- if (substr($cls, 0, 7) == 'Phergie') {
- include_once str_replace('_', DIRECTORY_SEPARATOR, $cls) . '.php';
- return false;
- }
- return parent::onAutoload($cls);
- }
-
- public function onStartImDaemonIoManagers(&$classes) {
- parent::onStartImDaemonIoManagers($classes);
- $classes[] = new IrcManager($this);
- return true;
- }
-
- public function onCheckSchema() {
- $schema = Schema::get();
-
- $schema->ensureTable('irc_waiting_message', Irc_waiting_message::schemaDef());
- return true;
- }
-
- public function microiduri($screenname) {
- return 'irc:' . $screenname;
- }
-
- public function sendMessage($screenname, $body) {
- $lines = explode("\n", $body);
- foreach ($lines as $line) {
- $this->fake_irc->doPrivmsg($screenname, $line);
- $this->enqueueOutgoingRaw(array('type' => 'message', 'prioritise' => 0, 'data' => $this->fake_irc->would_be_sent));
- }
- return true;
- }
-
- public function receiveRawMessage($data) {
- if (strpos($data['source'], '#') === 0) {
- $message = $data['message'];
- $parts = explode(' ', $message, 2);
- $command = $parts[0];
- if (in_array($command, $this->whiteList)) {
- $this->handle_channel_incoming($data['sender'], $data['source'], $message);
- } else {
- $this->handleIncoming($data['sender'], $message);
- }
- } else {
- $this->handleIncoming($data['sender'], $data['message']);
- }
- return true;
- }
-
- protected function handle_channel_incoming($nick, $channel, $notice_text) {
- $user = $this->getUser($nick);
-
- global $_cur;
- $_cur = $user;
- if (!$user) {
- $this->sendFromSite($nick, 'Unknown user; go to ' .
- common_local_url('imsettings') .
- ' to add your address to your account');
- common_log(LOG_WARNING, 'Message from unknown user ' . $nick);
- return;
- }
- if ($this->handle_channel_command($user, $channel, $notice_text)) {
- common_log(LOG_INFO, "Command message by $nick handled.");
- return;
- } else if ($this->isAutoreply($notice_text)) {
- common_log(LOG_INFO, 'Ignoring auto reply from ' . $nick);
- return;
- } else if ($this->isOtr($notice_text)) {
- common_log(LOG_INFO, 'Ignoring OTR from ' . $nick);
- return;
- } else {
- common_log(LOG_INFO, 'Posting a notice from ' . $user->nickname);
- $this->addNotice($nick, $user, $notice_text);
- }
- $user->free();
- unset($user);
- unset($_cur);
- unset($message);
- }
-
- protected function handle_channel_command($user, $channel, $body) {
- $inter = new CommandInterpreter();
- $cmd = $inter->handle_command($user, $body);
- if ($cmd) {
- $chan = new ChannelResponseChannel($this, $channel);
- $cmd->execute($chan);
- return true;
- } else {
- return false;
- }
- }
-
- public function sendConfirmationCode($screenname, $code, $user, $checked = false) {
-
-
-
- $body = sprintf(_m('User "%1$s" on %2$s has said that your %3$s screenname belongs to them. ' .
- 'If that\'s true, you can confirm by clicking on this URL: ' .
- '%4$s' .
- ' . (If you cannot click it, copy-and-paste it into the ' .
- 'address bar of your browser). If that user is not you, ' .
- 'or if you did not request this confirmation, just ignore this message.'),
- $user->nickname, common_config('site', 'name'), $this->getDisplayName(), common_local_url('confirmaddress', array('code' => $code)));
- if ($this->regcheck && !$checked) {
- return $this->checked_sendConfirmationCode($screenname, $code, $user);
- } else {
- return $this->sendMessage($screenname, $body);
- }
- }
-
- public function checked_sendConfirmationCode($screenname, $code, $user) {
- $this->fake_irc->doPrivmsg('NickServ', 'INFO '.$screenname);
- $this->enqueueOutgoingRaw(
- array(
- 'type' => 'nickcheck',
- 'prioritise' => 1,
- 'data' => $this->fake_irc->would_be_sent,
- 'nickdata' =>
- array(
- 'screenname' => $screenname,
- 'code' => $code,
- 'user' => $user
- )
- )
- );
- return true;
- }
-
- public function initialize() {
- if (!isset($this->host)) {
-
- throw new Exception(_m('You must specify a host.'));
- }
- if (!isset($this->username)) {
-
- throw new Exception(_m('You must specify a username.'));
- }
- if (!isset($this->realname)) {
-
- throw new Exception(_m('You must specify a "real name".'));
- }
- if (!isset($this->nick)) {
-
- throw new Exception(_m('You must specify a nickname.'));
- }
- if (!isset($this->port)) {
- $this->port = 6667;
- }
- if (!isset($this->transporttype)) {
- $this->transporttype = 'tcp';
- }
- if (!isset($this->encoding)) {
- $this->encoding = 'UTF-8';
- }
- if (!isset($this->pinginterval)) {
- $this->pinginterval = 120;
- }
- if (!isset($this->regcheck)) {
- $this->regcheck = true;
- }
- $this->fake_irc = new FakeIrc;
-
- $this->whiteList = array('stats', 'last', 'get');
- return true;
- }
-
- public function onPluginVersion(&$versions) {
- $versions[] = array('name' => 'IRC',
- 'version' => GNUSOCIAL_VERSION,
- 'author' => 'Luke Fitzgerald',
- 'homepage' => 'http://status.net/wiki/Plugin:IRC',
- 'rawdescription' =>
-
- _m('The IRC plugin allows users to send and receive notices over an IRC network.'));
- return true;
- }
- }
|