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 WebChannel extends Channel
54 function __construct($out=null)
74 function output($user, $text)
76 # XXX: buffer all output and send it at the end
77 # XXX: even better, redirect to appropriate page
78 # depending on what command was run
79 $this->out->startHTML();
80 $this->out->elementStart('head');
81 $this->out->element('title', null, _('Command results'));
82 $this->out->elementEnd('head');
83 $this->out->elementStart('body');
84 $this->out->element('p', array('id' => 'command_result'), $text);
85 $this->out->elementEnd('body');
86 $this->out->endHTML();
89 function error($user, $text)
91 common_user_error($text);
95 class AjaxWebChannel extends WebChannel
97 function output($user, $text)
99 $this->out->startHTML('text/xml;charset=utf-8');
100 $this->out->elementStart('head');
101 $this->out->element('title', null, _('Command results'));
102 $this->out->elementEnd('head');
103 $this->out->elementStart('body');
104 $this->out->element('p', array('id' => 'command_result'), $text);
105 $this->out->elementEnd('body');
106 $this->out->endHTML();
109 function error($user, $text)
111 $this->out->startHTML('text/xml;charset=utf-8');
112 $this->out->elementStart('head');
113 $this->out->element('title', null, _('Ajax Error'));
114 $this->out->elementEnd('head');
115 $this->out->elementStart('body');
116 $this->out->element('p', array('id' => 'error'), $text);
117 $this->out->elementEnd('body');
118 $this->out->endHTML();
122 class MailChannel extends Channel
132 function __construct($addr=null)
139 return $this->set_notify($user, 1);
144 return $this->set_notify($user, 0);
147 function output($user, $text)
150 $headers['From'] = $user->incomingemail;
151 $headers['To'] = $this->addr;
153 $headers['Subject'] = _('Command complete');
155 return mail_send(array($this->addr), $headers, $text);
158 function error($user, $text)
161 $headers['From'] = $user->incomingemail;
162 $headers['To'] = $this->addr;
164 $headers['Subject'] = _('Command failed');
166 return mail_send(array($this->addr), $headers, $text);
169 function set_notify($user, $value)
171 $orig = clone($user);
172 $user->smsnotify = $value;
173 $result = $user->update($orig);
175 common_log_db_error($user, 'UPDATE', __FILE__);