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)
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
120 function __construct($user, $other)
122 parent::__construct($user);
123 $this->other = $other;
126 function execute($channel)
130 common_relative_profile($this->user, common_canonical_nickname($this->other));
133 $channel->error($this->user, _('No such user.'));
136 $notice = $recipient->getCurrentNotice();
138 $channel->error($this->user, _('User has no last notice'));
142 $fave = Fave::addNew($this->user, $notice);
145 $channel->error($this->user, _('Could not create favorite.'));
149 $other = User::staticGet('id', $recipient->id);
151 if ($other && $other->id != $user->id) {
152 if ($other->email && $other->emailnotifyfav) {
153 mail_notify_fave($other, $this->user, $notice);
157 $this->user->blowFavesCache();
159 $channel->output($this->user, _('Notice marked as fave.'));
163 class WhoisCommand extends Command
166 function __construct($user, $other)
168 parent::__construct($user);
169 $this->other = $other;
172 function execute($channel)
175 common_relative_profile($this->user, common_canonical_nickname($this->other));
178 $channel->error($this->user, _('No such user.'));
182 $whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
183 $recipient->profileurl);
184 if ($recipient->fullname) {
185 $whois .= "\n" . sprintf(_('Fullname: %s'), $recipient->fullname);
187 if ($recipient->location) {
188 $whois .= "\n" . sprintf(_('Location: %s'), $recipient->location);
190 if ($recipient->homepage) {
191 $whois .= "\n" . sprintf(_('Homepage: %s'), $recipient->homepage);
193 if ($recipient->bio) {
194 $whois .= "\n" . sprintf(_('About: %s'), $recipient->bio);
196 $channel->output($this->user, $whois);
200 class MessageCommand extends Command
204 function __construct($user, $other, $text)
206 parent::__construct($user);
207 $this->other = $other;
211 function execute($channel)
213 $other = User::staticGet('nickname', common_canonical_nickname($this->other));
214 $len = mb_strlen($this->text);
216 $channel->error($this->user, _('No content!'));
218 } else if ($len > 140) {
219 $content = common_shorten_links($content);
220 if (mb_strlen($content) > 140) {
221 $channel->error($this->user, sprintf(_('Message too long - maximum is 140 characters, you sent %d'), $len));
227 $channel->error($this->user, _('No such user.'));
229 } else if (!$this->user->mutuallySubscribed($other)) {
230 $channel->error($this->user, _('You can\'t send a message to this user.'));
232 } else if ($this->user->id == $other->id) {
233 $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
236 $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
238 $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
240 $channel->error($this->user, _('Error sending direct message.'));
245 class GetCommand extends Command
250 function __construct($user, $other)
252 parent::__construct($user);
253 $this->other = $other;
256 function execute($channel)
258 $target_nickname = common_canonical_nickname($this->other);
261 common_relative_profile($this->user, $target_nickname);
264 $channel->error($this->user, _('No such user.'));
267 $notice = $target->getCurrentNotice();
269 $channel->error($this->user, _('User has no last notice'));
272 $notice_content = $notice->content;
274 $channel->output($this->user, $target_nickname . ": " . $notice_content);
278 class SubCommand extends Command
283 function __construct($user, $other)
285 parent::__construct($user);
286 $this->other = $other;
289 function execute($channel)
293 $channel->error($this->user, _('Specify the name of the user to subscribe to'));
297 $result = subs_subscribe_user($this->user, $this->other);
299 if ($result == 'true') {
300 $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
302 $channel->error($this->user, $result);
307 class UnsubCommand extends Command
312 function __construct($user, $other)
314 parent::__construct($user);
315 $this->other = $other;
318 function execute($channel)
321 $channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
325 $result=subs_unsubscribe_user($this->user, $this->other);
328 $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
330 $channel->error($this->user, $result);
335 class OffCommand extends Command
338 function __construct($user, $other=null)
340 parent::__construct($user);
341 $this->other = $other;
343 function execute($channel)
346 $channel->error($this->user, _("Command not yet implemented."));
348 if ($channel->off($this->user)) {
349 $channel->output($this->user, _('Notification off.'));
351 $channel->error($this->user, _('Can\'t turn off notification.'));
357 class OnCommand extends Command
360 function __construct($user, $other=null)
362 parent::__construct($user);
363 $this->other = $other;
366 function execute($channel)
369 $channel->error($this->user, _("Command not yet implemented."));
371 if ($channel->on($this->user)) {
372 $channel->output($this->user, _('Notification on.'));
374 $channel->error($this->user, _('Can\'t turn on notification.'));
380 class HelpCommand extends Command
382 function execute($channel)
384 $channel->output($this->user,
386 "on - turn on notifications\n".
387 "off - turn off notifications\n".
388 "help - show this help\n".
389 "follow <nickname> - subscribe to user\n".
390 "leave <nickname> - unsubscribe from user\n".
391 "d <nickname> <text> - direct message to user\n".
392 "get <nickname> - get last notice from user\n".
393 "whois <nickname> - get profile info on user\n".
394 "fav <nickname> - add user's last notice as a 'fave'\n".
395 "stats - get your stats\n".
396 "stop - same as 'off'\n".
397 "quit - same as 'off'\n".
398 "sub <nickname> - same as 'follow'\n".
399 "unsub <nickname> - same as 'leave'\n".
400 "last <nickname> - same as 'get'\n".
401 "on <nickname> - not yet implemented.\n".
402 "off <nickname> - not yet implemented.\n".
403 "nudge <nickname> - not yet implemented.\n".
404 "invite <phone number> - not yet implemented.\n".
405 "track <word> - not yet implemented.\n".
406 "untrack <word> - not yet implemented.\n".
407 "track off - not yet implemented.\n".
408 "untrack all - not yet implemented.\n".
409 "tracks - not yet implemented.\n".
410 "tracking - not yet implemented.\n"));