]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/command.php
Finalize move of 'repeat' Command
[quix0rs-gnu-social.git] / lib / command.php
index d15fe43ce17f2356ce18027024112202dab0a3ad..94e95f0ee993c96db83188d32226caefa08e3d32 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 require_once(INSTALLDIR.'/lib/channel.php');
 
 class Command
 {
+    protected $scoped = null;   // The Profile of the user performing the command
     var $user = null;
 
     function __construct($user=null)
     {
+        $this->scoped = $user->getProfile();
         $this->user = $user;
     }
 
@@ -274,57 +276,6 @@ class StatsCommand extends Command
     }
 }
 
-class FavCommand extends Command
-{
-    var $other = null;
-
-    function __construct($user, $other)
-    {
-        parent::__construct($user);
-        $this->other = $other;
-    }
-
-    function handle($channel)
-    {
-        $notice = $this->getNotice($this->other);
-
-        $fave            = new Fave();
-        $fave->user_id   = $this->user->id;
-        $fave->notice_id = $notice->id;
-        $fave->find();
-
-        if ($fave->fetch()) {
-            // TRANS: Error message text shown when a favorite could not be set because it has already been favorited.
-            $channel->error($this->user, _('Could not create favorite: Already favorited.'));
-            return;
-        }
-
-        $fave = Fave::addNew($this->user->getProfile(), $notice);
-
-        if (!$fave) {
-            // TRANS: Error message text shown when a favorite could not be set.
-            $channel->error($this->user, _('Could not create favorite.'));
-            return;
-        }
-
-        // @fixme favorite notification should be triggered
-        // at a lower level
-
-        $other = User::getKV('id', $notice->profile_id);
-
-        if ($other && $other->id != $this->user->id) {
-            if ($other->email && $other->emailnotifyfav) {
-                mail_notify_fave($other, $this->user, $notice);
-            }
-        }
-
-        $this->user->blowFavesCache();
-
-        // TRANS: Text shown when a notice has been marked as favourite successfully.
-        $channel->output($this->user, _('Notice marked as fave.'));
-    }
-}
-
 class JoinCommand extends Command
 {
     var $other = null;
@@ -572,105 +523,6 @@ class WhoisCommand extends Command
     }
 }
 
-class MessageCommand extends Command
-{
-    var $other = null;
-    var $text = null;
-    function __construct($user, $other, $text)
-    {
-        parent::__construct($user);
-        $this->other = $other;
-        $this->text = $text;
-    }
-
-    function handle($channel)
-    {
-        try {
-            $other = $this->getUser($this->other);
-        } catch (CommandException $e) {
-            try {
-                $profile = $this->getProfile($this->other);
-            } catch (CommandException $f) {
-                throw $e;
-            }
-            // TRANS: Command exception text shown when trying to send a direct message to a remote user (a user not registered at the current server).
-            // TRANS: %s is a remote profile.
-            throw new CommandException(sprintf(_('%s is a remote profile; you can only send direct messages to users on the same server.'), $this->other));
-        }
-
-        $len = mb_strlen($this->text);
-
-        if ($len == 0) {
-            // TRANS: Command exception text shown when trying to send a direct message to another user without content.
-            $channel->error($this->user, _('No content!'));
-            return;
-        }
-
-        $this->text = $this->user->shortenLinks($this->text);
-
-        if (Message::contentTooLong($this->text)) {
-            // XXX: i18n. Needs plural support.
-            // TRANS: Message given if content is too long. %1$sd is used for plural.
-            // TRANS: %1$d is the maximum number of characters, %2$d is the number of submitted characters.
-            $channel->error($this->user, sprintf(_m('Message too long - maximum is %1$d character, you sent %2$d.',
-                                                    'Message too long - maximum is %1$d characters, you sent %2$d.',
-                                                    Message::maxContent()),
-                                                 Message::maxContent(), mb_strlen($this->text)));
-            return;
-        }
-
-        if (!$other) {
-            // TRANS: Error text shown when trying to send a direct message to a user that does not exist.
-            $channel->error($this->user, _('No such user.'));
-            return;
-        } else if (!$this->user->mutuallySubscribed($other)) {
-            // TRANS: Error text shown when trying to send a direct message to a user without a mutual subscription (each user must be subscribed to the other).
-            $channel->error($this->user, _('You can\'t send a message to this user.'));
-            return;
-        } else if ($this->user->id == $other->id) {
-            // TRANS: Error text shown when trying to send a direct message to self.
-            $channel->error($this->user, _('Do not send a message to yourself; just say it to yourself quietly instead.'));
-            return;
-        }
-        try {
-            $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
-            $message->notify();
-            // TRANS: Message given have sent a direct message to another user.
-            // TRANS: %s is the name of the other user.
-            $channel->output($this->user, sprintf(_('Direct message to %s sent.'), $this->other));
-        } catch (Exception $e) {
-            // TRANS: Error text shown sending a direct message fails with an unknown reason.
-            $channel->error($this->user, $e->getMessage());
-        }
-    }
-}
-
-class RepeatCommand extends Command
-{
-    var $other = null;
-    function __construct($user, $other)
-    {
-        parent::__construct($user);
-        $this->other = $other;
-    }
-
-    function handle($channel)
-    {
-        $notice = $this->getNotice($this->other);
-
-        try {
-            $repeat = $notice->repeat($this->user->id, $channel->source());
-            $recipient = $notice->getProfile();
-
-            // TRANS: Message given having repeated a notice from another user.
-            // TRANS: %s is the name of the user for which the notice was repeated.
-            $channel->output($this->user, sprintf(_('Notice from %s repeated.'), $recipient->nickname));
-        } catch (Exception $e) {
-            $channel->error($this->user, $e->getMessage());
-        }
-    }
-}
-
 class ReplyCommand extends Command
 {
     var $other = null;
@@ -1034,14 +886,6 @@ class HelpCommand extends Command
                           "whois <nickname>" => _m('COMMANDHELP', "get profile info on user"),
                           // TRANS: Help message for IM/SMS command "lose <nickname>".
                           "lose <nickname>" => _m('COMMANDHELP', "force user to stop following you"),
-                          // TRANS: Help message for IM/SMS command "fav <nickname>".
-                          "fav <nickname>" => _m('COMMANDHELP', "add user's last notice as a 'fave'"),
-                          // TRANS: Help message for IM/SMS command "fav #<notice_id>".
-                          "fav #<notice_id>" => _m('COMMANDHELP', "add notice with the given id as a 'fave'"),
-                          // TRANS: Help message for IM/SMS command "repeat #<notice_id>".
-                          "repeat #<notice_id>" => _m('COMMANDHELP', "repeat a notice with a given id"),
-                          // TRANS: Help message for IM/SMS command "repeat <nickname>".
-                          "repeat <nickname>" => _m('COMMANDHELP', "repeat the last notice from user"),
                           // TRANS: Help message for IM/SMS command "reply #<notice_id>".
                           "reply #<notice_id>" => _m('COMMANDHELP', "reply to notice with a given id"),
                           // TRANS: Help message for IM/SMS command "reply <nickname>".
@@ -1087,6 +931,8 @@ class HelpCommand extends Command
 
         // Give plugins a chance to add or override...
         Event::handle('HelpCommandMessages', array($this, &$commands));
+
+        sort($commands);
         foreach ($commands as $command => $help) {
             $out[] = "$command - $help";
         }