3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, 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.'/classes/Channel.php');
28 function __construct($user=null)
33 function execute($channel)
39 class UnimplementedCommand extends Command {
40 function execute($channel)
42 $channel->error($this->user, _("Sorry, this command is not yet implemented."));
46 class TrackingCommand extends UnimplementedCommand {
49 class TrackOffCommand extends UnimplementedCommand {
52 class TrackCommand extends UnimplementedCommand {
54 function __construct($user, $word)
56 parent::__construct($user);
61 class UntrackCommand extends UnimplementedCommand {
63 function __construct($user, $word)
65 parent::__construct($user);
70 class NudgeCommand extends UnimplementedCommand {
72 function __construct($user, $other)
74 parent::__construct($user);
75 $this->other = $other;
79 class InviteCommand extends UnimplementedCommand {
81 function __construct($user, $other)
83 parent::__construct($user);
84 $this->other = $other;
88 class StatsCommand extends Command {
89 function execute($channel)
92 $subs = new Subscription();
93 $subs->subscriber = $this->user->id;
94 $subs_count = (int) $subs->count() - 1;
96 $subbed = new Subscription();
97 $subbed->subscribed = $this->user->id;
98 $subbed_count = (int) $subbed->count() - 1;
100 $notices = new Notice();
101 $notices->profile_id = $this->user->id;
102 $notice_count = (int) $notices->count();
104 $channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n".
105 "Subscribers: %2\$s\n".
113 class FavCommand extends Command {
117 function __construct($user, $other)
119 parent::__construct($user);
120 $this->other = $other;
123 function execute($channel)
127 common_relative_profile($this->user, common_canonical_nickname($this->other));
130 $channel->error($this->user, _('No such user.'));
133 $notice = $recipient->getCurrentNotice();
135 $channel->error($this->user, _('User has no last notice'));
139 $fave = Fave::addNew($this->user, $notice);
142 $channel->error($this->user, _('Could not create favorite.'));
146 $other = User::staticGet('id', $recipient->id);
148 if ($other && $other->id != $user->id) {
149 if ($other->email && $other->emailnotifyfav) {
150 mail_notify_fave($other, $this->user, $notice);
154 $this->user->blowFavesCache();
156 $channel->output($this->user, _('Notice marked as fave.'));
160 class WhoisCommand extends Command {
162 function __construct($user, $other)
164 parent::__construct($user);
165 $this->other = $other;
168 function execute($channel)
171 common_relative_profile($this->user, common_canonical_nickname($this->other));
174 $channel->error($this->user, _('No such user.'));
178 $whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
179 $recipient->profileurl);
180 if ($recipient->fullname) {
181 $whois .= "\n" . sprintf(_('Fullname: %s'), $recipient->fullname);
183 if ($recipient->location) {
184 $whois .= "\n" . sprintf(_('Location: %s'), $recipient->location);
186 if ($recipient->homepage) {
187 $whois .= "\n" . sprintf(_('Homepage: %s'), $recipient->homepage);
189 if ($recipient->bio) {
190 $whois .= "\n" . sprintf(_('About: %s'), $recipient->bio);
192 $channel->output($this->user, $whois);
196 class MessageCommand extends Command {
199 function __construct($user, $other, $text)
201 parent::__construct($user);
202 $this->other = $other;
206 function execute($channel)
208 $other = User::staticGet('nickname', common_canonical_nickname($this->other));
209 $len = mb_strlen($this->text);
211 $channel->error($this->user, _('No content!'));
213 } else if ($len > 140) {
214 $content = common_shorten_links($content);
215 if (mb_strlen($content) > 140) {
216 $channel->error($this->user, sprintf(_('Message too long - maximum is 140 characters, you sent %d'), $len));
222 $channel->error($this->user, _('No such user.'));
224 } else if (!$this->user->mutuallySubscribed($other)) {
225 $channel->error($this->user, _('You can\'t send a message to this user.'));
227 } else if ($this->user->id == $other->id) {
228 $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
231 $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
233 $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
235 $channel->error($this->user, _('Error sending direct message.'));
240 class GetCommand extends Command {
244 function __construct($user, $other)
246 parent::__construct($user);
247 $this->other = $other;
250 function execute($channel)
252 $target_nickname = common_canonical_nickname($this->other);
255 common_relative_profile($this->user, $target_nickname);
258 $channel->error($this->user, _('No such user.'));
261 $notice = $target->getCurrentNotice();
263 $channel->error($this->user, _('User has no last notice'));
266 $notice_content = $notice->content;
268 $channel->output($this->user, $target_nickname . ": " . $notice_content);
272 class SubCommand extends Command {
276 function __construct($user, $other)
278 parent::__construct($user);
279 $this->other = $other;
282 function execute($channel)
286 $channel->error($this->user, _('Specify the name of the user to subscribe to'));
290 $result = subs_subscribe_user($this->user, $this->other);
292 if ($result == 'true') {
293 $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
295 $channel->error($this->user, $result);
300 class UnsubCommand extends Command {
304 function __construct($user, $other)
306 parent::__construct($user);
307 $this->other = $other;
310 function execute($channel)
313 $channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
317 $result=subs_unsubscribe_user($this->user, $this->other);
320 $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
322 $channel->error($this->user, $result);
327 class OffCommand extends Command {
329 function __construct($user, $other=null)
331 parent::__construct($user);
332 $this->other = $other;
334 function execute($channel)
337 $channel->error($this->user, _("Command not yet implemented."));
339 if ($channel->off($this->user)) {
340 $channel->output($this->user, _('Notification off.'));
342 $channel->error($this->user, _('Can\'t turn off notification.'));
348 class OnCommand extends Command {
350 function __construct($user, $other=null)
352 parent::__construct($user);
353 $this->other = $other;
356 function execute($channel)
359 $channel->error($this->user, _("Command not yet implemented."));
361 if ($channel->on($this->user)) {
362 $channel->output($this->user, _('Notification on.'));
364 $channel->error($this->user, _('Can\'t turn on notification.'));
370 class HelpCommand extends Command {
371 function execute($channel)
373 $channel->output($this->user,
375 "on - turn on notifications\n".
376 "off - turn off notifications\n".
377 "help - show this help\n".
378 "follow <nickname> - subscribe to user\n".
379 "leave <nickname> - unsubscribe from user\n".
380 "d <nickname> <text> - direct message to user\n".
381 "get <nickname> - get last notice from user\n".
382 "whois <nickname> - get profile info on user\n".
383 "fav <nickname> - add user's last notice as a 'fave'\n".
384 "stats - get your stats\n".
385 "stop - same as 'off'\n".
386 "quit - same as 'off'\n".
387 "sub <nickname> - same as 'follow'\n".
388 "unsub <nickname> - same as 'leave'\n".
389 "last <nickname> - same as 'get'\n".
390 "on <nickname> - not yet implemented.\n".
391 "off <nickname> - not yet implemented.\n".
392 "nudge <nickname> - not yet implemented.\n".
393 "invite <phone number> - not yet implemented.\n".
394 "track <word> - not yet implemented.\n".
395 "untrack <word> - not yet implemented.\n".
396 "track off - not yet implemented.\n".
397 "untrack all - not yet implemented.\n".
398 "tracks - not yet implemented.\n".
399 "tracking - not yet implemented.\n"));