3 * StatusNet, the distributed open-source microblogging tool
5 * Allows users to flag content and accounts as offensive/spam/whatever
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.
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.
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/>.
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/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 * Allows users to flag content and accounts as offensive/spam/whatever
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/
44 class UserFlagPlugin extends Plugin
46 const REVIEWFLAGS = 'UserFlagPlugin::reviewflags';
48 function onCheckSchema()
50 $schema = Schema::get();
52 // For storing user-submitted flags on profiles
54 $schema->ensureTable('user_flag_profile',
55 array(new ColumnDef('profile_id', 'integer', null,
57 new ColumnDef('user_id', 'integer', null,
59 new ColumnDef('created', 'datetime', null,
61 new ColumnDef('cleared', 'datetime', null,
67 function onInitializePlugin()
69 // XXX: do something here?
73 function onRouterInitialized($m) {
74 $m->connect('main/flag/profile', array('action' => 'flagprofile'));
75 $m->connect('admin/profile/flag', array('action' => 'adminprofileflag'));
79 function onAutoload($cls)
83 case 'FlagprofileAction':
84 case 'AdminprofileflagAction':
85 require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
87 case 'FlagProfileForm':
88 require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower($cls . '.php'));
90 case 'User_flag_profile':
91 require_once(INSTALLDIR.'/plugins/UserFlag/'.$cls.'.php');
98 function onEndProfilePageActionsElements(&$action, $profile)
100 $user = common_current_user();
102 if (!empty($user) && ($user->id != $profile->id)) {
104 $action->elementStart('li', 'entity_flag');
106 if (User_flag_profile::exists($profile->id, $user->id)) {
107 $action->element('p', 'flagged', _('Flagged'));
109 $form = new FlagProfileForm($action, $profile,
110 array('action' => 'showstream',
111 'nickname' => $profile->nickname));
115 $action->elementEnd('li');
121 function onEndProfileListItemActionElements($item)
123 $user = common_current_user();
127 list($action, $args) = $item->action->returnToArgs();
129 $args['action'] = $action;
131 $form = new FlagProfileForm($item->action, $item->profile, $args);
133 $item->action->elementStart('li', 'entity_flag');
135 $item->action->elementEnd('li');
141 function onEndShowStatusNetStyles($action)
143 $action->cssLink(common_path('plugins/UserFlag/userflag.css'),
144 null, 'screen, projection, tv');
148 function onEndShowScripts($action)
150 $action->inlineScript('if ($(".form_entity_flag").length > 0) { SN.U.FormXHR($(".form_entity_flag")); }');
154 function onUserRightsCheck($user, $right, &$result) {
155 if ($right == self::REVIEWFLAGS) {
156 $result = $user->hasRole('moderator');
157 return false; // done processing!
159 return true; // unchanged!