]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Photo.php
Merge pull request #12251 from annando/remote-self
[friendica.git] / src / Model / Photo.php
index b2a815c839b8c516f1792afcef1279a886fdfc15..7c620b0ad45bb6afc9e95119bf518c788c0353a5 100644 (file)
@@ -25,7 +25,6 @@ use Friendica\Core\Cache\Enum\Duration;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
-use Friendica\Database\DBStructure;
 use Friendica\DI;
 use Friendica\Core\Storage\Type\ExternalResource;
 use Friendica\Core\Storage\Exception\InvalidClassStorageException;
@@ -167,7 +166,7 @@ class Photo
 
                $sql_acl = Security::getPermissionsSQLByUserId($uid, $accessible);
 
-               $conditions = ['`resource-id` = ? AND `scale` <= ? ' . $sql_acl, $resourceid, $scale];
+               $conditions = ["`resource-id` = ? AND `scale` <= ? " . $sql_acl, $resourceid, $scale];
                $params = ['order' => ['scale' => true]];
                $photo = self::selectFirst([], $conditions, $params);
 
@@ -250,7 +249,7 @@ class Photo
         */
        private static function getFields(): array
        {
-               $allfields = DBStructure::definition(DI::app()->getBasePath(), false);
+               $allfields = DI::dbaDefinition()->getAll();
                $fields = array_keys($allfields['photo']['fields']);
                array_splice($fields, array_search('data', $fields), 1);
                return $fields;
@@ -317,11 +316,11 @@ class Photo
         * @param Image   $image     Image object with data
         * @param integer $uid       User ID
         * @param integer $cid       Contact ID
-        * @param integer $rid       Resource ID
+        * @param string  $rid       Resource ID
         * @param string  $filename  Filename
         * @param string  $album     Album name
         * @param integer $scale     Scale
-        * @param integer $type      Photo type
+        * @param integer $type      Photo type, optional, default: Photo::DEFAULT
         * @param string  $allow_cid Permissions, allowed contacts. optional, default = ""
         * @param string  $allow_gid Permissions, allowed groups. optional, default = ""
         * @param string  $deny_cid  Permissions, denied contacts.optional, default = ""
@@ -331,9 +330,9 @@ class Photo
         * @return boolean True on success
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function store(Image $image, int $uid, int $cid, int $rid, string $filename, string $album, int $scale, int $type = self::DEFAULT, string $allow_cid = '', string $allow_gid = '', string $deny_cid = '', string $deny_gid = '', string $desc = ''): bool
+       public static function store(Image $image, int $uid, int $cid, string $rid, string $filename, string $album, int $scale, int $type = self::DEFAULT, string $allow_cid = '', string $allow_gid = '', string $deny_cid = '', string $deny_gid = '', string $desc = ''): bool
        {
-               $photo = self::selectFirst(['guid'], ['`resource-id` = ? AND `guid` != ?', $rid, '']);
+               $photo = self::selectFirst(['guid'], ["`resource-id` = ? AND `guid` != ?", $rid, '']);
                if (DBA::isResult($photo)) {
                        $guid = $photo['guid'];
                } else {
@@ -476,7 +475,7 @@ class Photo
         * @param integer $uid           user id
         * @param integer $cid           contact id
         * @param boolean $quit_on_error optional, default false
-        * @return array
+        * @return array|bool Array on success, false on error
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
@@ -586,11 +585,13 @@ class Photo
        }
 
        /**
+        * Returns a float that represents the GPS coordinate from EXIF data
+        *
         * @param array $exifCoord coordinate
         * @param string $hemi      hemi
         * @return float
         */
-       public static function getGps(array $exifCoord, strinf $hemi): float
+       public static function getGps(array $exifCoord, string $hemi): float
        {
                $degrees = count($exifCoord) > 0 ? self::gps2Num($exifCoord[0]) : 0;
                $minutes = count($exifCoord) > 1 ? self::gps2Num($exifCoord[1]) : 0;
@@ -637,10 +638,10 @@ class Photo
        {
                $sql_extra = Security::getPermissionsSQLByUserId($uid);
 
-               $avatar_type = (local_user() && (local_user() == $uid)) ? self::USER_AVATAR : self::DEFAULT;
-               $banner_type = (local_user() && (local_user() == $uid)) ? self::USER_BANNER : self::DEFAULT;
+               $avatar_type = (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $uid)) ? self::USER_AVATAR : self::DEFAULT;
+               $banner_type = (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $uid)) ? self::USER_BANNER : self::DEFAULT;
 
-               $key = 'photo_albums:' . $uid . ':' . local_user() . ':' . remote_user();
+               $key = 'photo_albums:' . $uid . ':' . DI::userSession()->getLocalUserId() . ':' . DI::userSession()->getRemoteUserId();
                $albums = DI::cache()->get($key);
 
                if (is_null($albums) || $update) {
@@ -679,7 +680,7 @@ class Photo
         */
        public static function clearAlbumCache(int $uid)
        {
-               $key = 'photo_albums:' . $uid . ':' . local_user() . ':' . remote_user();
+               $key = 'photo_albums:' . $uid . ':' . DI::userSession()->getLocalUserId() . ':' . DI::userSession()->getRemoteUserId();
                DI::cache()->set($key, null, Duration::DAY);
        }
 
@@ -1093,7 +1094,7 @@ class Photo
 
                $r = self::store($image, $user['uid'], 0, $resource_id, $filename, $album, 0, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
                if (!$r) {
-                       Logger::notice('Photo could not be stored');
+                       Logger::warning('Photo could not be stored', ['uid' => $user['uid'], 'resource_id' => $resource_id, 'filename' => $filename, 'album' => $album]);
                        return [];
                }
 
@@ -1129,8 +1130,8 @@ class Photo
                $picture['height']      = $photo['height'];
                $picture['type']        = $photo['type'];
                $picture['albumpage']   = DI::baseUrl() . '/photos/' . $user['nickname'] . '/image/' . $resource_id;
-               $picture['picture']     = DI::baseUrl() . '/photo/{$resource_id}-0.' . $image->getExt();
-               $picture['preview']     = DI::baseUrl() . '/photo/{$resource_id}-{$smallest}.' . $image->getExt();
+               $picture['picture']     = DI::baseUrl() . '/photo/' . $resource_id . '-0.' . $image->getExt();
+               $picture['preview']     = DI::baseUrl() . '/photo/' . $resource_id . '-' . $smallest . '.' . $image->getExt();
 
                Logger::info('upload done', ['picture' => $picture]);
                return $picture;
@@ -1180,7 +1181,7 @@ class Photo
 
                $r = self::store($image, $uid, 0, $resource_id, $filename, $album, 4, self::USER_AVATAR);
                if (!$r) {
-                       logger::notice('profile image upload with scale 4 (300) failed');
+                       logger::warning('profile image upload with scale 4 (300) failed', ['uid' => $uid, 'resource_id' => $resource_id, 'filename' => $filename, 'album' => $album]);
                }
 
                if ($width > 80 || $height > 80) {
@@ -1189,7 +1190,7 @@ class Photo
 
                $r = self::store($image, $uid, 0, $resource_id, $filename, $album, 5, self::USER_AVATAR);
                if (!$r) {
-                       logger::notice('profile image upload with scale 5 (80) failed');
+                       logger::warning('profile image upload with scale 5 (80) failed', ['uid' => $uid, 'resource_id' => $resource_id, 'filename' => $filename, 'album' => $album]);
                }
 
                if ($width > 48 || $height > 48) {
@@ -1198,7 +1199,7 @@ class Photo
 
                $r = self::store($image, $uid, 0, $resource_id, $filename, $album, 6, self::USER_AVATAR);
                if (!$r) {
-                       logger::notice('profile image upload with scale 6 (48) failed');
+                       logger::warning('profile image upload with scale 6 (48) failed', ['uid' => $uid, 'resource_id' => $resource_id, 'filename' => $filename, 'album' => $album]);
                }
 
                logger::info('new profile image upload ended');
@@ -1255,7 +1256,7 @@ class Photo
 
                $r = self::store($image, $uid, 0, $resource_id, $filename, $album, 3, self::USER_BANNER);
                if (!$r) {
-                       logger::notice('profile banner upload with scale 3 (960) failed');
+                       logger::warning('profile banner upload with scale 3 (960) failed');
                }
 
                logger::info('new profile banner upload ended');
@@ -1271,4 +1272,3 @@ class Photo
                return $resource_id;
        }
 }
-