Replace report with generalized notification
authorDuck (Jakob Munih) <duck@obala.net>
Thu, 12 Mar 2009 13:24:50 +0000 (14:24 +0100)
committerDuck (Jakob Munih) <duck@obala.net>
Thu, 12 Mar 2009 13:24:50 +0000 (14:24 +0100)
folks/config/conf.xml
folks/lib/Report.php [deleted file]
folks/lib/Report/letter.php [deleted file]
folks/lib/Report/mail.php [deleted file]
folks/lib/Report/tickets.php [deleted file]
folks/report.php

index 68dfb87..7ff40b8 100644 (file)
    </configsection>
  </configtab>
 
- <configtab name="report_content" desc="Content Reporting">
-  <configsection name="report_content">
-   <configheader>Content Reporting Settings</configheader>
-   <configswitch name="driver" desc="Driver to use">false
-    <case name="false" desc="Disable">
-    </case>
-    <case name="tickets" desc="Tickets (Whups)">
-     <configphp name="ticket_params" desc="Enter as a PHP array any
-     additional arguments for the created ticket (queue, state, priority,
-     etc). Example for Whups: array('queue' => 2, 'state' => 1, 'priority' => 1,
-     'type' => 1). You will need to look up the appropriate IDs in Whups's
-     database, or whatever is appropriate for the ticket system you are
-     using.">array()</configphp>
-     <configenum name="allow" desc="Who should be allowed to report
-     inappropriate content?">all
-      <values>
-       <value desc="All users">all</value>
-       <value desc="Authenticated users">authenticated</value>
-       <value desc="Never">never</value>
-      </values>
-     </configenum>
-    </case>
-    <case name="mail" desc="Email">
-     <configstring name="email" desc="Where should problem report emails be
-     sent?">webmaster@example.com</configstring>
-     <configstring name="maildomain" desc="If Horde cannot determine a user's
-     email address, this domain will be appended to their
-     username.">example.com</configstring>
-     <configstring name="username" required="false" desc="If requiring SMTP
-     authentication without a global SMTP user (in section &quot;Mailer&quot;
-     and allowing problem reporting for not authenticated users (in section
-     &quot;Menu Settings&quot;), what username should be use for SMTP
-     authentication?"/>
-     <configstring name="password" required="false" desc="The password to use"/>
-     <configenum name="allow" desc="Who should be allowed to report problems?">all
-      <values>
-       <value desc="All users">all</value>
-       <value desc="Authenticated users">authenticated</value>
-       <value desc="Never">never</value>
-      </values>
-     </configenum>
-    </case>
-    <case name="letter" desc="Send internal messages (Letter)">
-     <configlist name="users" desc="Username to receive these messages. If none, Folks admins will be used." />
-     <configenum name="allow" desc="Who should be allowed to report problems?">all
-      <values>
-       <value desc="All users">all</value>
-       <value desc="Authenticated users">authenticated</value>
-       <value desc="Never">never</value>
-      </values>
-     </configenum>
-    </case>
-   </configswitch>
-  </configsection>
- </configtab>
+ <configtab name="notifications" desc="Notifications">
+   <configsection name="notification">
+    <configheader>Notifications</configheader>
+    <configsection name="mail">
+     <configswitch name="enabled" desc="Email">true
+       <case name="false" desc="No">
+       </case>
+       <case name="true" desc="Yes">
+         <configboolean name="users" desc="Use to send users notifications" required="false">true</configboolean>
+         <configboolean name="friends" desc="Use to send friends notifications" required="false">false</configboolean>
+         <configboolean name="admins" desc="Use to send admin notifications" required="false">false</configboolean>
+         <configstring name="from_addr" desc="Email form where send mails">info@example.com</configstring>
+       </case>
+     </configswitch>
+    </configsection>
+    <configsection name="letter">
+     <configswitch name="enabled" desc="Letter">false
+       <case name="false" desc="No">
+       </case>
+       <case name="true" desc="Yes">
+         <configboolean name="users" desc="Use to send users notifications" required="false">true</configboolean>
+         <configboolean name="friends" desc="Use to send friends notifications" required="false">true</configboolean>
+         <configboolean name="admins" desc="Use to send admin notifications" required="false">true</configboolean>
+       </case>
+     </configswitch>
+    </configsection>
+    <configsection name="facebook">
+     <configswitch name="enabled" desc="Facebook">false
+       <case name="false" desc="No">
+       </case>
+       <case name="true" desc="Yes">
+         <configboolean name="users" desc="Use to send users notifications" required="false">true</configboolean>
+         <configboolean name="friends" desc="Use to send friends notifications" required="false">true</configboolean>
+         <configboolean name="admins" desc="Use to send admin notifications" required="false">false</configboolean>
+       </case>
+     </configswitch>
+    </configsection>
+    <configsection name="tickets">
+     <configswitch name="enabled" desc="Tickets (whups)">false
+       <case name="false" desc="No">
+       </case>
+       <case name="true" desc="Yes">
+         <configboolean name="users" desc="Use to send users notifications" required="false">false</configboolean>
+         <configboolean name="friends" desc="Use to send friends notifications" required="false">false</configboolean>
+         <configboolean name="admins" desc="Use to send admin notifications" required="false">false</configboolean>
+          <configphp name="ticket_params" desc="Enter as a PHP array any
+            additional arguments for the created ticket (queue, state, priority,
+            etc). Example for Whups: array('queue' => 2, 'state' => 1, 'priority' => 1,
+            'type' => 1). You will need to look up the appropriate IDs in Whups's
+            database, or whatever is appropriate for the ticket system you are
+            using.">array()</configphp>
+       </case>
+     </configswitch>
+    </configsection>
+   </configsection>
+</configtab>
 
  <configtab name="menu" desc="Menu">
    <configsection name="menu">
diff --git a/folks/lib/Report.php b/folks/lib/Report.php
deleted file mode 100644 (file)
index 61d4952..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-<?php
-/**
- * Reporting abstraction class
- *
- * $Horde: ansel/lib/Report.php,v 1.9 2008-07-03 04:16:00 mrubinsk Exp $
- *
- * Copyright 2009 The Horde Project (http://www.horde.org)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * Copyright 2008 The Horde Project (http://www.horde.org)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Duck <duck@obala.net>
- * @package Folks
- */
-class Folks_Report {
-
-    var $_title = '';
-
-    /**
-     * Create instance
-     */
-    public static factory($driver = null, $params = array())
-    {
-        if ($driver === null) {
-            $driver = $GLOBALS['conf']['report_content']['driver'];
-        }
-
-        if (empty($params)) {
-            $params = $GLOBALS['conf']['report_content'];
-        }
-
-        require_once FOLKS_BASE . '/lib/Report/' . $driver  . '.php';
-        $class_name = 'Folks_Report_' . $driver;
-        if (!class_exists($class_name)) {
-            return PEAR::RaiseError(_("Report driver does not exist."));
-        }
-
-        $report = new $class_name($params);
-
-        return $report;
-    }
-
-    /**
-     * Get reporting user email
-     */
-    public function getUserEmail()
-    {
-        return $this->_getUserEmail();
-    }
-
-    /**
-     * Get user email
-     */
-    public function _getUserEmail($user = null)
-    {
-        require_once 'Horde/Identity.php';
-
-        // Get user email
-        $identity = &Identity::singleton('none', $user);
-        return $identity->getValue('from_addr');
-    }
-
-    /**
-     * Get scope admins
-     */
-    public function getAdmins()
-    {
-        $name = $GLOBALS['registry']->getApp() . ':admin';
-
-        if ($GLOBALS['perms']->exists($name)) {
-            $permission = $GLOBALS['perms']->getPermission($name);
-            if ($permission instanceof PEAR_Error) {
-                return $permission;
-            }
-            return $permission->getUserPermissions(PERM_DELETE);
-        } else {
-            return $GLOBALS['conf']['auth']['admins'];
-        }
-    }
-
-    /**
-     * Set title
-     */
-    public function setTitle($title)
-    {
-        $this->_title = $title;
-    }
-
-    /**
-     * Get report message title
-     */
-    public function getTitle()
-    {
-        if (empty($this->_title)) {
-            return sprintf(_("Content abuse report in %s"), $GLOBALS['registry']->get('name'));
-        } else {
-            return $this->_title;
-        }
-    }
-
-    /**
-     * Get report message content
-     */
-    public function getMessage($message)
-    {
-        $message .=  "\n\n" . _("Report by user") . ': ' . Auth::getAuth()
-                 . ' (' . $_SERVER['REMOTE_ADDR'] . ')';
-
-        return $message;
-    }
-
-    /**
-     * Report
-     *
-     * @param string $message to pass
-     */
-    public function report($message, $users = array())
-    {
-        return PEAR::raiseError(_("Unsupported"));
-    }
-}
diff --git a/folks/lib/Report/letter.php b/folks/lib/Report/letter.php
deleted file mode 100644 (file)
index 759eaeb..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
- * Report by letter api class
- *
- * $Horde: Folks/lib/Report/letter.php,v 1.5 2008/07/03 04:13:35 mrubinsk Exp $
- *
- * @author  Duck <duck@obala.net>
- * @package Folks
- */
-class Folks_Report_letter extends Folks_Report {
-
-    /**
-     * Report
-     */
-    public function report($message, $users = array())
-    {
-        if (!empty($users)) {
-            // We are sending a report to to the gallery owner
-            $admins = array($users);
-        } elseif (empty($GLOBALS['conf']['report_content']['users'])) {
-            $admins = $this->getAdmins();
-            if ($admins instanceof PEAR_Error) {
-                return $admins;
-            }
-            if (empty($admins)) {
-                return true;
-            }
-        } else {
-            $admins = $GLOBALS['conf']['report_content']['users'];
-        }
-
-        $title = $this->getTitle();
-        $message = $this->getMessage($message);
-
-        return $GLOBALS['registry']->callByPackage(
-            'letter', 'sendMessage', array($admins,
-                                           array('title' => $title,
-                                                 'content' => $message)));
-    }
-}
\ No newline at end of file
diff --git a/folks/lib/Report/mail.php b/folks/lib/Report/mail.php
deleted file mode 100644 (file)
index f5a7b95..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/**
- * Report by email class
- *
- * $Horde: Folks/lib/Report/mail.php,v 1.7 2008/07/03 04:17:52 mrubinsk Exp $
- *
- * @author  Duck <duck@obala.net>
- * @package Folks
- */
-class Folks_Report_mail extends Folks_Report {
-
-    /**
-     * Report
-     */
-    public function report($message, $users = array())
-    {
-        global $conf;
-
-        if (empty($users)) {
-            $to = $conf['report_content']['email'];
-        } else {
-            // we are sending a report to to the gallery owner, but fall back
-            // to the admin in case the user has no email.
-            $to = $this->_getUserEmail($users);
-            if (empty($to)) {
-                $to = $conf['report_content']['email'];
-            }
-        }
-
-        /*
-         * Needed for the Horde 4 mime library - use autoload everywhere we can
-         * when this is *really* refactored for horde 4
-         */
-        $mail = new Horde_Mime_Mail($this->getTitle(), $this->getMessage($message), $to, $this->getUserEmail());
-
-        //FIXME: This address should be configurable
-        $mail->addHeader('Sender', 'horde-problem@' . $conf['report_content']['maildomain']);
-
-        $mail_driver = $conf['mailer']['type'];
-        $mail_params = $conf['mailer']['params'];
-        if ($mail_driver == 'smtp' && $mail_params['auth'] &&
-            empty($mail_params['username'])) {
-            if (Auth::getAuth()) {
-                $mail_params['username'] = Auth::getAuth();
-                $mail_params['password'] = Auth::getCredential('password');
-            } elseif (!empty($conf['report_content']['username']) &&
-                        !empty($conf['report_content']['password'])) {
-                $mail_params['username'] = $conf['report_content']['username'];
-                $mail_params['password'] = $conf['report_content']['password'];
-            }
-        }
-
-        return $mail->send($mail_driver, $mail_params);
-    }
-}
\ No newline at end of file
diff --git a/folks/lib/Report/tickets.php b/folks/lib/Report/tickets.php
deleted file mode 100644 (file)
index 0d445d2..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-/**
- * Report using tickets
- *
- * $Horde: Folks/lib/Report/tickets.php,v 1.3 2008/05/07 01:45:56 chuck Exp $
- *
- * @author  Duck <duck@obala.net>
- * @package Folks
- */
-class Folks_Report_tickets extends Folks_Report {
-
-    /**
-     * Report
-     */
-    public function report($message)
-    {
-        $info = array_merge($GLOBALS['conf']['report_content']['ticket_params'],
-                            array('summary' => $this->getTitle(),
-                                    'comment' => $message,
-                                    'user_email' => $this->getUserEmail()));
-
-        return $registry->call('tickets/addTicket', array($info));
-    }
-
-}
\ No newline at end of file
index 666d9f6..fee9ea1 100644 (file)
@@ -49,15 +49,15 @@ $user_id = Util::getFormData('id');
 
 if ($form->validate()) {
     if (Util::getFormData('submitbutton') == _("Report")) {
-        require FOLKS_BASE . '/lib/Report.php';
-        $report = Folks_Report::factory();
 
         $body =  _("User") . ': ' . $user . "\n"
             . _("Report type") . ': ' . $enum[$vars->get('type')] . "\n"
             . _("Report reason") . ': ' . $vars->get('reason') . "\n"
             . Folks::getUrlFor('user', $user);
 
-        $result = $report->report($body);
+        require FOLKS_BASE . '/lib/Notification.php';
+        $rn = new Folks_Notification();
+        $result = $rn->notifyAdmins($title, $body);
         if ($result instanceof PEAR_Error) {
             $notification->push(_("User was not reported.") . ' ' .
                                 $result->getMessage(), 'horde.error');