]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
Merge remote-tracking branch 'upstream/develop' into term2tag
[friendica.git] / src / Protocol / DFRN.php
index 078deff7a3876ab348c3a72d049a36805a94acad..57edfb02b70c9f26f09429598ad8708db569f70d 100644 (file)
@@ -24,9 +24,7 @@ namespace Friendica\Protocol;
 use DOMDocument;
 use DOMXPath;
 use Friendica\App\BaseURL;
-use Friendica\Content\OEmbed;
 use Friendica\Content\Text\BBCode;
-use Friendica\Content\Text\HTML;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
@@ -37,10 +35,12 @@ use Friendica\Model\Conversation;
 use Friendica\Model\Event;
 use Friendica\Model\GContact;
 use Friendica\Model\Item;
+use Friendica\Model\ItemURI;
 use Friendica\Model\Mail;
 use Friendica\Model\Notify\Type;
 use Friendica\Model\PermissionSet;
 use Friendica\Model\Profile;
+use Friendica\Model\Term;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
 use Friendica\Util\Crypto;
@@ -49,8 +49,6 @@ use Friendica\Util\Images;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
-use HTMLPurifier;
-use HTMLPurifier_Config;
 
 /**
  * This class contain functions to create and send DFRN XML files
@@ -252,8 +250,8 @@ class DFRN
                        $sql_post_table = sprintf(
                                "INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
                                DBA::escape(Strings::protectSprintf($category)),
-                               intval(TERM_OBJ_POST),
-                               intval(TERM_CATEGORY),
+                               intval(Term::OBJECT_TYPE_POST),
+                               intval(Term::CATEGORY),
                                intval($owner_id)
                        );
                }
@@ -1052,6 +1050,7 @@ class DFRN
                if ($item['private']) {
                        // Friendica versions prior to 2020.3 can't handle "unlisted" properly. So we can only transmit public and private
                        XML::addElement($doc, $entry, "dfrn:private", ($item['private'] == Item::PRIVATE ? Item::PRIVATE : Item::PUBLIC));
+                       XML::addElement($doc, $entry, "dfrn:unlisted", $item['private'] == Item::UNLISTED);
                }
 
                if ($item['extid']) {
@@ -1071,7 +1070,7 @@ class DFRN
                // The signed text contains the content in Markdown, the sender handle and the signatur for the content
                // It is needed for relayed comments to Diaspora.
                if ($item['signed_text']) {
-                       $sign = base64_encode(json_encode(['signed_text' => $item['signed_text'],'signature' => $item['signature'],'signer' => $item['signer']]));
+                       $sign = base64_encode(json_encode(['signed_text' => $item['signed_text'],'signature' => '','signer' => '']));
                        XML::addElement($doc, $entry, "dfrn:diaspora_signature", $sign);
                }
 
@@ -2368,32 +2367,11 @@ class DFRN
 
                $item["body"] = XML::getFirstNodeValue($xpath, "dfrn:env/text()", $entry);
                $item["body"] = str_replace([' ',"\t","\r","\n"], ['','','',''], $item["body"]);
-               // make sure nobody is trying to sneak some html tags by us
+
                $item["body"] = Strings::base64UrlDecode($item["body"]);
 
                $item["body"] = BBCode::limitBodySize($item["body"]);
 
-               /// @todo Do we really need this check for HTML elements? (It was copied from the old function)
-               if ((strpos($item['body'], '<') !== false) && (strpos($item['body'], '>') !== false)) {
-                       $base_url = DI::baseUrl()->get();
-                       $item['body'] = HTML::relToAbs($item['body'], $base_url);
-
-                       $item['body'] = HTML::toBBCodeVideo($item['body']);
-
-                       $item['body'] = OEmbed::HTML2BBCode($item['body']);
-
-                       $config = HTMLPurifier_Config::createDefault();
-                       $config->set('Cache.DefinitionImpl', null);
-
-                       // we shouldn't need a whitelist, because the bbcode converter
-                       // will strip out any unsupported tags.
-
-                       $purifier = new HTMLPurifier($config);
-                       $item['body'] = $purifier->purify($item['body']);
-
-                       $item['body'] = @HTML::toBBCode($item['body']);
-               }
-
                /// @todo We should check for a repeated post and if we know the repeated author.
 
                // We don't need the content element since "dfrn:env" is always present
@@ -2405,6 +2383,11 @@ class DFRN
 
                $item["private"] = XML::getFirstNodeValue($xpath, "dfrn:private/text()", $entry);
 
+               $unlisted = XML::getFirstNodeValue($xpath, "dfrn:unlisted/text()", $entry);
+               if (!empty($unlisted) && ($item['private'] != Item::PRIVATE)) {
+                       $item['private'] = Item::UNLISTED;
+               }
+
                $item["extid"] = XML::getFirstNodeValue($xpath, "dfrn:extid/text()", $entry);
 
                if (XML::getFirstNodeValue($xpath, "dfrn:bookmark/text()", $entry) == "true") {
@@ -2422,6 +2405,8 @@ class DFRN
 
                $item["guid"] = XML::getFirstNodeValue($xpath, "dfrn:diaspora_guid/text()", $entry);
 
+               $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
+
                // We store the data from "dfrn:diaspora_signature" in a different table, this is done in "Item::insert"
                $dsprsig = XML::unescape(XML::getFirstNodeValue($xpath, "dfrn:diaspora_signature/text()", $entry));
                if ($dsprsig != "") {
@@ -2475,6 +2460,27 @@ class DFRN
                                                }
 
                                                $item["tag"] .= $termhash . "[url=" . $termurl . "]" . $term . "[/url]";
+
+                                               // Store the hashtag/mention
+                                               $fields = ['uri-id' => $item['uri-id'], 'name' => substr($term, 0, 64)];
+
+                                               if ($termhash == Term::TAG_CHARACTER[Term::MENTION]) {
+                                                       $fields['type'] = Term::MENTION;
+                                               } elseif ($termhash == Term::TAG_CHARACTER[Term::EXCLUSIVE_MENTION]) {
+                                                       $fields['type'] = Term::EXCLUSIVE_MENTION;
+                                               } elseif ($termhash == Term::TAG_CHARACTER[Term::IMPLICIT_MENTION]) {
+                                                       $fields['type'] = Term::IMPLICIT_MENTION;
+                                               } elseif ($termhash == Term::TAG_CHARACTER[Term::HASHTAG]) {
+                                                       $fields['type'] = Term::HASHTAG;
+                                               }
+
+                                               if (!empty($termurl)) {
+                                                       $fields['url'] = $termurl;
+                                               }
+
+                                               DBA::insert('tag', $fields, true);
+
+                                               Logger::info('Stored tag/mention', ['uri-id' => $item['uri-id'], 'tag' => $term, 'url' => $termurl, 'hash' => $termhash, 'fields' => $fields]);
                                        }
                                }
                        }
@@ -2710,7 +2716,7 @@ class DFRN
 
                Logger::log('deleting item '.$item['id'].' uri='.$uri, Logger::DEBUG);
 
-               Item::delete(['id' => $item['id']]);
+               Item::markForDeletion(['id' => $item['id']]);
        }
 
        /**