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); }
34 function output($user, $text)
39 function error($user, $text)
50 class CLIChannel extends Channel
57 function output($user, $text)
59 $site = common_config('site', 'name');
60 print "[{$user->nickname}@{$site}] $text\n";
63 function error($user, $text)
65 $this->output($user, $text);
69 class XMPPChannel extends Channel
79 function __construct($conn)
86 return $this->set_notify($user, 1);
91 return $this->set_notify($user, 0);
94 function output($user, $text)
96 $text = '['.common_config('site', 'name') . '] ' . $text;
97 jabber_send_message($user->jabber, $text);
100 function error($user, $text)
102 $text = '['.common_config('site', 'name') . '] ' . $text;
103 jabber_send_message($user->jabber, $text);
106 function set_notify(&$user, $notify)
108 $orig = clone($user);
109 $user->jabbernotify = $notify;
110 $result = $user->update($orig);
112 $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
114 'Could not set notify flag to ' . $notify .
115 ' for user ' . common_log_objstring($user) .
116 ': ' . $last_error->message);
120 'User ' . $user->nickname . ' set notify flag to ' . $notify);
126 class WebChannel extends Channel
130 function __construct($out=null)
150 function output($user, $text)
152 # XXX: buffer all output and send it at the end
153 # XXX: even better, redirect to appropriate page
154 # depending on what command was run
155 $this->out->startHTML();
156 $this->out->elementStart('head');
157 $this->out->element('title', null, _('Command results'));
158 $this->out->elementEnd('head');
159 $this->out->elementStart('body');
160 $this->out->element('p', array('id' => 'command_result'), $text);
161 $this->out->elementEnd('body');
162 $this->out->endHTML();
165 function error($user, $text)
167 common_user_error($text);
171 class AjaxWebChannel extends WebChannel
173 function output($user, $text)
175 $this->out->startHTML('text/xml;charset=utf-8');
176 $this->out->elementStart('head');
177 $this->out->element('title', null, _('Command results'));
178 $this->out->elementEnd('head');
179 $this->out->elementStart('body');
180 $this->out->element('p', array('id' => 'command_result'), $text);
181 $this->out->elementEnd('body');
182 $this->out->endHTML();
185 function error($user, $text)
187 $this->out->startHTML('text/xml;charset=utf-8');
188 $this->out->elementStart('head');
189 $this->out->element('title', null, _('Ajax Error'));
190 $this->out->elementEnd('head');
191 $this->out->elementStart('body');
192 $this->out->element('p', array('id' => 'error'), $text);
193 $this->out->elementEnd('body');
194 $this->out->endHTML();
198 class MailChannel extends Channel
208 function __construct($addr=null)
215 return $this->set_notify($user, 1);
220 return $this->set_notify($user, 0);
223 function output($user, $text)
226 $headers['From'] = $user->incomingemail;
227 $headers['To'] = $this->addr;
229 $headers['Subject'] = _('Command complete');
231 return mail_send(array($this->addr), $headers, $text);
234 function error($user, $text)
237 $headers['From'] = $user->incomingemail;
238 $headers['To'] = $this->addr;
240 $headers['Subject'] = _('Command failed');
242 return mail_send(array($this->addr), $headers, $text);
245 function set_notify($user, $value)
247 $orig = clone($user);
248 $user->smsnotify = $value;
249 $result = $user->update($orig);
251 common_log_db_error($user, 'UPDATE', __FILE__);