X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fcommandinterpreter.php;h=b921a17cc25cedec84860fbd19cdd83f50defe1b;hb=9ef05030fe623f18c64f9d24da1ebff04cf6cb62;hp=6538d44420e9135f78d432277ac5a65c7b6c3928;hpb=899aad747a466609542388f86bbd22da4360ed6d;p=quix0rs-gnu-social.git diff --git a/lib/commandinterpreter.php b/lib/commandinterpreter.php index 6538d44420..b921a17cc2 100644 --- a/lib/commandinterpreter.php +++ b/lib/commandinterpreter.php @@ -1,7 +1,7 @@ . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/lib/command.php'; @@ -28,12 +28,12 @@ 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 # There are a few compatibility commands from earlier versions of - # Laconica + # StatusNet switch(strtolower($cmd)) { case 'help': @@ -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 { @@ -70,12 +70,32 @@ class CommandInterpreter } else { return new OffCommand($user); } + case 'join': + if (!$arg) { + return null; + } + list($other, $extra) = $this->split_arg($arg); + if ($extra) { + return null; + } else { + return new JoinCommand($user, $other); + } + case 'drop': + if (!$arg) { + return null; + } + list($other, $extra) = $this->split_arg($arg); + if ($extra) { + return null; + } else { + return new DropCommand($user, $other); + } case 'follow': case 'sub': if (!$arg) { return null; } - list($other, $extra) = explode(' ', $arg, 2); + list($other, $extra) = $this->split_arg($arg); if ($extra) { return null; } else { @@ -86,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 { @@ -97,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 { @@ -108,17 +128,28 @@ class CommandInterpreter if (!$arg) { return null; } - list($other, $extra) = explode(' ', $arg, 2); + list($other, $extra) = $this->split_arg($arg); if (!$extra) { return null; } else { return new MessageCommand($user, $other, $extra); } + case 'r': + case 'reply': + if (!$arg) { + return null; + } + list($other, $extra) = $this->split_arg($arg); + if (!$extra) { + return null; + } else { + return new ReplyCommand($user, $other, $extra); + } case 'whois': if (!$arg) { return null; } - list($other, $extra) = explode(' ', $arg, 2); + list($other, $extra) = $this->split_arg($arg); if ($extra) { return null; } else { @@ -128,7 +159,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 +169,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 { @@ -153,7 +184,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 { @@ -163,7 +194,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') { @@ -175,7 +206,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') { @@ -193,5 +224,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; + } }