]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Photo.php
Merge pull request #7828 from nupplaphil/task/move_enotify
[friendica.git] / src / Model / Photo.php
index e722444b18378c6b173aafef03a120470f513834..10e80a4fb5bc8daad21d8abbab828ea1137600fc 100644 (file)
@@ -17,8 +17,8 @@ use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\Model\Storage\IStorage;
 use Friendica\Object\Image;
-use Friendica\Protocol\DFRN;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
 use Friendica\Util\Network;
 use Friendica\Util\Security;
 use Friendica\Util\Strings;
@@ -131,31 +131,17 @@ class Photo extends BaseObject
         */
        public static function getPhoto($resourceid, $scale = 0)
        {
-               $r = self::selectFirst(["uid", "allow_cid", "allow_gid", "deny_cid", "deny_gid"], ["resource-id" => $resourceid]);
-               if ($r === false) {
+               $r = self::selectFirst(["uid"], ["resource-id" => $resourceid]);
+               if (!DBA::isResult($r)) {
                        return false;
                }
-               $uid = $r["uid"];
 
-               // This is the first place, when retrieving just a photo, that we know who owns the photo.
-               // Check if the photo is public (empty allow and deny means public), if so, skip auth attempt, if not
-               // make sure that the requester's session is appropriately authenticated to that user
-               // otherwise permissions checks done by getPermissionsSQLByUserId() won't work correctly
-               if (!empty($r["allow_cid"]) || !empty($r["allow_gid"]) || !empty($r["deny_cid"]) || !empty($r["deny_gid"])) {
-                       $r = DBA::selectFirst("user", ["nickname"], ["uid" => $uid], []);
-                       // this will either just return (if auth all ok) or will redirect and exit (starting over)
-                       DFRN::autoRedir(self::getApp(), $r["nickname"]);
-               }
+               $uid = $r["uid"];
 
                $sql_acl = Security::getPermissionsSQLByUserId($uid);
 
-               $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);
 
                return $photo;
@@ -418,9 +404,9 @@ class Photo extends BaseObject
                        "photo", ["resource-id"], ["uid" => $uid, "contact-id" => $cid, "scale" => 4, "album" => "Contact Photos"]
                );
                if (!empty($photo['resource-id'])) {
-                       $hash = $photo["resource-id"];
+                       $resource_id = $photo["resource-id"];
                } else {
-                       $hash = self::newResource();
+                       $resource_id = self::newResource();
                }
 
                $photo_failure = false;
@@ -439,14 +425,14 @@ class Photo extends BaseObject
                }
 
                if (empty($type)) {
-                       $type = Image::guessType($image_url, true);
+                       $type = Images::guessType($image_url, true);
                }
 
                $Image = new Image($img_str, $type);
                if ($Image->isValid()) {
                        $Image->scaleToSquare(300);
 
-                       $r = self::store($Image, $uid, $cid, $hash, $filename, "Contact Photos", 4);
+                       $r = self::store($Image, $uid, $cid, $resource_id, $filename, "Contact Photos", 4);
 
                        if ($r === false) {
                                $photo_failure = true;
@@ -454,7 +440,7 @@ class Photo extends BaseObject
 
                        $Image->scaleDown(80);
 
-                       $r = self::store($Image, $uid, $cid, $hash, $filename, "Contact Photos", 5);
+                       $r = self::store($Image, $uid, $cid, $resource_id, $filename, "Contact Photos", 5);
 
                        if ($r === false) {
                                $photo_failure = true;
@@ -462,7 +448,7 @@ class Photo extends BaseObject
 
                        $Image->scaleDown(48);
 
-                       $r = self::store($Image, $uid, $cid, $hash, $filename, "Contact Photos", 6);
+                       $r = self::store($Image, $uid, $cid, $resource_id, $filename, "Contact Photos", 6);
 
                        if ($r === false) {
                                $photo_failure = true;
@@ -470,24 +456,24 @@ class Photo extends BaseObject
 
                        $suffix = "?ts=" . time();
 
-                       $image_url = System::baseUrl() . "/photo/" . $hash . "-4." . $Image->getExt() . $suffix;
-                       $thumb = System::baseUrl() . "/photo/" . $hash . "-5." . $Image->getExt() . $suffix;
-                       $micro = System::baseUrl() . "/photo/" . $hash . "-6." . $Image->getExt() . $suffix;
+                       $image_url = System::baseUrl() . "/photo/" . $resource_id . "-4." . $Image->getExt() . $suffix;
+                       $thumb = System::baseUrl() . "/photo/" . $resource_id . "-5." . $Image->getExt() . $suffix;
+                       $micro = System::baseUrl() . "/photo/" . $resource_id . "-6." . $Image->getExt() . $suffix;
 
                        // Remove the cached photo
                        $a = \get_app();
                        $basepath = $a->getBasePath();
 
                        if (is_dir($basepath . "/photo")) {
-                               $filename = $basepath . "/photo/" . $hash . "-4." . $Image->getExt();
+                               $filename = $basepath . "/photo/" . $resource_id . "-4." . $Image->getExt();
                                if (file_exists($filename)) {
                                        unlink($filename);
                                }
-                               $filename = $basepath . "/photo/" . $hash . "-5." . $Image->getExt();
+                               $filename = $basepath . "/photo/" . $resource_id . "-5." . $Image->getExt();
                                if (file_exists($filename)) {
                                        unlink($filename);
                                }
-                               $filename = $basepath . "/photo/" . $hash . "-6." . $Image->getExt();
+                               $filename = $basepath . "/photo/" . $resource_id . "-6." . $Image->getExt();
                                if (file_exists($filename)) {
                                        unlink($filename);
                                }
@@ -656,6 +642,8 @@ class Photo extends BaseObject
                                continue;
                        }
 
+                       /// @todo Check if $str_contact_allow does contain a public forum. Then set the permissions to public.
+
                        $fields = ['allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow,
                                        'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny];
                        $condition = ['resource-id' => $image_uri, 'uid' => $uid];
@@ -676,7 +664,7 @@ class Photo extends BaseObject
        public static function stripExtension($name)
        {
                $name = str_replace([".jpg", ".png", ".gif"], ["", "", ""], $name);
-               foreach (Image::supportedTypes() as $m => $e) {
+               foreach (Images::supportedTypes() as $m => $e) {
                        $name = str_replace("." . $e, "", $name);
                }
                return $name;
@@ -702,7 +690,7 @@ class Photo extends BaseObject
                }
 
                $scale = intval(substr($guid, -1, 1));
-               if (empty($scale)) {
+               if (!is_numeric($scale)) {
                        return '';
                }