]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apiuserprofileimage.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / actions / apiuserprofileimage.php
index d2cf9a3e579fe21cd20df074ab5eace3fb87ccef..c9c8eab9af5fce75c3bcf2876a53dc9c752063b5 100644 (file)
@@ -31,8 +31,6 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-require_once INSTALLDIR . '/lib/apiprivateauth.php';
-
 /**
  * Ouputs avatar URL for a user, specified by screen name.
  * Unlike most API endpoints, this returns an HTTP redirect rather than direct data.
@@ -53,10 +51,15 @@ class ApiUserProfileImageAction extends ApiPrivateAuthAction
      * @return boolean success flag
      *
      */
-    function prepare($args)
+    protected function prepare(array $args=array())
     {
         parent::prepare($args);
-        $this->user = User::staticGet('nickname', $this->arg('screen_name'));
+        $user = User::getKV('nickname', $this->arg('screen_name'));
+        if (!($user instanceof User)) {
+            // TRANS: Client error displayed when requesting user information for a non-existing user.
+            $this->clientError(_('User not found.'), 404);
+        }
+        $this->target = $user->getProfile();
         $this->size = $this->arg('size');
 
         return true;
@@ -67,35 +70,14 @@ class ApiUserProfileImageAction extends ApiPrivateAuthAction
      *
      * Check the format and show the user info
      *
-     * @param array $args $_REQUEST data (unused)
-     *
      * @return void
      */
-    function handle($args)
+    protected function handle()
     {
-        parent::handle($args);
-
-        if (empty($this->user)) {
-            // TRANS: Client error displayed when requesting user information for a non-existing user.
-            $this->clientError(_('User not found.'), 404, $this->format);
-            return;
-        }
-
-        $profile = $this->user->getProfile();
-
-        if (empty($profile)) {
-            // TRANS: Client error displayed when requesting user information for a user without a profile.
-            $this->clientError(_('User has no profile.'));
-            return;
-        }
+        parent::handle();
 
         $size = $this->avatarSize();
-        $avatar = $profile->getAvatar($size);
-        if ($avatar) {
-            $url = $avatar->displayUrl();
-        } else {
-            $url = Avatar::defaultImage($size);
-        }
+        $url  = $this->target->avatarUrl($size);
 
         // We don't actually output JSON or XML data -- redirect!
         common_redirect($url, 302);
@@ -128,7 +110,7 @@ class ApiUserProfileImageAction extends ApiPrivateAuthAction
      *
      * @return boolean is read only action?
      */
-    function isReadOnly($args)
+    function isReadOnly(array $args=array())
     {
         return true;
     }