]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/commandinterpreter.php
Misses this file to merge. I like the comments.
[quix0rs-gnu-social.git] / lib / commandinterpreter.php
index f2caf48bdb47d5ff9cf01714429c3002bdb17234..d2b744e93d79c41554dc2788277efcc7f3f6883c 100644 (file)
@@ -28,7 +28,7 @@ class CommandInterpreter
         // XXX: localise
 
         $text = preg_replace('/\s+/', ' ', trim($text));
-        list($cmd, $arg) = $this->split_arg($text);
+        list($cmd, $arg) = self::split_arg($text);
 
         // We try to support all the same commands as Twitter, see
         // http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands
@@ -37,13 +37,14 @@ class CommandInterpreter
 
         $cmd = strtolower($cmd);
 
-        if (Event::handle('StartIntepretCommand', array($cmd, $arg, $user, &$result))) {
+        if (Event::handle('StartInterpretCommand', array($cmd, $arg, $user, &$result))) {
             switch($cmd) {
             case 'help':
                 if ($arg) {
                     $result = null;
+                } else {
+                    $result = new HelpCommand($user);
                 }
-                $result = new HelpCommand($user);
                 break;
             case 'login':
                 if ($arg) {
@@ -54,7 +55,7 @@ class CommandInterpreter
                 break;
             case 'lose':
                 if ($arg) {
-                    list($other, $extra) = $this->split_arg($arg);
+                    list($other, $extra) = self::split_arg($arg);
                     if ($extra) {
                         $result = null;
                     } else {
@@ -87,7 +88,7 @@ class CommandInterpreter
                 break;
             case 'on':
                 if ($arg) {
-                    list($other, $extra) = $this->split_arg($arg);
+                    list($other, $extra) = self::split_arg($arg);
                     if ($extra) {
                         $result = null;
                     } else {
@@ -99,7 +100,7 @@ class CommandInterpreter
                 break;
             case 'off':
                 if ($arg) {
-                    list($other, $extra) = $this->split_arg($arg);
+                    list($other, $extra) = self::split_arg($arg);
                     if ($extra) {
                         $result = null;
                     } else {
@@ -120,49 +121,51 @@ class CommandInterpreter
             case 'join':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new JoinCommand($user, $other);
+                    list($other, $extra) = self::split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new JoinCommand($user, $other);
+                    }
                 }
                 break;
             case 'drop':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new DropCommand($user, $other);
+                    list($other, $extra) = self::split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new DropCommand($user, $other);
+                    }
                 }
                 break;
             case 'follow':
             case 'sub':
                 if (!$arg) {
                     $result = null;
-                }
-
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new SubCommand($user, $other);
+                    list($other, $extra) = self::split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new SubCommand($user, $other);
+                    }
                 }
                 break;
             case 'leave':
             case 'unsub':
                 if (!$arg) {
                     $result = null;
-                }
-
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new UnsubCommand($user, $other);
+                    list($other, $extra) = self::split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new UnsubCommand($user, $other);
+                    }
                 }
                 break;
             case 'get':
@@ -170,139 +173,135 @@ class CommandInterpreter
                 if (!$arg) {
                     $result = null;
                 }
-                list($other, $extra) = $this->split_arg($arg);
+                list($other, $extra) = self::split_arg($arg);
                 if ($extra) {
                     $result = null;
                 } else {
                     $result = new GetCommand($user, $other);
                 }
                 break;
-            case 'd':
-            case 'dm':
-                if (!$arg) {
-                    $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if (!$extra) {
-                    $result = null;
-                } else {
-                    $result = new MessageCommand($user, $other, $extra);
-                }
-                break;
             case 'r':
             case 'reply':
                 if (!$arg) {
                     $result = null;
                 }
-                list($other, $extra) = $this->split_arg($arg);
+                list($other, $extra) = self::split_arg($arg);
                 if (!$extra) {
                     $result = null;
                 } else {
                     $result = new ReplyCommand($user, $other, $extra);
                 }
                 break;
-            case 'repeat':
-            case 'rp':
-            case 'rt':
-            case 'rd':
+            case 'whois':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new RepeatCommand($user, $other);
+                    list($other, $extra) = self::split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new WhoisCommand($user, $other);
+                    }
                 }
                 break;
-            case 'whois':
+            case 'nudge':
                 if (!$arg) {
                     $result = null;
+                } else {
+                    list($other, $extra) = self::split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new NudgeCommand($user, $other);
+                    }
                 }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
+                break;
+            case 'stats':
+                if ($arg) {
                     $result = null;
                 } else {
-                    $result = new WhoisCommand($user, $other);
+                    $result = new StatsCommand($user);
                 }
                 break;
-            case 'fav':
+            case 'invite':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new FavCommand($user, $other);
+                    list($other, $extra) = self::split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new InviteCommand($user, $other);
+                    }
                 }
                 break;
-            case 'nudge':
+             case 'list':
+             case 'tag':
                 if (!$arg) {
                     $result = null;
+                    break;
                 }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
+                list($other, $tags) = self::split_arg($arg);
+                if (!$tags) {
                     $result = null;
                 } else {
-                    $result = new NudgeCommand($user, $other);
+                    $result = new TagCommand($user, $other, $tags);
                 }
                 break;
-            case 'stats':
-                if ($arg) {
-                    $result = null;
-                }
-                $result = new StatsCommand($user);
-                break;
-            case 'invite':
+             case 'unlist':
+             case 'untag':
                 if (!$arg) {
                     $result = null;
+                    break;
                 }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
+                list($other, $tags) = self::split_arg($arg);
+                if (!$tags) {
                     $result = null;
                 } else {
-                    $result = new InviteCommand($user, $other);
+                    $result = new UntagCommand($user, $other, $tags);
                 }
                 break;
             case 'track':
                 if (!$arg) {
                     $result = null;
-                }
-                list($word, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
-                } else if ($word == 'off') {
-                    $result = new TrackOffCommand($user);
                 } else {
-                    $result = new TrackCommand($user, $word);
+                    list($word, $extra) = self::split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else if ($word == 'off') {
+                        $result = new TrackOffCommand($user);
+                    } else {
+                        $result = new TrackCommand($user, $word);
+                    }
                 }
                 break;
             case 'untrack':
                 if (!$arg) {
                     $result = null;
-                }
-                list($word, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
-                } else if ($word == 'all') {
-                    $result = new TrackOffCommand($user);
                 } else {
-                    $result = new UntrackCommand($user, $word);
+                    list($word, $extra) = self::split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else if ($word == 'all') {
+                        $result = new TrackOffCommand($user);
+                    } else {
+                        $result = new UntrackCommand($user, $word);
+                    }
                 }
                 break;
             case 'tracks':
             case 'tracking':
                 if ($arg) {
                     $result = null;
+                } else {
+                    $result = new TrackingCommand($user);
                 }
-                $result = new TrackingCommand($user);
                 break;
             default:
                 $result = false;
             }
-                
-            Event::handle('EndInterpretCommand', array($cmd, $arg, $user, $result));
+
+            Event::handle('EndInterpretCommand', array($cmd, $arg, $user, &$result));
         }
 
         return $result;
@@ -311,7 +310,7 @@ class CommandInterpreter
     /**
      * Split arguments without triggering a PHP notice warning
      */
-    function split_arg($text)
+    static function split_arg($text)
     {
         $pieces = explode(' ', $text, 2);
         if (count($pieces) == 1) {