use Friendica\Model\Post;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
+use Friendica\Util\Images;
$API = [];
$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]];
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++;
}
}
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) {
$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'];
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
*
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;
-}