From 60c88520b52c2a027427d652cd145bf94eeeaf01 Mon Sep 17 00:00:00 2001 From: "Duck (Jakob Munih)" Date: Thu, 12 Mar 2009 14:24:50 +0100 Subject: [PATCH] Replace report with generalized notification --- folks/config/conf.xml | 111 +++++++++++++++++++------------------- folks/lib/Report.php | 126 ------------------------------------------- folks/lib/Report/letter.php | 40 -------------- folks/lib/Report/mail.php | 55 ------------------- folks/lib/Report/tickets.php | 25 --------- folks/report.php | 6 +-- 6 files changed, 59 insertions(+), 304 deletions(-) delete mode 100644 folks/lib/Report.php delete mode 100644 folks/lib/Report/letter.php delete mode 100644 folks/lib/Report/mail.php delete mode 100644 folks/lib/Report/tickets.php diff --git a/folks/config/conf.xml b/folks/config/conf.xml index 68dfb87aa..7ff40b80b 100644 --- a/folks/config/conf.xml +++ b/folks/config/conf.xml @@ -119,61 +119,62 @@ - - - Content Reporting Settings - false - - - - array() - all - - all - authenticated - never - - - - - webmaster@example.com - example.com - - - all - - all - authenticated - never - - - - - - all - - all - authenticated - never - - - - - - + + + Notifications + + true + + + + true + false + false + info@example.com + + + + + false + + + + true + true + true + + + + + false + + + + true + true + false + + + + + false + + + + false + false + false + array() + + + + + diff --git a/folks/lib/Report.php b/folks/lib/Report.php deleted file mode 100644 index 61d495288..000000000 --- a/folks/lib/Report.php +++ /dev/null @@ -1,126 +0,0 @@ - - * @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 index 759eaeb6a..000000000 --- a/folks/lib/Report/letter.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @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 index f5a7b951a..000000000 --- a/folks/lib/Report/mail.php +++ /dev/null @@ -1,55 +0,0 @@ - - * @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 index 0d445d247..000000000 --- a/folks/lib/Report/tickets.php +++ /dev/null @@ -1,25 +0,0 @@ - - * @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 diff --git a/folks/report.php b/folks/report.php index 666d9f6a4..fee9ea110 100644 --- a/folks/report.php +++ b/folks/report.php @@ -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'); -- 2.11.0