]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Photo.php
Fix overly strict return value for revokeFollow methods
[friendica.git] / src / Model / Photo.php
index 20d2c8a7aa3d28df4858b1d96097ede13ed9d467..c30da19bd881eda5a26d01360c46aefc23574eda 100644 (file)
@@ -413,7 +413,7 @@ class Photo
                while ($photo = DBA::fetch($photos)) {
                        try {
                                $backend_class = DI::storageManager()->getWritableStorageByName($photo['backend-class'] ?? '');
-                               $backend_class->delete($item['backend-ref'] ?? '');
+                               $backend_class->delete($photo['backend-ref'] ?? '');
                                // Delete the photos after they had been deleted successfully
                                DBA::delete("photo", ['id' => $photo['id']]);
                        } catch (InvalidClassStorageException $storageException) {
@@ -490,19 +490,19 @@ class Photo
 
                $filename = basename($image_url);
                if (!empty($image_url)) {
-                       $ret = DI::httpRequest()->get($image_url);
+                       $ret = DI::httpClient()->get($image_url);
                        $img_str = $ret->getBody();
-                       $contType = $ret->getContentType();
+                       $type = $ret->getContentType();
                } else {
                        $img_str = '';
-                       $contType = [];
+                       $type = '';
                }
 
                if ($quit_on_error && ($img_str == "")) {
                        return false;
                }
 
-               $type = Images::getMimeTypeByData($img_str, $image_url, $contType);
+               $type = Images::getMimeTypeByData($img_str, $image_url, $type);
 
                $Image = new Image($img_str, $type);
                if ($Image->isValid()) {
@@ -651,23 +651,23 @@ class Photo
                        if (!DI::config()->get("system", "no_count", false)) {
                                /// @todo This query needs to be renewed. It is really slow
                                // At this time we just store the data in the cache
-                               $albums = q("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`, ANY_VALUE(`created`) AS `created`
+                               $albums = DBA::toArray(DBA::p("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`, ANY_VALUE(`created`) AS `created`
                                        FROM `photo`
-                                       WHERE `uid` = %d  AND `album` != '%s' AND `album` != '%s' $sql_extra
+                                       WHERE `uid` = ? AND NOT `album` IN (?, ?) $sql_extra
                                        GROUP BY `album` ORDER BY `created` DESC",
-                                       intval($uid),
-                                       DBA::escape(self::CONTACT_PHOTOS),
-                                       DBA::escape(DI::l10n()->t(self::CONTACT_PHOTOS))
-                               );
+                                       $uid,
+                                       self::CONTACT_PHOTOS,
+                                       DI::l10n()->t(self::CONTACT_PHOTOS)
+                               ));
                        } else {
                                // This query doesn't do the count and is much faster
-                               $albums = q("SELECT DISTINCT(`album`), '' AS `total`
+                               $albums = DBA::toArray(DBA::p("SELECT DISTINCT(`album`), '' AS `total`
                                        FROM `photo` USE INDEX (`uid_album_scale_created`)
-                                       WHERE `uid` = %d  AND `album` != '%s' AND `album` != '%s' $sql_extra",
-                                       intval($uid),
-                                       DBA::escape(self::CONTACT_PHOTOS),
-                                       DBA::escape(DI::l10n()->t(self::CONTACT_PHOTOS))
-                               );
+                                       WHERE `uid` = ? AND NOT `album` IN (?, ?) $sql_extra",
+                                       $uid,
+                                       self::CONTACT_PHOTOS,
+                                       DI::l10n()->t(self::CONTACT_PHOTOS)
+                               ));
                        }
                        DI::cache()->set($key, $albums, Duration::DAY);
                }
@@ -799,22 +799,6 @@ class Photo
                Photo::update($fields, $condition);
        }
 
-       /**
-        * Strips known picture extensions from picture links
-        *
-        * @param string $name Picture link
-        * @return string stripped picture link
-        * @throws \Exception
-        */
-       public static function stripExtension($name)
-       {
-               $name = str_replace([".jpg", ".png", ".gif"], ["", "", ""], $name);
-               foreach (Images::supportedTypes() as $m => $e) {
-                       $name = str_replace("." . $e, "", $name);
-               }
-               return $name;
-       }
-
        /**
         * Fetch the guid and scale from picture links
         *
@@ -831,7 +815,7 @@ class Photo
                        return [];
                }
 
-               $guid = self::stripExtension($guid);
+               $guid = pathinfo($guid, PATHINFO_FILENAME);
                if (substr($guid, -2, 1) != "-") {
                        return [];
                }