]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Don't trigger E_NOTICE when looking for commands in the notice input
authorBrion Vibber <brion@pobox.com>
Mon, 21 Sep 2009 04:39:57 +0000 (21:39 -0700)
committerBrion Vibber <brion@pobox.com>
Mon, 21 Sep 2009 04:39:57 +0000 (21:39 -0700)
explode() only returns one item if there was no space, leading to an E_NOTICE about an undefined array index in the list($a,$b) pattern.

lib/commandinterpreter.php

index 6e4340e5dcac05529218c6246b2aff02e35a62fa..60fc4c3c44802755af6e8bc1c6a5e4ea54bd92f1 100644 (file)
@@ -28,7 +28,7 @@ class CommandInterpreter
         # XXX: localise
 
         $text = preg_replace('/\s+/', ' ', trim($text));
-        list($cmd, $arg) = explode(' ', $text, 2);
+        list($cmd, $arg) = $this->split_arg($text);
 
         # We try to support all the same commands as Twitter, see
         # http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands
@@ -43,7 +43,7 @@ class CommandInterpreter
             return new HelpCommand($user);
          case 'on':
             if ($arg) {
-                list($other, $extra) = explode(' ', $arg, 2);
+                list($other, $extra) = $this->split_arg($arg);
                 if ($extra) {
                     return null;
                 } else {
@@ -54,7 +54,7 @@ class CommandInterpreter
             }
          case 'off':
             if ($arg) {
-                list($other, $extra) = explode(' ', $arg, 2);
+                list($other, $extra) = $this->split_arg($arg);
                 if ($extra) {
                     return null;
                 } else {
@@ -74,7 +74,7 @@ class CommandInterpreter
              if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -84,7 +84,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -95,7 +95,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -106,7 +106,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -117,7 +117,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -128,7 +128,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if (!$extra) {
                 return null;
             } else {
@@ -138,7 +138,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -148,7 +148,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -158,7 +158,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -173,7 +173,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($other, $extra) = explode(' ', $arg, 2);
+            list($other, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else {
@@ -183,7 +183,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($word, $extra) = explode(' ', $arg, 2);
+            list($word, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else if ($word == 'off') {
@@ -195,7 +195,7 @@ class CommandInterpreter
             if (!$arg) {
                 return null;
             }
-            list($word, $extra) = explode(' ', $arg, 2);
+            list($word, $extra) = $this->split_arg($arg);
             if ($extra) {
                 return null;
             } else if ($word == 'all') {
@@ -213,5 +213,17 @@ class CommandInterpreter
             return false;
         }
     }
+    
+    /**
+     * Split arguments without triggering a PHP notice warning
+     */
+    function split_arg($text)
+    {
+        $pieces = explode(' ', $text, 2);
+        if (count($pieces) == 1) {
+            $pieces[] = null;
+        }
+        return $pieces;
+    }
 }