]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Update references to bb2diaspora and diaspora2bb
[friendica.git] / src / Protocol / Diaspora.php
index 307b52f785f5e8e14786042073875b1205859815..a2a4f36031583d731143b8f2600e1f03a1bc73e3 100644 (file)
@@ -7,8 +7,11 @@
  * This implementation here interprets the old and the new protocol and sends the new one.
  * In the future we will remove most stuff from "validPosting" and interpret only the new protocol.
  */
+
 namespace Friendica\Protocol;
 
+use Friendica\Content\Text\BBCode;
+use Friendica\Content\Text\Markdown;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
@@ -825,7 +828,12 @@ class Diaspora
                        // if Diaspora connectivity is enabled on their server
                        if ($r && ($r["network"] === NETWORK_DIASPORA)) {
                                self::addFContact($r, $update);
-                               $person = $r;
+
+                               // Fetch the updated or added contact
+                               $person = dba::selectFirst('fcontact', [], ['network' => NETWORK_DIASPORA, 'addr' => $handle]);
+                               if (!DBM::is_result($person)) {
+                                       $person = $r;
+                               }
                        }
                }
 
@@ -902,23 +910,23 @@ class Diaspora
        }
 
        /**
-        * @brief get a handle (user@domain.tld) from a given contact id or gcontact id
+        * @brief get a handle (user@domain.tld) from a given contact id
         *
         * @param int $contact_id  The id in the contact table
-        * @param int $gcontact_id The id in the gcontact table
+        * @param int $pcontact_id The id in the contact table (Used for the public contact)
         *
         * @return string the handle
         */
-       public static function handleFromContact($contact_id, $gcontact_id = 0)
+       private static function handleFromContact($contact_id, $pcontact_id = 0)
        {
                $handle = false;
 
-               logger("contact id is ".$contact_id." - gcontact id is ".$gcontact_id, LOGGER_DEBUG);
+               logger("contact id is ".$contact_id." - pcontact id is ".$pcontact_id, LOGGER_DEBUG);
 
-               if ($gcontact_id != 0) {
+               if ($pcontact_id != 0) {
                        $r = q(
-                               "SELECT `addr` FROM `gcontact` WHERE `id` = %d AND `addr` != ''",
-                               intval($gcontact_id)
+                               "SELECT `addr` FROM `contact` WHERE `id` = %d AND `addr` != ''",
+                               intval($pcontact_id)
                        );
 
                        if (DBM::is_result($r)) {
@@ -1723,7 +1731,7 @@ class Diaspora
 
                $datarray["plink"] = self::plink($author, $guid, $parent_item['guid']);
 
-               $body = diaspora2bb($text);
+               $body = Markdown::toBBCode($text);
 
                $datarray["body"] = self::replacePeopleGuid($body, $person["url"]);
 
@@ -1790,7 +1798,7 @@ class Diaspora
                        return false;
                }
 
-               $body = diaspora2bb($msg_text);
+               $body = Markdown::toBBCode($msg_text);
                $message_uri = $msg_author.":".$msg_guid;
 
                $person = self::personByHandle($msg_author);
@@ -2124,7 +2132,7 @@ class Diaspora
                        return false;
                }
 
-               $body = diaspora2bb($text);
+               $body = Markdown::toBBCode($text);
 
                $body = self::replacePeopleGuid($body, $person["url"]);
 
@@ -2276,8 +2284,8 @@ class Diaspora
                $image_url = unxmlify($data->image_url);
                $birthday = unxmlify($data->birthday);
                $gender = unxmlify($data->gender);
-               $about = diaspora2bb(unxmlify($data->bio));
-               $location = diaspora2bb(unxmlify($data->location));
+               $about = Markdown::toBBCode(unxmlify($data->bio));
+               $location = Markdown::toBBCode(unxmlify($data->location));
                $searchable = (unxmlify($data->searchable) == "true");
                $nsfw = (unxmlify($data->nsfw) == "true");
                $tags = unxmlify($data->tag_string);
@@ -2654,7 +2662,7 @@ class Diaspora
                        if (self::isReshare($r[0]["body"], true)) {
                                $r = [];
                        } elseif (self::isReshare($r[0]["body"], false) || strstr($r[0]["body"], "[share")) {
-                               $r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"]));
+                               $r[0]["body"] = Markdown::toBBCode(BBCode::toMarkdown($r[0]["body"]));
 
                                $r[0]["body"] = self::replacePeopleGuid($r[0]["body"], $r[0]["author-link"]);
 
@@ -2689,7 +2697,7 @@ class Diaspora
                                if (DBM::is_result($r)) {
                                        // If it is a reshared post from another network then reformat to avoid display problems with two share elements
                                        if (self::isReshare($r[0]["body"], false)) {
-                                               $r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"]));
+                                               $r[0]["body"] = Markdown::toBBCode(BBCode::toMarkdown($r[0]["body"]));
                                                $r[0]["body"] = self::replacePeopleGuid($r[0]["body"], $r[0]["author-link"]);
                                        }
 
@@ -2933,7 +2941,7 @@ class Diaspora
                        }
                }
 
-               $body = diaspora2bb($text);
+               $body = Markdown::toBBCode($text);
 
                $datarray = [];
 
@@ -3584,14 +3592,14 @@ class Diaspora
                        $eventdata['end'] = DateTimeFormat::convert($event['finish'], "UTC", $eventdata['timezone'], $mask);
                }
                if ($event['summary']) {
-                       $eventdata['summary'] = html_entity_decode(bb2diaspora($event['summary']));
+                       $eventdata['summary'] = html_entity_decode(BBCode::toMarkdown($event['summary']));
                }
                if ($event['desc']) {
-                       $eventdata['description'] = html_entity_decode(bb2diaspora($event['desc']));
+                       $eventdata['description'] = html_entity_decode(BBCode::toMarkdown($event['desc']));
                }
                if ($event['location']) {
                        $location = [];
-                       $location["address"] = html_entity_decode(bb2diaspora($event['location']));
+                       $location["address"] = html_entity_decode(BBCode::toMarkdown($event['location']));
                        $location["lat"] = 0;
                        $location["lng"] = 0;
                        $eventdata['location'] = $location;
@@ -3641,7 +3649,7 @@ class Diaspora
                        $body = $item["body"];
 
                        // convert to markdown
-                       $body = html_entity_decode(bb2diaspora($body));
+                       $body = html_entity_decode(BBCode::toMarkdown($body));
 
                        // Adding the title
                        if (strlen($title)) {
@@ -3826,7 +3834,7 @@ class Diaspora
 
                $parent = $p[0];
 
-               $text = html_entity_decode(bb2diaspora($item["body"]));
+               $text = html_entity_decode(BBCode::toMarkdown($item["body"]));
                $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
 
                $comment = ["author" => self::myHandle($owner),
@@ -4008,7 +4016,7 @@ class Diaspora
         */
        public static function sendRetraction($item, $owner, $contact, $public_batch = false, $relay = false)
        {
-               $itemaddr = self::handleFromContact($item["contact-id"], $item["gcontact-id"]);
+               $itemaddr = self::handleFromContact($item["contact-id"], $item["author-id"]);
 
                $msg_type = "retraction";
 
@@ -4062,7 +4070,7 @@ class Diaspora
                        "participants" => $cnv["recips"]
                ];
 
-               $body = bb2diaspora($item["body"]);
+               $body = BBCode::toMarkdown($item["body"]);
                $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
 
                $msg = [
@@ -4197,7 +4205,7 @@ class Diaspora
                        }
 
                        $about = $profile['about'];
-                       $about = strip_tags(bbcode($about));
+                       $about = strip_tags(BBCode::convert($about));
 
                        $location = Profile::formatLocation($profile);
                        $tags = '';