]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/UserFlagPlugin.php
admin page checks for right to review flags
[quix0rs-gnu-social.git] / plugins / UserFlag / UserFlagPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Allows users to flag content and accounts as offensive/spam/whatever
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Plugin
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Allows users to flag content and accounts as offensive/spam/whatever
36  *
37  * @category Plugin
38  * @package  StatusNet
39  * @author   Evan Prodromou <evan@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43
44 class UserFlagPlugin extends Plugin
45 {
46     const REVIEWFLAGS = 'UserFlagPlugin::reviewflags';
47
48     function onCheckSchema()
49     {
50         $schema = Schema::get();
51
52         // For storing user-submitted flags on profiles
53
54         $schema->ensureTable('user_flag_profile',
55                              array(new ColumnDef('profile_id', 'integer', null,
56                                                  false, 'PRI'),
57                                    new ColumnDef('user_id', 'integer', null,
58                                                  false, 'PRI'),
59                                    new ColumnDef('created', 'datetime', null,
60                                                  false, 'MUL'),
61                                    new ColumnDef('cleared', 'datetime', null,
62                                                  true, 'MUL')));
63
64         return true;
65     }
66
67     function onInitializePlugin()
68     {
69         // XXX: do something here?
70         return true;
71     }
72
73     function onRouterInitialized($m) {
74         $m->connect('main/flag/profile', array('action' => 'flagprofile'));
75         $m->connect('admin/profile/flag', array('action' => 'adminprofileflag'));
76         return true;
77     }
78
79    function onAutoload($cls)
80     {
81         switch ($cls)
82         {
83         case 'FlagprofileAction':
84         case 'AdminprofileflagAction':
85             require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
86             return false;
87         case 'FlagProfileForm':
88             require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower($cls . '.php'));
89             return false;
90         case 'User_flag_profile':
91             require_once(INSTALLDIR.'/plugins/UserFlag/'.$cls.'.php');
92             return false;
93         default:
94             return true;
95         }
96     }
97
98     function onEndProfilePageActionsElements(&$action, $profile)
99     {
100         $user = common_current_user();
101
102         if (!empty($user) && ($user->id != $profile->id)) {
103
104             $action->elementStart('li', 'entity_flag');
105
106             if (User_flag_profile::exists($profile->id, $user->id)) {
107                 $action->element('p', 'flagged', _('Flagged'));
108             } else {
109                 $form = new FlagProfileForm($action, $profile,
110                                         array('action' => 'showstream',
111                                               'nickname' => $profile->nickname));
112                 $form->show();
113             }
114
115             $action->elementEnd('li');
116         }
117
118         return true;
119     }
120
121     function onEndProfileListItemActionElements($item)
122     {
123         $user = common_current_user();
124
125         if (!empty($user)) {
126
127             list($action, $args) = $item->action->returnToArgs();
128
129             $args['action'] = $action;
130
131             $form = new FlagProfileForm($item->action, $item->profile, $args);
132
133             $item->action->elementStart('li', 'entity_flag');
134             $form->show();
135             $item->action->elementEnd('li');
136         }
137
138         return true;
139     }
140
141     function onEndShowStatusNetStyles($action)
142     {
143         $action->cssLink(common_path('plugins/UserFlag/userflag.css'),
144                          null, 'screen, projection, tv');
145         return true;
146     }
147
148     function onEndShowScripts($action)
149     {
150         $action->inlineScript('if ($(".form_entity_flag").length > 0) { SN.U.FormXHR($(".form_entity_flag")); }');
151         return true;
152     }
153
154     function onUserRightsCheck($user, $right, &$result) {
155         if ($right == self::REVIEWFLAGS) {
156             $result = $user->hasRole('moderator');
157             return false; // done processing!
158         }
159         return true; // unchanged!
160     }
161 }