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 XMPPChannel extends Channel
60 function __construct($conn)
67 return $this->set_notify($user, 1);
72 return $this->set_notify($user, 0);
75 function output($user, $text)
77 $text = '['.common_config('site', 'name') . '] ' . $text;
78 jabber_send_message($user->jabber, $text);
81 function error($user, $text)
83 $text = '['.common_config('site', 'name') . '] ' . $text;
84 jabber_send_message($user->jabber, $text);
87 function set_notify(&$user, $notify)
90 $user->jabbernotify = $notify;
91 $result = $user->update($orig);
93 $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
95 'Could not set notify flag to ' . $notify .
96 ' for user ' . common_log_objstring($user) .
97 ': ' . $last_error->message);
101 'User ' . $user->nickname . ' set notify flag to ' . $notify);
107 class WebChannel extends Channel
111 function __construct($out=null)
131 function output($user, $text)
133 # XXX: buffer all output and send it at the end
134 # XXX: even better, redirect to appropriate page
135 # depending on what command was run
136 $this->out->startHTML();
137 $this->out->elementStart('head');
138 $this->out->element('title', null, _('Command results'));
139 $this->out->elementEnd('head');
140 $this->out->elementStart('body');
141 $this->out->element('p', array('id' => 'command_result'), $text);
142 $this->out->elementEnd('body');
143 $this->out->endHTML();
146 function error($user, $text)
148 common_user_error($text);
152 class AjaxWebChannel extends WebChannel
154 function output($user, $text)
156 $this->out->startHTML('text/xml;charset=utf-8');
157 $this->out->elementStart('head');
158 $this->out->element('title', null, _('Command results'));
159 $this->out->elementEnd('head');
160 $this->out->elementStart('body');
161 $this->out->element('p', array('id' => 'command_result'), $text);
162 $this->out->elementEnd('body');
163 $this->out->endHTML();
166 function error($user, $text)
168 $this->out->startHTML('text/xml;charset=utf-8');
169 $this->out->elementStart('head');
170 $this->out->element('title', null, _('Ajax Error'));
171 $this->out->elementEnd('head');
172 $this->out->elementStart('body');
173 $this->out->element('p', array('id' => 'error'), $text);
174 $this->out->elementEnd('body');
175 $this->out->endHTML();
179 class MailChannel extends Channel
189 function __construct($addr=null)
196 return $this->set_notify($user, 1);
201 return $this->set_notify($user, 0);
204 function output($user, $text)
207 $headers['From'] = $user->incomingemail;
208 $headers['To'] = $this->addr;
210 $headers['Subject'] = _('Command complete');
212 return mail_send(array($this->addr), $headers, $text);
215 function error($user, $text)
218 $headers['From'] = $user->incomingemail;
219 $headers['To'] = $this->addr;
221 $headers['Subject'] = _('Command failed');
223 return mail_send(array($this->addr), $headers, $text);
226 function set_notify($user, $value)
228 $orig = clone($user);
229 $user->smsnotify = $value;
230 $result = $user->update($orig);
232 common_log_db_error($user, 'UPDATE', __FILE__);