]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
fillAvatars would avoid the *ProfileGetAvatar events
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 5 Oct 2013 23:56:27 +0000 (01:56 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 6 Oct 2013 01:01:43 +0000 (03:01 +0200)
classes/Profile.php
lib/noticelist.php

index eced9bd47f89d7c97c6896868d712d1f8867ab4e..da779f9d4f0dc0a5d07263ba26718928b95621ec 100644 (file)
@@ -116,6 +116,8 @@ class Profile extends Managed_DataObject
         return true;
     }
 
+    protected $_avatars = array();
+
     public function getAvatar($width, $height=null)
     {
         $width = (int) floor($width);
@@ -124,10 +126,8 @@ class Profile extends Managed_DataObject
             $height = $width;
         }
 
-        try {
-            return $this->_getAvatar($width);
-        } catch (Exception $e) {
-            $avatar = null;
+        if (isset($this->_avatars[$width])) {
+            return $this->_avatars[$width];
         }
         
         if (Event::handle('StartProfileGetAvatar', array($this, $width, &$avatar))) {
@@ -144,40 +144,17 @@ class Profile extends Managed_DataObject
         if (is_null($avatar)) {
             // Obviously we can't find an avatar, so let's resize the original!
             $avatar = Avatar::newSize($this, $width);
+        } elseif (!($avatar instanceof Avatar)) {
+            throw new Exception('Bad Avatar retrieved');
         }
 
         // cache the avatar for future use
-        $this->_fillAvatar($width, $avatar);
+        $this->_avatars[$width] = $avatar;
 
         return $avatar;
     }
 
-    protected $_avatars = array();
-
-    // XXX: @Fix me gargargar
-    function _getAvatar($width)
-    {
-        // GAR! I cannot figure out where _avatars gets pre-filled with the avatar from
-        // the previously used profile! Please shoot me now! --Zach
-        if (array_key_exists($width, $this->_avatars)) {
-            // Don't return cached avatar unless it's really for this profile
-            if ($this->_avatars[$width]->profile_id == $this->id) {
-                return $this->_avatars[$width];
-            }
-        }
-
-        throw new Exception('No cached avatar available for size ');
-    }
-
-    protected function _fillAvatar($width, $avatar)
-    {
-        // This avoids storing null values, a problem report in issue #3478
-        if (!empty($avatar)) {
-           $this->_avatars[$width] = $avatar;
-        }
-    }
-
-    function setOriginal($filename)
+    public function setOriginal($filename)
     {
         $imagefile = new ImageFile($this->id, Avatar::path($filename));
 
@@ -1431,29 +1408,8 @@ class Profile extends Managed_DataObject
         $skip = array('_user', '_avatars');
         return array_diff($vars, $skip);
     }
-    
-    static function fillAvatars(&$profiles, $width)
-    {
-       $ids = array();
-       foreach ($profiles as $profile) {
-            if (!empty($profile)) {
-                $ids[] = $profile->id;
-            }
-       }
-       
-       $avatars = Avatar::pivotGet('profile_id', $ids, array('width' => $width,
-                                                                                                                         'height' => $width));
-       
-       foreach ($profiles as $profile) {
-            if (!empty($profile)) { // ???
-                $profile->_fillAvatar($width, $avatars[$profile->id]);
-            }
-       }
-    }
-    
-    // Can't seem to find how to fix this.
 
-    function getProfile()
+    public function getProfile()
     {
         return $this;
     }
index c242417e5ab0f91b61145c81514625f64dcf36fd..df6e8d98c205522b731c00c7d0677cbcc59b1bfa 100644 (file)
@@ -134,8 +134,6 @@ class NoticeList extends Widget
             Notice::fillRepeats($notices);
             // Prefill the profiles
             $profiles = Notice::fillProfiles($notices);
-            // Prefill the avatars
-            Profile::fillAvatars($profiles, $avatarSize);
        
             $p = Profile::current();