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);
108 class WebChannel extends Channel
112 function __construct($out=null)
132 function output($user, $text)
134 # XXX: buffer all output and send it at the end
135 # XXX: even better, redirect to appropriate page
136 # depending on what command was run
137 $this->out->startHTML();
138 $this->out->elementStart('head');
139 $this->out->element('title', null, _('Command results'));
140 $this->out->elementEnd('head');
141 $this->out->elementStart('body');
142 $this->out->element('p', array('id' => 'command_result'), $text);
143 $this->out->elementEnd('body');
144 $this->out->endHTML();
147 function error($user, $text)
149 common_user_error($text);
153 class AjaxWebChannel extends WebChannel
155 function output($user, $text)
157 $this->out->startHTML('text/xml;charset=utf-8');
158 $this->out->elementStart('head');
159 $this->out->element('title', null, _('Command results'));
160 $this->out->elementEnd('head');
161 $this->out->elementStart('body');
162 $this->out->element('p', array('id' => 'command_result'), $text);
163 $this->out->elementEnd('body');
164 $this->out->endHTML();
167 function error($user, $text)
169 $this->out->startHTML('text/xml;charset=utf-8');
170 $this->out->elementStart('head');
171 $this->out->element('title', null, _('Ajax Error'));
172 $this->out->elementEnd('head');
173 $this->out->elementStart('body');
174 $this->out->element('p', array('id' => 'error'), $text);
175 $this->out->elementEnd('body');
176 $this->out->endHTML();
180 class MailChannel extends Channel
190 function __construct($addr=null)
197 return $this->set_notify($user, 1);
202 return $this->set_notify($user, 0);
205 function output($user, $text)
208 $headers['From'] = $user->incomingemail;
209 $headers['To'] = $this->addr;
211 $headers['Subject'] = _('Command complete');
213 return mail_send(array($this->addr), $headers, $text);
216 function error($user, $text)
219 $headers['From'] = $user->incomingemail;
220 $headers['To'] = $this->addr;
222 $headers['Subject'] = _('Command failed');
224 return mail_send(array($this->addr), $headers, $text);
227 function set_notify($user, $value)
229 $orig = clone($user);
230 $user->smsnotify = $value;
231 $result = $user->update($orig);
233 common_log_db_error($user, 'UPDATE', __FILE__);