]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Fix capitalization of table definition key in DBStructure
[friendica.git] / src / Protocol / Diaspora.php
index e8c576a94cd09c7dd3cd147a9b3514437d5b989e..7704d3f07b4e7aae14ce30626fbd0a13277a8526 100644 (file)
@@ -2523,7 +2523,7 @@ class Diaspora
                }
 
                // Do we already have this item?
-               $fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
+               $fields = ['body', 'title', 'attach', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
                        'author-name', 'author-link', 'author-avatar'];
                $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
                $item = Item::selectFirst($fields, $condition);
@@ -2567,7 +2567,7 @@ class Diaspora
                        }
 
                        if ($stored) {
-                               $fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
+                               $fields = ['body', 'title', 'attach', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
                                        'author-name', 'author-link', 'author-avatar'];
                                $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
                                $item = Item::selectFirst($fields, $condition);
@@ -2701,9 +2701,15 @@ class Diaspora
                        $original_item["created"],
                        $orig_url
                );
+
+               if (!empty($original_item['title'])) {
+                       $prefix .= '[h3]' . $original_item['title'] . "[/h3]\n";
+               }
+
                $datarray["body"] = $prefix.$original_item["body"]."[/share]";
 
                $datarray["tag"] = $original_item["tag"];
+               $datarray["attach"] = $original_item["attach"];
                $datarray["app"]  = $original_item["app"];
 
                $datarray["plink"] = self::plink($author, $guid);
@@ -3385,72 +3391,40 @@ class Diaspora
        {
                $body = trim($body);
 
-               // Skip if it isn't a pure repeated messages
-               // Does it start with a share?
-               if ((strpos($body, "[share") > 0) && $complete) {
+               $reshared = Item::getShareArray(['body' => $body]);
+               if (empty($reshared)) {
                        return false;
                }
 
-               // Does it end with a share?
-               if (strlen($body) > (strrpos($body, "[/share]") + 8)) {
-                       return false;
-               }
-
-               $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$1", $body);
-               // Skip if there is no shared message in there
-               if ($body == $attributes) {
+               // Skip if it isn't a pure repeated messages
+               // Does it start with a share?
+               if (!empty($reshared['comment']) && $complete) {
                        return false;
                }
 
-               // If we don't do the complete check we quit here
-
-               $guid = "";
-               preg_match("/guid='(.*?)'/ism", $attributes, $matches);
-               if (!empty($matches[1])) {
-                       $guid = $matches[1];
-               }
-
-               preg_match('/guid="(.*?)"/ism', $attributes, $matches);
-               if (!empty($matches[1])) {
-                       $guid = $matches[1];
-               }
-
-               if (($guid != "") && $complete) {
-                       $condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
+               if (!empty($reshared['guid']) && $complete) {
+                       $condition = ['guid' => $reshared['guid'], 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
                        $item = Item::selectFirst(['contact-id'], $condition);
                        if (DBA::isResult($item)) {
-                               $ret= [];
+                               $ret = [];
                                $ret["root_handle"] = self::handleFromContact($item["contact-id"]);
-                               $ret["root_guid"] = $guid;
+                               $ret["root_guid"] = $reshared['guid'];
                                return $ret;
                        } elseif ($complete) {
                                // We are resharing something that isn't a DFRN or Diaspora post.
                                // So we have to return "false" on "$complete" to not trigger a reshare.
                                return false;
                        }
-               } elseif (($guid == "") && $complete) {
+               } elseif (empty($reshared['guid']) && $complete) {
                        return false;
                }
 
-               $ret["root_guid"] = $guid;
-
-               $profile = "";
-               preg_match("/profile='(.*?)'/ism", $attributes, $matches);
-               if (!empty($matches[1])) {
-                       $profile = $matches[1];
-               }
-
-               preg_match('/profile="(.*?)"/ism', $attributes, $matches);
-               if (!empty($matches[1])) {
-                       $profile = $matches[1];
-               }
-
-               $ret= [];
+               $ret = [];
 
-               if ($profile != "") {
-                       if (Contact::getIdForURL($profile)) {
-                               $author = Contact::getDetailsByURL($profile);
-                               $ret["root_handle"] = $author['addr'];
+               if (!empty($reshared['profile']) && ($cid = Contact::getIdForURL($reshared['profile']))) {
+                       $contact = DBA::selectFirst('contact', ['addr'], ['id' => $cid]);
+                       if (!empty($contact['addr'])) {
+                               $ret['root_handle'] = $contact['addr'];
                        }
                }
 
@@ -3565,8 +3539,7 @@ class Diaspora
                $myaddr = self::myHandle($owner);
 
                $public = ($item["private"] ? "false" : "true");
-
-               $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
+               $created = DateTimeFormat::utc($item['received'], DateTimeFormat::ATOM);
                $edited = DateTimeFormat::utc($item["edited"] ?? $item["created"], DateTimeFormat::ATOM);
 
                // Detect a share element and do a reshare
@@ -3584,6 +3557,14 @@ class Diaspora
                        $title = $item["title"];
                        $body = $item["body"];
 
+                       // Fetch the title from an attached link - if there is one
+                       if (empty($item["title"]) && PConfig::get($owner['uid'], 'system', 'attach_link_title')) {
+                               $page_data = BBCode::getAttachmentData($item['body']);
+                               if (!empty($page_data['type']) && !empty($page_data['title']) && ($page_data['type'] == 'link')) {
+                                       $title = $page_data['title'];
+                               }
+                       }
+
                        if ($item['author-link'] != $item['owner-link']) {
                                require_once 'mod/share.php';
                                $body = share_header($item['author-name'], $item['author-link'], $item['author-avatar'],
@@ -3595,7 +3576,7 @@ class Diaspora
 
                        // Adding the title
                        if (strlen($title)) {
-                               $body = "## ".html_entity_decode($title)."\n\n".$body;
+                               $body = "### ".html_entity_decode($title)."\n\n".$body;
                        }
 
                        if ($item["attach"]) {