]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Photo.php
Merge pull request #9816 from annando/post-thread
[friendica.git] / src / Model / Photo.php
index f09e88ce7dd8f9c401baf743a11557d8b6cb97d7..e5b2ef87b96e3654901cf12c6f2c0b5721a3fd52 100644 (file)
@@ -31,7 +31,8 @@ use Friendica\Model\Storage\SystemResource;
 use Friendica\Object\Image;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Images;
-use Friendica\Util\Security;
+use Friendica\Security\Security;
+use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 
 require_once "include/dba.php";
@@ -177,7 +178,7 @@ class Photo
 
 
        /**
-        * Get Image object for given row id. null if row id does not exist
+        * Get Image data for given row id. null if row id does not exist
         *
         * @param array $photo Photo data. Needs at least 'id', 'type', 'backend-class', 'backend-ref'
         *
@@ -185,7 +186,7 @@ class Photo
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function getImageForPhoto(array $photo)
+       public static function getImageDataForPhoto(array $photo)
        {
                $backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? '');
                if ($backendClass === null) {
@@ -199,7 +200,21 @@ class Photo
                        $backendRef = $photo['backend-ref'] ?? '';
                        $data = $backendClass->get($backendRef);
                }
+               return $data;
+       }
 
+       /**
+        * Get Image object for given row id. null if row id does not exist
+        *
+        * @param array $photo Photo data. Needs at least 'id', 'type', 'backend-class', 'backend-ref'
+        *
+        * @return \Friendica\Object\Image
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function getImageForPhoto(array $photo)
+       {
+               $data = self::getImageDataForPhoto($photo);
                if (empty($data)) {
                        return null;
                }
@@ -304,6 +319,7 @@ class Photo
                        "contact-id" => $cid,
                        "guid" => $guid,
                        "resource-id" => $rid,
+                       "hash" => md5($Image->asString()),
                        "created" => $created,
                        "edited" => DateTimeFormat::utcNow(),
                        "filename" => basename($filename),
@@ -422,7 +438,7 @@ class Photo
 
                $filename = basename($image_url);
                if (!empty($image_url)) {
-                       $ret = DI::httpRequest()->get($image_url, true);
+                       $ret = DI::httpRequest()->get($image_url);
                        $img_str = $ret->getBody();
                        $type = $ret->getContentType();
                } else {
@@ -494,9 +510,10 @@ class Photo
                }
 
                if ($photo_failure) {
-                       $image_url = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
-                       $thumb = DI::baseUrl() . Contact::DEFAULT_AVATAR_THUMB;
-                       $micro = DI::baseUrl() . Contact::DEFAULT_AVATAR_MICRO;
+                       $contact = Contact::getById($cid) ?: [];
+                       $image_url = Contact::getDefaultAvatar($contact, Proxy::SIZE_SMALL);
+                       $thumb = Contact::getDefaultAvatar($contact, Proxy::SIZE_THUMB);
+                       $micro = Contact::getDefaultAvatar($contact, Proxy::SIZE_MICRO);
                }
 
                return [$image_url, $thumb, $micro];