]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/command.php
Merge remote-tracking branch 'mainline/1.0.x' into people_tags_rebase
[quix0rs-gnu-social.git] / lib / command.php
index 03baa8212d998a569b1125be893a4b2030d4d771..a922aa73ac57b66091551c00b843598ca8d6895e 100644 (file)
@@ -352,10 +352,7 @@ class JoinCommand extends Command
         }
 
         try {
-            if (Event::handle('StartJoinGroup', array($group, $cur))) {
-                Group_member::join($group->id, $cur->id);
-                Event::handle('EndJoinGroup', array($group, $cur));
-            }
+            $cur->joinGroup($group);
         } catch (Exception $e) {
             // TRANS: Message given having failed to add a user to a group.
             // TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group.
@@ -400,10 +397,7 @@ class DropCommand extends Command
         }
 
         try {
-            if (Event::handle('StartLeaveGroup', array($group, $cur))) {
-                Group_member::leave($group->id, $cur->id);
-                Event::handle('EndLeaveGroup', array($group, $cur));
-            }
+            $cur->leaveGroup($group);
         } catch (Exception $e) {
             // TRANS: Message given having failed to remove a user from a group.
             // TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group.
@@ -420,6 +414,104 @@ class DropCommand extends Command
     }
 }
 
+class TagCommand extends Command
+{
+    var $other = null;
+    var $tags = null;
+    function __construct($user, $other, $tags)
+    {
+        parent::__construct($user);
+        $this->other = $other;
+        $this->tags = $tags;
+    }
+
+    function handle($channel)
+    {
+        $profile = $this->getProfile($this->other);
+        $cur     = $this->user->getProfile();
+
+        if (!$profile) {
+            $channel->error($cur, _('No such profile.'));
+            return;
+        }
+        if (!$cur->canTag($profile)) {
+            $channel->error($cur, _('You cannot tag this user.'));
+            return;
+        }
+
+        $privs = array();
+        $tags = preg_split('/[\s,]+/', $this->tags);
+        $clean_tags = array();
+
+        foreach ($tags as $tag) {
+            $private = @$tag[0] === '.';
+            $tag = $clean_tags[] = common_canonical_tag($tag);
+
+            if (!common_valid_profile_tag($tag)) {
+                $channel->error($cur, sprintf(_('Invalid tag: "%s"'), $tag));
+                return;
+            }
+            $privs[$tag] = $private;
+        }
+
+        try {
+            foreach ($clean_tags as $tag) {
+                Profile_tag::setTag($cur->id, $profile->id, $tag, null, $privs[$tag]);
+            }
+        } catch (Exception $e) {
+            $channel->error($cur, sprintf(_('Error tagging %s: %s'),
+                                          $profile->nickname, $e->getMessage()));
+            return;
+        }
+
+        $channel->output($cur, sprintf(_('%1$s was tagged %2$s'),
+                                              $profile->nickname,
+                                              implode(', ', $clean_tags)));
+    }
+}
+
+
+class UntagCommand extends TagCommand
+{
+    function handle($channel)
+    {
+        $profile = $this->getProfile($this->other);
+        $cur     = $this->user->getProfile();
+
+        if (!$profile) {
+            $channel->error($cur, _('No such profile.'));
+            return;
+        }
+        if (!$cur->canTag($profile)) {
+            $channel->error($cur, _('You cannot tag this user.'));
+            return;
+        }
+
+        $tags = array_map('common_canonical_tag', preg_split('/[\s,]+/', $this->tags));
+
+        foreach ($tags as $tag) {
+            if (!common_valid_profile_tag($tag)) {
+                $channel->error($cur, sprintf(_('Invalid tag: "%s"'), $tag));
+                return;
+            }
+        }
+
+        try {
+            foreach ($tags as $tag) {
+                Profile_tag::unTag($cur->id, $profile->id, $tag);
+            }
+        } catch (Exception $e) {
+            $channel->error($cur, sprintf(_('Error untagging %s: %s'),
+                                          $profile->nickname, $e->getMessage()));
+            return;
+        }
+
+        $channel->output($cur, sprintf(_('The following tag(s) were removed from user %1$s: %2$s.'),
+                                              $profile->nickname,
+                                              implode(', ', $tags)));
+    }
+}
+
 class WhoisCommand extends Command
 {
     var $other = null;
@@ -543,29 +635,15 @@ class RepeatCommand extends Command
     {
         $notice = $this->getNotice($this->other);
 
-        if($this->user->id == $notice->profile_id)
-        {
-            // TRANS: Error text shown when trying to repeat an own notice.
-            $channel->error($this->user, _('Cannot repeat your own notice.'));
-            return;
-        }
-
-        if ($this->user->getProfile()->hasRepeated($notice->id)) {
-            // TRANS: Error text shown when trying to repeat an notice that was already repeated by the user.
-            $channel->error($this->user, _('Already repeated that notice.'));
-            return;
-        }
-
-        $repeat = $notice->repeat($this->user->id, $channel->source);
-
-        if ($repeat) {
+        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));
-        } else {
-            // TRANS: Error text shown when repeating a notice fails with an unknown reason.
-            $channel->error($this->user, _('Error repeating notice.'));
+        } catch (Exception $e) {
+            $channel->error($this->user, $e->getMessage());
         }
     }
 }
@@ -844,7 +922,7 @@ class SubscriptionsCommand extends Command
             // TRANS: Text shown after requesting other users a user is subscribed to.
             // TRANS: This message supports plural forms. This message is followed by a
             // TRANS: hard coded space and a comma separated list of subscribed users.
-            $out = ngettext('You are subscribed to this person:',
+            $out = _m('You are subscribed to this person:',
                 'You are subscribed to these people:',
                 count($nicknames));
             $out .= ' ';
@@ -871,7 +949,7 @@ class SubscribersCommand extends Command
             // TRANS: Text shown after requesting other users that are subscribed to a user (followers).
             // TRANS: This message supports plural forms. This message is followed by a
             // TRANS: hard coded space and a comma separated list of subscribing users.
-            $out = ngettext('This person is subscribed to you:',
+            $out = _m('This person is subscribed to you:',
                 'These people are subscribed to you:',
                 count($nicknames));
             $out .= ' ';
@@ -898,7 +976,7 @@ class GroupsCommand extends Command
             // TRANS: Text shown after requesting groups a user is subscribed to.
             // TRANS: This message supports plural forms. This message is followed by a
             // TRANS: hard coded space and a comma separated list of subscribed groups.
-            $out = ngettext('You are a member of this group:',
+            $out = _m('You are a member of this group:',
                 'You are a member of these groups:',
                 count($nicknames));
             $out.=implode(', ',$groups);
@@ -923,6 +1001,10 @@ class HelpCommand extends Command
                           "follow <nickname>" => _m('COMMANDHELP', "subscribe to user"),
                           // TRANS: Help message for IM/SMS command "groups"
                           "groups" => _m('COMMANDHELP', "lists the groups you have joined"),
+                          // TRANS: Help message for IM/SMS command "tag"
+                          "tag <nickname> <tags>" => _m('COMMANDHELP',"tag a user"),
+                          // TRANS: Help message for IM/SMS command "untag"
+                          "untag <nickname> <tags>" => _m('COMMANDHELP',"untag a user"),
                           // TRANS: Help message for IM/SMS command "subscriptions"
                           "subscriptions" => _m('COMMANDHELP', "list the people you follow"),
                           // TRANS: Help message for IM/SMS command "subscribers"