use Friendica\Util\Proxy;
use Friendica\Util\Strings;
-require_once "include/dba.php";
-
/**
* Class to handle photo dabatase table
*/
try {
$backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? '');
- $image = $backendClass->get($photo['backend-ref'] ?? '');
-
- if ($image instanceof Image) {
- return $image;
- } else {
- DI::logger()->info('Stored data is not an image', ['photo' => $photo]);
- }
+ /// @todo refactoring this returning, because the storage returns a "string" which is casted in different ways - a check "instanceof Image" will fail!
+ return $backendClass->get($photo['backend-ref'] ?? '');
} catch (InvalidClassStorageException $storageException) {
try {
// legacy data storage in "data" column
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) {
$filename = basename($image_url);
if (!empty($image_url)) {
- $ret = DI::httpRequest()->get($image_url);
+ $ret = DI::httpClient()->get($image_url);
$img_str = $ret->getBody();
$type = $ret->getContentType();
} else {
$img_str = '';
+ $type = '';
}
if ($quit_on_error && ($img_str == "")) {
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);
}
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
*
return [];
}
- $guid = self::stripExtension($guid);
+ $guid = pathinfo($guid, PATHINFO_FILENAME);
if (substr($guid, -2, 1) != "-") {
return [];
}