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/channel.php');
29 function __construct($user=null)
34 function execute($channel)
40 class UnimplementedCommand extends Command
42 function execute($channel)
44 $channel->error($this->user, _("Sorry, this command is not yet implemented."));
48 class TrackingCommand extends UnimplementedCommand
52 class TrackOffCommand extends UnimplementedCommand
56 class TrackCommand extends UnimplementedCommand
59 function __construct($user, $word)
61 parent::__construct($user);
66 class UntrackCommand extends UnimplementedCommand
69 function __construct($user, $word)
71 parent::__construct($user);
76 class NudgeCommand extends UnimplementedCommand
79 function __construct($user, $other)
81 parent::__construct($user);
82 $this->other = $other;
86 class InviteCommand extends UnimplementedCommand
89 function __construct($user, $other)
91 parent::__construct($user);
92 $this->other = $other;
96 class StatsCommand extends Command
98 function execute($channel)
100 $profile = $this->user->getProfile();
102 $subs_count = $profile->subscriptionCount();
103 $subbed_count = $profile->subscriberCount();
104 $notice_count = $profile->noticeCount();
106 $channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n".
107 "Subscribers: %2\$s\n".
115 class FavCommand extends Command
119 function __construct($user, $other)
121 parent::__construct($user);
122 $this->other = $other;
125 function execute($channel)
129 common_relative_profile($this->user, common_canonical_nickname($this->other));
132 $channel->error($this->user, _('No such user.'));
135 $notice = $recipient->getCurrentNotice();
137 $channel->error($this->user, _('User has no last notice'));
141 $fave = Fave::addNew($this->user, $notice);
144 $channel->error($this->user, _('Could not create favorite.'));
148 $other = User::staticGet('id', $recipient->id);
150 if ($other && $other->id != $user->id) {
151 if ($other->email && $other->emailnotifyfav) {
152 mail_notify_fave($other, $this->user, $notice);
156 $this->user->blowFavesCache();
158 $channel->output($this->user, _('Notice marked as fave.'));
162 class JoinCommand extends Command
166 function __construct($user, $other)
168 parent::__construct($user);
169 $this->other = $other;
172 function execute($channel)
175 $nickname = common_canonical_nickname($this->other);
176 $group = User_group::staticGet('nickname', $nickname);
180 $channel->error($cur, _('No such group.'));
184 if ($cur->isMember($group)) {
185 $channel->error($cur, _('You are already a member of that group'));
188 if (Group_block::isBlocked($group, $cur->getProfile())) {
189 $channel->error($cur, _('You have been blocked from that group by the admin.'));
193 $member = new Group_member();
195 $member->group_id = $group->id;
196 $member->profile_id = $cur->id;
197 $member->created = common_sql_now();
199 $result = $member->insert();
201 common_log_db_error($member, 'INSERT', __FILE__);
202 $channel->error($cur, sprintf(_('Could not join user %s to group %s'),
203 $cur->nickname, $group->nickname));
207 $channel->output($cur, sprintf(_('%s joined group %s'),
213 class DropCommand extends Command
217 function __construct($user, $other)
219 parent::__construct($user);
220 $this->other = $other;
223 function execute($channel)
226 $nickname = common_canonical_nickname($this->other);
227 $group = User_group::staticGet('nickname', $nickname);
231 $channel->error($cur, _('No such group.'));
235 if (!$cur->isMember($group)) {
236 $channel->error($cur, _('You are not a member of that group.'));
240 $member = new Group_member();
242 $member->group_id = $group->id;
243 $member->profile_id = $cur->id;
245 if (!$member->find(true)) {
246 $channel->error($cur,_('Could not find membership record.'));
249 $result = $member->delete();
251 common_log_db_error($member, 'INSERT', __FILE__);
252 $channel->error($cur, sprintf(_('Could not remove user %s to group %s'),
253 $cur->nickname, $group->nickname));
257 $channel->output($cur, sprintf(_('%s left group %s'),
264 class WhoisCommand extends Command
267 function __construct($user, $other)
269 parent::__construct($user);
270 $this->other = $other;
273 function execute($channel)
276 common_relative_profile($this->user, common_canonical_nickname($this->other));
279 $channel->error($this->user, _('No such user.'));
283 $whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
284 $recipient->profileurl);
285 if ($recipient->fullname) {
286 $whois .= "\n" . sprintf(_('Fullname: %s'), $recipient->fullname);
288 if ($recipient->location) {
289 $whois .= "\n" . sprintf(_('Location: %s'), $recipient->location);
291 if ($recipient->homepage) {
292 $whois .= "\n" . sprintf(_('Homepage: %s'), $recipient->homepage);
294 if ($recipient->bio) {
295 $whois .= "\n" . sprintf(_('About: %s'), $recipient->bio);
297 $channel->output($this->user, $whois);
301 class MessageCommand extends Command
305 function __construct($user, $other, $text)
307 parent::__construct($user);
308 $this->other = $other;
312 function execute($channel)
314 $other = User::staticGet('nickname', common_canonical_nickname($this->other));
316 $len = mb_strlen($this->text);
319 $channel->error($this->user, _('No content!'));
323 $this->text = common_shorten_links($this->text);
325 if (Message::contentTooLong($this->text)) {
326 $channel->error($this->user, sprintf(_('Message too long - maximum is %d characters, you sent %d'),
327 Message::maxContent(), mb_strlen($this->text)));
332 $channel->error($this->user, _('No such user.'));
334 } else if (!$this->user->mutuallySubscribed($other)) {
335 $channel->error($this->user, _('You can\'t send a message to this user.'));
337 } else if ($this->user->id == $other->id) {
338 $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
341 $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
343 $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
345 $channel->error($this->user, _('Error sending direct message.'));
350 class GetCommand extends Command
355 function __construct($user, $other)
357 parent::__construct($user);
358 $this->other = $other;
361 function execute($channel)
363 $target_nickname = common_canonical_nickname($this->other);
366 common_relative_profile($this->user, $target_nickname);
369 $channel->error($this->user, _('No such user.'));
372 $notice = $target->getCurrentNotice();
374 $channel->error($this->user, _('User has no last notice'));
377 $notice_content = $notice->content;
379 $channel->output($this->user, $target_nickname . ": " . $notice_content);
383 class SubCommand extends Command
388 function __construct($user, $other)
390 parent::__construct($user);
391 $this->other = $other;
394 function execute($channel)
398 $channel->error($this->user, _('Specify the name of the user to subscribe to'));
402 $result = subs_subscribe_user($this->user, $this->other);
404 if ($result == 'true') {
405 $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
407 $channel->error($this->user, $result);
412 class UnsubCommand extends Command
417 function __construct($user, $other)
419 parent::__construct($user);
420 $this->other = $other;
423 function execute($channel)
426 $channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
430 $result=subs_unsubscribe_user($this->user, $this->other);
433 $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
435 $channel->error($this->user, $result);
440 class OffCommand extends Command
443 function __construct($user, $other=null)
445 parent::__construct($user);
446 $this->other = $other;
448 function execute($channel)
451 $channel->error($this->user, _("Command not yet implemented."));
453 if ($channel->off($this->user)) {
454 $channel->output($this->user, _('Notification off.'));
456 $channel->error($this->user, _('Can\'t turn off notification.'));
462 class OnCommand extends Command
465 function __construct($user, $other=null)
467 parent::__construct($user);
468 $this->other = $other;
471 function execute($channel)
474 $channel->error($this->user, _("Command not yet implemented."));
476 if ($channel->on($this->user)) {
477 $channel->output($this->user, _('Notification on.'));
479 $channel->error($this->user, _('Can\'t turn on notification.'));
485 class HelpCommand extends Command
487 function execute($channel)
489 $channel->output($this->user,
491 "on - turn on notifications\n".
492 "off - turn off notifications\n".
493 "help - show this help\n".
494 "follow <nickname> - subscribe to user\n".
495 "leave <nickname> - unsubscribe from user\n".
496 "d <nickname> <text> - direct message to user\n".
497 "get <nickname> - get last notice from user\n".
498 "whois <nickname> - get profile info on user\n".
499 "fav <nickname> - add user's last notice as a 'fave'\n".
500 "join <group> - join group\n".
501 "drop <group> - leave group\n".
502 "stats - get your stats\n".
503 "stop - same as 'off'\n".
504 "quit - same as 'off'\n".
505 "sub <nickname> - same as 'follow'\n".
506 "unsub <nickname> - same as 'leave'\n".
507 "last <nickname> - same as 'get'\n".
508 "on <nickname> - not yet implemented.\n".
509 "off <nickname> - not yet implemented.\n".
510 "nudge <nickname> - not yet implemented.\n".
511 "invite <phone number> - not yet implemented.\n".
512 "track <word> - not yet implemented.\n".
513 "untrack <word> - not yet implemented.\n".
514 "track off - not yet implemented.\n".
515 "untrack all - not yet implemented.\n".
516 "tracks - not yet implemented.\n".
517 "tracking - not yet implemented.\n"));