]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/BBCode.php
Add a couple of cases to DateTimeFormat::fix()
[friendica.git] / src / Content / Text / BBCode.php
index 0a07e18f40716b6f53acc86f8bf5adf3f6ac002d..43d4127ea99c51bf136283b22657681dd08c3535 100644 (file)
@@ -294,7 +294,7 @@ class BBCode
                // Simplify image codes
                $post['text'] = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $post['text']);
                $post['text'] = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $post['text']);
-               
+
                // if nothing is found, it maybe having an image.
                if (!isset($post['type'])) {
                        if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]#ism", $post['text'], $pictures, PREG_SET_ORDER)) {
@@ -1009,18 +1009,32 @@ class BBCode
        /**
         * @param string $text A BBCode string
         * @return array Empty array if no share tag is present or the following array, missing attributes end up empty strings:
-        *               - comment: Text before the opening share tag
-        *               - shared : Text inside the share tags
-        *               - author : (Optional) Display name of the shared author
-        *               - profile: (Optional) Profile page URL of the shared author
-        *               - avatar : (Optional) Profile picture URL of the shared author
-        *               - link   : (Optional) Canonical URL of the shared post
-        *               - posted : (Optional) Date the shared post was initially posted ("Y-m-d H:i:s" in GMT)
-        *               - guid   : (Optional) Shared post GUID if any
+        *               - comment   : Text before the opening share tag
+        *               - shared    : Text inside the share tags
+        *               - author    : (Optional) Display name of the shared author
+        *               - profile   : (Optional) Profile page URL of the shared author
+        *               - avatar    : (Optional) Profile picture URL of the shared author
+        *               - link      : (Optional) Canonical URL of the shared post
+        *               - posted    : (Optional) Date the shared post was initially posted ("Y-m-d H:i:s" in GMT)
+        *               - message_id: (Optional) Shared post URI if any
+        *               - guid      : (Optional) Shared post GUID if any
         */
        public static function fetchShareAttributes(string $text): array
        {
                DI::profiler()->startRecording('rendering');
+               if (preg_match('~(.*?)\[share](.*)\[/share]~ism', $text, $matches)) {
+                       return [
+                               'author'     => '',
+                               'profile'    => '',
+                               'avatar'     => '',
+                               'link'       => '',
+                               'posted'     => '',
+                               'guid'       => '',
+                               'message_id' => trim($matches[2]),
+                               'comment'    => trim($matches[1]),
+                               'shared'     => '',
+                       ];
+               }
                // See Issue https://github.com/friendica/friendica/issues/10454
                // Hashtags in usernames are expanded to links. This here is a quick fix.
                $text = preg_replace('~([@!#])\[url=.*?](.*?)\[/url]~ism', '$1$2', $text);
@@ -1047,7 +1061,7 @@ class BBCode
        private static function extractShareAttributes(string $shareString): array
        {
                $attributes = [];
-               foreach (['author', 'profile', 'avatar', 'link', 'posted', 'guid'] as $field) {
+               foreach (['author', 'profile', 'avatar', 'link', 'posted', 'guid', 'message_id'] as $field) {
                        preg_match("/$field=(['\"])(.+?)\\1/ism", $shareString, $matches);
                        $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8');
                }
@@ -2458,10 +2472,11 @@ class BBCode
         * @param string      $link    Post source URL
         * @param string      $posted  Post created date
         * @param string|null $guid    Post guid (if any)
+        * @param string|null $uri     Post uri (if any)
         * @return string
         * @TODO Rewrite to handle over whole record array
         */
-       public static function getShareOpeningTag(string $author, string $profile, string $avatar, string $link, string $posted, string $guid = null): string
+       public static function getShareOpeningTag(string $author, string $profile, string $avatar, string $link, string $posted, string $guid = null, string $uri = null): string
        {
                DI::profiler()->startRecording('rendering');
                $header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author) .
@@ -2474,6 +2489,10 @@ class BBCode
                        $header .= "' guid='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $guid);
                }
 
+               if ($uri) {
+                       $header .= "' message_id='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $uri);
+               }
+
                $header  .= "']";
 
                DI::profiler()->stopRecording();