diff --git a/include/api.php b/include/api.php index 9e8b3dd336..7914b4dbd6 100644 --- a/include/api.php +++ b/include/api.php @@ -34,6 +34,7 @@ use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Module\BaseApi; use Friendica\Network\HTTPException; +use Friendica\Util\Images; $API = []; @@ -162,12 +163,6 @@ function prepare_photo_data($type, $scale, $photo_id, $uid) $photo_id )); - $typetoext = [ - 'image/jpeg' => 'jpg', - 'image/png' => 'png', - 'image/gif' => 'gif' - ]; - // prepare output data for photo if (DBA::isResult($r)) { $data = ['photo' => $r[0]]; @@ -182,14 +177,14 @@ function prepare_photo_data($type, $scale, $photo_id, $uid) for ($k = intval($data['photo']['minscale']); $k <= intval($data['photo']['maxscale']); $k++) { $data['photo']['links'][$k . ":link"]["@attributes"] = ["type" => $data['photo']['type'], "scale" => $k, - "href" => DI::baseUrl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . $typetoext[$data['photo']['type']]]; + "href" => DI::baseUrl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . Images::getExtensionByMimeType($data['photo']['type'])]; } } else { $data['photo']['link'] = []; // when we have profile images we could have only scales from 4 to 6, but index of array always needs to start with 0 $i = 0; for ($k = intval($data['photo']['minscale']); $k <= intval($data['photo']['maxscale']); $k++) { - $data['photo']['link'][$i] = DI::baseUrl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . $typetoext[$data['photo']['type']]; + $data['photo']['link'][$i] = DI::baseUrl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . Images::getExtensionByMimeType($data['photo']['type']); $i++; } } @@ -331,11 +326,7 @@ function api_fr_photos_list($type) WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) GROUP BY `resource-id`, `album`, `filename`, `type`", $uid, Photo::CONTACT_AVATAR, Photo::CONTACT_BANNER )); - $typetoext = [ - 'image/jpeg' => 'jpg', - 'image/png' => 'png', - 'image/gif' => 'gif' - ]; + $data = ['photo'=>[]]; if (DBA::isResult($r)) { foreach ($r as $rr) { @@ -344,7 +335,7 @@ function api_fr_photos_list($type) $photo['album'] = $rr['album']; $photo['filename'] = $rr['filename']; $photo['type'] = $rr['type']; - $thumb = DI::baseUrl() . "/photo/" . $rr['resource-id'] . "-" . $rr['scale'] . "." . $typetoext[$rr['type']]; + $thumb = DI::baseUrl() . "/photo/" . $rr['resource-id'] . "-" . $rr['scale'] . "." . Images::getExtensionByMimeType($rr['type']); $photo['created'] = $rr['created']; $photo['edited'] = $rr['edited']; $photo['desc'] = $rr['desc']; diff --git a/src/Model/User.php b/src/Model/User.php index ccc9261fd2..d99588e05b 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -890,6 +890,9 @@ class User if (in_array($photo['type'], ['image/png', 'image/gif'])) { $imagetype = IMAGETYPE_PNG; } + } else { + // Only for the RC phase: Don't return an image link for the default picture + return ''; } return $url . $user['nickname'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : ''); diff --git a/src/Util/Images.php b/src/Util/Images.php index cd4704dcee..997f3c6f9d 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -46,6 +46,30 @@ class Images return $m; } + /** + * Return file extension for mime type + * @param string $mimetype + * @return string + */ + public static function getExtensionByMimeType(string $mimetype): string + { + switch ($mimetype) { + case 'image/png': + $imagetype = IMAGETYPE_PNG; + break; + + case 'image/gif': + $imagetype = IMAGETYPE_GIF; + break; + + default: + $imagetype = IMAGETYPE_JPC; + break; + } + + return image_type_to_extension($imagetype); + } + /** * Returns supported image mimetypes and corresponding file extensions * diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 39481348e2..ca52dace8b 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -55,7 +55,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1449); + define('DB_UPDATE_VERSION', 1448); } return [ diff --git a/update.php b/update.php index ed5962cf1f..7b5f6778be 100644 --- a/update.php +++ b/update.php @@ -1087,16 +1087,3 @@ function update_1446() return Update::SUCCESS; } - -function update_1449() -{ - $users = DBA::select('user', ['uid']); - while ($user = DBA::fetch($users)) { - if (Contact::updateSelfFromUserID($user['uid'])) { - Profile::publishUpdate($user['uid']); - } - } - DBA::close($users); - - return Update::SUCCESS; -}