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) {
32 function execute($channel) {
37 class UnimplementedCommand extends Command {
38 function execute($channel) {
39 $channel->error($this->user, _("Sorry, this command is not yet implemented."));
43 class TrackingCommand extends UnimplementedCommand {
46 class TrackOffCommand extends UnimplementedCommand {
49 class TrackCommand extends UnimplementedCommand {
51 function __construct($user, $word) {
52 parent::__construct($user);
57 class UntrackCommand extends UnimplementedCommand {
59 function __construct($user, $word) {
60 parent::__construct($user);
65 class NudgeCommand extends UnimplementedCommand {
67 function __construct($user, $other) {
68 parent::__construct($user);
69 $this->other = $other;
73 class InviteCommand extends UnimplementedCommand {
75 function __construct($user, $other) {
76 parent::__construct($user);
77 $this->other = $other;
81 class StatsCommand extends Command {
82 function execute($channel) {
84 $subs = new Subscription();
85 $subs->subscriber = $this->user->id;
86 $subs_count = (int) $subs->count() - 1;
88 $subbed = new Subscription();
89 $subbed->subscribed = $this->user->id;
90 $subbed_count = (int) $subbed->count() - 1;
92 $notices = new Notice();
93 $notices->profile_id = $this->user->id;
94 $notice_count = (int) $notices->count();
96 $channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n".
97 "Subscribers: %2\$s\n".
105 class FavCommand extends Command {
109 function __construct($user, $other) {
110 parent::__construct($user);
111 $this->other = $other;
114 function execute($channel) {
117 common_relative_profile($this->user, common_canonical_nickname($this->other));
120 $channel->error($this->user, _('No such user.'));
123 $notice = $recipient->getCurrentNotice();
125 $channel->error($this->user, _('User has no last notice'));
129 $fave = Fave::addNew($this->user, $notice);
132 $channel->error($this->user, _('Could not create favorite.'));
136 $other = User::staticGet('id', $recipient->id);
138 if ($other && $other->id != $user->id) {
139 if ($other->email && $other->emailnotifyfav) {
140 mail_notify_fave($other, $this->user, $notice);
144 $this->user->blowFavesCache();
146 $channel->output($this->user, _('Notice marked as fave.'));
150 class WhoisCommand extends Command {
152 function __construct($user, $other) {
153 parent::__construct($user);
154 $this->other = $other;
157 function execute($channel) {
159 common_relative_profile($this->user, common_canonical_nickname($this->other));
162 $channel->error($this->user, _('No such user.'));
166 $whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
167 $recipient->profileurl);
168 if ($recipient->fullname) {
169 $whois .= "\n" . sprintf(_('Fullname: %s'), $recipient->fullname);
171 if ($recipient->location) {
172 $whois .= "\n" . sprintf(_('Location: %s'), $recipient->location);
174 if ($recipient->homepage) {
175 $whois .= "\n" . sprintf(_('Homepage: %s'), $recipient->homepage);
177 if ($recipient->bio) {
178 $whois .= "\n" . sprintf(_('About: %s'), $recipient->bio);
180 $channel->output($this->user, $whois);
184 class MessageCommand extends Command {
187 function __construct($user, $other, $text) {
188 parent::__construct($user);
189 $this->other = $other;
193 function execute($channel) {
194 $other = User::staticGet('nickname', common_canonical_nickname($this->other));
195 $len = mb_strlen($this->text);
197 $channel->error($this->user, _('No content!'));
199 } else if ($len > 140) {
200 $content = common_shorten_links($content);
201 if (mb_strlen($content) > 140) {
202 $channel->error($this->user, sprintf(_('Message too long - maximum is 140 characters, you sent %d'), $len));
208 $channel->error($this->user, _('No such user.'));
210 } else if (!$this->user->mutuallySubscribed($other)) {
211 $channel->error($this->user, _('You can\'t send a message to this user.'));
213 } else if ($this->user->id == $other->id) {
214 $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
217 $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
219 $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
221 $channel->error($this->user, _('Error sending direct message.'));
226 class GetCommand extends Command {
230 function __construct($user, $other) {
231 parent::__construct($user);
232 $this->other = $other;
235 function execute($channel) {
236 $target_nickname = common_canonical_nickname($this->other);
239 common_relative_profile($this->user, $target_nickname);
242 $channel->error($this->user, _('No such user.'));
245 $notice = $target->getCurrentNotice();
247 $channel->error($this->user, _('User has no last notice'));
250 $notice_content = $notice->content;
252 $channel->output($this->user, $target_nickname . ": " . $notice_content);
256 class SubCommand extends Command {
260 function __construct($user, $other) {
261 parent::__construct($user);
262 $this->other = $other;
265 function execute($channel) {
268 $channel->error($this->user, _('Specify the name of the user to subscribe to'));
272 $result = subs_subscribe_user($this->user, $this->other);
274 if ($result == 'true') {
275 $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
277 $channel->error($this->user, $result);
282 class UnsubCommand extends Command {
286 function __construct($user, $other) {
287 parent::__construct($user);
288 $this->other = $other;
291 function execute($channel) {
293 $channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
297 $result=subs_unsubscribe_user($this->user, $this->other);
300 $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
302 $channel->error($this->user, $result);
307 class OffCommand extends Command {
309 function __construct($user, $other=NULL) {
310 parent::__construct($user);
311 $this->other = $other;
313 function execute($channel) {
315 $channel->error($this->user, _("Command not yet implemented."));
317 if ($channel->off($this->user)) {
318 $channel->output($this->user, _('Notification off.'));
320 $channel->error($this->user, _('Can\'t turn off notification.'));
326 class OnCommand extends Command {
328 function __construct($user, $other=NULL) {
329 parent::__construct($user);
330 $this->other = $other;
333 function execute($channel) {
335 $channel->error($this->user, _("Command not yet implemented."));
337 if ($channel->on($this->user)) {
338 $channel->output($this->user, _('Notification on.'));
340 $channel->error($this->user, _('Can\'t turn on notification.'));
346 class HelpCommand extends Command {
347 function execute($channel) {
348 $channel->output($this->user,
350 "on - turn on notifications\n".
351 "off - turn off notifications\n".
352 "help - show this help\n".
353 "follow <nickname> - subscribe to user\n".
354 "leave <nickname> - unsubscribe from user\n".
355 "d <nickname> <text> - direct message to user\n".
356 "get <nickname> - get last notice from user\n".
357 "whois <nickname> - get profile info on user\n".
358 "fav <nickname> - add user's last notice as a 'fave'\n".
359 "stats - get your stats\n".
360 "stop - same as 'off'\n".
361 "quit - same as 'off'\n".
362 "sub <nickname> - same as 'follow'\n".
363 "unsub <nickname> - same as 'leave'\n".
364 "last <nickname> - same as 'get'\n".
365 "on <nickname> - not yet implemented.\n".
366 "off <nickname> - not yet implemented.\n".
367 "nudge <nickname> - not yet implemented.\n".
368 "invite <phone number> - not yet implemented.\n".
369 "track <word> - not yet implemented.\n".
370 "untrack <word> - not yet implemented.\n".
371 "track off - not yet implemented.\n".
372 "untrack all - not yet implemented.\n".
373 "tracks - not yet implemented.\n".
374 "tracking - not yet implemented.\n"));