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([" ", "+", "/", ".", "#", "'"],
}
$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 = "")
*/
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']);
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;
}
$tags = '';
+ $taglist = [];
$categories = $xpath->query("category", $entry);
foreach ($categories AS $category) {
$hashtag = $category->nodeValue;
$taglink = "#[url=" . DI::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]";
$tags .= $taglink;
+ $taglist[] = $hashtag;
}
$body = trim(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry));
$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 {
} 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
// 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]);
+ }
+ }
}
}