X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fcommand.php;h=39865234b6611d1cd79bb38409d13363cdc25c39;hb=31c1177970124cee31823cab3a11542c23b4126d;hp=ae69f04a1366b80d990110344374db868c40ef09;hpb=65eeb7cba530e45b8d8a25644505619e8af63971;p=quix0rs-gnu-social.git diff --git a/lib/command.php b/lib/command.php index ae69f04a13..39865234b6 100644 --- a/lib/command.php +++ b/lib/command.php @@ -139,7 +139,7 @@ class Command { $user = null; if (Event::handle('StartCommandGetUser', array($this, $arg, &$user))) { - $user = User::staticGet('nickname', $arg); + $user = User::staticGet('nickname', Nickname::normalize($arg)); } Event::handle('EndCommandGetUser', array($this, $arg, &$user)); if (!$user){ @@ -287,6 +287,18 @@ class FavCommand extends Command 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) { @@ -300,7 +312,7 @@ class FavCommand extends Command $other = User::staticGet('id', $notice->profile_id); - if ($other && $other->id != $user->id) { + if ($other && $other->id != $this->user->id) { if ($other->email && $other->emailnotifyfav) { mail_notify_fave($other, $this->user, $notice); } @@ -408,6 +420,104 @@ class DropCommand extends Command } } +class TagCommand extends Command +{ + var $other = null; + var $tags = null; + function __construct($user, $other, $tags) + { + parent::__construct($user); + $this->other = $other; + $this->tags = $tags; + } + + function handle($channel) + { + $profile = $this->getProfile($this->other); + $cur = $this->user->getProfile(); + + if (!$profile) { + $channel->error($cur, _('No such profile.')); + return; + } + if (!$cur->canTag($profile)) { + $channel->error($cur, _('You cannot tag this user.')); + return; + } + + $privs = array(); + $tags = preg_split('/[\s,]+/', $this->tags); + $clean_tags = array(); + + foreach ($tags as $tag) { + $private = @$tag[0] === '.'; + $tag = $clean_tags[] = common_canonical_tag($tag); + + if (!common_valid_profile_tag($tag)) { + $channel->error($cur, sprintf(_('Invalid tag: "%s"'), $tag)); + return; + } + $privs[$tag] = $private; + } + + try { + foreach ($clean_tags as $tag) { + Profile_tag::setTag($cur->id, $profile->id, $tag, null, $privs[$tag]); + } + } catch (Exception $e) { + $channel->error($cur, sprintf(_('Error tagging %s: %s'), + $profile->nickname, $e->getMessage())); + return; + } + + $channel->output($cur, sprintf(_('%1$s was tagged %2$s'), + $profile->nickname, + implode(', ', $clean_tags))); + } +} + + +class UntagCommand extends TagCommand +{ + function handle($channel) + { + $profile = $this->getProfile($this->other); + $cur = $this->user->getProfile(); + + if (!$profile) { + $channel->error($cur, _('No such profile.')); + return; + } + if (!$cur->canTag($profile)) { + $channel->error($cur, _('You cannot tag this user.')); + return; + } + + $tags = array_map('common_canonical_tag', preg_split('/[\s,]+/', $this->tags)); + + foreach ($tags as $tag) { + if (!common_valid_profile_tag($tag)) { + $channel->error($cur, sprintf(_('Invalid tag: "%s"'), $tag)); + return; + } + } + + try { + foreach ($tags as $tag) { + Profile_tag::unTag($cur->id, $profile->id, $tag); + } + } catch (Exception $e) { + $channel->error($cur, sprintf(_('Error untagging %s: %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))); + } +} + class WhoisCommand extends Command { var $other = null; @@ -479,7 +589,7 @@ class MessageCommand extends Command return; } - $this->text = common_shorten_links($this->text); + $this->text = $this->user->shortenLinks($this->text); if (Message::contentTooLong($this->text)) { // XXX: i18n. Needs plural support. @@ -582,7 +692,7 @@ class ReplyCommand extends Command return; } - $this->text = common_shorten_links($this->text); + $this->text = $this->user->shortenLinks($this->text); if (Notice::contentTooLong($this->text)) { // XXX: i18n. Needs plural support. @@ -718,7 +828,7 @@ class OffCommand extends Command } function handle($channel) { - if ($other) { + if ($this->other) { // TRANS: Error text shown when issuing the command "off" with a setting which has not yet been implemented. $channel->error($this->user, _("Command not yet implemented.")); } else { @@ -744,7 +854,7 @@ class OnCommand extends Command function handle($channel) { - if ($other) { + if ($this->other) { // TRANS: Error text shown when issuing the command "on" with a setting which has not yet been implemented. $channel->error($this->user, _("Command not yet implemented.")); } else { @@ -899,45 +1009,92 @@ class HelpCommand extends Command { function handle($channel) { - $channel->output($this->user, - // TRANS: Help text for commands. Do not translate the command names themselves; they are fixed strings. - _("Commands:\n". - "on - turn on notifications\n". - "off - turn off notifications\n". - "help - show this help\n". - "follow - subscribe to user\n". - "groups - lists the groups you have joined\n". - "subscriptions - list the people you follow\n". - "subscribers - list the people that follow you\n". - "leave - unsubscribe from user\n". - "d - direct message to user\n". - "get - get last notice from user\n". - "whois - get profile info on user\n". - "lose - force user to stop following you\n". - "fav - add user's last notice as a 'fave'\n". - "fav # - add notice with the given id as a 'fave'\n". - "repeat # - repeat a notice with a given id\n". - "repeat - repeat the last notice from user\n". - "reply # - reply to notice with a given id\n". - "reply - reply to the last notice from user\n". - "join - join group\n". - "login - Get a link to login to the web interface\n". - "drop - leave group\n". - "stats - get your stats\n". - "stop - same as 'off'\n". - "quit - same as 'off'\n". - "sub - same as 'follow'\n". - "unsub - same as 'leave'\n". - "last - same as 'get'\n". - "on - not yet implemented.\n". - "off - not yet implemented.\n". - "nudge - remind a user to update.\n". - "invite - not yet implemented.\n". - "track - not yet implemented.\n". - "untrack - not yet implemented.\n". - "track off - not yet implemented.\n". - "untrack all - not yet implemented.\n". - "tracks - not yet implemented.\n". - "tracking - not yet implemented.\n")); + // TRANS: Header line of help text for commands. + $out = array(_m('COMMANDHELP', "Commands:")); + $commands = array(// TRANS: Help message for IM/SMS command "on" + "on" => _m('COMMANDHELP', "turn on notifications"), + // TRANS: Help message for IM/SMS command "off" + "off" => _m('COMMANDHELP', "turn off notifications"), + // TRANS: Help message for IM/SMS command "help" + "help" => _m('COMMANDHELP', "show this help"), + // TRANS: Help message for IM/SMS command "follow " + "follow " => _m('COMMANDHELP', "subscribe to user"), + // 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" + "tag " => _m('COMMANDHELP',"tag a user"), + // TRANS: Help message for IM/SMS command "untag" + "untag " => _m('COMMANDHELP',"untag a user"), + // TRANS: Help message for IM/SMS command "subscriptions" + "subscriptions" => _m('COMMANDHELP', "list the people you follow"), + // 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 " + "leave " => _m('COMMANDHELP', "unsubscribe from user"), + // TRANS: Help message for IM/SMS command "d " + "d " => _m('COMMANDHELP', "direct message to user"), + // TRANS: Help message for IM/SMS command "get " + "get " => _m('COMMANDHELP', "get last notice from user"), + // TRANS: Help message for IM/SMS command "whois " + "whois " => _m('COMMANDHELP', "get profile info on user"), + // TRANS: Help message for IM/SMS command "lose " + "lose " => _m('COMMANDHELP', "force user to stop following you"), + // TRANS: Help message for IM/SMS command "fav " + "fav " => _m('COMMANDHELP', "add user's last notice as a 'fave'"), + // TRANS: Help message for IM/SMS command "fav #" + "fav #" => _m('COMMANDHELP', "add notice with the given id as a 'fave'"), + // TRANS: Help message for IM/SMS command "repeat #" + "repeat #" => _m('COMMANDHELP', "repeat a notice with a given id"), + // TRANS: Help message for IM/SMS command "repeat " + "repeat " => _m('COMMANDHELP', "repeat the last notice from user"), + // TRANS: Help message for IM/SMS command "reply #" + "reply #" => _m('COMMANDHELP', "reply to notice with a given id"), + // TRANS: Help message for IM/SMS command "reply " + "reply " => _m('COMMANDHELP', "reply to the last notice from user"), + // TRANS: Help message for IM/SMS command "join " + "join " => _m('COMMANDHELP', "join group"), + // 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 " + "drop " => _m('COMMANDHELP', "leave group"), + // TRANS: Help message for IM/SMS command "stats" + "stats" => _m('COMMANDHELP', "get your stats"), + // TRANS: Help message for IM/SMS command "stop" + "stop" => _m('COMMANDHELP', "same as 'off'"), + // TRANS: Help message for IM/SMS command "quit" + "quit" => _m('COMMANDHELP', "same as 'off'"), + // TRANS: Help message for IM/SMS command "sub " + "sub " => _m('COMMANDHELP', "same as 'follow'"), + // TRANS: Help message for IM/SMS command "unsub " + "unsub " => _m('COMMANDHELP', "same as 'leave'"), + // TRANS: Help message for IM/SMS command "last " + "last " => _m('COMMANDHELP', "same as 'get'"), + // TRANS: Help message for IM/SMS command "on " + "on " => _m('COMMANDHELP', "not yet implemented."), + // TRANS: Help message for IM/SMS command "off " + "off " => _m('COMMANDHELP', "not yet implemented."), + // TRANS: Help message for IM/SMS command "nudge " + "nudge " => _m('COMMANDHELP', "remind a user to update."), + // TRANS: Help message for IM/SMS command "invite " + "invite " => _m('COMMANDHELP', "not yet implemented."), + // TRANS: Help message for IM/SMS command "track " + "track " => _m('COMMANDHELP', "not yet implemented."), + // TRANS: Help message for IM/SMS command "untrack " + "untrack " => _m('COMMANDHELP', "not yet implemented."), + // 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" + "untrack all" => _m('COMMANDHELP', "not yet implemented."), + // TRANS: Help message for IM/SMS command "tracks" + "tracks" => _m('COMMANDHELP', "not yet implemented."), + // 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)); + foreach ($commands as $command => $help) { + $out[] = "$command - $help"; + } + $channel->output($this->user, implode("\n", $out)); } }