The new tag table should work for feeds no as well
This commit is contained in:
parent
010491e0b0
commit
9a0d2c9e0c
3 changed files with 27 additions and 8 deletions
|
@ -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 = "")
|
||||
|
|
|
@ -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']);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -520,6 +527,16 @@ class Feed {
|
|||
$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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue