]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Feed.php
Basic forum support for Diaspora
[friendica.git] / src / Protocol / Feed.php
index dc4548b3ead97d9635e7d1b951ba778fb5252ae3..203a2e83565d27396dcb4dc7486e17e8a5bab5a8 100644 (file)
@@ -8,6 +8,8 @@ namespace Friendica\Protocol;
 
 use Friendica\Database\DBM;
 use Friendica\Core\System;
+use Friendica\Model\Item;
+use Friendica\Util\Network;
 use dba;
 use DOMDocument;
 use DOMXPath;
@@ -242,7 +244,7 @@ class Feed {
 
                        $orig_plink = $item["plink"];
 
-                       $item["plink"] = original_url($item["plink"]);
+                       $item["plink"] = Network::finalUrl($item["plink"]);
 
                        $item["parent-uri"] = $item["uri"];
 
@@ -357,7 +359,7 @@ class Feed {
 
                        // remove the content of the title if it is identically to the body
                        // This helps with auto generated titles e.g. from tumblr
-                       if (title_is_body($item["title"], $body)) {
+                       if (self::titleIsBody($item["title"], $body)) {
                                $item["title"] = "";
                        }
                        $item["body"] = html2bbcode($body, $basepath);
@@ -413,7 +415,7 @@ class Feed {
                                        $item["body"] .= "\n".$item['tag'];
                                }
                                // Add the link to the original feed entry if not present in feed
-                               if (!strstr($item["body"], $item['plink']) && ($item['plink'] != '')) {
+                               if (($item['plink'] != '') && !strstr($item["body"], $item['plink'])) {
                                        $item["body"] .= "[hr][url]".$item['plink']."[/url]";
                                }
                        }
@@ -421,17 +423,17 @@ class Feed {
                        if (!$simulate) {
                                logger("Stored feed: ".print_r($item, true), LOGGER_DEBUG);
 
-                               $notify = item_is_remote_self($contact, $item);
+                               $notify = Item::isRemoteSelf($contact, $item);
 
                                // Distributed items should have a well formatted URI.
                                // Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
                                if ($notify) {
-                                       $item['guid'] = uri_to_guid($orig_plink, $a->get_hostname());
+                                       $item['guid'] = Item::guidFromUri($orig_plink, $a->get_hostname());
                                        unset($item['uri']);
                                        unset($item['parent-uri']);
                                }
 
-                               $id = item_store($item, false, $notify);
+                               $id = Item::insert($item, false, $notify);
 
                                logger("Feed for contact ".$contact["url"]." stored under id ".$id);
                        } else {
@@ -446,4 +448,30 @@ class Feed {
                        return ["header" => $author, "items" => $items];
                }
        }
+
+       private static function titleIsBody($title, $body)
+       {
+               $title = strip_tags($title);
+               $title = trim($title);
+               $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
+               $title = str_replace(["\n", "\r", "\t", " "], ["", "", "", ""], $title);
+
+               $body = strip_tags($body);
+               $body = trim($body);
+               $body = html_entity_decode($body, ENT_QUOTES, 'UTF-8');
+               $body = str_replace(["\n", "\r", "\t", " "], ["", "", "", ""], $body);
+
+               if (strlen($title) < strlen($body)) {
+                       $body = substr($body, 0, strlen($title));
+               }
+
+               if (($title != $body) && (substr($title, -3) == "...")) {
+                       $pos = strrpos($title, "...");
+                       if ($pos > 0) {
+                               $title = substr($title, 0, $pos);
+                               $body = substr($body, 0, $pos);
+                       }
+               }
+               return ($title == $body);
+       }
 }