2020-12-26 01:42:23 +08:00
< ? php
2021-01-13 19:32:26 +08:00
require_once ( " ../include/bittorrent.php " );
2020-12-26 01:42:23 +08:00
dbconn ( true );
2021-05-29 18:26:04 +08:00
require_once ( get_langfile_path ( 'torrents.php' ));
2025-04-19 02:06:51 +07:00
require_once ( get_langfile_path ( 'special.php' ));
2020-12-26 01:42:23 +08:00
loggedinorreturn ();
parked ();
2023-04-06 02:06:01 +08:00
2020-12-26 01:42:23 +08:00
//check searchbox
2022-03-20 22:14:00 +08:00
switch ( nexus () -> getScript ()) {
2021-05-29 18:26:04 +08:00
case 'torrents' :
$sectiontype = $browsecatmode ;
break ;
case 'special' :
if ( get_setting ( 'main.spsct' ) != 'yes' ) {
httperr ();
}
2022-09-14 19:05:29 +08:00
if ( ! user_can ( 'view_special_torrent' )) {
2025-04-19 02:06:51 +07:00
stderr ( $lang_special [ 'std_sorry' ], $lang_special [ 'std_permission_denied_only' ] . get_user_class_name ( get_setting ( 'authority.view_special_torrent' ), false , true , true ) . sprintf ( $lang_special [ 'std_or_above_can_view' ], \App\Models\Setting :: getSiteName ()), false );
2021-05-29 18:26:04 +08:00
}
$sectiontype = $specialcatmode ;
break ;
default :
$sectiontype = 0 ;
}
2022-10-30 17:30:24 +08:00
/**
* tags
*/
$tagRep = new \App\Repositories\TagRepository ();
$allTags = $tagRep -> listAll ( $sectiontype );
2022-12-20 22:24:31 +08:00
$filterInputWidth = 62 ;
2023-04-06 02:06:01 +08:00
$searchParams = $_GET ;
$searchParams [ 'mode' ] = $sectiontype ;
2022-10-30 17:30:24 +08:00
2020-12-26 01:42:23 +08:00
$showsubcat = get_searchbox_value ( $sectiontype , 'showsubcat' ); //whether show subcategory (i.e. sources, codecs) or not
$showsource = get_searchbox_value ( $sectiontype , 'showsource' ); //whether show sources or not
$showmedium = get_searchbox_value ( $sectiontype , 'showmedium' ); //whether show media or not
$showcodec = get_searchbox_value ( $sectiontype , 'showcodec' ); //whether show codecs or not
$showstandard = get_searchbox_value ( $sectiontype , 'showstandard' ); //whether show standards or not
$showprocessing = get_searchbox_value ( $sectiontype , 'showprocessing' ); //whether show processings or not
$showteam = get_searchbox_value ( $sectiontype , 'showteam' ); //whether show teams or not
$showaudiocodec = get_searchbox_value ( $sectiontype , 'showaudiocodec' ); //whether show audio codec or not
$catsperrow = get_searchbox_value ( $sectiontype , 'catsperrow' ); //show how many cats per line in search box
$catpadding = get_searchbox_value ( $sectiontype , 'catpadding' ); //padding space between categories in pixel
$cats = genrelist ( $sectiontype );
if ( $showsubcat ){
2022-09-14 19:05:29 +08:00
if ( $showsource ) $sources = searchbox_item_list ( " sources " , $sectiontype );
if ( $showmedium ) $media = searchbox_item_list ( " media " , $sectiontype );
if ( $showcodec ) $codecs = searchbox_item_list ( " codecs " , $sectiontype );
if ( $showstandard ) $standards = searchbox_item_list ( " standards " , $sectiontype );
if ( $showprocessing ) $processings = searchbox_item_list ( " processings " , $sectiontype );
if ( $showteam ) $teams = searchbox_item_list ( " teams " , $sectiontype );
if ( $showaudiocodec ) $audiocodecs = searchbox_item_list ( " audiocodecs " , $sectiontype );
2020-12-26 01:42:23 +08:00
}
2020-12-28 20:52:54 +08:00
$searchstr_ori = htmlspecialchars ( trim ( $_GET [ " search " ] ? ? '' ));
$searchstr = mysql_real_escape_string ( trim ( $_GET [ " search " ] ? ? '' ));
2023-04-06 02:06:01 +08:00
if ( empty ( $searchstr )) {
unset ( $searchstr );
}
2020-12-26 01:42:23 +08:00
2023-05-13 22:34:27 +08:00
$meilisearchEnabled = get_setting ( 'meilisearch.enabled' ) == 'yes' ;
2023-04-06 02:06:01 +08:00
$shouldUseMeili = $meilisearchEnabled && ! empty ( $searchstr );
do_log ( " [SHOULD_USE_MEILI]: $shouldUseMeili " );
2020-12-26 01:42:23 +08:00
// sorting by MarkoStamcar
2020-12-28 20:52:54 +08:00
$column = '' ;
$ascdesc = '' ;
if ( isset ( $_GET [ 'sort' ]) && $_GET [ 'sort' ] && isset ( $_GET [ 'type' ]) && $_GET [ 'type' ]) {
2020-12-26 01:42:23 +08:00
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 ;
}
if ( $column == " owner " )
{
$orderby = " ORDER BY pos_state DESC, torrents.anonymous, users.username " . $ascdesc ;
}
else
{
$orderby = " ORDER BY pos_state DESC, torrents. " . $column . " " . $ascdesc ;
}
$pagerlink = " sort= " . intval ( $_GET [ 'sort' ]) . " &type= " . $linkascdesc . " & " ;
} else {
$orderby = " ORDER BY pos_state DESC, torrents.id DESC " ;
$pagerlink = " " ;
}
2023-07-06 03:23:28 +08:00
$allCategoryId = \App\Models\SearchBox :: listCategoryId ( $sectiontype );
2020-12-26 01:42:23 +08:00
$addparam = " " ;
$wherea = array ();
$wherecatina = array ();
2022-10-27 20:21:54 +08:00
$wheresourceina = array ();
$wheremediumina = array ();
$wherecodecina = array ();
$wherestandardina = array ();
$whereprocessingina = array ();
$whereteamina = array ();
$whereaudiocodecina = array ();
2025-09-20 17:22:53 +07:00
$whereothera = [];
2020-12-26 01:42:23 +08:00
//----------------- start whether show torrents from all sections---------------------//
if ( $_GET )
2021-01-06 02:19:03 +08:00
$allsec = intval ( $_GET [ " allsec " ] ? ? 0 );
2020-12-26 01:42:23 +08:00
else $allsec = 0 ;
if ( $allsec == 1 ) //show torrents from all sections
{
$addparam .= " allsec=1& " ;
}
// ----------------- end whether ignoring section ---------------------//
// ----------------- start bookmarked ---------------------//
2021-02-26 13:58:12 +08:00
$inclbookmarked = 0 ;
2020-12-26 01:42:23 +08:00
if ( $_GET )
2021-01-06 01:39:45 +08:00
$inclbookmarked = intval ( $_GET [ " inclbookmarked " ] ? ? 0 );
2020-12-26 01:42:23 +08:00
elseif ( $CURUSER [ 'notifs' ]){
if ( strpos ( $CURUSER [ 'notifs' ], " [inclbookmarked=0] " ) !== false )
$inclbookmarked = 0 ;
elseif ( strpos ( $CURUSER [ 'notifs' ], " [inclbookmarked=1] " ) !== false )
$inclbookmarked = 1 ;
elseif ( strpos ( $CURUSER [ 'notifs' ], " [inclbookmarked=2] " ) !== false )
$inclbookmarked = 2 ;
}
if ( ! in_array ( $inclbookmarked , array ( 0 , 1 , 2 )))
{
$inclbookmarked = 0 ;
write_log ( " User " . $CURUSER [ " username " ] . " , " . $CURUSER [ " ip " ] . " is hacking inclbookmarked field in " . $_SERVER [ 'SCRIPT_NAME' ], 'mod' );
}
if ( $inclbookmarked == 0 ) //all(bookmarked,not)
{
$addparam .= " inclbookmarked=0& " ;
}
elseif ( $inclbookmarked == 1 ) //bookmarked
{
$addparam .= " inclbookmarked=1& " ;
if ( isset ( $CURUSER ))
$wherea [] = " torrents.id IN (SELECT torrentid FROM bookmarks WHERE userid= " . $CURUSER [ 'id' ] . " ) " ;
}
elseif ( $inclbookmarked == 2 ) //not bookmarked
{
$addparam .= " inclbookmarked=2& " ;
if ( isset ( $CURUSER ))
$wherea [] = " torrents.id NOT IN (SELECT torrentid FROM bookmarks WHERE userid= " . $CURUSER [ 'id' ] . " ) " ;
}
// ----------------- end bookmarked ---------------------//
// ----------------- start include dead ---------------------//
if ( isset ( $_GET [ " incldead " ]))
2021-01-06 01:39:45 +08:00
$include_dead = intval ( $_GET [ " incldead " ] ? ? 0 );
2020-12-26 01:42:23 +08:00
elseif ( $CURUSER [ 'notifs' ]){
if ( strpos ( $CURUSER [ 'notifs' ], " [incldead=0] " ) !== false )
$include_dead = 0 ;
elseif ( strpos ( $CURUSER [ 'notifs' ], " [incldead=1] " ) !== false )
$include_dead = 1 ;
elseif ( strpos ( $CURUSER [ 'notifs' ], " [incldead=2] " ) !== false )
$include_dead = 2 ;
else $include_dead = 1 ;
}
else $include_dead = 1 ;
if ( ! in_array ( $include_dead , array ( 0 , 1 , 2 )))
{
$include_dead = 0 ;
write_log ( " User " . $CURUSER [ " username " ] . " , " . $CURUSER [ " ip " ] . " is hacking incldead field in " . $_SERVER [ 'SCRIPT_NAME' ], 'mod' );
}
if ( $include_dead == 0 ) //all(active,dead)
{
$addparam .= " incldead=0& " ;
}
elseif ( $include_dead == 1 ) //active
{
$addparam .= " incldead=1& " ;
2025-09-20 17:22:53 +07:00
// $wherea[] = "visible = 'yes'";
$whereothera [] = " visible = 'yes' " ;
2020-12-26 01:42:23 +08:00
}
elseif ( $include_dead == 2 ) //dead
{
$addparam .= " incldead=2& " ;
2025-09-20 17:22:53 +07:00
// $wherea[] = "visible = 'no'";
$whereothera [] = " visible = 'no' " ;
2020-12-26 01:42:23 +08:00
}
// ----------------- end include dead ---------------------//
2025-09-20 17:22:53 +07:00
if ( ! isset ( $CURUSER ) || ! user_can ( 'seebanned' )) {
// $wherea[] = "banned = 'no'";
$whereothera [] = " banned = 'no' " ;
$searchParams [ " banned " ] = 'no' ;
}
2021-02-26 13:58:12 +08:00
$special_state = 0 ;
2020-12-26 01:42:23 +08:00
if ( $_GET )
2021-01-06 01:39:45 +08:00
$special_state = intval ( $_GET [ " spstate " ] ? ? 0 );
2020-12-26 01:42:23 +08:00
elseif ( $CURUSER [ 'notifs' ]){
if ( strpos ( $CURUSER [ 'notifs' ], " [spstate=0] " ) !== false )
$special_state = 0 ;
elseif ( strpos ( $CURUSER [ 'notifs' ], " [spstate=1] " ) !== false )
$special_state = 1 ;
elseif ( strpos ( $CURUSER [ 'notifs' ], " [spstate=2] " ) !== false )
$special_state = 2 ;
elseif ( strpos ( $CURUSER [ 'notifs' ], " [spstate=3] " ) !== false )
$special_state = 3 ;
elseif ( strpos ( $CURUSER [ 'notifs' ], " [spstate=4] " ) !== false )
$special_state = 4 ;
elseif ( strpos ( $CURUSER [ 'notifs' ], " [spstate=5] " ) !== false )
$special_state = 5 ;
elseif ( strpos ( $CURUSER [ 'notifs' ], " [spstate=6] " ) !== false )
$special_state = 6 ;
2022-11-09 21:56:03 +08:00
elseif ( strpos ( $CURUSER [ 'notifs' ], " [spstate=7] " ) !== false )
2020-12-26 01:42:23 +08:00
$special_state = 7 ;
}
if ( ! in_array ( $special_state , array ( 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 )))
{
$special_state = 0 ;
write_log ( " User " . $CURUSER [ " username " ] . " , " . $CURUSER [ " ip " ] . " is hacking spstate field in " . $_SERVER [ 'SCRIPT_NAME' ], 'mod' );
}
if ( $special_state == 0 ) //all
{
$addparam .= " spstate=0& " ;
}
elseif ( $special_state == 1 ) //normal
{
$addparam .= " spstate=1& " ;
$wherea [] = " sp_state = 1 " ;
if ( get_global_sp_state () == 1 )
{
$wherea [] = " sp_state = 1 " ;
}
}
elseif ( $special_state == 2 ) //free
{
$addparam .= " spstate=2& " ;
if ( get_global_sp_state () == 1 )
{
$wherea [] = " sp_state = 2 " ;
}
else if ( get_global_sp_state () == 2 )
{
;
}
}
elseif ( $special_state == 3 ) //2x up
{
$addparam .= " spstate=3& " ;
if ( get_global_sp_state () == 1 ) //only sp state
{
$wherea [] = " sp_state = 3 " ;
}
else if ( get_global_sp_state () == 3 ) //all
{
;
}
}
elseif ( $special_state == 4 ) //2x up and free
{
$addparam .= " spstate=4& " ;
if ( get_global_sp_state () == 1 ) //only sp state
{
$wherea [] = " sp_state = 4 " ;
}
else if ( get_global_sp_state () == 4 ) //all
{
;
}
}
elseif ( $special_state == 5 ) //half down
{
$addparam .= " spstate=5& " ;
if ( get_global_sp_state () == 1 ) //only sp state
{
$wherea [] = " sp_state = 5 " ;
}
else if ( get_global_sp_state () == 5 ) //all
{
;
}
}
elseif ( $special_state == 6 ) //half down
{
$addparam .= " spstate=6& " ;
if ( get_global_sp_state () == 1 ) //only sp state
{
$wherea [] = " sp_state = 6 " ;
}
else if ( get_global_sp_state () == 6 ) //all
{
;
}
}
elseif ( $special_state == 7 ) //30% down
{
$addparam .= " spstate=7& " ;
if ( get_global_sp_state () == 1 ) //only sp state
{
$wherea [] = " sp_state = 7 " ;
}
else if ( get_global_sp_state () == 7 ) //all
{
;
}
}
2021-01-06 01:39:45 +08:00
$category_get = intval ( $_GET [ " cat " ] ? ? 0 );
2020-12-28 20:52:54 +08:00
$source_get = $medium_get = $codec_get = $standard_get = $processing_get = $team_get = $audiocodec_get = 0 ;
2020-12-26 01:42:23 +08:00
if ( $showsubcat ){
2021-01-06 01:39:45 +08:00
if ( $showsource ) $source_get = intval ( $_GET [ " source " ] ? ? 0 );
if ( $showmedium ) $medium_get = intval ( $_GET [ " medium " ] ? ? 0 );
if ( $showcodec ) $codec_get = intval ( $_GET [ " codec " ] ? ? 0 );
if ( $showstandard ) $standard_get = intval ( $_GET [ " standard " ] ? ? 0 );
if ( $showprocessing ) $processing_get = intval ( $_GET [ " processing " ] ? ? 0 );
if ( $showteam ) $team_get = intval ( $_GET [ " team " ] ? ? 0 );
if ( $showaudiocodec ) $audiocodec_get = intval ( $_GET [ " audiocodec " ] ? ? 0 );
2020-12-26 01:42:23 +08:00
}
2021-01-06 01:39:45 +08:00
$all = intval ( $_GET [ " all " ] ? ? 0 );
2020-12-26 01:42:23 +08:00
if ( ! $all )
{
if ( ! $_GET && $CURUSER [ 'notifs' ])
{
$all = true ;
foreach ( $cats as $cat )
{
2020-12-28 20:52:54 +08:00
$all &= $cat [ 'id' ];
2020-12-26 01:42:23 +08:00
$mystring = $CURUSER [ 'notifs' ];
$findme = '[cat' . $cat [ 'id' ] . ']' ;
$search = strpos ( $mystring , $findme );
if ( $search === false )
$catcheck = false ;
else
$catcheck = true ;
if ( $catcheck )
{
2020-12-28 20:52:54 +08:00
$wherecatina [] = $cat [ 'id' ];
2020-12-26 01:42:23 +08:00
$addparam .= " cat $cat[id] =1& " ;
}
}
if ( $showsubcat ){
if ( $showsource )
foreach ( $sources as $source )
{
2020-12-28 20:52:54 +08:00
$all &= $source [ 'id' ];
2020-12-26 01:42:23 +08:00
$mystring = $CURUSER [ 'notifs' ];
$findme = '[sou' . $source [ 'id' ] . ']' ;
$search = strpos ( $mystring , $findme );
if ( $search === false )
$sourcecheck = false ;
else
$sourcecheck = true ;
if ( $sourcecheck )
{
2020-12-28 20:52:54 +08:00
$wheresourceina [] = $source [ 'id' ];
$addparam .= " source { $source [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showmedium )
foreach ( $media as $medium )
{
2020-12-28 20:52:54 +08:00
$all &= $medium [ 'id' ];
2020-12-26 01:42:23 +08:00
$mystring = $CURUSER [ 'notifs' ];
$findme = '[med' . $medium [ 'id' ] . ']' ;
$search = strpos ( $mystring , $findme );
if ( $search === false )
$mediumcheck = false ;
else
$mediumcheck = true ;
if ( $mediumcheck )
{
2020-12-28 20:52:54 +08:00
$wheremediumina [] = $medium [ 'id' ];
$addparam .= " medium { $medium [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showcodec )
foreach ( $codecs as $codec )
{
2020-12-28 20:52:54 +08:00
$all &= $codec [ 'id' ];
2020-12-26 01:42:23 +08:00
$mystring = $CURUSER [ 'notifs' ];
$findme = '[cod' . $codec [ 'id' ] . ']' ;
$search = strpos ( $mystring , $findme );
if ( $search === false )
$codeccheck = false ;
else
$codeccheck = true ;
if ( $codeccheck )
{
2020-12-28 20:52:54 +08:00
$wherecodecina [] = $codec [ 'id' ];
$addparam .= " codec { $codec [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showstandard )
foreach ( $standards as $standard )
{
2020-12-28 20:52:54 +08:00
$all &= $standard [ 'id' ];
2020-12-26 01:42:23 +08:00
$mystring = $CURUSER [ 'notifs' ];
$findme = '[sta' . $standard [ 'id' ] . ']' ;
$search = strpos ( $mystring , $findme );
if ( $search === false )
$standardcheck = false ;
else
$standardcheck = true ;
if ( $standardcheck )
{
2020-12-28 20:52:54 +08:00
$wherestandardina [] = $standard [ 'id' ];
$addparam .= " standard { $standard [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showprocessing )
foreach ( $processings as $processing )
{
2020-12-28 20:52:54 +08:00
$all &= $processing [ 'id' ];
2020-12-26 01:42:23 +08:00
$mystring = $CURUSER [ 'notifs' ];
$findme = '[pro' . $processing [ 'id' ] . ']' ;
$search = strpos ( $mystring , $findme );
if ( $search === false )
$processingcheck = false ;
else
$processingcheck = true ;
if ( $processingcheck )
{
2020-12-28 20:52:54 +08:00
$whereprocessingina [] = $processing [ 'id' ];
$addparam .= " processing { $processing [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showteam )
foreach ( $teams as $team )
{
2020-12-28 20:52:54 +08:00
$all &= $team [ 'id' ];
2020-12-26 01:42:23 +08:00
$mystring = $CURUSER [ 'notifs' ];
$findme = '[tea' . $team [ 'id' ] . ']' ;
$search = strpos ( $mystring , $findme );
if ( $search === false )
$teamcheck = false ;
else
$teamcheck = true ;
if ( $teamcheck )
{
2020-12-28 20:52:54 +08:00
$whereteamina [] = $team [ 'id' ];
$addparam .= " team { $team [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showaudiocodec )
foreach ( $audiocodecs as $audiocodec )
{
2020-12-28 20:52:54 +08:00
$all &= $audiocodec [ 'id' ];
2020-12-26 01:42:23 +08:00
$mystring = $CURUSER [ 'notifs' ];
$findme = '[aud' . $audiocodec [ 'id' ] . ']' ;
$search = strpos ( $mystring , $findme );
if ( $search === false )
$audiocodeccheck = false ;
else
$audiocodeccheck = true ;
if ( $audiocodeccheck )
{
2020-12-28 20:52:54 +08:00
$whereaudiocodecina [] = $audiocodec [ 'id' ];
$addparam .= " audiocodec { $audiocodec [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
2021-05-14 11:04:03 +08:00
}
2020-12-26 01:42:23 +08:00
}
// when one clicked the cat, source, etc. name/image
elseif ( $category_get )
{
int_check ( $category_get , true , true , true );
$wherecatina [] = $category_get ;
$addparam .= " cat= $category_get & " ;
}
elseif ( $medium_get )
{
int_check ( $medium_get , true , true , true );
$wheremediumina [] = $medium_get ;
$addparam .= " medium= $medium_get & " ;
}
elseif ( $source_get )
{
int_check ( $source_get , true , true , true );
$wheresourceina [] = $source_get ;
$addparam .= " source= $source_get & " ;
}
elseif ( $codec_get )
{
int_check ( $codec_get , true , true , true );
$wherecodecina [] = $codec_get ;
$addparam .= " codec= $codec_get & " ;
}
elseif ( $standard_get )
{
int_check ( $standard_get , true , true , true );
$wherestandardina [] = $standard_get ;
$addparam .= " standard= $standard_get & " ;
}
elseif ( $processing_get )
{
int_check ( $processing_get , true , true , true );
$whereprocessingina [] = $processing_get ;
$addparam .= " processing= $processing_get & " ;
}
elseif ( $team_get )
{
int_check ( $team_get , true , true , true );
$whereteamina [] = $team_get ;
$addparam .= " team= $team_get & " ;
}
elseif ( $audiocodec_get )
{
int_check ( $audiocodec_get , true , true , true );
$whereaudiocodecina [] = $audiocodec_get ;
$addparam .= " audiocodec= $audiocodec_get & " ;
}
else //select and go
{
$all = True ;
foreach ( $cats as $cat )
{
2020-12-28 20:52:54 +08:00
$__is = ( isset ( $_GET [ " cat { $cat [ 'id' ] } " ]) && $_GET [ " cat { $cat [ 'id' ] } " ]);
$all &= $__is ;
if ( $__is )
2020-12-26 01:42:23 +08:00
{
2020-12-28 20:52:54 +08:00
$wherecatina [] = $cat [ 'id' ];
$addparam .= " cat { $cat [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showsubcat ){
if ( $showsource )
foreach ( $sources as $source )
{
2020-12-28 20:52:54 +08:00
$__is = ( isset ( $_GET [ " source { $source [ 'id' ] } " ]) && $_GET [ " source { $source [ 'id' ] } " ]);
$all &= $__is ;
if ( $__is )
2020-12-26 01:42:23 +08:00
{
2020-12-28 20:52:54 +08:00
$wheresourceina [] = $source [ 'id' ];
$addparam .= " source { $source [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showmedium )
foreach ( $media as $medium )
{
2020-12-28 20:52:54 +08:00
$__is = ( isset ( $_GET [ " medium { $medium [ 'id' ] } " ]) && $_GET [ " medium { $medium [ 'id' ] } " ]);
$all &= $__is ;
if ( $__is )
2020-12-26 01:42:23 +08:00
{
2020-12-28 20:52:54 +08:00
$wheremediumina [] = $medium [ 'id' ];
$addparam .= " medium { $medium [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showcodec )
foreach ( $codecs as $codec )
{
2020-12-28 20:52:54 +08:00
$__is = ( isset ( $_GET [ " codec { $codec [ 'id' ] } " ]) && $_GET [ " codec { $codec [ 'id' ] } " ]);
$all &= $__is ;
if ( $__is )
2020-12-26 01:42:23 +08:00
{
2020-12-28 20:52:54 +08:00
$wherecodecina [] = $codec [ 'id' ];
$addparam .= " codec { $codec [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showstandard )
foreach ( $standards as $standard )
{
2020-12-28 20:52:54 +08:00
$__is = ( isset ( $_GET [ " standard { $standard [ 'id' ] } " ]) && $_GET [ " standard { $standard [ 'id' ] } " ]);
$all &= $__is ;
if ( $__is )
2020-12-26 01:42:23 +08:00
{
2020-12-28 20:52:54 +08:00
$wherestandardina [] = $standard [ 'id' ];
$addparam .= " standard { $standard [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showprocessing )
foreach ( $processings as $processing )
{
2020-12-28 20:52:54 +08:00
$__is = ( isset ( $_GET [ " processing { $processing [ 'id' ] } " ]) && $_GET [ " processing { $processing [ 'id' ] } " ]);
$all &= $__is ;
if ( $__is )
2020-12-26 01:42:23 +08:00
{
2020-12-28 20:52:54 +08:00
$whereprocessingina [] = $processing [ 'id' ];
$addparam .= " processing { $processing [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showteam )
foreach ( $teams as $team )
{
2020-12-28 20:52:54 +08:00
$__is = ( isset ( $_GET [ " team { $team [ 'id' ] } " ]) && $_GET [ " team { $team [ 'id' ] } " ]);
$all &= $__is ;
if ( $__is )
2020-12-26 01:42:23 +08:00
{
2020-12-28 20:52:54 +08:00
$whereteamina [] = $team [ 'id' ];
$addparam .= " team { $team [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $showaudiocodec )
foreach ( $audiocodecs as $audiocodec )
{
2020-12-28 20:52:54 +08:00
$__is = ( isset ( $_GET [ " audiocodec { $audiocodec [ 'id' ] } " ]) && $_GET [ " audiocodec { $audiocodec [ 'id' ] } " ]);
$all &= $__is ;
if ( $__is )
2020-12-26 01:42:23 +08:00
{
2020-12-28 20:52:54 +08:00
$whereaudiocodecina [] = $audiocodec [ 'id' ];
$addparam .= " audiocodec { $audiocodec [ 'id' ] } =1& " ;
2020-12-26 01:42:23 +08:00
}
}
}
}
}
if ( $all )
{
//stderr("in if all","");
$wherecatina = array ();
if ( $showsubcat ){
$wheresourceina = array ();
$wheremediumina = array ();
$wherecodecina = array ();
$wherestandardina = array ();
$whereprocessingina = array ();
$whereteamina = array ();
$whereaudiocodecina = array ();}
$addparam .= " " ;
}
//stderr("", count($wherecatina)."-". count($wheresourceina));
2020-12-28 20:52:54 +08:00
$wherecatin = $wheresourcein = $wheremediumin = $wherecodecin = $wherestandardin = $whereprocessingin = $whereteamin = $whereaudiocodecin = '' ;
2023-08-15 03:35:13 +08:00
if ( empty ( $wherecatina ) && ! ( in_array ( $inclbookmarked , [ 1 , 2 ]) && $allsec == 1 )) {
//require limit in some category
2023-07-06 03:23:28 +08:00
$wherecatina = $allCategoryId ;
}
2020-12-26 01:42:23 +08:00
if ( count ( $wherecatina ) > 1 )
$wherecatin = implode ( " , " , $wherecatina );
elseif ( count ( $wherecatina ) == 1 )
$wherea [] = " category = $wherecatina[0] " ;
if ( $showsubcat ){
if ( $showsource ){
if ( count ( $wheresourceina ) > 1 )
$wheresourcein = implode ( " , " , $wheresourceina );
elseif ( count ( $wheresourceina ) == 1 )
$wherea [] = " source = $wheresourceina[0] " ;}
if ( $showmedium ){
if ( count ( $wheremediumina ) > 1 )
$wheremediumin = implode ( " , " , $wheremediumina );
elseif ( count ( $wheremediumina ) == 1 )
$wherea [] = " medium = $wheremediumina[0] " ;}
if ( $showcodec ){
if ( count ( $wherecodecina ) > 1 )
$wherecodecin = implode ( " , " , $wherecodecina );
elseif ( count ( $wherecodecina ) == 1 )
$wherea [] = " codec = $wherecodecina[0] " ;}
if ( $showstandard ){
if ( count ( $wherestandardina ) > 1 )
$wherestandardin = implode ( " , " , $wherestandardina );
elseif ( count ( $wherestandardina ) == 1 )
$wherea [] = " standard = $wherestandardina[0] " ;}
if ( $showprocessing ){
if ( count ( $whereprocessingina ) > 1 )
$whereprocessingin = implode ( " , " , $whereprocessingina );
elseif ( count ( $whereprocessingina ) == 1 )
$wherea [] = " processing = $whereprocessingina[0] " ;}
}
if ( $showteam ){
if ( count ( $whereteamina ) > 1 )
$whereteamin = implode ( " , " , $whereteamina );
elseif ( count ( $whereteamina ) == 1 )
$wherea [] = " team = $whereteamina[0] " ;}
if ( $showaudiocodec ){
if ( count ( $whereaudiocodecina ) > 1 )
$whereaudiocodecin = implode ( " , " , $whereaudiocodecina );
elseif ( count ( $whereaudiocodecina ) == 1 )
$wherea [] = " audiocodec = $whereaudiocodecina[0] " ;}
$wherebase = $wherea ;
2020-12-28 20:52:54 +08:00
$search_area = 0 ;
2020-12-26 01:42:23 +08:00
if ( isset ( $searchstr ))
{
2021-05-14 11:04:03 +08:00
if ( ! isset ( $_GET [ 'notnewword' ]) || ! $_GET [ 'notnewword' ]){
2020-12-26 01:42:23 +08:00
$notnewword = " " ;
}
else {
$notnewword = " notnewword=1& " ;
}
2021-01-06 01:39:45 +08:00
$search_mode = intval ( $_GET [ " search_mode " ] ? ? 0 );
2023-03-04 13:26:20 +08:00
/**
* Deprecated search mode : 1 ( OR )
* @ since 1.8
*/
if ( ! in_array ( $search_mode , array ( 0 , 2 )))
2020-12-26 01:42:23 +08:00
{
$search_mode = 0 ;
write_log ( " User " . $CURUSER [ " username " ] . " , " . $CURUSER [ " ip " ] . " is hacking search_mode field in " . $_SERVER [ 'SCRIPT_NAME' ], 'mod' );
}
2021-01-06 01:39:45 +08:00
$search_area = intval ( $_GET [ " search_area " ] ? ? 0 ) ;
2020-12-26 01:42:23 +08:00
if ( $search_area == 4 ) {
$searchstr = ( int ) parse_imdb_id ( $searchstr );
}
$like_expression_array = array ();
unset ( $like_expression_array );
switch ( $search_mode )
{
case 0 : // AND, OR
case 1 :
{
$searchstr = str_replace ( " . " , " " , $searchstr );
$searchstr_exploded = explode ( " " , $searchstr );
$searchstr_exploded_count = 0 ;
foreach ( $searchstr_exploded as $searchstr_element )
{
$searchstr_element = trim ( $searchstr_element ); // furthur trim to ensure that multi space seperated words still work
$searchstr_exploded_count ++ ;
2025-09-08 03:05:55 +07:00
if ( $searchstr_exploded_count > 3 ) // maximum 3 keywords
2020-12-26 01:42:23 +08:00
break ;
$like_expression_array [] = " LIKE '% " . $searchstr_element . " %' " ;
}
break ;
}
case 2 : // exact
{
$like_expression_array [] = " LIKE '% " . $searchstr . " %' " ;
break ;
}
/* case 3 : // parsed
{
$like_expression_array [] = $searchstr ;
break ;
} */
}
$ANDOR = ( $search_mode == 0 ? " AND " : " OR " ); // only affects mode 0 and mode 1
switch ( $search_area )
{
case 0 : // torrent name
{
foreach ( $like_expression_array as & $like_expression_array_element )
$like_expression_array_element = " (torrents.name " . $like_expression_array_element . " OR torrents.small_descr " . $like_expression_array_element . " ) " ;
$wherea [] = implode ( $ANDOR , $like_expression_array );
break ;
}
case 1 : // torrent description
{
foreach ( $like_expression_array as & $like_expression_array_element )
2025-06-17 20:54:18 +07:00
// $like_expression_array_element = "torrents.descr". $like_expression_array_element;
$like_expression_array_element = " torrent_extras.descr " . $like_expression_array_element ;
2020-12-26 01:42:23 +08:00
$wherea [] = implode ( $ANDOR , $like_expression_array );
break ;
}
/* case 2 : // torrent small description
{
foreach ( $like_expression_array as & $like_expression_array_element )
$like_expression_array_element = " torrents.small_descr " . $like_expression_array_element ;
$wherea [] = implode ( $ANDOR , $like_expression_array );
break ;
} */
case 3 : // torrent uploader
{
foreach ( $like_expression_array as & $like_expression_array_element )
$like_expression_array_element = " users.username " . $like_expression_array_element ;
if ( ! isset ( $CURUSER )) // not registered user, only show not anonymous torrents
{
$wherea [] = implode ( $ANDOR , $like_expression_array ) . " AND torrents.anonymous = 'no' " ;
}
else
{
2022-08-20 19:11:28 +08:00
if ( user_can ( 'torrentmanage' )) // moderator or above, show all
2020-12-26 01:42:23 +08:00
{
$wherea [] = implode ( $ANDOR , $like_expression_array );
}
else // only show normal torrents and anonymous torrents from hiself
{
$wherea [] = " ( " . implode ( $ANDOR , $like_expression_array ) . " AND torrents.anonymous = 'no') OR ( " . implode ( $ANDOR , $like_expression_array ) . " AND torrents.anonymous = 'yes' AND users.id= " . $CURUSER [ " id " ] . " ) " ;
}
}
break ;
}
case 4 : //imdb url
foreach ( $like_expression_array as & $like_expression_array_element )
$like_expression_array_element = " torrents.url " . $like_expression_array_element ;
$wherea [] = implode ( $ANDOR , $like_expression_array );
break ;
default : // unkonwn
{
$search_area = 0 ;
$wherea [] = " torrents.name LIKE '% " . $searchstr . " %' " ;
write_log ( " User " . $CURUSER [ " username " ] . " , " . $CURUSER [ " ip " ] . " is hacking search_area field in " . $_SERVER [ 'SCRIPT_NAME' ], 'mod' );
break ;
}
}
$addparam .= " search_area= " . $search_area . " & " ;
$addparam .= " search= " . rawurlencode ( $searchstr ) . " & " . $notnewword ;
$addparam .= " search_mode= " . $search_mode . " & " ;
}
2022-06-24 14:55:10 +08:00
//approval status
$approvalStatusNoneVisible = get_setting ( 'torrent.approval_status_none_visible' );
2022-06-27 13:22:16 +08:00
$approvalStatusIconEnabled = get_setting ( 'torrent.approval_status_icon_enabled' );
$approvalStatus = null ;
$showApprovalStatusFilter = false ;
2022-07-05 15:36:11 +08:00
//when enable approval status icon, all user can use this filter, otherwise only staff member and approval none visible is 'no' can use
2022-08-26 01:23:50 +08:00
if ( $approvalStatusIconEnabled == 'yes' || ( user_can ( 'torrent-approval' ) && $approvalStatusNoneVisible == 'no' )) {
2022-06-27 13:22:16 +08:00
$showApprovalStatusFilter = true ;
}
//when user can use approval status filter, and pass `approval_status` parameter, will affect
//OR if [not approval can not be view] and not staff member, force to view approval allowed
if ( $showApprovalStatusFilter && isset ( $_REQUEST [ 'approval_status' ]) && is_numeric ( $_REQUEST [ 'approval_status' ])) {
$approvalStatus = intval ( $_REQUEST [ 'approval_status' ]);
$wherea [] = " torrents.approval_status = $approvalStatus " ;
2023-04-06 02:06:01 +08:00
$searchParams [ 'approval_status' ] = $approvalStatus ;
2022-10-29 19:55:51 +08:00
$addparam .= " approval_status= $approvalStatus & " ;
2022-08-26 01:23:50 +08:00
} elseif ( $approvalStatusNoneVisible == 'no' && ! user_can ( 'torrent-approval' )) {
2022-06-24 14:55:10 +08:00
$wherea [] = " torrents.approval_status = " . \App\Models\Torrent :: APPROVAL_STATUS_ALLOW ;
2023-04-06 02:06:01 +08:00
$searchParams [ 'approval_status' ] = \App\Models\Torrent :: APPROVAL_STATUS_ALLOW ;
2022-06-24 14:55:10 +08:00
}
2022-12-20 22:24:31 +08:00
if ( isset ( $_GET [ 'size_begin' ]) && ctype_digit ( $_GET [ 'size_begin' ])) {
$wherea [] = " torrents.size >= " . intval ( $_GET [ 'size_begin' ]) * 1024 * 1024 * 1024 ;
2023-04-09 16:49:35 +08:00
$addparam .= " size_begin= " . intval ( $_GET [ 'size_begin' ]) . " & " ;
2022-12-20 22:24:31 +08:00
}
if ( isset ( $_GET [ 'size_end' ]) && ctype_digit ( $_GET [ 'size_end' ])) {
$wherea [] = " torrents.size <= " . intval ( $_GET [ 'size_end' ]) * 1024 * 1024 * 1024 ;
2023-04-09 16:49:35 +08:00
$addparam .= " size_end= " . intval ( $_GET [ 'size_end' ]) . " & " ;
2022-12-20 22:24:31 +08:00
}
if ( isset ( $_GET [ 'seeders_begin' ]) && ctype_digit ( $_GET [ 'seeders_begin' ])) {
$wherea [] = " torrents.seeders >= " . ( int ) $_GET [ 'seeders_begin' ];
2023-04-09 16:49:35 +08:00
$addparam .= " seeders_begin= " . intval ( $_GET [ 'seeders_begin' ]) . " & " ;
2022-12-20 22:24:31 +08:00
}
if ( isset ( $_GET [ 'seeders_end' ]) && ctype_digit ( $_GET [ 'seeders_end' ])) {
$wherea [] = " torrents.seeders <= " . ( int ) $_GET [ 'seeders_end' ];
2023-04-09 16:49:35 +08:00
$addparam .= " seeders_end= " . intval ( $_GET [ 'seeders_end' ]) . " & " ;
2022-12-20 22:24:31 +08:00
}
if ( isset ( $_GET [ 'leechers_begin' ]) && ctype_digit ( $_GET [ 'leechers_begin' ])) {
$wherea [] = " torrents.leechers >= " . ( int ) $_GET [ 'leechers_begin' ];
2023-04-09 16:49:35 +08:00
$addparam .= " leechers_begin= " . intval ( $_GET [ 'leechers_begin' ]) . " & " ;
2022-12-20 22:24:31 +08:00
}
if ( isset ( $_GET [ 'leechers_end' ]) && ctype_digit ( $_GET [ 'leechers_end' ])) {
$wherea [] = " torrents.leechers <= " . ( int ) $_GET [ 'leechers_end' ];
2023-04-09 16:49:35 +08:00
$addparam .= " leechers_end= " . intval ( $_GET [ 'leechers_end' ]) . " & " ;
2022-12-20 22:24:31 +08:00
}
if ( isset ( $_GET [ 'times_completed_begin' ]) && ctype_digit ( $_GET [ 'times_completed_begin' ])) {
$wherea [] = " torrents.times_completed >= " . ( int ) $_GET [ 'times_completed_begin' ];
2023-04-09 16:49:35 +08:00
$addparam .= " times_completed_begin= " . intval ( $_GET [ 'times_completed_begin' ]) . " & " ;
2022-12-20 22:24:31 +08:00
}
if ( isset ( $_GET [ 'times_completed_end' ]) && ctype_digit ( $_GET [ 'times_completed_end' ])) {
$wherea [] = " torrents.times_completed <= " . ( int ) $_GET [ 'times_completed_end' ];
2023-04-09 16:49:35 +08:00
$addparam .= " times_completed_end= " . intval ( $_GET [ 'times_completed_end' ]) . " & " ;
2022-12-20 22:24:31 +08:00
}
if ( isset ( $_GET [ 'added_begin' ]) && ! empty ( $_GET [ 'added_begin' ])) {
$wherea [] = " torrents.added >= " . sqlesc ( $_GET [ 'added_begin' ]);
2023-04-09 16:49:35 +08:00
$addparam .= " added_begin= " . $_GET [ 'added_begin' ] . " & " ;
2022-12-20 22:24:31 +08:00
}
if ( isset ( $_GET [ 'added_end' ]) && ! empty ( $_GET [ 'added_end' ])) {
$wherea [] = " torrents.added <= " . sqlesc ( \Carbon\Carbon :: parse ( $_GET [ 'added_end' ]) -> endOfDay () -> toDateTimeString ());
2023-04-09 16:49:35 +08:00
$addparam .= " added_end= " . $_GET [ 'added_end' ] . " & " ;
2022-12-20 22:24:31 +08:00
}
2020-12-26 01:42:23 +08:00
$where = implode ( " AND " , $wherea );
if ( $wherecatin )
$where .= ( $where ? " AND " : " " ) . " category IN( " . $wherecatin . " ) " ;
if ( $showsubcat ){
if ( $wheresourcein )
$where .= ( $where ? " AND " : " " ) . " source IN( " . $wheresourcein . " ) " ;
if ( $wheremediumin )
$where .= ( $where ? " AND " : " " ) . " medium IN( " . $wheremediumin . " ) " ;
if ( $wherecodecin )
$where .= ( $where ? " AND " : " " ) . " codec IN( " . $wherecodecin . " ) " ;
if ( $wherestandardin )
$where .= ( $where ? " AND " : " " ) . " standard IN( " . $wherestandardin . " ) " ;
if ( $whereprocessingin )
$where .= ( $where ? " AND " : " " ) . " processing IN( " . $whereprocessingin . " ) " ;
if ( $whereteamin )
$where .= ( $where ? " AND " : " " ) . " team IN( " . $whereteamin . " ) " ;
if ( $whereaudiocodecin )
$where .= ( $where ? " AND " : " " ) . " audiocodec IN( " . $whereaudiocodecin . " ) " ;
}
2025-09-20 17:22:53 +07:00
//last
if ( ! empty ( $whereothera )) {
$where .= ( $where ? " AND " : " " ) . implode ( " AND " , $whereothera );
}
2020-12-26 01:42:23 +08:00
2022-03-08 15:08:56 +08:00
$tagFilter = " " ;
$tagId = intval ( $_REQUEST [ 'tag_id' ] ? ? 0 );
if ( $tagId > 0 ) {
$tagFilter = " inner join torrent_tags on torrents.id = torrent_tags.torrent_id and torrent_tags.tag_id = $tagId " ;
2022-03-09 20:07:39 +08:00
$addparam .= " tag_id= { $tagId } & " ;
2022-03-08 15:08:56 +08:00
}
2025-06-17 20:54:18 +07:00
$torrentExtraFilter = " " ;
if ( $search_area == 1 ) {
$torrentExtraFilter = " inner join torrent_extras on torrents.id = torrent_extras.torrent_id " ;
}
2020-12-26 01:42:23 +08:00
if ( $allsec == 1 || $enablespecial != 'yes' )
{
if ( $where != " " )
$where = " WHERE $where " ;
else $where = " " ;
2025-06-17 20:54:18 +07:00
$sql = " SELECT COUNT(*) FROM torrents " . ( $search_area == 3 || $column == " owner " ? " LEFT JOIN users ON torrents.owner = users.id " : " " ) . $tagFilter . $torrentExtraFilter . $where ;
2020-12-26 01:42:23 +08:00
}
else
{
2023-07-06 03:23:28 +08:00
// if ($where != "")
// $where = "WHERE $where AND categories.mode = '$sectiontype'";
// else $where = "WHERE categories.mode = '$sectiontype'";
if ( $where != " " )
$where = " WHERE $where " ;
else $where = " " ;
// $sql = "SELECT COUNT(*), categories.mode FROM torrents LEFT JOIN categories ON category = categories.id " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $where . " GROUP BY categories.mode";
2025-06-17 20:54:18 +07:00
$sql = " SELECT COUNT(*) FROM torrents " . ( $search_area == 3 || $column == " owner " ? " LEFT JOIN users ON torrents.owner = users.id " : " " ) . $tagFilter . $torrentExtraFilter . $where ;
2020-12-26 01:42:23 +08:00
}
2023-04-06 02:06:01 +08:00
if ( $shouldUseMeili ) {
$searchRep = new \App\Repositories\MeiliSearchRepository ();
$resultFromSearchRep = $searchRep -> search ( $searchParams , $CURUSER [ 'id' ]);
$count = $resultFromSearchRep [ 'total' ];
2022-03-26 04:27:04 +08:00
} else {
2025-09-20 00:45:53 +07:00
do_log ( " [BEFORE_TORRENT_COUNT_SQL] " , 'debug' );
2022-03-26 04:27:04 +08:00
$res = sql_query ( $sql );
2025-09-20 00:45:53 +07:00
do_log ( " [AFTER_TORRENT_COUNT_SQL] $sql " , 'debug' );
2022-03-26 04:27:04 +08:00
$count = 0 ;
while ( $row = mysql_fetch_array ( $res )) {
$count += $row [ 0 ];
}
}
2025-09-22 20:26:08 +07:00
$maxPageSize = 100 ;
if ( ! empty ( $_GET [ 'pageSize' ])) {
2025-09-22 21:09:06 +08:00
$torrentsperpage = $_GET [ 'pageSize' ];
2025-09-22 20:26:08 +07:00
} elseif ( $CURUSER [ " torrentsperpage " ]) {
2025-09-22 21:09:06 +08:00
$torrentsperpage = ( int ) $CURUSER [ " torrentsperpage " ];
2025-09-22 20:26:08 +07:00
} elseif ( $torrentsperpage_main ) {
$torrentsperpage = $torrentsperpage_main ;
} else {
$torrentsperpage = $maxPageSize ;
}
$torrentsperpage = min ( $maxPageSize , $torrentsperpage );
2020-12-26 01:42:23 +08:00
if ( $count )
{
2023-07-07 16:31:38 +08:00
if ( isset ( $searchstr ) && ( ! isset ( $_GET [ 'notnewword' ]) || ! $_GET [ 'notnewword' ])){
insert_suggest ( $searchstr , $CURUSER [ 'id' ]);
}
2020-12-26 01:42:23 +08:00
if ( $addparam != " " )
{
if ( $pagerlink != " " )
{
2020-12-28 20:52:54 +08:00
if ( $addparam [ strlen ( $addparam ) - 1 ] != " ; " )
2020-12-26 01:42:23 +08:00
{ // & = &
$addparam = $addparam . " & " . $pagerlink ;
}
else
{
$addparam = $addparam . $pagerlink ;
}
}
}
else
{
//stderr("in else","");
$addparam = $pagerlink ;
}
//stderr("addparam",$addparam);
//echo $addparam;
2022-06-08 14:15:59 +08:00
list ( $pagertop , $pagerbottom , $limit , $offset , $size , $page ) = pager ( $torrentsperpage , $count , " ? " . $addparam );
$fieldsStr = implode ( ', ' , \App\Models\Torrent :: getFieldsForList ( true ));
2022-10-22 20:52:08 +08:00
// 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 {
2023-07-06 03:23:28 +08:00
// $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";
2025-06-17 20:54:18 +07:00
$query = " SELECT $fieldsStr , $sectiontype as search_box_id FROM torrents " . ( $search_area == 3 || $column == " owner " ? " LEFT JOIN users ON torrents.owner = users.id " : " " ) . " $tagFilter $torrentExtraFilter $where $orderby $limit " ;
2022-10-22 20:52:08 +08:00
// }
2025-09-20 19:41:29 +07:00
2023-04-06 02:06:01 +08:00
if ( ! $shouldUseMeili ) {
2025-09-20 19:41:29 +07:00
do_log ( " [BEFORE_TORRENT_LIST_SQL] " , 'debug' );
2022-03-26 04:27:04 +08:00
$res = sql_query ( $query );
2025-09-20 19:41:29 +07:00
do_log ( " [AFTER_TORRENT_LIST_SQL] $query " , 'debug' );
2022-03-26 04:27:04 +08:00
}
} else {
unset ( $res );
2020-12-26 01:42:23 +08:00
}
if ( isset ( $searchstr ))
stdhead ( $lang_torrents [ 'head_search_results_for' ] . $searchstr_ori );
elseif ( $sectiontype == $browsecatmode )
stdhead ( $lang_torrents [ 'head_torrents' ]);
2021-06-04 21:04:12 +08:00
else stdhead ( $lang_torrents [ 'head_special' ]);
2021-05-26 21:38:39 +08:00
print ( " <table width= \" 97% \" class= \" main \" border= \" 0 \" cellspacing= \" 0 \" cellpadding= \" 0 \" ><tr><td class= \" embedded \" > " );
2021-03-05 02:05:27 +08:00
displayHotAndClassic ();
2023-02-08 13:33:25 +08:00
$searchBoxRightTdStyle = 'padding: 1px;padding-left: 10px;white-space: nowrap' ;
2020-12-26 01:42:23 +08:00
if ( $allsec != 1 || $enablespecial != 'yes' ){ //do not print searchbox if showing bookmarked torrents from all sections;
?>
< form method = " get " name = " searchbox " action = " ? " >
< table border = " 1 " class = " searchbox " cellspacing = " 0 " cellpadding = " 5 " width = " 100% " >
< tbody >
< tr >
2021-03-04 10:35:55 +08:00
< td class = " colhead " align = " center " colspan = " 2 " >< a href = " javascript: klappe_news('searchboxmain') " >< img class = " plus " src = " pic/trans.gif " id = " picsearchboxmain " alt = " Show/Hide " />< ? php echo $lang_torrents [ 'text_search_box' ] ?> </a></td>
2020-12-26 01:42:23 +08:00
</ tr ></ tbody >
2021-03-04 10:35:55 +08:00
< tbody id = " ksearchboxmain " style = " display:none " >
2020-12-26 01:42:23 +08:00
< tr >
< td class = " rowfollow " align = " left " >
2022-10-27 20:21:54 +08:00
<!-- < table >-->
<!-- -->< ? php
// function printcat($name, $listarray, $cbname, $wherelistina, $btname, $showimg = false)
// {
// global $catpadding,$catsperrow,$lang_torrents,$CURUSER,$CURLANGDIR,$catimgurl;
//
// print("<tr><td class=\"embedded\" colspan=\"".$catsperrow."\" align=\"left\"><b>".$name."</b></td></tr><tr>");
// $i = 0;
// foreach($listarray as $list){
// if ($i && $i % $catsperrow == 0){
// print("</tr><tr>");
// }
// print("<td align=\"left\" class=\"bottom\" style=\"padding-bottom: 4px; padding-left: ".$catpadding."px;\"><input type=\"checkbox\" id=\"".$cbname.$list['id']."\" name=\"".$cbname.$list['id']."\"" . (in_array($list['id'],$wherelistina) ? " checked=\"checked\"" : "") . " value=\"1\" />".($showimg ? return_category_image($list['id'], "?") : "<a title=\"" .$list['name'] . "\" href=\"?".$cbname."=".$list['id']."\">".$list['name']."</a>")."</td>\n");
// $i++;
// }
// $checker = "<input name=\"".$btname."\" value='" . $lang_torrents['input_check_all'] . "' class=\"btn medium\" type=\"button\" onclick=\"javascript:SetChecked('".$cbname."','".$btname."','". $lang_torrents['input_check_all'] ."','" . $lang_torrents['input_uncheck_all'] . "',-1,10)\" />";
// print("<td colspan=\"2\" class=\"bottom\" align=\"left\" style=\"padding-left: 15px\">".$checker."</td>\n");
// print("</tr>");
// }
// printcat($lang_torrents['text_category'],$cats,"cat",$wherecatina,"cat_check",true);
//
// if ($showsubcat){
// if ($showsource)
// printcat($lang_torrents['text_source'], $sources, "source", $wheresourceina, "source_check");
// if ($showmedium)
// printcat($lang_torrents['text_medium'], $media, "medium", $wheremediumina, "medium_check");
// if ($showcodec)
// printcat($lang_torrents['text_codec'], $codecs, "codec", $wherecodecina, "codec_check");
// if ($showaudiocodec)
// printcat($lang_torrents['text_audio_codec'], $audiocodecs, "audiocodec", $whereaudiocodecina, "audiocodec_check");
// if ($showstandard)
// printcat($lang_torrents['text_standard'], $standards, "standard", $wherestandardina, "standard_check");
// if ($showprocessing)
// printcat($lang_torrents['text_processing'], $processings, "processing", $whereprocessingina, "processing_check");
// if ($showteam)
// printcat($lang_torrents['text_team'], $teams, "team", $whereteamina, "team_check");
// }
// ?>
<!-- </ table >-->
2022-11-24 18:51:03 +08:00
< ? php echo build_search_box_category_table ( $sectiontype , '1' , '?' , '?' , 0 , $_SERVER [ 'QUERY_STRING' ], [ 'select_unselect' => true , 'user_notifs' => $CURUSER [ 'notifs' ]]) ?>
2020-12-26 01:42:23 +08:00
</ td >
2021-05-14 11:04:03 +08:00
2020-12-26 01:42:23 +08:00
< td class = " rowfollow " valign = " middle " >
< table >
< tr >
< td class = " bottom " style = " padding: 1px;padding-left: 10px " >
< font class = " medium " >< ? php echo $lang_torrents [ 'text_show_dead_active' ] ?> </font>
</ td >
2021-05-14 11:04:03 +08:00
</ tr >
2020-12-26 01:42:23 +08:00
< tr >
< td class = " bottom " style = " padding: 1px;padding-left: 10px " >
< select class = " med " name = " incldead " style = " width: 100px; " >
< option value = " 0 " >< ? php echo $lang_torrents [ 'select_including_dead' ] ?> </option>
< option value = " 1 " < ? php print ( $include_dead == 1 ? " selected= \" selected \" " : " " ); ?> ><?php echo $lang_torrents['select_active'] ?> </option>
< option value = " 2 " < ? php print ( $include_dead == 2 ? " selected= \" selected \" " : " " ); ?> ><?php echo $lang_torrents['select_dead'] ?></option>
</ select >
</ td >
</ tr >
< tr >
< td class = " bottom " style = " padding: 1px;padding-left: 10px " >
< font class = " medium " >< ? php echo $lang_torrents [ 'text_show_special_torrents' ] ?> </font>
</ td >
</ tr >
< tr >
< td class = " bottom " style = " padding: 1px;padding-left: 10px " >
< select class = " med " name = " spstate " style = " width: 100px; " >
< option value = " 0 " >< ? php echo $lang_torrents [ 'select_all' ] ?> </option>
< ? php echo promotion_selection ( $special_state , 0 ) ?>
</ select >
</ td >
</ tr >
< tr >
< td class = " bottom " style = " padding: 1px;padding-left: 10px " >
< font class = " medium " >< ? php echo $lang_torrents [ 'text_show_bookmarked' ] ?> </font>
</ td >
</ tr >
< tr >
< td class = " bottom " style = " padding: 1px;padding-left: 10px " >
< select class = " med " name = " inclbookmarked " style = " width: 100px; " >
< option value = " 0 " >< ? php echo $lang_torrents [ 'select_all' ] ?> </option>
< option value = " 1 " < ? php print ( $inclbookmarked == 1 ? " selected= \" selected \" " : " " ); ?> ><?php echo $lang_torrents['select_bookmarked'] ?></option>
< option value = " 2 " < ? php print ( $inclbookmarked == 2 ? " selected= \" selected \" " : " " ); ?> ><?php echo $lang_torrents['select_bookmarked_exclude'] ?></option>
</ select >
</ td >
</ tr >
2022-06-27 13:22:16 +08:00
< ? php if ( $showApprovalStatusFilter ) { ?>
< tr >
< td class = " bottom " style = " padding: 1px;padding-left: 10px " >
< font class = " medium " >< ? php echo $lang_torrents [ 'text_approval_status' ] ?> </font>
</ td >
</ tr >
< tr >
< td class = " bottom " style = " padding: 1px;padding-left: 10px " >
< select class = " med " name = " approval_status " style = " width: 100px; " >
2022-07-02 21:22:12 +08:00
< option value = " " >< ? php echo $lang_torrents [ 'select_all' ] ?> </option>
2022-06-27 13:22:16 +08:00
< ? php
foreach ( \App\Models\Torrent :: listApprovalStatus ( true ) as $key => $value ) {
2022-07-02 21:22:12 +08:00
printf ( '<option value="%s"%s>%s</option>' , $key , isset ( $approvalStatus ) && ( string ) $approvalStatus === ( string ) $key ? ' selected' : '' , $value );
2022-06-27 13:22:16 +08:00
}
?>
</ select >
</ td >
</ tr >
< ? php } ?>
2022-12-20 22:24:31 +08:00
< tr >
2023-02-08 13:33:25 +08:00
< td class = " bottom " style = " <?php echo $searchBoxRightTdStyle ?> " >
2022-12-20 22:24:31 +08:00
< font class = " medium " >< ? php echo $lang_torrents [ 'size_range' ] ?> </font>
</ td >
</ tr >
< tr >
2023-02-08 13:33:25 +08:00
< td class = " bottom " style = " <?php echo $searchBoxRightTdStyle ?> " >
2022-12-20 22:24:31 +08:00
< input type = " number " min = " 1 " name = " size_begin " style = " width: <?php echo $filterInputWidth ?>px " value = " <?php echo htmlspecialchars( $_GET['size_begin'] ?? '') ?> " /> ~ < input type = " number " min = " 1 " name = " size_end " style = " width: <?php echo $filterInputWidth ?>px " value = " <?php echo htmlspecialchars( $_GET['size_end'] ?? '') ?> " />
</ td >
</ tr >
< tr >
2023-02-08 13:33:25 +08:00
< td class = " bottom " style = " <?php echo $searchBoxRightTdStyle ?> " >
2022-12-21 00:37:21 +08:00
< font class = " medium " >< ? php echo $lang_torrents [ 'seeders_range' ] ?> </font>
2022-12-20 22:24:31 +08:00
</ td >
</ tr >
< tr >
2023-02-08 13:33:25 +08:00
< td class = " bottom " style = " <?php echo $searchBoxRightTdStyle ?> " >
2022-12-21 00:37:21 +08:00
< input type = " number " min = " 1 " name = " seeders_begin " style = " width: <?php echo $filterInputWidth ?>px " value = " <?php echo htmlspecialchars( $_GET['seeders_begin'] ?? '') ?> " /> ~ < input type = " number " min = " 1 " name = " seeders_end " style = " width: <?php echo $filterInputWidth ?>px " value = " <?php echo htmlspecialchars( $_GET['seeders_end'] ?? '') ?> " />
2022-12-20 22:24:31 +08:00
</ td >
</ tr >
< tr >
2023-02-08 13:33:25 +08:00
< td class = " bottom " style = " <?php echo $searchBoxRightTdStyle ?> " >
2022-12-21 00:37:21 +08:00
< font class = " medium " >< ? php echo $lang_torrents [ 'leechers_range' ] ?> </font>
2022-12-20 22:24:31 +08:00
</ td >
</ tr >
< tr >
2023-02-08 13:33:25 +08:00
< td class = " bottom " style = " <?php echo $searchBoxRightTdStyle ?> " >
2022-12-21 00:37:21 +08:00
< input type = " number " min = " 1 " name = " leechers_begin " style = " width: <?php echo $filterInputWidth ?>px " value = " <?php echo htmlspecialchars( $_GET['leechers_begin'] ?? '') ?> " /> ~ < input type = " number " min = " 1 " name = " leechers_end " style = " width: <?php echo $filterInputWidth ?>px " value = " <?php echo htmlspecialchars( $_GET['leechers_end'] ?? '') ?> " />
2022-12-20 22:24:31 +08:00
</ td >
</ tr >
< tr >
2023-02-08 13:33:25 +08:00
< td class = " bottom " style = " <?php echo $searchBoxRightTdStyle ?> " >
2022-12-20 22:24:31 +08:00
< font class = " medium " >< ? php echo $lang_torrents [ 'times_completed_range' ] ?> </font>
</ td >
</ tr >
< tr >
2023-02-08 13:33:25 +08:00
< td class = " bottom " style = " <?php echo $searchBoxRightTdStyle ?> " >
2022-12-20 22:24:31 +08:00
< input type = " number " min = " 1 " name = " times_completed_begin " style = " width: <?php echo $filterInputWidth ?>px " value = " <?php echo htmlspecialchars( $_GET['times_completed_begin'] ?? '') ?> " /> ~ < input type = " number " min = " 1 " name = " times_completed_end " style = " width: <?php echo $filterInputWidth ?>px " value = " <?php echo htmlspecialchars( $_GET['times_completed_end'] ?? '') ?> " />
</ td >
</ tr >
< tr >
2023-02-08 13:33:25 +08:00
< td class = " bottom " style = " <?php echo $searchBoxRightTdStyle ?> " >
2022-12-20 22:24:31 +08:00
< font class = " medium " >< ? php echo $lang_torrents [ 'added_range' ] ?> </font>
</ td >
</ tr >
< tr >
2023-02-08 13:33:25 +08:00
< td class = " bottom " style = " <?php echo $searchBoxRightTdStyle ?> " >
2022-12-20 22:24:31 +08:00
< ? php echo sprintf (
'%s ~ %s' ,
datetimepicker_input ( 'added_begin' , htmlspecialchars ( $_GET [ 'added_begin' ] ? ? '' ), '' , [ 'require_files' => true , 'format' => 'Y-m-d' , 'style' => 'width: ' . $filterInputWidth . 'px' ]),
datetimepicker_input ( 'added_end' , htmlspecialchars ( $_GET [ 'added_end' ] ? ? '' ), '' , [ 'require_files' => false , 'format' => 'Y-m-d' , 'style' => 'width: ' . $filterInputWidth . 'px' ]),
) ?>
</ td >
</ tr >
2020-12-26 01:42:23 +08:00
</ table >
</ td >
</ tr >
</ tbody >
< tbody >
< tr >
< td class = " rowfollow " align = " center " >
< table >
< tr >
< td class = " embedded " >
< ? php echo $lang_torrents [ 'text_search' ] ?>
</ td >
< td class = " embedded " >
< table >
< tr >
< td class = " embedded " >
< input id = " searchinput " name = " search " type = " text " value = " <?php echo $searchstr_ori ?> " autocomplete = " off " style = " width: 200px " ondblclick = " suggest(event.keyCode,this.value); " onkeyup = " suggest(event.keyCode,this.value); " onkeypress = " return noenter(event.keyCode); " />
2022-05-07 22:11:24 +08:00
< script src = " js/suggest.js " type = " text/javascript " ></ script >
2020-12-26 01:42:23 +08:00
< div id = " suggcontainer " style = " text-align: left; width:100px; display: none; " >
< div id = " suggestions " style = " width:204px; border: 1px solid rgb(119, 119, 119); cursor: default; position: absolute; color: rgb(0,0,0); background-color: rgb(255, 255, 255); " ></ div >
</ div >
</ td >
</ tr >
</ table >
</ td >
< td class = " embedded " >
< ? php echo " " . $lang_torrents [ 'text_in' ] ?>
< select name = " search_area " >
< option value = " 0 " >< ? php echo $lang_torrents [ 'select_title' ] ?> </option>
2020-12-28 20:52:54 +08:00
< option value = " 1 " < ? php print ( isset ( $_GET [ " search_area " ]) && $_GET [ " search_area " ] == 1 ? " selected= \" selected \" " : " " ); ?> ><?php echo $lang_torrents['select_description'] ?></option>
2020-12-26 01:42:23 +08:00
< ? php
/* if ( $smalldescription_main == 'yes' ){
?>
< option value = " 2 " < ? php print ( $_GET [ " search_area " ] == 2 ? " selected= \" selected \" " : " " ); ?> ><?php echo $lang_torrents['select_small_description'] ?></option>
< ? php
} */
?>
2020-12-28 20:52:54 +08:00
< option value = " 3 " < ? php print ( isset ( $_GET [ " search_area " ]) && $_GET [ " search_area " ] == 3 ? " selected= \" selected \" " : " " ); ?> ><?php echo $lang_torrents['select_uploader'] ?></option>
< option value = " 4 " < ? php print ( isset ( $_GET [ " search_area " ]) && $_GET [ " search_area " ] == 4 ? " selected= \" selected \" " : " " ); ?> ><?php echo $lang_torrents['select_imdb_url'] ?></option>
2020-12-26 01:42:23 +08:00
</ select >
< ? php echo $lang_torrents [ 'text_with' ] ?>
< select name = " search_mode " style = " width: 60px; " >
2023-05-11 02:23:19 +08:00
< ? php echo \App\Models\SearchBox :: listSelectModeOptions ( $_GET [ " search_mode " ] ? ? " " ) ?>
2020-12-26 01:42:23 +08:00
</ select >
2021-05-14 11:04:03 +08:00
2020-12-26 01:42:23 +08:00
< ? php echo $lang_torrents [ 'text_mode' ] ?>
</ td >
</ tr >
< ? php
$Cache -> new_page ( 'hot_search' , 3670 , true );
if ( ! $Cache -> get_page ()){
$secs = 3 * 24 * 60 * 60 ;
$dt = sqlesc ( date ( " Y-m-d H:i:s " ,( TIMENOW - $secs )));
$dt2 = sqlesc ( date ( " Y-m-d H:i:s " ,( TIMENOW - $secs * 2 )));
sql_query ( " DELETE FROM suggest WHERE adddate < " . $dt2 ) or sqlerr ();
$searchres = sql_query ( " SELECT keywords, COUNT(DISTINCT userid) as count FROM suggest WHERE adddate > " . $dt . " GROUP BY keywords ORDER BY count DESC LIMIT 15 " ) or sqlerr ();
$hotcount = 0 ;
$hotsearch = " " ;
while ( $searchrow = mysql_fetch_assoc ( $searchres ))
{
2022-09-27 22:06:05 +08:00
$hotsearch .= " <a href= \" " . htmlspecialchars ( " ?search= " . rawurlencode ( $searchrow [ " keywords " ]) . " ¬newword=1 " ) . " \" ><u> " . htmlspecialchars ( $searchrow [ " keywords " ]) . " </u></a> " ;
2020-12-26 01:42:23 +08:00
$hotcount += mb_strlen ( $searchrow [ " keywords " ], " UTF-8 " );
if ( $hotcount > 60 )
break ;
}
$Cache -> add_whole_row ();
if ( $hotsearch )
print ( " <tr><td class= \" embedded \" colspan= \" 3 \" > " . $hotsearch . " </td></tr> " );
$Cache -> end_whole_row ();
$Cache -> cache_page ();
}
echo $Cache -> next_row ();
2022-03-08 15:08:56 +08:00
2022-09-17 20:38:54 +08:00
if ( $allTags -> isNotEmpty ()) {
2022-10-30 17:30:24 +08:00
echo '<tr><td colspan="3" class="embedded" style="padding-top: 4px">' . $tagRep -> renderSpan ( $sectiontype , [ '*' ], true ) . '</td></tr>' ;
2022-03-08 15:08:56 +08:00
}
2020-12-26 01:42:23 +08:00
?>
2022-03-08 15:08:56 +08:00
2020-12-26 01:42:23 +08:00
</ table >
</ td >
< td class = " rowfollow " align = " center " >
< input type = " submit " class = " btn " value = " <?php echo $lang_torrents['submit_go'] ?> " />
</ td >
</ tr >
</ tbody >
</ table >
</ form >
< ? php
}
if ( $Advertisement -> enable_ad ()){
2020-12-28 20:52:54 +08:00
$belowsearchboxad = $Advertisement -> get_ad ( 'belowsearchbox' );
if ( ! empty ( $belowsearchboxad [ 0 ])) {
2022-05-07 22:11:24 +08:00
echo " <div align= \" center \" style= \" margin-top: 10px \" id= \" \" > " . $belowsearchboxad [ 0 ] . " </div> " ;
2020-12-28 20:52:54 +08:00
}
2020-12-26 01:42:23 +08:00
}
if ( $inclbookmarked == 1 )
{
print ( " <h1 align= \" center \" > " . get_username ( $CURUSER [ 'id' ]) . $lang_torrents [ 'text_s_bookmarked_torrent' ] . " </h1> " );
}
elseif ( $inclbookmarked == 2 )
{
print ( " <h1 align= \" center \" > " . get_username ( $CURUSER [ 'id' ]) . $lang_torrents [ 'text_s_not_bookmarked_torrent' ] . " </h1> " );
}
if ( $count ) {
2021-03-16 21:12:27 +08:00
$rows = [];
2023-04-06 02:06:01 +08:00
if ( $shouldUseMeili ) {
$rows = $resultFromSearchRep [ 'list' ];
2022-03-26 04:27:04 +08:00
} else {
while ( $row = mysql_fetch_assoc ( $res )) {
$rows [] = $row ;
}
2021-03-16 21:12:27 +08:00
}
2022-11-10 01:52:41 +08:00
$rows = apply_filter ( 'torrent_list' , $rows , $page , $sectiontype , $_GET [ 'search' ] ? ? '' );
2020-12-26 01:42:23 +08:00
print ( $pagertop );
if ( $sectiontype == $browsecatmode )
2022-09-02 19:49:41 +08:00
torrenttable ( $rows , " torrents " , $sectiontype );
2021-05-14 11:04:03 +08:00
elseif ( $sectiontype == $specialcatmode )
2022-09-02 19:49:41 +08:00
torrenttable ( $rows , " music " , $sectiontype );
else torrenttable ( $rows , " bookmarks " , $sectiontype );
2020-12-26 01:42:23 +08:00
print ( $pagerbottom );
}
else {
if ( isset ( $searchstr )) {
print ( " <br /> " );
stdmsg ( $lang_torrents [ 'std_search_results_for' ] . $searchstr_ori . " \" " , $lang_torrents [ 'std_try_again' ]);
}
else {
stdmsg ( $lang_torrents [ 'std_nothing_found' ], $lang_torrents [ 'std_no_active_torrents' ]);
}
}
if ( $CURUSER ){
if ( $sectiontype == $browsecatmode )
$USERUPDATESET [] = " last_browse = " . TIMENOW ;
else $USERUPDATESET [] = " last_music = " . TIMENOW ;
}
print ( " </td></tr></table> " );
stdfoot ();