*/
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)) {
return;
}
$cid = 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)) {
// No mention without a contact url
return;
if (empty($cid)) {
$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 = ['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['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)) {
Logger::info('Tag already exists', $fields);
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;
+ }
}
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Util\Strings;
-use Friendica\Model\Tag;
-use Friendica\Model\Term;
/**
* Hashtag module.
*/
class Hashtag extends BaseModule
{
-
public static function content(array $parameters = [])
{
$result = [];
System::jsonExit($result);
}
- $taglist = DBA::p("SELECT DISTINCT(`term`) FROM `term` WHERE `term` LIKE ? AND `type` = ? ORDER BY `term`",
- $t . '%',
- intval(Tag::HASHTAG)
- );
+ $taglist = DBA::select('tag', ['name'], ["`name` LIKE ?", $t . "%"], ['order' => ['name'], 'limit' => 100]);
while ($tag = DBA::fetch($taglist)) {
- $result[] = ['text' => $tag['term']];
+ $result[] = ['text' => $tag['name']];
}
DBA::close($taglist);
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Tag;
-use Friendica\Model\Term;
use Friendica\Module\BaseSearch;
use Friendica\Network\HTTPException;
use Friendica\Util\Strings;
if ($tag) {
Logger::info('Start tag search.', ['q' => $search]);
+ $uriids = Tag::getURIIdListForTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage());
- $condition = [
- "(`uid` = 0 OR (`uid` = ? AND NOT `global`))
- AND `otype` = ? AND `type` = ? AND `term` = ?",
- 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);
+ if (!empty($uriids)) {
+ $params = ['order' => ['id' => true], 'group_by' => ['uri-id']];
+ $items = Item::selectForUser(local_user(), [], ['uri-id' => $uriids], $params);
$r = Item::inArray($items);
} else {
$r = [];