1: <?php
2: /**
3: * Reporting abstraction class
4: *
5: * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (GPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/gpl.
9: *
10: * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
11: *
12: * See the enclosed file COPYING for license information (GPL). If you
13: * did not receive this file, see http://www.horde.org/licenses/gpl.
14: *
15: * @author Duck <duck@obala.net>
16: * @package Ansel
17: */
18: class Ansel_Report {
19:
20: var $_title = '';
21:
22: /**
23: * Create instance
24: */
25: function factory($driver = null, $params = array())
26: {
27: if ($driver === null) {
28: $driver = $GLOBALS['conf']['report_content']['driver'];
29: }
30:
31: if (empty($params)) {
32: $params = $GLOBALS['conf']['report_content'];
33: }
34:
35: $class_name = 'Ansel_Report_' . $driver;
36: if (!class_exists($class_name)) {
37: return PEAR::RaiseError(_("Report driver does not exist."));
38: }
39:
40: $report = new $class_name($params);
41:
42: return $report;
43: }
44:
45: /**
46: * Get reporting user email
47: */
48: function getUserEmail()
49: {
50: return $this->_getUserEmail();
51: }
52:
53: /**
54: * Get user email
55: */
56: function _getUserEmail($user = null)
57: {
58: return $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user)->getValue('from_addr');
59: }
60:
61: /**
62: * Get scope admins
63: */
64: function getAdmins()
65: {
66: $name = $GLOBALS['registry']->getApp() . ':admin';
67:
68: if ($GLOBALS['injector']->getInstance('Horde_Perms')->exists($name)) {
69: return array();
70: }
71:
72: $permission = $GLOBALS['injector']->getInstance('Horde_Perms')->getPermission($name);
73:
74: return $permission->getUserPermissions(PERM_DELETE);
75: }
76:
77: /**
78: * Set title
79: */
80: function setTitle($title)
81: {
82: $this->_title = $title;
83: }
84:
85: /**
86: * Get report message title
87: */
88: function getTitle()
89: {
90: if (empty($this->_title)) {
91: return sprintf(_("Content abuse report in %s"), $GLOBALS['registry']->get('name'));
92: } else {
93: return $this->_title;
94: }
95: }
96:
97: /**
98: * Get report message content
99: */
100: function getMessage($message)
101: {
102: $message .= "\n\n" . _("Report by user") . ': ' . $GLOBALS['registry']->getAuth()
103: . ' (' . $_SERVER['REMOTE_ADDR'] . ')';
104:
105: return $message;
106: }
107:
108: /**
109: * Report
110: *
111: * @param string $message to pass
112: */
113: function report($message, $users = array())
114: {
115: return PEAR::raiseError(_("Unsupported"));
116: }
117: }
118: