class Command
{
+ protected $scoped = null; // The Profile of the user performing the command
var $user = null;
function __construct($user=null)
{
+ $this->scoped = $user->getProfile();
$this->user = $user;
}
if(substr($this->other,0,1)=='#'){
// A specific notice_id #123
- $notice = Notice::staticGet(substr($arg,1));
+ $notice = Notice::getKV(substr($arg,1));
if (!$notice) {
// TRANS: Command exception text shown when a notice ID is requested that does not exist.
throw new CommandException(_('Notice with that id does not exist.'));
if (Validate::uri($this->other)) {
// A specific notice by URI lookup
- $notice = Notice::staticGet('uri', $arg);
+ $notice = Notice::getKV('uri', $arg);
}
if (!$notice) {
{
$user = null;
if (Event::handle('StartCommandGetUser', array($this, $arg, &$user))) {
- $user = User::staticGet('nickname', Nickname::normalize($arg));
+ $user = User::getKV('nickname', Nickname::normalize($arg));
}
Event::handle('EndCommandGetUser', array($this, $arg, &$user));
if (!$user){
function handle($channel)
{
// TRANS: Error text shown when an unimplemented command is given.
- $channel->error($this->user, _("Sorry, this command is not yet implemented."));
+ $channel->error($this->user, _('Sorry, this command is not yet implemented.'));
}
}
}
}
-class FavCommand extends Command
-{
- var $other = null;
-
- function __construct($user, $other)
- {
- parent::__construct($user);
- $this->other = $other;
- }
-
- function handle($channel)
- {
- $notice = $this->getNotice($this->other);
-
- $fave = new Fave();
- $fave->user_id = $this->user->id;
- $fave->notice_id = $notice->id;
- $fave->find();
-
- if ($fave->fetch()) {
- // TRANS: Error message text shown when a favorite could not be set because it has already been favorited.
- $channel->error($this->user, _('Could not create favorite: already favorited.'));
- return;
- }
-
- $fave = Fave::addNew($this->user->getProfile(), $notice);
-
- if (!$fave) {
- // TRANS: Error message text shown when a favorite could not be set.
- $channel->error($this->user, _('Could not create favorite.'));
- return;
- }
-
- // @fixme favorite notification should be triggered
- // at a lower level
-
- $other = User::staticGet('id', $notice->profile_id);
-
- if ($other && $other->id != $this->user->id) {
- if ($other->email && $other->emailnotifyfav) {
- mail_notify_fave($other, $this->user, $notice);
- }
- }
-
- $this->user->blowFavesCache();
-
- // TRANS: Text shown when a notice has been marked as favourite successfully.
- $channel->output($this->user, _('Notice marked as fave.'));
- }
-}
-
class JoinCommand extends Command
{
var $other = null;
$cur = $this->user->getProfile();
if (!$profile) {
+ // TRANS: Client error displayed trying to perform an action related to a non-existing profile.
$channel->error($cur, _('No such profile.'));
return;
}
if (!$cur->canTag($profile)) {
+ // TRANS: Error displayed when trying to tag a user that cannot be tagged.
$channel->error($cur, _('You cannot tag this user.'));
return;
}
$tag = $clean_tags[] = common_canonical_tag($tag);
if (!common_valid_profile_tag($tag)) {
- $channel->error($cur, sprintf(_('Invalid tag: "%s"'), $tag));
+ // TRANS: Error displayed if a given tag is invalid.
+ // TRANS: %s is the invalid tag.
+ $channel->error($cur, sprintf(_('Invalid tag: "%s".'), $tag));
return;
}
$privs[$tag] = $private;
Profile_tag::setTag($cur->id, $profile->id, $tag, null, $privs[$tag]);
}
} catch (Exception $e) {
- $channel->error($cur, sprintf(_('Error tagging %s: %s'),
+ // TRANS: Error displayed if tagging a user fails.
+ // TRANS: %1$s is the tagged user, %2$s is the error message (no punctuation).
+ $channel->error($cur, sprintf(_('Error tagging %1$s: %2$s'),
$profile->nickname, $e->getMessage()));
return;
}
- $channel->output($cur, sprintf(_('%1$s was tagged %2$s'),
- $profile->nickname,
- implode(', ', $clean_tags)));
+ // TRANS: Succes message displayed if tagging a user succeeds.
+ // TRANS: %1$s is the tagged user's nickname, %2$s is a list of tags.
+ // TRANS: Plural is decided based on the number of tags added (not part of message).
+ $channel->output($cur, sprintf(_m('%1$s was tagged %2$s',
+ '%1$s was tagged %2$s',
+ count($clean_tags)),
+ $profile->nickname,
+ // TRANS: Separator for list of tags.
+ implode(_(', '), $clean_tags)));
}
}
-
class UntagCommand extends TagCommand
{
function handle($channel)
$cur = $this->user->getProfile();
if (!$profile) {
+ // TRANS: Client error displayed trying to perform an action related to a non-existing profile.
$channel->error($cur, _('No such profile.'));
return;
}
if (!$cur->canTag($profile)) {
+ // TRANS: Error displayed when trying to tag a user that cannot be tagged.
$channel->error($cur, _('You cannot tag this user.'));
return;
}
foreach ($tags as $tag) {
if (!common_valid_profile_tag($tag)) {
+ // TRANS: Error displayed if a given tag is invalid.
+ // TRANS: %s is the invalid tag.
$channel->error($cur, sprintf(_('Invalid tag: "%s"'), $tag));
return;
}
Profile_tag::unTag($cur->id, $profile->id, $tag);
}
} catch (Exception $e) {
- $channel->error($cur, sprintf(_('Error untagging %s: %s'),
+ // TRANS: Error displayed if untagging a user fails.
+ // TRANS: %1$s is the untagged user, %2$s is the error message (no punctuation).
+ $channel->error($cur, sprintf(_('Error untagging %1$s: %2$s'),
$profile->nickname, $e->getMessage()));
return;
}
- $channel->output($cur, sprintf(_('The following tag(s) were removed from user %1$s: %2$s.'),
- $profile->nickname,
- implode(', ', $tags)));
+ // TRANS: Succes message displayed if untagging a user succeeds.
+ // TRANS: %1$s is the untagged user's nickname, %2$s is a list of tags.
+ // TRANS: Plural is decided based on the number of tags removed (not part of message).
+ $channel->output($cur, sprintf(_m('The following tag was removed from user %1$s: %2$s.',
+ 'The following tags were removed from user %1$s: %2$s.',
+ count($tags)),
+ $profile->nickname,
+ // TRANS: Separator for list of tags.
+ implode(_(', '), $tags)));
}
}
}
}
-class MessageCommand extends Command
-{
- var $other = null;
- var $text = null;
- function __construct($user, $other, $text)
- {
- parent::__construct($user);
- $this->other = $other;
- $this->text = $text;
- }
-
- function handle($channel)
- {
- try {
- $other = $this->getUser($this->other);
- } catch (CommandException $e) {
- try {
- $profile = $this->getProfile($this->other);
- } catch (CommandException $f) {
- throw $e;
- }
- // TRANS: Command exception text shown when trying to send a direct message to a remote user (a user not registered at the current server).
- // TRANS: %s is a remote profile.
- throw new CommandException(sprintf(_('%s is a remote profile; you can only send direct messages to users on the same server.'), $this->other));
- }
-
- $len = mb_strlen($this->text);
-
- if ($len == 0) {
- // TRANS: Command exception text shown when trying to send a direct message to another user without content.
- $channel->error($this->user, _('No content!'));
- return;
- }
-
- $this->text = $this->user->shortenLinks($this->text);
-
- if (Message::contentTooLong($this->text)) {
- // XXX: i18n. Needs plural support.
- // TRANS: Message given if content is too long. %1$sd is used for plural.
- // TRANS: %1$d is the maximum number of characters, %2$d is the number of submitted characters.
- $channel->error($this->user, sprintf(_m('Message too long - maximum is %1$d character, you sent %2$d.',
- 'Message too long - maximum is %1$d characters, you sent %2$d.',
- Message::maxContent()),
- Message::maxContent(), mb_strlen($this->text)));
- return;
- }
-
- if (!$other) {
- // TRANS: Error text shown when trying to send a direct message to a user that does not exist.
- $channel->error($this->user, _('No such user.'));
- return;
- } else if (!$this->user->mutuallySubscribed($other)) {
- // TRANS: Error text shown when trying to send a direct message to a user without a mutual subscription (each user must be subscribed to the other).
- $channel->error($this->user, _('You can\'t send a message to this user.'));
- return;
- } else if ($this->user->id == $other->id) {
- // TRANS: Error text shown when trying to send a direct message to self.
- $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
- return;
- }
- $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
- if ($message) {
- $message->notify();
- // TRANS: Message given have sent a direct message to another user.
- // TRANS: %s is the name of the other user.
- $channel->output($this->user, sprintf(_('Direct message to %s sent.'), $this->other));
- } else {
- // TRANS: Error text shown sending a direct message fails with an unknown reason.
- $channel->error($this->user, _('Error sending direct message.'));
- }
- }
-}
-
class RepeatCommand extends Command
{
var $other = null;
$notice = $this->getNotice($this->other);
try {
- $repeat = $notice->repeat($this->user->id, $channel->source());
+ $repeat = $notice->repeat($this->scoped->id, $channel->source());
$recipient = $notice->getProfile();
// TRANS: Message given having repeated a notice from another user.
$target = $this->getProfile($this->other);
- $remote = Remote_profile::staticGet('id', $target->id);
- if ($remote) {
- // TRANS: Command exception text shown when trying to subscribe to an OMB profile using the subscribe command.
- throw new CommandException(_("Can't subscribe to OMB profiles by command."));
- }
-
try {
- Subscription::start($this->user->getProfile(),
- $target);
+ Subscription::start($this->user->getProfile(), $target);
// TRANS: Text shown after having subscribed to another user successfully.
// TRANS: %s is the name of the user the subscription was requested for.
$channel->output($this->user, sprintf(_('Subscribed to %s.'), $this->other));
$target = $this->getProfile($this->other);
try {
- Subscription::cancel($this->user->getProfile(),
- $target);
+ Subscription::cancel($this->user->getProfile(), $target);
// TRANS: Text shown after having unsubscribed from another user successfully.
// TRANS: %s is the name of the user the unsubscription was requested for.
$channel->output($this->user, sprintf(_('Unsubscribed from %s.'), $this->other));
{
function handle($channel)
{
- $profile = $this->user->getSubscriptions(0);
+ $profile = $this->user->getSubscribed(0);
$nicknames=array();
while ($profile->fetch()) {
$nicknames[]=$profile->nickname;
{
$group = $this->user->getGroups();
$groups=array();
- while ($group->fetch()) {
+ while ($group instanceof User_group && $group->fetch()) {
$groups[]=$group->nickname;
}
if(count($groups)==0){
{
// TRANS: Header line of help text for commands.
$out = array(_m('COMMANDHELP', "Commands:"));
- $commands = array(// TRANS: Help message for IM/SMS command "on"
+ $commands = array(// TRANS: Help message for IM/SMS command "on".
"on" => _m('COMMANDHELP', "turn on notifications"),
- // TRANS: Help message for IM/SMS command "off"
+ // TRANS: Help message for IM/SMS command "off".
"off" => _m('COMMANDHELP', "turn off notifications"),
- // TRANS: Help message for IM/SMS command "help"
+ // TRANS: Help message for IM/SMS command "help".
"help" => _m('COMMANDHELP', "show this help"),
- // TRANS: Help message for IM/SMS command "follow <nickname>"
+ // TRANS: Help message for IM/SMS command "follow <nickname>".
"follow <nickname>" => _m('COMMANDHELP', "subscribe to user"),
- // TRANS: Help message for IM/SMS command "groups"
+ // TRANS: Help message for IM/SMS command "groups".
"groups" => _m('COMMANDHELP', "lists the groups you have joined"),
- // TRANS: Help message for IM/SMS command "tag"
+ // TRANS: Help message for IM/SMS command "tag".
"tag <nickname> <tags>" => _m('COMMANDHELP',"tag a user"),
- // TRANS: Help message for IM/SMS command "untag"
+ // TRANS: Help message for IM/SMS command "untag".
"untag <nickname> <tags>" => _m('COMMANDHELP',"untag a user"),
- // TRANS: Help message for IM/SMS command "subscriptions"
+ // TRANS: Help message for IM/SMS command "subscriptions".
"subscriptions" => _m('COMMANDHELP', "list the people you follow"),
- // TRANS: Help message for IM/SMS command "subscribers"
+ // TRANS: Help message for IM/SMS command "subscribers".
"subscribers" => _m('COMMANDHELP', "list the people that follow you"),
- // TRANS: Help message for IM/SMS command "leave <nickname>"
+ // TRANS: Help message for IM/SMS command "leave <nickname>".
"leave <nickname>" => _m('COMMANDHELP', "unsubscribe from user"),
- // TRANS: Help message for IM/SMS command "d <nickname> <text>"
+ // TRANS: Help message for IM/SMS command "d <nickname> <text>".
"d <nickname> <text>" => _m('COMMANDHELP', "direct message to user"),
- // TRANS: Help message for IM/SMS command "get <nickname>"
+ // TRANS: Help message for IM/SMS command "get <nickname>".
"get <nickname>" => _m('COMMANDHELP', "get last notice from user"),
- // TRANS: Help message for IM/SMS command "whois <nickname>"
+ // TRANS: Help message for IM/SMS command "whois <nickname>".
"whois <nickname>" => _m('COMMANDHELP', "get profile info on user"),
- // TRANS: Help message for IM/SMS command "lose <nickname>"
+ // TRANS: Help message for IM/SMS command "lose <nickname>".
"lose <nickname>" => _m('COMMANDHELP', "force user to stop following you"),
- // TRANS: Help message for IM/SMS command "fav <nickname>"
- "fav <nickname>" => _m('COMMANDHELP', "add user's last notice as a 'fave'"),
- // TRANS: Help message for IM/SMS command "fav #<notice_id>"
- "fav #<notice_id>" => _m('COMMANDHELP', "add notice with the given id as a 'fave'"),
- // TRANS: Help message for IM/SMS command "repeat #<notice_id>"
+ // TRANS: Help message for IM/SMS command "repeat #<notice_id>".
"repeat #<notice_id>" => _m('COMMANDHELP', "repeat a notice with a given id"),
- // TRANS: Help message for IM/SMS command "repeat <nickname>"
+ // TRANS: Help message for IM/SMS command "repeat <nickname>".
"repeat <nickname>" => _m('COMMANDHELP', "repeat the last notice from user"),
- // TRANS: Help message for IM/SMS command "reply #<notice_id>"
+ // TRANS: Help message for IM/SMS command "reply #<notice_id>".
"reply #<notice_id>" => _m('COMMANDHELP', "reply to notice with a given id"),
- // TRANS: Help message for IM/SMS command "reply <nickname>"
+ // TRANS: Help message for IM/SMS command "reply <nickname>".
"reply <nickname>" => _m('COMMANDHELP', "reply to the last notice from user"),
- // TRANS: Help message for IM/SMS command "join <group>"
+ // TRANS: Help message for IM/SMS command "join <group>".
"join <group>" => _m('COMMANDHELP', "join group"),
- // TRANS: Help message for IM/SMS command "login"
+ // TRANS: Help message for IM/SMS command "login".
"login" => _m('COMMANDHELP', "Get a link to login to the web interface"),
- // TRANS: Help message for IM/SMS command "drop <group>"
+ // TRANS: Help message for IM/SMS command "drop <group>".
"drop <group>" => _m('COMMANDHELP', "leave group"),
- // TRANS: Help message for IM/SMS command "stats"
+ // TRANS: Help message for IM/SMS command "stats".
"stats" => _m('COMMANDHELP', "get your stats"),
- // TRANS: Help message for IM/SMS command "stop"
+ // TRANS: Help message for IM/SMS command "stop".
"stop" => _m('COMMANDHELP', "same as 'off'"),
- // TRANS: Help message for IM/SMS command "quit"
+ // TRANS: Help message for IM/SMS command "quit".
"quit" => _m('COMMANDHELP', "same as 'off'"),
- // TRANS: Help message for IM/SMS command "sub <nickname>"
+ // TRANS: Help message for IM/SMS command "sub <nickname>".
"sub <nickname>" => _m('COMMANDHELP', "same as 'follow'"),
- // TRANS: Help message for IM/SMS command "unsub <nickname>"
+ // TRANS: Help message for IM/SMS command "unsub <nickname>".
"unsub <nickname>" => _m('COMMANDHELP', "same as 'leave'"),
- // TRANS: Help message for IM/SMS command "last <nickname>"
+ // TRANS: Help message for IM/SMS command "last <nickname>".
"last <nickname>" => _m('COMMANDHELP', "same as 'get'"),
- // TRANS: Help message for IM/SMS command "on <nickname>"
+ // TRANS: Help message for IM/SMS command "on <nickname>".
"on <nickname>" => _m('COMMANDHELP', "not yet implemented."),
- // TRANS: Help message for IM/SMS command "off <nickname>"
+ // TRANS: Help message for IM/SMS command "off <nickname>".
"off <nickname>" => _m('COMMANDHELP', "not yet implemented."),
- // TRANS: Help message for IM/SMS command "nudge <nickname>"
+ // TRANS: Help message for IM/SMS command "nudge <nickname>".
"nudge <nickname>" => _m('COMMANDHELP', "remind a user to update."),
- // TRANS: Help message for IM/SMS command "invite <phone number>"
+ // TRANS: Help message for IM/SMS command "invite <phone number>".
"invite <phone number>" => _m('COMMANDHELP', "not yet implemented."),
- // TRANS: Help message for IM/SMS command "track <word>"
+ // TRANS: Help message for IM/SMS command "track <word>".
"track <word>" => _m('COMMANDHELP', "not yet implemented."),
- // TRANS: Help message for IM/SMS command "untrack <word>"
+ // TRANS: Help message for IM/SMS command "untrack <word>".
"untrack <word>" => _m('COMMANDHELP', "not yet implemented."),
- // TRANS: Help message for IM/SMS command "track off"
+ // TRANS: Help message for IM/SMS command "track off".
"track off" => _m('COMMANDHELP', "not yet implemented."),
- // TRANS: Help message for IM/SMS command "untrack all"
+ // TRANS: Help message for IM/SMS command "untrack all".
"untrack all" => _m('COMMANDHELP', "not yet implemented."),
- // TRANS: Help message for IM/SMS command "tracks"
+ // TRANS: Help message for IM/SMS command "tracks".
"tracks" => _m('COMMANDHELP', "not yet implemented."),
- // TRANS: Help message for IM/SMS command "tracking"
+ // TRANS: Help message for IM/SMS command "tracking".
"tracking" => _m('COMMANDHELP', "not yet implemented."));
// Give plugins a chance to add or override...
Event::handle('HelpCommandMessages', array($this, &$commands));
+
+ sort($commands);
foreach ($commands as $command => $help) {
$out[] = "$command - $help";
}