The new tag table should work for feeds no as well

This commit is contained in:
Michael 2020-04-15 05:10:40 +00:00
parent 010491e0b0
commit 9a0d2c9e0c
3 changed files with 27 additions and 8 deletions

View File

@ -141,11 +141,12 @@ function query_page_info($url, $photo = "", $keywords = false, $keyword_blacklis
return $data; 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); $data = query_page_info($url, $photo, $keywords, $keyword_blacklist);
$tags = ""; $tags = "";
$taglist = [];
if (isset($data["keywords"]) && count($data["keywords"])) { if (isset($data["keywords"]) && count($data["keywords"])) {
foreach ($data["keywords"] as $keyword) { foreach ($data["keywords"] as $keyword) {
$hashtag = str_replace([" ", "+", "/", ".", "#", "'"], $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]"; $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 = "") function add_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "")

View File

@ -170,16 +170,12 @@ class Processor
*/ */
public static function updateItem($activity) 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)) { if (!DBA::isResult($item)) {
Logger::warning('Unknown item', ['uri' => $activity['id']]); Logger::warning('Unknown item', ['uri' => $activity['id']]);
return; return;
} }
if (empty($item['uri-id'])) {
$item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
}
$item['changed'] = DateTimeFormat::utcNow(); $item['changed'] = DateTimeFormat::utcNow();
$item['edited'] = DateTimeFormat::utc($activity['updated']); $item['edited'] = DateTimeFormat::utc($activity['updated']);

View File

@ -29,6 +29,7 @@ use Friendica\Core\Protocol;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Term;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -385,6 +386,7 @@ class Feed {
} }
$tags = ''; $tags = '';
$taglist = [];
$categories = $xpath->query("category", $entry); $categories = $xpath->query("category", $entry);
foreach ($categories AS $category) { foreach ($categories AS $category) {
$hashtag = $category->nodeValue; $hashtag = $category->nodeValue;
@ -394,6 +396,7 @@ class Feed {
$taglink = "#[url=" . DI::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]"; $taglink = "#[url=" . DI::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]";
$tags .= $taglink; $tags .= $taglink;
$taglist[] = $hashtag;
} }
$body = trim(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry)); $body = trim(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry));
@ -475,6 +478,7 @@ class Feed {
$item["title"] = ""; $item["title"] = "";
$item["body"] = $item["body"] . add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]); $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"]); $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; $item["object-type"] = Activity\ObjectType::BOOKMARK;
unset($item["attach"]); unset($item["attach"]);
} else { } else {
@ -488,8 +492,11 @@ class Feed {
} else { } else {
// @todo $preview is never set in this case, is it intended? - @MrPetovan 2018-02-13 // @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"]); $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']; $item["body"] .= "\n" . $item['tag'];
} else {
$taglist = [];
} }
// Add the link to the original feed entry if not present in feed // 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" // Set the delivery priority for "remote self" to "medium"
$notify = PRIORITY_MEDIUM; $notify = PRIORITY_MEDIUM;
} }
$id = Item::insert($item, false, $notify); $id = Item::insert($item, false, $notify);
Logger::info("Feed for contact " . $contact["url"] . " stored under id " . $id); 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]);
}
}
} }
} }