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')) {
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/
43 class UserFlagPlugin extends Plugin
45 const REVIEWFLAGS = 'UserFlagPlugin::reviewflags';
46 const CLEARFLAGS = 'UserFlagPlugin::clearflags';
48 public $flagOnBlock = true;
51 * Hook for ensuring our tables are created
53 * Ensures that the user_flag_profile table exists
54 * and has the right columns.
56 * @return boolean hook return
58 function onCheckSchema()
60 $schema = Schema::get();
62 // For storing user-submitted flags on profiles
63 $schema->ensureTable('user_flag_profile', User_flag_profile::schemaDef());
68 * Add our actions to the URL router
70 * @param URLMapper $m URL mapper for this hit
72 * @return boolean hook return
74 public function onRouterInitialized(URLMapper $m)
76 $m->connect('main/flag/profile', array('action' => 'flagprofile'));
77 $m->connect('main/flag/clear', array('action' => 'clearflag'));
78 $m->connect('panel/profile/flag', array('action' => 'adminprofileflag'));
83 * Add a 'flag' button to profile page
85 * @param Action $action The action being called
86 * @param Profile $profile Profile being shown
88 * @return boolean hook result
90 function onEndProfilePageActionsElements($action, $profile)
92 $this->showFlagButton($action, $profile,
93 array('action' => 'showstream',
94 'nickname' => $profile->nickname));
100 * Add a 'flag' button to profiles in a list
102 * @param ProfileListItem $item item being shown
104 * @return boolean hook result
106 function onEndProfileListItemActionElements($item)
108 list($action, $args) = $item->action->returnToArgs();
109 $args['action'] = $action;
110 $this->showFlagButton($item->action, $item->profile, $args);
116 * Actually output a flag button. If the target profile has already been
117 * flagged by the current user, a null-action faux button is shown.
119 * @param Action $action
120 * @param Profile $profile
121 * @param array $returnToArgs
123 protected function showFlagButton($action, $profile, $returnToArgs)
125 $user = common_current_user();
127 if (!empty($user) && ($user->id != $profile->id)) {
129 $action->elementStart('li', 'entity_flag');
131 if (User_flag_profile::exists($profile->id, $user->id)) {
132 // @todo FIXME: Add a title explaining what 'flagged' means?
133 // TRANS: Message added to a profile if it has been flagged for review.
134 $action->element('p', 'flagged', _m('Flagged'));
136 $form = new FlagProfileForm($action, $profile, $returnToArgs);
140 $action->elementEnd('li');
145 * Check whether a user has one of our defined rights
147 * We define extra rights; this function checks to see if a
148 * user has one of them.
150 * @param User $user User being checked
151 * @param string $right Right we're checking
152 * @param boolean &$result out, result of the check
154 * @return boolean hook result
156 function onUserRightsCheck($user, $right, &$result)
159 case self::REVIEWFLAGS:
160 case self::CLEARFLAGS:
161 $result = $user->hasRole('moderator');
162 return false; // done processing!
165 return true; // unchanged!
169 * Optionally flag profile when a block happens
171 * We optionally add a flag when a profile has been blocked
173 * @param User $user User doing the block
174 * @param Profile $profile Profile being blocked
176 * @return boolean hook result
178 function onEndBlockProfile($user, $profile)
180 if ($this->flagOnBlock && !User_flag_profile::exists($profile->id,
183 User_flag_profile::create($user->id, $profile->id);
189 * Ensure that flag entries for a profile are deleted
190 * along with the profile when deleting users.
191 * This prevents breakage of the admin profile flag UI.
193 * @param Profile $profile
194 * @param array &$related list of related tables; entries
195 * with matching profile_id will be deleted.
197 * @return boolean hook result
199 function onProfileDeleteRelated($profile, &$related)
201 $related[] = 'user_flag_profile';
206 * Ensure that flag entries created by a user are deleted
207 * when that user gets deleted.
210 * @param array &$related list of related tables; entries
211 * with matching user_id will be deleted.
213 * @return boolean hook result
215 function onUserDeleteRelated($user, &$related)
217 $related[] = 'user_flag_profile';
222 * Provide plugin version information.
224 * This data is used when showing the version page.
226 * @param array &$versions array of version data arrays; see EVENTS.txt
228 * @return boolean hook value
230 function onPluginVersion(array &$versions)
232 $url = 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/UserFlag';
234 $versions[] = array('name' => 'UserFlag',
235 'version' => GNUSOCIAL_VERSION,
236 'author' => 'Evan Prodromou',
239 // TRANS: Plugin description.
240 _m('This plugin allows flagging of profiles for review and reviewing flagged profiles.'));