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 FaveCommand 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 mail_notify_fave($recipient, $this->user, $notice);
137 $this->user->blowFavesCache();
139 $channel->output($this->user, _('Message marked as fave.'));
143 class WhoisCommand extends Command {
145 function __construct($user, $other) {
146 parent::__construct($user);
147 $this->other = $other;
150 function execute($channel) {
152 common_relative_profile($this->user, common_canonical_nickname($this->other));
155 $channel->error($this->user, _('No such user.'));
159 $whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
160 $recipient->profileurl);
161 if ($recipient->fullname) {
162 $whois .= "\n" . sprintf(_('Fullname: %s'), $recipient->fullname);
164 if ($recipient->location) {
165 $whois .= "\n" . sprintf(_('Location: %s'), $recipient->location);
167 if ($recipient->homepage) {
168 $whois .= "\n" . sprintf(_('Homepage: %s'), $recipient->homepage);
170 if ($recipient->bio) {
171 $whois .= "\n" . sprintf(_('About: %s'), $recipient->bio);
173 $channel->output($this->user, $whois);
177 class MessageCommand extends Command {
180 function __construct($user, $other, $text) {
181 parent::__construct($user);
182 $this->other = $other;
183 $this->text = $other;
186 function execute($channel) {
187 $other = User::staticGet('nickname', common_canonical_nickname($this->other));
188 $len = mb_strlen($this->text);
190 $channel->error($this->user, _('No content!'));
192 } else if ($len > 140) {
193 $channel->error($this->user,sprintf(_('Message too long - maximum is 140 characters, you sent %d'), $len));
195 } else if (!$other) {
196 $channel->error($this->user, _('No such user.'));
198 } else if (!$user->mutuallySubscribed($other)) {
199 $channel->error($this->user, _('You can\'t send a message to this user.'));
201 } else if ($user->id == $other->id) {
202 $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
205 $message = Message::saveNew($user->id, $other->id, $body, 'xmpp');
207 $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
209 $channel->error($this->user, _('Error sending direct message.'));
214 class GetCommand extends Command {
218 function __construct($user, $other) {
219 parent::__construct($user);
220 $this->other = $other;
223 function execute($channel) {
225 common_relative_profile($this->user, common_canonical_nickname($this->other));
228 $channel->error($this->user, _('No such user.'));
231 $notice = $target->getCurrentNotice();
233 $channel->error($this->user, _('User has no last notice'));
236 $notice_content = $notice->content;
237 $channel->output($this->user, $target_nickname . ": " . $notice_content);
241 class SubCommand extends Command {
245 function __construct($user, $other) {
246 parent::__construct($user);
247 $this->other = $other;
250 function execute($channel) {
253 $channel->error($this->user, _('Specify the name of the user to subscribe to'));
257 $result = subs_subscribe_user($user, $this->other);
259 if ($result == 'true') {
260 $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
262 $channel->error($this->user, $result);
267 class UnsubCommand extends Command {
271 function __construct($user, $other) {
272 parent::__construct($user);
273 $this->other = $other;
276 function execute($channel) {
278 $channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
282 $result=subs_unsubscribe_user($user, $this->other);
285 $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
287 $channel->error($this->user, $result);
292 class OffCommand extends Command {
294 function __construct($user, $other=NULL) {
295 parent::__construct($user);
296 $this->other = $other;
298 function execute($channel) {
300 $channel->error($this->user, _("Command not yet implemented."));
302 if ($channel->off($this->user)) {
303 $channel->output(_('Notification off.'));
305 $channel->error(_('Can\'t turn off notification.'));
311 class OnCommand extends Command {
313 function __construct($user, $other=NULL) {
314 parent::__construct($user);
315 $this->other = $other;
318 function execute($channel) {
320 $channel->error($this->user, _("Command not yet implemented."));
322 if ($channel->on($this->user)) {
323 $channel->output(_('Notification on.'));
325 $channel->error(_('Can\'t turn on notification.'));
331 class HelpCommand extends Command {
332 function execute($channel) {
333 $channel->output($this->user,
335 "on - turn on notifications\n".
336 "off - turn off notifications\n".
337 "help - show this help\n".
338 "follow <nickname> - subscribe to user\n".
339 "leave <nickname> - unsubscribe from user\n".
340 "d <nickname> <text> - direct message to user\n".
341 "get <nickname> - get last notice from user\n".
342 "whois <nickname> - get profile info on user\n".
343 "fav <nickname> - add user's last notice as a 'fave'\n".
344 "stats - get your stats\n".
345 "stop - same as 'off'\n".
346 "quit - same as 'off'\n".
347 "sub <nickname> - same as 'follow'\n".
348 "unsub <nickname> - same as 'leave'\n".
349 "last <nickname> - same as 'get'\n".
350 "on <nickname> - not yet implemented.\n".
351 "off <nickname> - not yet implemented.\n".
352 "nudge <nickname> - not yet implemented.\n".
353 "invite <phone number> - not yet implemented.\n".
354 "track <word> - not yet implemented.\n".
355 "untrack <word> - not yet implemented.\n".
356 "track off - not yet implemented.\n".
357 "untrack all - not yet implemented.\n".
358 "tracks - not yet implemented.\n".
359 "tracking - not yet implemented.\n"));