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); }
32 function output($user, $text) {
36 function error($user, $text) {
45 class XMPPChannel extends Channel {
53 function __construct($conn) {
58 return $this->set_notify($user, 1);
62 return $this->set_notify($user, 0);
65 function output($user, $text) {
66 $text = '['.common_config('site', 'name') . '] ' . $text;
67 jabber_send_message($user->jabber, $text);
70 function error($user, $text) {
71 $text = '['.common_config('site', 'name') . '] ' . $text;
72 jabber_send_message($user->jabber, $text);
75 function set_notify(&$user, $notify) {
77 $user->jabbernotify = $notify;
78 $result = $user->update($orig);
80 $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
82 'Could not set notify flag to ' . $notify .
83 ' for user ' . common_log_objstring($user) .
84 ': ' . $last_error->message);
88 'User ' . $user->nickname . ' set notify flag to ' . $notify);
95 class WebChannel extends Channel {
105 function off($user) {
109 function output($user, $text) {
110 # XXX: buffer all output and send it at the end
111 # XXX: even better, redirect to appropriate page
112 # depending on what command was run
113 common_show_header(_('Command results'));
114 common_element('p', NULL, $text);
115 common_show_footer();
118 function error($user, $text) {
119 common_user_error($text);
123 class MailChannel extends Channel {
131 function __construct($addr=NULL) {
136 return $this->set_notify($user, 1);
139 function off($user) {
140 return $this->set_notify($user, 0);
143 function output($user, $text) {
145 $headers['From'] = $user->incomingemail;
146 $headers['To'] = $this->addr;
148 $headers['Subject'] = _('Command complete');
150 return mail_send(array($this->addr), $headers, $text);
153 function error($user, $text) {
155 $headers['From'] = $user->incomingemail;
156 $headers['To'] = $this->addr;
158 $headers['Subject'] = _('Command failed');
160 return mail_send(array($this->addr), $headers, $text);
163 function set_notify($user, $value) {
164 $orig = clone($user);
165 $user->smsnotify = $value;
166 $result = $user->update($orig);
168 common_log_db_error($user, 'UPDATE', __FILE__);