forked from GNUsocial/gnu-social
actions
avatar
background
classes
db
doc-src
extlib
file
js
lib
accountmover.php
accountprofileblock.php
action.php
activity.php
activitycontext.php
activityimporter.php
activitymover.php
activityobject.php
activitysink.php
activitysource.php
activitystreamjsondocument.php
activityutils.php
activityverb.php
adminform.php
adminpanelaction.php
adminpanelnav.php
apiaction.php
apiauth.php
apibareauth.php
apilistusers.php
apioauth.php
apioauthstore.php
apiprivateauth.php
applicationeditform.php
applicationlist.php
approvegroupform.php
approvesubform.php
arraywrapper.php
atom10feed.php
atomcategory.php
atomgroupnoticefeed.php
atomlistnoticefeed.php
atomnoticefeed.php
atomusernoticefeed.php
attachmentlist.php
attachmentnoticesection.php
attachmenttagcloudsection.php
authenticationplugin.php
authorizationexception.php
authorizationplugin.php
avatarlink.php
blockform.php
cache.php
cachingnoticestream.php
cancelgroupform.php
cancelsubscriptionform.php
channel.php
clienterroraction.php
clientexception.php
columndef.php
command.php
commandinterpreter.php
common.php
conversationnoticestream.php
currentuserdesignaction.php
curry.php
daemon.php
dberroraction.php
dbqueuemanager.php
default.php
defaultlocalnav.php
defaultprofileblock.php
deletegroupform.php
deleteuserform.php
deluserqueuehandler.php
designform.php
designsettings.php
discovery.php
disfavorform.php
distribqueuehandler.php
docfile.php
dofollowlistitem.php
error.php
event.php
favenoticestream.php
favorform.php
featureduserssection.php
feed.php
feedimporter.php
feedlist.php
filenoticestream.php
filteringnoticestream.php
form.php
framework.php
fullthreadednoticelist.php
galleryaction.php
grantroleform.php
groupblockform.php
groupdesignaction.php
groupeditform.php
grouplist.php
groupmemberlist.php
groupmemberlistitem.php
groupminilist.php
groupnav.php
groupnoticestream.php
groupprofileblock.php
groupsbymemberssection.php
groupsbypostssection.php
groupsection.php
groupsnav.php
grouptagcloudsection.php
htmloutputter.php
httpclient.php
imagefile.php
imchannel.php
immanager.php
implugin.php
imqueuehandler.php
imreceiverqueuehandler.php
imsenderqueuehandler.php
inboxnoticestream.php
inboxtagcloudsection.php
info.php
inlineattachmentlist.php
installer.php
invitebuttonsection.php
iomanager.php
iomaster.php
joinform.php
jsonsearchresultslist.php
language.php
leaveform.php
liberalstomp.php
linkheader.php
listsnav.php
location.php
logingroupnav.php
mail.php
mailbox.php
mailboxmenu.php
mailhandler.php
makeadminform.php
mediafile.php
menu.php
messageform.php
messagelist.php
messagelistitem.php
microappplugin.php
microid.php
mysqlschema.php
nickname.php
noticeform.php
noticelist.php
noticelistitem.php
noticelistitemadapter.php
noticeplaceholderform.php
noticesection.php
noticestream.php
nudgeform.php
oauthclient.php
oauthstore.php
oembedhelper.php
omb.php
ombqueuehandler.php
ownerdesignaction.php
parallelizingdaemon.php
peopletageditform.php
peopletaggroupnav.php
peopletaglist.php
peopletagnav.php
peopletagnoticestream.php
peopletags.php
peopletagsbysubssection.php
peopletagsection.php
peopletagsforusersection.php
peopletagsubscriptionssection.php
personalgroupnav.php
personaltagcloudsection.php
pgsqlschema.php
ping.php
pingqueuehandler.php
plugin.php
plugindisableform.php
pluginenableform.php
pluginlist.php
pluginqueuehandler.php
poco.php
pocoaddress.php
pocourl.php
popularity.php
popularnoticesection.php
primarynav.php
processmanager.php
profileaction.php
profileactionform.php
profileblock.php
profileformaction.php
profilelist.php
profileminilist.php
profilenoticestream.php
profilequeuehandler.php
profilesection.php
publicgroupnav.php
publicnoticestream.php
publictagcloudsection.php
queuehandler.php
queuemanager.php
queuemonitor.php
redirectingaction.php
repeatedbymenoticestream.php
repeatform.php
repeatsofmenoticestream.php
replynoticestream.php
revokeroleform.php
right.php
router.php
rssaction.php
sandboxform.php
schema.php
schemaupdater.php
scopingnoticestream.php
search_engines.php
searchaction.php
searchgroupnav.php
searchnoticestream.php
secondarynav.php
section.php
servererroraction.php
serverexception.php
settingsaction.php
settingsnav.php
silenceform.php
smsqueuehandler.php
snapshot.php
spawningdaemon.php
statusnet.php
stompqueuemanager.php
subgroupnav.php
subpeopletagcloudsection.php
subs.php
subscribeform.php
subscribepeopletagform.php
subscriberspeopleselftagcloudsection.php
subscriberspeopletagcloudsection.php
subscriptionlist.php
subscriptionspeopleselftagcloudsection.php
subscriptionspeopletagcloudsection.php
tabledef.php
tagcloudsection.php
taggedprofilenoticestream.php
tagnoticestream.php
taguri.php
theme.php
themeuploader.php
threadednoticelist.php
threadingnoticestream.php
togglepeopletag.php
topposterssection.php
toselector.php
uapplugin.php
unblockform.php
unqueuemanager.php
unsandboxform.php
unsilenceform.php
unsubscribeform.php
unsubscribepeopletagform.php
urlshortenerplugin.php
useractivitystream.php
usernoprofileexception.php
util.php
uuid.php
webcolor.php
widget.php
xmloutputter.php
xmlstringer.php
xrd.php
xrdaction.php
xrdsoutputter.php
local
locale
mail-src
plugins
scripts
tests
theme
tpl
.gitignore
COPYING
EVENTS.txt
Makefile
README
apple-touch-icon.png
config.php.sample
favicon.ico
htaccess.sample
index.php
install.php
lighttpd.conf.example
L10n/i18n updates. Superfluous whitespace removed. Add FIXME for a few i18n issues I couldn't solve this quickly. Takes care of documentation for all core code added in merge of "people tags" feature (Commit:e75c9988ebe33822e493ac225859bc593ff9b855).
361 lines
12 KiB
PHP
361 lines
12 KiB
PHP
<?php
|
|
/*
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
* Copyright (C) 2008, 2009, StatusNet, Inc.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
|
|
|
require_once INSTALLDIR.'/lib/command.php';
|
|
|
|
class CommandInterpreter
|
|
{
|
|
function handle_command($user, $text)
|
|
{
|
|
// XXX: localise
|
|
|
|
$text = preg_replace('/\s+/', ' ', trim($text));
|
|
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
|
|
// StatusNet
|
|
|
|
$cmd = strtolower($cmd);
|
|
|
|
if (Event::handle('StartIntepretCommand', array($cmd, $arg, $user, &$result))) {
|
|
switch($cmd) {
|
|
case 'help':
|
|
if ($arg) {
|
|
$result = null;
|
|
} else {
|
|
$result = new HelpCommand($user);
|
|
}
|
|
break;
|
|
case 'login':
|
|
if ($arg) {
|
|
$result = null;
|
|
} else {
|
|
$result = new LoginCommand($user);
|
|
}
|
|
break;
|
|
case 'lose':
|
|
if ($arg) {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new LoseCommand($user, $other);
|
|
}
|
|
} else {
|
|
$result = null;
|
|
}
|
|
break;
|
|
case 'subscribers':
|
|
if ($arg) {
|
|
$result = null;
|
|
} else {
|
|
$result = new SubscribersCommand($user);
|
|
}
|
|
break;
|
|
case 'subscriptions':
|
|
if ($arg) {
|
|
$result = null;
|
|
} else {
|
|
$result = new SubscriptionsCommand($user);
|
|
}
|
|
break;
|
|
case 'groups':
|
|
if ($arg) {
|
|
$result = null;
|
|
} else {
|
|
$result = new GroupsCommand($user);
|
|
}
|
|
break;
|
|
case 'on':
|
|
if ($arg) {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new OnCommand($user, $other);
|
|
}
|
|
} else {
|
|
$result = new OnCommand($user);
|
|
}
|
|
break;
|
|
case 'off':
|
|
if ($arg) {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new OffCommand($user, $other);
|
|
}
|
|
} else {
|
|
$result = new OffCommand($user);
|
|
}
|
|
break;
|
|
case 'stop':
|
|
case 'quit':
|
|
if ($arg) {
|
|
$result = null;
|
|
} else {
|
|
$result = new OffCommand($user);
|
|
}
|
|
break;
|
|
case 'join':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new JoinCommand($user, $other);
|
|
}
|
|
}
|
|
break;
|
|
case 'drop':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new DropCommand($user, $other);
|
|
}
|
|
}
|
|
break;
|
|
case 'follow':
|
|
case 'sub':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new SubCommand($user, $other);
|
|
}
|
|
}
|
|
break;
|
|
case 'leave':
|
|
case 'unsub':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new UnsubCommand($user, $other);
|
|
}
|
|
}
|
|
break;
|
|
case 'get':
|
|
case 'last':
|
|
if (!$arg) {
|
|
$result = null;
|
|
}
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new GetCommand($user, $other);
|
|
}
|
|
break;
|
|
case 'd':
|
|
case 'dm':
|
|
if (!$arg) {
|
|
$result = null;
|
|
}
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if (!$extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new MessageCommand($user, $other, $extra);
|
|
}
|
|
break;
|
|
case 'r':
|
|
case 'reply':
|
|
if (!$arg) {
|
|
$result = null;
|
|
}
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if (!$extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new ReplyCommand($user, $other, $extra);
|
|
}
|
|
break;
|
|
case 'repeat':
|
|
case 'rp':
|
|
case 'rt':
|
|
case 'rd':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new RepeatCommand($user, $other);
|
|
}
|
|
}
|
|
break;
|
|
case 'whois':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new WhoisCommand($user, $other);
|
|
}
|
|
}
|
|
break;
|
|
case 'fav':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new FavCommand($user, $other);
|
|
}
|
|
}
|
|
break;
|
|
case 'nudge':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new NudgeCommand($user, $other);
|
|
}
|
|
}
|
|
break;
|
|
case 'stats':
|
|
if ($arg) {
|
|
$result = null;
|
|
} else {
|
|
$result = new StatsCommand($user);
|
|
}
|
|
break;
|
|
case 'invite':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($other, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else {
|
|
$result = new InviteCommand($user, $other);
|
|
}
|
|
}
|
|
break;
|
|
case 'list':
|
|
case 'tag':
|
|
if (!$arg) {
|
|
$result = null;
|
|
break;
|
|
}
|
|
list($other, $tags) = $this->split_arg($arg);
|
|
if (!$tags) {
|
|
$result = null;
|
|
} else {
|
|
$result = new TagCommand($user, $other, $tags);
|
|
}
|
|
break;
|
|
case 'unlist':
|
|
case 'untag':
|
|
if (!$arg) {
|
|
$result = null;
|
|
break;
|
|
}
|
|
list($other, $tags) = $this->split_arg($arg);
|
|
if (!$tags) {
|
|
$result = null;
|
|
} else {
|
|
$result = new UntagCommand($user, $other, $tags);
|
|
}
|
|
break;
|
|
case 'track':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($word, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else if ($word == 'off') {
|
|
$result = new TrackOffCommand($user);
|
|
} else {
|
|
$result = new TrackCommand($user, $word);
|
|
}
|
|
}
|
|
break;
|
|
case 'untrack':
|
|
if (!$arg) {
|
|
$result = null;
|
|
} else {
|
|
list($word, $extra) = $this->split_arg($arg);
|
|
if ($extra) {
|
|
$result = null;
|
|
} else if ($word == 'all') {
|
|
$result = new TrackOffCommand($user);
|
|
} else {
|
|
$result = new UntrackCommand($user, $word);
|
|
}
|
|
}
|
|
break;
|
|
case 'tracks':
|
|
case 'tracking':
|
|
if ($arg) {
|
|
$result = null;
|
|
} else {
|
|
$result = new TrackingCommand($user);
|
|
}
|
|
break;
|
|
default:
|
|
$result = false;
|
|
}
|
|
|
|
Event::handle('EndInterpretCommand', array($cmd, $arg, $user, &$result));
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Split arguments without triggering a PHP notice warning
|
|
*/
|
|
function split_arg($text)
|
|
{
|
|
$pieces = explode(' ', $text, 2);
|
|
if (count($pieces) == 1) {
|
|
$pieces[] = null;
|
|
}
|
|
return $pieces;
|
|
}
|
|
}
|