Browse Source

Improved resource id creation

pull/4480/head
Michael 4 years ago
parent
commit
a3af6807ac
  1. 12
      boot.php
  2. 2
      include/api.php
  3. 25
      include/text.php
  4. 2
      mod/photos.php
  5. 2
      mod/profile_photo.php
  6. 2
      mod/wall_upload.php
  7. 11
      src/Model/Photo.php
  8. 2
      src/Model/User.php
  9. 2
      src/Object/Image.php

12
boot.php

@ -854,11 +854,13 @@ function check_addons(App $a)
return;
}
function get_guid($size = 16, $prefix = "")
function get_guid($size = 16, $prefix = '')
{
if ($prefix == "") {
if (is_bool($prefix)) {
$prefix = '';
} elseif ($prefix == '') {
$a = get_app();
$prefix = hash("crc32", $a->get_hostname());
$prefix = hash('crc32', $a->get_hostname());
}
while (strlen($prefix) < ($size - 13)) {
@ -867,10 +869,10 @@ function get_guid($size = 16, $prefix = "")
if ($size >= 24) {
$prefix = substr($prefix, 0, $size - 22);
return(str_replace(".", "", uniqid($prefix, true)));
return str_replace('.', '', uniqid($prefix, true));
} else {
$prefix = substr($prefix, 0, max($size - 13, 0));
return(uniqid($prefix));
return uniqid($prefix);
}
}

2
include/api.php

@ -4614,7 +4614,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
$height = $Image->getHeight();
// create a new resource-id if not already provided
$hash = ($photo_id == null) ? photo_new_resource() : $photo_id;
$hash = ($photo_id == null) ? Photo::newResource() : $photo_id;
if ($mediatype == "photo") {
// upload normal image (scales 0, 1, 2)

25
include/text.php

@ -489,31 +489,6 @@ function item_new_uri($hostname, $uid, $guid = "") {
return $uri;
}
/**
* Generate a guaranteed unique photo ID.
* safe from birthday paradox
*
* @return string
*/
function photo_new_resource() {
do {
$found = false;
$resource = hash('md5',uniqid(mt_rand(),true));
$r = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' LIMIT 1",
dbesc($resource)
);
if (DBM::is_result($r)) {
$found = true;
}
} while ($found == true);
return $resource;
}
/**
* @deprecated
* wrapper to load a view template, checking for alternate

2
mod/photos.php

@ -838,7 +838,7 @@ function photos_post(App $a)
$smallest = 0;
$photo_hash = photo_new_resource();
$photo_hash = 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);

2
mod/profile_photo.php

@ -308,7 +308,7 @@ function profile_photo_crop_ui_head(App $a, Image $Image) {
$height = $Image->getHeight();
}
$hash = photo_new_resource();
$hash = Photo::newResource();
$smallest = 0;

2
mod/wall_upload.php

@ -222,7 +222,7 @@ function wall_upload_post(App $a, $desktopmode = true) {
$width = $Image->getWidth();
$height = $Image->getHeight();
$hash = photo_new_resource();
$hash = Photo::newResource();
$smallest = 0;

11
src/Model/Photo.php

@ -100,7 +100,7 @@ class Photo
if (x($photo['resource-id'])) {
$hash = $photo['resource-id'];
} else {
$hash = photo_new_resource();
$hash = self::newResource();
}
$photo_failure = false;
@ -267,4 +267,13 @@ class Photo
$key = "photo_albums:".$uid.":".local_user().":".remote_user();
Cache::set($key, null, CACHE_DAY);
}
/**
* Generate a unique photo ID.
*
* @return string
*/
public static function newResource() {
return get_guid(32, false);
}
}

2
src/Model/User.php

@ -521,7 +521,7 @@ class User
if ($Image->isValid()) {
$Image->scaleToSquare(175);
$hash = photo_new_resource();
$hash = Photo::newResource();
$r = Photo::store($Image, $uid, 0, $hash, $filename, L10n::t('Profile Photos'), 4);

2
src/Object/Image.php

@ -937,7 +937,7 @@ class Image
$width = $Image->getWidth();
$height = $Image->getHeight();
$hash = photo_new_resource();
$hash = Photo::newResource();
$smallest = 0;

Loading…
Cancel
Save