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 WebChannel extends Channel
73 function __construct($out=null)
93 function output($user, $text)
95 # XXX: buffer all output and send it at the end
96 # XXX: even better, redirect to appropriate page
97 # depending on what command was run
98 $this->out->startHTML();
99 $this->out->elementStart('head');
100 $this->out->element('title', null, _('Command results'));
101 $this->out->elementEnd('head');
102 $this->out->elementStart('body');
103 $this->out->element('p', array('id' => 'command_result'), $text);
104 $this->out->elementEnd('body');
105 $this->out->endHTML();
108 function error($user, $text)
110 common_user_error($text);
114 class AjaxWebChannel extends WebChannel
116 function output($user, $text)
118 $this->out->startHTML('text/xml;charset=utf-8');
119 $this->out->elementStart('head');
120 $this->out->element('title', null, _('Command results'));
121 $this->out->elementEnd('head');
122 $this->out->elementStart('body');
123 $this->out->element('p', array('id' => 'command_result'), $text);
124 $this->out->elementEnd('body');
125 $this->out->endHTML();
128 function error($user, $text)
130 $this->out->startHTML('text/xml;charset=utf-8');
131 $this->out->elementStart('head');
132 $this->out->element('title', null, _('Ajax Error'));
133 $this->out->elementEnd('head');
134 $this->out->elementStart('body');
135 $this->out->element('p', array('id' => 'error'), $text);
136 $this->out->elementEnd('body');
137 $this->out->endHTML();
141 class MailChannel extends Channel
151 function __construct($addr=null)
158 return $this->set_notify($user, 1);
163 return $this->set_notify($user, 0);
166 function output($user, $text)
169 $headers['From'] = $user->incomingemail;
170 $headers['To'] = $this->addr;
172 $headers['Subject'] = _('Command complete');
174 return mail_send(array($this->addr), $headers, $text);
177 function error($user, $text)
180 $headers['From'] = $user->incomingemail;
181 $headers['To'] = $this->addr;
183 $headers['Subject'] = _('Command failed');
185 return mail_send(array($this->addr), $headers, $text);
188 function set_notify($user, $value)
190 $orig = clone($user);
191 $user->smsnotify = $value;
192 $result = $user->update($orig);
194 common_log_db_error($user, 'UPDATE', __FILE__);