]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Photo.php
Changed to null-coalscing style (??) as sugguested by @MrPetovan
[friendica.git] / src / Model / Photo.php
index d43c2805d2cdf0ba49aadf1ceeb343e705bde277..d9e6f7cadebb8c54688cce3f531d15d5e025da54 100644 (file)
@@ -32,6 +32,7 @@ use Friendica\Core\Storage\Exception\InvalidClassStorageException;
 use Friendica\Core\Storage\Exception\ReferenceStorageException;
 use Friendica\Core\Storage\Exception\StorageException;
 use Friendica\Core\Storage\Type\SystemResource;
+use Friendica\Network\HTTPClient\Client\HttpClientAccept;
 use Friendica\Object\Image;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Images;
@@ -497,7 +498,8 @@ class Photo
 
                $filename = basename($image_url);
                if (!empty($image_url)) {
-                       $ret = DI::httpClient()->get($image_url);
+                       $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE);
+                       Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
                        $img_str = $ret->getBody();
                        $type = $ret->getContentType();
                } else {
@@ -702,10 +704,19 @@ class Photo
                }
                $image_uri = substr($image_uri, strrpos($image_uri, '/') + 1);
                $image_uri = substr($image_uri, 0, strpos($image_uri, '-'));
-               if (!strlen($image_uri)) {
-                       return '';
-               }
-               return $image_uri;
+               return trim($image_uri);
+       }
+
+       /**
+        * Checks if the given URL is a local photo.
+        * Since it is meant for time critical occasions, the check is done without any database requests.
+        *
+        * @param string $url
+        * @return boolean
+        */
+       public static function isPhotoURI(string $url): bool
+       {
+               return !empty(self::ridFromURI($url));
        }
 
        /**
@@ -912,7 +923,8 @@ class Photo
        {
                $filename = basename($image_url);
                if (!empty($image_url)) {
-                       $ret = DI::httpClient()->get($image_url);
+                       $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE);
+                       Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
                        $img_str = $ret->getBody();
                        $type = $ret->getContentType();
                } else {
@@ -1014,10 +1026,17 @@ class Photo
        }
 
        /**
-        *
-        * @param int   $uid   User ID
-        * @param array $files uploaded file array
+        * @param int         $uid   User ID
+        * @param array       $files uploaded file array
+        * @param string      $album
+        * @param string|null $allow_cid
+        * @param string|null $allow_gid
+        * @param string      $deny_cid
+        * @param string      $deny_gid
+        * @param string      $desc
+        * @param string      $resource_id
         * @return array photo record
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function upload(int $uid, array $files, string $album = '', string $allow_cid = null, string $allow_gid = null, string $deny_cid = '', string $deny_gid = '', string $desc = '', string $resource_id = ''): array
        {