]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/command.php
More Favorite pluginification (favecount, cache, menus(favecount, cache, menus))
[quix0rs-gnu-social.git] / lib / command.php
index fcc21cc5e55d4642ae6467985ed254a5924e60cd..02324280baec871a361c7700e591cb6d1c3f931b 100644 (file)
@@ -23,10 +23,12 @@ 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;
     }
 
@@ -76,7 +78,7 @@ class Command
             if(substr($this->other,0,1)=='#'){
                 // A specific notice_id #123
 
-                $notice = Notice::staticGet(substr($arg,1));
+                $notice = Notice::getKV(substr($arg,1));
                 if (!$notice) {
                     // TRANS: Command exception text shown when a notice ID is requested that does not exist.
                     throw new CommandException(_('Notice with that id does not exist.'));
@@ -85,7 +87,7 @@ class Command
 
             if (Validate::uri($this->other)) {
                 // A specific notice by URI lookup
-                $notice = Notice::staticGet('uri', $arg);
+                $notice = Notice::getKV('uri', $arg);
             }
 
             if (!$notice) {
@@ -139,7 +141,7 @@ class Command
     {
         $user = null;
         if (Event::handle('StartCommandGetUser', array($this, $arg, &$user))) {
-            $user = User::staticGet('nickname', Nickname::normalize($arg));
+            $user = User::getKV('nickname', Nickname::normalize($arg));
         }
         Event::handle('EndCommandGetUser', array($this, $arg, &$user));
         if (!$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::staticGet('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;
@@ -586,7 +537,7 @@ class MessageCommand extends Command
     function handle($channel)
     {
         try {
-            $other = $this->getUser($this->other);
+            $other = $this->getUser($this->other)->getProfile();
         } catch (CommandException $e) {
             try {
                 $profile = $this->getProfile($this->other);
@@ -619,7 +570,7 @@ class MessageCommand extends Command
             return;
         }
 
-        if (!$other) {
+        if (!$other instanceof Profile) {
             // 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;
@@ -629,18 +580,18 @@ class MessageCommand extends Command
             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, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
+            $channel->error($this->user, _('Do not send a message to yourself; just say it to yourself quietly instead.'));
             return;
         }
-        $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
-        if ($message) {
+        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));
-        } else {
+        } catch (Exception $e) {
             // TRANS: Error text shown sending a direct message fails with an unknown reason.
-            $channel->error($this->user, _('Error sending direct message.'));
+            $channel->error($this->user, $e->getMessage());
         }
     }
 }
@@ -659,7 +610,7 @@ class RepeatCommand extends Command
         $notice = $this->getNotice($this->other);
 
         try {
-            $repeat = $notice->repeat($this->user->id, $channel->source());
+            $repeat = $notice->repeat($this->scoped->id, $channel->source());
             $recipient = $notice->getProfile();
 
             // TRANS: Message given having repeated a notice from another user.
@@ -770,15 +721,8 @@ class SubCommand extends Command
 
         $target = $this->getProfile($this->other);
 
-        $remote = Remote_profile::staticGet('id', $target->id);
-        if ($remote) {
-            // TRANS: Command exception text shown when trying to subscribe to an OMB profile using the subscribe command.
-            throw new CommandException(_("Can't subscribe to OMB profiles by command."));
-        }
-
         try {
-            Subscription::start($this->user->getProfile(),
-                                $target);
+            Subscription::start($this->user->getProfile(), $target);
             // TRANS: Text shown after having subscribed to another user successfully.
             // TRANS: %s is the name of the user the subscription was requested for.
             $channel->output($this->user, sprintf(_('Subscribed to %s.'), $this->other));
@@ -809,8 +753,7 @@ class UnsubCommand extends Command
         $target = $this->getProfile($this->other);
 
         try {
-            Subscription::cancel($this->user->getProfile(),
-                                 $target);
+            Subscription::cancel($this->user->getProfile(), $target);
             // TRANS: Text shown after having unsubscribed from another user successfully.
             // TRANS: %s is the name of the user the unsubscription was requested for.
             $channel->output($this->user, sprintf(_('Unsubscribed from %s.'), $this->other));
@@ -933,7 +876,7 @@ class SubscriptionsCommand extends Command
 {
     function handle($channel)
     {
-        $profile = $this->user->getSubscriptions(0);
+        $profile = $this->user->getSubscribed(0);
         $nicknames=array();
         while ($profile->fetch()) {
             $nicknames[]=$profile->nickname;
@@ -988,7 +931,7 @@ class GroupsCommand extends Command
     {
         $group = $this->user->getGroups();
         $groups=array();
-        while ($group->fetch()) {
+        while ($group instanceof User_group && $group->fetch()) {
             $groups[]=$group->nickname;
         }
         if(count($groups)==0){
@@ -1042,10 +985,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>".
@@ -1095,6 +1034,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";
         }