3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, 2010 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/channel.php');
28 function __construct($user=null)
34 * Execute the command and send success or error results
35 * back via the given communications channel.
39 public function execute($channel)
42 $this->handle($channel);
43 } catch (CommandException $e) {
44 $channel->error($this->user, $e->getMessage());
45 } catch (Exception $e) {
46 common_log(LOG_ERR, "Error handling " . get_class($this) . ": " . $e->getMessage());
47 $channel->error($this->user, $e->getMessage());
52 * Override this with the meat!
54 * An error to send back to the user may be sent by throwing
55 * a CommandException with a formatted message.
58 * @throws CommandException
60 function handle($channel)
66 * Look up a notice from an argument, by poster's name to get last post
67 * or notice_id prefixed with #.
70 * @throws CommandException
72 function getNotice($arg)
75 if (Event::handle('StartCommandGetNotice', array($this, $arg, &$notice))) {
76 if(substr($this->other,0,1)=='#'){
77 // A specific notice_id #123
79 $notice = Notice::staticGet(substr($arg,1));
81 // TRANS: Command exception text shown when a notice ID is requested that does not exist.
82 throw new CommandException(_('Notice with that id does not exist.'));
86 if (Validate::uri($this->other)) {
87 // A specific notice by URI lookup
88 $notice = Notice::staticGet('uri', $arg);
92 // Local or remote profile name to get their last notice.
93 // May throw an exception and report 'no such user'
94 $recipient = $this->getProfile($arg);
96 $notice = $recipient->getCurrentNotice();
98 // TRANS: Command exception text shown when a last user notice is requested and it does not exist.
99 throw new CommandException(_('User has no last notice.'));
103 Event::handle('EndCommandGetNotice', array($this, $arg, &$notice));
105 // TRANS: Command exception text shown when a notice ID is requested that does not exist.
106 throw new CommandException(_('Notice with that id does not exist.'));
112 * Look up a local or remote profile by nickname.
115 * @throws CommandException
117 function getProfile($arg)
120 if (Event::handle('StartCommandGetProfile', array($this, $arg, &$profile))) {
122 common_relative_profile($this->user, common_canonical_nickname($arg));
124 Event::handle('EndCommandGetProfile', array($this, $arg, &$profile));
126 // TRANS: Message given requesting a profile for a non-existing user.
127 // TRANS: %s is the nickname of the user for which the profile could not be found.
128 throw new CommandException(sprintf(_('Could not find a user with nickname %s.'), $arg));
134 * Get a local user by name
136 * @throws CommandException
138 function getUser($arg)
141 if (Event::handle('StartCommandGetUser', array($this, $arg, &$user))) {
142 $user = User::staticGet('nickname', Nickname::normalize($arg));
144 Event::handle('EndCommandGetUser', array($this, $arg, &$user));
146 // TRANS: Message given getting a non-existing user.
147 // TRANS: %s is the nickname of the user that could not be found.
148 throw new CommandException(sprintf(_('Could not find a local user with nickname %s.'),
155 * Get a local or remote group by name.
157 * @throws CommandException
159 function getGroup($arg)
162 if (Event::handle('StartCommandGetGroup', array($this, $arg, &$group))) {
163 $group = User_group::getForNickname($arg, $this->user->getProfile());
165 Event::handle('EndCommandGetGroup', array($this, $arg, &$group));
167 // TRANS: Command exception text shown when a group is requested that does not exist.
168 throw new CommandException(_('No such group.'));
174 class CommandException extends Exception
178 class UnimplementedCommand extends Command
180 function handle($channel)
182 // TRANS: Error text shown when an unimplemented command is given.
183 $channel->error($this->user, _('Sorry, this command is not yet implemented.'));
187 class TrackingCommand extends UnimplementedCommand
191 class TrackOffCommand extends UnimplementedCommand
195 class TrackCommand extends UnimplementedCommand
198 function __construct($user, $word)
200 parent::__construct($user);
205 class UntrackCommand extends UnimplementedCommand
208 function __construct($user, $word)
210 parent::__construct($user);
215 class NudgeCommand extends Command
218 function __construct($user, $other)
220 parent::__construct($user);
221 $this->other = $other;
224 function handle($channel)
226 $recipient = $this->getUser($this->other);
227 if ($recipient->id == $this->user->id) {
228 // TRANS: Command exception text shown when a user tries to nudge themselves.
229 throw new CommandException(_('It does not make a lot of sense to nudge yourself!'));
231 if ($recipient->email && $recipient->emailnotifynudge) {
232 mail_notify_nudge($this->user, $recipient);
235 // XXX: notify by SMS
236 // TRANS: Message given having nudged another user.
237 // TRANS: %s is the nickname of the user that was nudged.
238 $channel->output($this->user, sprintf(_('Nudge sent to %s.'),
239 $recipient->nickname));
244 class InviteCommand extends UnimplementedCommand
247 function __construct($user, $other)
249 parent::__construct($user);
250 $this->other = $other;
254 class StatsCommand extends Command
256 function handle($channel)
258 $profile = $this->user->getProfile();
260 $subs_count = $profile->subscriptionCount();
261 $subbed_count = $profile->subscriberCount();
262 $notice_count = $profile->noticeCount();
264 // TRANS: User statistics text.
265 // TRANS: %1$s is the number of other user the user is subscribed to.
266 // TRANS: %2$s is the number of users that are subscribed to the user.
267 // TRANS: %3$s is the number of notices the user has sent.
268 $channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n".
269 "Subscribers: %2\$s\n".
277 class FavCommand extends Command
281 function __construct($user, $other)
283 parent::__construct($user);
284 $this->other = $other;
287 function handle($channel)
289 $notice = $this->getNotice($this->other);
292 $fave->user_id = $this->user->id;
293 $fave->notice_id = $notice->id;
296 if ($fave->fetch()) {
297 // TRANS: Error message text shown when a favorite could not be set because it has already been favorited.
298 $channel->error($this->user, _('Could not create favorite: Already favorited.'));
302 $fave = Fave::addNew($this->user->getProfile(), $notice);
305 // TRANS: Error message text shown when a favorite could not be set.
306 $channel->error($this->user, _('Could not create favorite.'));
310 // @fixme favorite notification should be triggered
313 $other = User::staticGet('id', $notice->profile_id);
315 if ($other && $other->id != $this->user->id) {
316 if ($other->email && $other->emailnotifyfav) {
317 mail_notify_fave($other, $this->user, $notice);
321 $this->user->blowFavesCache();
323 // TRANS: Text shown when a notice has been marked as favourite successfully.
324 $channel->output($this->user, _('Notice marked as fave.'));
328 class JoinCommand extends Command
332 function __construct($user, $other)
334 parent::__construct($user);
335 $this->other = $other;
338 function handle($channel)
340 $group = $this->getGroup($this->other);
343 if ($cur->isMember($group)) {
344 // TRANS: Error text shown a user tries to join a group they already are a member of.
345 $channel->error($cur, _('You are already a member of that group.'));
348 if (Group_block::isBlocked($group, $cur->getProfile())) {
349 // TRANS: Error text shown when a user tries to join a group they are blocked from joining.
350 $channel->error($cur, _('You have been blocked from that group by the admin.'));
355 $cur->joinGroup($group);
356 } catch (Exception $e) {
357 // TRANS: Message given having failed to add a user to a group.
358 // TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group.
359 $channel->error($cur, sprintf(_('Could not join user %1$s to group %2$s.'),
360 $cur->nickname, $group->nickname));
364 // TRANS: Message given having added a user to a group.
365 // TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group.
366 $channel->output($cur, sprintf(_('%1$s joined group %2$s.'),
372 class DropCommand extends Command
376 function __construct($user, $other)
378 parent::__construct($user);
379 $this->other = $other;
382 function handle($channel)
384 $group = $this->getGroup($this->other);
388 // TRANS: Error text shown when trying to leave a group that does not exist.
389 $channel->error($cur, _('No such group.'));
393 if (!$cur->isMember($group)) {
394 // TRANS: Error text shown when trying to leave an existing group the user is not a member of.
395 $channel->error($cur, _('You are not a member of that group.'));
400 $cur->leaveGroup($group);
401 } catch (Exception $e) {
402 // TRANS: Message given having failed to remove a user from a group.
403 // TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group.
404 $channel->error($cur, sprintf(_('Could not remove user %1$s from group %2$s.'),
405 $cur->nickname, $group->nickname));
409 // TRANS: Message given having removed a user from a group.
410 // TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group.
411 $channel->output($cur, sprintf(_('%1$s left group %2$s.'),
417 class TagCommand extends Command
421 function __construct($user, $other, $tags)
423 parent::__construct($user);
424 $this->other = $other;
428 function handle($channel)
430 $profile = $this->getProfile($this->other);
431 $cur = $this->user->getProfile();
434 // TRANS: Client error displayed trying to perform an action related to a non-existing profile.
435 $channel->error($cur, _('No such profile.'));
438 if (!$cur->canTag($profile)) {
439 // TRANS: Error displayed when trying to tag a user that cannot be tagged.
440 $channel->error($cur, _('You cannot tag this user.'));
445 $tags = preg_split('/[\s,]+/', $this->tags);
446 $clean_tags = array();
448 foreach ($tags as $tag) {
449 $private = @$tag[0] === '.';
450 $tag = $clean_tags[] = common_canonical_tag($tag);
452 if (!common_valid_profile_tag($tag)) {
453 // TRANS: Error displayed if a given tag is invalid.
454 // TRANS: %s is the invalid tag.
455 $channel->error($cur, sprintf(_('Invalid tag: "%s".'), $tag));
458 $privs[$tag] = $private;
462 foreach ($clean_tags as $tag) {
463 Profile_tag::setTag($cur->id, $profile->id, $tag, null, $privs[$tag]);
465 } catch (Exception $e) {
466 // TRANS: Error displayed if tagging a user fails.
467 // TRANS: %1$s is the tagged user, %2$s is the error message (no punctuation).
468 $channel->error($cur, sprintf(_('Error tagging %1$s: %2$s'),
469 $profile->nickname, $e->getMessage()));
473 // TRANS: Succes message displayed if tagging a user succeeds.
474 // TRANS: %1$s is the tagged user's nickname, %2$s is a list of tags.
475 $channel->output($cur, sprintf(_('%1$s was tagged %2$s'),
477 // TRANS: Separator for list of tags.
478 implode(_(', '), $clean_tags)));
482 class UntagCommand extends TagCommand
484 function handle($channel)
486 $profile = $this->getProfile($this->other);
487 $cur = $this->user->getProfile();
490 // TRANS: Client error displayed trying to perform an action related to a non-existing profile.
491 $channel->error($cur, _('No such profile.'));
494 if (!$cur->canTag($profile)) {
495 // TRANS: Error displayed when trying to tag a user that cannot be tagged.
496 $channel->error($cur, _('You cannot tag this user.'));
500 $tags = array_map('common_canonical_tag', preg_split('/[\s,]+/', $this->tags));
502 foreach ($tags as $tag) {
503 if (!common_valid_profile_tag($tag)) {
504 // TRANS: Error displayed if a given tag is invalid.
505 // TRANS: %s is the invalid tag.
506 $channel->error($cur, sprintf(_('Invalid tag: "%s"'), $tag));
512 foreach ($tags as $tag) {
513 Profile_tag::unTag($cur->id, $profile->id, $tag);
515 } catch (Exception $e) {
516 // TRANS: Error displayed if untagging a user fails.
517 // TRANS: %1$s is the untagged user, %2$s is the error message (no punctuation).
518 $channel->error($cur, sprintf(_('Error untagging %1$s: %2$s'),
519 $profile->nickname, $e->getMessage()));
523 // TRANS: Succes message displayed if untagging a user succeeds.
524 // TRANS: %1$s is the untagged user's nickname, %2$s is a list of tags.
525 $channel->output($cur, sprintf(_('The following tag(s) were removed from user %1$s: %2$s.'),
527 // TRANS: Separator for list of tags.
528 implode(_(', '), $tags)));
532 class WhoisCommand extends Command
535 function __construct($user, $other)
537 parent::__construct($user);
538 $this->other = $other;
541 function handle($channel)
543 $recipient = $this->getProfile($this->other);
545 // TRANS: Whois output.
546 // TRANS: %1$s nickname of the queried user, %2$s is their profile URL.
547 $whois = sprintf(_m('WHOIS',"%1\$s (%2\$s)"), $recipient->nickname,
548 $recipient->profileurl);
549 if ($recipient->fullname) {
550 // TRANS: Whois output. %s is the full name of the queried user.
551 $whois .= "\n" . sprintf(_('Fullname: %s'), $recipient->fullname);
553 if ($recipient->location) {
554 // TRANS: Whois output. %s is the location of the queried user.
555 $whois .= "\n" . sprintf(_('Location: %s'), $recipient->location);
557 if ($recipient->homepage) {
558 // TRANS: Whois output. %s is the homepage of the queried user.
559 $whois .= "\n" . sprintf(_('Homepage: %s'), $recipient->homepage);
561 if ($recipient->bio) {
562 // TRANS: Whois output. %s is the bio information of the queried user.
563 $whois .= "\n" . sprintf(_('About: %s'), $recipient->bio);
565 $channel->output($this->user, $whois);
569 class MessageCommand extends Command
573 function __construct($user, $other, $text)
575 parent::__construct($user);
576 $this->other = $other;
580 function handle($channel)
583 $other = $this->getUser($this->other);
584 } catch (CommandException $e) {
586 $profile = $this->getProfile($this->other);
587 } catch (CommandException $f) {
590 // TRANS: Command exception text shown when trying to send a direct message to a remote user (a user not registered at the current server).
591 // TRANS: %s is a remote profile.
592 throw new CommandException(sprintf(_('%s is a remote profile; you can only send direct messages to users on the same server.'), $this->other));
595 $len = mb_strlen($this->text);
598 // TRANS: Command exception text shown when trying to send a direct message to another user without content.
599 $channel->error($this->user, _('No content!'));
603 $this->text = $this->user->shortenLinks($this->text);
605 if (Message::contentTooLong($this->text)) {
606 // XXX: i18n. Needs plural support.
607 // TRANS: Message given if content is too long. %1$sd is used for plural.
608 // TRANS: %1$d is the maximum number of characters, %2$d is the number of submitted characters.
609 $channel->error($this->user, sprintf(_m('Message too long - maximum is %1$d character, you sent %2$d.',
610 'Message too long - maximum is %1$d characters, you sent %2$d.',
611 Message::maxContent()),
612 Message::maxContent(), mb_strlen($this->text)));
617 // TRANS: Error text shown when trying to send a direct message to a user that does not exist.
618 $channel->error($this->user, _('No such user.'));
620 } else if (!$this->user->mutuallySubscribed($other)) {
621 // 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).
622 $channel->error($this->user, _('You can\'t send a message to this user.'));
624 } else if ($this->user->id == $other->id) {
625 // TRANS: Error text shown when trying to send a direct message to self.
626 $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
629 $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
632 // TRANS: Message given have sent a direct message to another user.
633 // TRANS: %s is the name of the other user.
634 $channel->output($this->user, sprintf(_('Direct message to %s sent.'), $this->other));
636 // TRANS: Error text shown sending a direct message fails with an unknown reason.
637 $channel->error($this->user, _('Error sending direct message.'));
642 class RepeatCommand extends Command
645 function __construct($user, $other)
647 parent::__construct($user);
648 $this->other = $other;
651 function handle($channel)
653 $notice = $this->getNotice($this->other);
656 $repeat = $notice->repeat($this->user->id, $channel->source());
657 $recipient = $notice->getProfile();
659 // TRANS: Message given having repeated a notice from another user.
660 // TRANS: %s is the name of the user for which the notice was repeated.
661 $channel->output($this->user, sprintf(_('Notice from %s repeated.'), $recipient->nickname));
662 } catch (Exception $e) {
663 $channel->error($this->user, $e->getMessage());
668 class ReplyCommand extends Command
672 function __construct($user, $other, $text)
674 parent::__construct($user);
675 $this->other = $other;
679 function handle($channel)
681 $notice = $this->getNotice($this->other);
682 $recipient = $notice->getProfile();
684 $len = mb_strlen($this->text);
687 // TRANS: Command exception text shown when trying to reply to a notice without providing content for the reply.
688 $channel->error($this->user, _('No content!'));
692 $this->text = $this->user->shortenLinks($this->text);
694 if (Notice::contentTooLong($this->text)) {
695 // XXX: i18n. Needs plural support.
696 // TRANS: Message given if content of a notice for a reply is too long. %1$d is used for plural.
697 // TRANS: %1$d is the maximum number of characters, %2$d is the number of submitted characters.
698 $channel->error($this->user, sprintf(_m('Notice too long - maximum is %1$d character, you sent %2$d.',
699 'Notice too long - maximum is %1$d characters, you sent %2$d.',
700 Notice::maxContent()),
701 Notice::maxContent(), mb_strlen($this->text)));
705 $notice = Notice::saveNew($this->user->id, $this->text, $channel->source(),
706 array('reply_to' => $notice->id));
709 // TRANS: Text shown having sent a reply to a notice successfully.
710 // TRANS: %s is the nickname of the user of the notice the reply was sent to.
711 $channel->output($this->user, sprintf(_('Reply to %s sent.'), $recipient->nickname));
713 // TRANS: Error text shown when a reply to a notice fails with an unknown reason.
714 $channel->error($this->user, _('Error saving notice.'));
720 class GetCommand extends Command
724 function __construct($user, $other)
726 parent::__construct($user);
727 $this->other = $other;
730 function handle($channel)
732 $target = $this->getProfile($this->other);
734 $notice = $target->getCurrentNotice();
736 // TRANS: Error text shown when a last user notice is requested and it does not exist.
737 $channel->error($this->user, _('User has no last notice.'));
740 $notice_content = $notice->content;
742 $channel->output($this->user, $target->nickname . ": " . $notice_content);
746 class SubCommand extends Command
750 function __construct($user, $other)
752 parent::__construct($user);
753 $this->other = $other;
756 function handle($channel)
760 // TRANS: Error text shown when no username was provided when issuing a subscribe command.
761 $channel->error($this->user, _('Specify the name of the user to subscribe to.'));
765 $target = $this->getProfile($this->other);
767 $remote = Remote_profile::staticGet('id', $target->id);
769 // TRANS: Command exception text shown when trying to subscribe to an OMB profile using the subscribe command.
770 throw new CommandException(_("Can't subscribe to OMB profiles by command."));
774 Subscription::start($this->user->getProfile(),
776 // TRANS: Text shown after having subscribed to another user successfully.
777 // TRANS: %s is the name of the user the subscription was requested for.
778 $channel->output($this->user, sprintf(_('Subscribed to %s.'), $this->other));
779 } catch (Exception $e) {
780 $channel->error($this->user, $e->getMessage());
785 class UnsubCommand extends Command
789 function __construct($user, $other)
791 parent::__construct($user);
792 $this->other = $other;
795 function handle($channel)
798 // TRANS: Error text shown when no username was provided when issuing an unsubscribe command.
799 $channel->error($this->user, _('Specify the name of the user to unsubscribe from.'));
803 $target = $this->getProfile($this->other);
806 Subscription::cancel($this->user->getProfile(),
808 // TRANS: Text shown after having unsubscribed from another user successfully.
809 // TRANS: %s is the name of the user the unsubscription was requested for.
810 $channel->output($this->user, sprintf(_('Unsubscribed from %s.'), $this->other));
811 } catch (Exception $e) {
812 $channel->error($this->user, $e->getMessage());
817 class OffCommand extends Command
821 function __construct($user, $other=null)
823 parent::__construct($user);
824 $this->other = $other;
826 function handle($channel)
829 // TRANS: Error text shown when issuing the command "off" with a setting which has not yet been implemented.
830 $channel->error($this->user, _("Command not yet implemented."));
832 if ($channel->off($this->user)) {
833 // TRANS: Text shown when issuing the command "off" successfully.
834 $channel->output($this->user, _('Notification off.'));
836 // TRANS: Error text shown when the command "off" fails for an unknown reason.
837 $channel->error($this->user, _('Can\'t turn off notification.'));
843 class OnCommand extends Command
846 function __construct($user, $other=null)
848 parent::__construct($user);
849 $this->other = $other;
852 function handle($channel)
855 // TRANS: Error text shown when issuing the command "on" with a setting which has not yet been implemented.
856 $channel->error($this->user, _("Command not yet implemented."));
858 if ($channel->on($this->user)) {
859 // TRANS: Text shown when issuing the command "on" successfully.
860 $channel->output($this->user, _('Notification on.'));
862 // TRANS: Error text shown when the command "on" fails for an unknown reason.
863 $channel->error($this->user, _('Can\'t turn on notification.'));
869 class LoginCommand extends Command
871 function handle($channel)
873 $disabled = common_config('logincommand','disabled');
874 $disabled = isset($disabled) && $disabled;
876 // TRANS: Error text shown when issuing the login command while login is disabled.
877 $channel->error($this->user, _('Login command is disabled.'));
882 $login_token = Login_token::makeNew($this->user);
883 } catch (Exception $e) {
884 $channel->error($this->user, $e->getMessage());
887 $channel->output($this->user,
888 // TRANS: Text shown after issuing the login command successfully.
889 // TRANS: %s is a logon link..
890 sprintf(_('This link is useable only once and is valid for only 2 minutes: %s.'),
891 common_local_url('otp',
892 array('user_id' => $login_token->user_id, 'token' => $login_token->token))));
896 class LoseCommand extends Command
900 function __construct($user, $other)
902 parent::__construct($user);
903 $this->other = $other;
906 function execute($channel)
909 // TRANS: Error text shown when no username was provided when issuing the command.
910 $channel->error($this->user, _('Specify the name of the user to unsubscribe from.'));
914 $result = Subscription::cancel($this->getProfile($this->other), $this->user->getProfile());
917 // TRANS: Text shown after issuing the lose command successfully (stop another user from following the current user).
918 // TRANS: %s is the name of the user the unsubscription was requested for.
919 $channel->output($this->user, sprintf(_('Unsubscribed %s.'), $this->other));
921 $channel->error($this->user, $result);
926 class SubscriptionsCommand extends Command
928 function handle($channel)
930 $profile = $this->user->getSubscriptions(0);
932 while ($profile->fetch()) {
933 $nicknames[]=$profile->nickname;
935 if(count($nicknames)==0){
936 // TRANS: Text shown after requesting other users a user is subscribed to without having any subscriptions.
937 $out=_('You are not subscribed to anyone.');
939 // TRANS: Text shown after requesting other users a user is subscribed to.
940 // TRANS: This message supports plural forms. This message is followed by a
941 // TRANS: hard coded space and a comma separated list of subscribed users.
942 $out = _m('You are subscribed to this person:',
943 'You are subscribed to these people:',
946 $out .= implode(', ',$nicknames);
948 $channel->output($this->user,$out);
952 class SubscribersCommand extends Command
954 function handle($channel)
956 $profile = $this->user->getSubscribers();
958 while ($profile->fetch()) {
959 $nicknames[]=$profile->nickname;
961 if(count($nicknames)==0){
962 // TRANS: Text shown after requesting other users that are subscribed to a user
963 // TRANS: (followers) without having any subscribers.
964 $out=_('No one is subscribed to you.');
966 // TRANS: Text shown after requesting other users that are subscribed to a user (followers).
967 // TRANS: This message supports plural forms. This message is followed by a
968 // TRANS: hard coded space and a comma separated list of subscribing users.
969 $out = _m('This person is subscribed to you:',
970 'These people are subscribed to you:',
973 $out .= implode(', ',$nicknames);
975 $channel->output($this->user,$out);
979 class GroupsCommand extends Command
981 function handle($channel)
983 $group = $this->user->getGroups();
985 while ($group->fetch()) {
986 $groups[]=$group->nickname;
988 if(count($groups)==0){
989 // TRANS: Text shown after requesting groups a user is subscribed to without having
990 // TRANS: any group subscriptions.
991 $out=_('You are not a member of any groups.');
993 // TRANS: Text shown after requesting groups a user is subscribed to.
994 // TRANS: This message supports plural forms. This message is followed by a
995 // TRANS: hard coded space and a comma separated list of subscribed groups.
996 $out = _m('You are a member of this group:',
997 'You are a member of these groups:',
999 $out.=implode(', ',$groups);
1001 $channel->output($this->user,$out);
1005 class HelpCommand extends Command
1007 function handle($channel)
1009 // TRANS: Header line of help text for commands.
1010 $out = array(_m('COMMANDHELP', "Commands:"));
1011 $commands = array(// TRANS: Help message for IM/SMS command "on".
1012 "on" => _m('COMMANDHELP', "turn on notifications"),
1013 // TRANS: Help message for IM/SMS command "off".
1014 "off" => _m('COMMANDHELP', "turn off notifications"),
1015 // TRANS: Help message for IM/SMS command "help".
1016 "help" => _m('COMMANDHELP', "show this help"),
1017 // TRANS: Help message for IM/SMS command "follow <nickname>".
1018 "follow <nickname>" => _m('COMMANDHELP', "subscribe to user"),
1019 // TRANS: Help message for IM/SMS command "groups".
1020 "groups" => _m('COMMANDHELP', "lists the groups you have joined"),
1021 // TRANS: Help message for IM/SMS command "tag".
1022 "tag <nickname> <tags>" => _m('COMMANDHELP',"tag a user"),
1023 // TRANS: Help message for IM/SMS command "untag".
1024 "untag <nickname> <tags>" => _m('COMMANDHELP',"untag a user"),
1025 // TRANS: Help message for IM/SMS command "subscriptions".
1026 "subscriptions" => _m('COMMANDHELP', "list the people you follow"),
1027 // TRANS: Help message for IM/SMS command "subscribers".
1028 "subscribers" => _m('COMMANDHELP', "list the people that follow you"),
1029 // TRANS: Help message for IM/SMS command "leave <nickname>".
1030 "leave <nickname>" => _m('COMMANDHELP', "unsubscribe from user"),
1031 // TRANS: Help message for IM/SMS command "d <nickname> <text>".
1032 "d <nickname> <text>" => _m('COMMANDHELP', "direct message to user"),
1033 // TRANS: Help message for IM/SMS command "get <nickname>".
1034 "get <nickname>" => _m('COMMANDHELP', "get last notice from user"),
1035 // TRANS: Help message for IM/SMS command "whois <nickname>".
1036 "whois <nickname>" => _m('COMMANDHELP', "get profile info on user"),
1037 // TRANS: Help message for IM/SMS command "lose <nickname>".
1038 "lose <nickname>" => _m('COMMANDHELP', "force user to stop following you"),
1039 // TRANS: Help message for IM/SMS command "fav <nickname>".
1040 "fav <nickname>" => _m('COMMANDHELP', "add user's last notice as a 'fave'"),
1041 // TRANS: Help message for IM/SMS command "fav #<notice_id>".
1042 "fav #<notice_id>" => _m('COMMANDHELP', "add notice with the given id as a 'fave'"),
1043 // TRANS: Help message for IM/SMS command "repeat #<notice_id>".
1044 "repeat #<notice_id>" => _m('COMMANDHELP', "repeat a notice with a given id"),
1045 // TRANS: Help message for IM/SMS command "repeat <nickname>".
1046 "repeat <nickname>" => _m('COMMANDHELP', "repeat the last notice from user"),
1047 // TRANS: Help message for IM/SMS command "reply #<notice_id>".
1048 "reply #<notice_id>" => _m('COMMANDHELP', "reply to notice with a given id"),
1049 // TRANS: Help message for IM/SMS command "reply <nickname>".
1050 "reply <nickname>" => _m('COMMANDHELP', "reply to the last notice from user"),
1051 // TRANS: Help message for IM/SMS command "join <group>".
1052 "join <group>" => _m('COMMANDHELP', "join group"),
1053 // TRANS: Help message for IM/SMS command "login".
1054 "login" => _m('COMMANDHELP', "Get a link to login to the web interface"),
1055 // TRANS: Help message for IM/SMS command "drop <group>".
1056 "drop <group>" => _m('COMMANDHELP', "leave group"),
1057 // TRANS: Help message for IM/SMS command "stats".
1058 "stats" => _m('COMMANDHELP', "get your stats"),
1059 // TRANS: Help message for IM/SMS command "stop".
1060 "stop" => _m('COMMANDHELP', "same as 'off'"),
1061 // TRANS: Help message for IM/SMS command "quit".
1062 "quit" => _m('COMMANDHELP', "same as 'off'"),
1063 // TRANS: Help message for IM/SMS command "sub <nickname>".
1064 "sub <nickname>" => _m('COMMANDHELP', "same as 'follow'"),
1065 // TRANS: Help message for IM/SMS command "unsub <nickname>".
1066 "unsub <nickname>" => _m('COMMANDHELP', "same as 'leave'"),
1067 // TRANS: Help message for IM/SMS command "last <nickname>".
1068 "last <nickname>" => _m('COMMANDHELP', "same as 'get'"),
1069 // TRANS: Help message for IM/SMS command "on <nickname>".
1070 "on <nickname>" => _m('COMMANDHELP', "not yet implemented."),
1071 // TRANS: Help message for IM/SMS command "off <nickname>".
1072 "off <nickname>" => _m('COMMANDHELP', "not yet implemented."),
1073 // TRANS: Help message for IM/SMS command "nudge <nickname>".
1074 "nudge <nickname>" => _m('COMMANDHELP', "remind a user to update."),
1075 // TRANS: Help message for IM/SMS command "invite <phone number>".
1076 "invite <phone number>" => _m('COMMANDHELP', "not yet implemented."),
1077 // TRANS: Help message for IM/SMS command "track <word>".
1078 "track <word>" => _m('COMMANDHELP', "not yet implemented."),
1079 // TRANS: Help message for IM/SMS command "untrack <word>".
1080 "untrack <word>" => _m('COMMANDHELP', "not yet implemented."),
1081 // TRANS: Help message for IM/SMS command "track off".
1082 "track off" => _m('COMMANDHELP', "not yet implemented."),
1083 // TRANS: Help message for IM/SMS command "untrack all".
1084 "untrack all" => _m('COMMANDHELP', "not yet implemented."),
1085 // TRANS: Help message for IM/SMS command "tracks".
1086 "tracks" => _m('COMMANDHELP', "not yet implemented."),
1087 // TRANS: Help message for IM/SMS command "tracking".
1088 "tracking" => _m('COMMANDHELP', "not yet implemented."));
1090 // Give plugins a chance to add or override...
1091 Event::handle('HelpCommandMessages', array($this, &$commands));
1092 foreach ($commands as $command => $help) {
1093 $out[] = "$command - $help";
1095 $channel->output($this->user, implode("\n", $out));