Rename Photo::newResource() result variable from $hash to $resource_id

This commit is contained in:
Hypolite Petovan 2019-10-26 09:05:35 -04:00
parent 03bf1dcbd3
commit 26b5de9a76
5 changed files with 41 additions and 41 deletions

View File

@ -4788,19 +4788,19 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
$height = $Image->getHeight(); $height = $Image->getHeight();
// create a new resource-id if not already provided // create a new resource-id if not already provided
$hash = ($photo_id == null) ? Photo::newResource() : $photo_id; $resource_id = ($photo_id == null) ? Photo::newResource() : $photo_id;
if ($mediatype == "photo") { if ($mediatype == "photo") {
// upload normal image (scales 0, 1, 2) // upload normal image (scales 0, 1, 2)
Logger::log("photo upload: starting new photo upload", Logger::DEBUG); Logger::log("photo upload: starting new photo upload", Logger::DEBUG);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) { if (!$r) {
Logger::log("photo upload: image upload with scale 0 (original size) failed"); Logger::log("photo upload: image upload with scale 0 (original size) failed");
} }
if ($width > 640 || $height > 640) { if ($width > 640 || $height > 640) {
$Image->scaleDown(640); $Image->scaleDown(640);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) { if (!$r) {
Logger::log("photo upload: image upload with scale 1 (640x640) failed"); Logger::log("photo upload: image upload with scale 1 (640x640) failed");
} }
@ -4808,7 +4808,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
if ($width > 320 || $height > 320) { if ($width > 320 || $height > 320) {
$Image->scaleDown(320); $Image->scaleDown(320);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) { if (!$r) {
Logger::log("photo upload: image upload with scale 2 (320x320) failed"); Logger::log("photo upload: image upload with scale 2 (320x320) failed");
} }
@ -4820,7 +4820,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
if ($width > 300 || $height > 300) { if ($width > 300 || $height > 300) {
$Image->scaleDown(300); $Image->scaleDown(300);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) { if (!$r) {
Logger::log("photo upload: profile image upload with scale 4 (300x300) failed"); Logger::log("photo upload: profile image upload with scale 4 (300x300) failed");
} }
@ -4828,7 +4828,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
if ($width > 80 || $height > 80) { if ($width > 80 || $height > 80) {
$Image->scaleDown(80); $Image->scaleDown(80);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) { if (!$r) {
Logger::log("photo upload: profile image upload with scale 5 (80x80) failed"); Logger::log("photo upload: profile image upload with scale 5 (80x80) failed");
} }
@ -4836,7 +4836,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
if ($width > 48 || $height > 48) { if ($width > 48 || $height > 48) {
$Image->scaleDown(48); $Image->scaleDown(48);
$r = Photo::store($Image, local_user(), $visitor, $hash, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc); $r = Photo::store($Image, local_user(), $visitor, $resource_id, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (!$r) { if (!$r) {
Logger::log("photo upload: profile image upload with scale 6 (48x48) failed"); Logger::log("photo upload: profile image upload with scale 6 (48x48) failed");
} }
@ -4848,10 +4848,10 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
if (isset($r) && $r) { if (isset($r) && $r) {
// create entry in 'item'-table on new uploads to enable users to comment/like/dislike the photo // create entry in 'item'-table on new uploads to enable users to comment/like/dislike the photo
if ($photo_id == null && $mediatype == "photo") { if ($photo_id == null && $mediatype == "photo") {
post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility); post_photo_item($resource_id, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility);
} }
// on success return image data in json/xml format (like /api/friendica/photo does when no scale is given) // on success return image data in json/xml format (like /api/friendica/photo does when no scale is given)
return prepare_photo_data($type, false, $hash); return prepare_photo_data($type, false, $resource_id);
} else { } else {
throw new InternalServerErrorException("image upload failed"); throw new InternalServerErrorException("image upload failed");
} }

View File

@ -749,9 +749,9 @@ function photos_post(App $a)
$smallest = 0; $smallest = 0;
$photo_hash = Photo::newResource(); $resource_id = Photo::newResource();
$r = Photo::store($image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny); $r = Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
if (!$r) { if (!$r) {
Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG); Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
@ -761,13 +761,13 @@ function photos_post(App $a)
if ($width > 640 || $height > 640) { if ($width > 640 || $height > 640) {
$image->scaleDown(640); $image->scaleDown(640);
Photo::store($image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny); Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
$smallest = 1; $smallest = 1;
} }
if ($width > 320 || $height > 320) { if ($width > 320 || $height > 320) {
$image->scaleDown(320); $image->scaleDown(320);
Photo::store($image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny); Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
$smallest = 2; $smallest = 2;
} }
@ -791,7 +791,7 @@ function photos_post(App $a)
$arr['parent-uri'] = $uri; $arr['parent-uri'] = $uri;
$arr['type'] = 'photo'; $arr['type'] = 'photo';
$arr['wall'] = 1; $arr['wall'] = 1;
$arr['resource-id'] = $photo_hash; $arr['resource-id'] = $resource_id;
$arr['contact-id'] = $owner_record['id']; $arr['contact-id'] = $owner_record['id'];
$arr['owner-name'] = $owner_record['name']; $arr['owner-name'] = $owner_record['name'];
$arr['owner-link'] = $owner_record['url']; $arr['owner-link'] = $owner_record['url'];
@ -807,8 +807,8 @@ function photos_post(App $a)
$arr['visible'] = $visible; $arr['visible'] = $visible;
$arr['origin'] = 1; $arr['origin'] = 1;
$arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']' $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
. '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$image->getExt() . '[/img]' . '[img]' . System::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
. '[/url]'; . '[/url]';
$item_id = Item::insert($arr); $item_id = Item::insert($arr);

View File

@ -222,7 +222,7 @@ function wall_upload_post(App $a, $desktopmode = true)
$width = $Image->getWidth(); $width = $Image->getWidth();
$height = $Image->getHeight(); $height = $Image->getHeight();
$hash = Photo::newResource(); $resource_id = Photo::newResource();
$smallest = 0; $smallest = 0;
@ -233,7 +233,7 @@ function wall_upload_post(App $a, $desktopmode = true)
$defperm = '<' . $default_cid . '>'; $defperm = '<' . $default_cid . '>';
$r = Photo::store($Image, $page_owner_uid, $visitor, $hash, $filename, $album, 0, 0, $defperm); $r = Photo::store($Image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0, 0, $defperm);
if (!$r) { if (!$r) {
$msg = L10n::t('Image upload failed.'); $msg = L10n::t('Image upload failed.');
@ -247,7 +247,7 @@ function wall_upload_post(App $a, $desktopmode = true)
if ($width > 640 || $height > 640) { if ($width > 640 || $height > 640) {
$Image->scaleDown(640); $Image->scaleDown(640);
$r = Photo::store($Image, $page_owner_uid, $visitor, $hash, $filename, $album, 1, 0, $defperm); $r = Photo::store($Image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 1, 0, $defperm);
if ($r) { if ($r) {
$smallest = 1; $smallest = 1;
} }
@ -255,7 +255,7 @@ function wall_upload_post(App $a, $desktopmode = true)
if ($width > 320 || $height > 320) { if ($width > 320 || $height > 320) {
$Image->scaleDown(320); $Image->scaleDown(320);
$r = Photo::store($Image, $page_owner_uid, $visitor, $hash, $filename, $album, 2, 0, $defperm); $r = Photo::store($Image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 2, 0, $defperm);
if ($r && ($smallest == 0)) { if ($r && ($smallest == 0)) {
$smallest = 2; $smallest = 2;
} }
@ -265,7 +265,7 @@ function wall_upload_post(App $a, $desktopmode = true)
$r = q("SELECT `id`, `datasize`, `width`, `height`, `type` FROM `photo` $r = q("SELECT `id`, `datasize`, `width`, `height`, `type` FROM `photo`
WHERE `resource-id` = '%s' WHERE `resource-id` = '%s'
ORDER BY `width` DESC LIMIT 1", ORDER BY `width` DESC LIMIT 1",
$hash $resource_id
); );
if (!$r) { if (!$r) {
if ($r_json) { if ($r_json) {
@ -281,9 +281,9 @@ function wall_upload_post(App $a, $desktopmode = true)
$picture["width"] = $r[0]["width"]; $picture["width"] = $r[0]["width"];
$picture["height"] = $r[0]["height"]; $picture["height"] = $r[0]["height"];
$picture["type"] = $r[0]["type"]; $picture["type"] = $r[0]["type"];
$picture["albumpage"] = System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $hash; $picture["albumpage"] = System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $resource_id;
$picture["picture"] = System::baseUrl() . "/photo/{$hash}-0." . $Image->getExt(); $picture["picture"] = System::baseUrl() . "/photo/{$resource_id}-0." . $Image->getExt();
$picture["preview"] = System::baseUrl() . "/photo/{$hash}-{$smallest}." . $Image->getExt(); $picture["preview"] = System::baseUrl() . "/photo/{$resource_id}-{$smallest}." . $Image->getExt();
if ($r_json) { if ($r_json) {
echo json_encode(['picture' => $picture]); echo json_encode(['picture' => $picture]);
@ -300,7 +300,7 @@ function wall_upload_post(App $a, $desktopmode = true)
exit(); exit();
} }
echo "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . System::baseUrl() . "/photo/{$hash}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n"; echo "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $resource_id . '][img]' . System::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n";
exit(); exit();
// NOTREACHED // NOTREACHED
} }

View File

@ -404,9 +404,9 @@ class Photo extends BaseObject
"photo", ["resource-id"], ["uid" => $uid, "contact-id" => $cid, "scale" => 4, "album" => "Contact Photos"] "photo", ["resource-id"], ["uid" => $uid, "contact-id" => $cid, "scale" => 4, "album" => "Contact Photos"]
); );
if (!empty($photo['resource-id'])) { if (!empty($photo['resource-id'])) {
$hash = $photo["resource-id"]; $resource_id = $photo["resource-id"];
} else { } else {
$hash = self::newResource(); $resource_id = self::newResource();
} }
$photo_failure = false; $photo_failure = false;
@ -432,7 +432,7 @@ class Photo extends BaseObject
if ($Image->isValid()) { if ($Image->isValid()) {
$Image->scaleToSquare(300); $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) { if ($r === false) {
$photo_failure = true; $photo_failure = true;
@ -440,7 +440,7 @@ class Photo extends BaseObject
$Image->scaleDown(80); $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) { if ($r === false) {
$photo_failure = true; $photo_failure = true;
@ -448,7 +448,7 @@ class Photo extends BaseObject
$Image->scaleDown(48); $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) { if ($r === false) {
$photo_failure = true; $photo_failure = true;
@ -456,24 +456,24 @@ class Photo extends BaseObject
$suffix = "?ts=" . time(); $suffix = "?ts=" . time();
$image_url = System::baseUrl() . "/photo/" . $hash . "-4." . $Image->getExt() . $suffix; $image_url = System::baseUrl() . "/photo/" . $resource_id . "-4." . $Image->getExt() . $suffix;
$thumb = System::baseUrl() . "/photo/" . $hash . "-5." . $Image->getExt() . $suffix; $thumb = System::baseUrl() . "/photo/" . $resource_id . "-5." . $Image->getExt() . $suffix;
$micro = System::baseUrl() . "/photo/" . $hash . "-6." . $Image->getExt() . $suffix; $micro = System::baseUrl() . "/photo/" . $resource_id . "-6." . $Image->getExt() . $suffix;
// Remove the cached photo // Remove the cached photo
$a = \get_app(); $a = \get_app();
$basepath = $a->getBasePath(); $basepath = $a->getBasePath();
if (is_dir($basepath . "/photo")) { if (is_dir($basepath . "/photo")) {
$filename = $basepath . "/photo/" . $hash . "-4." . $Image->getExt(); $filename = $basepath . "/photo/" . $resource_id . "-4." . $Image->getExt();
if (file_exists($filename)) { if (file_exists($filename)) {
unlink($filename); unlink($filename);
} }
$filename = $basepath . "/photo/" . $hash . "-5." . $Image->getExt(); $filename = $basepath . "/photo/" . $resource_id . "-5." . $Image->getExt();
if (file_exists($filename)) { if (file_exists($filename)) {
unlink($filename); unlink($filename);
} }
$filename = $basepath . "/photo/" . $hash . "-6." . $Image->getExt(); $filename = $basepath . "/photo/" . $resource_id . "-6." . $Image->getExt();
if (file_exists($filename)) { if (file_exists($filename)) {
unlink($filename); unlink($filename);
} }

View File

@ -836,9 +836,9 @@ class User
if ($Image->isValid()) { if ($Image->isValid()) {
$Image->scaleToSquare(300); $Image->scaleToSquare(300);
$hash = Photo::newResource(); $resource_id = Photo::newResource();
$r = Photo::store($Image, $uid, 0, $hash, $filename, L10n::t('Profile Photos'), 4); $r = Photo::store($Image, $uid, 0, $resource_id, $filename, L10n::t('Profile Photos'), 4);
if ($r === false) { if ($r === false) {
$photo_failure = true; $photo_failure = true;
@ -846,7 +846,7 @@ class User
$Image->scaleDown(80); $Image->scaleDown(80);
$r = Photo::store($Image, $uid, 0, $hash, $filename, L10n::t('Profile Photos'), 5); $r = Photo::store($Image, $uid, 0, $resource_id, $filename, L10n::t('Profile Photos'), 5);
if ($r === false) { if ($r === false) {
$photo_failure = true; $photo_failure = true;
@ -854,14 +854,14 @@ class User
$Image->scaleDown(48); $Image->scaleDown(48);
$r = Photo::store($Image, $uid, 0, $hash, $filename, L10n::t('Profile Photos'), 6); $r = Photo::store($Image, $uid, 0, $resource_id, $filename, L10n::t('Profile Photos'), 6);
if ($r === false) { if ($r === false) {
$photo_failure = true; $photo_failure = true;
} }
if (!$photo_failure) { if (!$photo_failure) {
Photo::update(['profile' => 1], ['resource-id' => $hash]); Photo::update(['profile' => 1], ['resource-id' => $resource_id]);
} }
} }
} }