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); }
34 function output($user, $text)
39 function error($user, $text)
50 class XMPPChannel extends Channel {
59 function __construct($conn)
66 return $this->set_notify($user, 1);
71 return $this->set_notify($user, 0);
74 function output($user, $text)
76 $text = '['.common_config('site', 'name') . '] ' . $text;
77 jabber_send_message($user->jabber, $text);
80 function error($user, $text)
82 $text = '['.common_config('site', 'name') . '] ' . $text;
83 jabber_send_message($user->jabber, $text);
86 function set_notify(&$user, $notify)
89 $user->jabbernotify = $notify;
90 $result = $user->update($orig);
92 $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
94 'Could not set notify flag to ' . $notify .
95 ' for user ' . common_log_objstring($user) .
96 ': ' . $last_error->message);
100 'User ' . $user->nickname . ' set notify flag to ' . $notify);
107 class WebChannel extends Channel {
124 function output($user, $text)
126 # XXX: buffer all output and send it at the end
127 # XXX: even better, redirect to appropriate page
128 # depending on what command was run
129 common_show_header(_('Command results'));
130 common_element('p', null, $text);
131 common_show_footer();
134 function error($user, $text)
136 common_user_error($text);
141 class AjaxWebChannel extends WebChannel {
143 function output($user, $text)
145 common_start_html('text/xml;charset=utf-8', true);
146 common_element_start('head');
147 common_element('title', null, _('Command results'));
148 common_element_end('head');
149 common_element_start('body');
150 common_element('p', array('id' => 'command_result'), $text);
151 common_element_end('body');
152 common_element_end('html');
155 function error($user, $text)
157 common_start_html('text/xml;charset=utf-8', true);
158 common_element_start('head');
159 common_element('title', null, _('Ajax Error'));
160 common_element_end('head');
161 common_element_start('body');
162 common_element('p', array('id' => 'error'), $text);
163 common_element_end('body');
164 common_element_end('html');
169 class MailChannel extends Channel {
178 function __construct($addr=null)
185 return $this->set_notify($user, 1);
190 return $this->set_notify($user, 0);
193 function output($user, $text)
196 $headers['From'] = $user->incomingemail;
197 $headers['To'] = $this->addr;
199 $headers['Subject'] = _('Command complete');
201 return mail_send(array($this->addr), $headers, $text);
204 function error($user, $text)
207 $headers['From'] = $user->incomingemail;
208 $headers['To'] = $this->addr;
210 $headers['Subject'] = _('Command failed');
212 return mail_send(array($this->addr), $headers, $text);
215 function set_notify($user, $value)
217 $orig = clone($user);
218 $user->smsnotify = $value;
219 $result = $user->update($orig);
221 common_log_db_error($user, 'UPDATE', __FILE__);