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';
47 const CLEARFLAGS = 'UserFlagPlugin::clearflags';
49 function onCheckSchema()
51 $schema = Schema::get();
53 // For storing user-submitted flags on profiles
55 $schema->ensureTable('user_flag_profile',
56 array(new ColumnDef('profile_id', 'integer', null,
58 new ColumnDef('user_id', 'integer', null,
60 new ColumnDef('created', 'datetime', null,
62 new ColumnDef('cleared', 'datetime', null,
68 function onInitializePlugin()
70 // XXX: do something here?
74 function onRouterInitialized($m) {
75 $m->connect('main/flag/profile', array('action' => 'flagprofile'));
76 $m->connect('main/flag/clear', array('action' => 'clearflag'));
77 $m->connect('admin/profile/flag', array('action' => 'adminprofileflag'));
81 function onAutoload($cls)
85 case 'FlagprofileAction':
86 case 'AdminprofileflagAction':
87 case 'ClearflagAction':
88 require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
90 case 'FlagProfileForm':
92 require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower($cls . '.php'));
94 case 'User_flag_profile':
95 require_once(INSTALLDIR.'/plugins/UserFlag/'.$cls.'.php');
102 function onEndProfilePageActionsElements(&$action, $profile)
104 $user = common_current_user();
106 if (!empty($user) && ($user->id != $profile->id)) {
108 $action->elementStart('li', 'entity_flag');
110 if (User_flag_profile::exists($profile->id, $user->id)) {
111 $action->element('p', 'flagged', _('Flagged'));
113 $form = new FlagProfileForm($action, $profile,
114 array('action' => 'showstream',
115 'nickname' => $profile->nickname));
119 $action->elementEnd('li');
125 function onEndProfileListItemActionElements($item)
127 $user = common_current_user();
131 list($action, $args) = $item->action->returnToArgs();
133 $args['action'] = $action;
135 $form = new FlagProfileForm($item->action, $item->profile, $args);
137 $item->action->elementStart('li', 'entity_flag');
139 $item->action->elementEnd('li');
145 function onEndShowStatusNetStyles($action)
147 $action->cssLink(common_path('plugins/UserFlag/userflag.css'),
148 null, 'screen, projection, tv');
152 function onEndShowScripts($action)
154 $action->inlineScript('if ($(".form_entity_flag").length > 0) { SN.U.FormXHR($(".form_entity_flag")); }');
158 function onUserRightsCheck($user, $right, &$result) {
160 case self::REVIEWFLAGS:
161 case self::CLEARFLAGS:
162 $result = $user->hasRole('moderator');
163 return false; // done processing!
166 return true; // unchanged!