]> git.mxchange.org Git - friendica.git/commitdiff
The new tag table should work for feeds no as well
authorMichael <heluecht@pirati.ca>
Wed, 15 Apr 2020 05:10:40 +0000 (05:10 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 15 Apr 2020 05:10:40 +0000 (05:10 +0000)
include/items.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/Feed.php

index 4c7551e5c49f0a565a4b7b75dfde9339472b1d2a..6068be4b9469c71041ef7a498c1443ee5ead7823 100644 (file)
@@ -141,11 +141,12 @@ function query_page_info($url, $photo = "", $keywords = false, $keyword_blacklis
        return $data;
 }
 
-function add_page_keywords($url, $photo = "", $keywords = false, $keyword_blacklist = "")
+function add_page_keywords($url, $photo = "", $keywords = false, $keyword_blacklist = "", $return_array = false)
 {
        $data = query_page_info($url, $photo, $keywords, $keyword_blacklist);
 
        $tags = "";
+       $taglist = [];
        if (isset($data["keywords"]) && count($data["keywords"])) {
                foreach ($data["keywords"] as $keyword) {
                        $hashtag = str_replace([" ", "+", "/", ".", "#", "'"],
@@ -156,10 +157,15 @@ function add_page_keywords($url, $photo = "", $keywords = false, $keyword_blackl
                        }
 
                        $tags .= "#[url=" . DI::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]";
+                       $taglist[] = $hashtag;
                }
        }
 
-       return $tags;
+       if ($return_array) {
+               return $taglist;
+       } else {
+               return $tags;
+       }
 }
 
 function add_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "")
index 89cff653684bf711fcbf646543254618e2ea64b0..a29414e941628f7c812eacf5309bd54dfc177b59 100644 (file)
@@ -170,16 +170,12 @@ class Processor
         */
        public static function updateItem($activity)
        {
-               $item = Item::selectFirst(['uri', 'uri-id', 'guid', 'thr-parent', 'gravity'], ['uri' => $activity['id']]);
+               $item = Item::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity'], ['uri' => $activity['id']]);
                if (!DBA::isResult($item)) {
                        Logger::warning('Unknown item', ['uri' => $activity['id']]);
                        return;
                }
 
-               if (empty($item['uri-id'])) {
-                       $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
-               }
-
                $item['changed'] = DateTimeFormat::utcNow();
                $item['edited'] = DateTimeFormat::utc($activity['updated']);
 
index 397edf3b41b4817f288dd1504db41526636ba9e7..0ce4144387027e22b5a5f8b39c3ade123fcad413 100644 (file)
@@ -29,6 +29,7 @@ use Friendica\Core\Protocol;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Item;
+use Friendica\Model\Term;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
 use Friendica\Util\XML;
@@ -385,6 +386,7 @@ class Feed {
                        }
 
                        $tags = '';
+                       $taglist = [];
                        $categories = $xpath->query("category", $entry);
                        foreach ($categories AS $category) {
                                $hashtag = $category->nodeValue;
@@ -394,6 +396,7 @@ class Feed {
 
                                $taglink = "#[url=" . DI::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]";
                                $tags .= $taglink;
+                               $taglist[] = $hashtag;
                        }
 
                        $body = trim(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry));
@@ -475,6 +478,7 @@ class Feed {
                                $item["title"] = "";
                                $item["body"] = $item["body"] . add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
                                $item["tag"] = add_page_keywords($item["plink"], $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
+                               $taglist = add_page_keywords($item["plink"], $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"], true);
                                $item["object-type"] = Activity\ObjectType::BOOKMARK;
                                unset($item["attach"]);
                        } else {
@@ -488,8 +492,11 @@ class Feed {
                                        } else {
                                                // @todo $preview is never set in this case, is it intended? - @MrPetovan 2018-02-13
                                                $item["tag"] = add_page_keywords($item["plink"], $preview, true, $contact["ffi_keyword_blacklist"]);
+                                               $taglist = add_page_keywords($item["plink"], $preview, true, $contact["ffi_keyword_blacklist"], true);
                                        }
                                        $item["body"] .= "\n" . $item['tag'];
+                               } else {
+                                       $taglist = [];
                                }
 
                                // Add the link to the original feed entry if not present in feed
@@ -516,10 +523,20 @@ class Feed {
                                        // Set the delivery priority for "remote self" to "medium"
                                        $notify = PRIORITY_MEDIUM;
                                }
-
+       
                                $id = Item::insert($item, false, $notify);
 
                                Logger::info("Feed for contact " . $contact["url"] . " stored under id " . $id);
+
+                               if (!empty($id) && !empty($taglist)) {
+                                       $feeditem = Item::selectFirst(['uri-id'], ['id' => $id]);
+                                       foreach ($taglist as $tag) {
+                                               $fields = ['uri-id' => $feeditem['uri-id'], 'name' => substr($tag, 0, 64), 'type' => Term::HASHTAG];
+                                               DBA::insert('tag', $fields, true);
+               
+                                               Logger::info('Stored tag', ['uri-id' => $feeditem['uri-id'], 'tag' => $tag, 'fields' => $fields]);
+                                       }                                       
+                               }
                        }
                }