3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
22 require_once INSTALLDIR.'/lib/command.php';
24 class CommandInterpreter
26 function handle_command($user, $text)
30 $text = preg_replace('/\s+/', ' ', trim($text));
31 list($cmd, $arg) = self::split_arg($text);
33 // We try to support all the same commands as Twitter, see
34 // http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands
35 // There are a few compatibility commands from earlier versions of
38 $cmd = strtolower($cmd);
40 if (Event::handle('StartInterpretCommand', array($cmd, $arg, $user, &$result))) {
46 $result = new HelpCommand($user);
53 $result = new LoginCommand($user);
58 list($other, $extra) = self::split_arg($arg);
62 $result = new LoseCommand($user, $other);
72 $result = new SubscribersCommand($user);
79 $result = new SubscriptionsCommand($user);
86 $result = new GroupsCommand($user);
91 list($other, $extra) = self::split_arg($arg);
95 $result = new OnCommand($user, $other);
98 $result = new OnCommand($user);
103 list($other, $extra) = self::split_arg($arg);
107 $result = new OffCommand($user, $other);
110 $result = new OffCommand($user);
118 $result = new OffCommand($user);
125 list($other, $extra) = self::split_arg($arg);
129 $result = new JoinCommand($user, $other);
137 list($other, $extra) = self::split_arg($arg);
141 $result = new DropCommand($user, $other);
150 list($other, $extra) = self::split_arg($arg);
154 $result = new SubCommand($user, $other);
163 list($other, $extra) = self::split_arg($arg);
167 $result = new UnsubCommand($user, $other);
176 list($other, $extra) = self::split_arg($arg);
180 $result = new GetCommand($user, $other);
188 list($other, $extra) = self::split_arg($arg);
192 $result = new ReplyCommand($user, $other, $extra);
199 list($other, $extra) = self::split_arg($arg);
203 $result = new WhoisCommand($user, $other);
211 list($other, $extra) = self::split_arg($arg);
215 $result = new NudgeCommand($user, $other);
223 $result = new StatsCommand($user);
230 list($other, $extra) = self::split_arg($arg);
234 $result = new InviteCommand($user, $other);
244 list($other, $tags) = self::split_arg($arg);
248 $result = new TagCommand($user, $other, $tags);
257 list($other, $tags) = self::split_arg($arg);
261 $result = new UntagCommand($user, $other, $tags);
268 list($word, $extra) = self::split_arg($arg);
271 } else if ($word == 'off') {
272 $result = new TrackOffCommand($user);
274 $result = new TrackCommand($user, $word);
282 list($word, $extra) = self::split_arg($arg);
285 } else if ($word == 'all') {
286 $result = new TrackOffCommand($user);
288 $result = new UntrackCommand($user, $word);
297 $result = new TrackingCommand($user);
304 Event::handle('EndInterpretCommand', array($cmd, $arg, $user, &$result));
311 * Split arguments without triggering a PHP notice warning
313 static function split_arg($text)
315 $pieces = explode(' ', $text, 2);
316 if (count($pieces) == 1) {