add global search

This commit is contained in:
xiaomlove
2022-10-22 20:52:08 +08:00
parent 348112364c
commit 505c7122b1
16 changed files with 252 additions and 38 deletions
@@ -75,6 +75,16 @@ class ClaimResource extends Resource
return $query->when($data['uid'], fn (Builder $query, $uid) => $query->where("uid", $uid));
})
,
Tables\Filters\Filter::make('torrent_id')
->form([
Forms\Components\TextInput::make('torrent_id')
->label(__('claim.fields.torrent_id'))
->placeholder(__('claim.fields.torrent_id'))
,
])->query(function (Builder $query, array $data) {
return $query->when($data['torrent_id'], fn (Builder $query, $value) => $query->where("torrent_id", $value));
})
,
])
->actions([
// Tables\Actions\EditAction::make(),
-2
View File
@@ -5,8 +5,6 @@ namespace App\Models;
use App\Repositories\TagRepository;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use JeroenG\Explorer\Application\Explored;
use Laravel\Scout\Searchable;
class Torrent extends NexusModel
{
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.30');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-10-21');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-10-22');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
+55 -23
View File
@@ -2638,8 +2638,8 @@ else {
[<a href="torrents.php?inclbookmarked=1&amp;allsec=1&amp;incldead=0"><?php echo $lang_functions['text_bookmarks'] ?></a>]
<font class = 'color_bonus'><?php echo $lang_functions['text_bonus'] ?></font>[<a href="mybonus.php"><?php echo $lang_functions['text_use'] ?></a>]: <?php echo number_format($CURUSER['seedbonus'], 1)?>
<?php if($attendance){ printf(' <a href="attendance.php" class="">'.$lang_functions['text_attended'].'</a>', $attendance->points, $CURUSER['attendance_card']); }else{ printf(' <a href="attendance.php" class="faqlink">%s</a>', $lang_functions['text_attendance']);}?>
<font class = 'color_bonus'><?php echo $lang_functions['text_seed_points'] ?></font>: <?php echo number_format($CURUSER['seed_points'], 1)?>
<font class = 'color_invite'><?php echo $lang_functions['text_invite'] ?></font>[<a href="invite.php?id=<?php echo $CURUSER['id']?>"><?php echo $lang_functions['text_send'] ?></a>]: <?php echo $CURUSER['invites']?>
<?php if(get_user_class() >= \App\Models\User::CLASS_ADMINISTRATOR) printf('[<a href="%s" target="_blank">%s</a>]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?>
<br />
<font class="color_ratio"><?php echo $lang_functions['text_ratio'] ?></font> <?php echo $ratio?>
<font class='color_uploaded'><?php echo $lang_functions['text_uploaded'] ?></font> <?php echo mksize($CURUSER['uploaded'])?>
@@ -2648,27 +2648,47 @@ else {
<font class='color_connectable'><?php echo $lang_functions['text_connectable'] ?></font><?php echo $connectable?> <?php echo maxslots();?>
<?php if(\App\Models\HitAndRun::getIsEnabled()) { ?><font class='color_bonus'>H&R: </font> <?php echo sprintf('[<a href="myhr.php">%s</a>]', (new \App\Repositories\HitAndRunRepository())->getStatusStats($CURUSER['id']))?><?php }?>
<?php if(\App\Models\Claim::getConfigIsEnabled()) { ?><font class='color_bonus'><?php echo $lang_functions['menu_claim']?></font> <?php echo sprintf('[<a href="claim.php?uid=%s">%s</a>]', $CURUSER['id'], (new \App\Repositories\ClaimRepository())->getStats($CURUSER['id']))?><?php }?>
<?php if(get_user_class() >= \App\Models\User::CLASS_ADMINISTRATOR) printf('[<a href="%s" target="_blank">%s</a>]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?>
</span>
</td>
<td class="bottom" align="right"><span class="medium"><?php echo $lang_functions['text_the_time_is_now'] ?><?php echo $datum['hours'].":".$datum['minutes']?><br />
<td class="bottom" align="left" style="border: none">
<form action="search.php" method="get" target="_blank">
<div style="display: flex;align-items: center">
<div style="display: flex;flex-direction: column">
<div>
<span style="display: inline-block;width:50px"><?php echo nexus_trans('search.search_keyword')?>: </span>
<span><input type="text" name="search" style="width: 100px;height: 12px" value="<?php echo $_GET['search'] ?? '' ?>"/></span>
</div>
<div>
<span style="display: inline-block;width:50px"><?php echo nexus_trans('search.search_area')?>: </span>
<span><?php echo build_search_area($_GET['search_area'] ?? '', ['style' => 'width: 108px'])?></span>
</div>
</div>
<div><input type="submit" value="<?php echo nexus_trans('search.global_search')?>" style="width: 39px;white-space: break-spaces;padding: 0" /></div>
</div>
</form>
</td>
<td class="bottom" align="right"><span class="medium">
<?php
if (user_can('staffmem')) {
$totalreports = $Cache->get_value('staff_report_count');
if ($totalreports == ""){
$totalreports = get_row_count("reports");
$Cache->cache_value('staff_report_count', $totalreports, 900);
}
$totalcheaters = $Cache->get_value('staff_cheater_count');
if ($totalcheaters == ""){
$totalcheaters = get_row_count("cheaters");
$Cache->cache_value('staff_cheater_count', $totalcheaters, 900);
}
print(
"<a href=\"cheaterbox.php\"><img class=\"cheaterbox\" alt=\"cheaterbox\" title=\"".$lang_functions['title_cheaterbox']."\" src=\"pic/trans.gif\" /> </a>".$totalcheaters
." <a href=\"reports.php\"><img class=\"reportbox\" alt=\"reportbox\" title=\"".$lang_functions['title_reportbox']."\" src=\"pic/trans.gif\" /> </a>".$totalreports
);
}
if (user_can('staffmem')) {
$totalreports = $Cache->get_value('staff_report_count');
if ($totalreports == ""){
$totalreports = get_row_count("reports");
$Cache->cache_value('staff_report_count', $totalreports, 900);
}
$totalcheaters = $Cache->get_value('staff_cheater_count');
if ($totalcheaters == ""){
$totalcheaters = get_row_count("cheaters");
$Cache->cache_value('staff_cheater_count', $totalcheaters, 900);
}
print(
"<a href=\"cheaterbox.php\"><img class=\"cheaterbox\" alt=\"cheaterbox\" title=\"".$lang_functions['title_cheaterbox']."\" src=\"pic/trans.gif\" /> </a>".$totalcheaters
." <a href=\"reports.php\"><img class=\"reportbox\" alt=\"reportbox\" title=\"".$lang_functions['title_reportbox']."\" src=\"pic/trans.gif\" /> </a>".$totalreports
);
}
print(" <a href=\"friends.php\"><img class=\"buddylist\" alt=\"Buddylist\" title=\"".$lang_functions['title_buddylist']."\" src=\"pic/trans.gif\" /></a>");
print(" <a href=\"getrss.php\"><img class=\"rss\" alt=\"RSS\" title=\"".$lang_functions['title_get_rss']."\" src=\"pic/trans.gif\" /></a>");
print '<br/>';
//echo $lang_functions['text_the_time_is_now'].$datum['hours'].":".$datum['minutes'] . '<br />';
// $cacheKey = "staff_message_count_" . $CURUSER['id'];
// $totalsm = $Cache->get_value($cacheKey);
$totalsm = \App\Repositories\MessageRepository::getStaffMessageCountCache($CURUSER['id'], 'total');
@@ -2683,8 +2703,7 @@ else {
print("<a href=\"messages.php\">".$inboxpic."</a> ".($messages ? $messages." (".$unread.$lang_functions['text_message_new'].")" : "0"));
print(" <a href=\"messages.php?action=viewmailbox&amp;box=-1\"><img class=\"sentbox\" alt=\"sentbox\" title=\"".$lang_functions['title_sentbox']."\" src=\"pic/trans.gif\" /></a> ".($outmessages ? $outmessages : "0"));
print(" <a href=\"friends.php\"><img class=\"buddylist\" alt=\"Buddylist\" title=\"".$lang_functions['title_buddylist']."\" src=\"pic/trans.gif\" /></a>");
print(" <a href=\"getrss.php\"><img class=\"rss\" alt=\"RSS\" title=\"".$lang_functions['title_get_rss']."\" src=\"pic/trans.gif\" /></a>");
?>
</span></td>
@@ -3544,7 +3563,7 @@ foreach ($rows as $row)
}
$stickyicon = apply_filter('sticky_icon', $stickyicon, $row);
$sp_torrent = get_torrent_promotion_append($row['sp_state'],"",true,$row["added"], $row['promotion_time_type'], $row['promotion_until'], $row['__ignore_global_sp_state'] ?? false);
$hrImg = get_hr_img($row, $searchBoxId);
$hrImg = get_hr_img($row, $row['search_box_id']);
//cover
$coverSrc = $tdCover = '';
@@ -4730,7 +4749,7 @@ function get_hr_img(array $torrent, $searchBoxId)
if ($mode == \App\Models\HitAndRun::MODE_GLOBAL || ($mode == \App\Models\HitAndRun::MODE_MANUAL && isset($torrent['hr']) && $torrent['hr'] == \App\Models\Torrent::HR_YES)) {
$result = '<img class="hitandrun" src="pic/trans.gif" alt="H&R" title="H&R" />';
}
do_log("mode: $mode, result: $result");
do_log("searchBoxId: $searchBoxId, mode: $mode, result: $result");
return $result;
}
@@ -6073,4 +6092,17 @@ function build_bonus_table(array $user, array $bonusResult = [], array $options
];
}
function build_search_area($searchArea, array $options = [])
{
$result = sprintf('<select name="search_area" style="%s">', $options['style'] ?? '');
foreach ([0, 1, 3, 4] as $item) {
$result .= sprintf(
'<option value="%s"%s>%s</option>',
$item, $item == $searchArea ? ' selected' : '', nexus_trans("search.search_area_options.$item")
);
}
$result .= '</select>';
return $result;
}
?>
+1 -1
View File
@@ -87,7 +87,7 @@ $lang_functions = array
'title_torrents_seeding' => "当前做种",
'title_torrents_leeching' => "当前下载",
'text_connectable' => "可连接:",
'text_the_time_is_now' => "当前时间:",
'text_the_time_is_now' => "时间: ",
'text_message_new' => "",
'title_sentbox' => "发件箱",
'title_inbox' => "收件箱",
+1 -1
View File
@@ -87,7 +87,7 @@ $lang_functions = array
'title_torrents_seeding' => "當前做種",
'title_torrents_leeching' => "當前下載",
'text_connectable' => "可連接:",
'text_the_time_is_now' => "當前時間:",
'text_the_time_is_now' => "時間: ",
'text_message_new' => "",
'title_sentbox' => "發件箱",
'title_inbox' => "收件箱",
+3 -3
View File
@@ -83,11 +83,11 @@ $lang_functions = array
'text_ratio' => "Ratio:",
'text_uploaded' => "Uploaded:",
'text_downloaded' => "Downloaded:",
'text_active_torrents' => "Active Torrents: ",
'text_active_torrents' => "Active: ",
'title_torrents_seeding' => "Torrents&nbsp;Seeding",
'title_torrents_leeching' => "Torrents&nbsp;Leeching",
'text_connectable' => "Connectable:&nbsp;",
'text_the_time_is_now' => "The time is now: ",
'text_the_time_is_now' => "Time: ",
'text_message_new' => " New",
'title_sentbox' => "sentbox",
'title_inbox' => "inbox",
@@ -322,7 +322,7 @@ $lang_functions = array
'text_invalid' => 'Invalid',
'text_technical_info' => 'MediaInfo',
'text_technical_info_help_text' => 'MediaInfo comes from software <b><a href="https://mediaarea.net/en/MediaInfo" target=\'_blank\'>MediaInfo</a></b>open file, click the view menu > text > right click in the box > select all > copy > past into this box.',
'text_management_system' => 'Management system',
'text_management_system' => 'Management',
'text_seed_points' => 'Seed points',
'spoiler_expand_collapse' => 'Click to expand/collapse',
'spoiler_default_title' => 'Collapse content',
+125
View File
@@ -0,0 +1,125 @@
<?php
require_once("../include/bittorrent.php");
dbconn(true);
require_once(get_langfile_path('torrents.php'));
loggedinorreturn();
parked();
$search = $_REQUEST['search'] ?? '';
$searchArea = $_REQUEST['search_area'] ?? \App\Repositories\SearchRepository::SEARCH_AREA_TITLE;
//approval status
$approvalStatusNoneVisible = get_setting('torrent.approval_status_none_visible');
$approvalStatus = null;
if ($approvalStatusNoneVisible == 'no' && !user_can('torrent-approval')) {
$approvalStatus = \App\Models\Torrent::APPROVAL_STATUS_ALLOW;
}
$count = 0;
$rows = [];
if ($search) {
$search = str_replace(".", " ", $search);
$searchArr = preg_split("/[\s]+/", $search, 10,PREG_SPLIT_NO_EMPTY);
$tableTorrent = "torrents";
$tableUser = "users";
$tableCategory = "categories";
$torrentQuery = \Nexus\Database\NexusDB::table($tableTorrent)->join($tableCategory, "$tableTorrent.category", "=", "$tableCategory.id");
if (get_setting('main.spsct') == 'yes' && !user_can('view_special_torrent')) {
$torrentQuery->where("$tableCategory.mode", get_setting('main.browsecat'));
}
if ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_TITLE) {
foreach ($searchArr as $queryString) {
$q = "%{$queryString}%";
$torrentQuery->where(function (\Illuminate\Database\Query\Builder $query) use ($q, $tableTorrent) {
return $query->where("$tableTorrent.name", 'like', $q)->orWhere("$tableTorrent.small_descr", "like", $q);
});
}
} elseif ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_DESC) {
foreach ($searchArr as $queryString) {
$q = "%{$queryString}%";
$torrentQuery->where("$tableTorrent.descr", "like", $q);
}
} elseif ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_OWNER) {
$torrentQuery->join($tableUser, "$tableTorrent.owner", "=", "$tableUser.id");
foreach ($searchArr as $queryString) {
$q = "%{$queryString}%";
$torrentQuery->where("$tableUser.username", "like", $q);
}
} elseif ($searchArea == \App\Repositories\SearchRepository::SEARCH_AREA_IMDB) {
foreach ($searchArr as $queryString) {
$q = "%{$queryString}%";
$torrentQuery->where("$tableTorrent.url", "like", $q);
}
} else {
foreach ($searchArr as $queryString) {
$q = "%{$queryString}%";
$torrentQuery->where("$tableTorrent.name", "like", $q);
}
write_log("User " . $CURUSER["username"] . "," . $CURUSER["ip"] . " is hacking search_area field in" . $_SERVER['SCRIPT_NAME'], 'mod');
}
if ($approvalStatus !== null) {
$torrentQuery->where("$tableTorrent.approval_status", $approvalStatus);
}
$torrentQuery->where("$tableTorrent.visible", 'yes');
$count = $torrentQuery->count();
}
if ($CURUSER["torrentsperpage"])
$torrentsperpage = (int)$CURUSER["torrentsperpage"];
elseif ($torrentsperpage_main)
$torrentsperpage = $torrentsperpage_main;
else $torrentsperpage = 50;
// sorting by MarkoStamcar
$column = 'id';
$ascdesc = 'desc';
$addparam = "?search=$search&";
if (isset($_GET['sort']) && $_GET['sort'] && isset($_GET['type']) && $_GET['type']) {
switch($_GET['sort']) {
case '1': $column = "name"; break;
case '2': $column = "numfiles"; break;
case '3': $column = "comments"; break;
case '4': $column = "added"; break;
case '5': $column = "size"; break;
case '6': $column = "times_completed"; break;
case '7': $column = "seeders"; break;
case '8': $column = "leechers"; break;
case '9': $column = "owner"; break;
default: $column = "id"; break;
}
switch($_GET['type']) {
case 'asc': $ascdesc = "ASC"; $linkascdesc = "asc"; break;
case 'desc': $ascdesc = "DESC"; $linkascdesc = "desc"; break;
default: $ascdesc = "DESC"; $linkascdesc = "desc"; break;
}
$addparam .= "sort=" . intval($_GET['sort']) . "&type=" . $linkascdesc . "&";
}
list($pagertop, $pagerbottom, $limit, $offset, $size, $page) = pager($torrentsperpage, $count, $addparam);
stdhead(nexus_trans('search.global_search'));
print("<table width=\"97%\" class=\"main\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td class=\"embedded\">");
if ($search && $count > 0) {
$fieldsStr = implode(', ', \App\Models\Torrent::getFieldsForList(true));
$rows = $torrentQuery->selectRaw("$fieldsStr, categories.mode as search_box_id")
->forPage($page + 1, $torrentsperpage)
->orderBy("$tableTorrent.$column", $ascdesc)
->get()
->toArray();
print($pagertop);
torrenttable(json_decode(json_encode($rows), true));
print($pagerbottom);
} else {
stdmsg($lang_torrents['std_search_results_for'] . $search . "\"",$lang_torrents['std_try_again']);
}
print("</td></tr></table>");
stdfoot();
+5 -5
View File
@@ -913,11 +913,11 @@ if ($count)
list($pagertop, $pagerbottom, $limit, $offset, $size, $page) = pager($torrentsperpage, $count, "?" . $addparam);
$fieldsStr = implode(', ', \App\Models\Torrent::getFieldsForList(true));
if ($allsec == 1 || $enablespecial != 'yes') {
$query = "SELECT $fieldsStr FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." $tagFilter $where $orderby $limit";
} else {
$query = "SELECT $fieldsStr FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." LEFT JOIN categories ON torrents.category=categories.id $tagFilter $where $orderby $limit";
}
// if ($allsec == 1 || $enablespecial != 'yes') {
// $query = "SELECT $fieldsStr FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." $tagFilter $where $orderby $limit";
// } else {
$query = "SELECT $fieldsStr, categories.mode as search_box_id FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." LEFT JOIN categories ON torrents.category=categories.id $tagFilter $where $orderby $limit";
// }
do_log("[TORRENT_LIST_SQL] $query", 'debug');
if (!$elasticsearchEnabled) {
$res = sql_query($query);
+3
View File
@@ -31,4 +31,7 @@ return [
'remove_claim_confirm' => 'Confirm to give up the claim?',
'already_claimed' => 'Claimed',
'not_claim_yet' => 'Unclaimed',
'fields' => [
'torrent_id' => 'Torrent ID',
],
];
+13
View File
@@ -0,0 +1,13 @@
<?php
return [
'global_search' => 'Global Search',
'search_keyword' => 'Keyword',
'search_area' => 'Range',
'search_area_options' => [
'0' => 'Title',
'1' => 'Description',
'3' => 'Uploader',
'4' => 'IMDB URL'
],
];
+2 -2
View File
@@ -14,7 +14,7 @@ return [
\App\Models\SearchBox::EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST => 'Display seed box icon on torrent list',
],
'sections' => [
'browse' => 'Torrents section',
'special' => 'Special section',
'browse' => 'Torrents',
'special' => 'Special',
],
];
+4
View File
@@ -31,4 +31,8 @@ return [
'remove_claim_confirm' => '确认要放弃认领?',
'already_claimed' => '已认领',
'not_claim_yet' => '未认领',
'fields' => [
'torrent_id' => '种子 ID',
],
];
+13
View File
@@ -0,0 +1,13 @@
<?php
return [
'global_search' => '全站搜索',
'search_keyword' => '关键字',
'search_area' => '范围',
'search_area_options' => [
'0' => '标题',
'1' => '简介',
'3' => '发布者',
'4' => 'IMDB链接'
],
];
+3
View File
@@ -30,4 +30,7 @@ return [
'remove_claim_confirm' => '確認要放棄認領?',
'already_claimed' => '已認領',
'not_claim_yet' => '未認領',
'fields' => [
'torrent_id' => '種子 ID',
],
];
+13
View File
@@ -0,0 +1,13 @@
<?php
return [
'global_search' => '全站搜索',
'search_keyword' => '關鍵字',
'search_area' => '範圍',
'search_area_options' => [
'0' => '標題',
'1' => '簡介',
'3' => '發布者',
'4' => 'IMDB鏈接'
],
];