]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Irc/IrcPlugin.php
Fixed type hints:
[quix0rs-gnu-social.git] / plugins / Irc / IrcPlugin.php
index 75eaf687b265bc354b6f0298279aadee415bd6bc..99dc4b2bc125e54e22b86b6e4beca3fded6cf301 100644 (file)
@@ -47,7 +47,6 @@ set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/ext
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  * @link      http://status.net/
  */
-
 class IrcPlugin extends ImPlugin {
     public $host =  null;
     public $port = null;
@@ -60,14 +59,15 @@ class IrcPlugin extends ImPlugin {
     public $channels = null;
     public $transporttype = null;
     public $encoding = null;
+    public $pinginterval = null;
 
     public $regcheck = null;
     public $unregregexp = null;
     public $regregexp = null;
 
     public $transport = 'irc';
-    public $whiteList;
-    public $fake_irc;
+    protected $whiteList;
+    protected $fake_irc;
 
     /**
      * Get the internationalized/translated display name of this IM service
@@ -75,14 +75,15 @@ class IrcPlugin extends ImPlugin {
      * @return string Name of service
      */
     public function getDisplayName() {
+        // TRANS: Service name for IRC.
         return _m('IRC');
     }
 
     /**
      * Normalize a screenname for comparison
      *
-     * @param string $screenname screenname to normalize
-     * @return string an equivalent screenname in normalized form
+     * @param string $screenname Screenname to normalize
+     * @return string An equivalent screenname in normalized form
      */
     public function normalize($screenname) {
         $screenname = str_replace(" ","", $screenname);
@@ -94,15 +95,15 @@ class IrcPlugin extends ImPlugin {
      *
      * @return string Screenname
      */
-    public function daemon_screenname() {
+    public function daemonScreenname() {
         return $this->nick;
     }
 
     /**
      * Validate (ensure the validity of) a screenname
      *
-     * @param string $screenname screenname to validate
-     * @return boolean
+     * @param string $screenname Screenname to validate
+     * @return boolean true if screenname is valid
      */
     public function validate($screenname) {
         if (preg_match('/\A[a-z0-9\-_]{1,1000}\z/i', $screenname)) {
@@ -119,40 +120,43 @@ class IrcPlugin extends ImPlugin {
      * @return boolean hook value; true means continue processing, false means stop.
      */
     public function onAutoload($cls) {
-        $dir = dirname(__FILE__);
-
-        switch ($cls) {
-            case 'IrcManager':
-                include_once $dir . '/'.strtolower($cls).'.php';
-                return false;
-            case 'Fake_Irc':
-            case 'ChannelResponseChannel':
-                include_once $dir . '/'. $cls .'.php';
-                return false;
-            default:
-                if (substr($cls, 0, 7) == 'Phergie') {
-                    include_once str_replace('_', DIRECTORY_SEPARATOR, $cls) . '.php';
-                    return false;
-                }
-                return true;
+        // in the beginning of this file, we have added an include path
+        if (substr($cls, 0, 7) == 'Phergie') {
+            include_once str_replace('_', DIRECTORY_SEPARATOR, $cls) . '.php';
+            return false;
         }
+
+        return parent::onAutoload($cls);
     }
 
     /*
      * Start manager on daemon start
      *
+     * @param array &$versions Array to insert manager into
      * @return boolean
      */
     public function onStartImDaemonIoManagers(&$classes) {
-        parent::onStartImDaemonIoManagers(&$classes);
+        parent::onStartImDaemonIoManagers($classes);
         $classes[] = new IrcManager($this); // handles sending/receiving
         return true;
     }
 
+    /**
+    * Ensure the database table is present
+    *
+    */
+    public function onCheckSchema() {
+        $schema = Schema::get();
+
+        // For storing messages while sessions become ready
+        $schema->ensureTable('irc_waiting_message', Irc_waiting_message::schemaDef());
+        return true;
+    }
+
     /**
     * Get a microid URI for the given screenname
     *
-    * @param string $screenname
+    * @param string $screenname Screenname
     * @return string microid URI
     */
     public function microiduri($screenname) {
@@ -164,13 +168,13 @@ class IrcPlugin extends ImPlugin {
      *
      * @param string $screenname Screenname to send to
      * @param string $body Text to send
-     * @return boolean success value
+     * @return boolean true on success
      */
-    public function send_message($screenname, $body) {
+    public function sendMessage($screenname, $body) {
         $lines = explode("\n", $body);
         foreach ($lines as $line) {
             $this->fake_irc->doPrivmsg($screenname, $line);
-            $this->enqueue_outgoing_raw(array('type' => 'message', 'data' => $this->fake_irc->would_be_sent));
+            $this->enqueueOutgoingRaw(array('type' => 'message', 'prioritise' => 0, 'data' => $this->fake_irc->would_be_sent));
         }
         return true;
     }
@@ -178,9 +182,9 @@ class IrcPlugin extends ImPlugin {
     /**
      * Accept a queued input message.
      *
-     * @return true if processing completed, false if message should be reprocessed
+     * @return boolean true if processing completed, false if message should be reprocessed
      */
-    public function receive_raw_message($data) {
+    public function receiveRawMessage($data) {
         if (strpos($data['source'], '#') === 0) {
             $message = $data['message'];
             $parts = explode(' ', $message, 2);
@@ -188,22 +192,31 @@ class IrcPlugin extends ImPlugin {
             if (in_array($command, $this->whiteList)) {
                 $this->handle_channel_incoming($data['sender'], $data['source'], $message);
             } else {
-                $this->handle_incoming($data['sender'], $message);
+                $this->handleIncoming($data['sender'], $message);
             }
         } else {
-            $this->handle_incoming($data['sender'], $data['message']);
+            $this->handleIncoming($data['sender'], $data['message']);
         }
         return true;
     }
 
+    /**
+     * Helper for handling incoming messages from a channel requiring response
+     * to the channel instead of via PM
+     *
+     * @param string $nick Screenname the message was sent from
+     * @param string $channel Channel the message originated from
+     * @param string $message Message text
+     * @param boolean true on success
+     */
     protected function handle_channel_incoming($nick, $channel, $notice_text) {
-        $user = $this->get_user($nick);
+        $user = $this->getUser($nick);
         // For common_current_user to work
         global $_cur;
         $_cur = $user;
 
         if (!$user) {
-            $this->send_from_site($nick, 'Unknown user; go to ' .
+            $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);
@@ -212,15 +225,15 @@ class IrcPlugin extends ImPlugin {
         if ($this->handle_channel_command($user, $channel, $notice_text)) {
             common_log(LOG_INFO, "Command message by $nick handled.");
             return;
-        } else if ($this->is_autoreply($notice_text)) {
+        } else if ($this->isAutoreply($notice_text)) {
             common_log(LOG_INFO, 'Ignoring auto reply from ' . $nick);
             return;
-        } else if ($this->is_otr($notice_text)) {
+        } 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->add_notice($nick, $user, $notice_text);
+            $this->addNotice($nick, $user, $notice_text);
         }
 
         $user->free();
@@ -232,9 +245,9 @@ class IrcPlugin extends ImPlugin {
     /**
      * Attempt to handle a message from a channel as a command
      *
-     * @param User $user user the message is from
+     * @param User $user User the message is from
      * @param string $channel Channel the message originated from
-     * @param string $body message text
+     * @param string $body Message text
      * @return boolean true if the message was a command and was executed, false if it was not a command
      */
     protected function handle_channel_command($user, $channel, $body) {
@@ -257,19 +270,22 @@ class IrcPlugin extends ImPlugin {
      * @param User $user user sending to
      * @return boolean success value
      */
-    public function send_confirmation_code($screenname, $code, $user, $checked = false) {
-        $body = sprintf(_('User "%s" on %s has said that your %s screenname belongs to them. ' .
+    public function sendConfirmationCode($screenname, $code, $user, $checked = false) {
+        // TRANS: Body text for e-mail confirmation message for IRC.
+        // TRANS: %1$s is a user nickname, %2$s is the StatusNet sitename,
+        // TRANS: %3$s is the plugin display name ("IRC"), %4$s is the confirm address URL.
+        $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: ' .
-          '%s' .
+          '%4$s' .
           ' . (If you cannot click it, copy-and-paste it into the ' .
-          'address bar of your browser). If that user isn\'t you, ' .
-          'or if you didn\'t request this confirmation, just ignore this message.'),
+          '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_send_confirmation_code($screenname, $code, $user);
+            return $this->checked_sendConfirmationCode($screenname, $code, $user);
         } else {
-            return $this->send_message($screenname, $body);
+            return $this->sendMessage($screenname, $body);
         }
     }
 
@@ -277,16 +293,17 @@ class IrcPlugin extends ImPlugin {
     * Only sends the confirmation message if the nick is
     * registered
     *
-    * @param string $screenname screenname sending to
-    * @param string $code the confirmation code
-    * @param User $user user sending to
-    * @return boolean success value
+    * @param string $screenname Screenname sending to
+    * @param string $code The confirmation code
+    * @param User $user User sending to
+    * @return boolean true on succes
     */
-    public function checked_send_confirmation_code($screenname, $code, $user) {
+    public function checked_sendConfirmationCode($screenname, $code, $user) {
         $this->fake_irc->doPrivmsg('NickServ', 'INFO '.$screenname);
-        $this->enqueue_outgoing_raw(
+        $this->enqueueOutgoingRaw(
             array(
                 'type' => 'nickcheck',
+                'prioritise' => 1,
                 'data' => $this->fake_irc->would_be_sent,
                 'nickdata' =>
                     array(
@@ -306,16 +323,20 @@ class IrcPlugin extends ImPlugin {
     */
     public function initialize() {
         if (!isset($this->host)) {
-            throw new Exception('must specify a host');
+            // TRANS: Exception thrown when initialising the IRC plugin fails because of an incorrect configuration.
+            throw new Exception(_m('You must specify a host.'));
         }
         if (!isset($this->username)) {
-            throw new Exception('must specify a username');
+            // TRANS: Exception thrown when initialising the IRC plugin fails because of an incorrect configuration.
+            throw new Exception(_m('You must specify a username.'));
         }
         if (!isset($this->realname)) {
-            throw new Exception('must specify a "real name"');
+            // TRANS: Exception thrown when initialising the IRC plugin fails because of an incorrect configuration.
+            throw new Exception(_m('You must specify a "real name".'));
         }
         if (!isset($this->nick)) {
-            throw new Exception('must specify a nickname');
+            // TRANS: Exception thrown when initialising the IRC plugin fails because of an incorrect configuration.
+            throw new Exception(_m('You must specify a nickname.'));
         }
 
         if (!isset($this->port)) {
@@ -327,12 +348,15 @@ class IrcPlugin extends ImPlugin {
         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 Fake_Irc;
+        $this->fake_irc = new FakeIrc;
 
         /*
          * Commands allowed to return output to a channel
@@ -345,15 +369,16 @@ class IrcPlugin extends ImPlugin {
     /**
      * Get plugin information
      *
-     * @param array $versions array to insert information into
+     * @param array $versions Array to insert information into
      * @return void
      */
-    public function onPluginVersion(&$versions) {
+    public function onPluginVersion(array &$versions) {
         $versions[] = array('name' => 'IRC',
-                            'version' => STATUSNET_VERSION,
+                            'version' => GNUSOCIAL_VERSION,
                             'author' => 'Luke Fitzgerald',
                             'homepage' => 'http://status.net/wiki/Plugin:IRC',
                             'rawdescription' =>
+                            // TRANS: Plugin description.
                             _m('The IRC plugin allows users to send and receive notices over an IRC network.'));
         return true;
     }