3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, Control Yourself, 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('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)
101 $subs = new Subscription();
102 $subs->subscriber = $this->user->id;
103 $subs_count = (int) $subs->count() - 1;
105 $subbed = new Subscription();
106 $subbed->subscribed = $this->user->id;
107 $subbed_count = (int) $subbed->count() - 1;
109 $notices = new Notice();
110 $notices->profile_id = $this->user->id;
111 $notice_count = (int) $notices->count();
113 $channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n".
114 "Subscribers: %2\$s\n".
122 class FavCommand extends Command
127 function __construct($user, $other)
129 parent::__construct($user);
130 $this->other = $other;
133 function execute($channel)
137 common_relative_profile($this->user, common_canonical_nickname($this->other));
140 $channel->error($this->user, _('No such user.'));
143 $notice = $recipient->getCurrentNotice();
145 $channel->error($this->user, _('User has no last notice'));
149 $fave = Fave::addNew($this->user, $notice);
152 $channel->error($this->user, _('Could not create favorite.'));
156 $other = User::staticGet('id', $recipient->id);
158 if ($other && $other->id != $user->id) {
159 if ($other->email && $other->emailnotifyfav) {
160 mail_notify_fave($other, $this->user, $notice);
164 $this->user->blowFavesCache();
166 $channel->output($this->user, _('Notice marked as fave.'));
170 class WhoisCommand extends Command
173 function __construct($user, $other)
175 parent::__construct($user);
176 $this->other = $other;
179 function execute($channel)
182 common_relative_profile($this->user, common_canonical_nickname($this->other));
185 $channel->error($this->user, _('No such user.'));
189 $whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
190 $recipient->profileurl);
191 if ($recipient->fullname) {
192 $whois .= "\n" . sprintf(_('Fullname: %s'), $recipient->fullname);
194 if ($recipient->location) {
195 $whois .= "\n" . sprintf(_('Location: %s'), $recipient->location);
197 if ($recipient->homepage) {
198 $whois .= "\n" . sprintf(_('Homepage: %s'), $recipient->homepage);
200 if ($recipient->bio) {
201 $whois .= "\n" . sprintf(_('About: %s'), $recipient->bio);
203 $channel->output($this->user, $whois);
207 class MessageCommand extends Command
211 function __construct($user, $other, $text)
213 parent::__construct($user);
214 $this->other = $other;
218 function execute($channel)
220 $other = User::staticGet('nickname', common_canonical_nickname($this->other));
221 $len = mb_strlen($this->text);
223 $channel->error($this->user, _('No content!'));
225 } else if ($len > 140) {
226 $content = common_shorten_links($content);
227 if (mb_strlen($content) > 140) {
228 $channel->error($this->user, sprintf(_('Message too long - maximum is 140 characters, you sent %d'), $len));
234 $channel->error($this->user, _('No such user.'));
236 } else if (!$this->user->mutuallySubscribed($other)) {
237 $channel->error($this->user, _('You can\'t send a message to this user.'));
239 } else if ($this->user->id == $other->id) {
240 $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
243 $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
245 $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
247 $channel->error($this->user, _('Error sending direct message.'));
252 class GetCommand extends Command
257 function __construct($user, $other)
259 parent::__construct($user);
260 $this->other = $other;
263 function execute($channel)
265 $target_nickname = common_canonical_nickname($this->other);
268 common_relative_profile($this->user, $target_nickname);
271 $channel->error($this->user, _('No such user.'));
274 $notice = $target->getCurrentNotice();
276 $channel->error($this->user, _('User has no last notice'));
279 $notice_content = $notice->content;
281 $channel->output($this->user, $target_nickname . ": " . $notice_content);
285 class SubCommand extends Command
290 function __construct($user, $other)
292 parent::__construct($user);
293 $this->other = $other;
296 function execute($channel)
300 $channel->error($this->user, _('Specify the name of the user to subscribe to'));
304 $result = subs_subscribe_user($this->user, $this->other);
306 if ($result == 'true') {
307 $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
309 $channel->error($this->user, $result);
314 class UnsubCommand extends Command
319 function __construct($user, $other)
321 parent::__construct($user);
322 $this->other = $other;
325 function execute($channel)
328 $channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
332 $result=subs_unsubscribe_user($this->user, $this->other);
335 $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
337 $channel->error($this->user, $result);
342 class OffCommand extends Command
345 function __construct($user, $other=null)
347 parent::__construct($user);
348 $this->other = $other;
350 function execute($channel)
353 $channel->error($this->user, _("Command not yet implemented."));
355 if ($channel->off($this->user)) {
356 $channel->output($this->user, _('Notification off.'));
358 $channel->error($this->user, _('Can\'t turn off notification.'));
364 class OnCommand extends Command
367 function __construct($user, $other=null)
369 parent::__construct($user);
370 $this->other = $other;
373 function execute($channel)
376 $channel->error($this->user, _("Command not yet implemented."));
378 if ($channel->on($this->user)) {
379 $channel->output($this->user, _('Notification on.'));
381 $channel->error($this->user, _('Can\'t turn on notification.'));
387 class HelpCommand extends Command
389 function execute($channel)
391 $channel->output($this->user,
393 "on - turn on notifications\n".
394 "off - turn off notifications\n".
395 "help - show this help\n".
396 "follow <nickname> - subscribe to user\n".
397 "leave <nickname> - unsubscribe from user\n".
398 "d <nickname> <text> - direct message to user\n".
399 "get <nickname> - get last notice from user\n".
400 "whois <nickname> - get profile info on user\n".
401 "fav <nickname> - add user's last notice as a 'fave'\n".
402 "stats - get your stats\n".
403 "stop - same as 'off'\n".
404 "quit - same as 'off'\n".
405 "sub <nickname> - same as 'follow'\n".
406 "unsub <nickname> - same as 'leave'\n".
407 "last <nickname> - same as 'get'\n".
408 "on <nickname> - not yet implemented.\n".
409 "off <nickname> - not yet implemented.\n".
410 "nudge <nickname> - not yet implemented.\n".
411 "invite <phone number> - not yet implemented.\n".
412 "track <word> - not yet implemented.\n".
413 "untrack <word> - not yet implemented.\n".
414 "track off - not yet implemented.\n".
415 "untrack all - not yet implemented.\n".
416 "tracks - not yet implemented.\n".
417 "tracking - not yet implemented.\n"));