diff --git a/app/Repositories/TagRepository.php b/app/Repositories/TagRepository.php index 13a84e56..c871a526 100644 --- a/app/Repositories/TagRepository.php +++ b/app/Repositories/TagRepository.php @@ -11,6 +11,8 @@ class TagRepository extends BaseRepository { private static $orderByFieldIdString; + private static $allTags; + public function getList(array $params) { $query = $this->createBasicQuery(); @@ -61,20 +63,25 @@ class TagRepository extends BaseRepository return $html; } - public function renderSpan(Collection $tagKeyById, array $renderIdArr = [], $withFilterLink = false): string + public function renderSpan(array $renderIdArr = [], $withFilterLink = false): string { + if (empty(self::$allTags)) { + self::$allTags = self::createBasicQuery()->get(); + } $html = ''; - foreach ($renderIdArr as $tagId) { - $value = $tagKeyById->get($tagId); - if ($value) { - $item = sprintf( - "%s", - $value->color, $value->font_color, $value->border_radius, $value->font_size, $value->margin, $value->padding, $value->name - ); - if ($withFilterLink) { - $html .= sprintf('%s', $tagId, $item); - } else { - $html .= $item; + foreach (self::$allTags as $value) { + if (in_array($value->id, $renderIdArr) || (isset($renderIdArr[0]) && $renderIdArr[0] == '*')) { + $tagId = $value->id; + if ($value) { + $item = sprintf( + "%s", + $value->color, $value->font_color, $value->border_radius, $value->font_size, $value->margin, $value->padding, $value->name + ); + if ($withFilterLink) { + $html .= sprintf('%s', $tagId, $item); + } else { + $html .= $item; + } } } } @@ -141,5 +148,11 @@ class TagRepository extends BaseRepository return self::$orderByFieldIdString; } + public function listAll() + { + self::$allTags = self::createBasicQuery()->get(); + return self::$allTags; + } + } diff --git a/include/functions.php b/include/functions.php index e60b3856..ec4fbf02 100644 --- a/include/functions.php +++ b/include/functions.php @@ -3320,10 +3320,7 @@ function torrenttable($rows, $variant = "torrent", $searchBoxId = 0) { $torrentSeedingLeechingStatus = $torrent->listLeechingSeedingStatus($CURUSER['id'], $torrentIdArr); $tagRep = new \App\Repositories\TagRepository(); - $tagCollection = $tagRep->createBasicQuery()->get(); - $tagIdStr = $tagCollection->implode('id', ',') ?: '0'; - $torrentTagCollection = \App\Models\TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->orderByRaw("field(tag_id,$tagIdStr)")->get(); - $tagKeyById = $tagCollection->keyBy('id'); + $torrentTagCollection = \App\Models\TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->get(); $torrentTagResult = $torrentTagCollection->groupBy('torrent_id'); $showCover = false; $showSeedBoxIcon = get_setting('seed_box.enabled') == 'yes'; @@ -3573,7 +3570,7 @@ foreach ($rows as $row) */ $tagOwns = $torrentTagResult->get($id); if ($tagOwns) { - $tags = $tagRep->renderSpan($tagKeyById, $tagOwns->pluck('tag_id')->toArray()); + $tags = $tagRep->renderSpan($tagOwns->pluck('tag_id')->toArray()); } else { $tags = ''; } diff --git a/lang/chs/lang_details.php b/lang/chs/lang_details.php index f0f0b672..e9d12c43 100644 --- a/lang/chs/lang_details.php +++ b/lang/chs/lang_details.php @@ -239,6 +239,7 @@ $lang_details = array 'claim_label' => '认领种子', 'claim_confirm' => '确定要认领此种子吗?', 'action_approval' => '审核', + 'row_tags' => '标签', ); ?> diff --git a/lang/cht/lang_details.php b/lang/cht/lang_details.php index f963817f..30a723fe 100644 --- a/lang/cht/lang_details.php +++ b/lang/cht/lang_details.php @@ -238,6 +238,7 @@ $lang_details = array 'claim_label' => '認領種子', 'claim_confirm' => '確定要認領此種子嗎?', 'action_approval' => '審核', + 'row_tags' => '標簽', ); ?> diff --git a/lang/en/lang_details.php b/lang/en/lang_details.php index 53621957..7a193e4e 100644 --- a/lang/en/lang_details.php +++ b/lang/en/lang_details.php @@ -238,6 +238,7 @@ $lang_details = array 'claim_label' => 'Claim torrent', 'claim_confirm' => 'Are you sure to claim this torrent?', 'action_approval' => 'Approval', + 'row_tags' => 'Tags', ); ?> diff --git a/public/details.php b/public/details.php index d3914460..e1ca5a2a 100644 --- a/public/details.php +++ b/public/details.php @@ -126,6 +126,13 @@ if (!$row) { if ($smalldescription_main == 'yes') tr($lang_details['row_small_description'],htmlspecialchars(trim($row["small_descr"])),true); + //tag + $torrentTags = \App\Models\TorrentTag::query()->where('torrent_id', $row['id'])->get(); + if ($torrentTags->isNotEmpty()) { + $tagRep = new \App\Repositories\TagRepository(); + tr($lang_details['row_tags'], $tagRep->renderSpan($torrentTags->pluck('tag_id')->toArray()),true); + } + $size_info = "".$lang_details['text_size']."" . mksize($row["size"]); $type_info = " ".$lang_details['row_type'].": ".$row["cat_name"]; $source_info = $medium_info = $codec_info = $audiocodec_info = $standard_info = $processing_info = $team_info = ''; diff --git a/public/torrents.php b/public/torrents.php index ace249b1..d83b43fe 100644 --- a/public/torrents.php +++ b/public/torrents.php @@ -10,8 +10,7 @@ parked(); * tags */ $tagRep = new \App\Repositories\TagRepository(); -$tagKeyById = $tagRep->createBasicQuery()->get()->keyBy('id'); -$renderKeyArr = $tagKeyById->keys()->toArray(); +$allTags = $tagRep->listAll(); $elasticsearchEnabled = nexus_env('ELASTICSEARCH_ENABLED'); //check searchbox @@ -1143,8 +1142,8 @@ if (!$Cache->get_page()){ } echo $Cache->next_row(); -if ($tagKeyById->isNotEmpty()) { - echo '