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 WebChannel extends Channel
76 function __construct($out=null)
96 function output($user, $text)
98 // XXX: buffer all output and send it at the end
99 // XXX: even better, redirect to appropriate page
100 // depending on what command was run
101 $this->out->startHTML();
102 $this->out->elementStart('head');
103 // TRANS: Title for command results.
104 $this->out->element('title', null, _('Command results'));
105 $this->out->elementEnd('head');
106 $this->out->elementStart('body');
107 $this->out->element('p', array('id' => 'command_result'), $text);
108 $this->out->elementEnd('body');
109 $this->out->endHTML();
112 function error($user, $text)
114 common_user_error($text);
118 class AjaxWebChannel extends WebChannel
120 function output($user, $text)
122 $this->out->startHTML('text/xml;charset=utf-8');
123 $this->out->elementStart('head');
124 // TRANS: Title for command results.
125 $this->out->element('title', null, _('Command results'));
126 $this->out->elementEnd('head');
127 $this->out->elementStart('body');
128 $this->out->element('p', array('id' => 'command_result'), $text);
129 $this->out->elementEnd('body');
130 $this->out->endHTML();
133 function error($user, $text)
135 $this->out->startHTML('text/xml;charset=utf-8');
136 $this->out->elementStart('head');
137 // TRANS: Title for command results.
138 $this->out->element('title', null, _('AJAX error'));
139 $this->out->elementEnd('head');
140 $this->out->elementStart('body');
141 $this->out->element('p', array('id' => 'error'), $text);
142 $this->out->elementEnd('body');
143 $this->out->endHTML();
147 class MailChannel extends Channel
156 function __construct($addr=null)
163 return $this->setNotify($user, 1);
168 return $this->setNotify($user, 0);
171 function output($user, $text)
173 $headers['From'] = $user->incomingemail;
174 $headers['To'] = $this->addr;
176 // TRANS: E-mail subject when a command has completed.
177 $headers['Subject'] = _('Command complete');
179 return mail_send(array($this->addr), $headers, $text);
182 function error($user, $text)
184 $headers['From'] = $user->incomingemail;
185 $headers['To'] = $this->addr;
187 // TRANS: E-mail subject when a command has failed.
188 $headers['Subject'] = _('Command failed');
190 return mail_send(array($this->addr), $headers, $text);
193 function setNotify($user, $value)
195 $orig = clone($user);
196 $user->smsnotify = $value;
197 $result = $user->update($orig);
199 common_log_db_error($user, 'UPDATE', __FILE__);