Logger::log('API: api_statuses_repeat: '.$id);
- $fields = ['uri-id', 'body', 'title', 'attach', 'tag', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
+ $fields = ['uri-id', 'body', 'title', 'attach', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
$item = Item::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
if (DBA::isResult($item) && $item['body'] != "") {
$post .= "[/share]";
}
$_REQUEST['body'] = $post;
- $_REQUEST['tag'] = $item['tag'];
$_REQUEST['attach'] = $item['attach'];
$_REQUEST['profile_uid'] = api_user();
$_REQUEST['api_source'] = true;
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
function check_item_notification($itemid, $uid, $notification_type) {
- $fields = ['id', 'mention', 'tag', 'parent', 'title', 'body',
+ $fields = ['id', 'mention', 'parent', 'title', 'body',
'author-link', 'author-name', 'author-avatar', 'author-id',
'guid', 'parent-uri', 'uri', 'contact-id', 'network'];
$condition = ['id' => $itemid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'deleted' => false];
return $data;
}
-function add_page_keywords($url, $photo = "", $keywords = false, $keyword_blacklist = "")
-{
- $data = query_page_info($url, $photo, $keywords, $keyword_blacklist);
- if (empty($data["keywords"]) || !is_array($data["keywords"])) {
- return '';
- }
-
- $tags = "";
- foreach ($data["keywords"] as $keyword) {
- $hashtag = str_replace([" ", "+", "/", ".", "#", "'"],
- ["", "", "", "", "", ""], $keyword);
-
- if ($tags != "") {
- $tags .= ", ";
- }
-
- $tags .= "#[url=" . DI::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]";
- }
-
- return $tags;
-}
-
function get_page_keywords($url, $photo = "", $keywords = false, $keyword_blacklist = "")
{
$data = query_page_info($url, $photo, $keywords, $keyword_blacklist);
}
// Look for any tags and linkify them
- $str_tags = '';
$inform = '';
$tags = BBCode::getTags($body);
continue;
}
- $success = handle_tag($body, $inform, $str_tags, local_user() ? local_user() : $profile_uid, $tag, $network);
+ $success = handle_tag($body, $inform, local_user() ? local_user() : $profile_uid, $tag, $network);
if ($success['replaced']) {
$tagged[] = $tag;
}
$datarray['app'] = $app;
$datarray['location'] = $location;
$datarray['coord'] = $coord;
- $datarray['tag'] = $str_tags;
$datarray['file'] = $categories;
$datarray['inform'] = $inform;
$datarray['verb'] = $verb;
$fields = [
'title' => $datarray['title'],
'body' => $datarray['body'],
- 'tag' => $datarray['tag'],
'attach' => $datarray['attach'],
'file' => $datarray['file'],
'rendered-html' => $datarray['rendered-html'],
* @param App $a
* @param string $body the text to replace the tag in
* @param string $inform a comma-seperated string containing everybody to inform
- * @param string $str_tags string to add the tag to
* @param integer $profile_uid
* @param string $tag the tag to replace
* @param string $network The network of the post
* @throws ImagickException
* @throws HTTPException\InternalServerErrorException
*/
-function handle_tag(&$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "")
+function handle_tag(&$body, &$inform, $profile_uid, $tag, $network = "")
{
$replaced = false;
- $r = null;
//is it a person tag?
if (Tag::isType($tag, Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION)) {
$tag_type = substr($tag, 0, 1);
//is it already replaced?
if (strpos($tag, '[url=')) {
- //append tag to str_tags
- if (!stristr($str_tags, $tag)) {
- if (strlen($str_tags)) {
- $str_tags .= ',';
- }
- $str_tags .= $tag;
- }
-
// Checking for the alias that is used for OStatus
$pattern = "/[@!]\[url\=(.*?)\](.*?)\[\/url\]/ism";
if (preg_match($pattern, $tag, $matches)) {
if ($data["alias"] != "") {
$newtag = '@[url=' . $data["alias"] . ']' . $data["nick"] . '[/url]';
-
- if (!stripos($str_tags, '[url=' . $data["alias"] . ']')) {
- if (strlen($str_tags)) {
- $str_tags .= ',';
- }
-
- $str_tags .= $newtag;
- }
}
}
}
$profile = $contact["url"];
- $alias = $contact["alias"];
$newname = ($contact["name"] ?? '') ?: $contact["nick"];
}
$profile = str_replace(',', '%2c', $profile);
$newtag = $tag_type.'[url=' . $profile . ']' . $newname . '[/url]';
$body = str_replace($tag_type . $name, $newtag, $body);
- // append tag to str_tags
- if (!stristr($str_tags, $newtag)) {
- if (strlen($str_tags)) {
- $str_tags .= ',';
- }
- $str_tags .= $newtag;
- }
-
- /*
- * Status.Net seems to require the numeric ID URL in a mention if the person isn't
- * subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
- */
- if (!empty($alias)) {
- $newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
- if (!stripos($str_tags, '[url=' . $alias . ']')) {
- if (strlen($str_tags)) {
- $str_tags .= ',';
- }
- $str_tags .= $newtag;
- }
- }
}
}
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Tag;
-use Friendica\Model\Term;
use Friendica\Protocol\Activity;
use Friendica\Util\Strings;
use Friendica\Util\XML;
Item::update(['visible' => true], ['id' => $item['id']]);
}
- $term_objtype = ($item['resource-id'] ? Term::OBJECT_TYPE_PHOTO : Term::OBJECT_TYPE_POST);
-
Tag::store($item['uri-id'], Tag::HASHTAG, $term);
- $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
- intval($item['id']),
- DBA::escape($term)
- );
-
- if (!$blocktags && $t[0]['tcount'] == 0) {
- q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
- intval($item['id']),
- $term_objtype,
- Tag::HASHTAG,
- DBA::escape($term),
- '',
- intval($owner_uid)
- );
- }
-
- // if the original post is on this site, update it.
- $original_item = Item::selectFirst(['tag', 'id', 'uid'], ['origin' => true, 'uri' => $item['uri']]);
- if (DBA::isResult($original_item)) {
- $x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
- intval($original_item['uid'])
- );
- $t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
- intval($original_item['id']),
- DBA::escape($term)
- );
-
- if (DBA::isResult($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
- q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
- intval($original_item['id']),
- $term_objtype,
- Tag::HASHTAG,
- DBA::escape($term),
- '',
- intval($owner_uid)
- );
- }
- }
-
-
$arr['id'] = $post_id;
Hook::callAll('post_local_end', $arr);
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Tag;
-use Friendica\Model\Term;
use Friendica\Util\Strings;
function tagrm_post(App $a)
* @param $tags array
* @throws Exception
*/
-function update_tags($item_id, $tags){
- if (empty($item_id) || empty($tags)){
+function update_tags($item_id, $tags)
+{
+ if (empty($item_id) || empty($tags)) {
return;
}
- $item = Item::selectFirst(['tag', 'uri-id'], ['id' => $item_id, 'uid' => local_user()]);
+ $item = Item::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => local_user()]);
if (!DBA::isResult($item)) {
return;
}
- $old_tags = explode(',', $item['tag']);
-
foreach ($tags as $new_tag) {
if (preg_match_all('/([#@!])\[url\=([^\[\]]*)\]([^\[\]]*)\[\/url\]/ism', $new_tag, $results, PREG_SET_ORDER)) {
foreach ($results as $tag) {
Tag::removeByHash($item['uri-id'], $tag[1], $tag[3], $tag[2]);
}
}
-
- foreach ($old_tags as $index => $old_tag) {
- if (strcmp($old_tag, $new_tag) == 0) {
- unset($old_tags[$index]);
- break;
- }
- }
}
-
- $tag_str = implode(',', $old_tags);
- Term::insertFromTagFieldByItemId($item_id, $tag_str);
}
function tagrm_content(App $a)
const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid',
'parent-guid', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
'private', 'title', 'body', 'location', 'coord', 'app',
- 'attach', 'tag', 'deleted', 'extid', 'post-type',
+ 'attach', 'deleted', 'extid', 'post-type',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'author-id', 'author-link', 'owner-link', 'contact-uid',
'signed_text', 'signature', 'signer', 'network'];
'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id',
'contact-id', 'type', 'wall', 'gravity', 'extid', 'icid', 'iaid', 'psid',
'created', 'edited', 'commented', 'received', 'changed', 'verb',
- 'postopts', 'plink', 'resource-id', 'event-id', 'tag', 'attach', 'inform',
+ 'postopts', 'plink', 'resource-id', 'event-id', 'attach', 'inform',
'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type',
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network',
}
if (!array_key_exists('verb', $row) || in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) {
- // Build the tag string out of the term entries
- if (array_key_exists('tag', $row) && empty($row['tag'])) {
- $row['tag'] = Term::tagTextFromItemId($row['internal-iid']);
- }
-
// Build the file string out of the term entries
if (array_key_exists('file', $row) && empty($row['file'])) {
$row['file'] = Term::fileTextFromItemId($row['internal-iid']);
'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id',
'contact-id', 'owner-id', 'author-id', 'type', 'wall', 'gravity', 'extid',
'created', 'edited', 'commented', 'received', 'changed', 'psid',
- 'resource-id', 'event-id', 'tag', 'attach', 'post-type', 'file',
+ 'resource-id', 'event-id', 'attach', 'post-type', 'file',
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global',
'id' => 'item_id', 'network', 'icid', 'iaid', 'id' => 'internal-iid',
// We cannot simply expand the condition to check for origin entries
// The condition needn't to be a simple array but could be a complex condition.
// And we have to execute this query before the update to ensure to fetch the same data.
- $items = DBA::select('item', ['id', 'origin', 'uri', 'uri-id', 'iaid', 'icid', 'tag', 'file'], $condition);
+ $items = DBA::select('item', ['id', 'origin', 'uri', 'uri-id', 'iaid', 'icid', 'file'], $condition);
$content_fields = [];
foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) {
}
}
- if (array_key_exists('tag', $fields)) {
- $tags = $fields['tag'];
- $fields['tag'] = null;
- } else {
- $tags = null;
- }
-
if (array_key_exists('file', $fields)) {
$files = $fields['file'];
$fields['file'] = null;
}
}
- if (!is_null($tags)) {
- Term::insertFromTagFieldByItemId($item['id'], $tags);
- if (!empty($item['tag'])) {
- DBA::update('item', ['tag' => ''], ['id' => $item['id']]);
- }
- }
-
if (!is_null($files)) {
Term::insertFromFileFieldByItemId($item['id'], $files);
if (!empty($item['file'])) {
}
}
- // Delete tags that had been attached to other items
- self::deleteTagsFromItem($item);
-
// Delete notifications
DBA::delete('notify', ['iid' => $item['id'], 'uid' => $item['uid']]);
$item_fields = ['deleted' => true, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
DBA::update('item', $item_fields, ['id' => $item['id']]);
- Term::insertFromTagFieldByItemId($item['id'], '');
Term::insertFromFileFieldByItemId($item['id'], '');
self::deleteThread($item['id'], $item['parent-uri']);
return true;
}
- private static function deleteTagsFromItem($item)
- {
- if (($item["verb"] != Activity::TAG) || ($item["object-type"] != Activity\ObjectType::TAGTERM)) {
- return;
- }
-
- $xo = XML::parseString($item["object"]);
- $xt = XML::parseString($item["target"]);
-
- if ($xt->type != Activity\ObjectType::NOTE) {
- return;
- }
-
- $i = self::selectFirst(['id', 'contact-id', 'tag'], ['uri' => $xt->id, 'uid' => $item['uid']]);
- if (!DBA::isResult($i)) {
- return;
- }
-
- // For tags, the owner cannot remove the tag on the author's copy of the post.
- $owner_remove = ($item["contact-id"] == $i["contact-id"]);
- $author_copy = $item["origin"];
-
- if (($owner_remove && $author_copy) || !$owner_remove) {
- return;
- }
-
- $tags = explode(',', $i["tag"]);
- $newtags = [];
- if (count($tags)) {
- foreach ($tags as $tag) {
- if (trim($tag) !== trim($xo->body)) {
- $newtags[] = trim($tag);
- }
- }
- }
- self::update(['tag' => implode(',', $newtags)], ['id' => $i["id"]]);
- }
private static function guid($item, $notify)
{
$item['deny_gid'] = trim($item['deny_gid'] ?? '');
$item['private'] = intval($item['private'] ?? self::PUBLIC);
$item['body'] = trim($item['body'] ?? '');
- $item['tag'] = trim($item['tag'] ?? '');
$item['attach'] = trim($item['attach'] ?? '');
$item['app'] = trim($item['app'] ?? '');
$item['origin'] = intval($item['origin'] ?? 0);
Logger::log('' . print_r($item,true), Logger::DATA);
- if (array_key_exists('tag', $item)) {
- $tags = $item['tag'];
- unset($item['tag']);
- } else {
- $tags = '';
- }
-
if (array_key_exists('file', $item)) {
$files = $item['file'];
unset($item['file']);
* Due to deadlock issues with the "term" table we are doing these steps after the commit.
* This is not perfect - but a workable solution until we found the reason for the problem.
*/
- if (!empty($tags)) {
- Term::insertFromTagFieldByItemId($current_post, $tags);
- }
-
if (!empty($files)) {
Term::insertFromFileFieldByItemId($current_post, $files);
}
if (DI::config()->get('system', 'local_tags')) {
$item["body"] = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
"#[url=".DI::baseUrl()."/search?tag=$2]$2[/url]", $item["body"]);
-
- $item["tag"] = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
- "#[url=".DI::baseUrl()."/search?tag=$2]$2[/url]", $item["tag"]);
}
// mask hashtags inside of url, bookmarks and attachments to avoid urls in urls
$newtag = '#[url=' . DI::baseUrl() . '/search?tag=' . $basetag . ']' . $basetag . '[/url]';
$item["body"] = str_replace($tag, $newtag, $item["body"]);
-
- if (!stristr($item["tag"], "/search?tag=" . $basetag . "]" . $basetag . "[/url]")) {
- if (strlen($item["tag"])) {
- $item["tag"] = ',' . $item["tag"];
- }
- $item["tag"] = $newtag . $item["tag"];
- }
}
// Convert back the masked hashtags
return $recipients;
}
- public static function getFeedTags($item)
- {
- $ret = [];
- $matches = false;
- $cnt = preg_match_all('|\#\[url\=(.*?)\](.*?)\[\/url\]|', $item['tag'], $matches);
- if ($cnt) {
- for ($x = 0; $x < $cnt; $x ++) {
- if ($matches[1][$x]) {
- $ret[$matches[2][$x]] = ['#', $matches[1][$x], $matches[2][$x]];
- }
- }
- }
- $matches = false;
- $cnt = preg_match_all('|\@\[url\=(.*?)\](.*?)\[\/url\]|', $item['tag'], $matches);
- if ($cnt) {
- for ($x = 0; $x < $cnt; $x ++) {
- if ($matches[1][$x]) {
- $ret[] = ['@', $matches[1][$x], $matches[2][$x]];
- }
- }
- }
- return $ret;
- }
-
public static function expire($uid, $days, $network = "", $force = false)
{
if (!$uid || ($days < 1)) {
const UNKNOWN = 0;
const HASHTAG = 1;
const MENTION = 2;
- const CATEGORY = 3;
- const FILE = 5;
/**
* An implicit mention is a mention in a comment body that is redundant with the threading information.
*/
namespace Friendica\Model;
-use Friendica\Core\Logger;
use Friendica\Database\DBA;
-use Friendica\DI;
-use Friendica\Util\Strings;
/**
* Class Term
class Term
{
const UNKNOWN = 0;
- const HASHTAG = 1;
- const MENTION = 2;
const CATEGORY = 3;
const FILE = 5;
- /**
- * An implicit mention is a mention in a comment body that is redundant with the threading information.
- */
- const IMPLICIT_MENTION = 8;
- /**
- * An exclusive mention transfers the ownership of the post to the target account, usually a forum.
- */
- const EXCLUSIVE_MENTION = 9;
-
- const TAG_CHARACTER = [
- self::HASHTAG => '#',
- self::MENTION => '@',
- self::IMPLICIT_MENTION => '%',
- self::EXCLUSIVE_MENTION => '!',
- ];
const OBJECT_TYPE_POST = 1;
- const OBJECT_TYPE_PHOTO = 2;
-
- /**
- * Generates the legacy item.tag field comma-separated BBCode string from an item ID.
- * Includes only hashtags, implicit and explicit mentions.
- *
- * @param int $item_id
- * @return string
- * @throws \Exception
- */
- public static function tagTextFromItemId($item_id)
- {
- $tag_list = [];
- $tags = self::getByItemId($item_id, [self::HASHTAG, self::MENTION, self::IMPLICIT_MENTION]);
- foreach ($tags as $tag) {
- $tag_list[] = self::TAG_CHARACTER[$tag['type']] . '[url=' . $tag['url'] . ']' . $tag['term'] . '[/url]';
- }
-
- return implode(',', $tag_list);
- }
-
- /**
- * Retrieves the terms from the provided type(s) associated with the provided item ID.
- *
- * @param int $item_id
- * @param int|array $type
- * @return array
- * @throws \Exception
- */
- private static function getByItemId($item_id, $type = [self::HASHTAG, self::MENTION])
- {
- $condition = ['otype' => self::OBJECT_TYPE_POST, 'oid' => $item_id, 'type' => $type];
- $tags = DBA::select('term', ['type', 'term', 'url'], $condition);
- if (!DBA::isResult($tags)) {
- return [];
- }
-
- return DBA::toArray($tags);
- }
/**
* Generates the legacy item.file field string from an item ID.
public static function fileTextFromItemId($item_id)
{
$file_text = '';
- $tags = self::getByItemId($item_id, [self::FILE, self::CATEGORY]);
+
+ $condition = ['otype' => self::OBJECT_TYPE_POST, 'oid' => $item_id, 'type' => [self::FILE, self::CATEGORY]];
+ $tags = DBA::selectToArray('term', ['type', 'term', 'url'], $condition);
foreach ($tags as $tag) {
if ($tag['type'] == self::CATEGORY) {
$file_text .= '<' . $tag['term'] . '>';
return $file_text;
}
- /**
- * Inserts new terms for the provided item ID based on the legacy item.tag field BBCode content.
- * Deletes all previous tag terms for the same item ID.
- * Sets both the item.mention and thread.mentions field flags if a mention concerning the item UID is found.
- *
- * @param int $item_id
- * @param string $tag_str
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
- public static function insertFromTagFieldByItemId($item_id, $tag_str)
- {
- $profile_base = DI::baseUrl();
- $profile_data = parse_url($profile_base);
- $profile_path = $profile_data['path'] ?? '';
- $profile_base_friendica = $profile_data['host'] . $profile_path . '/profile/';
- $profile_base_diaspora = $profile_data['host'] . $profile_path . '/u/';
-
- $fields = ['guid', 'uid', 'id', 'edited', 'deleted', 'created', 'received', 'title', 'body', 'parent'];
- $item = Item::selectFirst($fields, ['id' => $item_id]);
- if (!DBA::isResult($item)) {
- return;
- }
-
- $item['tag'] = $tag_str;
-
- // Clean up all tags
- self::deleteByItemId($item_id);
-
- if ($item['deleted']) {
- return;
- }
-
- $taglist = explode(',', $item['tag']);
-
- $tags_string = '';
- foreach ($taglist as $tag) {
- if (Strings::startsWith($tag, self::TAG_CHARACTER)) {
- $tags_string .= ' ' . trim($tag);
- } else {
- $tags_string .= ' #' . trim($tag);
- }
- }
-
- $data = ' ' . $item['title'] . ' ' . $item['body'] . ' ' . $tags_string . ' ';
-
- // ignore anything in a code block
- $data = preg_replace('/\[code\](.*?)\[\/code\]/sm', '', $data);
-
- $tags = [];
-
- $pattern = '/\W\#([^\[].*?)[\s\'".,:;\?!\[\]\/]/ism';
- if (preg_match_all($pattern, $data, $matches)) {
- foreach ($matches[1] as $match) {
- $tags['#' . $match] = '';
- }
- }
-
- $pattern = '/\W([\#@!%])\[url\=(.*?)\](.*?)\[\/url\]/ism';
- if (preg_match_all($pattern, $data, $matches, PREG_SET_ORDER)) {
- foreach ($matches as $match) {
-
- if (in_array($match[1], [
- self::TAG_CHARACTER[self::MENTION],
- self::TAG_CHARACTER[self::IMPLICIT_MENTION],
- self::TAG_CHARACTER[self::EXCLUSIVE_MENTION]
- ])) {
- $contact = Contact::getDetailsByURL($match[2], 0);
- if (!empty($contact['addr'])) {
- $match[3] = $contact['addr'];
- }
-
- if (!empty($contact['url'])) {
- $match[2] = $contact['url'];
- }
- }
-
- $tags[$match[2]] = $match[1] . trim($match[3], ',.:;[]/\"?!');
- }
- }
-
- foreach ($tags as $link => $tag) {
- if (Tag::isType($tag, self::HASHTAG)) {
- // try to ignore #039 or #1 or anything like that
- if (ctype_digit(substr(trim($tag), 1))) {
- continue;
- }
-
- // try to ignore html hex escapes, e.g. #x2317
- if ((substr(trim($tag), 1, 1) == 'x' || substr(trim($tag), 1, 1) == 'X') && ctype_digit(substr(trim($tag), 2))) {
- continue;
- }
-
- $type = self::HASHTAG;
- $term = substr($tag, 1);
- $link = '';
- } elseif (Tag::isType($tag, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION)) {
- if (Tag::isType($tag, self::MENTION, self::EXCLUSIVE_MENTION)) {
- $type = self::MENTION;
- } else {
- $type = self::IMPLICIT_MENTION;
- }
-
- $contact = Contact::getDetailsByURL($link, 0);
- if (!empty($contact['name'])) {
- $term = $contact['name'];
- } else {
- $term = substr($tag, 1);
- }
- } else { // This shouldn't happen
- $type = self::HASHTAG;
- $term = $tag;
- $link = '';
-
- Logger::notice('Unknown term type', ['tag' => $tag]);
- }
-
- if (DBA::exists('term', ['uid' => $item['uid'], 'otype' => self::OBJECT_TYPE_POST, 'oid' => $item_id, 'term' => $term, 'type' => $type])) {
- continue;
- }
-
- if (empty($term)) {
- continue;
- }
-
- if ($item['uid'] == 0) {
- $global = true;
- DBA::update('term', ['global' => true], ['otype' => self::OBJECT_TYPE_POST, 'guid' => $item['guid']]);
- } else {
- $global = DBA::exists('term', ['uid' => 0, 'otype' => self::OBJECT_TYPE_POST, 'guid' => $item['guid']]);
- }
-
- DBA::insert('term', [
- 'uid' => $item['uid'],
- 'oid' => $item_id,
- 'otype' => self::OBJECT_TYPE_POST,
- 'type' => $type,
- 'term' => substr($term, 0, 255),
- 'url' => $link,
- 'guid' => $item['guid'],
- 'created' => $item['created'],
- 'received' => $item['received'],
- 'global' => $global
- ]);
-
- // Search for mentions
- if (Tag::isType($tag, self::MENTION, self::EXCLUSIVE_MENTION)
- && (
- strpos($link, $profile_base_friendica) !== false
- || strpos($link, $profile_base_diaspora) !== false
- )
- ) {
- $users_stmt = DBA::p("SELECT `uid` FROM `contact` WHERE self AND (`url` = ? OR `nurl` = ?)", $link, $link);
- $users = DBA::toArray($users_stmt);
- foreach ($users AS $user) {
- if ($user['uid'] == $item['uid']) {
- /// @todo This function is called from Item::update - so we mustn't call that function here
- DBA::update('item', ['mention' => true], ['id' => $item_id]);
- DBA::update('thread', ['mention' => true], ['iid' => $item['parent']]);
- }
- }
- }
- }
- }
-
/**
* Inserts new terms for the provided item ID based on the legacy item.file field BBCode content.
* Deletes all previous file terms for the same item ID.
}
}
}
-
- /**
- * Delete tags of the specific type(s) from an item
- *
- * @param int $item_id
- * @param int|array $type
- * @throws \Exception
- */
- public static function deleteByItemId($item_id, $type = [self::HASHTAG, self::MENTION, self::IMPLICIT_MENTION])
- {
- if (empty($item_id)) {
- return;
- }
-
- // Clean up all tags
- DBA::delete('term', ['otype' => self::OBJECT_TYPE_POST, 'oid' => $item_id, 'type' => $type]);
- }
}
*/
private static function checkImplicitMention(array $item, array $profiles)
{
- foreach ($profiles AS $profile) {
- if (strpos($item['tag'], '=' . $profile.']') || strpos($item['body'], '=' . $profile . ']')) {
- if (strpos($item['body'], $profile) === false) {
+ $mentions = Tag::getByURIId($item['uri-id'], [Tag::IMPLICIT_MENTION]);
+ foreach ($mentions as $mention) {
+ foreach ($profiles as $profile) {
+ if (Strings::compareLink($profile, $mention['url'])) {
return true;
}
}
*/
private static function checkExplicitMention(array $item, array $profiles)
{
- foreach ($profiles AS $profile) {
- if (strpos($item['tag'], '=' . $profile.']') || strpos($item['body'], '=' . $profile . ']')) {
- if (!(strpos($item['body'], $profile) === false)) {
+ $mentions = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::EXCLUSIVE_MENTION]);
+ foreach ($mentions as $mention) {
+ foreach ($profiles as $profile) {
+ if (Strings::compareLink($profile, $mention['url'])) {
return true;
}
}
$entry->appendChild($actarg);
}
- $tags = Item::getFeedTags($item);
+ $tags = Tag::getByURIId($item['uri-id']);
- /// @TODO Combine this with similar below if() block?
if (count($tags)) {
- foreach ($tags as $t) {
- if (($type != 'html') || ($t[0] != "@")) {
- XML::addElement($doc, $entry, "category", "", ["scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2]]);
+ foreach ($tags as $tag) {
+ if (($type != 'html') || ($tag['type'] == Tag::HASHTAG)) {
+ XML::addElement($doc, $entry, "category", "", ["scheme" => "X-DFRN:" . Tag::TAG_CHARACTER[$tag['type']] . ":" . $tag['url'], "term" => $tag['name']]);
}
- }
- }
-
- if (count($tags)) {
- foreach ($tags as $t) {
- if ($t[0] == "@") {
- $mentioned[$t[1]] = $t[1];
+ if ($tag['type'] != Tag::HASHTAG) {
+ $mentioned[$tag['url']] = $tag['url'];
}
}
}
// extract tag, if not duplicate, add to parent item
if ($xo->content) {
Tag::store($item_tag['uri-id'], Tag::HASHTAG, $xo->content);
-
- if (!stristr($item_tag["tag"], trim($xo->content))) {
- $tag = $item_tag["tag"] . (strlen($item_tag["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]';
- Item::update(['tag' => $tag], ['id' => $item_tag["id"]]);
- }
}
}
}
if (($term != "") && ($scheme != "")) {
$parts = explode(":", $scheme);
if ((count($parts) >= 4) && (array_shift($parts) == "X-DFRN")) {
- $termhash = array_shift($parts);
$termurl = implode(":", $parts);
-
- if (!empty($item["tag"])) {
- $item["tag"] .= ",";
- } else {
- $item["tag"] = "";
- }
-
- $item["tag"] .= $termhash . "[url=" . $termurl . "]" . $term . "[/url]";
-
Tag::store($item['uri-id'], Tag::IMPLICIT_MENTION, $term, $termurl);
}
}
}
// Do we already have this item?
- $fields = ['body', 'title', 'attach', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
+ $fields = ['body', 'title', 'attach', 'app', 'created', 'object-type', 'uri', 'guid',
'author-name', 'author-link', 'author-avatar'];
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]];
$item = Item::selectFirst($fields, $condition);
}
if ($stored) {
- $fields = ['body', 'title', 'attach', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
+ $fields = ['body', 'title', 'attach', 'app', 'created', 'object-type', 'uri', 'guid',
'author-name', 'author-link', 'author-avatar'];
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]];
$item = Item::selectFirst($fields, $condition);
Tag::storeFromBody($datarray['uri-id'], $datarray["body"]);
- $datarray["tag"] = $original_item["tag"];
$datarray["attach"] = $original_item["attach"];
$datarray["app"] = $original_item["app"];
$item["attach"] .= '[attach]href="' . $href . '" length="' . $length . '" type="' . $type . '"[/attach]';
}
- $tags = '';
$taglist = [];
$categories = $xpath->query("category", $entry);
foreach ($categories AS $category) {
- $hashtag = $category->nodeValue;
- if ($tags != '') {
- $tags .= ', ';
- }
-
- $taglink = "#[url=" . DI::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]";
- $tags .= $taglink;
- $taglist[] = $hashtag;
+ $taglist[] = $category->nodeValue;
}
$body = trim(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry));
// We always strip the title since it will be added in the page information
$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 = get_page_keywords($item["plink"], $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
$item["object-type"] = Activity\ObjectType::BOOKMARK;
unset($item["attach"]);
}
if (!empty($contact["fetch_further_information"]) && ($contact["fetch_further_information"] == 3)) {
- if (!empty($tags)) {
- $item["tag"] = $tags;
- } 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"]);
+ if (empty($taglist)) {
$taglist = get_page_keywords($item["plink"], $preview, true, $contact["ffi_keyword_blacklist"]);
}
- $item["body"] .= "\n" . $item['tag'];
+ /// @todo $item["body"] .= "\n" . $tags;
} else {
$taglist = [];
}
XML::addElement($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
}
- $tags = item::getFeedTags($item);
-
+ $tags = Tag::getByURIId($item['uri-id']);
if (count($tags)) {
- foreach ($tags as $t) {
- if ($t[0] == "@") {
- $mentioned[$t[1]] = $t[1];
- }
+ foreach ($tags as $tag) {
+ $mentioned[$tag['url']] = $tag['url'];
}
}
}
if (count($tags)) {
- foreach ($tags as $t) {
- if ($t[0] != "@") {
- XML::addElement($doc, $entry, "category", "", ["term" => $t[2]]);
+ foreach ($tags as $tag) {
+ if ($tag['type'] == Tag::HASHTAG) {
+ XML::addElement($doc, $entry, "category", "", ["term" => $tag['name']]);
}
}
}