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); }
35 function output($user, $text)
40 function error($user, $text)
51 class XMPPChannel extends Channel
61 function __construct($conn)
68 return $this->set_notify($user, 1);
73 return $this->set_notify($user, 0);
76 function output($user, $text)
78 $text = '['.common_config('site', 'name') . '] ' . $text;
79 jabber_send_message($user->jabber, $text);
82 function error($user, $text)
84 $text = '['.common_config('site', 'name') . '] ' . $text;
85 jabber_send_message($user->jabber, $text);
88 function set_notify(&$user, $notify)
91 $user->jabbernotify = $notify;
92 $result = $user->update($orig);
94 $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
96 'Could not set notify flag to ' . $notify .
97 ' for user ' . common_log_objstring($user) .
98 ': ' . $last_error->message);
102 'User ' . $user->nickname . ' set notify flag to ' . $notify);
109 class WebChannel extends Channel
127 function output($user, $text)
129 # XXX: buffer all output and send it at the end
130 # XXX: even better, redirect to appropriate page
131 # depending on what command was run
132 common_show_header(_('Command results'));
133 common_element('p', null, $text);
134 common_show_footer();
137 function error($user, $text)
139 common_user_error($text);
144 class AjaxWebChannel extends WebChannel
147 function output($user, $text)
149 common_start_html('text/xml;charset=utf-8', true);
150 common_element_start('head');
151 common_element('title', null, _('Command results'));
152 common_element_end('head');
153 common_element_start('body');
154 common_element('p', array('id' => 'command_result'), $text);
155 common_element_end('body');
156 common_element_end('html');
159 function error($user, $text)
161 common_start_html('text/xml;charset=utf-8', true);
162 common_element_start('head');
163 common_element('title', null, _('Ajax Error'));
164 common_element_end('head');
165 common_element_start('body');
166 common_element('p', array('id' => 'error'), $text);
167 common_element_end('body');
168 common_element_end('html');
173 class MailChannel extends Channel
183 function __construct($addr=null)
190 return $this->set_notify($user, 1);
195 return $this->set_notify($user, 0);
198 function output($user, $text)
201 $headers['From'] = $user->incomingemail;
202 $headers['To'] = $this->addr;
204 $headers['Subject'] = _('Command complete');
206 return mail_send(array($this->addr), $headers, $text);
209 function error($user, $text)
212 $headers['From'] = $user->incomingemail;
213 $headers['To'] = $this->addr;
215 $headers['Subject'] = _('Command failed');
217 return mail_send(array($this->addr), $headers, $text);
220 function set_notify($user, $value)
222 $orig = clone($user);
223 $user->smsnotify = $value;
224 $result = $user->update($orig);
226 common_log_db_error($user, 'UPDATE', __FILE__);