]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ModLog/ModLogPlugin.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / ModLog / ModLogPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2012, StatusNet, Inc.
5  *
6  * ModLogPlugin.php
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Moderation
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2012 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Moderation logging
39  *
40  * Shows a history of moderation for this user in the sidebar
41  *
42  * @category  Moderation
43  * @package   StatusNet
44  * @author    Evan Prodromou <evan@status.net>
45  * @copyright 2012 StatusNet, Inc.
46  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
47  * @link      http://status.net/
48  */
49
50 class ModLogPlugin extends Plugin
51 {
52     const VIEWMODLOG = 'ModLogPlugin::VIEWMODLOG';
53
54     /**
55      * Database schema setup
56      *
57      * We keep a moderation log table
58      *
59      * @see Schema
60      * @see ColumnDef
61      *
62      * @return boolean hook value; true means continue processing, false means stop.
63      */
64
65     function onCheckSchema()
66     {
67         $schema = Schema::get();
68
69         $schema->ensureTable('mod_log', ModLog::schemaDef());
70
71         return true;
72     }
73
74     function onEndGrantRole($profile, $role)
75     {
76         $modlog = new ModLog();
77
78         $modlog->id         = UUID::gen();
79         $modlog->profile_id = $profile->id;
80
81         $cur = common_current_user();
82         
83         if (!empty($cur)) {
84             $modlog->moderator_id = $cur->id;
85         }
86
87         $modlog->role     = $role;
88         $modlog->is_grant = 1;
89         $modlog->created  = common_sql_now();
90
91         $modlog->insert();
92
93         return true;
94     }
95
96     function onEndRevokeRole($profile, $role)
97     {
98         $modlog = new ModLog();
99
100         $modlog->id = UUID::gen();
101
102         $modlog->profile_id = $profile->id;
103
104         $scoped = Profile::current();
105         
106         if ($scoped instanceof Profile) {
107             $modlog->moderator_id = $scoped->getID();
108         }
109
110         $modlog->role     = $role;
111         $modlog->is_grant = 0;
112         $modlog->created  = common_sql_now();
113
114         $modlog->insert();
115
116         return true;
117     }
118
119     function onEndShowSections(Action $action)
120     {
121         if (!$action instanceof ShowstreamAction) {
122             // early return for actions we're not interested in
123             return true;
124         }
125
126         $scoped = $action->getScoped();
127         if (!$scoped instanceof Profile || !$scoped->hasRight(self::VIEWMODLOG)) {
128             // only continue if we are allowed to VIEWMODLOG
129             return true;
130         }
131
132         $profile = $action->getTarget();
133
134         $ml = new ModLog();
135
136         $ml->profile_id = $profile->getID();
137         $ml->orderBy("created");
138
139         $cnt = $ml->find();
140
141         if ($cnt > 0) {
142
143             $action->elementStart('div', array('id' => 'entity_mod_log',
144                                                'class' => 'section'));
145
146             $action->element('h2', null, _('Moderation'));
147
148             $action->elementStart('table');
149
150             while ($ml->fetch()) {
151                 $action->elementStart('tr');
152                 $action->element('td', null, strftime('%y-%m-%d', strtotime($ml->created)));
153                 $action->element('td', null, sprintf(($ml->is_grant) ? _('+%s') : _('-%s'), $ml->role));
154                 $action->elementStart('td');
155                 if ($ml->moderator_id) {
156                     $mod = Profile::getByID($ml->moderator_id);
157                     if (empty($mod)) {
158                         $action->text(_('[unknown]'));
159                     } else {
160                         $action->element('a', array('href' => $mod->getUrl(),
161                                                     'title' => $mod->getFullname()),
162                                          $mod->getNickname());
163                     }
164                 } else {
165                     $action->text(_('[unknown]'));
166                 }
167                 $action->elementEnd('td');
168                 $action->elementEnd('tr');
169             }
170
171             $action->elementEnd('table');
172
173             $action->elementEnd('div');
174         }
175     }
176
177     function onUserRightsCheck($profile, $right, &$result) {
178         switch ($right) {
179         case self::VIEWMODLOG:
180             $result = ($profile->hasRole(Profile_role::MODERATOR) || $profile->hasRole('modhelper'));
181             return false;
182         default:
183             return true;
184         }
185     }
186
187     function onPluginVersion(array &$versions)
188     {
189         $versions[] = array('name' => 'ModLog',
190                             'version' => GNUSOCIAL_VERSION,
191                             'author' => 'Evan Prodromou',
192                             'homepage' => 'http://status.net/wiki/Plugin:ModLog',
193                             'description' =>
194                             _m('Show the moderation history for a profile in the sidebar'));
195         return true;
196     }
197 }