+
+ /**
+ * Initialize any flagging buttons on the page
+ *
+ * @param Action $action action being shown
+ *
+ * @return boolean hook result
+ */
+
+ function onEndShowScripts($action)
+ {
+ $action->inlineScript('if ($(".form_entity_flag").length > 0) { '.
+ '$(".form_entity_flag").bind("click", function() {'.
+ 'SN.U.FormXHR($(this)); return false; }); }');
+ return true;
+ }
+
+ /**
+ * Check whether a user has one of our defined rights
+ *
+ * We define extra rights; this function checks to see if a
+ * user has one of them.
+ *
+ * @param User $user User being checked
+ * @param string $right Right we're checking
+ * @param boolean &$result out, result of the check
+ *
+ * @return boolean hook result
+ */
+
+ function onUserRightsCheck($user, $right, &$result)
+ {
+ switch ($right) {
+ case self::REVIEWFLAGS:
+ case self::CLEARFLAGS:
+ $result = $user->hasRole('moderator');
+ return false; // done processing!
+ }
+
+ return true; // unchanged!
+ }
+
+ /**
+ * Optionally flag profile when a block happens
+ *
+ * We optionally add a flag when a profile has been blocked
+ *
+ * @param User $user User doing the block
+ * @param Profile $profile Profile being blocked
+ *
+ * @return boolean hook result
+ */
+
+ function onEndBlockProfile($user, $profile)
+ {
+ if ($this->flagOnBlock && !User_flag_profile::exists($profile->id,
+ $user->id)) {
+
+ User_flag_profile::create($user->id, $profile->id);
+ }
+ return true;
+ }
+
+ /**
+ * Ensure that flag entries for a profile are deleted
+ * along with the profile when deleting users.
+ * This prevents breakage of the admin profile flag UI.
+ *
+ * @param Profile $profile
+ * @param array &$related list of related tables; entries
+ * with matching profile_id will be deleted.
+ *
+ * @return boolean hook result
+ */
+
+ function onProfileDeleteRelated($profile, &$related)
+ {
+ $related[] = 'user_flag_profile';
+ return true;
+ }
+
+ /**
+ * Ensure that flag entries created by a user are deleted
+ * when that user gets deleted.
+ *
+ * @param User $user
+ * @param array &$related list of related tables; entries
+ * with matching user_id will be deleted.
+ *
+ * @return boolean hook result
+ */
+
+ function onUserDeleteRelated($user, &$related)
+ {
+ $related[] = 'user_flag_profile';
+ return true;
+ }