]> git.mxchange.org Git - friendica.git/commitdiff
Some more "convertForUriId" replacements
authorMichael <heluecht@pirati.ca>
Sat, 10 Jul 2021 12:58:48 +0000 (12:58 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 10 Jul 2021 12:58:48 +0000 (12:58 +0000)
15 files changed:
database.sql
include/api.php
include/conversation.php
include/enotify.php
mod/message.php
src/Model/Profile.php
src/Module/Api/Friendica/Events/Index.php
src/Module/Profile/Profile.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/DFRN.php
src/Protocol/Feed.php
src/Protocol/OStatus.php
static/dbstructure.config.php
static/dbview.config.php

index 5ee4ef053d3ea77eb682ab1743f0ca62798162c2..8f9fc8f0d5c5e5de806698e35535eaa65f6ea4b3 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2021.09-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1426
+-- DB_UPDATE_VERSION 1427
 -- ------------------------------------------
 
 
@@ -2291,6 +2291,7 @@ CREATE VIEW `owner-view` AS SELECT
        `contact`.`dfrn-id` AS `dfrn-id`,
        `contact`.`url` AS `url`,
        `contact`.`nurl` AS `nurl`,
+       `contact`.`uri-id` AS `uri-id`,
        `contact`.`addr` AS `addr`,
        `contact`.`alias` AS `alias`,
        `contact`.`pubkey` AS `pubkey`,
index 25efa8f1b73ac913f42ee0c37aebb9bee95209b7..951c2b3e582e72f03539b5d1554822415213b48f 100644 (file)
@@ -2525,12 +2525,12 @@ function api_format_messages($item, $recipient, $sender)
        if (!empty($_GET['getText'])) {
                $ret['title'] = $item['title'];
                if ($_GET['getText'] == 'html') {
-                       $ret['text'] = BBCode::convert($item['body'], false);
+                       $ret['text'] = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::API);
                } elseif ($_GET['getText'] == 'plain') {
-                       $ret['text'] = trim(HTML::toPlaintext(BBCode::convert(api_clean_plain_items($item['body']), false, BBCode::API, true), 0));
+                       $ret['text'] = trim(HTML::toPlaintext(BBCode::convertForUriId($item['uri-id'], api_clean_plain_items($item['body']), BBCode::API), 0));
                }
        } else {
-               $ret['text'] = $item['title'] . "\n" . HTML::toPlaintext(BBCode::convert(api_clean_plain_items($item['body']), false, BBCode::API, true), 0);
+               $ret['text'] = $item['title'] . "\n" . HTML::toPlaintext(BBCode::convertForUriId($item['uri-id'], api_clean_plain_items($item['body']), BBCode::API), 0);
        }
        if (!empty($_GET['getUserObjects']) && $_GET['getUserObjects'] == 'false') {
                unset($ret['sender']);
@@ -2557,7 +2557,7 @@ function api_convert_item($item)
        $attachments = api_get_attachments($body, $item['uri-id']);
 
        // Workaround for ostatus messages where the title is identically to the body
-       $html = BBCode::convert(api_clean_plain_items($body), false, BBCode::API, true);
+       $html = BBCode::convertForUriId($item['uri-id'], api_clean_plain_items($body), BBCode::API);
        $statusbody = trim(HTML::toPlaintext($html, 0));
 
        // handle data: images
@@ -2575,7 +2575,7 @@ function api_convert_item($item)
                $statustext = mb_substr($statustext, 0, 1000) . "... \n" . ($item['plink'] ?? '');
        }
 
-       $statushtml = BBCode::convert(BBCode::removeAttachment($body), false, BBCode::API, true);
+       $statushtml = BBCode::convertForUriId($item['uri-id'], BBCode::removeAttachment($body), BBCode::API);
 
        // Workaround for clients with limited HTML parser functionality
        $search = ["<br>", "<blockquote>", "</blockquote>",
@@ -2589,7 +2589,7 @@ function api_convert_item($item)
        $statushtml = str_replace($search, $replace, $statushtml);
 
        if ($item['title'] != "") {
-               $statushtml = "<br><h4>" . BBCode::convert($item['title']) . "</h4><br>" . $statushtml;
+               $statushtml = "<br><h4>" . BBCode::convertForUriId($item['uri-id'], $item['title']) . "</h4><br>" . $statushtml;
        }
 
        do {
@@ -2607,7 +2607,7 @@ function api_convert_item($item)
 
        // feeds without body should contain the link
        if ((($item['network'] ?? Protocol::PHANTOM) == Protocol::FEED) && (strlen($item['body']) == 0)) {
-               $statushtml .= BBCode::convert($item['plink']);
+               $statushtml .= BBCode::convertForUriId($item['uri-id'], $item['plink']);
        }
 
        return [
@@ -3054,7 +3054,7 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use
                'external_url' => DI::baseUrl() . "/display/" . $item['guid'],
                'friendica_activities' => api_format_items_activities($item, $type),
                'friendica_title' => $item['title'],
-               'friendica_html' => BBCode::convert($item['body'], false)
+               'friendica_html' => BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL)
        ];
 
        if (count($converted["attachments"]) > 0) {
index 4bd6ce600760b150578e566c601294086ed50774..cd9e098990f10e5ae29d5ea53fbafacaacf1d5f3 100644 (file)
@@ -47,91 +47,6 @@ use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 use Friendica\Util\XML;
 
-function item_extract_images($body) {
-
-       $saved_image = [];
-       $orig_body = $body;
-       $new_body = '';
-
-       $cnt = 0;
-       $img_start = strpos($orig_body, '[img');
-       $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
-       $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
-       while (($img_st_close !== false) && ($img_end !== false)) {
-
-               $img_st_close++; // make it point to AFTER the closing bracket
-               $img_end += $img_start;
-
-               if (!strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
-                       // This is an embedded image
-
-                       $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
-                       $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
-
-                       $cnt++;
-               } else {
-                       $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
-               }
-
-               $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
-
-               if ($orig_body === false) {
-                       // in case the body ends on a closing image tag
-                       $orig_body = '';
-               }
-
-               $img_start = strpos($orig_body, '[img');
-               $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
-               $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
-       }
-
-       $new_body = $new_body . $orig_body;
-
-       return ['body' => $new_body, 'images' => $saved_image];
-}
-
-function item_redir_and_replace_images($body, $images, $cid) {
-
-       $origbody = $body;
-       $newbody = '';
-
-       $cnt = 1;
-       $pos = BBCode::getTagPosition($origbody, 'url', 0);
-       while ($pos !== false && $cnt < 1000) {
-
-               $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
-               $replace = '[url=' . DI::baseUrl() . '/redir/' . $cid
-                                  . '?url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
-
-               $newbody .= substr($origbody, 0, $pos['start']['open']);
-               $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
-               $origbody = substr($origbody, $pos['end']['close']);
-               if ($origbody === false) {
-                       $origbody = '';
-               }
-
-               $subject = preg_replace($search, $replace, $subject);
-               $newbody .= $subject;
-
-               $cnt++;
-               // Isn't this supposed to use $cnt value for $occurrences? - @MrPetovan
-               $pos = BBCode::getTagPosition($origbody, 'url', 0);
-       }
-       $newbody .= $origbody;
-
-       $cnt = 0;
-       foreach ($images as $image) {
-               /*
-                * We're depending on the property of 'foreach' (specified on the PHP website) that
-                * it loops over the array starting from the first element and going sequentially
-                * to the last element.
-                */
-               $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
-               $cnt++;
-       }
-       return $newbody;
-}
-
 /**
  * Render actions localized
  *
@@ -141,11 +56,6 @@ function item_redir_and_replace_images($body, $images, $cid) {
  */
 function localize_item(&$item)
 {
-       $extracted = item_extract_images($item['body']);
-       if ($extracted['images']) {
-               $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
-       }
-
        /// @todo The following functionality needs to be cleaned up.
        if (!empty($item['verb'])) {
                $activity = DI::activity();
@@ -260,13 +170,6 @@ function localize_item(&$item)
                }
        }
 
-       // add zrl's to public images
-       $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
-       if (preg_match($photo_pattern, $item['body'])) {
-               $photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' , true) . '][img' . '$4' . ']h' . '$5'  . '[/img][/url]';
-               $item['body'] = BBCode::pregReplaceInTag($photo_pattern, $photo_replace, 'url', $item['body']);
-       }
-
        // add sparkle links to appropriate permalinks
        // Only create a redirection to a magic link when logged in
        if (!empty($item['plink']) && Session::isAuthenticated()) {
index 409fc66facceffb8d2482e5be27824a0549f69df..cfc03626f585459fa4d121f4bb4a3144fe333537 100644 (file)
@@ -474,7 +474,7 @@ function notification($params)
        if ($show_in_notification_page) {
                $fields = [
                        'name'          => $params['source_name'] ?? '',
-                       'name_cache'    => substr(strip_tags(BBCode::convert($params['source_name'])), 0, 255),
+                       'name_cache'    => substr(strip_tags(BBCode::convertForUriId($uri_id, $params['source_name'])), 0, 255),
                        'url'           => $params['source_link'] ?? '',
                        'photo'         => $params['source_photo'] ?? '',
                        'link'          => $itemlink ?? '',
index 2705708ea6f206e43dc43cfbb2869f3feda1328d..ff4998992dc20b03cc768cfded1857e56255fefd 100644 (file)
@@ -314,14 +314,9 @@ function message_content(App $a)
                                $sparkle = ' sparkle';
                        }
 
-                       $extracted = item_extract_images($message['body']);
-                       if ($extracted['images']) {
-                               $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']);
-                       }
-
                        $from_name_e = $message['from-name'];
                        $subject_e = $message['title'];
-                       $body_e = BBCode::convert($message['body']);
+                       $body_e = BBCode::convertForUriId($message['uri-id'], $message['body']);
                        $to_name_e = $message['name'];
 
                        $contact = Contact::getByURL($message['from-url'], false, ['thumb', 'addr', 'id', 'avatar']);
index 4a0db9ecd8b0d4c0a942f38fc330bfa751a05572..b3345eb63fb547ba0c46df7596f339c7801d1c81 100644 (file)
@@ -486,11 +486,11 @@ class Profile
                }
 
                if (isset($p['about'])) {
-                       $p['about'] = BBCode::convert($p['about']);
+                       $p['about'] = BBCode::convertForUriId($profile['uri-id'] ?? 0, $p['about']);
                }
 
                if (isset($p['address'])) {
-                       $p['address'] = BBCode::convert($p['address']);
+                       $p['address'] = BBCode::convertForUriId($profile['uri-id'] ?? 0, $p['address']);
                }
 
                $p['photo'] = Contact::getAvatarUrlForId($cid, ProxyUtils::SIZE_SMALL);
@@ -670,13 +670,13 @@ class Profile
                                        $istoday = true;
                                }
 
-                               $title = strip_tags(html_entity_decode(BBCode::convert($rr['summary']), ENT_QUOTES, 'UTF-8'));
+                               $title = strip_tags(html_entity_decode(BBCode::convertForUriId($rr['uri-id'], $rr['summary']), ENT_QUOTES, 'UTF-8'));
 
                                if (strlen($title) > 35) {
                                        $title = substr($title, 0, 32) . '... ';
                                }
 
-                               $description = substr(strip_tags(BBCode::convert($rr['desc'])), 0, 32) . '... ';
+                               $description = substr(strip_tags(BBCode::convertForUriId($rr['uri-id'], $rr['desc'])), 0, 32) . '... ';
                                if (!$description) {
                                        $description = DI::l10n()->t('[No description]');
                                }
index d53273ef66f3fff262a65024d8865a79283d68f8..febbdea48e1b1e07d054eec2d00cef3097bd7f12 100644 (file)
@@ -55,7 +55,7 @@ class Index extends BaseApi
                                'cid'       => $event['cid'],
                                'uri'       => $event['uri'],
                                'name'      => $event['summary'],
-                               'desc'      => BBCode::convert($event['desc']),
+                               'desc'      => BBCode::convertForUriId($event['uri-id'], $event['desc']),
                                'startTime' => $event['start'],
                                'endTime'   => $event['finish'],
                                'type'      => $event['type'],
index dfe537c8c0f196ffa119c2b7c25ba50d49a1015b..96545deaf9de0a1fc70eff8d90f7066ccce6ebfa 100644 (file)
@@ -169,7 +169,7 @@ class Profile extends BaseProfile
                }
 
                if ($a->profile['about']) {
-                       $basic_fields += self::buildField('about', DI::l10n()->t('Description:'), BBCode::convert($a->profile['about']));
+                       $basic_fields += self::buildField('about', DI::l10n()->t('Description:'), BBCode::convertForUriId($a->profile['uri-id'], $a->profile['about']));
                }
 
                if ($a->profile['xmpp']) {
@@ -218,7 +218,7 @@ class Profile extends BaseProfile
                        $custom_fields += self::buildField(
                                'custom_' . $profile_field->order,
                                $profile_field->label,
-                               BBCode::convert($profile_field->value),
+                               BBCode::convertForUriId($a->profile['uri-id'], $profile_field->value),
                                'aprofile custom'
                        );
                };
index d59d9c4af6f57a4c3c4df616f52611621b0d04f8..7669934a650b288b97e2952a0527f73e325e678a 100644 (file)
@@ -1345,8 +1345,7 @@ class Receiver
                        // Some AP software allow formatted text in post location, so we run all the text converters we have to boil
                        // down to HTML and then finally format to plaintext.
                        $location = Markdown::convert($location);
-                       $location = BBCode::convert($location);
-                       $location = HTML::toPlaintext($location);
+                       $location = BBCode::toPlaintext($location);
                }
 
                $object_data['sc:identifier'] = JsonLD::fetchElement($object, 'sc:identifier', '@value');
index cdf1538308f340eea717ad28b3d429eedd901117..29fb1a11a7a47688704e73d56ca3d38e4a57dbee 100644 (file)
@@ -345,7 +345,7 @@ class Transmitter
                }
 
                if (!empty($owner['about'])) {
-                       $data['summary'] = BBCode::convert($owner['about'], false);
+                       $data['summary'] = BBCode::convertForUriId($owner['uri-id'], $owner['about'], BBCode::EXTERNAL);
                }
 
                $data['url'] = $owner['url'];
index 4d2744498787125673215aafccc542f3ca58f7ab..faae900b331ec22d6b0f51247ee933f01674ca11 100644 (file)
@@ -765,12 +765,13 @@ class DFRN
         * @param DOMDocument $doc      XML document
         * @param string      $element  Element name for the activity
         * @param string      $activity activity value
+        * @param int         $uriid    Uri-Id of the post
         *
         * @return \DOMElement XML activity object
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @todo  Find proper type-hints
         */
-       private static function createActivity(DOMDocument $doc, $element, $activity)
+       private static function createActivity(DOMDocument $doc, $element, $activity, $uriid)
        {
                if ($activity) {
                        $entry = $doc->createElement($element);
@@ -817,7 +818,7 @@ class DFRN
                                }
                        }
                        if ($r->content) {
-                               XML::addElement($doc, $entry, "content", BBCode::convert($r->content), ["type" => "html"]);
+                               XML::addElement($doc, $entry, "content", BBCode::convertForUriId($uriid, $r->content, BBCode::EXTERNAL), ["type" => "html"]);
                        }
 
                        return $entry;
@@ -918,7 +919,7 @@ class DFRN
                                $htmlbody = "[b]" . $item['title'] . "[/b]\n\n" . $htmlbody;
                        }
 
-                       $htmlbody = BBCode::convertForUriId($item['uri-id'], $htmlbody, BBCode::OSTATUS);
+                       $htmlbody = BBCode::convertForUriId($item['uri-id'], $htmlbody, BBCode::ACTIVITYPUB);
                }
 
                $author = self::addEntryAuthor($doc, "author", $item["author-link"], $item);
@@ -1033,12 +1034,12 @@ class DFRN
                        XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::COMMENT);
                }
 
-               $actobj = self::createActivity($doc, "activity:object", $item['object']);
+               $actobj = self::createActivity($doc, "activity:object", $item['object'], $item['uri-id']);
                if ($actobj) {
                        $entry->appendChild($actobj);
                }
 
-               $actarg = self::createActivity($doc, "activity:target", $item['target']);
+               $actarg = self::createActivity($doc, "activity:target", $item['target'], $item['uri-id']);
                if ($actarg) {
                        $entry->appendChild($actarg);
                }
index c088876d93f4834d10d908a95d446c30619404e9..c155e9e3d250b326074ccac8236a08d1b97fe0cc 100644 (file)
@@ -1109,7 +1109,7 @@ class Feed
 
                $body = OStatus::formatPicturePost($item['body'], $item['uri-id']);
 
-               $body = BBCode::convertForUriId($item['uri-id'], $body, BBCode::OSTATUS, false);
+               $body = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
 
                XML::addElement($doc, $entry, "content", $body, ["type" => "html"]);
 
@@ -1186,7 +1186,7 @@ class Feed
        private static function getTitle(array $item)
        {
                if ($item['title'] != '') {
-                       return BBCode::convertForUriId($item['uri-id'], $item['title'], BBCode::OSTATUS);
+                       return BBCode::convertForUriId($item['uri-id'], $item['title'], BBCode::ACTIVITYPUB);
                }
 
                // Fetch information about the post
index 03ff68d963ce33db7c5af782f26015ad907c0b85..e813cc2507c12a74a1a031fcc610584dfc54958d 100644 (file)
@@ -1418,7 +1418,7 @@ class OStatus
                XML::addElement($doc, $author, "name", $owner["nick"]);
                XML::addElement($doc, $author, "email", $owner["addr"]);
                if ($show_profile) {
-                       XML::addElement($doc, $author, "summary", BBCode::convert($owner["about"], false, BBCode::OSTATUS));
+                       XML::addElement($doc, $author, "summary", BBCode::convertForUriId($owner['uri-id'], $owner["about"], BBCode::OSTATUS));
                }
 
                $attributes = ["rel" => "alternate", "type" => "text/html", "href" => $owner["url"]];
@@ -1445,7 +1445,7 @@ class OStatus
                XML::addElement($doc, $author, "poco:preferredUsername", $owner["nick"]);
                XML::addElement($doc, $author, "poco:displayName", $owner["name"]);
                if ($show_profile) {
-                       XML::addElement($doc, $author, "poco:note", BBCode::convert($owner["about"], false, BBCode::OSTATUS));
+                       XML::addElement($doc, $author, "poco:note", BBCode::convertForUriId($owner['uri-id'], $owner["about"], BBCode::OSTATUS));
 
                        if (trim($owner["location"]) != "") {
                                $element = $doc->createElement("poco:address");
index e47f0d5dc13ba09c199094296d5d543087e87f34..7eec39a9848653711664745aca3df3d3750934ef 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1426);
+       define('DB_UPDATE_VERSION', 1427);
 }
 
 return [
index 01cda59a62c0da7b849f137faf2eaf5e8cd0878e..f4ff02a268488b1652d8e84ed6573d44e67fd308 100644 (file)
                        "dfrn-id" => ["contact", "dfrn-id"],
                        "url" => ["contact", "url"],
                        "nurl" => ["contact", "nurl"],
+                       "uri-id" => ["contact", "uri-id"],
                        "addr" => ["contact", "addr"],
                        "alias" => ["contact", "alias"],
                        "pubkey" => ["contact", "pubkey"],