Usage of the new tag tables
This commit is contained in:
parent
5367620467
commit
c2a9b3b9e9
|
@ -68,7 +68,19 @@ class Tag
|
||||||
*/
|
*/
|
||||||
public static function store(int $uriid, int $type, string $name, string $url = '', $probing = true)
|
public static function store(int $uriid, int $type, string $name, string $url = '', $probing = true)
|
||||||
{
|
{
|
||||||
$name = trim($name, "\x00..\x20\xFF#!@");
|
if ($type = self::HASHTAG) {
|
||||||
|
// Remove some common "garbarge" from tags
|
||||||
|
$name = trim($name, "\x00..\x20\xFF#!@,;.:'/?!^°$%".'"');
|
||||||
|
|
||||||
|
$tags = explode(self::TAG_CHARACTER[self::HASHTAG], $name);
|
||||||
|
if (count($tags) > 1) {
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
self::store($uriid, $type, $tag, $url, $probing);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($name)) {
|
if (empty($name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +88,7 @@ class Tag
|
||||||
$cid = 0;
|
$cid = 0;
|
||||||
$tagid = 0;
|
$tagid = 0;
|
||||||
|
|
||||||
if (in_array($type, [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION])) {
|
if (in_array($type, [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION])) {
|
||||||
if (empty($url)) {
|
if (empty($url)) {
|
||||||
// No mention without a contact url
|
// No mention without a contact url
|
||||||
return;
|
return;
|
||||||
|
@ -115,7 +127,7 @@ class Tag
|
||||||
if (empty($cid)) {
|
if (empty($cid)) {
|
||||||
$fields = ['name' => substr($name, 0, 96), 'url' => ''];
|
$fields = ['name' => substr($name, 0, 96), 'url' => ''];
|
||||||
|
|
||||||
if (($type != Tag::HASHTAG) && !empty($url) && ($url != $name)) {
|
if (($type != self::HASHTAG) && !empty($url) && ($url != $name)) {
|
||||||
$fields['url'] = strtolower($url);
|
$fields['url'] = strtolower($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,9 +147,9 @@ class Tag
|
||||||
|
|
||||||
$fields = ['uri-id' => $uriid, 'type' => $type, 'tid' => $tagid, 'cid' => $cid];
|
$fields = ['uri-id' => $uriid, 'type' => $type, 'tid' => $tagid, 'cid' => $cid];
|
||||||
|
|
||||||
if (in_array($type, [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION])) {
|
if (in_array($type, [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION])) {
|
||||||
$condition = $fields;
|
$condition = $fields;
|
||||||
$condition['type'] = [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION];
|
$condition['type'] = [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION];
|
||||||
if (DBA::exists('post-tag', $condition)) {
|
if (DBA::exists('post-tag', $condition)) {
|
||||||
Logger::info('Tag already exists', $fields);
|
Logger::info('Tag already exists', $fields);
|
||||||
return;
|
return;
|
||||||
|
@ -376,4 +388,32 @@ class Tag
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search posts for given tag
|
||||||
|
*
|
||||||
|
* @param string $search
|
||||||
|
* @param integer $uid
|
||||||
|
* @param integer $start
|
||||||
|
* @param integer $limit
|
||||||
|
* @return array with URI-ID
|
||||||
|
*/
|
||||||
|
public static function getURIIdListForTag(string $search, int $uid = 0, int $start = 0, int $limit = 100)
|
||||||
|
{
|
||||||
|
$condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid];
|
||||||
|
$params = [
|
||||||
|
'order' => ['uri-id' => true],
|
||||||
|
'group_by' => ['uri-id'],
|
||||||
|
'limit' => [$start, $limit]
|
||||||
|
];
|
||||||
|
|
||||||
|
$tags = DBA::select('tag-search-view', ['uri-id'], $condition, $params);
|
||||||
|
|
||||||
|
$uriids = [];
|
||||||
|
while ($tag = DBA::fetch($tags)) {
|
||||||
|
$uriids[] = $tag['uri-id'];
|
||||||
|
}
|
||||||
|
DBA::close($tags);
|
||||||
|
|
||||||
|
return $uriids;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ use Friendica\BaseModule;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Model\Tag;
|
|
||||||
use Friendica\Model\Term;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hashtag module.
|
* Hashtag module.
|
||||||
*/
|
*/
|
||||||
class Hashtag extends BaseModule
|
class Hashtag extends BaseModule
|
||||||
{
|
{
|
||||||
|
|
||||||
public static function content(array $parameters = [])
|
public static function content(array $parameters = [])
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
|
@ -43,12 +40,9 @@ class Hashtag extends BaseModule
|
||||||
System::jsonExit($result);
|
System::jsonExit($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
$taglist = DBA::p("SELECT DISTINCT(`term`) FROM `term` WHERE `term` LIKE ? AND `type` = ? ORDER BY `term`",
|
$taglist = DBA::select('tag', ['name'], ["`name` LIKE ?", $t . "%"], ['order' => ['name'], 'limit' => 100]);
|
||||||
$t . '%',
|
|
||||||
intval(Tag::HASHTAG)
|
|
||||||
);
|
|
||||||
while ($tag = DBA::fetch($taglist)) {
|
while ($tag = DBA::fetch($taglist)) {
|
||||||
$result[] = ['text' => $tag['term']];
|
$result[] = ['text' => $tag['name']];
|
||||||
}
|
}
|
||||||
DBA::close($taglist);
|
DBA::close($taglist);
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\Tag;
|
use Friendica\Model\Tag;
|
||||||
use Friendica\Model\Term;
|
|
||||||
use Friendica\Module\BaseSearch;
|
use Friendica\Module\BaseSearch;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
@ -150,28 +149,11 @@ class Index extends BaseSearch
|
||||||
|
|
||||||
if ($tag) {
|
if ($tag) {
|
||||||
Logger::info('Start tag search.', ['q' => $search]);
|
Logger::info('Start tag search.', ['q' => $search]);
|
||||||
|
$uriids = Tag::getURIIdListForTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage());
|
||||||
|
|
||||||
$condition = [
|
if (!empty($uriids)) {
|
||||||
"(`uid` = 0 OR (`uid` = ? AND NOT `global`))
|
$params = ['order' => ['id' => true], 'group_by' => ['uri-id']];
|
||||||
AND `otype` = ? AND `type` = ? AND `term` = ?",
|
$items = Item::selectForUser(local_user(), [], ['uri-id' => $uriids], $params);
|
||||||
local_user(), Term::OBJECT_TYPE_POST, Tag::HASHTAG, $search
|
|
||||||
];
|
|
||||||
$params = [
|
|
||||||
'order' => ['received' => true],
|
|
||||||
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]
|
|
||||||
];
|
|
||||||
$terms = DBA::select('term', ['oid'], $condition, $params);
|
|
||||||
|
|
||||||
$itemids = [];
|
|
||||||
while ($term = DBA::fetch($terms)) {
|
|
||||||
$itemids[] = $term['oid'];
|
|
||||||
}
|
|
||||||
|
|
||||||
DBA::close($terms);
|
|
||||||
|
|
||||||
if (!empty($itemids)) {
|
|
||||||
$params = ['order' => ['id' => true]];
|
|
||||||
$items = Item::selectForUser(local_user(), [], ['id' => $itemids], $params);
|
|
||||||
$r = Item::inArray($items);
|
$r = Item::inArray($items);
|
||||||
} else {
|
} else {
|
||||||
$r = [];
|
$r = [];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user