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)) {
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);
}
}
$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)
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
$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);
$height = $Image->getHeight();
}
- $hash = photo_new_resource();
+ $hash = Photo::newResource();
$smallest = 0;
$width = $Image->getWidth();
$height = $Image->getHeight();
- $hash = photo_new_resource();
+ $hash = Photo::newResource();
$smallest = 0;
if (x($photo['resource-id'])) {
$hash = $photo['resource-id'];
} else {
- $hash = photo_new_resource();
+ $hash = self::newResource();
}
$photo_failure = false;
$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);
+ }
}
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);
$width = $Image->getWidth();
$height = $Image->getHeight();
- $hash = photo_new_resource();
+ $hash = Photo::newResource();
$smallest = 0;