]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
tag / untag commands for people tags
authorShashi Gowda <connect2shashi@gmail.com>
Sun, 6 Mar 2011 19:16:42 +0000 (00:46 +0530)
committerShashi Gowda <connect2shashi@gmail.com>
Sun, 6 Mar 2011 19:16:42 +0000 (00:46 +0530)
lib/command.php
lib/commandinterpreter.php

index 39fb283dd87d82bbc02b02dcc30647fa1fde853b..750b1c88a26808f688474d4490930dafd8049ce7 100644 (file)
@@ -420,6 +420,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;
@@ -919,6 +1017,8 @@ class HelpCommand extends Command
                            "help - show this help\n".
                            "follow <nickname> - subscribe to user\n".
                            "groups - lists the groups you have joined\n".
+                           "tag <nickname> <tags> - tag a user\n".
+                           "untag <nickname> <tags> - untag a user\n".
                            "subscriptions - list the people you follow\n".
                            "subscribers - list the people that follow you\n".
                            "leave <nickname> - unsubscribe from user\n".
index fe426f1fcd3a41f6b4a6515a2fcaaf10079f561e..9aaa8228c7f3eaf4e5b3b45b2fb85420a5f6cec4 100644 (file)
@@ -274,6 +274,32 @@ class CommandInterpreter
                     }
                 }
                 break;
+             case 'list':
+             case 'tag':
+                if (!$arg) {
+                    $result = null;
+                    break;
+                }
+                list($other, $tags) = $this->split_arg($arg);
+                if (!$tags) {
+                    $result = null;
+                } else {
+                    $result = new TagCommand($user, $other, $tags);
+                }
+                break;
+             case 'unlist':
+             case 'untag':
+                if (!$arg) {
+                    $result = null;
+                    break;
+                }
+                list($other, $tags) = $this->split_arg($arg);
+                if (!$tags) {
+                    $result = null;
+                } else {
+                    $result = new UntagCommand($user, $other, $tags);
+                }
+                break;
             case 'track':
                 if (!$arg) {
                     $result = null;