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);
41 if (Event::handle('StartInterpretCommand', array($cmd, $arg, $user, &$result))) {
47 $result = new HelpCommand($user);
54 $result = new LoginCommand($user);
59 list($other, $extra) = self::split_arg($arg);
63 $result = new LoseCommand($user, $other);
73 $result = new SubscribersCommand($user);
80 $result = new SubscriptionsCommand($user);
87 $result = new GroupsCommand($user);
92 list($other, $extra) = self::split_arg($arg);
96 $result = new OnCommand($user, $other);
99 $result = new OnCommand($user);
104 list($other, $extra) = self::split_arg($arg);
108 $result = new OffCommand($user, $other);
111 $result = new OffCommand($user);
119 $result = new OffCommand($user);
126 list($other, $extra) = self::split_arg($arg);
130 $result = new JoinCommand($user, $other);
138 list($other, $extra) = self::split_arg($arg);
142 $result = new DropCommand($user, $other);
151 list($other, $extra) = self::split_arg($arg);
155 $result = new SubCommand($user, $other);
164 list($other, $extra) = self::split_arg($arg);
168 $result = new UnsubCommand($user, $other);
177 list($other, $extra) = self::split_arg($arg);
181 $result = new GetCommand($user, $other);
189 list($other, $extra) = self::split_arg($arg);
193 $result = new ReplyCommand($user, $other, $extra);
200 list($other, $extra) = self::split_arg($arg);
204 $result = new WhoisCommand($user, $other);
212 list($other, $extra) = self::split_arg($arg);
216 $result = new NudgeCommand($user, $other);
224 $result = new StatsCommand($user);
231 list($other, $extra) = self::split_arg($arg);
235 $result = new InviteCommand($user, $other);
245 list($other, $tags) = self::split_arg($arg);
249 $result = new TagCommand($user, $other, $tags);
258 list($other, $tags) = self::split_arg($arg);
262 $result = new UntagCommand($user, $other, $tags);
269 list($word, $extra) = self::split_arg($arg);
272 } else if ($word == 'off') {
273 $result = new TrackOffCommand($user);
275 $result = new TrackCommand($user, $word);
283 list($word, $extra) = self::split_arg($arg);
286 } else if ($word == 'all') {
287 $result = new TrackOffCommand($user);
289 $result = new UntrackCommand($user, $word);
298 $result = new TrackingCommand($user);
303 Event::handle('EndInterpretCommand', array($cmd, $arg, $user, &$result));
310 * Split arguments without triggering a PHP notice warning
312 static function split_arg($text)
314 $pieces = explode(' ', $text, 2);
315 if (count($pieces) == 1) {