Trending tags are now sort by different users
[friendica.git/.git] / src / Model / Tag.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Model;
23
24 use Friendica\Content\Text\BBCode;
25 use Friendica\Core\Cache\Duration;
26 use Friendica\Core\Logger;
27 use Friendica\Core\Protocol;
28 use Friendica\Core\System;
29 use Friendica\Database\Database;
30 use Friendica\Database\DBA;
31 use Friendica\DI;
32 use Friendica\Util\Strings;
33
34 /**
35  * Class Tag
36  *
37  * This Model class handles tag table interactions.
38  * This tables stores relevant tags related to posts, like hashtags and mentions.
39  */
40 class Tag
41 {
42         const UNKNOWN  = 0;
43         const HASHTAG  = 1;
44         const MENTION  = 2;
45         /**
46          * An implicit mention is a mention in a comment body that is redundant with the threading information.
47          */
48         const IMPLICIT_MENTION  = 8;
49         /**
50          * An exclusive mention transfers the ownership of the post to the target account, usually a forum.
51          */
52         const EXCLUSIVE_MENTION = 9;
53
54         const TAG_CHARACTER = [
55                 self::HASHTAG           => '#',
56                 self::MENTION           => '@',
57                 self::IMPLICIT_MENTION  => '%',
58                 self::EXCLUSIVE_MENTION => '!',
59         ];
60
61         /**
62          * Store tag/mention elements
63          *
64          * @param integer $uriid
65          * @param integer $type
66          * @param string  $name
67          * @param string  $url
68          * @param boolean $probing
69          */
70         public static function store(int $uriid, int $type, string $name, string $url = '', $probing = true)
71         {
72                 if ($type == self::HASHTAG) {
73                         // Trim Unicode non-word characters
74                         $name = preg_replace('/(^\W+)|(\W+$)/us', '', $name);
75
76                         $tags = explode(self::TAG_CHARACTER[self::HASHTAG], $name);
77                         if (count($tags) > 1) {
78                                 foreach ($tags as $tag) {
79                                         self::store($uriid, $type, $tag, $url, $probing);
80                                 }
81                                 return;
82                         }
83                 }
84
85                 if (empty($name)) {
86                         return;
87                 }
88
89                 $cid = 0;
90                 $tagid = 0;
91
92                 if (in_array($type, [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION])) {
93                         if (empty($url)) {
94                                 // No mention without a contact url
95                                 return;
96                         }
97
98                         if ((substr($url, 0, 7) == 'https//') || (substr($url, 0, 6) == 'http//')) {
99                                 Logger::notice('Wrong scheme in url', ['url' => $url, 'callstack' => System::callstack(20)]);
100                         }
101
102                         if (!$probing) {
103                                 $condition = ['nurl' => Strings::normaliseLink($url), 'uid' => 0, 'deleted' => false];
104                                 $contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
105                                 if (DBA::isResult($contact)) {
106                                         $cid = $contact['id'];
107                                         Logger::info('Got id for contact url', ['cid' => $cid, 'url' => $url]);
108                                 }
109
110                                 if (empty($cid)) {
111                                         $ssl_url = str_replace('http://', 'https://', $url);
112                                         $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, 0];
113                                         $contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
114                                         if (DBA::isResult($contact)) {
115                                                 $cid = $contact['id'];
116                                                 Logger::info('Got id for contact alias', ['cid' => $cid, 'url' => $url]);
117                                         }
118                                 }
119                         } else {
120                                 $cid = Contact::getIdForURL($url, 0, false);
121                                 Logger::info('Got id by probing', ['cid' => $cid, 'url' => $url]);
122                         }
123
124                         if (empty($cid)) {
125                                 // The contact wasn't found in the system (most likely some dead account)
126                                 // We ensure that we only store a single entry by overwriting the previous name
127                                 Logger::info('Contact not found, updating tag', ['url' => $url, 'name' => $name]);
128                                 if (!DBA::exists('tag', ['name' => substr($name, 0, 96), 'url' => $url])) {
129                                         DBA::update('tag', ['name' => substr($name, 0, 96)], ['url' => $url]);
130                                 }
131                         }
132                 }
133
134                 if (empty($cid)) {
135                         if (($type != self::HASHTAG) && !empty($url) && ($url != $name)) {
136                                 $url = strtolower($url);
137                         } else {
138                                 $url = '';
139                         }
140
141                         $tagid = self::getID($name, $url);
142                         if (empty($tagid)) {
143                                 return;
144                         }
145                 }
146
147                 $fields = ['uri-id' => $uriid, 'type' => $type, 'tid' => $tagid, 'cid' => $cid];
148
149                 if (in_array($type, [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION])) {
150                         $condition = $fields;
151                         $condition['type'] = [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION];
152                         if (DBA::exists('post-tag', $condition)) {
153                                 Logger::info('Tag already exists', $fields);
154                                 return;
155                         }
156                 }
157
158                 DBA::insert('post-tag', $fields, Database::INSERT_IGNORE);
159
160                 Logger::info('Stored tag/mention', ['uri-id' => $uriid, 'tag-id' => $tagid, 'contact-id' => $cid, 'name' => $name, 'type' => $type, 'callstack' => System::callstack(8)]);
161         }
162
163         /**
164          * Get a tag id for a given tag name and url
165          *
166          * @param string $name
167          * @param string $url
168          * @return void
169          */
170         public static function getID(string $name, string $url = '')
171         {
172                 $fields = ['name' => substr($name, 0, 96), 'url' => $url];
173
174                 $tag = DBA::selectFirst('tag', ['id'], $fields);
175                 if (DBA::isResult($tag)) {
176                         return $tag['id'];
177                 }
178
179                 DBA::insert('tag', $fields, Database::INSERT_IGNORE);
180                 $tid = DBA::lastInsertId();
181                 if (!empty($tid)) {
182                         return $tid;
183                 }
184
185                 Logger::error('No tag id created', $fields);
186                 return 0;
187         }
188
189         /**
190          * Store tag/mention elements
191          *
192          * @param integer $uriid
193          * @param string $hash
194          * @param string $name
195          * @param string $url
196          * @param boolean $probing
197          */
198         public static function storeByHash(int $uriid, string $hash, string $name, string $url = '', $probing = true)
199         {
200                 $type = self::getTypeForHash($hash);
201                 if ($type == self::UNKNOWN) {
202                         return;
203                 }
204
205                 self::store($uriid, $type, $name, $url, $probing);
206         }
207
208         /**
209          * Store tags and mentions from the body
210          * 
211          * @param integer $uriid   URI-Id
212          * @param string  $body    Body of the post
213          * @param string  $tags    Accepted tags
214          * @param boolean $probing Perform a probing for contacts, adding them if needed
215          */
216         public static function storeFromBody(int $uriid, string $body, string $tags = null, $probing = true)
217         {
218                 if (is_null($tags)) {
219                         $tags =  self::TAG_CHARACTER[self::HASHTAG] . self::TAG_CHARACTER[self::MENTION] . self::TAG_CHARACTER[self::EXCLUSIVE_MENTION];
220                 }
221
222                 Logger::info('Check for tags', ['uri-id' => $uriid, 'hash' => $tags, 'callstack' => System::callstack()]);
223
224                 if (!preg_match_all("/([" . $tags . "])\[url\=([^\[\]]*)\]([^\[\]]*)\[\/url\]/ism", $body, $result, PREG_SET_ORDER)) {
225                         return;
226                 }
227
228                 Logger::info('Found tags', ['uri-id' => $uriid, 'hash' => $tags, 'result' => $result]);
229
230                 foreach ($result as $tag) {
231                         self::storeByHash($uriid, $tag[1], $tag[3], $tag[2], $probing);
232                 }
233         }
234
235         /**
236          * Store raw tags (not encapsulated in links) from the body
237          * This function is needed in the intermediate phase.
238          * Later we can call item::setHashtags in advance to have all tags converted.
239          * 
240          * @param integer $uriid URI-Id
241          * @param string  $body   Body of the post
242          */
243         public static function storeRawTagsFromBody(int $uriid, string $body)
244         {
245                 Logger::info('Check for tags', ['uri-id' => $uriid, 'callstack' => System::callstack()]);
246
247                 $result = BBCode::getTags($body);
248                 if (empty($result)) {
249                         return;
250                 }
251
252                 Logger::info('Found tags', ['uri-id' => $uriid, 'result' => $result]);
253
254                 foreach ($result as $tag) {
255                         if (substr($tag, 0, 1) != self::TAG_CHARACTER[self::HASHTAG]) {
256                                 continue;
257                         }
258                         self::storeByHash($uriid, substr($tag, 0, 1), substr($tag, 1));
259                 }
260         }
261
262         /**
263          * Checks for stored hashtags and mentions for the given post
264          *
265          * @param integer $uriid
266          * @return bool
267          */
268         public static function existsForPost(int $uriid)
269         {
270                 return DBA::exists('post-tag', ['uri-id' => $uriid, 'type' => [self::HASHTAG, self::MENTION, self::IMPLICIT_MENTION, self::EXCLUSIVE_MENTION]]);
271         }
272
273         /**
274          * Remove tag/mention
275          *
276          * @param integer $uriid
277          * @param integer $type
278          * @param string $name
279          * @param string $url
280          */
281         public static function remove(int $uriid, int $type, string $name, string $url = '')
282         {
283                 $condition = ['uri-id' => $uriid, 'type' => $type, 'url' => $url];
284                 if ($type == self::HASHTAG) {
285                         $condition['name'] = $name;
286                 }
287
288                 $tag = DBA::selectFirst('tag-view', ['tid', 'cid'], $condition);
289                 if (!DBA::isResult($tag)) {
290                         return;
291                 }
292
293                 Logger::info('Removing tag/mention', ['uri-id' => $uriid, 'tid' => $tag['tid'], 'name' => $name, 'url' => $url, 'callstack' => System::callstack(8)]);
294                 DBA::delete('post-tag', ['uri-id' => $uriid, 'type' => $type, 'tid' => $tag['tid'], 'cid' => $tag['cid']]);
295         }
296
297         /**
298          * Remove tag/mention
299          *
300          * @param integer $uriid
301          * @param string $hash
302          * @param string $name
303          * @param string $url
304          */
305         public static function removeByHash(int $uriid, string $hash, string $name, string $url = '')
306         {
307                 $type = self::getTypeForHash($hash);
308                 if ($type == self::UNKNOWN) {
309                         return;
310                 }
311
312                 self::remove($uriid, $type, $name, $url);
313         }
314
315         /**
316          * Get the type for the given hash
317          *
318          * @param string $hash
319          * @return integer type
320          */
321         private static function getTypeForHash(string $hash)
322         {
323                 if ($hash == self::TAG_CHARACTER[self::MENTION]) {
324                         return self::MENTION;
325                 } elseif ($hash == self::TAG_CHARACTER[self::EXCLUSIVE_MENTION]) {
326                         return self::EXCLUSIVE_MENTION;
327                 } elseif ($hash == self::TAG_CHARACTER[self::IMPLICIT_MENTION]) {
328                         return self::IMPLICIT_MENTION;
329                 } elseif ($hash == self::TAG_CHARACTER[self::HASHTAG]) {
330                         return self::HASHTAG;
331                 } else {
332                         return self::UNKNOWN;
333                 }
334         }
335
336         /**
337          * Create implicit mentions for a given post
338          *
339          * @param integer $uri_id
340          * @param integer $parent_uri_id
341          */
342         public static function createImplicitMentions(int $uri_id, int $parent_uri_id)
343         {
344                 // Always mention the direct parent author
345                 $parent = Post::selectFirst(['author-link', 'author-name'], ['uri-id' => $parent_uri_id]);
346                 self::store($uri_id, self::IMPLICIT_MENTION, $parent['author-name'], $parent['author-link']);
347
348                 if (DI::config()->get('system', 'disable_implicit_mentions')) {
349                         return;
350                 }
351
352                 $tags = DBA::select('tag-view', ['name', 'url'], ['uri-id' => $parent_uri_id]);
353                 while ($tag = DBA::fetch($tags)) {
354                         self::store($uri_id, self::IMPLICIT_MENTION, $tag['name'], $tag['url']);
355                 }
356                 DBA::close($tags);
357         }
358
359         /**
360          * Retrieves the terms from the provided type(s) associated with the provided item ID.
361          *
362          * @param int       $item_id
363          * @param int|array $type
364          * @return array
365          * @throws \Exception
366          */
367         public static function getByURIId(int $uri_id, array $type = [self::HASHTAG, self::MENTION, self::IMPLICIT_MENTION, self::EXCLUSIVE_MENTION])
368         {
369                 $condition = ['uri-id' => $uri_id, 'type' => $type];
370                 return DBA::selectToArray('tag-view', ['type', 'name', 'url'], $condition);
371         }
372
373         /**
374          * Return a string with all tags and mentions
375          *
376          * @param integer $uri_id
377          * @param array   $type
378          * @return string tags and mentions
379          * @throws \Exception
380          */
381         public static function getCSVByURIId(int $uri_id, array $type = [self::HASHTAG, self::MENTION, self::IMPLICIT_MENTION, self::EXCLUSIVE_MENTION])
382         {
383                 $tag_list = [];
384                 $tags = self::getByURIId($uri_id, $type);
385                 foreach ($tags as $tag) {
386                         $tag_list[] = self::TAG_CHARACTER[$tag['type']] . '[url=' . $tag['url'] . ']' . $tag['name'] . '[/url]';
387                 }
388
389                 return implode(',', $tag_list);
390         }
391
392         /**
393          * Sorts an item's tags into mentions, hashtags and other tags. Generate personalized URLs by user and modify the
394          * provided item's body with them.
395          *
396          * @param array $item
397          * @return array
398          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
399          * @throws \ImagickException
400          */
401         public static function populateFromItem(&$item)
402         {
403                 $return = [
404                         'tags' => [],
405                         'hashtags' => [],
406                         'mentions' => [],
407                         'implicit_mentions' => [],
408                 ];
409
410                 $searchpath = DI::baseUrl() . "/search?tag=";
411
412                 $taglist = DBA::select('tag-view', ['type', 'name', 'url', 'cid'],
413                         ['uri-id' => $item['uri-id'], 'type' => [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION]]);
414                 while ($tag = DBA::fetch($taglist)) {
415                         if ($tag['url'] == '') {
416                                 $tag['url'] = $searchpath . rawurlencode($tag['name']);
417                         }
418
419                         $orig_tag = $tag['url'];
420
421                         $prefix = self::TAG_CHARACTER[$tag['type']];
422                         switch($tag['type']) {
423                                 case self::HASHTAG:
424                                         if ($orig_tag != $tag['url']) {
425                                                 $item['body'] = str_replace($orig_tag, $tag['url'], $item['body']);
426                                         }
427
428                                         $return['hashtags'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a>';
429                                         $return['tags'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a>';
430                                         break;
431                                 case self::MENTION:
432                                 case self::EXCLUSIVE_MENTION:
433                                         if (!empty($tag['cid'])) {
434                                                 $tag['url'] = Contact::magicLinkById($tag['cid']);
435                                         } else {
436                                                 $tag['url'] = Contact::magicLink($tag['url']);
437                                         }
438                                         $return['mentions'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a>';
439                                         $return['tags'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a>';
440                                         break;
441                                 case self::IMPLICIT_MENTION:
442                                         $return['implicit_mentions'][] = $prefix . $tag['name'];
443                                         break;
444                         }
445                 }
446                 DBA::close($taglist);
447
448                 return $return;
449         }
450
451         /**
452          * Counts posts for given tag
453          *
454          * @param string $search
455          * @param integer $uid
456          * @return integer number of posts
457          */
458         public static function countByTag(string $search, int $uid = 0)
459         {
460                 $condition = ["`name` = ? AND (`uid` = ? OR (`uid` = ? AND NOT `global`))
461                         AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
462                         $search, 0, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
463
464                 return DBA::count('tag-search-view', $condition);
465         }
466
467         /**
468          * Search posts for given tag
469          *
470          * @param string $search
471          * @param integer $uid
472          * @param integer $start
473          * @param integer $limit
474          * @param integer $last_uriid
475          * @return array with URI-ID
476          */
477         public static function getURIIdListByTag(string $search, int $uid = 0, int $start = 0, int $limit = 100, int $last_uriid = 0)
478         {
479                 $condition = ["`name` = ? AND (`uid` = ? OR (`uid` = ? AND NOT `global`))
480                         AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
481                         $search, 0, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
482
483                 if (!empty($last_uriid)) {
484                         $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $last_uriid]);
485                 }
486
487                 $params = [
488                         'order' => ['uri-id' => true],
489                         'limit' => [$start, $limit]
490                 ];
491
492                 $tags = DBA::select('tag-search-view', ['uri-id'], $condition, $params);
493
494                 $uriids = [];
495                 while ($tag = DBA::fetch($tags)) {
496                         $uriids[] = $tag['uri-id'];
497                 }
498                 DBA::close($tags);
499
500                 return $uriids;
501         }
502
503         /**
504          * Returns a list of the most frequent global hashtags over the given period
505          *
506          * @param int $period Period in hours to consider posts
507          * @param int $limit  Number of returned tags
508          * @return array
509          * @throws \Exception
510          */
511         public static function getGlobalTrendingHashtags(int $period, $limit = 10)
512         {
513                 $tags = DI::cache()->get('global_trending_tags-' . $period . '-' . $limit);
514                 if (!empty($tags)) {
515                         return $tags;
516                 } else {
517                         return self::setGlobalTrendingHashtags($period, $limit);
518                 }
519         }
520
521         /**
522          * Fetch the blocked tags as SQL
523          *
524          * @return string 
525          */
526         private static function getBlockedSQL()
527         {
528                 $blocked_txt = DI::config()->get('system', 'blocked_tags');
529                 if (empty($blocked_txt)) {
530                         return '';
531                 }
532
533                 $blocked = explode(',', $blocked_txt);
534                 array_walk($blocked, function(&$value) { $value = "'" . DBA::escape(trim($value)) . "'";});
535                 return " AND NOT `name` IN (" . implode(',', $blocked) . ")";
536         }
537
538         /**
539          * Creates a list of the most frequent global hashtags over the given period
540          *
541          * @param int $period Period in hours to consider posts
542          * @param int $limit  Number of returned tags
543          * @return array
544          * @throws \Exception
545          */
546         public static function setGlobalTrendingHashtags(int $period, int $limit = 10)
547         {
548                 $block_sql = self::getBlockedSQL();
549
550                 $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`, COUNT(DISTINCT(`author-id`)) as `authors`
551                         FROM `tag-search-view`
552                         WHERE `private` = ? AND `uid` = ? AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR) $block_sql
553                         GROUP BY `term` ORDER BY `authors` DESC, `score` DESC LIMIT ?",
554                         Item::PUBLIC, 0, $period, $limit);
555
556                 if (DBA::isResult($tagsStmt)) {
557                         $tags = DBA::toArray($tagsStmt);
558                         DI::cache()->set('global_trending_tags-' . $period . '-' . $limit, $tags, Duration::DAY);
559                         return $tags;
560                 }
561
562                 return [];
563         }
564
565         /**
566          * Returns a list of the most frequent local hashtags over the given period
567          *
568          * @param int $period Period in hours to consider posts
569          * @param int $limit  Number of returned tags
570          * @return array
571          * @throws \Exception
572          */
573         public static function getLocalTrendingHashtags(int $period, $limit = 10)
574         {
575                 $tags = DI::cache()->get('local_trending_tags-' . $period . '-' . $limit);
576                 if (!empty($tags)) {
577                         return $tags;
578                 } else {
579                         return self::setLocalTrendingHashtags($period, $limit);
580                 }
581         }
582
583         /**
584          * Returns a list of the most frequent local hashtags over the given period
585          *
586          * @param int $period Period in hours to consider posts
587          * @param int $limit  Number of returned tags
588          * @return array
589          * @throws \Exception
590          */
591         public static function setLocalTrendingHashtags(int $period, int $limit = 10)
592         {
593                 $block_sql = self::getBlockedSQL();
594
595                 $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`, COUNT(DISTINCT(`author-id`)) as `authors`
596                         FROM `tag-search-view`
597                         WHERE `private` = ? AND `wall` AND `origin` AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR) $block_sql
598                         GROUP BY `term` ORDER BY `authors` DESC, `score` DESC LIMIT ?",
599                         Item::PUBLIC, $period, $limit);
600
601                 if (DBA::isResult($tagsStmt)) {
602                         $tags = DBA::toArray($tagsStmt);
603                         DI::cache()->set('local_trending_tags-' . $period . '-' . $limit, $tags, Duration::DAY);
604                         return $tags;
605                 }
606
607                 return [];
608         }
609
610         /**
611          * Check if the provided tag is of one of the provided term types.
612          *
613          * @param string $tag
614          * @param int    ...$types
615          * @return bool
616          */
617         public static function isType($tag, ...$types)
618         {
619                 $tag_chars = [];
620                 foreach ($types as $type) {
621                         if (array_key_exists($type, self::TAG_CHARACTER)) {
622                                 $tag_chars[] = self::TAG_CHARACTER[$type];
623                         }
624                 }
625
626                 return Strings::startsWithChars($tag, $tag_chars);
627         }
628
629         /**
630          * Fetch user who subscribed to the given tag
631          *
632          * @param string $tag
633          * @return array User list
634          */
635         private static function getUIDListByTag(string $tag)
636         {
637                 $uids = [];
638                 $searches = DBA::select('search', ['uid'], ['term' => $tag]);
639                 while ($search = DBA::fetch($searches)) {
640                         $uids[] = $search['uid'];
641                 }
642                 DBA::close($searches);
643
644                 return $uids;
645         }
646
647         /**
648          * Fetch user who subscribed to the tags of the given item
649          *
650          * @param integer $uri_id
651          * @return array User list
652          */
653         public static function getUIDListByURIId(int $uri_id)
654         {
655                 $uids = [];
656                 $tags = self::getByURIId($uri_id, [self::HASHTAG]);
657
658                 foreach ($tags as $tag) {
659                         $uids = array_merge($uids, self::getUIDListByTag(self::TAG_CHARACTER[self::HASHTAG] . $tag['name']));
660                 }
661
662                 return array_unique($uids);
663         }
664 }