Don't trigger E_NOTICE when looking for commands in the notice input
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.
This commit is contained in:
		@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user