]> 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 e6ad3e37d31f5b289b8125e1ca46f7b4866babfa..52b1fc299e320f3f82b64c591679b8f29480a586 100644 (file)
@@ -85,7 +85,7 @@ class UserFlagPlugin extends Plugin
     {
         $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;
     }
 
@@ -121,32 +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)) {
-                // @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', _('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;
     }
@@ -160,22 +144,40 @@ class UserFlagPlugin extends Plugin
      */
     function onEndProfileListItemActionElements($item)
     {
-        $user = common_current_user();
+        list($action, $args) = $item->action->returnToArgs();
+        $args['action'] = $action;
+        $this->showFlagButton($item->action, $item->profile, $args);
+
+        return true;
+    }
 
-        if (!empty($user)) {
+    /**
+     * 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
+     * @param Profile $profile
+     * @param array $returnToArgs
+     */
+    protected function showFlagButton($action, $profile, $returnToArgs)
+    {
+        $user = common_current_user();
 
-            list($action, $args) = $item->action->returnToArgs();
+        if (!empty($user) && ($user->id != $profile->id)) {
 
-            $args['action'] = $action;
+            $action->elementStart('li', 'entity_flag');
 
-            $form = new FlagProfileForm($item->action, $item->profile, $args);
+            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();
+            }
 
-            $item->action->elementStart('li', 'entity_flag');
-            $form->show();
-            $item->action->elementEnd('li');
+            $action->elementEnd('li');
         }
-
-        return true;
     }
 
     /**