]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/UserFlag/UserFlagPlugin.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / plugins / UserFlag / UserFlagPlugin.php
index 602a5bfa881d20c6739b71269a09fcc6b87f2803..52b1fc299e320f3f82b64c591679b8f29480a586 100644 (file)
@@ -40,7 +40,6 @@ if (!defined('STATUSNET')) {
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
  */
-
 class UserFlagPlugin extends Plugin
 {
     const REVIEWFLAGS = 'UserFlagPlugin::reviewflags';
@@ -56,7 +55,6 @@ class UserFlagPlugin extends Plugin
      *
      * @return boolean hook return
      */
-
     function onCheckSchema()
     {
         $schema = Schema::get();
@@ -83,12 +81,11 @@ class UserFlagPlugin extends Plugin
      *
      * @return boolean hook return
      */
-
     function onRouterInitialized($m)
     {
         $m->connect('main/flag/profile', array('action' => 'flagprofile'));
         $m->connect('main/flag/clear', array('action' => 'clearflag'));
-        $m->connect('admin/profile/flag', array('action' => 'adminprofileflag'));
+        $m->connect('panel/profile/flag', array('action' => 'adminprofileflag'));
         return true;
     }
 
@@ -99,23 +96,22 @@ class UserFlagPlugin extends Plugin
      *
      * @return boolean hook return
      */
-
     function onAutoload($cls)
     {
-        switch ($cls)
+        switch (strtolower($cls))
         {
-        case 'FlagprofileAction':
-        case 'AdminprofileflagAction':
-        case 'ClearflagAction':
+        case 'flagprofileaction':
+        case 'adminprofileflagaction':
+        case 'clearflagaction':
             include_once INSTALLDIR.'/plugins/UserFlag/' .
               strtolower(mb_substr($cls, 0, -6)) . '.php';
             return false;
-        case 'FlagProfileForm':
-        case 'ClearFlagForm':
+        case 'flagprofileform':
+        case 'clearflagform':
             include_once INSTALLDIR.'/plugins/UserFlag/' . strtolower($cls . '.php');
             return false;
-        case 'User_flag_profile':
-            include_once INSTALLDIR.'/plugins/UserFlag/'.$cls.'.php';
+        case 'user_flag_profile':
+            include_once INSTALLDIR.'/plugins/UserFlag/'.ucfirst(strtolower($cls)).'.php';
             return false;
         default:
             return true;
@@ -125,31 +121,16 @@ class UserFlagPlugin extends Plugin
     /**
      * Add a 'flag' button to profile page
      *
-     * @param Action  &$action The action being called
+     * @param Action  $action The action being called
      * @param Profile $profile Profile being shown
      *
      * @return boolean hook result
      */
-
-    function onEndProfilePageActionsElements(&$action, $profile)
+    function onEndProfilePageActionsElements($action, $profile)
     {
-        $user = common_current_user();
-
-        if (!empty($user) && ($user->id != $profile->id)) {
-
-            $action->elementStart('li', 'entity_flag');
-
-            if (User_flag_profile::exists($profile->id, $user->id)) {
-                $action->element('p', 'flagged', _('Flagged'));
-            } else {
-                $form = new FlagProfileForm($action, $profile,
-                                            array('action' => 'showstream',
-                                                  'nickname' => $profile->nickname));
-                $form->show();
-            }
-
-            $action->elementEnd('li');
-        }
+        $this->showFlagButton($action, $profile,
+                              array('action' => 'showstream',
+                                    'nickname' => $profile->nickname));
 
         return true;
     }
@@ -161,40 +142,42 @@ class UserFlagPlugin extends Plugin
      *
      * @return boolean hook result
      */
-
     function onEndProfileListItemActionElements($item)
     {
-        $user = common_current_user();
-
-        if (!empty($user)) {
-
-            list($action, $args) = $item->action->returnToArgs();
-
-            $args['action'] = $action;
-
-            $form = new FlagProfileForm($item->action, $item->profile, $args);
-
-            $item->action->elementStart('li', 'entity_flag');
-            $form->show();
-            $item->action->elementEnd('li');
-        }
+        list($action, $args) = $item->action->returnToArgs();
+        $args['action'] = $action;
+        $this->showFlagButton($item->action, $item->profile, $args);
 
         return true;
     }
 
     /**
-     * Add our plugin's CSS to page output
+     * Actually output a flag button. If the target profile has already been
+     * flagged by the current user, a null-action faux button is shown.
      *
-     * @param Action $action action being shown
-     *
-     * @return boolean hook result
+     * @param Action $action
+     * @param Profile $profile
+     * @param array $returnToArgs
      */
-
-    function onEndShowStatusNetStyles($action)
+    protected function showFlagButton($action, $profile, $returnToArgs)
     {
-        $action->cssLink(common_path('plugins/UserFlag/userflag.css'),
-                         null, 'screen, projection, tv');
-        return true;
+        $user = common_current_user();
+
+        if (!empty($user) && ($user->id != $profile->id)) {
+
+            $action->elementStart('li', 'entity_flag');
+
+            if (User_flag_profile::exists($profile->id, $user->id)) {
+                // @todo FIXME: Add a title explaining what 'flagged' means?
+                // TRANS: Message added to a profile if it has been flagged for review.
+                $action->element('p', 'flagged', _m('Flagged'));
+            } else {
+                $form = new FlagProfileForm($action, $profile, $returnToArgs);
+                $form->show();
+            }
+
+            $action->elementEnd('li');
+        }
     }
 
     /**
@@ -204,12 +187,11 @@ class UserFlagPlugin extends Plugin
      *
      * @return boolean hook result
      */
-
     function onEndShowScripts($action)
     {
         $action->inlineScript('if ($(".form_entity_flag").length > 0) { '.
-                              'SN.U.FormXHR($(".form_entity_flag")); '.
-                              '}');
+                              '$(".form_entity_flag").bind("click", function() {'.
+                              'SN.U.FormXHR($(this)); return false; }); }');
         return true;
     }
 
@@ -225,7 +207,6 @@ class UserFlagPlugin extends Plugin
      *
      * @return boolean hook result
      */
-
     function onUserRightsCheck($user, $right, &$result)
     {
         switch ($right) {
@@ -248,7 +229,6 @@ class UserFlagPlugin extends Plugin
      *
      * @return boolean hook result
      */
-
     function onEndBlockProfile($user, $profile)
     {
         if ($this->flagOnBlock && !User_flag_profile::exists($profile->id,
@@ -258,4 +238,61 @@ class UserFlagPlugin extends Plugin
         }
         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;
+    }
+
+    /**
+     * Provide plugin version information.
+     *
+     * This data is used when showing the version page.
+     *
+     * @param array &$versions array of version data arrays; see EVENTS.txt
+     *
+     * @return boolean hook value
+     */
+    function onPluginVersion(&$versions)
+    {
+        $url = 'http://status.net/wiki/Plugin:UserFlag';
+
+        $versions[] = array('name' => 'UserFlag',
+            'version' => STATUSNET_VERSION,
+            'author' => 'Evan Prodromou',
+            'homepage' => $url,
+            'rawdescription' =>
+            // TRANS: Plugin description.
+            _m('This plugin allows flagging of profiles for review and reviewing flagged profiles.'));
+
+        return true;
+    }
 }