]> git.mxchange.org Git - friendica.git/commitdiff
Improved resource id creation
authorMichael <heluecht@pirati.ca>
Tue, 20 Feb 2018 10:02:07 +0000 (10:02 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 20 Feb 2018 10:02:07 +0000 (10:02 +0000)
boot.php
include/api.php
include/text.php
mod/photos.php
mod/profile_photo.php
mod/wall_upload.php
src/Model/Photo.php
src/Model/User.php
src/Object/Image.php

index 6400274550216d2ecc34bc03331bd4244616ffa5..0d26403bcb9a1f94317741e7b1313163b916fb1b 100644 (file)
--- a/boot.php
+++ b/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);
        }
 }
 
index f7c04aaf88f0e4e621178e69d53bbd2b04e5be32..f742d2cb2abd3b1a8ee31c2ce59e4353d852ea23 100644 (file)
@@ -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)
index 02f17fdb4b3bfb4f3b89983b36cee3c615af8a4b..5f01fae361f6ab1d8f9790db451302ddc42a3b5e 100644 (file)
@@ -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
index 2b6998ae1dfb0aa992390162a8b0ce06d64e1bd0..3cd8b752863b6a68b49a04113a9aa6659b8e7cd9 100644 (file)
@@ -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);
 
index 5556553cf96391c8d741068724afd2bb34ee7451..80bdfa534e709f536f9086778b0ceea786aee832 100644 (file)
@@ -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;
index dd7d0f158632f7307c40377b1b490fb2c9dcc20c..61578ca5c8204e334b7b86728b671c0660472840 100644 (file)
@@ -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;
 
index e4e609155cc625d8f70e17d82ba71ac9bcb1686f..9f0007f8bcebd927390eb3521abd3bccb377a9a3 100644 (file)
@@ -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);
+       }
 }
index eacd4ec33c7e936920ab3960465b65c4f9181d18..702e815e601aa268ee0f2dee8feba8ced4c64428 100644 (file)
@@ -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);
 
index d8d6dafc3ca86d60bfbe180f6ad2e8f290cddac3..2f4d55dc0ac15c3a03d407f36c59bc67abbd1a1b 100644 (file)
@@ -937,7 +937,7 @@ class Image
                $width = $Image->getWidth();
                $height = $Image->getHeight();
 
-               $hash = photo_new_resource();
+               $hash = Photo::newResource();
 
                $smallest = 0;