3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, 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('STATUSNET') && !defined('LACONICA')) { exit(1); }
23 * @todo Needs documentation.
37 function output($user, $text)
42 function error($user, $text)
53 class CLIChannel extends Channel
60 function output($user, $text)
62 $site = common_config('site', 'name');
63 print "[{$user->nickname}@{$site}] $text\n";
66 function error($user, $text)
68 $this->output($user, $text);
72 class XMPPChannel extends Channel
81 function __construct($conn)
88 return $this->set_notify($user, 1);
93 return $this->set_notify($user, 0);
96 function output($user, $text)
98 $text = '['.common_config('site', 'name') . '] ' . $text;
99 jabber_send_message($user->jabber, $text);
102 function error($user, $text)
104 $text = '['.common_config('site', 'name') . '] ' . $text;
105 jabber_send_message($user->jabber, $text);
108 function set_notify(&$user, $notify)
110 $orig = clone($user);
111 $user->jabbernotify = $notify;
112 $result = $user->update($orig);
114 $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
116 'Could not set notify flag to ' . $notify .
117 ' for user ' . common_log_objstring($user) .
118 ': ' . $last_error->message);
122 'User ' . $user->nickname . ' set notify flag to ' . $notify);
128 class WebChannel extends Channel
132 function __construct($out=null)
152 function output($user, $text)
154 # XXX: buffer all output and send it at the end
155 # XXX: even better, redirect to appropriate page
156 # depending on what command was run
157 $this->out->startHTML();
158 $this->out->elementStart('head');
159 // TRANS: Title for command results.
160 $this->out->element('title', null, _('Command results'));
161 $this->out->elementEnd('head');
162 $this->out->elementStart('body');
163 $this->out->element('p', array('id' => 'command_result'), $text);
164 $this->out->elementEnd('body');
165 $this->out->endHTML();
168 function error($user, $text)
170 common_user_error($text);
174 class AjaxWebChannel extends WebChannel
176 function output($user, $text)
178 $this->out->startHTML('text/xml;charset=utf-8');
179 $this->out->elementStart('head');
180 // TRANS: Title for command results.
181 $this->out->element('title', null, _('Command results'));
182 $this->out->elementEnd('head');
183 $this->out->elementStart('body');
184 $this->out->element('p', array('id' => 'command_result'), $text);
185 $this->out->elementEnd('body');
186 $this->out->endHTML();
189 function error($user, $text)
191 $this->out->startHTML('text/xml;charset=utf-8');
192 $this->out->elementStart('head');
193 // TRANS: Title for command results.
194 $this->out->element('title', null, _('AJAX error'));
195 $this->out->elementEnd('head');
196 $this->out->elementStart('body');
197 $this->out->element('p', array('id' => 'error'), $text);
198 $this->out->elementEnd('body');
199 $this->out->endHTML();
203 class MailChannel extends Channel
212 function __construct($addr=null)
219 return $this->set_notify($user, 1);
224 return $this->set_notify($user, 0);
227 function output($user, $text)
229 $headers['From'] = $user->incomingemail;
230 $headers['To'] = $this->addr;
232 // TRANS: E-mail subject when a command has completed.
233 $headers['Subject'] = _('Command complete');
235 return mail_send(array($this->addr), $headers, $text);
238 function error($user, $text)
240 $headers['From'] = $user->incomingemail;
241 $headers['To'] = $this->addr;
243 // TRANS: E-mail subject when a command has failed.
244 $headers['Subject'] = _('Command failed');
246 return mail_send(array($this->addr), $headers, $text);
249 function set_notify($user, $value)
251 $orig = clone($user);
252 $user->smsnotify = $value;
253 $result = $user->update($orig);
255 common_log_db_error($user, 'UPDATE', __FILE__);