From: Michael Date: Wed, 15 Apr 2020 05:10:40 +0000 (+0000) Subject: The new tag table should work for feeds no as well X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9a0d2c9e0c9879a221559564ee99c5aaff929329;p=friendica.git The new tag table should work for feeds no as well --- diff --git a/include/items.php b/include/items.php index 4c7551e5c4..6068be4b94 100644 --- a/include/items.php +++ b/include/items.php @@ -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 = "") diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 89cff65368..a29414e941 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -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']); diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 397edf3b41..0ce4144387 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -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]); + } + } } }