1
1
Fork 0

Merge pull request #5305 from annando/item-tags

Tags aren't stored in the item table anymore
This commit is contained in:
Hypolite Petovan 2018-06-30 17:50:55 -04:00 committed by GitHub
commit 0c553150ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 146 additions and 54 deletions

View file

@ -987,7 +987,6 @@ CREATE TABLE IF NOT EXISTS `term` (
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
`received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
`global` boolean NOT NULL DEFAULT '0' COMMENT '', `global` boolean NOT NULL DEFAULT '0' COMMENT '',
`aid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
PRIMARY KEY(`tid`), PRIMARY KEY(`tid`),
INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`(32)), INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`(32)),

View file

@ -738,18 +738,13 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
// Only act if it is a "real" post // Only act if it is a "real" post
// We need the additional check for the "local_profile" because of mixed situations on connector networks // We need the additional check for the "local_profile" because of mixed situations on connector networks
$item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-id`, `guid`, $fields = ['id', 'mention', 'tag', 'parent', 'title', 'body',
`parent-uri`, `uri`, `contact-id`, `network` 'author-link', 'author-name', 'author-avatar', 'author-id',
FROM `item` WHERE `id` = %d AND `gravity` IN (%d, %d) AND 'guid', 'parent-uri', 'uri', 'contact-id', 'network'];
NOT (`author-id` IN ($contact_list)) LIMIT 1", $condition = ['id' => $itemid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
intval($itemid), intval(GRAVITY_PARENT), intval(GRAVITY_COMMENT)); $item = Item::selectFirst($fields, $condition);
if (!$item) if (!DBM::is_result($item) || in_array($item['author-id'], $contacts)) {
return false; return;
if ($item[0]['network'] != NETWORK_FEED) {
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['author-id']]);
} else {
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['contact-id']]);
} }
// Generate the notification array // Generate the notification array
@ -759,17 +754,17 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
$params["language"] = $user["language"]; $params["language"] = $user["language"];
$params["to_name"] = $user["username"]; $params["to_name"] = $user["username"];
$params["to_email"] = $user["email"]; $params["to_email"] = $user["email"];
$params["item"] = $item[0]; $params["item"] = $item;
$params["parent"] = $item[0]["parent"]; $params["parent"] = $item["parent"];
$params["link"] = System::baseUrl().'/display/'.urlencode($item[0]["guid"]); $params["link"] = System::baseUrl().'/display/'.urlencode($item["guid"]);
$params["otype"] = 'item'; $params["otype"] = 'item';
$params["source_name"] = $author["name"]; $params["source_name"] = $item["author-name"];
$params["source_link"] = $author["url"]; $params["source_link"] = $item["author-link"];
$params["source_photo"] = $author["thumb"]; $params["source_photo"] = $item["author-avatar"];
if ($item[0]["parent-uri"] === $item[0]["uri"]) { if ($item["parent-uri"] === $item["uri"]) {
// Send a notification for every new post? // Send a notification for every new post?
$send_notification = dba::exists('contact', ['id' => $item[0]['contact-id'], 'notify_new_posts' => true]); $send_notification = dba::exists('contact', ['id' => $item['contact-id'], 'notify_new_posts' => true]);
if (!$send_notification) { if (!$send_notification) {
$tags = q("SELECT `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` = %d AND `uid` = %d", $tags = q("SELECT `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` = %d AND `uid` = %d",
@ -796,11 +791,11 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
$tagged = false; $tagged = false;
foreach ($profiles AS $profile) { foreach ($profiles AS $profile) {
if (strpos($item[0]["tag"], "=".$profile."]") || strpos($item[0]["body"], "=".$profile."]")) if (strpos($item["tag"], "=".$profile."]") || strpos($item["body"], "=".$profile."]"))
$tagged = true; $tagged = true;
} }
if ($item[0]["mention"] || $tagged || ($defaulttype == NOTIFY_TAGSELF)) { if ($item["mention"] || $tagged || ($defaulttype == NOTIFY_TAGSELF)) {
$params["type"] = NOTIFY_TAGSELF; $params["type"] = NOTIFY_TAGSELF;
$params["verb"] = ACTIVITY_TAG; $params["verb"] = ACTIVITY_TAG;
} }
@ -810,7 +805,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
WHERE `thread`.`iid` = %d AND NOT `thread`.`ignored` AND WHERE `thread`.`iid` = %d AND NOT `thread`.`ignored` AND
(`thread`.`mention` OR `item`.`author-id` IN ($contact_list)) (`thread`.`mention` OR `item`.`author-id` IN ($contact_list))
LIMIT 1", LIMIT 1",
intval($item[0]["parent"])); intval($item["parent"]));
if ($parent && !isset($params["type"])) { if ($parent && !isset($params["type"])) {
$params["type"] = NOTIFY_COMMENT; $params["type"] = NOTIFY_COMMENT;

View file

@ -1716,7 +1716,6 @@ class DBStructure
"created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""], "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
"received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""], "received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
"global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"aid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
], ],
"indexes" => [ "indexes" => [

View file

@ -117,6 +117,17 @@ class Item extends BaseObject
} }
} }
// Build the tag string out of the term entries
if (isset($row['id']) && array_key_exists('tag', $row)) {
$row['tag'] = Term::tagTextFromItemId($row['id']);
}
/// @todo This is a preparation
// Build the file string out of the term entries
//if (isset($row['id']) && array_key_exists('file', $row)) {
// $row['file'] = Term::fileTextFromItemId($row['id']);
//}
// We can always comment on posts from these networks // We can always comment on posts from these networks
if (isset($row['writable']) && !empty($row['network']) && if (isset($row['writable']) && !empty($row['network']) &&
in_array($row['network'], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) { in_array($row['network'], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) {
@ -525,6 +536,17 @@ class Item extends BaseObject
*/ */
private static function constructSelectFields($fields, $selected) private static function constructSelectFields($fields, $selected)
{ {
// To be able to fetch the tags we need the item id
if (in_array('tag', $selected) && !in_array('id', $selected)) {
$selected[] = 'id';
}
/// @todo This is a preparation
// To be able to fetch the files we need the item id
//if (in_array('file', $selected) && !in_array('id', $selected)) {
// $selected[] = 'id';
//}
$selection = []; $selection = [];
foreach ($fields as $table => $table_fields) { foreach ($fields as $table => $table_fields) {
foreach ($table_fields as $field => $select) { foreach ($table_fields as $field => $select) {
@ -604,6 +626,21 @@ class Item extends BaseObject
} }
} }
if (array_key_exists('tag', $fields)) {
$tags = $fields['tag'];
unset($fields['tag']);
} else {
$tags = '';
}
if (array_key_exists('file', $fields)) {
$files = $fields['file'];
/// @todo This is a preparation
//unset($fields['file']);
} else {
$files = '';
}
if (!empty($fields)) { if (!empty($fields)) {
$success = dba::update('item', $fields, $condition); $success = dba::update('item', $fields, $condition);
@ -622,8 +659,15 @@ class Item extends BaseObject
$content_fields['plink'] = $item['plink']; $content_fields['plink'] = $item['plink'];
} }
self::updateContent($content_fields, ['uri' => $item['uri']]); self::updateContent($content_fields, ['uri' => $item['uri']]);
Term::insertFromTagFieldByItemId($item['id']);
Term::insertFromFileFieldByItemId($item['id']); if (!empty($tags)) {
Term::insertFromTagFieldByItemId($item['id'], $tags);
}
if (!empty($files)) {
Term::insertFromFileFieldByItemId($item['id'], $files);
}
self::updateThread($item['id']); self::updateThread($item['id']);
// We only need to notfiy others when it is an original entry from us. // We only need to notfiy others when it is an original entry from us.
@ -693,7 +737,7 @@ class Item extends BaseObject
$fields = ['id', 'uri', 'uid', 'parent', 'parent-uri', 'origin', $fields = ['id', 'uri', 'uid', 'parent', 'parent-uri', 'origin',
'deleted', 'file', 'resource-id', 'event-id', 'attach', 'deleted', 'file', 'resource-id', 'event-id', 'attach',
'verb', 'object-type', 'object', 'target', 'contact-id']; 'verb', 'object-type', 'object', 'target', 'contact-id'];
$item = dba::selectFirst('item', $fields, ['id' => $item_id]); $item = self::selectFirst($fields, ['id' => $item_id]);
if (!DBM::is_result($item)) { if (!DBM::is_result($item)) {
logger('Item with ID ' . $item_id . " hasn't been found.", LOGGER_DEBUG); logger('Item with ID ' . $item_id . " hasn't been found.", LOGGER_DEBUG);
return false; return false;
@ -704,7 +748,7 @@ class Item extends BaseObject
return false; return false;
} }
$parent = dba::selectFirst('item', ['origin'], ['id' => $item['parent']]); $parent = self::selectFirst(['origin'], ['id' => $item['parent']]);
if (!DBM::is_result($parent)) { if (!DBM::is_result($parent)) {
$parent = ['origin' => false]; $parent = ['origin' => false];
} }
@ -760,8 +804,8 @@ class Item extends BaseObject
'object' => '', 'target' => '', 'tag' => '', 'postopts' => '', 'attach' => '', 'file' => '']; 'object' => '', 'target' => '', 'tag' => '', 'postopts' => '', 'attach' => '', 'file' => ''];
dba::update('item', $item_fields, ['id' => $item['id']]); dba::update('item', $item_fields, ['id' => $item['id']]);
Term::insertFromTagFieldByItemId($item['id']); Term::insertFromTagFieldByItemId($item['id'], '');
Term::insertFromFileFieldByItemId($item['id']); Term::insertFromFileFieldByItemId($item['id'], '');
self::deleteThread($item['id'], $item['parent-uri']); self::deleteThread($item['id'], $item['parent-uri']);
if (!self::exists(["`uri` = ? AND `uid` != 0 AND NOT `deleted`", $item['uri']])) { if (!self::exists(["`uri` = ? AND `uid` != 0 AND NOT `deleted`", $item['uri']])) {
@ -784,7 +828,7 @@ class Item extends BaseObject
} elseif ($item['uid'] != 0) { } elseif ($item['uid'] != 0) {
// When we delete just our local user copy of an item, we have to set a marker to hide it // When we delete just our local user copy of an item, we have to set a marker to hide it
$global_item = dba::selectFirst('item', ['id'], ['uri' => $item['uri'], 'uid' => 0, 'deleted' => false]); $global_item = self::selectFirst(['id'], ['uri' => $item['uri'], 'uid' => 0, 'deleted' => false]);
if (DBM::is_result($global_item)) { if (DBM::is_result($global_item)) {
dba::update('user-item', ['hidden' => true], ['iid' => $global_item['id'], 'uid' => $item['uid']], true); dba::update('user-item', ['hidden' => true], ['iid' => $global_item['id'], 'uid' => $item['uid']], true);
} }
@ -808,7 +852,7 @@ class Item extends BaseObject
return; return;
} }
$i = dba::selectFirst('item', ['id', 'contact-id', 'tag'], ['uri' => $xt->id, 'uid' => $item['uid']]); $i = self::selectFirst(['id', 'contact-id', 'tag'], ['uri' => $xt->id, 'uid' => $item['uid']]);
if (!DBM::is_result($i)) { if (!DBM::is_result($i)) {
return; return;
} }
@ -1024,7 +1068,7 @@ class Item extends BaseObject
$condition = ["`uri` = ? AND `uid` = ? AND `network` IN (?, ?, ?)", $condition = ["`uri` = ? AND `uid` = ? AND `network` IN (?, ?, ?)",
trim($item['uri']), $item['uid'], trim($item['uri']), $item['uid'],
NETWORK_DIASPORA, NETWORK_DFRN, NETWORK_OSTATUS]; NETWORK_DIASPORA, NETWORK_DFRN, NETWORK_OSTATUS];
$existing = dba::selectFirst('item', ['id', 'network'], $condition); $existing = self::selectFirst(['id', 'network'], $condition);
if (DBM::is_result($existing)) { if (DBM::is_result($existing)) {
// We only log the entries with a different user id than 0. Otherwise we would have too many false positives // We only log the entries with a different user id than 0. Otherwise we would have too many false positives
if ($uid != 0) { if ($uid != 0) {
@ -1181,7 +1225,7 @@ class Item extends BaseObject
'wall', 'private', 'forum_mode', 'origin']; 'wall', 'private', 'forum_mode', 'origin'];
$condition = ['uri' => $item['parent-uri'], 'uid' => $item['uid']]; $condition = ['uri' => $item['parent-uri'], 'uid' => $item['uid']];
$params = ['order' => ['id' => false]]; $params = ['order' => ['id' => false]];
$parent = dba::selectFirst('item', $fields, $condition, $params); $parent = self::selectFirst($fields, $condition, $params);
if (DBM::is_result($parent)) { if (DBM::is_result($parent)) {
// is the new message multi-level threaded? // is the new message multi-level threaded?
@ -1195,7 +1239,7 @@ class Item extends BaseObject
'parent-uri' => $item['parent-uri'], 'parent-uri' => $item['parent-uri'],
'uid' => $item['uid']]; 'uid' => $item['uid']];
$params = ['order' => ['id' => false]]; $params = ['order' => ['id' => false]];
$toplevel_parent = dba::selectFirst('item', $fields, $condition, $params); $toplevel_parent = self::selectFirst($fields, $condition, $params);
if (DBM::is_result($toplevel_parent)) { if (DBM::is_result($toplevel_parent)) {
$parent = $toplevel_parent; $parent = $toplevel_parent;
@ -1340,6 +1384,21 @@ class Item extends BaseObject
logger('' . print_r($item,true), LOGGER_DATA); logger('' . 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'];
/// @todo This is a preparation
//unset($item['file']);
} else {
$files = '';
}
// We are doing this outside of the transaction to avoid timing problems // We are doing this outside of the transaction to avoid timing problems
self::insertContent($item); self::insertContent($item);
@ -1447,7 +1506,7 @@ class Item extends BaseObject
* in it. * in it.
*/ */
if (!$deleted && !$dontcache) { if (!$deleted && !$dontcache) {
$posted_item = dba::selectFirst('item', [], ['id' => $current_post]); $posted_item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $current_post]);
if (DBM::is_result($posted_item)) { if (DBM::is_result($posted_item)) {
if ($notify) { if ($notify) {
Addon::callHooks('post_local_end', $posted_item); Addon::callHooks('post_local_end', $posted_item);
@ -1471,8 +1530,13 @@ class Item extends BaseObject
* Due to deadlock issues with the "term" table we are doing these steps after the commit. * 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. * This is not perfect - but a workable solution until we found the reason for the problem.
*/ */
Term::insertFromTagFieldByItemId($current_post); if (!empty($tags)) {
Term::insertFromFileFieldByItemId($current_post); Term::insertFromTagFieldByItemId($current_post, $tags);
}
if (!empty($files)) {
Term::insertFromFileFieldByItemId($current_post, $files);
}
if ($item['parent-uri'] === $item['uri']) { if ($item['parent-uri'] === $item['uri']) {
self::addShadow($current_post); self::addShadow($current_post);
@ -1590,7 +1654,7 @@ class Item extends BaseObject
public static function distribute($itemid, $signed_text = '') public static function distribute($itemid, $signed_text = '')
{ {
$condition = ["`id` IN (SELECT `parent` FROM `item` WHERE `id` = ?)", $itemid]; $condition = ["`id` IN (SELECT `parent` FROM `item` WHERE `id` = ?)", $itemid];
$parent = dba::selectFirst('item', ['owner-id'], $condition); $parent = self::selectFirst(['owner-id'], $condition);
if (!DBM::is_result($parent)) { if (!DBM::is_result($parent)) {
return; return;
} }
@ -1623,7 +1687,7 @@ class Item extends BaseObject
$origin_uid = 0; $origin_uid = 0;
if ($item['uri'] != $item['parent-uri']) { if ($item['uri'] != $item['parent-uri']) {
$parents = dba::select('item', ['uid', 'origin'], ["`uri` = ? AND `uid` != 0", $item['parent-uri']]); $parents = self::select(['uid', 'origin'], ["`uri` = ? AND `uid` != 0", $item['parent-uri']]);
while ($parent = dba::fetch($parents)) { while ($parent = dba::fetch($parents)) {
$users[$parent['uid']] = $parent['uid']; $users[$parent['uid']] = $parent['uid'];
if ($parent['origin'] && !$item['origin']) { if ($parent['origin'] && !$item['origin']) {
@ -1704,7 +1768,7 @@ class Item extends BaseObject
{ {
$fields = ['uid', 'private', 'moderated', 'visible', 'deleted', 'network']; $fields = ['uid', 'private', 'moderated', 'visible', 'deleted', 'network'];
$condition = ['id' => $itemid, 'parent' => [0, $itemid]]; $condition = ['id' => $itemid, 'parent' => [0, $itemid]];
$item = dba::selectFirst('item', $fields, $condition); $item = self::selectFirst($fields, $condition);
if (!DBM::is_result($item)) { if (!DBM::is_result($item)) {
return; return;
@ -2010,7 +2074,7 @@ class Item extends BaseObject
public static function getGuidById($id) public static function getGuidById($id)
{ {
$item = dba::selectFirst('item', ['guid'], ['id' => $id]); $item = self::selectFirst(['guid'], ['id' => $id]);
if (DBM::is_result($item)) { if (DBM::is_result($item)) {
return $item['guid']; return $item['guid'];
} else { } else {
@ -2074,7 +2138,7 @@ class Item extends BaseObject
$community_page = (($user['page-flags'] == PAGE_COMMUNITY) ? true : false); $community_page = (($user['page-flags'] == PAGE_COMMUNITY) ? true : false);
$prvgroup = (($user['page-flags'] == PAGE_PRVGROUP) ? true : false); $prvgroup = (($user['page-flags'] == PAGE_PRVGROUP) ? true : false);
$item = dba::selectFirst('item', [], ['id' => $item_id]); $item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $item_id]);
if (!DBM::is_result($item)) { if (!DBM::is_result($item)) {
return; return;
} }
@ -2560,7 +2624,7 @@ class Item extends BaseObject
logger('like: verb ' . $verb . ' item ' . $item_id); logger('like: verb ' . $verb . ' item ' . $item_id);
$item = dba::selectFirst('item', [], ['`id` = ? OR `uri` = ?', $item_id, $item_id]); $item = self::selectFirst(self::ITEM_FIELDLIST, ['`id` = ? OR `uri` = ?', $item_id, $item_id]);
if (!DBM::is_result($item)) { if (!DBM::is_result($item)) {
logger('like: unknown item ' . $item_id); logger('like: unknown item ' . $item_id);
return false; return false;
@ -2737,7 +2801,7 @@ EOT;
'moderated', 'visible', 'starred', 'bookmark', 'contact-id', 'moderated', 'visible', 'starred', 'bookmark', 'contact-id',
'deleted', 'origin', 'forum_mode', 'mention', 'network', 'author-id', 'owner-id']; 'deleted', 'origin', 'forum_mode', 'mention', 'network', 'author-id', 'owner-id'];
$condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid]; $condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid];
$item = dba::selectFirst('item', $fields, $condition); $item = self::selectFirst($fields, $condition);
if (!DBM::is_result($item)) { if (!DBM::is_result($item)) {
return; return;
@ -2759,7 +2823,7 @@ EOT;
'deleted', 'origin', 'forum_mode', 'network', 'author-id', 'owner-id']; 'deleted', 'origin', 'forum_mode', 'network', 'author-id', 'owner-id'];
$condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid]; $condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid];
$item = dba::selectFirst('item', $fields, $condition); $item = self::selectFirst($fields, $condition);
if (!DBM::is_result($item)) { if (!DBM::is_result($item)) {
return; return;
} }

View file

@ -15,7 +15,38 @@ require_once 'include/dba.php';
class Term class Term
{ {
public static function insertFromTagFieldByItemId($itemid) public static function tagTextFromItemId($itemid)
{
$tag_text = '';
$condition = ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]];
$tags = dba::select('term', [], $condition);
while ($tag = dba::fetch($tags)) {
if ($tag_text != '') {
$tag_text .= ',';
}
if ($tag['type'] == 1) {
$tag_text .= '#';
} else {
$tag_text .= '@';
}
$tag_text .= '[url=' . $tag['url'] . ']' . $tag['term'] . '[/url]';
}
return $tag_text;
}
public static function fileTextFromItemId($itemid)
{
$file_text = '';
$condition = ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_FILE, TERM_CATEGORY]];
$tags = dba::select('term', [], $condition);
while ($tag = dba::fetch($tags)) {
$file_text .= '[' . $tag['term'] . ']';
}
return $file_text;
}
public static function insertFromTagFieldByItemId($itemid, $tags)
{ {
$profile_base = System::baseUrl(); $profile_base = System::baseUrl();
$profile_data = parse_url($profile_base); $profile_data = parse_url($profile_base);
@ -23,12 +54,14 @@ class Term
$profile_base_friendica = $profile_data['host'] . $profile_path . '/profile/'; $profile_base_friendica = $profile_data['host'] . $profile_path . '/profile/';
$profile_base_diaspora = $profile_data['host'] . $profile_path . '/u/'; $profile_base_diaspora = $profile_data['host'] . $profile_path . '/u/';
$fields = ['guid', 'uid', 'id', 'edited', 'deleted', 'created', 'received', 'title', 'body', 'tag', 'parent']; $fields = ['guid', 'uid', 'id', 'edited', 'deleted', 'created', 'received', 'title', 'body', 'parent'];
$message = Item::selectFirst($fields, ['id' => $itemid]); $message = Item::selectFirst($fields, ['id' => $itemid]);
if (!DBM::is_result($message)) { if (!DBM::is_result($message)) {
return; return;
} }
$message['tag'] = $tags;
// Clean up all tags // Clean up all tags
dba::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]); dba::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]);
@ -57,14 +90,14 @@ class Term
$pattern = '/\W\#([^\[].*?)[\s\'".,:;\?!\[\]\/]/ism'; $pattern = '/\W\#([^\[].*?)[\s\'".,:;\?!\[\]\/]/ism';
if (preg_match_all($pattern, $data, $matches)) { if (preg_match_all($pattern, $data, $matches)) {
foreach ($matches[1] as $match) { foreach ($matches[1] as $match) {
$tags['#' . strtolower($match)] = ''; $tags['#' . $match] = '';
} }
} }
$pattern = '/\W([\#@])\[url\=(.*?)\](.*?)\[\/url\]/ism'; $pattern = '/\W([\#@])\[url\=(.*?)\](.*?)\[\/url\]/ism';
if (preg_match_all($pattern, $data, $matches, PREG_SET_ORDER)) { if (preg_match_all($pattern, $data, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) { foreach ($matches as $match) {
$tags[$match[1] . strtolower(trim($match[3], ',.:;[]/\"?!'))] = $match[2]; $tags[$match[1] . trim($match[3], ',.:;[]/\"?!')] = $match[2];
} }
} }
@ -128,9 +161,9 @@ class Term
* @param integer $itemid item id * @param integer $itemid item id
* @return void * @return void
*/ */
public static function insertFromFileFieldByItemId($itemid) public static function insertFromFileFieldByItemId($itemid, $files)
{ {
$message = Item::selectFirst(['uid', 'deleted', 'file'], ['id' => $itemid]); $message = Item::selectFirst(['uid', 'deleted'], ['id' => $itemid]);
if (!DBM::is_result($message)) { if (!DBM::is_result($message)) {
return; return;
} }
@ -142,6 +175,8 @@ class Term
return; return;
} }
$message['file'] = $files;
if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files)) { if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files)) {
foreach ($files[1] as $file) { foreach ($files[1] as $file) {
dba::insert('term', [ dba::insert('term', [
@ -193,7 +228,7 @@ class Term
while ($tag = dba::fetch($taglist)) { while ($tag = dba::fetch($taglist)) {
if ($tag["url"] == "") { if ($tag["url"] == "") {
$tag["url"] = $searchpath . strtolower($tag["term"]); $tag["url"] = $searchpath . $tag["term"];
} }
$orig_tag = $tag["url"]; $orig_tag = $tag["url"];