]> git.mxchange.org Git - friendica.git/commitdiff
UUID instead of GUID
authorMichael <heluecht@pirati.ca>
Wed, 26 Sep 2018 20:03:46 +0000 (20:03 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 26 Sep 2018 20:03:46 +0000 (20:03 +0000)
13 files changed:
include/api.php
mod/item.php
mod/photos.php
mod/poke.php
mod/subthread.php
mod/tagger.php
src/Core/System.php
src/Model/Event.php
src/Model/Item.php
src/Model/Mail.php
src/Model/User.php
src/Protocol/ActivityPub.php
src/Protocol/Diaspora.php

index 5510eddb4f1bc98d44e238d93145b939945058d5..52f8e7ad8e24579887dde342843d9a155fd3ad2e 100644 (file)
@@ -4534,7 +4534,7 @@ function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $f
        $owner_record = DBA::selectFirst('contact', [], ['uid' => api_user(), 'self' => true]);
 
        $arr = [];
-       $arr['guid']          = System::createGUID(32);
+       $arr['guid']          = System::UUID();
        $arr['uid']           = intval(api_user());
        $arr['uri']           = $uri;
        $arr['parent-uri']    = $uri;
index 213a9907898bf0cafa98de592528716c2018bd23..c8207984a92a35a5b2f865e4049f202e21dd139a 100644 (file)
@@ -240,7 +240,7 @@ function item_post(App $a) {
                $emailcc           =      notags(trim(defaults($_REQUEST, 'emailcc' , '')));
                $body              = escape_tags(trim(defaults($_REQUEST, 'body'    , '')));
                $network           =      notags(trim(defaults($_REQUEST, 'network' , Protocol::DFRN)));
-               $guid              =      System::createGUID(32);
+               $guid              =      System::UUID();
 
                $postopts = defaults($_REQUEST, 'postopts', '');
 
index e205d72c6d93114d13b2c10708f4b80bcdefe684..9794e9e7c016dc3804d4f8ba343ba04e8fef6dca 100644 (file)
@@ -472,7 +472,7 @@ function photos_post(App $a)
                        $uri = Item::newURI($page_owner_uid);
 
                        $arr = [];
-                       $arr['guid']          = System::createGUID(32);
+                       $arr['guid']          = System::UUID();
                        $arr['uid']           = $page_owner_uid;
                        $arr['uri']           = $uri;
                        $arr['parent-uri']    = $uri;
@@ -651,7 +651,7 @@ function photos_post(App $a)
                                        $uri = Item::newURI($page_owner_uid);
 
                                        $arr = [];
-                                       $arr['guid']          = System::createGUID(32);
+                                       $arr['guid']          = System::UUID();
                                        $arr['uid']           = $page_owner_uid;
                                        $arr['uri']           = $uri;
                                        $arr['parent-uri']    = $uri;
@@ -889,7 +889,7 @@ function photos_post(App $a)
                $arr['coord'] = $lat . ' ' . $lon;
        }
 
-       $arr['guid']          = System::createGUID(32);
+       $arr['guid']          = System::UUID();
        $arr['uid']           = $page_owner_uid;
        $arr['uri']           = $uri;
        $arr['parent-uri']    = $uri;
index 91f33c0def2fd43a2991fb1aef40b41109f0f9da..46c9d2f4a95c71e4edf5e62108161aa8e0d82d49 100644 (file)
@@ -97,7 +97,7 @@ function poke_init(App $a)
 
        $arr = [];
 
-       $arr['guid']          = System::createGUID(32);
+       $arr['guid']          = System::UUID();
        $arr['uid']           = $uid;
        $arr['uri']           = $uri;
        $arr['parent-uri']    = (!empty($parent_uri) ? $parent_uri : $uri);
index 1153f2147d7c5efcb11f2f71b141fda086640253..901bb0129b2809cc0bd429e72ef5defffedcbda3 100644 (file)
@@ -108,7 +108,7 @@ EOT;
 
        $arr = [];
 
-       $arr['guid'] = System::createGUID(32);
+       $arr['guid'] = System::UUID();
        $arr['uri'] = $uri;
        $arr['uid'] = $owner_uid;
        $arr['contact-id'] = $contact['id'];
index 959394c07881a1e8b0b9c7dd43623d77b000eac3..889ccd16f55c9cfb4efe4074d90165a201b14e3b 100644 (file)
@@ -115,7 +115,7 @@ EOT;
 
        $arr = [];
 
-       $arr['guid'] = System::createGUID(32);
+       $arr['guid'] = System::UUID();
        $arr['uri'] = $uri;
        $arr['uid'] = $owner_uid;
        $arr['contact-id'] = $contact['id'];
index 88b89cda27ac60189375854ecca2a103439ff4d2..4eb6be0809d9771d9907160e8a6f471c9d1bbef0 100644 (file)
@@ -161,6 +161,18 @@ class System extends BaseObject
                killme();
        }
 
+       /**
+        * Generates a random string in the UUID format
+        *
+        * @param bool|string  $prefix   A given prefix (default is empty)
+        * @return string a generated UUID
+        */
+       public static function UUID($prefix = '')
+       {
+               $guid = System::createGUID(32, $prefix);
+               return substr($guid, 0, 8). '-' . substr($guid, 8, 4) . '-' . substr($guid, 12, 4) . '-' . substr($guid, 16, 4) . '-' . substr($guid, 20, 12);
+       }
+
        /**
         * Generates a GUID with the given parameters
         *
index 016d1f8d9e3974a47ec0197223a1ec4fda5ece83..f08e1298945b36fbea9562a7d9272b6c84827517 100644 (file)
@@ -314,7 +314,7 @@ class Event extends BaseObject
 
                        Addon::callHooks('event_updated', $event['id']);
                } else {
-                       $event['guid']  = defaults($arr, 'guid', System::createGUID(32));
+                       $event['guid']  = defaults($arr, 'guid', System::UUID());
 
                        // New event. Store it.
                        DBA::insert('event', $event);
index e33cf020d8e02d3ec88fa55db6c6359692fd9590..d8e814b8e6e8f68f560518dad798289b95dfbac5 100644 (file)
@@ -1205,7 +1205,7 @@ class Item extends BaseObject
                } elseif (!empty($item['uri'])) {
                        $guid = self::guidFromUri($item['uri'], $prefix_host);
                } else {
-                       $guid = System::createGUID(32, hash('crc32', $prefix_host));
+                       $guid = System::UUID(hash('crc32', $prefix_host));
                }
 
                return $guid;
@@ -2359,7 +2359,7 @@ class Item extends BaseObject
        public static function newURI($uid, $guid = "")
        {
                if ($guid == "") {
-                       $guid = System::createGUID(32);
+                       $guid = System::UUID();
                }
 
                return self::getApp()->get_baseurl() . '/object/' . $guid;
@@ -2686,7 +2686,7 @@ class Item extends BaseObject
                        }
 
                        if ($contact['network'] != Protocol::FEED) {
-                               $datarray["guid"] = System::createGUID(32);
+                               $datarray["guid"] = System::UUID();
                                unset($datarray["plink"]);
                                $datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]);
                                $datarray["parent-uri"] = $datarray["uri"];
@@ -3115,7 +3115,7 @@ class Item extends BaseObject
                $objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ;
 
                $new_item = [
-                       'guid'          => System::createGUID(32),
+                       'guid'          => System::UUID(),
                        'uri'           => self::newURI($item['uid']),
                        'uid'           => $item['uid'],
                        'contact-id'    => $item_contact_id,
index 24a174b6b58251df7c5dd674c4ad75d207c50b46..64a99d4def337a1e7b91d40ad5f422fb386959d4 100644 (file)
@@ -46,7 +46,7 @@ class Mail
                        return -2;
                }
 
-               $guid = System::createGUID(32);
+               $guid = System::UUID();
                $uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid;
 
                $convid = 0;
@@ -73,7 +73,7 @@ class Mail
                        $recip_handle = (($contact['addr']) ? $contact['addr'] : $contact['nick'] . '@' . $recip_host);
                        $sender_handle = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
 
-                       $conv_guid = System::createGUID(32);
+                       $conv_guid = System::UUID();
                        $convuri = $recip_handle . ':' . $conv_guid;
 
                        $handles = $recip_handle . ';' . $sender_handle;
@@ -171,7 +171,7 @@ class Mail
                        $subject = L10n::t('[no subject]');
                }
 
-               $guid = System::createGUID(32);
+               $guid = System::UUID();
                $uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid;
 
                $me = Probe::uri($replyto);
@@ -180,7 +180,7 @@ class Mail
                        return -2;
                }
 
-               $conv_guid = System::createGUID(32);
+               $conv_guid = System::UUID();
 
                $recip_handle = $recipient['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
 
index d65e7d8f9699e41aabadb406bd3034bd7da2266f..366490bfc8850f88e687bd34544ed7d7afb96645 100644 (file)
@@ -495,7 +495,7 @@ class User
                $spubkey = $sres['pubkey'];
 
                $insert_result = DBA::insert('user', [
-                       'guid'     => System::createGUID(32),
+                       'guid'     => System::UUID(),
                        'username' => $username,
                        'password' => $new_password_encoded,
                        'email'    => $email,
index 0229aaac321ed638ced87c7f46ce5a045760535d..539a7302b7a07d3d43c1ee29a49a796df69a5e9b 100644 (file)
@@ -78,9 +78,10 @@ class ActivityPub
        const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public';
        const CONTEXT = ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1',
                ['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier',
-               'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag',
-               'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation',
-               'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']];
+               'vcard' => 'http://www.w3.org/2006/vcard/ns#',
+               'diaspora' => 'https://diasporafoundation.org#',
+               'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
+               'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag']];
 
        public static function isRequest()
        {
@@ -235,12 +236,9 @@ class ActivityPub
                        return [];
                }
 
-               $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1',
-                       ['vcard' => 'http://www.w3.org/2006/vcard/ns#', 'uuid' => 'http://schema.org/identifier',
-                       'sensitive' => 'as:sensitive', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers']]];
-
+               $data = ['@context' => self::CONTEXT];
                $data['id'] = $contact['url'];
-               $data['uuid'] = $user['guid'];
+               $data['diaspora:guid'] = $user['guid'];
                $data['type'] = $accounttype[$user['account-type']];
                $data['following'] = System::baseUrl() . '/following/' . $user['nickname'];
                $data['followers'] = System::baseUrl() . '/followers/' . $user['nickname'];
@@ -562,19 +560,6 @@ class ActivityPub
                return $tags;
        }
 
-       private static function fetchConversationURLForItem($item)
-       {
-               $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]);
-               if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
-                       $conversation_uri = $conversation['conversation-uri'];
-               } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) {
-                       $conversation_uri = $conversation['conversation-href'];
-               } else {
-                       $conversation_uri = str_replace('/object/', '/context/', $item['parent-uri']);
-               }
-               return $conversation_uri;
-       }
-
        private static function fetchContextURLForItem($item)
        {
                $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]);
@@ -616,7 +601,7 @@ class ActivityPub
                        $data['inReplyTo'] = null;
                }
 
-               $data['uuid'] = $item['guid'];
+               $data['diaspora:guid'] = $item['guid'];
                $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM);
 
                if ($item["created"] != $item["edited"]) {
@@ -627,7 +612,6 @@ class ActivityPub
                $data['attributedTo'] = $item['author-link'];
                $data['actor'] = $item['author-link'];
                $data['sensitive'] = false; // - Query NSFW
-               $data['conversation'] = self::fetchConversationURLForItem($item);
                $data['context'] = self::fetchContextURLForItem($item);
 
                if (!empty($item['title'])) {
@@ -755,7 +739,7 @@ class ActivityPub
                $profile = ['network' => Protocol::ACTIVITYPUB];
                $profile['nick'] = $apcontact['nick'];
                $profile['name'] = $apcontact['name'];
-               $profile['guid'] = $apcontact['uuid'];
+               $profile['guid'] = $apcontact['diaspora:guid'];
                $profile['url'] = $apcontact['url'];
                $profile['addr'] = $apcontact['addr'];
                $profile['alias'] = $apcontact['alias'];
@@ -1232,9 +1216,6 @@ class ActivityPub
 
                // Data in Notes:
 
-               // To-Do?
-               // emoji, atomUri, inReplyToAtomUri
-
                // Unhandled
                // contentMap, announcement_count, announcements, context_id, likes, like_count
                // inReplyToStatusId, shares, quoteUrl, statusnetConversationId
@@ -1368,7 +1349,7 @@ class ActivityPub
                $item['uri'] = $activity['id'];
                $item['created'] = $activity['published'];
                $item['edited'] = $activity['updated'];
-               $item['guid'] = $activity['uuid'];
+               $item['guid'] = $activity['diaspora:guid'];
                $item['title'] = HTML::toBBCode($activity['name']);
                $item['content-warning'] = HTML::toBBCode($activity['summary']);
                $item['body'] = self::convertMentions(HTML::toBBCode($activity['content']));
index e7edcdc490a9363d693d502bec5d29df73006af1..5239255fee83eb2c2f46f1a33d0f52150aeccc77 100644 (file)
@@ -3200,7 +3200,7 @@ class Diaspora
                $author = self::myHandle($owner);
 
                $message = ["author" => $author,
-                               "guid" => System::createGUID(32),
+                               "guid" => System::UUID(),
                                "parent_type" => "Post",
                                "parent_guid" => $item["guid"]];