]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/channel.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / lib / channel.php
index f1e2055466ae2f7f83fe66b39b8ca9b94f2caaac..ae9b2d214f602e8b68a35feeedeaa4bf2655f37f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, StatusNet, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
+/**
+ * @todo Needs documentation.
+ */
 class Channel
 {
     function on($user)
@@ -47,60 +50,22 @@ class Channel
     }
 }
 
-class XMPPChannel extends Channel
+class CLIChannel extends Channel
 {
-
-    var $conn = null;
-
     function source()
     {
-        return 'xmpp';
-    }
-
-    function __construct($conn)
-    {
-        $this->conn = $conn;
-    }
-
-    function on($user)
-    {
-        return $this->set_notify($user, 1);
-    }
-
-    function off($user)
-    {
-        return $this->set_notify($user, 0);
+        return 'cli';
     }
 
     function output($user, $text)
     {
-        $text = '['.common_config('site', 'name') . '] ' . $text;
-        jabber_send_message($user->jabber, $text);
+        $site = common_config('site', 'name');
+        print "[{$user->nickname}@{$site}] $text\n";
     }
 
     function error($user, $text)
     {
-        $text = '['.common_config('site', 'name') . '] ' . $text;
-        jabber_send_message($user->jabber, $text);
-    }
-
-    function set_notify(&$user, $notify)
-    {
-        $orig = clone($user);
-        $user->jabbernotify = $notify;
-        $result = $user->update($orig);
-        if (!$result) {
-            $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
-            common_log(LOG_ERR,
-                       'Could not set notify flag to ' . $notify .
-                       ' for user ' . common_log_objstring($user) .
-                       ': ' . $last_error->message);
-            return false;
-        } else {
-            common_log(LOG_INFO,
-                       'User ' . $user->nickname . ' set notify flag to ' . $notify);
-            return true;
-        }
+        $this->output($user, $text);
     }
 }
 
@@ -135,6 +100,7 @@ class WebChannel extends Channel
         #      depending on what command was run
         $this->out->startHTML();
         $this->out->elementStart('head');
+        // TRANS: Title for command results.
         $this->out->element('title', null, _('Command results'));
         $this->out->elementEnd('head');
         $this->out->elementStart('body');
@@ -155,6 +121,7 @@ class AjaxWebChannel extends WebChannel
     {
         $this->out->startHTML('text/xml;charset=utf-8');
         $this->out->elementStart('head');
+        // TRANS: Title for command results.
         $this->out->element('title', null, _('Command results'));
         $this->out->elementEnd('head');
         $this->out->elementStart('body');
@@ -167,7 +134,8 @@ class AjaxWebChannel extends WebChannel
     {
         $this->out->startHTML('text/xml;charset=utf-8');
         $this->out->elementStart('head');
-        $this->out->element('title', null, _('Ajax Error'));
+        // TRANS: Title for command results.
+        $this->out->element('title', null, _('AJAX error'));
         $this->out->elementEnd('head');
         $this->out->elementStart('body');
         $this->out->element('p', array('id' => 'error'), $text);
@@ -178,7 +146,6 @@ class AjaxWebChannel extends WebChannel
 
 class MailChannel extends Channel
 {
-
     var $addr = null;
 
     function source()
@@ -193,20 +160,20 @@ class MailChannel extends Channel
 
     function on($user)
     {
-        return $this->set_notify($user, 1);
+        return $this->setNotify($user, 1);
     }
 
     function off($user)
     {
-        return $this->set_notify($user, 0);
+        return $this->setNotify($user, 0);
     }
 
     function output($user, $text)
     {
-
         $headers['From'] = $user->incomingemail;
         $headers['To'] = $this->addr;
 
+        // TRANS: E-mail subject when a command has completed.
         $headers['Subject'] = _('Command complete');
 
         return mail_send(array($this->addr), $headers, $text);
@@ -214,16 +181,16 @@ class MailChannel extends Channel
 
     function error($user, $text)
     {
-
         $headers['From'] = $user->incomingemail;
         $headers['To'] = $this->addr;
 
+        // TRANS: E-mail subject when a command has failed.
         $headers['Subject'] = _('Command failed');
 
         return mail_send(array($this->addr), $headers, $text);
     }
 
-    function set_notify($user, $value)
+    function setNotify($user, $value)
     {
         $orig = clone($user);
         $user->smsnotify = $value;