123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
- class Channel
- {
- function on($user)
- {
- return false;
- }
- function off($user)
- {
- return false;
- }
- function output($user, $text)
- {
- return false;
- }
- function error($user, $text)
- {
- return false;
- }
- function source()
- {
- return null;
- }
- }
- class CLIChannel extends Channel
- {
- function source()
- {
- return 'cli';
- }
- function output($user, $text)
- {
- $site = common_config('site', 'name');
- print "[{$user->nickname}@{$site}] $text\n";
- }
- function error($user, $text)
- {
- $this->output($user, $text);
- }
- }
- class WebChannel extends Channel
- {
- var $out = null;
- function __construct($out=null)
- {
- $this->out = $out;
- }
- function source()
- {
- return 'web';
- }
- function on($user)
- {
- return false;
- }
- function off($user)
- {
- return false;
- }
- function output($user, $text)
- {
-
-
-
- $this->out->startHTML();
- $this->out->elementStart('head');
-
- $this->out->element('title', null, _('Command results'));
- $this->out->elementEnd('head');
- $this->out->elementStart('body');
- $this->out->element('p', array('id' => 'command_result'), $text);
- $this->out->elementEnd('body');
- $this->out->endHTML();
- }
- function error($user, $text)
- {
- common_user_error($text);
- }
- }
- class AjaxWebChannel extends WebChannel
- {
- function output($user, $text)
- {
- $this->out->startHTML('text/xml;charset=utf-8');
- $this->out->elementStart('head');
-
- $this->out->element('title', null, _('Command results'));
- $this->out->elementEnd('head');
- $this->out->elementStart('body');
- $this->out->element('p', array('id' => 'command_result'), $text);
- $this->out->elementEnd('body');
- $this->out->endHTML();
- }
- function error($user, $text)
- {
- $this->out->startHTML('text/xml;charset=utf-8');
- $this->out->elementStart('head');
-
- $this->out->element('title', null, _('AJAX error'));
- $this->out->elementEnd('head');
- $this->out->elementStart('body');
- $this->out->element('p', array('id' => 'error'), $text);
- $this->out->elementEnd('body');
- $this->out->endHTML();
- }
- }
- class MailChannel extends Channel
- {
- var $addr = null;
- function source()
- {
- return 'mail';
- }
- function __construct($addr=null)
- {
- $this->addr = $addr;
- }
- function on($user)
- {
- return $this->setNotify($user, 1);
- }
- function off($user)
- {
- return $this->setNotify($user, 0);
- }
- function output($user, $text)
- {
- $headers['From'] = $user->incomingemail;
- $headers['To'] = $this->addr;
-
- $headers['Subject'] = _('Command complete');
- return mail_send(array($this->addr), $headers, $text);
- }
- function error($user, $text)
- {
- $headers['From'] = $user->incomingemail;
- $headers['To'] = $this->addr;
-
- $headers['Subject'] = _('Command failed');
- return mail_send(array($this->addr), $headers, $text);
- }
- function setNotify($user, $value)
- {
- $orig = clone($user);
- $user->smsnotify = $value;
- $result = $user->update($orig);
- if (!$result) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- return false;
- }
- return true;
- }
- }
|