]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Photo.php
Use a constant for the avatar base path
[friendica.git] / src / Model / Photo.php
index d43c2805d2cdf0ba49aadf1ceeb343e705bde277..6537c41d1fd81158c75b1a011b7a3127f3f52910 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 {
@@ -708,6 +710,18 @@ class Photo
                return $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));
+       }
+
        /**
         * Changes photo permissions that had been embedded in a post
         *
@@ -912,7 +926,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 +1029,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
        {