2020-12-26 01:42:23 +08:00
< ? php
2022-06-14 14:41:22 +08:00
2022-10-27 20:21:54 +08:00
use App\Models\SearchBox ;
2022-12-08 03:48:20 +08:00
use Illuminate\Support\HtmlString ;
2022-08-04 00:48:42 +08:00
use Illuminate\Support\Str ;
2022-07-02 21:22:12 +08:00
function get_langfolder_cookie ( $transToLocale = false )
2020-12-26 01:42:23 +08:00
{
global $deflang ;
2022-07-02 21:22:12 +08:00
$lang = " " ;
2020-12-26 01:42:23 +08:00
if ( ! isset ( $_COOKIE [ " c_lang_folder " ])) {
2022-07-02 21:22:12 +08:00
$lang = $deflang ;
2020-12-26 01:42:23 +08:00
} else {
$langfolder_array = get_langfolder_list ();
2022-04-14 00:52:28 +08:00
$enabled = \App\Models\Language :: listEnabled ();
2020-12-26 01:42:23 +08:00
foreach ( $langfolder_array as $lf )
{
2022-07-02 21:22:12 +08:00
if ( $lf == $_COOKIE [ " c_lang_folder " ] && in_array ( $lf , $enabled )) {
$lang = $_COOKIE [ " c_lang_folder " ];
break ;
}
2020-12-26 01:42:23 +08:00
}
}
2022-07-02 21:22:12 +08:00
if ( ! $lang ) {
$lang = $deflang ;
}
if ( ! $transToLocale ) {
return $lang ;
}
return \App\Http\Middleware\Locale :: $languageMaps [ $lang ] ? ? 'en' ;
2020-12-26 01:42:23 +08:00
}
function get_user_lang ( $user_id )
{
$lang = mysql_fetch_assoc ( sql_query ( " SELECT site_lang_folder FROM language LEFT JOIN users ON language.id = users.lang WHERE language.site_lang=1 AND users.id= " . sqlesc ( $user_id ) . " LIMIT 1 " )) or sqlerr ( __FILE__ , __LINE__ );
return $lang [ 'site_lang_folder' ];
}
function get_langfile_path ( $script_name = " " , $target = false , $lang_folder = " " )
{
global $CURLANGDIR ;
$CURLANGDIR = get_langfolder_cookie ();
if ( $lang_folder == " " )
{
$lang_folder = $CURLANGDIR ;
}
return " lang/ " . ( $target == false ? $lang_folder : " _target " ) . " /lang_ " . ( $script_name == " " ? substr ( strrchr ( $_SERVER [ 'SCRIPT_NAME' ], '/' ), 1 ) : $script_name );
}
function get_row_sum ( $table , $field , $suffix = " " )
{
$r = sql_query ( " SELECT SUM( $field ) FROM $table $suffix " ) or sqlerr ( __FILE__ , __LINE__ );
2021-06-15 10:35:13 +08:00
$a = mysql_fetch_row ( $r );
2020-12-26 01:42:23 +08:00
return $a [ 0 ];
}
function get_single_value ( $table , $field , $suffix = " " ){
$r = sql_query ( " SELECT $field FROM $table $suffix LIMIT 1 " ) or sqlerr ( __FILE__ , __LINE__ );
2021-06-15 10:35:13 +08:00
$a = mysql_fetch_row ( $r );
2020-12-26 01:42:23 +08:00
if ( $a ) {
return $a [ 0 ];
} else {
return false ;
}
}
function stdmsg ( $heading , $text , $htmlstrip = false )
{
if ( $htmlstrip ) {
$heading = htmlspecialchars ( trim ( $heading ));
$text = htmlspecialchars ( trim ( $text ));
2023-05-27 23:45:39 +08:00
}
2020-12-26 01:42:23 +08:00
print ( " <table align= \" center \" class= \" main \" width= \" 500 \" border= \" 0 \" cellpadding= \" 0 \" cellspacing= \" 0 \" ><tr><td class= \" embedded \" > \n " );
if ( $heading )
print ( " <h2> " . $heading . " </h2> \n " );
print ( " <table width= \" 100% \" border= \" 1 \" cellspacing= \" 0 \" cellpadding= \" 10 \" ><tr><td class= \" text \" > " );
print ( $text . " </td></tr></table></td></tr></table> \n " );
}
function stderr ( $heading , $text , $htmlstrip = true , $head = true , $foot = true , $die = true )
{
if ( $head ) stdhead ();
stdmsg ( $heading , $text , $htmlstrip );
if ( $foot ) stdfoot ();
if ( $die ) die ;
}
function sqlerr ( $file = '' , $line = '' )
{
print ( " <table border= \" 0 \" bgcolor= \" blue \" align= \" left \" cellspacing= \" 0 \" cellpadding= \" 10 \" style= \" background: blue; \" > " .
" <tr><td class= \" embedded \" ><font color= \" white \" ><h1>SQL Error</h1> \n " .
" <b> " . mysql_error () . ( $file != '' && $line != '' ? " <p>in $file , line $line </p> " : " " ) . " </b></font></td></tr></table> " );
die ;
}
function format_quotes ( $s )
{
global $lang_functions ;
preg_match_all ( '/\\[quote.*?\\]/i' , $s , $result , PREG_PATTERN_ORDER );
$openquotecount = count ( $openquote = $result [ 0 ]);
preg_match_all ( '/\\[\/quote\\]/i' , $s , $result , PREG_PATTERN_ORDER );
$closequotecount = count ( $closequote = $result [ 0 ]);
if ( $openquotecount != $closequotecount ) return $s ; // quote mismatch. Return raw string...
// Get position of opening quotes
$openval = array ();
$pos = - 1 ;
foreach ( $openquote as $val )
$openval [] = $pos = strpos ( $s , $val , $pos + 1 );
// Get position of closing quotes
$closeval = array ();
$pos = - 1 ;
foreach ( $closequote as $val )
$closeval [] = $pos = strpos ( $s , $val , $pos + 1 );
for ( $i = 0 ; $i < count ( $openval ); $i ++ )
if ( $openval [ $i ] > $closeval [ $i ]) return $s ; // Cannot close before opening. Return raw string...
$s = preg_replace ( " / \\ [quote \\ ]/i " , " <fieldset><legend> " . $lang_functions [ 'text_quote' ] . " </legend><br /> " , $s );
$s = preg_replace ( " / \\ [quote=(.+?) \\ ]/i " , " <fieldset><legend> " . $lang_functions [ 'text_quote' ] . " : \\ 1 </legend><br /> " , $s );
$s = preg_replace ( " / \\ [ \\ /quote \\ ]/i " , " </fieldset><br /> " , $s );
return $s ;
}
function print_attachment ( $dlkey , $enableimage = true , $imageresizer = true )
{
global $Cache , $httpdirectory_attachment ;
global $lang_functions ;
if ( strlen ( $dlkey ) == 32 ){
if ( ! $row = $Cache -> get_value ( 'attachment_' . $dlkey . '_content' )){
$res = sql_query ( " SELECT * FROM attachments WHERE dlkey= " . sqlesc ( $dlkey ) . " LIMIT 1 " ) or sqlerr ( __FILE__ , __LINE__ );
$row = mysql_fetch_array ( $res );
$Cache -> cache_value ( 'attachment_' . $dlkey . '_content' , $row , 86400 );
}
}
if ( ! $row )
{
return " <div style= \" text-decoration: line-through; font-size: 7pt \" > " . $lang_functions [ 'text_attachment_key' ] . $dlkey . $lang_functions [ 'text_not_found' ] . " </div> " ;
}
else {
$id = $row [ 'id' ];
if ( $row [ 'isimage' ] == 1 )
{
if ( $enableimage ){
if ( $row [ 'thumb' ] == 1 ){
$url = $httpdirectory_attachment . " / " . $row [ 'location' ] . " .thumb.jpg " ;
}
else {
$url = $httpdirectory_attachment . " / " . $row [ 'location' ];
}
if ( $imageresizer == true )
$onclick = " onclick= \" Previewurl(' " . $httpdirectory_attachment . " / " . $row [ 'location' ] . " ') \" " ;
else $onclick = " " ;
$return = " <img id= \" attach " . $id . " \" alt= \" " . htmlspecialchars ( $row [ 'filename' ]) . " \" src= \" " . $url . " \" " . $onclick . " onmouseover= \" domTT_activate(this, event, 'content', ' " . htmlspecialchars ( " <strong> " . $lang_functions [ 'text_size' ] . " </strong>: " . mksize ( $row [ 'filesize' ]) . " <br /> " . gettime ( $row [ 'added' ])) . " ', 'styleClass', 'attach', 'x', findPosition(this)[0], 'y', findPosition(this)[1]-58); \" /> " ;
}
else $return = " " ;
}
else
{
switch ( $row [ 'filetype' ])
{
case 'application/x-bittorrent' : {
$icon = " <img alt= \" torrent \" src= \" pic/attachicons/torrent.gif \" /> " ;
break ;
}
case 'application/zip' : {
$icon = " <img alt= \" zip \" src= \" pic/attachicons/archive.gif \" /> " ;
break ;
}
case 'application/rar' : {
$icon = " <img alt= \" rar \" src= \" pic/attachicons/archive.gif \" /> " ;
break ;
}
case 'application/x-7z-compressed' : {
$icon = " <img alt= \" 7z \" src= \" pic/attachicons/archive.gif \" /> " ;
break ;
}
case 'application/x-gzip' : {
$icon = " <img alt= \" gzip \" src= \" pic/attachicons/archive.gif \" /> " ;
break ;
}
case 'audio/mpeg' : {
}
case 'audio/ogg' : {
$icon = " <img alt= \" audio \" src= \" pic/attachicons/audio.gif \" /> " ;
break ;
}
case 'video/x-flv' : {
$icon = " <img alt= \" flv \" src= \" pic/attachicons/flv.gif \" /> " ;
break ;
}
default : {
$icon = " <img alt= \" other \" src= \" pic/attachicons/common.gif \" /> " ;
}
}
$return = " <div class= \" attach \" > " . $icon . " <a href= \" " . htmlspecialchars ( " getattachment.php?id= " . $id . " &dlkey= " . $dlkey ) . " \" target= \" _blank \" id= \" attach " . $id . " \" onmouseover= \" domTT_activate(this, event, 'content', ' " . htmlspecialchars ( " <strong> " . $lang_functions [ 'text_downloads' ] . " </strong>: " . number_format ( $row [ 'downloads' ]) . " <br /> " . gettime ( $row [ 'added' ])) . " ', 'styleClass', 'attach', 'x', findPosition(this)[0], 'y', findPosition(this)[1]-58); \" > " . htmlspecialchars ( $row [ 'filename' ]) . " </a> <font class= \" size \" >( " . mksize ( $row [ 'filesize' ]) . " )</font></div> " ;
}
return $return ;
}
}
function addTempCode ( $value ) {
global $tempCode , $tempCodeCount ;
$tempCode [ $tempCodeCount ] = $value ;
$return = " <tempCode_ $tempCodeCount > " ;
$tempCodeCount ++ ;
return $return ;
}
function formatAdUrl ( $adid , $url , $content , $newWindow = true )
{
return formatUrl ( " adredir.php?id= " . $adid . " &url= " . rawurlencode ( $url ), $newWindow , $content );
}
function formatUrl ( $url , $newWindow = false , $text = '' , $linkClass = '' ) {
if ( ! $text ) {
$text = $url ;
}
return addTempCode ( " <a " . ( $linkClass ? " class= \" $linkClass\ " " : ''). " href = \ " $url\ " " . ( $newWindow ==true? " target = \ " _blank \" " : " " ) . " > $text </a> " );
}
function formatCode ( $text ) {
global $lang_functions ;
2023-07-30 14:28:19 +08:00
return addTempCode ( " <br /><div class= \" codetop \" > " . $lang_functions [ 'text_code' ] . " </div><div class= \" codemain \" ><pre><code> $text </code></pre></div><br /> " );
2020-12-26 01:42:23 +08:00
}
2021-03-03 19:29:29 +08:00
function formatImg ( $src , $enableImageResizer , $image_max_width , $image_max_height , $imgId = " " ) {
2023-07-19 02:32:02 +08:00
if ( is_danger_url ( $src )) {
$msg = " [DANGER_URL]: $src " ;
do_log ( $msg , " alert " );
write_log ( $msg , " mod " );
return " " ;
}
2021-03-19 11:07:29 +08:00
return addTempCode ( " <img style= \" max-width: 100% \" id= \" $imgId\ " alt = \ " image \" src= \" $src\ " " .( $enableImageResizer ? " onload = \ " Scale(this, $image_max_width , $image_max_height ); \" onclick= \" Preview(this); \" " : " " ) . " /> " );
2020-12-26 01:42:23 +08:00
}
function formatFlash ( $src , $width , $height ) {
if ( ! $width ) {
$width = 500 ;
}
if ( ! $height ) {
$height = 300 ;
}
return addTempCode ( " <object width= \" $width\ " height = \ " $height\ " >< param name = \ " movie \" value= \" $src\ " />< embed src = \ " $src\ " width = \ " $width\ " height = \ " $height\ " type = \ " application/x-shockwave-flash \" ></embed></object> " );
}
function formatFlv ( $src , $width , $height ) {
if ( ! $width ) {
$width = 320 ;
}
if ( ! $height ) {
$height = 240 ;
}
return addTempCode ( " <object width= \" $width\ " height = \ " $height\ " >< param name = \ " movie \" value= \" flvplayer.swf?file= $src\ " />< param name = \ " allowFullScreen \" value= \" true \" /><embed src= \" flvplayer.swf?file= $src\ " type = \ " application/x-shockwave-flash \" allowfullscreen= \" true \" width= \" $width\ " height = \ " $height\ " ></ embed ></ object > " );
}
2022-04-11 19:34:49 +08:00
function formatYoutube ( $src , $width = '' , $height = '' ) : string
{
if ( ! $width ) {
$width = 560 ;
}
if ( ! $height ) {
$height = 315 ;
}
$queryString = parse_url ( $src , PHP_URL_QUERY );
parse_str ( $queryString , $parameters );
if ( empty ( $parameters [ 'v' ])) {
$videoId = '' ;
} else {
$videoId = $parameters [ 'v' ];
}
return addTempCode ( sprintf (
'<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>' ,
$width , $height , $videoId
));
}
2022-04-12 01:48:22 +08:00
function formatSpoiler ( $content , $title = '' , $defaultCollapsed = true ) : string
{
global $lang_functions ;
if ( ! $title ) {
$title = $lang_functions [ 'spoiler_default_title' ];
}
2023-06-18 17:37:06 +08:00
// $content = str_replace(['<br>', '<br />'], '', $content);
2022-04-12 01:48:22 +08:00
$contentClass = " spoiler-content " ;
if ( $defaultCollapsed ) {
$contentClass .= " collapse " ;
}
$HTML = sprintf (
2022-09-19 18:48:03 +08:00
'<div><div class="spoiler-title-box"><div class="spoiler-title" title="%s">%s</div></div><div class="%s">%s</div></div>' ,
2022-04-12 01:48:22 +08:00
$lang_functions [ 'spoiler_expand_collapse' ], $title , $contentClass , $content
);
return addTempCode ( $HTML );
}
2022-04-14 00:52:28 +08:00
function formatTextAlign ( $text , $align ) : string
{
return addTempCode ( sprintf ( '<div style="text-align: %s">%s</div>' , $align , $text ));
}
2020-12-26 01:42:23 +08:00
function format_urls ( $text , $newWindow = false ) {
2020-12-29 03:02:34 +08:00
// return preg_replace("/((https?|ftp|gopher|news|telnet|mms|rtsp):\/\/[^()\[\]<>\s]+)/ei", "formatUrl('\\1', ".($newWindow==true ? 1 : 0).", '', 'faqlink')", $text);
return preg_replace_callback ( " /((https?|ftp|gopher|news|telnet|mms|rtsp): \ / \ /[^() \ [ \ ]<> \ s]+)/i " , function ( $matches ) use ( $newWindow ) {
2022-06-08 14:15:59 +08:00
return formatUrl ( $matches [ 1 ], $newWindow , '' , 'faqlink' );
2020-12-29 03:02:34 +08:00
}, $text );
2020-12-26 01:42:23 +08:00
}
2022-06-08 14:15:59 +08:00
function format_comment ( $text , $strip_html = true , $xssclean = false , $newtab = true , $imageresizer = true , $image_max_width = 700 , $enableimage = true , $enableflash = true , $imagenum = - 1 , $image_max_height = 0 , $adid = 0 )
2020-12-26 01:42:23 +08:00
{
global $lang_functions ;
2022-09-03 18:54:54 +08:00
global $CURUSER , $SITENAME , $BASEURL ;
2020-12-26 01:42:23 +08:00
global $tempCode , $tempCodeCount ;
2022-09-03 18:54:54 +08:00
$enableattach_attachment = get_setting ( 'attachment.enableattach' );
2020-12-26 01:42:23 +08:00
$tempCode = array ();
$tempCodeCount = 0 ;
$imageresizer = $imageresizer ? 1 : 0 ;
$s = $text ;
if ( $strip_html ) {
$s = htmlspecialchars ( $s );
}
if ( strpos ( $s , " [code] " ) !== false && strpos ( $s , " [/code] " ) !== false ) {
2020-12-29 03:02:34 +08:00
// $s = preg_replace("/\[code\](.+?)\[\/code\]/eis","formatCode('\\1')", $s);
$s = preg_replace_callback ( " / \ [code \ ](.+?) \ [ \ /code \ ]/is " , function ( $matches ) {
return formatCode ( $matches [ 1 ]);
}, $s );
2020-12-26 01:42:23 +08:00
}
2022-09-19 18:48:03 +08:00
if ( strpos ( $s , " [raw] " ) !== false && strpos ( $s , " [/raw] " ) !== false ) {
$s = preg_replace_callback ( " / \ [raw \ ](.+?) \ [ \ /raw \ ]/is " , function ( $matches ) {
return addTempCode ( $matches [ 1 ]);
}, $s );
}
// Linebreaks
$s = nl2br ( $s );
2020-12-26 01:42:23 +08:00
$originalBbTagArray = array ( '[siteurl]' , '[site]' , '[*]' , '[b]' , '[/b]' , '[i]' , '[/i]' , '[u]' , '[/u]' , '[pre]' , '[/pre]' , '[/color]' , '[/font]' , '[/size]' , " " );
2022-09-03 18:54:54 +08:00
$replaceXhtmlTagArray = array ( get_protocol_prefix () . get_setting ( 'basic.BASEURL' ), get_setting ( 'basic.SITENAME' ), '<img class="listicon listitem" src="pic/trans.gif" alt="list" />' , '<b>' , '</b>' , '<i>' , '</i>' , '<u>' , '</u>' , '<pre>' , '</pre>' , '</span>' , '</font>' , '</font>' , ' ' );
2020-12-26 01:42:23 +08:00
$s = str_replace ( $originalBbTagArray , $replaceXhtmlTagArray , $s );
$originalBbTagArray = array ( " / \ [font=([^ \ [ \ (& \\ ;]+?) \ ]/is " , " / \ [color=([#0-9a-z] { 1,15}) \ ]/is " , " / \ [color=([a-z]+) \ ]/is " , " / \ [size=([1-7]) \ ]/is " );
$replaceXhtmlTagArray = array ( " <font face= \" \\ 1 \" > " , " <span style= \" color: \\ 1; \" > " , " <span style= \" color: \\ 1; \" > " , " <font size= \" \\ 1 \" > " );
$s = preg_replace ( $originalBbTagArray , $replaceXhtmlTagArray , $s );
if ( $enableattach_attachment == 'yes' && $imagenum != 1 ){
$limit = 20 ;
2020-12-28 20:52:54 +08:00
// $s = preg_replace("/\[attach\]([0-9a-zA-z][0-9a-zA-z]*)\[\/attach\]/ies", "print_attachment('\\1', ".($enableimage ? 1 : 0).", ".($imageresizer ? 1 : 0).")", $s, $limit);
$s = preg_replace_callback ( " / \ [attach \ ]([0-9a-zA-z][0-9a-zA-z]*) \ [ \ /attach \ ]/is " , function ( $matches ) use ( $enableimage , $imageresizer ) {
return print_attachment ( $matches [ 1 ], " .( $enableimage ? 1 : 0). " , " .( $imageresizer ? 1 : 0). " );
}, $s , $limit );
2020-12-26 01:42:23 +08:00
}
if ( $enableimage ) {
2020-12-28 20:52:54 +08:00
// $s = preg_replace("/\[img\]([^\<\r\n\"']+?)\[\/img\]/ei", "formatImg('\\1',".$imageresizer.",".$image_max_width.",".$image_max_height.")", $s, $imagenum, $imgReplaceCount);
$s = preg_replace_callback ( " / \ [img \ ]([^ \ < \r \n \" ']+?) \ [ \ /img \ ]/i " , function ( $matches ) use ( $imageresizer , $image_max_width , $image_max_height ) {
2022-04-14 00:52:28 +08:00
return formatImg ( $matches [ 1 ], $imageresizer , $image_max_width , $image_max_height );
2020-12-28 20:52:54 +08:00
}, $s , $imagenum , $imgReplaceCount );
// $s = preg_replace("/\[img=([^\<\r\n\"']+?)\]/ei", "formatImg('\\1',".$imageresizer.",".$image_max_width.",".$image_max_height.")", $s, ($imagenum != -1 ? max($imagenum-$imgReplaceCount, 0) : -1));
$s = preg_replace_callback ( " / \ [img=([^ \ < \r \n \" ']+?) \ ]/i " , function ( $matches ) use ( $imageresizer , $image_max_width , $image_max_height ) {
2022-04-14 00:52:28 +08:00
return formatImg ( $matches [ 1 ], $imageresizer , $image_max_width , $image_max_height );
2020-12-28 20:52:54 +08:00
}, $s , ( $imagenum != - 1 ? max ( $imagenum - $imgReplaceCount , 0 ) : - 1 ));
2020-12-26 01:42:23 +08:00
} else {
$s = preg_replace ( " / \ [img \ ]([^ \ < \r \n \" ']+?) \ [ \ /img \ ]/i " , '' , $s , - 1 );
$s = preg_replace ( " / \ [img=([^ \ < \r \n \" ']+?) \ ]/i " , '' , $s , - 1 );
}
// [flash,500,400]http://www/image.swf[/flash]
if ( strpos ( $s , " [flash " ) !== false ) { //flash is not often used. Better check if it exist before hand
if ( $enableflash ) {
2020-12-29 03:02:34 +08:00
// $s = preg_replace("/\[flash(\,([1-9][0-9]*)\,([1-9][0-9]*))?\]((http|ftp):\/\/[^\s'\"<>]+(\.(swf)))\[\/flash\]/ei", "formatFlash('\\4', '\\2', '\\3')", $s);
$s = preg_replace_callback ( " / \ [flash( \ ,([1-9][0-9]*) \ ,([1-9][0-9]*))? \ ]((http|ftp): \ / \ /[^ \ s' \" <>]+( \ .(swf))) \ [ \ /flash \ ]/i " , function ( $matches ) {
return formatFlash ( $matches [ 4 ], $matches [ 2 ], $matches [ 3 ]);
}, $s );
2020-12-26 01:42:23 +08:00
} else {
$s = preg_replace ( " / \ [flash( \ ,([1-9][0-9]*) \ ,([1-9][0-9]*))? \ ]((http|ftp): \ / \ /[^ \ s' \" <>]+( \ .(swf))) \ [ \ /flash \ ]/i " , '' , $s );
}
}
//[flv,320,240]http://www/a.flv[/flv]
if ( strpos ( $s , " [flv " ) !== false ) { //flv is not often used. Better check if it exist before hand
if ( $enableflash ) {
2020-12-29 03:02:34 +08:00
// $s = preg_replace("/\[flv(\,([1-9][0-9]*)\,([1-9][0-9]*))?\]((http|ftp):\/\/[^\s'\"<>]+(\.(flv)))\[\/flv\]/ei", "formatFlv('\\4', '\\2', '\\3')", $s);
$s = preg_replace_callback ( " / \ [flv( \ ,([1-9][0-9]*) \ ,([1-9][0-9]*))? \ ]((http|ftp): \ / \ /[^ \ s' \" <>]+( \ .(flv))) \ [ \ /flv \ ]/i " , function ( $matches ) {
return formatFlv ( $matches [ 4 ], $matches [ 2 ], $matches [ 3 ]);
}, $s );
2020-12-26 01:42:23 +08:00
} else {
$s = preg_replace ( " / \ [flv( \ ,([1-9][0-9]*) \ ,([1-9][0-9]*))? \ ]((http|ftp): \ / \ /[^ \ s' \" <>]+( \ .(flv))) \ [ \ /flv \ ]/i " , '' , $s );
}
}
2022-04-11 19:34:49 +08:00
//[youtube,560,315]https://www.youtube.com/watch?v=DWDL3VTCcCg&ab_channel=ESPNMMA[/youtube]
if ( str_contains ( $s , '[youtube' ) && str_contains ( $s , 'v=' )) {
$s = preg_replace_callback ( " / \ [youtube( \ ,([1-9][0-9]*) \ ,([1-9][0-9]*))? \ ]((http|https): \ / \ /[^ \ s' \" <>]+) \ [ \ /youtube \ ]/i " , function ( $matches ) {
return formatYoutube ( $matches [ 4 ], $matches [ 2 ], $matches [ 3 ]);
}, $s );
}
2020-12-26 01:42:23 +08:00
// [url=http://www.example.com]Text[/url]
if ( $adid ) {
2020-12-29 03:02:34 +08:00
// $s = preg_replace("/\[url=([^\[\s]+?)\](.+?)\[\/url\]/ei", "formatAdUrl(".$adid." ,'\\1', '\\2', ".($newtab==true ? 1 : 0).", 'faqlink')", $s);
$s = preg_replace_callback ( " / \ [url=([^ \ [ \ s]+?) \ ](.+?) \ [ \ /url \ ]/i " , function ( $matches ) use ( $adid , $newtab ) {
2022-03-04 16:16:56 +08:00
return formatAdUrl ( $adid , $matches [ 1 ], $matches [ 2 ], " .( $newtab ==true ? 1 : 0). " , 'faqlink' );
2020-12-29 03:02:34 +08:00
}, $s );
2020-12-26 01:42:23 +08:00
} else {
2020-12-29 03:02:34 +08:00
// $s = preg_replace("/\[url=([^\[\s]+?)\](.+?)\[\/url\]/ei", "formatUrl('\\1', ".($newtab==true ? 1 : 0).", '\\2', 'faqlink')", $s);
$s = preg_replace_callback ( " / \ [url=([^ \ [ \ s]+?) \ ](.+?) \ [ \ /url \ ]/i " , function ( $matches ) use ( $newtab ) {
2022-06-08 14:15:59 +08:00
return formatUrl ( $matches [ 1 ], $newtab , $matches [ 2 ], 'faqlink' );
2020-12-29 03:02:34 +08:00
}, $s );
2020-12-26 01:42:23 +08:00
}
// [url]http://www.example.com[/url]
2020-12-29 03:02:34 +08:00
// $s = preg_replace("/\[url\]([^\[\s]+?)\[\/url\]/ei", "formatUrl('\\1', ".($newtab==true ? 1 : 0).", '', 'faqlink')", $s);
$s = preg_replace_callback ( " / \ [url \ ]([^ \ [ \ s]+?) \ [ \ /url \ ]/i " , function ( $matches ) use ( $newtab ) {
2022-06-08 14:15:59 +08:00
return formatUrl ( $matches [ 1 ], $newtab , '' , 'faqlink' );
2020-12-29 03:02:34 +08:00
}, $s );
2020-12-26 01:42:23 +08:00
2022-04-14 00:52:28 +08:00
// [left]Left text[/left]
$s = preg_replace_callback ( " / \ [left \ ](.*) \ [ \ /left \ ]/isU " , function ( $matches ) {
return formatTextAlign ( $matches [ 1 ], 'left' );
}, $s );
// [center]Center text[/center]
$s = preg_replace_callback ( " / \ [center \ ](.*) \ [ \ /center \ ]/isU " , function ( $matches ) {
return formatTextAlign ( $matches [ 1 ], 'center' );
}, $s );
// [right]Right text[/right]
$s = preg_replace_callback ( " / \ [right \ ](.*) \ [ \ /right \ ]/isU " , function ( $matches ) {
return formatTextAlign ( $matches [ 1 ], 'right' );
}, $s );
2020-12-26 01:42:23 +08:00
$s = format_urls ( $s , $newtab );
// Quotes
if ( strpos ( $s , " [quote " ) !== false && strpos ( $s , " [/quote] " ) !== false ) { //format_quote is kind of slow. Better check if [quote] exists beforehand
$s = format_quotes ( $s );
}
2020-12-29 03:02:34 +08:00
// $s = preg_replace("/\[em([1-9][0-9]*)\]/ie", "(\\1 < 192 ? '<img src=\"pic/smilies/\\1.gif\" alt=\"[em\\1]\" />' : '[em\\1]')", $s);
$s = preg_replace_callback ( " / \ [em([1-9][0-9]*) \ ]/i " , function ( $matches ) {
2022-04-04 17:26:26 +08:00
$smile = get_smile ( $matches [ 1 ]);
return $smile ? '<img src="' . $smile . '" alt="[em' . $matches [ 1 ] . ']" />' : '[em' . $matches [ 1 ] . ']' ;
2020-12-29 03:02:34 +08:00
}, $s );
2022-04-14 00:52:28 +08:00
//[spoiler=What happens to the hero?]The hero dies at the end![/spoiler]
if ( str_contains ( $s , '[spoiler' )) {
$s = preg_replace_callback ( " / \ [spoiler(=(.*))? \ ](.*) \ [ \ /spoiler \ ]/isU " , function ( $matches ) {
return formatSpoiler ( $matches [ 3 ], $matches [ 2 ], nexus () -> getScript () != 'preview' );
}, $s );
}
2020-12-26 01:42:23 +08:00
reset ( $tempCode );
2020-12-29 03:02:34 +08:00
$j = $i = 0 ;
2020-12-26 01:42:23 +08:00
while ( count ( $tempCode ) || $j > 5 ) {
foreach ( $tempCode as $key => $code ) {
$s = str_replace ( " <tempCode_ $key > " , $code , $s , $count );
if ( $count ) {
unset ( $tempCode [ $key ]);
$i = $i + $count ;
}
}
$j ++ ;
}
2023-05-24 02:00:18 +08:00
return str_replace ( ' ' , '' , $s );
2020-12-26 01:42:23 +08:00
}
2021-04-22 03:24:59 +08:00
function highlight ( $search , $subject , $hlstart = '<b><font class="striking">' , $hlend = " </font></b> " )
2020-12-26 01:42:23 +08:00
{
$srchlen = strlen ( $search ); // lenght of searched string
if ( $srchlen == 0 ) return $subject ;
$find = $subject ;
while ( $find = stristr ( $find , $search )) { // find $search text in $subject -case insensitiv
$srchtxt = substr ( $find , 0 , $srchlen ); // get new search text
$find = substr ( $find , $srchlen );
$subject = str_replace ( $srchtxt , " $hlstart $srchtxt $hlend " , $subject ); // highlight founded case insensitive search text
}
return $subject ;
}
2022-08-19 15:30:16 +08:00
function get_user_class_name ( $class , $compact = false , $b_colored = false , $I18N = false , array $options = [])
2020-12-26 01:42:23 +08:00
{
2022-06-12 15:15:09 +08:00
if ( ! IN_NEXUS ) {
return \App\Models\User :: getClassName ( $class , $compact , $b_colored , $I18N );
}
2020-12-28 20:52:54 +08:00
global $SITENAME ;
2020-12-26 01:42:23 +08:00
static $en_lang_functions ;
static $current_user_lang_functions ;
2022-04-21 16:14:08 +08:00
static $settingAccount ;
2020-12-26 01:42:23 +08:00
if ( ! $en_lang_functions ) {
require ( get_langfile_path ( " functions.php " , false , " en " ));
$en_lang_functions = $lang_functions ;
}
2022-04-21 16:14:08 +08:00
if ( ! $settingAccount ) {
$settingAccount = get_setting ( 'account' );
}
2020-12-26 01:42:23 +08:00
if ( ! $I18N ) {
$this_lang_functions = $en_lang_functions ;
} else {
if ( ! $current_user_lang_functions ) {
require ( get_langfile_path ( " functions.php " ));
$current_user_lang_functions = $lang_functions ;
}
$this_lang_functions = $current_user_lang_functions ;
}
2021-04-22 03:24:59 +08:00
2020-12-26 01:42:23 +08:00
$class_name = " " ;
switch ( $class )
{
case UC_PEASANT : { $class_name = $this_lang_functions [ 'text_peasant' ]; break ;}
case UC_USER : { $class_name = $this_lang_functions [ 'text_user' ]; break ;}
case UC_POWER_USER : { $class_name = $this_lang_functions [ 'text_power_user' ]; break ;}
case UC_ELITE_USER : { $class_name = $this_lang_functions [ 'text_elite_user' ]; break ;}
case UC_CRAZY_USER : { $class_name = $this_lang_functions [ 'text_crazy_user' ]; break ;}
case UC_INSANE_USER : { $class_name = $this_lang_functions [ 'text_insane_user' ]; break ;}
case UC_VETERAN_USER : { $class_name = $this_lang_functions [ 'text_veteran_user' ]; break ;}
case UC_EXTREME_USER : { $class_name = $this_lang_functions [ 'text_extreme_user' ]; break ;}
case UC_ULTIMATE_USER : { $class_name = $this_lang_functions [ 'text_ultimate_user' ]; break ;}
case UC_NEXUS_MASTER : { $class_name = $this_lang_functions [ 'text_nexus_master' ]; break ;}
case UC_VIP : { $class_name = $this_lang_functions [ 'text_vip' ]; break ;}
case UC_UPLOADER : { $class_name = $this_lang_functions [ 'text_uploader' ]; break ;}
case UC_RETIREE : { $class_name = $this_lang_functions [ 'text_retiree' ]; break ;}
case UC_MODERATOR : { $class_name = $this_lang_functions [ 'text_moderators' ]; break ;}
case UC_ADMINISTRATOR : { $class_name = $this_lang_functions [ 'text_administrators' ]; break ;}
case UC_SYSOP : { $class_name = $this_lang_functions [ 'text_sysops' ]; break ;}
case UC_STAFFLEADER : { $class_name = $this_lang_functions [ 'text_staff_leader' ]; break ;}
}
2023-02-09 18:14:51 +08:00
if ( isset ( $options [ 'with_alias' ]) && $options [ 'with_alias' ] && $class < UC_VIP && isset ( $settingAccount [ " { $class } _alias " ])) {
2022-04-21 16:14:08 +08:00
$alias = trim ( $settingAccount [ " { $class } _alias " ]);
if ( ! empty ( $alias )) {
$class_name = sprintf ( '%s(%s)' , $class_name , $alias );
}
}
2021-04-22 03:24:59 +08:00
2020-12-26 01:42:23 +08:00
switch ( $class )
{
case UC_PEASANT : { $class_name_color = $en_lang_functions [ 'text_peasant' ]; break ;}
case UC_USER : { $class_name_color = $en_lang_functions [ 'text_user' ]; break ;}
case UC_POWER_USER : { $class_name_color = $en_lang_functions [ 'text_power_user' ]; break ;}
case UC_ELITE_USER : { $class_name_color = $en_lang_functions [ 'text_elite_user' ]; break ;}
case UC_CRAZY_USER : { $class_name_color = $en_lang_functions [ 'text_crazy_user' ]; break ;}
case UC_INSANE_USER : { $class_name_color = $en_lang_functions [ 'text_insane_user' ]; break ;}
case UC_VETERAN_USER : { $class_name_color = $en_lang_functions [ 'text_veteran_user' ]; break ;}
case UC_EXTREME_USER : { $class_name_color = $en_lang_functions [ 'text_extreme_user' ]; break ;}
case UC_ULTIMATE_USER : { $class_name_color = $en_lang_functions [ 'text_ultimate_user' ]; break ;}
case UC_NEXUS_MASTER : { $class_name_color = $en_lang_functions [ 'text_nexus_master' ]; break ;}
case UC_VIP : { $class_name_color = $en_lang_functions [ 'text_vip' ]; break ;}
case UC_UPLOADER : { $class_name_color = $en_lang_functions [ 'text_uploader' ]; break ;}
case UC_RETIREE : { $class_name_color = $en_lang_functions [ 'text_retiree' ]; break ;}
case UC_MODERATOR : { $class_name_color = $en_lang_functions [ 'text_moderators' ]; break ;}
case UC_ADMINISTRATOR : { $class_name_color = $en_lang_functions [ 'text_administrators' ]; break ;}
case UC_SYSOP : { $class_name_color = $en_lang_functions [ 'text_sysops' ]; break ;}
case UC_STAFFLEADER : { $class_name_color = $en_lang_functions [ 'text_staff_leader' ]; break ;}
}
$class_name = ( $compact == true ? str_replace ( " " , " " , $class_name ) : $class_name );
2022-08-19 15:30:16 +08:00
if ( isset ( $options [ 'uid' ], $options [ 'with_role' ])) {
$class_name = implode ( ' | ' , apply_filter ( 'user_class_name' , [ $class_name ], $options [ 'uid' ]));
}
if ( $class_name && $b_colored ) {
$class_name = " <b class=' " . str_replace ( " " , " " , $class_name_color ) . " _Name'> " . $class_name . " </b> " ;
}
return $class_name ;
2020-12-26 01:42:23 +08:00
}
function is_valid_user_class ( $class )
{
return is_numeric ( $class ) && floor ( $class ) == $class && $class >= UC_PEASANT && $class <= UC_STAFFLEADER ;
}
function int_check ( $value , $stdhead = false , $stdfood = true , $die = true , $log = true ) {
global $lang_functions ;
global $CURUSER ;
if ( is_array ( $value ))
{
foreach ( $value as $val ) int_check ( $val );
}
else
{
if ( ! is_valid_id ( $value )) {
$msg = " Invalid ID Attempt: Username: " . $CURUSER [ " username " ] . " - UserID: " . $CURUSER [ " id " ] . " - UserIP : " . getip ();
2023-03-13 17:41:03 +08:00
if ( $log ) {
write_log ( $msg , 'mod' );
}
do_log ( $msg , 'error' );
2020-12-26 01:42:23 +08:00
if ( $stdhead )
stderr ( $lang_functions [ 'std_error' ], $lang_functions [ 'std_invalid_id' ]);
else
{
print ( " <h2> " . $lang_functions [ 'std_error' ] . " </h2><table width= \" 100% \" border= \" 1 \" cellspacing= \" 0 \" cellpadding= \" 10 \" ><tr><td class= \" text \" > " );
print ( $lang_functions [ 'std_invalid_id' ] . " </td></tr></table> " );
}
if ( $stdfood )
stdfoot ();
if ( $die )
die ;
}
else
return true ;
}
}
function is_valid_id ( $id )
{
return is_numeric ( $id ) && ( $id > 0 ) && ( floor ( $id ) == $id );
}
//-------- Begins a main frame
function begin_main_frame ( $caption = " " , $center = false , $width = 100 )
{
$tdextra = " " ;
if ( $caption )
print ( " <h2> " . $caption . " </h2> " );
if ( $center )
$tdextra .= " align= \" center \" " ;
2022-08-05 16:13:19 +08:00
if ( ! str_ends_with ( $width , '%' )) {
2022-08-19 17:02:35 +08:00
$width = CONTENT_WIDTH * $width / 100 ;
2022-08-05 16:13:19 +08:00
}
2020-12-26 01:42:23 +08:00
print ( " <table class= \" main \" width= \" " . $width . " \" border= \" 0 \" cellspacing= \" 0 \" cellpadding= \" 0 \" > " .
" <tr><td class= \" embedded \" $tdextra > " );
}
function end_main_frame ()
{
print ( " </td></tr></table> \n " );
}
function begin_frame ( $caption = " " , $center = false , $padding = 10 , $width = " 100% " , $caption_center = " left " )
{
$tdextra = " " ;
if ( $center )
$tdextra .= " align= \" center \" " ;
print (( $caption ? " <h2 align= \" " . $caption_center . " \" > " . $caption . " </h2> " : " " ) . " <table width= \" " . $width . " \" border= \" 1 \" cellspacing= \" 0 \" cellpadding= \" " . $padding . " \" > " . " <tr><td class= \" text \" $tdextra > \n " );
}
function end_frame ()
{
print ( " </td></tr></table> \n " );
}
function begin_table ( $fullwidth = false , $padding = 5 )
{
$width = " " ;
if ( $fullwidth )
$width .= " width=50% " ;
print ( " <table class= \" main " . $width . " \" border= \" 1 \" cellspacing= \" 0 \" cellpadding= \" " . $padding . " \" > " );
}
function end_table ()
{
print ( " </table> \n " );
}
//-------- Inserts a smilies frame
// (move to globals)
function insert_smilies_frame ()
{
global $lang_functions ;
begin_frame ( $lang_functions [ 'text_smilies' ], true );
begin_table ( false , 5 );
print ( " <tr><td class= \" colhead \" > " . $lang_functions [ 'col_type_something' ] . " </td><td class= \" colhead \" > " . $lang_functions [ 'col_to_make_a' ] . " </td></tr> \n " );
for ( $i = 1 ; $i < 192 ; $i ++ ) {
print ( " <tr><td>[em $i ]</td><td><img src= \" pic/smilies/ " . $i . " .gif \" alt= \" [em $i ] \" /></td></tr> \n " );
}
end_table ();
end_frame ();
}
function get_ratio_color ( $ratio )
{
if ( $ratio < 0.1 ) return " #ff0000 " ;
if ( $ratio < 0.2 ) return " #ee0000 " ;
if ( $ratio < 0.3 ) return " #dd0000 " ;
if ( $ratio < 0.4 ) return " #cc0000 " ;
if ( $ratio < 0.5 ) return " #bb0000 " ;
if ( $ratio < 0.6 ) return " #aa0000 " ;
if ( $ratio < 0.7 ) return " #990000 " ;
if ( $ratio < 0.8 ) return " #880000 " ;
if ( $ratio < 0.9 ) return " #770000 " ;
if ( $ratio < 1 ) return " #660000 " ;
return " " ;
}
function get_slr_color ( $ratio )
{
if ( $ratio < 0.025 ) return " #ff0000 " ;
if ( $ratio < 0.05 ) return " #ee0000 " ;
if ( $ratio < 0.075 ) return " #dd0000 " ;
if ( $ratio < 0.1 ) return " #cc0000 " ;
if ( $ratio < 0.125 ) return " #bb0000 " ;
if ( $ratio < 0.15 ) return " #aa0000 " ;
if ( $ratio < 0.175 ) return " #990000 " ;
if ( $ratio < 0.2 ) return " #880000 " ;
if ( $ratio < 0.225 ) return " #770000 " ;
if ( $ratio < 0.25 ) return " #660000 " ;
if ( $ratio < 0.275 ) return " #550000 " ;
if ( $ratio < 0.3 ) return " #440000 " ;
if ( $ratio < 0.325 ) return " #330000 " ;
if ( $ratio < 0.35 ) return " #220000 " ;
if ( $ratio < 0.375 ) return " #110000 " ;
return " " ;
}
function write_log ( $text , $security = " normal " )
{
$text = sqlesc ( $text );
$added = sqlesc ( date ( " Y-m-d H:i:s " ));
$security = sqlesc ( $security );
sql_query ( " INSERT INTO sitelog (added, txt, security_level) VALUES( $added , $text , $security ) " ) or sqlerr ( __FILE__ , __LINE__ );
}
function get_elapsed_time ( $ts , $shortunit = false )
{
global $lang_functions ;
$mins = floor ( abs ( TIMENOW - $ts ) / 60 );
$hours = floor ( $mins / 60 );
$mins -= $hours * 60 ;
$days = floor ( $hours / 24 );
$hours -= $days * 24 ;
$months = floor ( $days / 30 );
$days2 = $days - $months * 30 ;
$years = floor ( $days / 365 );
$months -= $years * 12 ;
$t = " " ;
if ( $years > 0 )
2021-02-28 02:15:11 +08:00
return $years . ( $shortunit ? $lang_functions [ 'text_short_year' ] : $lang_functions [ 'text_year' ] . add_s ( $years )) . " " . $months . ( $shortunit ? $lang_functions [ 'text_short_month' ] : $lang_functions [ 'text_month' ] . add_s ( $months ));
2020-12-26 01:42:23 +08:00
if ( $months > 0 )
return $months . ( $shortunit ? $lang_functions [ 'text_short_month' ] : $lang_functions [ 'text_month' ] . add_s ( $months )) . " " . $days2 . ( $shortunit ? $lang_functions [ 'text_short_day' ] : $lang_functions [ 'text_day' ] . add_s ( $days2 ));
if ( $days > 0 )
return $days . ( $shortunit ? $lang_functions [ 'text_short_day' ] : $lang_functions [ 'text_day' ] . add_s ( $days )) . " " . $hours . ( $shortunit ? $lang_functions [ 'text_short_hour' ] : $lang_functions [ 'text_hour' ] . add_s ( $hours ));
if ( $hours > 0 )
return $hours . ( $shortunit ? $lang_functions [ 'text_short_hour' ] : $lang_functions [ 'text_hour' ] . add_s ( $hours )) . " " . $mins . ( $shortunit ? $lang_functions [ 'text_short_min' ] : $lang_functions [ 'text_min' ] . add_s ( $mins ));
if ( $mins > 0 )
return $mins . ( $shortunit ? $lang_functions [ 'text_short_min' ] : $lang_functions [ 'text_min' ] . add_s ( $mins ));
return " < 1 " . ( $shortunit ? $lang_functions [ 'text_short_min' ] : $lang_functions [ 'text_min' ]);
}
2022-04-01 23:13:42 +08:00
function textbbcode ( $form , $text , $content = " " , $hastitle = false , $col_num = 130 , $withPreview = false )
2020-12-26 01:42:23 +08:00
{
global $lang_functions ;
global $subject , $BASEURL , $CURUSER , $enableattach_attachment ;
2022-04-01 23:13:42 +08:00
$editTbodyId = " $form - $text -edit " ;
$previewTbodyId = " $form - $text -preview " ;
$btnEditId = " $form - $text -btn-edit " ;
$btnPreviewId = " $form - $text -btn-preview " ;
2020-12-26 01:42:23 +08:00
?>
< script type = " text/javascript " >
2022-04-01 23:13:42 +08:00
let textareaId = " <?php echo $text ?> "
let editTbodyId = " <?php echo $editTbodyId ?> "
let previewTbodyId = " <?php echo $previewTbodyId ?> "
let btnEditId = " <?php echo $btnEditId ?> "
let btnPreviewId = " <?php echo $btnPreviewId ?> "
2020-12-26 01:42:23 +08:00
//<![CDATA[
var b_open = 0 ;
var i_open = 0 ;
var u_open = 0 ;
var color_open = 0 ;
var list_open = 0 ;
var quote_open = 0 ;
var html_open = 0 ;
var myAgent = navigator . userAgent . toLowerCase ();
var myVersion = parseInt ( navigator . appVersion );
var is_ie = (( myAgent . indexOf ( " msie " ) != - 1 ) && ( myAgent . indexOf ( " opera " ) == - 1 ));
var is_nav = (( myAgent . indexOf ( 'mozilla' ) !=- 1 ) && ( myAgent . indexOf ( 'spoofer' ) ==- 1 )
&& ( myAgent . indexOf ( 'compatible' ) == - 1 ) && ( myAgent . indexOf ( 'opera' ) ==- 1 )
&& ( myAgent . indexOf ( 'webtv' ) ==- 1 ) && ( myAgent . indexOf ( 'hotjava' ) ==- 1 ));
var is_win = (( myAgent . indexOf ( " win " ) !=- 1 ) || ( myAgent . indexOf ( " 16bit " ) !=- 1 ));
var is_mac = ( myAgent . indexOf ( " mac " ) !=- 1 );
var bbtags = new Array ();
function cstat () {
var c = stacksize ( bbtags );
if ( ( c < 1 ) || ( c == null ) ) { c = 0 ;}
if ( ! bbtags [ 0 ] ) { c = 0 ;}
document .< ? php echo $form ?> .tagcount.value = "Close last, Open "+c;
}
function stacksize ( thearray ) {
for ( i = 0 ; i < thearray . length ; i ++ ) {
if ( ( thearray [ i ] == " " ) || ( thearray [ i ] == null ) || ( thearray == 'undefined' ) ) { return i ;}
}
return thearray . length ;
}
function pushstack ( thearray , newval ) {
arraysize = stacksize ( thearray );
thearray [ arraysize ] = newval ;
}
function popstackd ( thearray ) {
arraysize = stacksize ( thearray );
theval = thearray [ arraysize - 1 ];
return theval ;
}
function popstack ( thearray ) {
arraysize = stacksize ( thearray );
theval = thearray [ arraysize - 1 ];
delete thearray [ arraysize - 1 ];
return theval ;
}
function closeall () {
if ( bbtags [ 0 ]) {
while ( bbtags [ 0 ]) {
tagRemove = popstack ( bbtags )
if ( ( tagRemove != 'color' ) ) {
doInsert ( " [/ " + tagRemove + " ] " , " " , false );
eval ( " document.<?php echo $form ?>. " + tagRemove + " .value = ' " + tagRemove + " ' " );
eval ( tagRemove + " _open = 0 " );
} else {
doInsert ( " [/ " + tagRemove + " ] " , " " , false );
}
cstat ();
return ;
}
}
document .< ? php echo $form ?> .tagcount.value = "Close last, Open 0";
bbtags = new Array ();
document .< ? php echo $form ?> .<?php echo $text?>.focus();
}
function add_code ( NewCode ) {
document .< ? php echo $form ?> .<?php echo $text?>.value += NewCode;
document .< ? php echo $form ?> .<?php echo $text?>.focus();
}
function alterfont ( theval , thetag ) {
if ( theval == 0 ) return ;
if ( doInsert ( " [ " + thetag + " = " + theval + " ] " , " [/ " + thetag + " ] " , true )) pushstack ( bbtags , thetag );
document .< ? php echo $form ?> .color.selectedIndex = 0;
cstat ();
}
function tag_url ( PromptURL , PromptTitle , PromptError ) {
var FoundErrors = '' ;
var enterURL = prompt ( PromptURL , " http:// " );
var enterTITLE = prompt ( PromptTitle , " " );
if ( ! enterURL || enterURL == " " ) { FoundErrors += " " + PromptURL + " , " ;}
if ( ! enterTITLE ) { FoundErrors += " " + PromptTitle ;}
if ( FoundErrors ) { alert ( PromptError + FoundErrors ); return ;}
doInsert ( " [url= " + enterURL + " ] " + enterTITLE + " [/url] " , " " , false );
}
function tag_list ( PromptEnterItem , PromptError ) {
var FoundErrors = '' ;
var enterTITLE = prompt ( PromptEnterItem , " " );
if ( ! enterTITLE ) { FoundErrors += " " + PromptEnterItem ;}
if ( FoundErrors ) { alert ( PromptError + FoundErrors ); return ;}
doInsert ( " [*] " + enterTITLE + " " , " " , false );
}
function tag_image ( PromptImageURL , PromptError ) {
var FoundErrors = '' ;
var enterURL = prompt ( PromptImageURL , " http:// " );
if ( ! enterURL || enterURL == " http:// " ) {
alert ( PromptError + PromptImageURL );
return ;
}
doInsert ( " [img] " + enterURL + " [/img] " , " " , false );
}
function tag_extimage ( content ) {
doInsert ( content , " " , false );
}
function tag_email ( PromptEmail , PromptError ) {
var emailAddress = prompt ( PromptEmail , " " );
if ( ! emailAddress ) {
alert ( PromptError + PromptEmail );
return ;
}
doInsert ( " [email] " + emailAddress + " [/email] " , " " , false );
}
function doInsert ( ibTag , ibClsTag , isSingle )
{
var isClose = false ;
var obj_ta = document .< ? php echo $form ?> .<?php echo $text?>;
if ( ( myVersion >= 4 ) && is_ie && is_win )
{
if ( obj_ta . isTextEdit )
{
obj_ta . focus ();
var sel = document . selection ;
var rng = sel . createRange ();
rng . colapse ;
if (( sel . type == " Text " || sel . type == " None " ) && rng != null )
{
if ( ibClsTag != " " && rng . text . length > 0 )
ibTag += rng . text + ibClsTag ;
else if ( isSingle ) isClose = true ;
rng . text = ibTag ;
}
}
else
{
if ( isSingle ) isClose = true ;
obj_ta . value += ibTag ;
}
}
else if ( obj_ta . selectionStart || obj_ta . selectionStart == '0' )
{
var startPos = obj_ta . selectionStart ;
var endPos = obj_ta . selectionEnd ;
obj_ta . value = obj_ta . value . substring ( 0 , startPos ) + ibTag + obj_ta . value . substring ( endPos , obj_ta . value . length );
obj_ta . selectionEnd = startPos + ibTag . length ;
if ( isSingle ) isClose = true ;
}
else
{
if ( isSingle ) isClose = true ;
obj_ta . value += ibTag ;
}
obj_ta . focus ();
// obj_ta.value = obj_ta.value.replace(/ /, " ");
return isClose ;
}
2022-05-25 02:15:41 +08:00
function clearContent ()
{
document .< ? php echo $form ?> .<?php echo $text?>.value = '';
}
2020-12-26 01:42:23 +08:00
function winop ()
{
windop = window . open ( " moresmilies.php?form=<?php echo $form ?>&text=<?php echo $text ?> " , " mywin " , " height=500,width=500,resizable=no,scrollbars=yes " );
}
function simpletag ( thetag )
{
var tagOpen = eval ( thetag + " _open " );
if ( tagOpen == 0 ) {
if ( doInsert ( " [ " + thetag + " ] " , " [/ " + thetag + " ] " , true ))
{
eval ( thetag + " _open = 1 " );
eval ( " document.<?php echo $form ?>. " + thetag + " .value += '*' " );
pushstack ( bbtags , thetag );
cstat ();
}
}
else {
lastindex = 0 ;
for ( i = 0 ; i < bbtags . length ; i ++ ) {
if ( bbtags [ i ] == thetag ) {
lastindex = i ;
}
}
while ( bbtags [ lastindex ]) {
tagRemove = popstack ( bbtags );
doInsert ( " [/ " + tagRemove + " ] " , " " , false )
if (( tagRemove != 'COLOR' ) ){
eval ( " document.<?php echo $form ?>. " + tagRemove + " .value = ' " + tagRemove . toUpperCase () + " ' " );
eval ( tagRemove + " _open = 0 " );
}
}
cstat ();
}
}
2022-04-01 23:13:42 +08:00
function textBBCodePreview () {
let poststr = encodeURIComponent ( document . getElementById ( textareaId ) . value );
let result = ajax . posts ( 'preview.php' , 'body=' + poststr );
jQuery ( '#' + editTbodyId ) . hide ()
jQuery ( '#' + previewTbodyId ) . html ( result ) . show ()
jQuery ( '#' + btnPreviewId ) . hide ()
jQuery ( '#' + btnEditId ) . show ()
}
function textBBCodeEdit () {
jQuery ( '#' + editTbodyId ) . show ()
jQuery ( '#' + previewTbodyId ) . hide ()
jQuery ( '#' + btnPreviewId ) . show ()
jQuery ( '#' + btnEditId ) . hide ()
}
2020-12-26 01:42:23 +08:00
//]]>
</ script >
< table width = " 100% " cellspacing = " 0 " cellpadding = " 5 " border = " 0 " >
2022-04-01 23:13:42 +08:00
< tbody id = " <?php echo $editTbodyId ?> " >
2020-12-26 01:42:23 +08:00
< tr >< td align = " left " colspan = " 2 " >
< table cellspacing = " 1 " cellpadding = " 2 " border = " 0 " >
< tr >
< td class = " embedded " >< input style = " font-weight: bold;font-size:11px; margin-right:3px " type = " button " name = " b " value = " B " onclick = " javascript: simpletag('b') " /></ td >
< td class = " embedded " >< input class = " codebuttons " style = " font-style: italic;font-size:11px;margin-right:3px " type = " button " name = " i " value = " I " onclick = " javascript: simpletag('i') " /></ td >
< td class = " embedded " >< input class = " codebuttons " style = " text-decoration: underline;font-size:11px;margin-right:3px " type = " button " name = " u " value = " U " onclick = " javascript: simpletag('u') " /></ td >
< ? php
print ( " <td class= \" embedded \" ><input class= \" codebuttons \" style= \" font-size:11px;margin-right:3px \" type= \" button \" name='url' value='URL' onclick= \" javascript:tag_url(' " . $lang_functions [ 'js_prompt_enter_url' ] . " ',' " . $lang_functions [ 'js_prompt_enter_title' ] . " ',' " . $lang_functions [ 'js_prompt_error' ] . " ') \" /></td> " );
print ( " <td class= \" embedded \" ><input class= \" codebuttons \" style= \" font-size:11px;margin-right:3px \" type= \" button \" name= \" IMG \" value= \" IMG \" onclick= \" javascript: tag_image(' " . $lang_functions [ 'js_prompt_enter_image_url' ] . " ',' " . $lang_functions [ 'js_prompt_error' ] . " ') \" /></td> " );
print ( " <td class= \" embedded \" ><input type= \" button \" style= \" font-size:11px;margin-right:3px \" name= \" list \" value= \" List \" onclick= \" tag_list(' " . addslashes ( $lang_functions [ 'js_prompt_enter_item' ]) . " ',' " . $lang_functions [ 'js_prompt_error' ] . " ') \" /></td> " );
?>
< td class = " embedded " >< input class = " codebuttons " style = " font-size:11px;margin-right:3px " type = " button " name = " quote " value = " QUOTE " onclick = " javascript: simpletag('quote') " /></ td >
< td class = " embedded " >< input style = " font-size:11px;margin-right:3px " type = " button " onclick = 'javascript:closeall();' name = 'tagcount' value = " Close all tags " /></ td >
< td class = " embedded " >< select class = " med codebuttons " style = " margin-right:3px " name = 'color' onchange = " alterfont(this.options[this.selectedIndex].value, 'color') " >
< option value = '0' >--- < ? php echo $lang_functions [ 'select_color' ] ?> ---</option>
< option style = " background-color: black " value = " Black " > Black </ option >
< option style = " background-color: sienna " value = " Sienna " > Sienna </ option >
< option style = " background-color: darkolivegreen " value = " DarkOliveGreen " > Dark Olive Green </ option >
< option style = " background-color: darkgreen " value = " DarkGreen " > Dark Green </ option >
< option style = " background-color: darkslateblue " value = " DarkSlateBlue " > Dark Slate Blue </ option >
< option style = " background-color: navy " value = " Navy " > Navy </ option >
< option style = " background-color: indigo " value = " Indigo " > Indigo </ option >
< option style = " background-color: darkslategray " value = " DarkSlateGray " > Dark Slate Gray </ option >
< option style = " background-color: darkred " value = " DarkRed " > Dark Red </ option >
< option style = " background-color: darkorange " value = " DarkOrange " > Dark Orange </ option >
< option style = " background-color: olive " value = " Olive " > Olive </ option >
< option style = " background-color: green " value = " Green " > Green </ option >
< option style = " background-color: teal " value = " Teal " > Teal </ option >
< option style = " background-color: blue " value = " Blue " > Blue </ option >
< option style = " background-color: slategray " value = " SlateGray " > Slate Gray </ option >
< option style = " background-color: dimgray " value = " DimGray " > Dim Gray </ option >
< option style = " background-color: red " value = " Red " > Red </ option >
< option style = " background-color: sandybrown " value = " SandyBrown " > Sandy Brown </ option >
< option style = " background-color: yellowgreen " value = " YellowGreen " > Yellow Green </ option >
< option style = " background-color: seagreen " value = " SeaGreen " > Sea Green </ option >
< option style = " background-color: mediumturquoise " value = " MediumTurquoise " > Medium Turquoise </ option >
< option style = " background-color: royalblue " value = " RoyalBlue " > Royal Blue </ option >
< option style = " background-color: purple " value = " Purple " > Purple </ option >
< option style = " background-color: gray " value = " Gray " > Gray </ option >
< option style = " background-color: magenta " value = " Magenta " > Magenta </ option >
< option style = " background-color: orange " value = " Orange " > Orange </ option >
< option style = " background-color: yellow " value = " Yellow " > Yellow </ option >
< option style = " background-color: lime " value = " Lime " > Lime </ option >
< option style = " background-color: cyan " value = " Cyan " > Cyan </ option >
< option style = " background-color: deepskyblue " value = " DeepSkyBlue " > Deep Sky Blue </ option >
< option style = " background-color: darkorchid " value = " DarkOrchid " > Dark Orchid </ option >
< option style = " background-color: silver " value = " Silver " > Silver </ option >
< option style = " background-color: pink " value = " Pink " > Pink </ option >
< option style = " background-color: wheat " value = " Wheat " > Wheat </ option >
< option style = " background-color: lemonchiffon " value = " LemonChiffon " > Lemon Chiffon </ option >
< option style = " background-color: palegreen " value = " PaleGreen " > Pale Green </ option >
< option style = " background-color: paleturquoise " value = " PaleTurquoise " > Pale Turquoise </ option >
< option style = " background-color: lightblue " value = " LightBlue " > Light Blue </ option >
< option style = " background-color: plum " value = " Plum " > Plum </ option >
< option style = " background-color: white " value = " White " > White </ option >
</ select ></ td >
< td class = " embedded " >
< select class = " med codebuttons " name = 'font' onchange = " alterfont(this.options[this.selectedIndex].value, 'font') " >
< option value = " 0 " >--- < ? php echo $lang_functions [ 'select_font' ] ?> ---</option>
< option value = " Arial " > Arial </ option >
< option value = " Arial Black " > Arial Black </ option >
< option value = " Arial Narrow " > Arial Narrow </ option >
< option value = " Book Antiqua " > Book Antiqua </ option >
< option value = " Century Gothic " > Century Gothic </ option >
< option value = " Comic Sans MS " > Comic Sans MS </ option >
< option value = " Courier New " > Courier New </ option >
< option value = " Fixedsys " > Fixedsys </ option >
< option value = " Garamond " > Garamond </ option >
< option value = " Georgia " > Georgia </ option >
< option value = " Impact " > Impact </ option >
< option value = " Lucida Console " > Lucida Console </ option >
< option value = " Lucida Sans Unicode " > Lucida Sans Unicode </ option >
< option value = " Microsoft Sans Serif " > Microsoft Sans Serif </ option >
< option value = " Palatino Linotype " > Palatino Linotype </ option >
< option value = " System " > System </ option >
< option value = " Tahoma " > Tahoma </ option >
< option value = " Times New Roman " > Times New Roman </ option >
< option value = " Trebuchet MS " > Trebuchet MS </ option >
< option value = " Verdana " > Verdana </ option >
</ select >
</ td >
< td class = " embedded " >
< select class = " med codebuttons " name = 'size' onchange = " alterfont(this.options[this.selectedIndex].value, 'size') " >
< option value = " 0 " >--- < ? php echo $lang_functions [ 'select_size' ] ?> ---</option>
< option value = " 1 " > 1 </ option >
< option value = " 2 " > 2 </ option >
< option value = " 3 " > 3 </ option >
< option value = " 4 " > 4 </ option >
< option value = " 5 " > 5 </ option >
< option value = " 6 " > 6 </ option >
< option value = " 7 " > 7 </ option >
</ select ></ td ></ tr >
</ table >
</ td >
</ tr >
< ? php
if ( $enableattach_attachment == 'yes' ){
?>
< tr >
< td colspan = " 2 " valign = " middle " >
2022-04-01 23:13:42 +08:00
< iframe src = " <?php echo getSchemeAndHttpHost()?>/attachment.php " width = " 100% " height = " 24 " frameborder = " 0 " scrolling = " no " marginheight = " 0 " marginwidth = " 0 " ></ iframe >
2020-12-26 01:42:23 +08:00
</ td >
</ tr >
< ? php
}
print ( " <tr> " );
2022-04-01 23:13:42 +08:00
print ( " <td align= \" left \" ><textarea class= \" bbcode \" cols= \" 100 \" style= \" width: 100%; \" name= \" " . $text . " \" id= \" " . $text . " \" rows= \" 20 \" onkeydown= \" ctrlenter(event,'compose','qr') \" > " . $content . " </textarea> " );
2020-12-26 01:42:23 +08:00
?>
</ td >
2022-04-01 23:13:42 +08:00
< td align = " center " width = " " >
2020-12-26 01:42:23 +08:00
< table cellspacing = " 1 " cellpadding = " 3 " >
< tr >
< ? php
$i = 0 ;
$quickSmilies = array ( 1 , 2 , 3 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 13 , 16 , 17 , 19 , 20 , 21 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 39 , 40 , 41 );
foreach ( $quickSmilies as $smily ) {
if ( $i % 4 == 0 && $i > 0 ) {
print ( '</tr><tr>' );
}
print ( " <td class= \" embedded \" style= \" padding: 3px; \" > " . getSmileIt ( $form , $text , $smily ) . " </td> " );
$i ++ ;
}
?>
</ tr ></ table >
< br />
< a href = " javascript:winop(); " >< ? php echo $lang_functions [ 'text_more_smilies' ] ?> </a>
2022-04-01 23:13:42 +08:00
</ td ></ tr ></ tobdy >
< ? php if ( $withPreview ) { ?>
< tbody id = " <?php echo $previewTbodyId ?> " ></ tbody >
< tbody >
< tr >< td colspan = " 2 " style = " text-align: center;border: none " >
< input id = " <?php echo $btnPreviewId ?> " type = " button " class = " btn " value = " <?php echo $lang_functions['submit_preview'] ?> " onclick = " javascript:textBBCodePreview() " >
< input id = " <?php echo $btnEditId ?> " type = " button " class = " btn " style = " display: none " value = " <?php echo $lang_functions['submit_edit'] ?> " onclick = " javascript:textBBCodeEdit() " >
</ td ></ tr >
</ tbody >
< ? php } ?>
</ table >
2020-12-26 01:42:23 +08:00
< ? php
}
function begin_compose ( $title = " " , $type = " new " , $body = " " , $hassubject = true , $subject = " " , $maxsubjectlength = 100 ){
global $lang_functions ;
if ( $title )
print ( " <h1 align= \" center \" > " . $title . " </h1> " );
switch ( $type ){
2021-04-22 03:24:59 +08:00
case 'new' :
2020-12-26 01:42:23 +08:00
{
$framename = $lang_functions [ 'text_new' ];
break ;
}
2021-04-22 03:24:59 +08:00
case 'reply' :
2020-12-26 01:42:23 +08:00
{
$framename = $lang_functions [ 'text_reply' ];
break ;
}
case 'quote' :
{
$framename = $lang_functions [ 'text_quote' ];
break ;
}
case 'edit' :
{
$framename = $lang_functions [ 'text_edit' ];
break ;
}
default :
{
$framename = $lang_functions [ 'text_new' ];
break ;
}
}
begin_frame ( $framename , true );
print ( " <table class= \" main \" width= \" 100% \" border= \" 1 \" cellspacing= \" 0 \" cellpadding= \" 5 \" > \n " );
if ( $hassubject )
print ( " <tr><td class= \" rowhead \" > " . $lang_functions [ 'row_subject' ] . " </td> " .
2022-04-01 23:13:42 +08:00
" <td class= \" rowfollow \" align= \" left \" ><input type= \" text \" style= \" width: 99%; \" name= \" subject \" maxlength= \" " . $maxsubjectlength . " \" value= \" " . htmlspecialchars ( $subject ) . " \" /></td></tr> \n " );
2020-12-26 01:42:23 +08:00
print ( " <tr><td class= \" rowhead \" valign= \" top \" > " . $lang_functions [ 'row_body' ] . " </td><td class= \" rowfollow \" align= \" left \" ><span style= \" display: none; \" id= \" previewouter \" ></span><div id= \" editorouter \" > " );
textbbcode ( " compose " , " body " , $body , false );
print ( " </div></td></tr> " );
}
function end_compose (){
global $lang_functions ;
print ( " <tr><td colspan= \" 2 \" align= \" center \" ><table><tr><td class= \" embedded \" ><input id= \" qr \" type= \" submit \" class= \" btn \" value= \" " . $lang_functions [ 'submit_submit' ] . " \" /></td><td class= \" embedded \" > " );
print ( " <input type= \" button \" class= \" btn2 \" name= \" previewbutton \" id= \" previewbutton \" value= \" " . $lang_functions [ 'submit_preview' ] . " \" onclick= \" javascript:preview(this.parentNode); \" /> " );
print ( " <input type= \" button \" class= \" btn2 \" style= \" display: none; \" name= \" unpreviewbutton \" id= \" unpreviewbutton \" value= \" " . $lang_functions [ 'submit_edit' ] . " \" onclick= \" javascript:unpreview(this.parentNode); \" /> " );
print ( " </td></tr></table> " );
print ( " </td></tr> " );
print ( " </table> \n " );
end_frame ();
print ( " <p align= \" center \" ><a href= \" tags.php \" target= \" _blank \" > " . $lang_functions [ 'text_tags' ] . " </a> | <a href= \" smilies.php \" target= \" _blank \" > " . $lang_functions [ 'text_smilies' ] . " </a></p> \n " );
}
function insert_suggest ( $keyword , $userid , $pre_escaped = true )
{
if ( mb_strlen ( $keyword , " UTF-8 " ) >= 2 )
{
2021-01-06 00:56:13 +08:00
$userid = intval ( $userid ? ? 0 );
2020-12-26 01:42:23 +08:00
if ( $userid )
sql_query ( " INSERT INTO suggest(keywords, userid, adddate) VALUES ( " . ( $pre_escaped == true ? " ' " . $keyword . " ' " : sqlesc ( $keyword )) . " , " . sqlesc ( $userid ) . " , NOW()) " ) or sqlerr ( __FILE__ , __LINE__ );
}
}
function get_external_tr ( $imdb_url = " " )
{
global $lang_functions ;
global $showextinfo ;
2022-04-14 00:52:28 +08:00
if ( $showextinfo [ 'imdb' ] != 'yes' ) {
return '' ;
}
$ptGen = new Nexus\PTGen\PTGen ();
2020-12-26 01:42:23 +08:00
$imdbNumber = parse_imdb_id ( $imdb_url );
2023-09-24 18:13:41 +08:00
$y = $ptGen -> buildInput ( " url " , $imdbNumber ? " https://www.imdb.com/title/tt " . parse_imdb_id ( $imdb_url ) : " " , $lang_functions [ 'text_imdb_url_note' ], nexus_trans ( 'ptgen.btn_get_desc' ));
2022-04-14 00:52:28 +08:00
return tr ( $lang_functions [ 'row_imdb_url' ], $y , 1 );
2023-09-24 18:13:41 +08:00
// ($showextinfo['imdb'] == 'yes' ? tr($lang_functions['row_imdb_url'], "<input type=\"text\" style=\"width: 99%;\" name=\"url\" value=\"".($imdbNumber ? "https://www.imdb.com/title/tt".parse_imdb_id($imdb_url) : "")."\" /><br /><font class=\"medium\">".$lang_functions['text_imdb_url_note']."</font>", 1) : "");
2020-12-26 01:42:23 +08:00
}
function get_torrent_extinfo_identifier ( $torrentid )
{
2021-01-06 00:56:13 +08:00
$torrentid = intval ( $torrentid ? ? 0 );
2020-12-26 01:42:23 +08:00
$result = array ( 'imdb_id' );
unset ( $result );
if ( $torrentid )
{
$res = sql_query ( " SELECT url FROM torrents WHERE id= " . $torrentid ) or sqlerr ( __FILE__ , __LINE__ );
if ( mysql_num_rows ( $res ) == 1 )
{
$arr = mysql_fetch_array ( $res ) or sqlerr ( __FILE__ , __LINE__ );
$imdb_id = parse_imdb_id ( $arr [ " url " ]);
$result [ 'imdb_id' ] = $imdb_id ;
}
}
return $result ;
}
function parse_imdb_id ( $url )
{
2021-03-17 18:46:40 +08:00
if ( $url && is_numeric ( $url ) && strlen ( $url ) < 7 ) {
$url = str_pad ( $url , 7 , '0' , STR_PAD_LEFT );
}
if ( $url != " " && preg_match ( " /[0-9]+/i " , $url , $matches )) {
2020-12-26 01:42:23 +08:00
return $matches [ 0 ];
}
2022-05-03 23:58:27 +08:00
return '' ;
2020-12-26 01:42:23 +08:00
}
function build_imdb_url ( $imdb_id )
{
2023-09-24 18:13:41 +08:00
return $imdb_id == " " ? " " : " https://www.imdb.com/title/tt " . $imdb_id . " / " ;
2020-12-26 01:42:23 +08:00
}
// it's a stub implemetation here, we need more acurate regression analysis to complete our algorithm
function get_torrent_2_user_value ( $user_snatched_arr )
{
// check if it's current user's torrent
$torrent_2_user_value = 1.0 ;
$torrent_res = sql_query ( " SELECT * FROM torrents WHERE id = " . $user_snatched_arr [ 'torrentid' ]) or sqlerr ( __FILE__ , __LINE__ );
if ( mysql_num_rows ( $torrent_res ) == 1 ) // torrent still exists
{
$torrent_arr = mysql_fetch_array ( $torrent_res ) or sqlerr ( __FILE__ , __LINE__ );
if ( $torrent_arr [ 'owner' ] == $user_snatched_arr [ 'userid' ]) // owner's torrent
{
$torrent_2_user_value *= 0.7 ; // owner's torrent
$torrent_2_user_value += ( $user_snatched_arr [ 'uploaded' ] / $torrent_arr [ 'size' ] ) - 1 > 0 ? 0.2 - exp ( - (( $user_snatched_arr [ 'uploaded' ] / $torrent_arr [ 'size' ] ) - 1 )) : ( $user_snatched_arr [ 'uploaded' ] / $torrent_arr [ 'size' ] ) - 1 ;
$torrent_2_user_value += min ( 0.1 , ( $user_snatched_arr [ 'seedtime' ] / 37 * 60 * 60 ) * 0.1 );
}
else
{
if ( $user_snatched_arr [ 'finished' ] == 'yes' )
{
$torrent_2_user_value *= 0.5 ;
$torrent_2_user_value += ( $user_snatched_arr [ 'uploaded' ] / $torrent_arr [ 'size' ] ) - 1 > 0 ? 0.4 - exp ( - (( $user_snatched_arr [ 'uploaded' ] / $torrent_arr [ 'size' ] ) - 1 )) : ( $user_snatched_arr [ 'uploaded' ] / $torrent_arr [ 'size' ] ) - 1 ;
$torrent_2_user_value += min ( 0.1 , ( $user_snatched_arr [ 'seedtime' ] / 22 * 60 * 60 ) * 0.1 );
}
else
{
$torrent_2_user_value *= 0.2 ;
$torrent_2_user_value += min ( 0.05 , ( $user_snatched_arr [ 'leechtime' ] / 24 * 60 * 60 ) * 0.1 ); // usually leechtime could not explain much
}
}
}
else // torrent already deleted, half blind guess, be conservative
{
2021-04-22 03:24:59 +08:00
2020-12-26 01:42:23 +08:00
if ( $user_snatched_arr [ 'finished' ] == 'no' && $user_snatched_arr [ 'uploaded' ] > 0 && $user_snatched_arr [ 'downloaded' ] == 0 ) // possibly owner
{
$torrent_2_user_value *= 0.55 ; //conservative
$torrent_2_user_value += min ( 0.05 , ( $user_snatched_arr [ 'leechtime' ] / 31 * 60 * 60 ) * 0.1 );
$torrent_2_user_value += min ( 0.1 , ( $user_snatched_arr [ 'seedtime' ] / 31 * 60 * 60 ) * 0.1 );
}
else if ( $user_snatched_arr [ 'downloaded' ] > 0 ) // possibly leecher
{
$torrent_2_user_value *= 0.38 ; //conservative
$torrent_2_user_value *= min ( 0.22 , 0.1 * $user_snatched_arr [ 'uploaded' ] / $user_snatched_arr [ 'downloaded' ]); // 0.3 for conservative
$torrent_2_user_value += min ( 0.05 , ( $user_snatched_arr [ 'leechtime' ] / 22 * 60 * 60 ) * 0.1 );
$torrent_2_user_value += min ( 0.12 , ( $user_snatched_arr [ 'seedtime' ] / 22 * 60 * 60 ) * 0.1 );
}
else
$torrent_2_user_value *= 0.0 ;
}
return $torrent_2_user_value ;
}
function cur_user_check () {
global $lang_functions ;
global $CURUSER ;
if ( $CURUSER )
{
sql_query ( " UPDATE users SET lang= " . get_langid_from_langcookie () . " WHERE id = " . $CURUSER [ 'id' ]);
stderr ( $lang_functions [ 'std_permission_denied' ], $lang_functions [ 'std_already_logged_in' ]);
}
}
function KPS ( $type = " + " , $point = " 1.0 " , $id = " " ) {
global $bonus_tweak ;
if ( $point != 0 ){
$point = sqlesc ( $point );
if ( $bonus_tweak == " enable " || $bonus_tweak == " disablesave " ){
sql_query ( " UPDATE users SET seedbonus = seedbonus $type $point WHERE id = " . sqlesc ( $id )) or sqlerr ( __FILE__ , __LINE__ );
}
}
else return ;
}
function get_agent ( $peer_id , $agent )
{
return substr ( $agent , 0 , ( strpos ( $agent , " ; " ) == false ? strlen ( $agent ) : strpos ( $agent , " ; " )));
}
function EmailBanned ( $newEmail )
{
$newEmail = trim ( strtolower ( $newEmail ));
$sql = sql_query ( " SELECT * FROM bannedemails " ) or sqlerr ( __FILE__ , __LINE__ );
$list = mysql_fetch_array ( $sql );
2020-12-28 20:52:54 +08:00
$addresses = explode ( ' ' , preg_replace ( " /[[:space:]]+/ " , " " , trim ( $list [ 'value' ])) );
2020-12-26 01:42:23 +08:00
if ( count ( $addresses ) > 0 )
{
foreach ( $addresses as $email )
{
$email = trim ( strtolower ( preg_replace ( '/\./' , '\\.' , $email )));
if ( strstr ( $email , " @ " ))
{
if ( preg_match ( '/^@/' , $email ))
{ // Any user @host?
// Expand the match expression to catch hosts and
// sub-domains
$email = preg_replace ( '/^@/' , '[@\\.]' , $email );
if ( preg_match ( " / " . $email . " $ / " , $newEmail ))
return true ;
}
}
elseif ( preg_match ( '/@$/' , $email ))
{ // User at any host?
if ( preg_match ( " /^ " . $email . " / " , $newEmail ))
return true ;
}
else
{ // User@host
if ( strtolower ( $email ) == $newEmail )
return true ;
}
}
}
return false ;
}
function EmailAllowed ( $newEmail )
{
global $restrictemaildomain ;
if ( $restrictemaildomain == 'yes' ){
$newEmail = trim ( strtolower ( $newEmail ));
$sql = sql_query ( " SELECT * FROM allowedemails " ) or sqlerr ( __FILE__ , __LINE__ );
$list = mysql_fetch_array ( $sql );
2022-02-10 22:30:26 +08:00
$addresses = explode ( ' ' , preg_replace ( " /[[:space:]]+/ " , " " , trim ( $list [ 'value' ])) );
2020-12-26 01:42:23 +08:00
if ( count ( $addresses ) > 0 )
{
foreach ( $addresses as $email )
{
$email = trim ( strtolower ( preg_replace ( '/\./' , '\\.' , $email )));
if ( strstr ( $email , " @ " ))
{
if ( preg_match ( '/^@/' , $email ))
{ // Any user @host?
// Expand the match expression to catch hosts and
// sub-domains
$email = preg_replace ( '/^@/' , '[@\\.]' , $email );
if ( preg_match ( '/' . $email . '$/' , $newEmail ))
return true ;
}
}
elseif ( preg_match ( '/@$/' , $email ))
{ // User at any host?
if ( preg_match ( " /^ " . $email . " / " , $newEmail ))
return true ;
}
else
{ // User@host
if ( strtolower ( $email ) == $newEmail )
return true ;
}
}
}
return false ;
}
else return true ;
}
function allowedemails ()
{
$sql = sql_query ( " SELECT * FROM allowedemails " ) or sqlerr ( __FILE__ , __LINE__ );
$list = mysql_fetch_array ( $sql );
return $list [ 'value' ];
}
2021-04-21 00:07:32 +08:00
function nexus_redirect ( $url )
2020-12-26 01:42:23 +08:00
{
2021-03-02 21:03:02 +08:00
if ( substr ( $url , 0 , 4 ) != 'http' ) {
$url = getSchemeAndHttpHost () . '/' . trim ( $url , '/' );
}
2020-12-26 01:42:23 +08:00
if ( ! headers_sent ()){
2021-03-02 21:03:02 +08:00
header ( " Location: $url " , true , 302 );
} else {
echo " <script type= \" text/javascript \" >window.location.href = ' $url ';</script> " ;
}
2020-12-26 01:42:23 +08:00
exit ;
}
function set_cachetimestamp ( $id , $field = " cache_stamp " )
{
sql_query ( " UPDATE torrents SET $field = " . time () . " WHERE id = " . sqlesc ( $id )) or sqlerr ( __FILE__ , __LINE__ );
}
function reset_cachetimestamp ( $id , $field = " cache_stamp " )
{
sql_query ( " UPDATE torrents SET $field = 0 WHERE id = " . sqlesc ( $id )) or sqlerr ( __FILE__ , __LINE__ );
}
function cache_check ( $file = 'cachefile' , $endpage = true , $cachetime = 600 ) {
global $lang_functions ;
global $rootpath , $cache , $CURLANGDIR ;
$cachefile = $rootpath . $cache . " / " . $CURLANGDIR . '/' . $file . '.html' ;
// Serve from the cache if it is younger than $cachetime
if ( file_exists ( $cachefile ) && ( time () - $cachetime < filemtime ( $cachefile )))
{
include ( $cachefile );
if ( $endpage )
{
print ( " <p align= \" center \" ><font class= \" small \" > " . $lang_functions [ 'text_page_last_updated' ] . date ( 'Y-m-d H:i:s' , filemtime ( $cachefile )) . " </font></p> " );
end_main_frame ();
stdfoot ();
exit ;
}
return false ;
}
ob_start ();
return true ;
}
function cache_save ( $file = 'cachefile' ) {
global $rootpath , $cache ;
global $CURLANGDIR ;
$cachefile = $rootpath . $cache . " / " . $CURLANGDIR . '/' . $file . '.html' ;
$fp = fopen ( $cachefile , 'w' );
// save the contents of output buffer to the file
fwrite ( $fp , ob_get_contents ());
// close the file
fclose ( $fp );
// Send the output to the browser
ob_end_flush ();
}
function get_email_encode ( $lang )
{
if ( $lang == 'chs' || $lang == 'cht' )
return " gbk " ;
else
return " utf-8 " ;
}
function change_email_encode ( $lang , $content )
{
return iconv ( " utf-8 " , get_email_encode ( $lang ) . " //IGNORE " , $content );
}
function safe_email ( $email ) {
$email = str_replace ( " < " , " " , $email );
$email = str_replace ( " > " , " " , $email );
$email = str_replace ( " \ ' " , " " , $email );
$email = str_replace ( '\"' , " " , $email );
$email = str_replace ( " \\ \\ " , " " , $email );
return $email ;
}
function check_email ( $email ) {
2022-11-24 18:51:03 +08:00
if ( ! preg_match ( '/^[A-Za-z0-9][A-Za-z0-9_.+\-]*@[A-Za-z0-9][A-Za-z0-9_+\-]*(\.[A-Za-z0-9][A-Za-z0-9_+\-]*)+$/' , $email )) {
return false ;
}
2023-01-07 16:27:27 +08:00
$bannedEmails = \Nexus\Database\NexusDB :: select ( 'select * from bannedemails' );
2023-06-14 03:20:04 +08:00
$bannedEmailsArr = array_filter ( preg_split ( '/[\s]+/' , $bannedEmails [ 0 ][ 'value' ] ? ? '' ));
2022-11-24 18:51:03 +08:00
if ( empty ( $bannedEmailsArr )) {
return true ;
}
foreach ( $bannedEmailsArr as $ban ) {
if ( str_ends_with ( $email , $ban )) {
do_log ( " [BANNED_EMAIL] email: $email is banned by record: $ban " );
return false ;
}
}
2020-12-26 01:42:23 +08:00
return true ;
}
function sent_mail ( $to , $fromname , $fromemail , $subject , $body , $type = " confirmation " , $showmsg = true , $multiple = false , $multiplemail = '' , $hdr_encoding = 'UTF-8' , $specialcase = '' ) {
2021-01-14 20:44:24 +08:00
do_log ( " to: $to , fromname: $fromname , fromemail: $fromemail , subject: $subject , body: $body . type: $type " );
2020-12-26 01:42:23 +08:00
global $lang_functions ;
global $rootpath , $SITENAME , $SITEEMAIL , $smtptype , $smtp , $smtp_host , $smtp_port , $smtp_from , $smtpaddress , $smtpport , $accountname , $accountpassword ;
# Is the OS Windows or Mac or Linux?
if ( strtoupper ( substr ( PHP_OS , 0 , 3 ) == 'WIN' )) {
$eol = " \r \n " ;
$windows = true ;
}
elseif ( strtoupper ( substr ( PHP_OS , 0 , 3 ) == 'MAC' ))
$eol = " \r " ;
else
$eol = " \n " ;
if ( $smtptype == 'none' )
return false ;
if ( $smtptype == 'default' ) {
@ mail ( $to , " =? " . $hdr_encoding . " ?B? " . base64_encode ( $subject ) . " ?= " , $body , " From: " . $SITEEMAIL . $eol . " Content-type: text/html; charset= " . $hdr_encoding . $eol , " -f $SITEEMAIL " ) or stderr ( $lang_functions [ 'std_error' ], $lang_functions [ 'text_unable_to_send_mail' ]);
}
elseif ( $smtptype == 'advanced' ) {
$mid = md5 ( getip () . $fromname );
$name = $_SERVER [ " SERVER_NAME " ];
2021-01-06 00:56:13 +08:00
$headers = '' ;
2020-12-26 01:42:23 +08:00
$headers .= " From: $fromname < $fromemail > " . $eol ;
$headers .= " Reply-To: $fromname < $fromemail > " . $eol ;
$headers .= " Return-Path: $fromname < $fromemail > " . $eol ;
$headers .= " Message-ID: < $mid thesystem@ $name > " . $eol ;
$headers .= " X-Mailer: PHP v " . phpversion () . $eol ;
$headers .= " MIME-Version: 1.0 " . $eol ;
$headers .= " Content-type: text/html; charset= " . $hdr_encoding . $eol ;
$headers .= " X-Sender: PHP " . $eol ;
if ( $multiple )
{
$bcc_multiplemail = " " ;
foreach ( $multiplemail as $toemail )
$bcc_multiplemail = $bcc_multiplemail . ( $bcc_multiplemail != " " ? " , " : " " ) . $toemail ;
$headers .= " Bcc: $multiplemail . $eol " ;
}
if ( $smtp == " yes " ) {
ini_set ( 'SMTP' , $smtp_host );
ini_set ( 'smtp_port' , $smtp_port );
if ( $windows )
ini_set ( 'sendmail_from' , $smtp_from );
}
@ mail ( $to , " =? " . $hdr_encoding . " ?B? " . base64_encode ( $subject ) . " ?= " , $body , $headers ) or stderr ( $lang_functions [ 'std_error' ], $lang_functions [ 'text_unable_to_send_mail' ]);
2022-05-13 17:55:49 +08:00
ini_restore ( 'SMTP' );
ini_restore ( 'smtp_port' );
2020-12-26 01:42:23 +08:00
if ( $windows )
2022-05-13 17:55:49 +08:00
ini_restore ( 'sendmail_from' );
2020-12-26 01:42:23 +08:00
}
elseif ( $smtptype == 'external' ) {
2021-01-13 19:32:26 +08:00
/*
2020-12-26 01:42:23 +08:00
require_once ( $rootpath . 'include/smtp/smtp.lib.php' );
$mail = new smtp ( $hdr_encoding , 'eYou' );
2021-01-11 22:00:46 +08:00
$mail -> debug ( true );
2020-12-26 01:42:23 +08:00
$mail -> open ( $smtpaddress , $smtpport );
$mail -> auth ( $accountname , $accountpassword );
// $mail->bcc($multiplemail);
$mail -> from ( $SITEEMAIL );
if ( $multiple )
{
$mail -> multi_to_head ( $to );
foreach ( $multiplemail as $toemail )
$mail -> multi_to ( $toemail );
}
else
$mail -> to ( $to );
$mail -> mime_content_transfer_encoding ();
$mail -> mime_charset ( 'text/html' , $hdr_encoding );
$mail -> subject ( $subject );
$mail -> body ( $body );
$mail -> send () or stderr ( $lang_functions [ 'std_error' ], $lang_functions [ 'text_unable_to_send_mail' ]);
$mail -> close ();
2021-01-13 19:32:26 +08:00
*/
/**
2022-03-31 22:22:04 +08:00
* use Symfony Mailer instead
2021-01-13 19:32:26 +08:00
*
2022-03-31 22:22:04 +08:00
* @ since 1.7
2021-01-13 19:32:26 +08:00
* @ author xiaomlove < 1939737565 @ qq . com >
*/
2022-03-31 22:22:04 +08:00
$toolRep = new \App\Repositories\ToolRepository ();
$sendResult = $toolRep -> sendMail ( $to , $subject , $body );
if ( $sendResult === false ) {
2021-01-14 20:44:24 +08:00
stderr ( $lang_functions [ 'std_error' ], $lang_functions [ 'text_unable_to_send_mail' ]);
}
2020-12-26 01:42:23 +08:00
}
if ( $showmsg ) {
if ( $type == " confirmation " )
stderr ( $lang_functions [ 'std_success' ], $lang_functions [ 'std_confirmation_email_sent' ] . " <b> " . htmlspecialchars ( $to ) . " </b>. \n " .
$lang_functions [ 'std_please_wait' ], false );
elseif ( $type == " details " )
stderr ( $lang_functions [ 'std_success' ], $lang_functions [ 'std_account_details_sent' ] . " <b> " . htmlspecialchars ( $to ) . " </b>. \n " .
$lang_functions [ 'std_please_wait' ], false );
} else
return true ;
}
function failedloginscheck ( $type = 'Login' ) {
global $lang_functions ;
global $maxloginattempts ;
$total = 0 ;
$ip = sqlesc ( getip ());
$Query = sql_query ( " SELECT SUM(attempts) FROM loginattempts WHERE ip= $ip " ) or sqlerr ( __FILE__ , __LINE__ );
list ( $total ) = mysql_fetch_array ( $Query );
if ( $total >= $maxloginattempts ) {
sql_query ( " UPDATE loginattempts SET banned = 'yes' WHERE ip= $ip " ) or sqlerr ( __FILE__ , __LINE__ );
2023-06-13 01:02:44 +08:00
stderr ( $type . $lang_functions [ 'std_locked' ] . $maxloginattempts . $lang_functions [ 'std_attempts_reached' ], $lang_functions [ 'std_your_ip_banned' ], true , true );
2020-12-26 01:42:23 +08:00
}
}
function failedlogins ( $type = 'login' , $recover = false , $head = true )
{
global $lang_functions ;
$ip = sqlesc ( getip ());
$added = sqlesc ( date ( " Y-m-d H:i:s " ));
$a = ( @ mysql_fetch_row ( @ sql_query ( " select count(*) from loginattempts where ip= $ip " ))) or sqlerr ( __FILE__ , __LINE__ );
if ( $a [ 0 ] == 0 )
sql_query ( " INSERT INTO loginattempts (ip, added, attempts) VALUES ( $ip , $added , 1) " ) or sqlerr ( __FILE__ , __LINE__ );
else
sql_query ( " UPDATE loginattempts SET attempts = attempts + 1 where ip= $ip " ) or sqlerr ( __FILE__ , __LINE__ );
if ( $recover )
sql_query ( " UPDATE loginattempts SET type = 'recover' WHERE ip = $ip " ) or sqlerr ( __FILE__ , __LINE__ );
if ( $type == 'silent' )
return ;
elseif ( $type == 'login' )
{
stderr ( $lang_functions [ 'std_login_failed' ], $lang_functions [ 'std_login_failed_note' ], false );
}
else
stderr ( $lang_functions [ 'std_failed' ], $type , false , $head );
}
function login_failedlogins ( $type = 'login' , $recover = false , $head = true )
{
global $lang_functions ;
$ip = sqlesc ( getip ());
$added = sqlesc ( date ( " Y-m-d H:i:s " ));
$a = ( @ mysql_fetch_row ( @ sql_query ( " select count(*) from loginattempts where ip= $ip " ))) or sqlerr ( __FILE__ , __LINE__ );
if ( $a [ 0 ] == 0 )
sql_query ( " INSERT INTO loginattempts (ip, added, attempts) VALUES ( $ip , $added , 1) " ) or sqlerr ( __FILE__ , __LINE__ );
else
sql_query ( " UPDATE loginattempts SET attempts = attempts + 1 where ip= $ip " ) or sqlerr ( __FILE__ , __LINE__ );
if ( $recover )
sql_query ( " UPDATE loginattempts SET type = 'recover' WHERE ip = $ip " ) or sqlerr ( __FILE__ , __LINE__ );
if ( $type == 'silent' )
return ;
elseif ( $type == 'login' )
{
stderr ( $lang_functions [ 'std_login_failed' ], $lang_functions [ 'std_login_failed_note' ], false );
}
else
stderr ( $lang_functions [ 'std_recover_failed' ], $type , false , $head );
}
function remaining ( $type = 'login' ) {
global $maxloginattempts ;
$total = 0 ;
$ip = sqlesc ( getip ());
$Query = sql_query ( " SELECT SUM(attempts) FROM loginattempts WHERE ip= $ip " ) or sqlerr ( __FILE__ , __LINE__ );
list ( $total ) = mysql_fetch_array ( $Query );
$remaining = $maxloginattempts - $total ;
if ( $remaining <= 2 )
$remaining = " <font color= \" red \" size= \" 2 \" >[ " . $remaining . " ]</font> " ;
else
$remaining = " <font color= \" green \" size= \" 2 \" >[ " . $remaining . " ]</font> " ;
return $remaining ;
}
function registration_check ( $type = " invitesystem " , $maxuserscheck = true , $ipcheck = true ) {
global $lang_functions ;
global $invitesystem , $registration , $maxusers , $SITENAME , $maxip ;
if ( $type == " invitesystem " ) {
if ( $invitesystem == " no " ) {
2023-05-13 01:59:51 +08:00
stderr ( $lang_functions [ 'std_oops' ], $lang_functions [ 'std_invite_system_disabled' ], 0 , true );
2020-12-26 01:42:23 +08:00
}
}
if ( $type == " normal " ) {
if ( $registration == " no " ) {
2023-05-13 01:59:51 +08:00
stderr ( $lang_functions [ 'std_sorry' ], $lang_functions [ 'std_open_registration_disabled' ], 0 , true );
2020-12-26 01:42:23 +08:00
}
}
if ( $maxuserscheck ) {
$res = sql_query ( " SELECT COUNT(*) FROM users " ) or sqlerr ( __FILE__ , __LINE__ );
$arr = mysql_fetch_row ( $res );
if ( $arr [ 0 ] >= $maxusers )
2023-05-13 01:59:51 +08:00
stderr ( $lang_functions [ 'std_sorry' ], $lang_functions [ 'std_account_limit_reached' ], 0 , true );
2020-12-26 01:42:23 +08:00
}
if ( $ipcheck ) {
$ip = getip () ;
$a = ( @ mysql_fetch_row ( @ sql_query ( " select count(*) from users where ip=' " . mysql_real_escape_string ( $ip ) . " ' " ))) or sqlerr ( __FILE__ , __LINE__ );
if ( $a [ 0 ] > $maxip )
2023-05-13 01:59:51 +08:00
stderr ( $lang_functions [ 'std_sorry' ], $lang_functions [ 'std_the_ip' ] . " <b> " . htmlspecialchars ( $ip ) . " </b> " . $lang_functions [ 'std_used_many_times' ], false , true );
2020-12-26 01:42:23 +08:00
}
return true ;
}
function random_str ( $length = " 6 " )
{
$set = array ( " A " , " B " , " C " , " D " , " E " , " F " , " G " , " H " , " P " , " R " , " M " , " N " , " 1 " , " 2 " , " 3 " , " 4 " , " 5 " , " 6 " , " 7 " , " 8 " , " 9 " );
2020-12-29 03:02:34 +08:00
$str = '' ;
2020-12-26 01:42:23 +08:00
for ( $i = 1 ; $i <= $length ; $i ++ )
{
$ch = rand ( 0 , count ( $set ) - 1 );
$str .= $set [ $ch ];
}
return $str ;
}
function image_code () {
$randomstr = random_str ();
$imagehash = md5 ( $randomstr );
$dateline = time ();
$sql = 'INSERT INTO `regimages` (`imagehash`, `imagestring`, `dateline`) VALUES (\'' . $imagehash . '\', \'' . $randomstr . '\', \'' . $dateline . '\');' ;
2021-06-15 10:35:13 +08:00
sql_query ( $sql );
2020-12-26 01:42:23 +08:00
return $imagehash ;
}
function check_code ( $imagehash , $imagestring , $where = 'signup.php' , $maxattemptlog = false , $head = true ) {
global $lang_functions ;
2022-05-25 02:15:41 +08:00
global $iv ;
if ( $iv !== 'yes' ) {
return true ;
}
2020-12-26 01:42:23 +08:00
$query = sprintf ( " SELECT * FROM regimages WHERE imagehash='%s' AND imagestring='%s' " ,
2023-01-07 19:34:59 +08:00
mysql_real_escape_string (( string ) $imagehash ),
mysql_real_escape_string (( string ) $imagestring )
);
2020-12-26 01:42:23 +08:00
$sql = sql_query ( $query );
$imgcheck = mysql_fetch_array ( $sql );
if ( ! $imgcheck [ 'dateline' ]) {
$delete = sprintf ( " DELETE FROM regimages WHERE imagehash='%s' " ,
2023-01-07 19:34:59 +08:00
mysql_real_escape_string (( string ) $imagehash )
);
2020-12-26 01:42:23 +08:00
sql_query ( $delete );
if ( ! $maxattemptlog )
2022-05-06 17:42:18 +08:00
stderr ( 'Error' , $lang_functions [ 'std_invalid_image_code' ] . " <a href= \" " . htmlspecialchars ( $where ) . " \" > " . $lang_functions [ 'std_here_to_request_new' ], false );
2020-12-26 01:42:23 +08:00
else
failedlogins ( $lang_functions [ 'std_invalid_image_code' ] . " <a href= \" " . htmlspecialchars ( $where ) . " \" > " . $lang_functions [ 'std_here_to_request_new' ], true , $head );
} else {
$delete = sprintf ( " DELETE FROM regimages WHERE imagehash='%s' " ,
2023-01-07 19:34:59 +08:00
mysql_real_escape_string (( string ) $imagehash )
);
2020-12-26 01:42:23 +08:00
sql_query ( $delete );
return true ;
}
}
function show_image_code () {
global $lang_functions ;
global $iv ;
if ( $iv == " yes " ) {
unset ( $imagehash );
$imagehash = image_code () ;
print ( " <tr><td class= \" rowhead \" > " . $lang_functions [ 'row_security_image' ] . " </td> " );
2021-02-03 18:41:53 +08:00
print ( " <td align= \" left \" ><img src= \" " . htmlspecialchars ( " image.php?action=regimage&imagehash= " . $imagehash . " &secret= " . ( $_GET [ 'secret' ] ? ? '' )) . " \" border= \" 0 \" alt= \" CAPTCHA \" /></td></tr> " );
2020-12-26 01:42:23 +08:00
print ( " <tr><td class= \" rowhead \" > " . $lang_functions [ 'row_security_code' ] . " </td><td align= \" left \" > " );
print ( " <input type= \" text \" autocomplete= \" off \" style= \" width: 180px; border: 1px solid gray \" name= \" imagestring \" value= \" \" /> " );
print ( " <input type= \" hidden \" name= \" imagehash \" value= \" $imagehash\ " /></ td ></ tr > " );
}
}
function get_ip_location ( $ip )
{
global $lang_functions ;
global $Cache ;
2021-06-07 15:41:47 +08:00
static $locations ;
if ( isset ( $locations [ $ip ])) {
return $locations [ $ip ];
}
2022-04-18 20:05:46 +08:00
/**
* @ since 1.7 . 4
*/
$arr = get_ip_location_from_geoip ( $ip );
2022-07-23 15:05:32 +08:00
$result = [];
if ( $arr ) {
$result [] = $arr [ 'name' ];
} else {
$result [] = $lang_functions [ 'text_unknown' ];
}
$result [] = $lang_functions [ 'text_user_ip' ] . " : " . trim ( $ip , ',' );
2022-04-18 20:05:46 +08:00
return $locations [ $ip ] = $result ;
2021-06-07 15:41:47 +08:00
$cacheKey = " location_ $ip " ;
if ( ! $ret = $Cache -> get_value ( $cacheKey )){
2020-12-26 01:42:23 +08:00
$ret = array ();
2021-06-07 15:41:47 +08:00
// $res = sql_query("SELECT * FROM locations") or sqlerr(__FILE__, __LINE__);
// while ($row = mysql_fetch_array($res))
// $ret[] = $row;
//get from geoip2
$row = get_ip_location_from_geoip ( $ip );
if ( $row ) {
$ret [] = $row ;
}
$Cache -> cache_value ( $cacheKey , $ret , 152800 );
2020-12-26 01:42:23 +08:00
}
$location = array ( $lang_functions [ 'text_unknown' ], " " );
foreach ( $ret AS $arr )
{
2021-06-07 17:16:43 +08:00
$location = array ( $arr [ " name " ], $lang_functions [ 'text_user_ip' ] . " : " . $ip );
2021-06-07 15:41:47 +08:00
break ;
// if(in_ip_range(false, $ip, $arr["start_ip"], $arr["end_ip"]))
// {
// $location = array($arr["name"], $lang_functions['text_user_ip'].": " . $ip . ($arr["location_main"] != "" ? " ".$lang_functions['text_location_main'].": " . $arr["location_main"] : ""). ($arr["location_sub"] != "" ? " ".$lang_functions['text_location_sub'].": " . $arr["location_sub"] : "") . " ".$lang_functions['text_ip_range'].": " . $arr["start_ip"] . " ~ ". $arr["end_ip"]);
// break;
// }
2020-12-26 01:42:23 +08:00
}
return $location ;
}
function in_ip_range ( $long , $targetip , $ip_one , $ip_two = false )
{
// if only one ip, check if is this ip
if ( $ip_two === false ){
if (( $long ? ( long2ip ( $ip_one ) == $targetip ) : ( $ip_one == $targetip ))){
$ip = true ;
}
else {
$ip = false ;
}
}
else {
if ( $long ? ( $ip_one <= ip2long ( $targetip ) && $ip_two >= ip2long ( $targetip )) : ( ip2long ( $ip_one ) <= ip2long ( $targetip ) && ip2long ( $ip_two ) >= ip2long ( $targetip ))){
$ip = true ;
}
else {
$ip = false ;
}
}
return $ip ;
}
function validip_format ( $ip )
{
$ipPattern =
'/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.' .
'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.' .
'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.' .
'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/' ;
return preg_match ( $ipPattern , $ip );
}
function maxslots () {
global $lang_functions ;
global $CURUSER , $maxdlsystem ;
$gigs = $CURUSER [ " uploaded " ] / ( 1024 * 1024 * 1024 );
$ratio = (( $CURUSER [ " downloaded " ] > 0 ) ? ( $CURUSER [ " uploaded " ] / $CURUSER [ " downloaded " ]) : 1 );
if ( $ratio < 0.5 || $gigs < 5 ) $max = 1 ;
elseif ( $ratio < 0.65 || $gigs < 6.5 ) $max = 2 ;
elseif ( $ratio < 0.8 || $gigs < 8 ) $max = 3 ;
elseif ( $ratio < 0.95 || $gigs < 9.5 ) $max = 4 ;
else $max = 0 ;
if ( $maxdlsystem == " yes " ) {
if ( get_user_class () < UC_VIP ) {
if ( $max > 0 )
print ( " <font class='color_slots'> " . $lang_functions [ 'text_slots' ] . " </font><a href= \" faq.php#id215 \" > $max </a> " );
else
print ( " <font class='color_slots'> " . $lang_functions [ 'text_slots' ] . " </font> " . $lang_functions [ 'text_unlimited' ]);
} else
print ( " <font class='color_slots'> " . $lang_functions [ 'text_slots' ] . " </font> " . $lang_functions [ 'text_unlimited' ]);
} else
print ( " <font class='color_slots'> " . $lang_functions [ 'text_slots' ] . " </font> " . $lang_functions [ 'text_unlimited' ]);
}
function WriteConfig ( $configname = NULL , $config = NULL ) {
global $lang_functions , $CONFIGURATIONS ;
if ( file_exists ( 'config/allconfig.php' )) {
require ( 'config/allconfig.php' );
}
if ( $configname ) {
$$configname = $config ;
}
$path = './config/allconfig.php' ;
if ( ! file_exists ( $path ) || ! is_writable ( $path )) {
stdmsg ( $lang_functions [ 'std_error' ], $lang_functions [ 'std_cannot_read_file' ] . " [<b> " . htmlspecialchars ( $path ) . " </b>] " . $lang_functions [ 'std_access_permission_note' ]);
}
$data = " <?php \n " ;
foreach ( $CONFIGURATIONS as $CONFIGURATION ) {
$data .= " \$ $CONFIGURATION = " . getExportedValue ( $$CONFIGURATION ) . " ; \n " ;
}
$fp = @ fopen ( $path , 'w' );
if ( ! $fp ) {
stdmsg ( $lang_functions [ 'std_error' ], $lang_functions [ 'std_cannot_open_file' ] . " [<b> " . htmlspecialchars ( $path ) . " </b>] " . $lang_functions [ 'std_to_save_info' ] . $lang_functions [ 'std_access_permission_note' ]);
}
$Res = @ fwrite ( $fp , $data );
if ( empty ( $Res )) {
stdmsg ( $lang_functions [ 'std_error' ], $lang_functions [ 'text_cannot_save_info_in' ] . " [<b> " . htmlspecialchars ( $path ) . " </b>] " . $lang_functions [ 'std_access_permission_note' ]);
}
fclose ( $fp );
return true ;
}
function getExportedValue ( $input , $t = null ) {
switch ( gettype ( $input )) {
case 'string' :
return " ' " . str_replace ( array ( " \\ " , " ' " ), array ( " \\ \\ " , " \ ' " ), $input ) . " ' " ;
case 'array' :
$output = " array( \r " ;
foreach ( $input as $key => $value ) {
$output .= $t . " \t " . getExportedValue ( $key , $t . " \t " ) . ' => ' . getExportedValue ( $value , $t . " \t " );
$output .= " , \n " ;
}
$output .= $t . ')' ;
return $output ;
case 'boolean' :
return $input ? 'true' : 'false' ;
case 'NULL' :
return 'NULL' ;
case 'integer' :
case 'double' :
case 'float' :
return " ' " . ( string ) $input . " ' " ;
}
return 'NULL' ;
}
2021-01-22 19:43:15 +08:00
function dbconn ( $autoclean = false , $doLogin = true )
2020-12-26 01:42:23 +08:00
{
2021-01-29 19:44:50 +08:00
global $useCronTriggerCleanUp ;
2021-06-08 10:42:39 +08:00
\Nexus\Database\NexusDB :: getInstance () -> autoConnect ();
2021-01-22 19:43:15 +08:00
if ( $doLogin ) {
userlogin ();
}
2021-01-29 19:44:50 +08:00
if ( ! $useCronTriggerCleanUp && $autoclean ) {
register_shutdown_function ( " autoclean " );
}
2020-12-26 01:42:23 +08:00
}
function userlogin () {
2022-07-09 18:06:09 +08:00
// do_log("COOKIE:" . json_encode($_COOKIE) . ", uid: " . (isset($_COOKIE['c_secure_uid']) ? base64($_COOKIE["c_secure_uid"],false) : ''));
2021-02-03 18:41:53 +08:00
static $loginResult ;
if ( ! is_null ( $loginResult )) {
return $loginResult ;
}
2020-12-26 01:42:23 +08:00
global $lang_functions ;
global $Cache ;
global $SITE_ONLINE , $oldip ;
global $enablesqldebug_tweak , $sqldebug_tweak ;
unset ( $GLOBALS [ " CURUSER " ]);
2022-08-25 21:45:55 +08:00
$log = " cookie: " . json_encode ( $_COOKIE );
2020-12-26 01:42:23 +08:00
$ip = getip ();
$nip = ip2long ( $ip );
if ( $nip ) //$nip would be false for IPv6 address
{
$res = sql_query ( " SELECT * FROM bans WHERE $nip >= first AND $nip <= last " ) or sqlerr ( __FILE__ , __LINE__ );
if ( mysql_num_rows ( $res ) > 0 )
{
header ( " HTTP/1.0 403 Forbidden " );
print ( " <html><head><meta http-equiv= \" Content-Type \" content= \" text/html; charset=utf-8 \" ></head><body> " . $lang_functions [ 'text_unauthorized_ip' ] . " </body></html> \n " );
die ;
}
}
2021-02-03 18:41:53 +08:00
if ( empty ( $_COOKIE [ " c_secure_pass " ]) || empty ( $_COOKIE [ " c_secure_uid " ]) || empty ( $_COOKIE [ " c_secure_login " ])) {
2022-08-25 21:45:55 +08:00
do_log ( " $log , param not enough " );
2021-02-03 18:41:53 +08:00
return $loginResult = false ;
}
2020-12-26 01:42:23 +08:00
if ( $_COOKIE [ " c_secure_login " ] == base64 ( " yeah " ))
{
//if (empty($_SESSION["s_secure_uid"]) || empty($_SESSION["s_secure_pass"]))
//return;
}
$b_id = base64 ( $_COOKIE [ " c_secure_uid " ], false );
2021-01-06 00:56:13 +08:00
$id = intval ( $b_id ? ? 0 );
2021-02-03 18:41:53 +08:00
if ( ! $id || ! is_valid_id ( $id ) || strlen ( $_COOKIE [ " c_secure_pass " ]) != 32 ) {
2022-08-25 21:45:55 +08:00
do_log ( " $log , invalid c_secure_uid " );
2021-02-03 18:41:53 +08:00
return $loginResult = false ;
}
2020-12-26 01:42:23 +08:00
if ( $_COOKIE [ " c_secure_login " ] == base64 ( " yeah " ))
{
//if (strlen($_SESSION["s_secure_pass"]) != 32)
//return;
}
$res = sql_query ( " SELECT * FROM users WHERE users.id = " . sqlesc ( $id ) . " AND users.enabled='yes' AND users.status = 'confirmed' LIMIT 1 " );
$row = mysql_fetch_array ( $res );
2021-02-03 18:41:53 +08:00
if ( ! $row ) {
2022-08-25 21:45:55 +08:00
do_log ( " $log , c_secure_uid not exists " );
2021-02-03 18:41:53 +08:00
return $loginResult = false ;
}
2020-12-26 01:42:23 +08:00
$sec = hash_pad ( $row [ " secret " ]);
//die(base64_decode($_COOKIE["c_secure_login"]));
if ( $_COOKIE [ " c_secure_login " ] == base64 ( " yeah " ))
{
2022-10-30 17:30:24 +08:00
/**
* Not IP related
* @ since 1.8 . 0
*/
// $md5 = md5($row["passhash"].$ip);
$md5 = md5 ( $row [ " passhash " ]);
2022-08-25 22:38:06 +08:00
$log .= " , secure login == yeah, passhash: { $row [ 'passhash' ] } , ip: $ip , md5: $md5 " ;
2022-08-25 22:07:57 +08:00
if ( $_COOKIE [ " c_secure_pass " ] != $md5 ) {
do_log ( " $log , c_secure_pass != md5 " );
2021-02-03 18:41:53 +08:00
return $loginResult = false ;
}
2020-12-26 01:42:23 +08:00
}
else
{
2022-08-25 22:07:57 +08:00
$md5 = md5 ( $row [ " passhash " ]);
$log .= " $log , passhash: { $row [ 'passhash' ] } , md5: $md5 " ;
if ( $_COOKIE [ " c_secure_pass " ] !== $md5 ) {
do_log ( " $log , c_secure_pass != md5 " );
2021-02-03 18:41:53 +08:00
return $loginResult = false ;
}
2020-12-26 01:42:23 +08:00
}
if ( $_COOKIE [ " c_secure_login " ] == base64 ( " yeah " ))
{
//if ($_SESSION["s_secure_pass"] !== md5($row["passhash"].$_SERVER["REMOTE_ADDR"]))
//return;
}
if ( ! $row [ " passkey " ]){
$passkey = md5 ( $row [ 'username' ] . date ( " Y-m-d H:i:s " ) . $row [ 'passhash' ]);
2021-06-15 10:35:13 +08:00
sql_query ( " UPDATE users SET passkey = " . sqlesc ( $passkey ) . " WHERE id= " . sqlesc ( $row [ " id " ]));
2020-12-26 01:42:23 +08:00
}
$oldip = $row [ 'ip' ];
$row [ 'ip' ] = $ip ;
$GLOBALS [ " CURUSER " ] = $row ;
2021-01-11 22:00:46 +08:00
if ( isset ( $_GET [ 'clearcache' ]) && $_GET [ 'clearcache' ] && get_user_class () >= UC_MODERATOR ) {
2020-12-26 01:42:23 +08:00
$Cache -> setClearCache ( 1 );
}
2021-02-03 18:41:53 +08:00
/**
* no need any more , already set in core . php
* @ since v1 . 6
*/
// if ($enablesqldebug_tweak == 'yes' && get_user_class() >= $sqldebug_tweak) {
2020-12-29 03:54:56 +08:00
// error_reporting(E_ALL & ~E_NOTICE);
2021-02-03 18:41:53 +08:00
// error_reporting(-1);
// }
return $loginResult = true ;
2020-12-26 01:42:23 +08:00
}
2022-03-09 12:08:14 +08:00
function autoclean ( $printProgress = false ) {
2020-12-26 01:42:23 +08:00
global $autoclean_interval_one , $rootpath ;
$now = TIMENOW ;
$res = sql_query ( " SELECT value_u FROM avps WHERE arg = 'lastcleantime' " );
$row = mysql_fetch_array ( $res );
if ( ! $row ) {
2021-01-30 13:53:15 +08:00
do_log ( " SELECT value_u FROM avps WHERE arg = 'lastcleantime', empty " );
2020-12-26 01:42:23 +08:00
sql_query ( " INSERT INTO avps (arg, value_u) VALUES ('lastcleantime', $now ) " ) or sqlerr ( __FILE__ , __LINE__ );
return false ;
}
$ts = $row [ 0 ];
if ( $ts + $autoclean_interval_one > $now ) {
2021-01-30 13:53:15 +08:00
do_log ( " ts: { $ts } + autoclean_interval_one: $autoclean_interval_one > now: $now " );
2020-12-26 01:42:23 +08:00
return false ;
}
sql_query ( " UPDATE avps SET value_u= $now WHERE arg='lastcleantime' AND value_u = $ts " ) or sqlerr ( __FILE__ , __LINE__ );
if ( ! mysql_affected_rows ()) {
2021-01-30 13:53:15 +08:00
do_log ( " UPDATE avps SET value_u= $now WHERE arg='lastcleantime' AND value_u = $ts , affectedRows = 0 " );
2020-12-26 01:42:23 +08:00
return false ;
}
require_once ( $rootpath . 'include/cleanup.php' );
2022-03-09 12:08:14 +08:00
return docleanup ( 0 , $printProgress );
2020-12-26 01:42:23 +08:00
}
function unesc ( $x ) {
return $x ;
}
function getsize_int ( $amount , $unit = " G " )
{
if ( $unit == " B " )
return floor ( $amount );
elseif ( $unit == " K " )
return floor ( $amount * 1024 );
elseif ( $unit == " M " )
return floor ( $amount * 1048576 );
elseif ( $unit == " G " )
return floor ( $amount * 1073741824 );
elseif ( $unit == " T " )
return floor ( $amount * 1099511627776 );
elseif ( $unit == " P " )
return floor ( $amount * 1125899906842624 );
}
function mksize_compact ( $bytes )
{
if ( $bytes < 1000 * 1024 )
return number_format ( $bytes / 1024 , 2 ) . " <br />KB " ;
elseif ( $bytes < 1000 * 1048576 )
return number_format ( $bytes / 1048576 , 2 ) . " <br />MB " ;
elseif ( $bytes < 1000 * 1073741824 )
return number_format ( $bytes / 1073741824 , 2 ) . " <br />GB " ;
elseif ( $bytes < 1000 * 1099511627776 )
return number_format ( $bytes / 1099511627776 , 3 ) . " <br />TB " ;
else
return number_format ( $bytes / 1125899906842624 , 3 ) . " <br />PB " ;
}
function mksize_loose ( $bytes )
{
if ( $bytes < 1000 * 1024 )
return number_format ( $bytes / 1024 , 2 ) . " KB " ;
elseif ( $bytes < 1000 * 1048576 )
return number_format ( $bytes / 1048576 , 2 ) . " MB " ;
elseif ( $bytes < 1000 * 1073741824 )
return number_format ( $bytes / 1073741824 , 2 ) . " GB " ;
elseif ( $bytes < 1000 * 1099511627776 )
return number_format ( $bytes / 1099511627776 , 3 ) . " TB " ;
else
return number_format ( $bytes / 1125899906842624 , 3 ) . " PB " ;
}
function mksize ( $bytes )
{
if ( $bytes < 1000 * 1024 )
return number_format ( $bytes / 1024 , 2 ) . " KB " ;
elseif ( $bytes < 1000 * 1048576 )
return number_format ( $bytes / 1048576 , 2 ) . " MB " ;
elseif ( $bytes < 1000 * 1073741824 )
return number_format ( $bytes / 1073741824 , 2 ) . " GB " ;
elseif ( $bytes < 1000 * 1099511627776 )
return number_format ( $bytes / 1099511627776 , 3 ) . " TB " ;
else
return number_format ( $bytes / 1125899906842624 , 3 ) . " PB " ;
}
function mksizeint ( $bytes )
{
$bytes = max ( 0 , $bytes );
if ( $bytes < 1000 )
return floor ( $bytes ) . " B " ;
elseif ( $bytes < 1000 * 1024 )
return floor ( $bytes / 1024 ) . " kB " ;
elseif ( $bytes < 1000 * 1048576 )
return floor ( $bytes / 1048576 ) . " MB " ;
elseif ( $bytes < 1000 * 1073741824 )
return floor ( $bytes / 1073741824 ) . " GB " ;
elseif ( $bytes < 1000 * 1099511627776 )
return floor ( $bytes / 1099511627776 ) . " TB " ;
else
return floor ( $bytes / 1125899906842624 ) . " PB " ;
}
function deadtime () {
2024-03-27 02:05:35 +08:00
$anninterthree = ( int ) get_setting ( " main.anninterthree " );
2020-12-26 01:42:23 +08:00
return time () - floor ( $anninterthree * 1.3 );
}
function mkprettytime ( $s ) {
global $lang_functions ;
if ( $s < 0 )
$s = 0 ;
$t = array ();
foreach ( array ( " 60:sec " , " 60:min " , " 24:hour " , " 0:day " ) as $x ) {
$y = explode ( " : " , $x );
if ( $y [ 0 ] > 1 ) {
$v = $s % $y [ 0 ];
$s = floor ( $s / $y [ 0 ]);
}
else
$v = $s ;
$t [ $y [ 1 ]] = $v ;
}
if ( $t [ " day " ])
2021-04-29 02:52:22 +08:00
return $t [ " day " ] . ( $lang_functions [ 'text_day' ] ? ? 'day(s)' ) . sprintf ( " %02d:%02d:%02d " , $t [ " hour " ], $t [ " min " ], $t [ " sec " ]);
2020-12-26 01:42:23 +08:00
if ( $t [ " hour " ])
return sprintf ( " %d:%02d:%02d " , $t [ " hour " ], $t [ " min " ], $t [ " sec " ]);
// if ($t["min"])
return sprintf ( " %d:%02d " , $t [ " min " ], $t [ " sec " ]);
// return $t["sec"] . " secs";
}
function mkglobal ( $vars ) {
if ( ! is_array ( $vars ))
$vars = explode ( " : " , $vars );
foreach ( $vars as $v ) {
if ( isset ( $_GET [ $v ]))
$GLOBALS [ $v ] = unesc ( $_GET [ $v ]);
elseif ( isset ( $_POST [ $v ]))
$GLOBALS [ $v ] = unesc ( $_POST [ $v ]);
else
return 0 ;
}
return 1 ;
}
2021-02-02 20:27:37 +08:00
function tr ( $x , $y , $noesc = 0 , $relation = '' , $return = false ) {
2020-12-26 01:42:23 +08:00
if ( $noesc )
$a = $y ;
else {
$a = htmlspecialchars ( $y );
$a = str_replace ( " \n " , " <br /> \n " , $a );
}
2021-02-02 20:27:37 +08:00
// $result = ("<tr".( $relation ? " relation = \"$relation\"" : "")."><td class=\"rowhead nowrap\" valign=\"top\" align=\"right\">$x</td><td class=\"rowfollow\" valign=\"top\" align=\"left\">".$a."</td></tr>\n");
$result = sprintf (
'<tr%s><td class="rowhead nowrap" valign="top" align="right">%s</td><td class="rowfollow" valign="top" align="left">%s</td></tr>' ,
2022-09-14 19:05:29 +08:00
$relation ? sprintf ( ' relation="%s" class="%s"' , $relation , $relation ) : '' ,
2021-02-02 20:27:37 +08:00
$x , $a
);
if ( $return ) {
return $result ;
}
print $result ;
2020-12-26 01:42:23 +08:00
}
2022-08-20 19:11:28 +08:00
function tr_small ( $x , $y , $noesc = 0 , $relation = '' , $return = false ) {
2020-12-26 01:42:23 +08:00
if ( $noesc )
$a = $y ;
else {
$a = htmlspecialchars ( $y );
//$a = str_replace("\n", "<br />\n", $a);
}
2022-08-20 19:11:28 +08:00
$result = " <tr " . ( $relation ? " relation = \" $relation\ " " : " " ). " >< td width = \ " 1% \" class= \" rowhead nowrap \" valign= \" top \" align= \" right \" > " . $x . " </td><td width= \" 99% \" class= \" rowfollow \" valign= \" top \" align= \" left \" > " . $a . " </td></tr> " ;
if ( $return ) {
return $result ;
}
print ( $result );
2020-12-26 01:42:23 +08:00
}
function twotd ( $x , $y , $nosec = 0 ){
2020-12-28 20:52:54 +08:00
if ( $nosec )
2020-12-26 01:42:23 +08:00
$a = $y ;
else {
$a = htmlspecialchars ( $y );
$a = str_replace ( " \n " , " <br /> \n " , $a );
}
print ( " <td class= \" rowhead \" > " . $x . " </td><td class= \" rowfollow \" > " . $y . " </td> " );
}
function validfilename ( $name ) {
return preg_match ( '/^[^\0-\x1f:\\\\\/?*\xff#<>|]+$/si' , $name );
}
function validemail ( $email ) {
return preg_match ( '/^[\w.-]+@([\w.-]+\.)+[a-z]{2,6}$/is' , $email );
}
function validlang ( $langid ) {
global $deflang ;
2021-01-06 00:56:13 +08:00
$langid = intval ( $langid ? ? 0 );
2020-12-26 01:42:23 +08:00
$res = sql_query ( " SELECT * FROM language WHERE site_lang = 1 AND id = " . sqlesc ( $langid )) or sqlerr ( __FILE__ , __LINE__ );
if ( mysql_num_rows ( $res ) == 1 )
{
$arr = mysql_fetch_array ( $res ) or sqlerr ( __FILE__ , __LINE__ );
return $arr [ 'site_lang_folder' ];
}
else return $deflang ;
}
function get_if_restricted_is_open ()
{
2021-04-22 03:24:59 +08:00
global $sptime ;
2020-12-26 01:42:23 +08:00
// it's sunday
if ( $sptime == 'yes' && ( date ( " w " , time ()) == '0' || ( date ( " w " , time ()) == 6 ) && ( date ( " G " , time ()) >= 12 && date ( " G " , time ()) <= 23 )))
{
return true ;
}
else
return false ;
}
function menu ( $selected = " home " ) {
global $lang_functions ;
global $BASEURL , $CURUSER ;
global $enableoffer , $enablespecial , $enableextforum , $extforumurl , $where_tweak ;
global $USERUPDATESET ;
2020-12-28 20:52:54 +08:00
//no this option in config.php
2021-02-20 18:22:19 +08:00
$enablerequest = 'yes' ;
2020-12-26 01:42:23 +08:00
$script_name = $_SERVER [ " SCRIPT_FILENAME " ];
if ( preg_match ( " /index/i " , $script_name )) {
$selected = " home " ;
} elseif ( preg_match ( " /forums/i " , $script_name )) {
$selected = " forums " ;
} elseif ( preg_match ( " /torrents/i " , $script_name )) {
$selected = " torrents " ;
2021-05-29 18:26:04 +08:00
} elseif ( preg_match ( " /special/i " , $script_name )) {
$selected = " special " ;
2020-12-26 01:42:23 +08:00
} elseif ( preg_match ( " /offers/i " , $script_name ) OR preg_match ( " /offcomment/i " , $script_name )) {
$selected = " offers " ;
2021-02-20 18:22:19 +08:00
} elseif ( preg_match ( " /requests/i " , $script_name )) {
$selected = " requests " ;
2020-12-26 01:42:23 +08:00
} elseif ( preg_match ( " /upload/i " , $script_name )) {
$selected = " upload " ;
} elseif ( preg_match ( " /subtitles/i " , $script_name )) {
$selected = " subtitles " ;
} elseif ( preg_match ( " /usercp/i " , $script_name )) {
$selected = " usercp " ;
} elseif ( preg_match ( " /topten/i " , $script_name )) {
$selected = " topten " ;
} elseif ( preg_match ( " /log/i " , $script_name )) {
$selected = " log " ;
} elseif ( preg_match ( " /rules/i " , $script_name )) {
$selected = " rules " ;
} elseif ( preg_match ( " /faq/i " , $script_name )) {
$selected = " faq " ;
2022-05-26 14:27:10 +08:00
} elseif ( preg_match ( " /contactstaff/i " , $script_name )) {
$selected = " contactstaff " ;
} elseif ( preg_match ( " /staff/i " , $script_name )) {
$selected = " staff " ;
2020-12-26 01:42:23 +08:00
} else
$selected = " " ;
2022-08-04 00:48:42 +08:00
$menu = apply_filter ( 'nexus_menu' );
print ( " <div id= \" nav \" > " );
if ( $menu ) {
print $menu ;
} else {
2022-10-27 20:21:54 +08:00
$lang = get_langfolder_cookie ();
2022-09-14 19:05:29 +08:00
$normalSectionName = get_searchbox_value ( get_setting ( 'main.browsecat' ), 'section_name' );
$specialSectionName = get_searchbox_value ( get_setting ( 'main.specialcat' ), 'section_name' );
2022-08-04 00:48:42 +08:00
print ( " <ul id= \" mainmenu \" class= \" menu \" > " );
print ( " <li " . ( $selected == " home " ? " class= \" selected \" " : " " ) . " ><a href= \" index.php \" > " . $lang_functions [ 'text_home' ] . " </a></li> " );
if ( $enableextforum != 'yes' )
print ( " <li " . ( $selected == " forums " ? " class= \" selected \" " : " " ) . " ><a href= \" forums.php \" > " . $lang_functions [ 'text_forums' ] . " </a></li> " );
else
print ( " <li " . ( $selected == " forums " ? " class= \" selected \" " : " " ) . " ><a href= \" " . $extforumurl . " \" target= \" _blank \" > " . $lang_functions [ 'text_forums' ] . " </a></li> " );
2022-10-27 20:21:54 +08:00
print ( " <li " . ( $selected == " torrents " ? " class= \" selected \" " : " " ) . " ><a href= \" torrents.php \" rel='sub-menu'> " . ( $normalSectionName [ $lang ] ? ? $lang_functions [ 'text_torrents' ]) . " </a></li> " );
2022-09-07 20:36:41 +08:00
if ( $enablespecial == 'yes' && user_can ( 'view_special_torrent' ))
2022-10-27 20:21:54 +08:00
print ( " <li " . ( $selected == " special " ? " class= \" selected \" " : " " ) . " ><a href= \" special.php \" > " . ( $specialSectionName [ $lang ] ? ? $lang_functions [ 'text_special' ]) . " </a></li> " );
2022-08-04 00:48:42 +08:00
if ( $enableoffer == 'yes' )
print ( " <li " . ( $selected == " offers " ? " class= \" selected \" " : " " ) . " ><a href= \" offers.php \" > " . $lang_functions [ 'text_offers' ] . " </a></li> " );
if ( $enablerequest == 'yes' )
print ( " <li " . ( $selected == " requests " ? " class= \" selected \" " : " " ) . " ><a href= \" viewrequests.php \" > " . $lang_functions [ 'text_request' ] . " </a></li> " );
print ( " <li " . ( $selected == " upload " ? " class= \" selected \" " : " " ) . " ><a href= \" upload.php \" > " . $lang_functions [ 'text_upload' ] . " </a></li> " );
print ( " <li " . ( $selected == " subtitles " ? " class= \" selected \" " : " " ) . " ><a href= \" subtitles.php \" > " . $lang_functions [ 'text_subtitles' ] . " </a></li> " );
// print ("<li" . ($selected == "usercp" ? " class=\"selected\"" : "") . "><a href=\"usercp.php\">".$lang_functions['text_user_cp']."</a></li>");
2022-09-07 20:36:41 +08:00
if ( user_can ( 'topten' )) {
print ( " <li " . ( $selected == " topten " ? " class= \" selected \" " : " " ) . " ><a href= \" topten.php \" > " . $lang_functions [ 'text_top_ten' ] . " </a></li> " );
}
if ( user_can ( 'log' )) {
print ( " <li " . ( $selected == " log " ? " class= \" selected \" " : " " ) . " ><a href= \" log.php \" > " . $lang_functions [ 'text_log' ] . " </a></li> " );
}
2022-08-04 00:48:42 +08:00
print ( " <li " . ( $selected == " rules " ? " class= \" selected \" " : " " ) . " ><a href= \" rules.php \" > " . $lang_functions [ 'text_rules' ] . " </a></li> " );
print ( " <li " . ( $selected == " faq " ? " class= \" selected \" " : " " ) . " ><a href= \" faq.php \" > " . $lang_functions [ 'text_faq' ] . " </a></li> " );
2022-09-07 20:36:41 +08:00
if ( user_can ( 'staffmem' )) {
print ( " <li " . ( $selected == " staff " ? " class= \" selected \" " : " " ) . " ><a href= \" staff.php \" > " . $lang_functions [ 'text_staff' ] . " </a></li> " );
}
2022-08-04 00:48:42 +08:00
print ( " <li " . ( $selected == " contactstaff " ? " class= \" selected \" " : " " ) . " ><a href= \" contactstaff.php \" > " . $lang_functions [ 'text_contactstaff' ] . " </a></li> " );
print ( " </ul> " );
}
print ( " </div> " );
2020-12-26 01:42:23 +08:00
if ( $CURUSER ){
if ( $where_tweak == 'yes' )
$USERUPDATESET [] = " page = " . sqlesc ( $selected );
}
}
function get_css_row () {
global $CURUSER , $defcss , $Cache ;
static $rows ;
$cssid = $CURUSER ? $CURUSER [ " stylesheet " ] : $defcss ;
if ( ! $rows && ! $rows = $Cache -> get_value ( 'stylesheet_content' )){
$rows = array ();
$res = sql_query ( " SELECT * FROM stylesheets ORDER BY id ASC " );
while ( $row = mysql_fetch_array ( $res )) {
$rows [ $row [ 'id' ]] = $row ;
}
$Cache -> cache_value ( 'stylesheet_content' , $rows , 95400 );
}
return $rows [ $cssid ];
}
function get_css_uri ( $file = " " )
{
2022-06-23 16:39:52 +08:00
global $defcss ;
2020-12-26 01:42:23 +08:00
$cssRow = get_css_row ();
$ss_uri = $cssRow [ 'uri' ];
if ( ! $ss_uri )
$ss_uri = get_single_value ( " stylesheets " , " uri " , " WHERE id= " . sqlesc ( $defcss ));
if ( $file == " " )
return $ss_uri ;
else return $ss_uri . $file ;
}
function get_font_css_uri (){
global $CURUSER ;
2021-05-14 00:31:37 +08:00
$file = 'mediumfont.css' ;
if ( $CURUSER && isset ( $CURUSER [ 'fontsize' ])) {
if ( $CURUSER [ 'fontsize' ] == 'large' )
$file = 'largefont.css' ;
elseif ( $CURUSER [ 'fontsize' ] == 'small' )
$file = 'smallfont.css' ;
}
2020-12-26 01:42:23 +08:00
return " styles/ " . $file ;
}
function get_style_addicode ()
{
$cssRow = get_css_row ();
return $cssRow [ 'addicode' ];
}
function get_cat_folder ( $cat = 101 )
{
static $catPath = array ();
2020-12-28 20:52:54 +08:00
if ( ! isset ( $catPath [ $cat ])) {
2020-12-26 01:42:23 +08:00
global $CURUSER , $CURLANGDIR ;
2021-02-26 13:58:12 +08:00
$catrow = get_category_row ( $cat );
2020-12-26 01:42:23 +08:00
$catmode = $catrow [ 'catmodename' ];
2021-02-26 13:58:12 +08:00
// $caticonrow = get_category_icon_row($CURUSER['caticon']);
2021-02-26 00:46:11 +08:00
/**
* @ since v1 . 6
2022-03-19 16:47:46 +08:00
* use setting , not user ' s caticon , that field make no sense !
2021-02-26 00:46:11 +08:00
*/
2021-02-26 13:58:12 +08:00
$caticonrow = get_category_icon_row ( $catrow [ 'icon_id' ] ? : 1 );
2021-05-29 18:26:04 +08:00
$path = sprintf ( 'category/%s/%s' , trim ( $catmode , '/' ), trim ( $caticonrow [ 'folder' ], '/' ));
if ( $caticonrow [ 'multilang' ] == 'yes' ) {
$path .= '/' . trim ( $CURLANGDIR , '/' );
}
2022-02-25 23:13:34 +08:00
do_log ( " cat: $cat , path: $path " , 'debug' );
2021-05-29 18:26:04 +08:00
$catPath [ $cat ] = $path ;
2020-12-26 01:42:23 +08:00
}
2021-05-29 18:26:04 +08:00
return $catPath [ $cat ] ? ? '' ;
2020-12-26 01:42:23 +08:00
}
function get_style_highlight ()
{
global $CURUSER ;
if ( $CURUSER )
{
$ss_a = @ mysql_fetch_array ( @ sql_query ( " select hltr from stylesheets where id= " . $CURUSER [ " stylesheet " ]));
if ( $ss_a ) $hltr = $ss_a [ " hltr " ];
}
if ( ! $hltr )
{
2021-06-15 10:35:13 +08:00
$r = sql_query ( " SELECT hltr FROM stylesheets WHERE id=5 " );
$a = mysql_fetch_array ( $r );
2020-12-26 01:42:23 +08:00
$hltr = $a [ " hltr " ];
}
return $hltr ;
}
function stdhead ( $title = " " , $msgalert = true , $script = " " , $place = " " )
{
global $lang_functions ;
2022-03-20 22:14:00 +08:00
global $CURUSER , $CURLANGDIR , $USERUPDATESET , $iplog1 , $oldip , $SITE_ONLINE , $FUNDS , $SITENAME , $SLOGAN , $logo_main , $BASEURL , $offlinemsg , $enabledonation , $staffmem_class , $titlekeywords_tweak , $metakeywords_tweak , $metadescription_tweak , $cssdate_tweak , $deletenotransfertwo_account , $neverdelete_account , $iniupload_main ;
2020-12-26 01:42:23 +08:00
global $tstart ;
global $Cache ;
global $Advertisement ;
$Cache -> setLanguage ( $CURLANGDIR );
2021-04-22 03:24:59 +08:00
2021-05-14 00:31:37 +08:00
$Advertisement = new ADVERTISEMENT ( $CURUSER [ 'id' ] ? ? 0 );
2020-12-26 01:42:23 +08:00
$cssupdatedate = $cssdate_tweak ;
// Variable for Start Time
$tstart = getmicrotime (); // Start time
//Insert old ip into iplog
if ( $CURUSER ){
if ( $iplog1 == " yes " ) {
if (( $oldip != $CURUSER [ " ip " ]) && $CURUSER [ " ip " ])
sql_query ( " INSERT INTO iplog (ip, userid, access) VALUES ( " . sqlesc ( $CURUSER [ 'ip' ]) . " , " . $CURUSER [ 'id' ] . " , ' " . $CURUSER [ 'last_access' ] . " ') " );
}
$USERUPDATESET [] = " last_access = " . sqlesc ( date ( " Y-m-d H:i:s " ));
$USERUPDATESET [] = " ip = " . sqlesc ( $CURUSER [ 'ip' ]);
}
header ( " Content-Type: text/html; charset=utf-8; Cache-control:private " );
//header("Pragma: No-cache");
if ( $title == " " )
$title = $SITENAME ;
else
$title = $SITENAME . " :: " . htmlspecialchars ( $title );
if ( $titlekeywords_tweak )
$title .= " " . htmlspecialchars ( $titlekeywords_tweak );
2022-03-20 22:14:00 +08:00
$title .= " - Powered by " . PROJECTNAME ;
2020-12-26 01:42:23 +08:00
if ( $SITE_ONLINE == " no " ) {
if ( get_user_class () < UC_ADMINISTRATOR ) {
die ( $lang_functions [ 'std_site_down_for_maintenance' ]);
}
else
{
$offlinemsg = true ;
}
}
?>
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head >
< meta http - equiv = " Content-Type " content = " text/html; charset=utf-8 " />
< ? php
if ( $metakeywords_tweak ){
?>
< meta name = " keywords " content = " <?php echo htmlspecialchars( $metakeywords_tweak )?> " />
< ? php
}
if ( $metadescription_tweak ){
?>
< meta name = " description " content = " <?php echo htmlspecialchars( $metadescription_tweak )?> " />
< ? php
}
?>
< meta name = " generator " content = " <?php echo PROJECTNAME?> " />
< ? php
print ( get_style_addicode ());
$css_uri = get_css_uri ();
$cssupdatedate = ( $cssupdatedate ? " ? " . htmlspecialchars ( $cssupdatedate ) : " " );
?>
< title >< ? php echo $title ?> </title>
< link rel = " shortcut icon " href = " favicon.ico " type = " image/x-icon " />
< link rel = " search " type = " application/opensearchdescription+xml " title = " <?php echo $SITENAME ?> Torrents " href = " opensearch.php " />
< link rel = " stylesheet " href = " <?php echo get_font_css_uri(). $cssupdatedate ?> " type = " text/css " />
< link rel = " stylesheet " href = " styles/sprites.css<?php echo $cssupdatedate ?> " type = " text/css " />
< link rel = " stylesheet " href = " <?php echo get_forum_pic_folder(). " / forumsprites . css " . $cssupdatedate ?> " type = " text/css " />
< link rel = " stylesheet " href = " <?php echo $css_uri . " theme . css " . $cssupdatedate ?> " type = " text/css " />
< link rel = " stylesheet " href = " <?php echo $css_uri . " DomTT . css " . $cssupdatedate ?> " type = " text/css " />
< link rel = " stylesheet " href = " styles/curtain_imageresizer.css<?php echo $cssupdatedate ?> " type = " text/css " />
2022-09-19 18:48:03 +08:00
< link rel = " stylesheet " href = " styles/nexus.css<?php echo $cssupdatedate ?> " type = " text/css " />
2020-12-26 01:42:23 +08:00
< ? php
if ( $CURUSER ){
2021-05-28 02:25:08 +08:00
// $caticonrow = get_category_icon_row($CURUSER['caticon']);
// if($caticonrow['cssfile']){
2021-05-29 18:26:04 +08:00
$requireSearchBoxIdAr = list_require_search_box_id ();
if ( ! empty ( $requireSearchBoxIdAr )) {
$icons = ( new \App\Repositories\SearchBoxRepository ()) -> listIcon ( $requireSearchBoxIdAr );
foreach ( $icons as $icon ) {
2021-05-28 02:25:08 +08:00
2020-12-26 01:42:23 +08:00
?>
2021-05-28 02:25:08 +08:00
< link rel = " stylesheet " href = " <?php echo htmlspecialchars(trim( $icon['cssfile'] , '/')). $cssupdatedate ?> " type = " text/css " />
2020-12-26 01:42:23 +08:00
< ? php
2021-05-29 18:26:04 +08:00
}}
2020-12-26 01:42:23 +08:00
}
?>
< link rel = " alternate " type = " application/rss+xml " title = " Latest Torrents " href = " torrentrss.php " />
2022-04-14 00:52:28 +08:00
< script type = " text/javascript " src = " js/curtain_imageresizer.js<?php echo $cssupdatedate ?> " ></ script >
< script type = " text/javascript " src = " js/ajaxbasic.js<?php echo $cssupdatedate ?> " ></ script >
< script type = " text/javascript " src = " js/common.js<?php echo $cssupdatedate ?> " ></ script >
< script type = " text/javascript " src = " js/domLib.js<?php echo $cssupdatedate ?> " ></ script >
< script type = " text/javascript " src = " js/domTT.js<?php echo $cssupdatedate ?> " ></ script >
< script type = " text/javascript " src = " js/domTT_drag.js<?php echo $cssupdatedate ?> " ></ script >
< script type = " text/javascript " src = " js/fadomatic.js<?php echo $cssupdatedate ?> " ></ script >
2022-04-03 16:03:47 +08:00
< ? php
2022-06-08 14:15:59 +08:00
do_action ( 'nexus_header' );
2022-04-03 16:03:47 +08:00
foreach ( \Nexus\Nexus :: getAppendHeaders () as $value ) {
print ( $value );
}
?>
2022-04-14 00:52:28 +08:00
< script type = " text/javascript " src = " js/jquery-1.12.4.min.js<?php echo $cssupdatedate ?> " ></ script >
2021-05-26 20:56:03 +08:00
< script type = " text/javascript " > jQuery . noConflict (); </ script >
2022-06-15 15:43:33 +08:00
< script type = " text/javascript " src = " vendor/layer-v3.5.1/layer/layer.js<?php echo $cssupdatedate ?> " ></ script >
2020-12-26 01:42:23 +08:00
</ head >
< body >
2022-08-19 17:22:14 +08:00
< table class = " head " cellspacing = " 0 " cellpadding = " 0 " align = " center " style = " width: <?php echo isset( $GLOBALS['CURUSER'] ) ? CONTENT_WIDTH + 28.66 : CONTENT_WIDTH ?>px " >
2020-12-26 01:42:23 +08:00
< tr >
< td class = " clear " >
< ? php
if ( $logo_main == " " )
{
?>
< div class = " logo " >< ? php echo htmlspecialchars ( $SITENAME ) ?> </div>
< div class = " slogan " >< ? php echo htmlspecialchars ( $SLOGAN ) ?> </div>
< ? php
}
else
{
?>
< div class = " logo_img " >< img src = " <?php echo $logo_main ?> " alt = " <?php echo htmlspecialchars( $SITENAME )?> " title = " <?php echo htmlspecialchars( $SITENAME )?> - <?php echo htmlspecialchars( $SLOGAN )?> " /></ div >
< ? php
}
?>
</ td >
< td class = " clear nowrap " align = " right " valign = " middle " >
< ? php if ( $Advertisement -> enable_ad ()){
$headerad = $Advertisement -> get_ad ( 'header' );
if ( $headerad ){
2022-05-07 22:11:24 +08:00
echo " <span> " . $headerad [ 0 ] . " </span> " ;
2020-12-26 01:42:23 +08:00
}
}
if ( $enabledonation == 'yes' ){ ?>
< a href = " donate.php " >< img src = " <?php echo get_forum_pic_folder()?>/donate.gif " alt = " Make a donation " style = " margin-left: 5px; margin-top: 50px; " /></ a >
< ? php
}
?>
</ td >
</ tr >
</ table >
2022-08-19 17:02:35 +08:00
< table class = " mainouter " width = " <?php echo CONTENT_WIDTH ?> " cellspacing = " 0 " cellpadding = " 5 " align = " center " >
2020-12-26 01:42:23 +08:00
< tr >< td id = " nav_block " class = " text " align = " center " >
< ? php if ( ! $CURUSER ) { ?>
< a href = " login.php " >< font class = " big " >< b >< ? php echo $lang_functions [ 'text_login' ] ?> </b></font></a> / <a href="signup.php"><font class="big"><b><?php echo $lang_functions['text_signup'] ?></b></font></a>
2021-04-22 03:24:59 +08:00
< ? php }
2020-12-26 01:42:23 +08:00
else {
begin_main_frame ();
menu ();
end_main_frame ();
$datum = getdate ();
$datum [ " hours " ] = sprintf ( " %02.0f " , $datum [ " hours " ]);
$datum [ " minutes " ] = sprintf ( " %02.0f " , $datum [ " minutes " ]);
$ratio = get_ratio ( $CURUSER [ 'id' ]);
//// check every 15 minutes //////////////////
$messages = $Cache -> get_value ( 'user_' . $CURUSER [ " id " ] . '_inbox_count' );
if ( $messages == " " ){
$messages = get_row_count ( " messages " , " WHERE receiver= " . sqlesc ( $CURUSER [ " id " ]) . " AND location<>0 " );
$Cache -> cache_value ( 'user_' . $CURUSER [ " id " ] . '_inbox_count' , $messages , 900 );
}
$outmessages = $Cache -> get_value ( 'user_' . $CURUSER [ " id " ] . '_outbox_count' );
if ( $outmessages == " " ){
$outmessages = get_row_count ( " messages " , " WHERE sender= " . sqlesc ( $CURUSER [ " id " ]) . " AND saved='yes' " );
$Cache -> cache_value ( 'user_' . $CURUSER [ " id " ] . '_outbox_count' , $outmessages , 900 );
}
if ( ! $connect = $Cache -> get_value ( 'user_' . $CURUSER [ " id " ] . '_connect' )){
2022-04-25 01:22:07 +08:00
$res3 = sql_query ( " SELECT connectable FROM peers WHERE userid= " . sqlesc ( $CURUSER [ " id " ]) . " order by id desc LIMIT 1 " );
2020-12-26 01:42:23 +08:00
if ( $row = mysql_fetch_row ( $res3 ))
$connect = $row [ 0 ];
else $connect = 'unknown' ;
$Cache -> cache_value ( 'user_' . $CURUSER [ " id " ] . '_connect' , $connect , 900 );
}
if ( $connect == " yes " )
$connectable = " <b><font color= \" green \" > " . $lang_functions [ 'text_yes' ] . " </font></b> " ;
elseif ( $connect == 'no' )
$connectable = " <a href= \" faq.php#id21 \" ><b><font color= \" red \" > " . $lang_functions [ 'text_no' ] . " </font></b></a> " ;
else
$connectable = $lang_functions [ 'text_unknown' ];
//// check every 60 seconds //////////////////
$activeseed = $Cache -> get_value ( 'user_' . $CURUSER [ " id " ] . '_active_seed_count' );
if ( $activeseed == " " ){
2022-04-22 01:32:17 +08:00
$activeseed = get_row_count ( " peers " , " WHERE userid= " . sqlesc ( $CURUSER [ " id " ]) . " AND seeder='yes' " );
2020-12-26 01:42:23 +08:00
$Cache -> cache_value ( 'user_' . $CURUSER [ " id " ] . '_active_seed_count' , $activeseed , 60 );
}
$activeleech = $Cache -> get_value ( 'user_' . $CURUSER [ " id " ] . '_active_leech_count' );
if ( $activeleech == " " ){
2022-04-22 01:32:17 +08:00
$activeleech = get_row_count ( " peers " , " WHERE userid= " . sqlesc ( $CURUSER [ " id " ]) . " AND seeder='no' " );
2020-12-26 01:42:23 +08:00
$Cache -> cache_value ( 'user_' . $CURUSER [ " id " ] . '_active_leech_count' , $activeleech , 60 );
}
$unread = $Cache -> get_value ( 'user_' . $CURUSER [ " id " ] . '_unread_message_count' );
if ( $unread == " " ){
$unread = get_row_count ( " messages " , " WHERE receiver= " . sqlesc ( $CURUSER [ " id " ]) . " AND unread='yes' " );
$Cache -> cache_value ( 'user_' . $CURUSER [ " id " ] . '_unread_message_count' , $unread , 60 );
}
2021-04-22 03:24:59 +08:00
2020-12-26 01:42:23 +08:00
$inboxpic = " <img class= \" " . ( $unread ? " inboxnew " : " inbox " ) . " \" src= \" pic/trans.gif \" alt= \" inbox \" title= \" " . ( $unread ? $lang_functions [ 'title_inbox_new_messages' ] : $lang_functions [ 'title_inbox_no_new_messages' ]) . " \" /> " ;
2022-02-25 23:13:34 +08:00
// $attend_desk = new Attendance($CURUSER['id']);
// $attendance = $attend_desk->check();
$attendanceRep = new \App\Repositories\AttendanceRepository ();
$attendance = $attendanceRep -> getAttendance ( $CURUSER [ 'id' ], date ( 'Ymd' ))
2020-12-26 01:42:23 +08:00
?>
< table id = " info_block " cellpadding = " 4 " cellspacing = " 0 " border = " 0 " width = " 100% " >< tr >
< td >< table width = " 100% " cellspacing = " 0 " cellpadding = " 0 " border = " 0 " >< tr >
2021-02-20 18:22:19 +08:00
< td class = " bottom " align = " left " >
< span class = " medium " >
< ? php echo $lang_functions [ 'text_welcome_back' ] ?> , <?php echo get_username($CURUSER['id'])?>
[ < a href = " logout.php " >< ? php echo $lang_functions [ 'text_logout' ] ?> </a>]
[ < a href = " usercp.php " >< ? php echo $lang_functions [ 'text_user_cp' ] ?> </a>]
< ? php if ( get_user_class () >= UC_MODERATOR ) { ?> [<a href="staffpanel.php"><?php echo $lang_functions['text_staff_panel'] ?></a>] <?php }?>
< ? php if ( get_user_class () >= UC_SYSOP ) { ?> [<a href="settings.php"><?php echo $lang_functions['text_site_settings'] ?></a>]<?php } ?>
[ < a href = " torrents.php?inclbookmarked=1&allsec=1&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 ) ?>
2022-04-03 16:03:47 +08:00
< ? 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' ]);} ?>
2022-12-19 19:01:22 +08:00
< a href = " medal.php " > [ < ? php echo nexus_trans ( 'medal.label' ) ?> ]</a>
2024-05-24 02:27:44 +08:00
< a href = " task.php " > [ < ? php echo nexus_trans ( 'exam.type_task' ) ?> ]</a>
2022-12-13 13:51:39 +08:00
< 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 sprintf(' % s ( % s ) ', $CURUSER[' invites '], \App\Models\Invite::query()->where(' inviter ', $CURUSER[' id '])->where(' invitee ', ' ')->where(' expired_at ', ' > ' , now ()) -> count ()) ?>
2023-09-03 03:29:25 +08:00
< ? php if ( get_user_class () >= \App\Models\User :: getAccessAdminClassMin ()) printf ( '[<a href="%s" target="_blank">%s</a>]' , nexus_env ( 'FILAMENT_PATH' , 'nexusphp' ), $lang_functions [ 'text_management_system' ]) ?>
2021-12-14 16:22:03 +08:00
< br />
2021-02-20 18:22:19 +08:00
< 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'])?>
< font class = 'color_downloaded' > < ? php echo $lang_functions [ 'text_downloaded' ] ?> </font> <?php echo mksize($CURUSER['downloaded'])?>
< font class = 'color_active' >< ? php echo $lang_functions [ 'text_active_torrents' ] ?> </font> <img class="arrowup" alt="Torrents seeding" title="<?php echo $lang_functions['title_torrents_seeding'] ?>" src="pic/trans.gif" /><?php echo $activeseed?> <img class="arrowdown" alt="Torrents leeching" title="<?php echo $lang_functions['title_torrents_leeching'] ?>" src="pic/trans.gif" /><?php echo $activeleech?>
< font class = 'color_connectable' >< ? php echo $lang_functions [ 'text_connectable' ] ?> </font><?php echo $connectable?> <?php echo maxslots();?>
2022-02-23 15:19:09 +08:00
< ? 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 }?>
2022-05-06 15:50:26 +08:00
< ? 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 }?>
2021-02-20 18:22:19 +08:00
</ span >
</ td >
2022-12-19 19:01:22 +08:00
< ? php if ( SearchBox :: isSpecialEnabled () && get_setting ( 'main.enable_global_search' ) == 'yes' ){ ?>
2022-10-22 20:52:08 +08:00
< td class = " bottom " align = " left " style = " border: none " >
2022-10-22 22:28:36 +08:00
< form action = " search.php " method = " get " target = " <?php echo nexus()->getScript() == 'search' ? '_self' : '_blank'?> " >
2022-10-22 20:52:08 +08:00
< div style = " display: flex;align-items: center " >
< div style = " display: flex;flex-direction: column " >
< div >
2022-10-22 22:23:54 +08:00
< span >< input type = " text " name = " search " style = " width: 80px;height: 12px " value = " <?php echo $_GET['search'] ?? '' ?> " placeholder = " <?php echo nexus_trans('search.search_keyword')?> " /></ span >
2022-10-22 20:52:08 +08:00
</ div >
< div >
2022-10-22 22:23:54 +08:00
< span >< ? php echo build_search_area ( $_GET [ 'search_area' ] ? ? '' , [ 'style' => 'width: 88px' ]) ?> </span>
2022-10-22 20:52:08 +08:00
</ 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 >
2022-10-22 23:53:02 +08:00
< ? php } ?>
2022-10-22 20:52:08 +08:00
< td class = " bottom " align = " right " >< span class = " medium " >
2020-12-26 01:42:23 +08:00
< ? php
2022-10-22 20:52:08 +08:00
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 />';
2022-08-22 21:07:06 +08:00
// $cacheKey = "staff_message_count_" . $CURUSER['id'];
// $totalsm = $Cache->get_value($cacheKey);
$totalsm = \App\Repositories\MessageRepository :: getStaffMessageCountCache ( $CURUSER [ 'id' ], 'total' );
2022-08-24 00:19:19 +08:00
if ( $totalsm === false ){
2022-08-22 21:07:06 +08:00
$totalsm = \App\Repositories\MessageRepository :: countStaffMessage ( $CURUSER [ 'id' ]);
// $Cache->cache_value($cacheKey, $totalsm, 900);
\App\Repositories\MessageRepository :: updateStaffMessageCountCache ( $CURUSER [ 'id' ], 'total' , $totalsm );
}
if ( $totalsm > 0 ) {
print ( " <a href= \" staffbox.php \" ><img class= \" staffbox \" alt= \" staffbox \" title= \" " . $lang_functions [ 'title_staffbox' ] . " \" src= \" pic/trans.gif \" /> </a> " . $totalsm . " " );
}
2020-12-26 01:42:23 +08:00
print ( " <a href= \" messages.php \" > " . $inboxpic . " </a> " . ( $messages ? $messages . " ( " . $unread . $lang_functions [ 'text_message_new' ] . " ) " : " 0 " ));
print ( " <a href= \" messages.php?action=viewmailbox&box=-1 \" ><img class= \" sentbox \" alt= \" sentbox \" title= \" " . $lang_functions [ 'title_sentbox' ] . " \" src= \" pic/trans.gif \" /></a> " . ( $outmessages ? $outmessages : " 0 " ));
2022-10-22 20:52:08 +08:00
2020-12-26 01:42:23 +08:00
?>
</ span ></ td >
</ tr ></ table ></ td >
</ tr ></ table >
</ td ></ tr >
< tr >< td id = " outer " align = " center " class = " outer " style = " padding-top: 20px; padding-bottom: 20px " >
< ? php
if ( $Advertisement -> enable_ad ()){
$belownavad = $Advertisement -> get_ad ( 'belownav' );
if ( $belownavad )
2022-05-07 22:11:24 +08:00
echo " <div align= \" center \" style= \" margin-bottom: 10px \" id= \" \" > " . $belownavad [ 0 ] . " </div> " ;
2020-12-26 01:42:23 +08:00
}
if ( $msgalert )
{
2022-06-12 22:14:16 +08:00
$spStateGlobal = get_global_sp_state ();
if ( $spStateGlobal != \App\Models\Torrent :: PROMOTION_NORMAL ) {
2022-08-26 17:35:49 +08:00
$torrentGlobalStateRow = \Nexus\Database\NexusDB :: cache_get ( \App\Models\Setting :: TORRENT_GLOBAL_STATE_CACHE_KEY );
2022-08-26 18:10:23 +08:00
$msg = sprintf ( $lang_functions [ 'full_site_promotion_in_effect' ], \App\Models\Torrent :: $promotionTypes [ $spStateGlobal ][ 'text' ]);
if ( ! empty ( $torrentGlobalStateRow [ 'begin' ]) || ! empty ( $torrentGlobalStateRow [ 'deadline' ])) {
$timeRange = sprintf ( $lang_functions [ 'full_site_promotion_time_range' ], $torrentGlobalStateRow [ 'begin' ] ? ? '-∞' , $torrentGlobalStateRow [ 'deadline' ] ? ? '∞' );
$msg .= $timeRange ;
}
msgalert ( " torrents.php " , $msg , " green " );
2022-06-12 22:14:16 +08:00
}
2020-12-26 01:42:23 +08:00
if ( $CURUSER [ 'leechwarn' ] == 'yes' )
{
$kicktimeout = gettime ( $CURUSER [ 'leechwarnuntil' ], false , false , true );
$text = $lang_functions [ 'text_please_improve_ratio_within' ] . $kicktimeout . $lang_functions [ 'text_or_you_will_be_banned' ];
msgalert ( " faq.php#id17 " , $text , " orange " );
}
if ( $deletenotransfertwo_account ) //inactive account deletion notice
{
if ( $CURUSER [ 'downloaded' ] == 0 && ( $CURUSER [ 'uploaded' ] == 0 || $CURUSER [ 'uploaded' ] == $iniupload_main ))
{
$neverdelete_account = ( $neverdelete_account <= UC_VIP ? $neverdelete_account : UC_VIP );
if ( get_user_class () < $neverdelete_account )
{
$secs = $deletenotransfertwo_account * 24 * 60 * 60 ;
$addedtime = strtotime ( $CURUSER [ 'added' ]);
if ( TIMENOW > $addedtime + ( $secs / 3 )) // start notification if one third of the time has passed
{
$kicktimeout = gettime ( date ( " Y-m-d H:i:s " , $addedtime + $secs ), false , false , true );
$text = $lang_functions [ 'text_please_download_something_within' ] . $kicktimeout . $lang_functions [ 'text_inactive_account_be_deleted' ];
msgalert ( " rules.php " , $text , " gray " );
}
}
}
}
if ( $CURUSER [ 'showclienterror' ] == 'yes' )
{
$text = $lang_functions [ 'text_banned_client_warning' ];
msgalert ( " faq.php#id29 " , $text , " black " );
}
if ( $unread )
{
$text = $lang_functions [ 'text_you_have' ] . $unread . $lang_functions [ 'text_new_message' ] . add_s ( $unread ) . $lang_functions [ 'text_click_here_to_read' ];
msgalert ( " messages.php " , $text , " red " );
}
/*
$pending_invitee = $Cache -> get_value ( 'user_' . $CURUSER [ " id " ] . '_pending_invitee_count' );
if ( $pending_invitee == " " ){
2020-12-29 21:49:37 +08:00
$pending_invitee = get_row_count ( " users " , " WHERE status = 'pending' AND invited_by = " . sqlesc ( $CURUSER [ 'id' ]));
2020-12-26 01:42:23 +08:00
$Cache -> cache_value ( 'user_' . $CURUSER [ " id " ] . '_pending_invitee_count' , $pending_invitee , 900 );
}
if ( $pending_invitee > 0 )
{
$text = $lang_functions [ 'text_your_friends' ] . add_s ( $pending_invitee ) . is_or_are ( $pending_invitee ) . $lang_functions [ 'text_awaiting_confirmation' ];
2020-12-29 21:49:37 +08:00
msgalert ( " invite.php?id= " . $CURUSER [ 'id' ], $text , " red " );
2020-12-26 01:42:23 +08:00
} */
$settings_script_name = $_SERVER [ " SCRIPT_FILENAME " ];
if ( ! preg_match ( " /index/i " , $settings_script_name ))
{
$new_news = $Cache -> get_value ( 'user_' . $CURUSER [ " id " ] . '_unread_news_count' );
if ( $new_news == " " ){
$new_news = get_row_count ( " news " , " WHERE notify = 'yes' AND added > " . sqlesc ( $CURUSER [ 'last_home' ]));
$Cache -> cache_value ( 'user_' . $CURUSER [ " id " ] . '_unread_news_count' , $new_news , 300 );
}
if ( $new_news > 0 )
{
$text = $lang_functions [ 'text_there_is' ] . is_or_are ( $new_news ) . $new_news . $lang_functions [ 'text_new_news' ];
msgalert ( " index.php " , $text , " green " );
}
}
2022-08-22 21:07:06 +08:00
//Staff message, not only staff member
// $cacheKey = 'staff_new_message_count_' . $CURUSER['id'];
// $nummessages = $Cache->get_value($cacheKey);
$nummessages = \App\Repositories\MessageRepository :: getStaffMessageCountCache ( $CURUSER [ 'id' ], 'new' );
2022-08-24 00:19:19 +08:00
if ( $nummessages === false ){
2022-08-22 21:07:06 +08:00
$nummessages = \App\Repositories\MessageRepository :: countStaffMessage ( $CURUSER [ 'id' ], 0 );
// $Cache->cache_value($cacheKey, $nummessages, 900);
\App\Repositories\MessageRepository :: updateStaffMessageCountCache ( $CURUSER [ 'id' ], 'new' , $nummessages );
}
if ( $nummessages > 0 ) {
$text = $lang_functions [ 'text_there_is' ] . is_or_are ( $nummessages ) . $nummessages . $lang_functions [ 'text_new_staff_message' ] . add_s ( $nummessages );
msgalert ( " staffbox.php " , $text , " blue " );
}
2022-08-26 01:23:50 +08:00
//torrent approval
if ( user_can ( 'torrent-approval' ) && get_setting ( 'torrent.approval_status_none_visible' ) == 'no' ) {
$cacheKey = 'TORRENT_APPROVAL_NONE' ;
$toApprovalCounts = $Cache -> get_value ( $cacheKey );
if ( $toApprovalCounts === false ) {
$toApprovalCounts = get_row_count ( 'torrents' , 'where approval_status = 0' );
$Cache -> cache_value ( $cacheKey , $toApprovalCounts , 60 );
}
if ( $toApprovalCounts ) {
msgalert ( 'torrents.php?approval_status=0' , sprintf ( $lang_functions [ 'text_torrent_to_approval' ], is_or_are ( $toApprovalCounts ), $toApprovalCounts , add_s ( $toApprovalCounts )), 'darkred' );
}
}
2022-10-16 04:52:44 +08:00
//seed box approval
if ( get_user_class () >= \App\Models\User :: CLASS_ADMINISTRATOR && get_setting ( 'seed_box.enabled' ) == 'yes' ) {
$cacheKey = 'SEED_BOX_RECORD_APPROVAL_NONE' ;
$toApprovalCounts = $Cache -> get_value ( $cacheKey );
if ( $toApprovalCounts === false ) {
$toApprovalCounts = get_row_count ( 'seed_box_records' , 'where status = 0' );
$Cache -> cache_value ( $cacheKey , $toApprovalCounts , 60 );
}
if ( $toApprovalCounts ) {
msgalert ( '/nexusphp/seed-box-records?tableFilters[status][value]=0' , sprintf ( $lang_functions [ 'text_seed_box_record_to_approval' ], is_or_are ( $toApprovalCounts ), $toApprovalCounts , add_s ( $toApprovalCounts )), 'darkred' );
}
}
2022-08-20 19:11:28 +08:00
if ( user_can ( 'staffmem' ))
2020-12-26 01:42:23 +08:00
{
2022-06-27 13:22:16 +08:00
2022-05-06 17:42:18 +08:00
if (( $complaints = $Cache -> get_value ( 'COMPLAINTS_COUNT_CACHE' )) === false ){
$complaints = get_row_count ( 'complains' , 'WHERE answered = 0' );
$Cache -> cache_value ( 'COMPLAINTS_COUNT_CACHE' , $complaints , 600 );
}
2022-06-27 13:22:16 +08:00
if ( $complaints ) {
msgalert ( 'complains.php?action=list' , sprintf ( $lang_functions [ 'text_complains' ], is_or_are ( $complaints ), $complaints , add_s ( $complaints )), 'darkred' );
}
2022-05-06 17:42:18 +08:00
2020-12-26 01:42:23 +08:00
$numreports = $Cache -> get_value ( 'staff_new_report_count' );
if ( $numreports == " " ){
$numreports = get_row_count ( " reports " , " WHERE dealtwith=0 " );
$Cache -> cache_value ( 'staff_new_report_count' , $numreports , 900 );
}
if ( $numreports ){
$text = $lang_functions [ 'text_there_is' ] . is_or_are ( $numreports ) . $numreports . $lang_functions [ 'text_new_report' ] . add_s ( $numreports );
msgalert ( " reports.php " , $text , " blue " );
}
2022-08-22 21:07:06 +08:00
2020-12-26 01:42:23 +08:00
$numcheaters = $Cache -> get_value ( 'staff_new_cheater_count' );
if ( $numcheaters == " " ){
$numcheaters = get_row_count ( " cheaters " , " WHERE dealtwith=0 " );
$Cache -> cache_value ( 'staff_new_cheater_count' , $numcheaters , 900 );
}
if ( $numcheaters ){
$text = $lang_functions [ 'text_there_is' ] . is_or_are ( $numcheaters ) . $numcheaters . $lang_functions [ 'text_new_suspected_cheater' ] . add_s ( $numcheaters );
msgalert ( " cheaterbox.php " , $text , " blue " );
}
}
2021-04-25 03:23:39 +08:00
//show the exam info
2021-04-25 21:28:58 +08:00
$exam = new \Nexus\Exam\Exam ();
$examHtml = $exam -> render ( $CURUSER [ 'id' ]);
if ( ! empty ( $examHtml )) {
2021-04-27 02:44:44 +08:00
msgalert ( " messages.php " , $examHtml , " blue " );
2021-04-25 21:28:58 +08:00
}
2020-12-26 01:42:23 +08:00
}
if ( $offlinemsg )
{
print ( " <p><table width= \" 737 \" border= \" 1 \" cellspacing= \" 0 \" cellpadding= \" 10 \" ><tr><td style='padding: 10px; background: red' class= \" text \" align= \" center \" > \n " );
print ( " <font color= \" white \" > " . $lang_functions [ 'text_website_offline_warning' ] . " </font> " );
print ( " </td></tr></table></p><br /> \n " );
}
}
}
function stdfoot () {
global $SITENAME , $BASEURL , $Cache , $datefounded , $tstart , $icplicense_main , $add_key_shortcut , $query_name , $USERUPDATESET , $CURUSER , $enablesqldebug_tweak , $sqldebug_tweak , $Advertisement , $analyticscode_tweak ;
2022-09-03 00:05:51 +08:00
global $hook ;
2020-12-26 01:42:23 +08:00
print ( " </td></tr></table> " );
print ( " <div id= \" footer \" > " );
2023-05-13 01:59:51 +08:00
if ( $Advertisement && $Advertisement -> enable_ad ()){
2020-12-26 01:42:23 +08:00
$footerad = $Advertisement -> get_ad ( 'footer' );
if ( $footerad )
2022-05-07 22:11:24 +08:00
echo " <div align= \" center \" style= \" margin-top: 10px \" id= \" \" > " . $footerad [ 0 ] . " </div> " ;
2020-12-26 01:42:23 +08:00
}
print ( " <div style= \" margin-top: 10px; margin-bottom: 30px; \" align= \" center \" > " );
2023-06-16 02:07:18 +08:00
if ( $CURUSER && count ( $USERUPDATESET )){
2020-12-26 01:42:23 +08:00
sql_query ( " UPDATE users SET " . join ( " , " , $USERUPDATESET ) . " WHERE id = " . $CURUSER [ 'id' ]);
}
// Variables for End Time
2021-01-11 22:00:46 +08:00
$tend = microtime ( true );
2022-03-20 22:14:00 +08:00
$totaltime = ( $tend - nexus () -> getStartTimestamp ());
2020-12-26 01:42:23 +08:00
$year = substr ( $datefounded , 0 , 4 );
$yearfounded = ( $year ? $year : 2007 );
print ( " (c) " . " <a href= \" " . get_protocol_prefix () . $BASEURL . " \" target= \" _self \" > " . $SITENAME . " </a> " . ( $icplicense_main ? " " . $icplicense_main . " " : " " ) . ( date ( " Y " ) != $yearfounded ? $yearfounded . " - " : " " ) . date ( " Y " ) . " " . VERSION . " <br /><br /> " );
2021-01-11 22:00:46 +08:00
printf ( " [page created in <b> %s </b> sec " , sprintf ( " %.3f " , $totaltime ));
2022-11-05 18:43:49 +08:00
print ( " with <b> " . count ( $query_name ) . " </b> db queries, <b> " . $Cache -> getCacheReadTimes () . " </b> reads and <b> " . $Cache -> getCacheWriteTimes () . " </b> writes of Redis and <b> " . mksize ( memory_get_usage ()) . " </b> ram] " );
2020-12-26 01:42:23 +08:00
print ( " </div> \n " );
if ( $enablesqldebug_tweak == 'yes' && get_user_class () >= $sqldebug_tweak ) {
2021-03-03 00:23:08 +08:00
print ( " <div id= \" sql_debug \" style='text-align: left;'>SQL query list: <ul> " );
2020-12-26 01:42:23 +08:00
foreach ( $query_name as $query ) {
2021-01-15 22:13:46 +08:00
print ( sprintf ( '<li>%s [%s]</li>' , htmlspecialchars ( $query [ 'query' ]), $query [ 'time' ]));
2020-12-26 01:42:23 +08:00
}
print ( " </ul> " );
2020-12-29 21:49:37 +08:00
print ( " Redis key read: <ul> " );
2020-12-26 01:42:23 +08:00
foreach ( $Cache -> getKeyHits ( 'read' ) as $keyName => $hits ) {
print ( " <li> " . htmlspecialchars ( $keyName ) . " : " . $hits . " </li> " );
}
print ( " </ul> " );
2020-12-29 21:49:37 +08:00
print ( " Redis key write: <ul> " );
2020-12-26 01:42:23 +08:00
foreach ( $Cache -> getKeyHits ( 'write' ) as $keyName => $hits ) {
print ( " <li> " . htmlspecialchars ( $keyName ) . " : " . $hits . " </li> " );
}
print ( " </ul> " );
print ( " </div> " );
}
print ( " <div style= \" display: none; \" id= \" lightbox \" class= \" lightbox \" ></div><div style= \" display: none; \" id= \" curtain \" class= \" curtain \" ></div> " );
if ( $add_key_shortcut != " " )
print ( $add_key_shortcut );
print ( " </div> " );
if ( $analyticscode_tweak )
print ( " \n " . $analyticscode_tweak . " \n " );
2022-09-03 00:05:51 +08:00
// $hook->dump();
2022-06-08 14:15:59 +08:00
do_action ( 'nexus_footer' );
2022-04-03 16:03:47 +08:00
foreach ( \Nexus\Nexus :: getAppendFooters () as $value ) {
print ( $value );
}
2022-04-14 00:52:28 +08:00
$js = <<< JS
< script type = " application/javascript " src = " js/nexus.js " ></ script >
< script type = " application/javascript " src = " vendor/jquery-goup-1.1.3/jquery.goup.min.js " ></ script >
2022-04-04 17:26:26 +08:00
< script >
jQuery ( document ) . ready ( function (){
2022-04-14 00:52:28 +08:00
jQuery . goup ()
2022-04-04 17:26:26 +08:00
});
</ script >
2022-04-14 00:52:28 +08:00
JS ;
print ( $js );
2022-08-10 17:38:05 +08:00
print ( '<img id="nexus-preview" style="display: none; position: absolute" src="" />' );
2020-12-26 01:42:23 +08:00
print ( " </body></html> " );
//echo replacePngTags(ob_get_clean());
2021-01-11 22:00:46 +08:00
// unset($_SESSION['queries']);
2020-12-26 01:42:23 +08:00
}
function genbark ( $x , $y ) {
stdhead ( $y );
print ( " <h1> " . htmlspecialchars ( $y ) . " </h1> \n " );
print ( " <p> " . htmlspecialchars ( $x ) . " </p> \n " );
stdfoot ();
exit ();
}
function mksecret ( $len = 20 ) {
$ret = " " ;
for ( $i = 0 ; $i < $len ; $i ++ )
$ret .= chr ( mt_rand ( 100 , 120 ));
return $ret ;
}
function httperr ( $code = 404 ) {
header ( " HTTP/1.0 404 Not found " );
print ( " <h1>Not Found</h1> \n " );
exit ();
}
function logincookie ( $id , $passhash , $updatedb = 1 , $expires = 0x7fffffff , $securelogin = false , $ssl = false , $trackerssl = false )
{
if ( $expires != 0x7fffffff )
$expires = time () + $expires ;
2023-05-15 03:45:51 +08:00
setcookie ( " c_secure_uid " , base64 ( $id ), $expires , " / " , " " , false , true );
setcookie ( " c_secure_pass " , $passhash , $expires , " / " , " " , false , true );
2020-12-26 01:42:23 +08:00
if ( $ssl )
2023-05-15 03:45:51 +08:00
setcookie ( " c_secure_ssl " , base64 ( " yeah " ), $expires , " / " , " " , false , true );
2020-12-26 01:42:23 +08:00
else
2023-05-15 03:45:51 +08:00
setcookie ( " c_secure_ssl " , base64 ( " nope " ), $expires , " / " , " " , false , true );
2020-12-26 01:42:23 +08:00
if ( $trackerssl )
2023-05-15 03:45:51 +08:00
setcookie ( " c_secure_tracker_ssl " , base64 ( " yeah " ), $expires , " / " , " " , false , true );
2020-12-26 01:42:23 +08:00
else
2023-05-15 03:45:51 +08:00
setcookie ( " c_secure_tracker_ssl " , base64 ( " nope " ), $expires , " / " , " " , false , true );
2020-12-26 01:42:23 +08:00
if ( $securelogin )
2023-05-15 03:45:51 +08:00
setcookie ( " c_secure_login " , base64 ( " yeah " ), $expires , " / " , " " , false , true );
2020-12-26 01:42:23 +08:00
else
2023-05-15 03:45:51 +08:00
setcookie ( " c_secure_login " , base64 ( " nope " ), $expires , " / " , " " , false , true );
2020-12-26 01:42:23 +08:00
if ( $updatedb )
sql_query ( " UPDATE users SET last_login = NOW(), lang= " . sqlesc ( get_langid_from_langcookie ()) . " WHERE id = " . sqlesc ( $id ));
}
function set_langfolder_cookie ( $folder , $expires = 0x7fffffff )
{
if ( $expires != 0x7fffffff )
$expires = time () + $expires ;
2023-05-15 03:45:51 +08:00
setcookie ( " c_lang_folder " , $folder , $expires , " / " , " " , false , true );
2020-12-26 01:42:23 +08:00
}
function get_protocol_prefix ()
{
global $securelogin ;
2021-02-28 02:47:13 +08:00
if ( isHttps ()) {
return " https:// " ;
}
2020-12-26 01:42:23 +08:00
if ( $securelogin == " yes " ) {
return " https:// " ;
} elseif ( $securelogin == " no " ) {
return " http:// " ;
} else {
if ( ! isset ( $_COOKIE [ " c_secure_ssl " ])) {
return " http:// " ;
} else {
return base64_decode ( $_COOKIE [ " c_secure_ssl " ]) == " yeah " ? " https:// " : " http:// " ;
}
}
}
2021-01-25 01:23:28 +08:00
function get_langid_from_langcookie ( $lang = '' )
2020-12-26 01:42:23 +08:00
{
2021-01-25 01:23:28 +08:00
if ( empty ( $lang )) {
global $CURLANGDIR ;
$lang = $CURLANGDIR ;
}
$row = mysql_fetch_array ( sql_query ( " SELECT id FROM language WHERE site_lang = 1 AND site_lang_folder = " . sqlesc ( $lang ) . " ORDER BY id ASC " )) or sqlerr ( __FILE__ , __LINE__ );
2020-12-26 01:42:23 +08:00
return $row [ 'id' ];
}
function make_folder ( $pre , $folder_name )
{
$path = $pre . $folder_name ;
2021-01-19 21:50:21 +08:00
$path = ROOT_PATH . ltrim ( $path , './' );
do_log ( $path );
if ( ! is_dir ( $path ))
2020-12-26 01:42:23 +08:00
mkdir ( $path , 0777 , true );
return $path ;
}
function logoutcookie () {
2023-05-15 03:45:51 +08:00
setcookie ( " c_secure_uid " , " " , 0x7fffffff , " / " , " " , false , true );
setcookie ( " c_secure_pass " , " " , 0x7fffffff , " / " , " " , false , true );
// setcookie("c_secure_ssl", "", 0x7fffffff, "/", "", false, true);
setcookie ( " c_secure_tracker_ssl " , " " , 0x7fffffff , " / " , " " , false , true );
setcookie ( " c_secure_login " , " " , 0x7fffffff , " / " , " " , false , true );
// setcookie("c_lang_folder", "", 0x7fffffff, "/", "", false, true);
2020-12-26 01:42:23 +08:00
}
function base64 ( $string , $encode = true ) {
if ( $encode )
return base64_encode ( $string );
else
return base64_decode ( $string );
}
function loggedinorreturn ( $mainpage = false ) {
global $CURUSER , $BASEURL ;
if ( ! $CURUSER ) {
2022-03-20 22:14:00 +08:00
if ( nexus () -> getScript () == 'ajax' ) {
2022-03-19 19:51:23 +08:00
exit ( fail ( 'Not login!' , $_POST ));
}
2023-07-29 23:53:04 +08:00
if ( $mainpage ) {
nexus_redirect ( " login.php " );
} else {
2020-12-26 01:42:23 +08:00
$to = $_SERVER [ " REQUEST_URI " ];
$to = basename ( $to );
2023-07-29 23:53:04 +08:00
nexus_redirect ( " login.php?returnto= " . rawurlencode ( $to ));
2020-12-26 01:42:23 +08:00
}
exit ();
}
2022-07-09 18:06:09 +08:00
// do_log("[USER]: " . $CURUSER['id']);
2020-12-26 01:42:23 +08:00
}
2022-12-08 03:48:20 +08:00
function deletetorrent ( $id , $notify = false ) {
2023-07-26 03:29:50 +08:00
$idArr = is_array ( $id ) ? $id : [ $id ];
2024-04-26 03:21:35 +08:00
$torrentInfo = \App\Models\Torrent :: query ()
2023-07-26 03:29:50 +08:00
-> whereIn ( " id " , $idArr )
2024-04-26 03:21:35 +08:00
-> get ()
2023-07-26 03:29:50 +08:00
-> KeyBy ( " id " )
;
$torrentRep = new \App\Repositories\TorrentRepository ();
2022-10-02 21:14:11 +08:00
$idStr = implode ( ', ' , $idArr ? : [ 0 ]);
2022-08-26 17:35:49 +08:00
$torrent_dir = get_setting ( 'main.torrent_dir' );
2022-10-02 21:14:11 +08:00
\Nexus\Database\NexusDB :: statement ( " DELETE FROM torrents WHERE id in ( $idStr ) " );
\Nexus\Database\NexusDB :: statement ( " DELETE FROM snatched WHERE torrentid in ( $idStr ) " );
2020-12-26 01:42:23 +08:00
foreach ( array ( " peers " , " files " , " comments " ) as $x ) {
2022-10-02 21:14:11 +08:00
\Nexus\Database\NexusDB :: statement ( " DELETE FROM $x WHERE torrent in ( $idStr ) " );
}
\Nexus\Database\NexusDB :: statement ( " DELETE FROM hit_and_runs WHERE torrent_id in ( $idStr ) " );
\Nexus\Database\NexusDB :: statement ( " DELETE FROM claims WHERE torrent_id in ( $idStr ) " );
2023-07-26 03:29:50 +08:00
foreach ( $torrentInfo as $_id => $info ) {
if ( $torrentInfo -> has ( $_id )) {
$torrentRep -> delPiecesHashCache ( $torrentInfo -> get ( $_id ) -> pieces_hash );
}
2022-10-02 21:14:11 +08:00
do_log ( " delete torrent: $_id " , " error " );
unlink ( getFullDirectory ( " $torrent_dir / $_id .torrent " ));
2022-12-08 03:48:20 +08:00
\App\Models\TorrentOperationLog :: add ([
'torrent_id' => $_id ,
'uid' => get_user_id (),
'action_type' => \App\Models\TorrentOperationLog :: ACTION_TYPE_DELETE ,
'comment' => '' ,
], $notify );
2022-10-02 21:14:11 +08:00
}
2023-04-06 02:06:01 +08:00
$meiliSearchRep = new \App\Repositories\MeiliSearchRepository ();
$meiliSearchRep -> deleteDocuments ( $idArr );
2024-04-25 02:15:56 +08:00
if ( is_int ( $id )) {
do_action ( " torrent_delete " , $id );
2024-04-26 03:21:35 +08:00
fire_event ( " torrent_deleted " , $torrentInfo -> get ( $id ));
2024-04-25 02:15:56 +08:00
}
2020-12-26 01:42:23 +08:00
}
function pager ( $rpp , $count , $href , $opts = array (), $pagename = " page " ) {
global $lang_functions , $add_key_shortcut ;
$pages = ceil ( $count / $rpp );
2020-12-28 20:52:54 +08:00
if ( empty ( $opts [ " lastpagedefault " ]))
2020-12-26 01:42:23 +08:00
$pagedefault = 0 ;
else {
$pagedefault = floor (( $count - 1 ) / $rpp );
if ( $pagedefault < 0 )
$pagedefault = 0 ;
}
if ( isset ( $_GET [ $pagename ])) {
2021-01-06 00:56:13 +08:00
$page = intval ( $_GET [ $pagename ] ? ? 0 );
2020-12-26 01:42:23 +08:00
if ( $page < 0 )
$page = $pagedefault ;
}
else
$page = $pagedefault ;
$pager = " " ;
$mp = $pages - 1 ;
//Opera (Presto) doesn't know about event.altKey
$is_presto = strpos ( $_SERVER [ 'HTTP_USER_AGENT' ], 'Presto' );
$as = " <b title= \" " . ( $is_presto ? $lang_functions [ 'text_shift_pageup_shortcut' ] : $lang_functions [ 'text_alt_pageup_shortcut' ]) . " \" ><< " . $lang_functions [ 'text_prev' ] . " </b> " ;
if ( $page >= 1 ) {
$pager .= " <a href= \" " . htmlspecialchars ( $href . $pagename . " = " . ( $page - 1 ) ) . " \" > " ;
$pager .= $as ;
$pager .= " </a> " ;
}
else
$pager .= " <font class= \" gray \" > " . $as . " </font> " ;
$pager .= " " ;
$as = " <b title= \" " . ( $is_presto ? $lang_functions [ 'text_shift_pagedown_shortcut' ] : $lang_functions [ 'text_alt_pagedown_shortcut' ]) . " \" > " . $lang_functions [ 'text_next' ] . " >></b> " ;
if ( $page < $mp && $mp >= 0 ) {
$pager .= " <a href= \" " . htmlspecialchars ( $href . $pagename . " = " . ( $page + 1 ) ) . " \" > " ;
$pager .= $as ;
$pager .= " </a> " ;
}
else
$pager .= " <font class= \" gray \" > " . $as . " </font> " ;
if ( $count ) {
$pagerarr = array ();
$dotted = 0 ;
$dotspace = 3 ;
$dotend = $pages - $dotspace ;
$curdotend = $page - $dotspace ;
$curdotstart = $page + $dotspace ;
for ( $i = 0 ; $i < $pages ; $i ++ ) {
if (( $i >= $dotspace && $i <= $curdotend ) || ( $i >= $curdotstart && $i < $dotend )) {
if ( ! $dotted )
$pagerarr [] = " ... " ;
$dotted = 1 ;
continue ;
}
$dotted = 0 ;
$start = $i * $rpp + 1 ;
$end = $start + $rpp - 1 ;
if ( $end > $count )
$end = $count ;
$text = " $start - $end " ;
if ( $i != $page )
$pagerarr [] = " <a href= \" " . htmlspecialchars ( $href . $pagename . " = " . $i ) . " \" ><b> $text </b></a> " ;
else
$pagerarr [] = " <font class= \" gray \" ><b> $text </b></font> " ;
}
$pagerstr = join ( " | " , $pagerarr );
2022-09-01 23:48:50 +08:00
$pagertop = " <p align= \" center \" class='nexus-pagination'> $pager <br /> $pagerstr </p> \n " ;
$pagerbottom = " <p align= \" center \" class='nexus-pagination'> $pagerstr <br /> $pager </p> \n " ;
2020-12-26 01:42:23 +08:00
}
else {
2022-09-01 23:48:50 +08:00
$pagertop = " <p align= \" center \" class='nexus-pagination'> $pager </p> \n " ;
2020-12-26 01:42:23 +08:00
$pagerbottom = $pagertop ;
}
$start = $page * $rpp ;
$add_key_shortcut = key_shortcut ( $page , $pages - 1 );
2022-06-08 14:15:59 +08:00
return array ( $pagertop , $pagerbottom , " LIMIT $start , $rpp " , $start , $rpp , $page );
2020-12-26 01:42:23 +08:00
}
function commenttable ( $rows , $type , $parent_id , $review = false )
{
global $lang_functions ;
global $CURUSER , $commanage_class ;
global $Advertisement ;
begin_main_frame ();
begin_frame ();
$count = 0 ;
if ( $Advertisement -> enable_ad ())
$commentad = $Advertisement -> get_ad ( 'comment' );
2022-01-19 23:54:55 +08:00
$uidArr = array_unique ( array_column ( $rows , 'user' ));
$neededColumns = array ( 'id' , 'noad' , 'class' , 'enabled' , 'privacy' , 'avatar' , 'signature' , 'uploaded' , 'downloaded' , 'last_access' , 'username' , 'donor' , 'leechwarn' , 'warned' , 'title' );
2022-08-10 17:38:05 +08:00
$userInfoArr = \App\Models\User :: query () -> find ( $uidArr , $neededColumns ) -> keyBy ( 'id' );
2022-01-19 23:54:55 +08:00
2020-12-26 01:42:23 +08:00
foreach ( $rows as $row )
{
2022-01-19 23:54:55 +08:00
// $userRow = get_user_row($row['user']);
2022-02-28 23:20:42 +08:00
$userInfo = $userInfoArr -> get ( $row [ 'user' ], \App\Models\User :: defaultUser ());
$userRow = $userInfo -> toArray ();
2020-12-26 01:42:23 +08:00
if ( $count >= 1 )
{
if ( $Advertisement -> enable_ad ()){
2020-12-29 21:49:37 +08:00
if ( ! empty ( $commentad [ $count - 1 ]))
2022-05-07 22:11:24 +08:00
echo " <div align= \" center \" style= \" margin-top: 10px \" id= \" \" > " . $commentad [ $count - 1 ] . " </div> " ;
2020-12-26 01:42:23 +08:00
}
}
print ( " <div style= \" margin-top: 8pt; margin-bottom: 8pt; \" ><table id= \" cid " . $row [ " id " ] . " \" border= \" 0 \" cellspacing= \" 0 \" cellpadding= \" 0 \" width= \" 100% \" ><tr><td class= \" embedded \" width= \" 99% \" ># " . $row [ " id " ] . " <font color= \" gray \" > " . $lang_functions [ 'text_by' ] . " </font> " );
2022-08-10 17:38:05 +08:00
print ( get_username ( $row [ " user " ], false , true , true , false , false , true ));
2020-12-26 01:42:23 +08:00
print ( " <font color= \" gray \" > " . $lang_functions [ 'text_at' ] . " </font> " . gettime ( $row [ " added " ]) .
2022-08-20 19:11:28 +08:00
( $row [ " editedby " ] && user_can ( 'commanage' ) ? " - [<a href= \" comment.php?action=vieworiginal&cid= " . $row [ 'id' ] . " &type= " . $type . " \" > " . $lang_functions [ 'text_view_original' ] . " </a>] " : " " ) . " </td><td class= \" embedded nowrap \" width= \" 1% \" ><a href= \" #top \" ><img class= \" top \" src= \" pic/trans.gif \" alt= \" Top \" title= \" Top \" /></a> </td></tr></table></div> " );
2020-12-26 01:42:23 +08:00
$avatar = ( $CURUSER [ " avatars " ] == " yes " ? htmlspecialchars ( trim ( $userRow [ " avatar " ])) : " " );
if ( ! $avatar )
$avatar = " pic/default_avatar.png " ;
$text = format_comment ( $row [ " text " ]);
$text_editby = " " ;
if ( $row [ " editedby " ]){
$lastedittime = gettime ( $row [ 'editdate' ], true , false );
$text_editby = " <br /><p><font class= \" small \" > " . $lang_functions [ 'text_last_edited_by' ] . get_username ( $row [ 'editedby' ]) . $lang_functions [ 'text_edited_at' ] . $lastedittime . " </font></p> \n " ;
}
print ( " <table class= \" main \" width= \" 100% \" border= \" 0 \" cellspacing= \" 0 \" cellpadding= \" 5 \" > \n " );
$secs = 900 ;
$dt = sqlesc ( date ( " Y-m-d H:i:s " ,( TIMENOW - $secs ))); // calculate date.
print ( " <tr> \n " );
print ( " <td class= \" rowfollow \" width= \" 150 \" valign= \" top \" style= \" padding: 0px; \" > " . return_avatar_image ( $avatar ) . " </td> \n " );
print ( " <td class= \" rowfollow \" valign= \" top \" ><br /> " . $text . $text_editby . " </td> \n " );
print ( " </tr> \n " );
2020-12-29 21:49:37 +08:00
$actionbar = " <a href= \" comment.php?action=add&sub=quote&cid= " . $row [ 'id' ] . " &pid= " . $parent_id . " &type= " . $type . " \" ><img class= \" f_quote \" src= \" pic/trans.gif \" alt= \" Quote \" title= \" " . $lang_functions [ 'title_reply_with_quote' ] . " \" /></a> " .
2022-08-20 19:11:28 +08:00
" <a href= \" comment.php?action=add&pid= " . $parent_id . " &type= " . $type . " \" ><img class= \" f_reply \" src= \" pic/trans.gif \" alt= \" Add Reply \" title= \" " . $lang_functions [ 'title_add_reply' ] . " \" /></a> " . ( user_can ( 'commanage' ) ? " <a href= \" comment.php?action=delete&cid= " . $row [ 'id' ] . " &type= " . $type . " \" ><img class= \" f_delete \" src= \" pic/trans.gif \" alt= \" Delete \" title= \" " . $lang_functions [ 'title_delete' ] . " \" /></a> " : " " ) . ( $row [ " user " ] == $CURUSER [ " id " ] || get_user_class () >= $commanage_class ? " <a href= \" comment.php?action=edit&cid= " . $row [ 'id' ] . " &type= " . $type . " \" ><img class= \" f_edit \" src= \" pic/trans.gif \" alt= \" Edit \" title= \" " . $lang_functions [ 'title_edit' ] . " \" /> " . " </a> " : " " );
2020-12-26 01:42:23 +08:00
print ( " <tr><td class= \" toolbox \" > " . ( " ' " . $userRow [ 'last_access' ] . " ' " > $dt ? " <img class= \" f_online \" src= \" pic/trans.gif \" alt= \" Online \" title= \" " . $lang_functions [ 'title_online' ] . " \" /> " : " <img class= \" f_offline \" src= \" pic/trans.gif \" alt= \" Offline \" title= \" " . $lang_functions [ 'title_offline' ] . " \" /> " ) . " <a href= \" sendmessage.php?receiver= " . htmlspecialchars ( trim ( $row [ " user " ])) . " \" ><img class= \" f_pm \" src= \" pic/trans.gif \" alt= \" PM \" title= \" " . $lang_functions [ 'title_send_message_to' ] . htmlspecialchars ( $userRow [ " username " ]) . " \" /></a><a href= \" report.php?commentid= " . htmlspecialchars ( trim ( $row [ " id " ])) . " \" ><img class= \" f_report \" src= \" pic/trans.gif \" alt= \" Report \" title= \" " . $lang_functions [ 'title_report_this_comment' ] . " \" /></a></td><td class= \" toolbox \" align= \" right \" > " . $actionbar . " </td> " );
print ( " </tr></table> \n " );
$count ++ ;
}
end_frame ();
end_main_frame ();
}
function searchfield ( $s ) {
return preg_replace ( array ( '/[^a-z0-9]/si' , '/^\s*/s' , '/\s*$/s' , '/\s+/s' ), array ( " " , " " , " " , " " ), $s );
}
function genrelist ( $catmode = 1 ) {
global $Cache ;
if ( ! $ret = $Cache -> get_value ( 'category_list_mode_' . $catmode )){
$ret = array ();
2023-04-21 00:50:10 +08:00
$res = sql_query ( " SELECT id, mode, name, image FROM categories WHERE mode = " . sqlesc ( $catmode ) . " ORDER BY sort_index desc " );
2020-12-26 01:42:23 +08:00
while ( $row = mysql_fetch_array ( $res ))
$ret [] = $row ;
2023-04-21 00:50:10 +08:00
$Cache -> cache_value ( 'category_list_mode_' . $catmode , $ret , 3600 );
2020-12-26 01:42:23 +08:00
}
return $ret ;
}
2022-11-09 21:56:03 +08:00
function searchbox_item_list ( string $table , int $mode ){
2020-12-26 01:42:23 +08:00
global $Cache ;
2022-09-14 19:05:29 +08:00
$cacheKey = " { $table } _list_mode_ { $mode } " ;
if ( ! $ret = $Cache -> get_value ( $cacheKey )){
2020-12-26 01:42:23 +08:00
$ret = array ();
2022-11-09 21:56:03 +08:00
$sql = " SELECT * FROM $table " ;
if ( $mode > 0 ) {
$sql .= " where (mode = ' $mode ' or mode = 0) " ;
}
$sql .= " ORDER BY sort_index, id " ;
$res = sql_query ( $sql );
2020-12-26 01:42:23 +08:00
while ( $row = mysql_fetch_array ( $res ))
$ret [] = $row ;
2022-10-27 20:21:54 +08:00
$Cache -> cache_value ( $cacheKey , $ret , 3600 );
2020-12-26 01:42:23 +08:00
}
return $ret ;
}
2022-04-14 00:52:28 +08:00
function langlist ( $type , $enabled = null ) {
2020-12-26 01:42:23 +08:00
global $Cache ;
2022-04-14 00:52:28 +08:00
$cacheKey = $type . '_lang_list' ;
return \Nexus\Database\NexusDB :: remember ( $cacheKey , 600 , function () use ( $type , $enabled ) {
$query = \App\Models\Language :: query () -> where ( $type , 1 );
if ( $enabled !== null ) {
$query -> whereIn ( 'site_lang_folder' , \App\Models\Language :: listEnabled ( true ));
}
return $query -> get () -> toArray ();
});
// if (!$ret = $Cache->get_value($type.'_lang_list')){
// $ret = array();
// $res = sql_query("SELECT id, lang_name, flagpic, site_lang_folder FROM language WHERE ". $type ."=1 ORDER BY site_lang DESC, id ASC");
// while ($row = mysql_fetch_array($res))
// $ret[] = $row;
// $Cache->cache_value($type.'_lang_list', $ret, 152800);
// }
// return $ret;
2020-12-26 01:42:23 +08:00
}
function linkcolor ( $num ) {
if ( ! $num )
return " red " ;
// if ($num == 1)
// return "yellow";
return " green " ;
}
2021-05-13 21:31:09 +08:00
function writecomment ( $userid , $comment , $oldModcomment = null ) {
if ( is_null ( $oldModcomment )) {
$res = sql_query ( " SELECT modcomment FROM users WHERE id = ' $userid ' " ) or sqlerr ( __FILE__ , __LINE__ );
$arr = mysql_fetch_assoc ( $res );
2022-04-25 01:22:07 +08:00
$modcomment = date ( " Y-m-d " ) . " - " . $comment . " " . ( $arr [ 'modcomment' ] != " " ? " \n " : " " ) . $arr [ 'modcomment' ];
2021-05-13 21:31:09 +08:00
} else {
2022-04-25 01:22:07 +08:00
$modcomment = date ( " Y-m-d " ) . " - " . $comment . " " . ( $oldModcomment != " " ? " \n " : " " ) . $oldModcomment ;
2021-05-13 21:31:09 +08:00
}
2020-12-26 01:42:23 +08:00
$modcom = sqlesc ( $modcomment );
2021-05-13 21:31:09 +08:00
do_log ( " update user: $userid prepend modcomment: $comment , with oldModcomment: $oldModcomment " );
2020-12-26 01:42:23 +08:00
return sql_query ( " UPDATE users SET modcomment = $modcom WHERE id = ' $userid ' " ) or sqlerr ( __FILE__ , __LINE__ );
}
function return_torrent_bookmark_array ( $userid )
{
global $Cache ;
static $ret ;
if ( ! $ret ){
if ( ! $ret = $Cache -> get_value ( 'user_' . $userid . '_bookmark_array' )){
$ret = array ();
$res = sql_query ( " SELECT * FROM bookmarks WHERE userid= " . sqlesc ( $userid ));
if ( mysql_num_rows ( $res ) != 0 ){
while ( $row = mysql_fetch_array ( $res ))
$ret [] = $row [ 'torrentid' ];
$Cache -> cache_value ( 'user_' . $userid . '_bookmark_array' , $ret , 132800 );
} else {
$Cache -> cache_value ( 'user_' . $userid . '_bookmark_array' , array ( 0 ), 132800 );
2021-03-26 12:00:25 +08:00
$ret [] = 0 ;
2020-12-26 01:42:23 +08:00
}
}
}
return $ret ;
}
function get_torrent_bookmark_state ( $userid , $torrentid , $text = false )
{
global $lang_functions ;
2021-01-06 02:26:28 +08:00
$userid = intval ( $userid ? ? 0 );
$torrentid = intval ( $torrentid ? ? 0 );
2020-12-26 01:42:23 +08:00
$ret = array ();
$ret = return_torrent_bookmark_array ( $userid );
if ( ! count ( $ret ) || ! in_array ( $torrentid , $ret , false )) // already bookmarked
$act = ( $text == true ? $lang_functions [ 'title_bookmark_torrent' ] : " <img class= \" delbookmark \" src= \" pic/trans.gif \" alt= \" Unbookmarked \" title= \" " . $lang_functions [ 'title_bookmark_torrent' ] . " \" /> " );
else
$act = ( $text == true ? $lang_functions [ 'title_delbookmark_torrent' ] : " <img class= \" bookmark \" src= \" pic/trans.gif \" alt= \" Bookmarked \" title= \" " . $lang_functions [ 'title_delbookmark_torrent' ] . " \" /> " );
return $act ;
}
2022-09-02 19:49:41 +08:00
function torrenttable ( $rows , $variant = " torrent " , $searchBoxId = 0 ) {
2020-12-26 01:42:23 +08:00
global $Cache ;
global $lang_functions ;
global $CURUSER , $waitsystem ;
global $showextinfo ;
2022-06-24 14:55:10 +08:00
global $torrentmanage_class , $smalldescription_main , $enabletooltip_tweak , $staffmem_class ;
2020-12-26 01:42:23 +08:00
global $CURLANGDIR ;
2021-03-16 21:12:27 +08:00
$torrent = new Nexus\Torrent\Torrent ();
2022-06-24 14:55:10 +08:00
$torrentRep = new \App\Repositories\TorrentRepository ();
2022-08-31 23:08:26 +08:00
$imdb = new \Nexus\Imdb\Imdb ();
2022-09-02 19:49:41 +08:00
$torrentIdArr = $ownerIdArr = [];
foreach ( $rows as $row ) {
$torrentIdArr [] = $row [ 'id' ];
$ownerIdArr [] = $row [ 'owner' ];
}
unset ( $row );
2023-04-13 01:33:35 +08:00
$enableImdb = get_setting ( " main.showimdbinfo " ) == 'yes' ;
$enablePtGen = get_setting ( 'main.enable_pt_gen_systemyes' ) == 'yes' ;
2022-03-08 15:08:56 +08:00
$torrentSeedingLeechingStatus = $torrent -> listLeechingSeedingStatus ( $CURUSER [ 'id' ], $torrentIdArr );
$tagRep = new \App\Repositories\TagRepository ();
2022-09-17 20:38:54 +08:00
$torrentTagCollection = \App\Models\TorrentTag :: query () -> whereIn ( 'torrent_id' , $torrentIdArr ) -> get ();
2022-03-08 15:08:56 +08:00
$torrentTagResult = $torrentTagCollection -> groupBy ( 'torrent_id' );
2022-09-02 19:49:41 +08:00
$showCover = false ;
2022-10-22 23:53:02 +08:00
$showSeedBoxIcon = false ;
2022-09-02 19:49:41 +08:00
if ( $searchBoxId ) {
$searchBoxExtra = get_searchbox_value ( $searchBoxId , " extra " );
if ( ! empty ( $searchBoxExtra [ \App\Models\SearchBox :: EXTRA_DISPLAY_COVER_ON_TORRENT_LIST ])) {
$showCover = true ;
}
2022-10-22 23:53:02 +08:00
$showSeedBoxIcon = get_setting ( 'seed_box.enabled' ) == 'yes' ;
2022-09-06 21:54:13 +08:00
if ( empty ( $searchBoxExtra [ \App\Models\SearchBox :: EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST ])) {
$showSeedBoxIcon = false ;
}
2022-09-02 19:49:41 +08:00
}
//seedBoxIcon
if ( $showSeedBoxIcon ) {
$seedBoxRep = new \App\Repositories\SeedBoxRepository ();
2022-09-12 20:00:07 +08:00
$seedBoxPeerInfo = \App\Models\Peer :: query ()
2022-09-02 19:49:41 +08:00
-> whereIn ( 'torrent' , $torrentIdArr )
-> where ( 'seeder' , 'yes' )
2022-09-12 20:00:07 +08:00
-> where ( 'is_seed_box' , '1' )
-> get ([ 'torrent' , 'is_seed_box' ])
2022-09-02 19:49:41 +08:00
-> keyBy ( 'torrent' );
}
2022-03-08 15:08:56 +08:00
2021-06-14 13:16:21 +08:00
$last_browse = $CURUSER [ 'last_browse' ];
// if ($variant == "torrent"){
// $last_browse = $CURUSER['last_browse'];
// $sectiontype = $browsecatmode;
// }
// elseif($variant == "music"){
// $last_browse = $CURUSER['last_music'];
// $sectiontype = $specialcatmode;
// }
// else{
// $last_browse = $CURUSER['last_browse'];
// $sectiontype = "";
// }
2020-12-26 01:42:23 +08:00
$time_now = TIMENOW ;
if ( $last_browse > $time_now ) {
$last_browse = $time_now ;
}
2020-12-29 21:49:37 +08:00
$wait = 0 ;
2020-12-26 01:42:23 +08:00
if ( get_user_class () < UC_VIP && $waitsystem == " yes " ) {
$ratio = get_ratio ( $CURUSER [ " id " ], false );
$gigs = $CURUSER [ " uploaded " ] / ( 1024 * 1024 * 1024 );
if ( $gigs > 10 )
{
if ( $ratio < 0.4 ) $wait = 24 ;
elseif ( $ratio < 0.5 ) $wait = 12 ;
elseif ( $ratio < 0.6 ) $wait = 6 ;
elseif ( $ratio < 0.8 ) $wait = 3 ;
else $wait = 0 ;
}
else $wait = 0 ;
}
?>
< table class = " torrents " cellspacing = " 0 " cellpadding = " 5 " width = " 100% " >
< tr >
< ? php
$count_get = 0 ;
$oldlink = " " ;
foreach ( $_GET as $get_name => $get_value ) {
$get_name = mysql_real_escape_string ( strip_tags ( str_replace ( array ( " \" " , " ' " ), array ( " " , " " ), $get_name )));
$get_value = mysql_real_escape_string ( strip_tags ( str_replace ( array ( " \" " , " ' " ), array ( " " , " " ), $get_value )));
if ( $get_name != " sort " && $get_name != " type " ) {
if ( $count_get > 0 ) {
$oldlink .= " & " . $get_name . " = " . $get_value ;
}
else {
$oldlink .= $get_name . " = " . $get_value ;
}
$count_get ++ ;
}
}
if ( $count_get > 0 ) {
$oldlink = $oldlink . " & " ;
}
2020-12-29 21:49:37 +08:00
$sort = $_GET [ 'sort' ] ? ? '' ;
2020-12-26 01:42:23 +08:00
$link = array ();
for ( $i = 1 ; $i <= 9 ; $i ++ ){
if ( $sort == $i )
$link [ $i ] = ( $_GET [ 'type' ] == " desc " ? " asc " : " desc " );
else $link [ $i ] = ( $i == 1 ? " asc " : " desc " );
}
?>
< td class = " colhead " style = " padding: 0px " >< ? php echo $lang_functions [ 'col_type' ] ?> </td>
< td class = " colhead " >< a href = " ?<?php echo $oldlink ?>sort=1&type=<?php echo $link[1] ?> " >< ? php echo $lang_functions [ 'col_name' ] ?> </a></td>
< ? php
if ( $wait )
{
print ( " <td class= \" colhead \" > " . $lang_functions [ 'col_wait' ] . " </td> \n " );
}
if ( $CURUSER [ 'showcomnum' ] != 'no' ) { ?>
< td class = " colhead " >< a href = " ?<?php echo $oldlink ?>sort=3&type=<?php echo $link[3] ?> " >< img class = " comments " src = " pic/trans.gif " alt = " comments " title = " <?php echo $lang_functions['title_number_of_comments'] ?> " /></ a ></ td >
< ? php } ?>
< td class = " colhead " >< a href = " ?<?php echo $oldlink ?>sort=4&type=<?php echo $link[4] ?> " >< img class = " time " src = " pic/trans.gif " alt = " time " title = " <?php echo ( $CURUSER['timetype'] != 'timealive' ? $lang_functions['title_time_added'] : $lang_functions['title_time_alive'] )?> " /></ a ></ td >
< td class = " colhead " >< a href = " ?<?php echo $oldlink ?>sort=5&type=<?php echo $link[5] ?> " >< img class = " size " src = " pic/trans.gif " alt = " size " title = " <?php echo $lang_functions['title_size'] ?> " /></ a ></ td >
< td class = " colhead " >< a href = " ?<?php echo $oldlink ?>sort=7&type=<?php echo $link[7] ?> " >< img class = " seeders " src = " pic/trans.gif " alt = " seeders " title = " <?php echo $lang_functions['title_number_of_seeders'] ?> " /></ a ></ td >
< td class = " colhead " >< a href = " ?<?php echo $oldlink ?>sort=8&type=<?php echo $link[8] ?> " >< img class = " leechers " src = " pic/trans.gif " alt = " leechers " title = " <?php echo $lang_functions['title_number_of_leechers'] ?> " /></ a ></ td >
< td class = " colhead " >< a href = " ?<?php echo $oldlink ?>sort=6&type=<?php echo $link[6] ?> " >< img class = " snatched " src = " pic/trans.gif " alt = " snatched " title = " <?php echo $lang_functions['title_number_of_snatched'] ?> " /></ a ></ td >
< td class = " colhead " >< a href = " ?<?php echo $oldlink ?>sort=9&type=<?php echo $link[9] ?> " >< ? php echo $lang_functions [ 'col_uploader' ] ?> </a></td>
< ? php
2022-08-20 19:11:28 +08:00
if ( user_can ( 'torrentmanage' )) { ?>
2020-12-26 01:42:23 +08:00
< td class = " colhead " >< ? php echo $lang_functions [ 'col_action' ] ?> </td>
< ? php } ?>
</ tr >
< ? php
$caticonrow = get_category_icon_row ( $CURUSER [ 'caticon' ]);
if ( $caticonrow [ 'secondicon' ] == 'yes' )
$has_secondicon = true ;
else $has_secondicon = false ;
$counter = 0 ;
if ( $smalldescription_main == 'no' || $CURUSER [ 'showsmalldescr' ] == 'no' )
$displaysmalldescr = false ;
else $displaysmalldescr = true ;
2021-03-16 21:12:27 +08:00
//while ($row = mysql_fetch_assoc($res))
2022-04-04 17:26:26 +08:00
$lastcom_tooltip = [];
$torrent_tooltip = [];
2021-03-16 21:12:27 +08:00
foreach ( $rows as $row )
2020-12-26 01:42:23 +08:00
{
$id = $row [ " id " ];
2022-08-10 17:38:05 +08:00
$sphighlight = get_torrent_bg_color ( $row [ 'sp_state' ], $row [ 'pos_state' ], $row );
2020-12-26 01:42:23 +08:00
print ( " <tr " . $sphighlight . " > \n " );
print ( " <td class= \" rowfollow nowrap \" valign= \" middle \" style='padding: 0px'> " );
if ( isset ( $row [ " category " ])) {
print ( return_category_image ( $row [ " category " ], " ? " ));
if ( $has_secondicon ){
2022-03-19 16:47:46 +08:00
print ( get_second_icon ( $row ));
2020-12-26 01:42:23 +08:00
}
}
else
print ( " - " );
print ( " </td> \n " );
//torrent name
$dispname = trim ( $row [ " name " ]);
$short_torrent_name_alt = " " ;
$mouseovertorrent = " " ;
$tooltipblock = " " ;
$has_tooltip = false ;
if ( $enabletooltip_tweak == 'yes' )
$tooltiptype = $CURUSER [ 'tooltip' ];
else
$tooltiptype = 'off' ;
switch ( $tooltiptype ){
case 'minorimdb' : {
if ( $showextinfo [ 'imdb' ] == 'yes' && $row [ " url " ])
{
$url = $row [ 'url' ];
$cache = $row [ 'cache_stamp' ];
$type = 'minor' ;
$has_tooltip = true ;
}
break ;
}
case 'medianimdb' :
{
if ( $showextinfo [ 'imdb' ] == 'yes' && $row [ " url " ])
{
$url = $row [ 'url' ];
$cache = $row [ 'cache_stamp' ];
$type = 'median' ;
$has_tooltip = true ;
}
break ;
}
case 'off' : break ;
}
if ( ! $has_tooltip )
$short_torrent_name_alt = " title= \" " . htmlspecialchars ( $dispname ) . " \" " ;
else {
$torrent_tooltip [ $counter ][ 'id' ] = " torrent_ " . $counter ;
$torrent_tooltip [ $counter ][ 'content' ] = " " ;
$mouseovertorrent = " onmouseover= \" get_ext_info_ajax(' " . $torrent_tooltip [ $counter ][ 'id' ] . " ',' " . $url . " ',' " . $cache . " ',' " . $type . " '); domTT_activate(this, event, 'content', document.getElementById(' " . $torrent_tooltip [ $counter ][ 'id' ] . " '), 'trail', false, 'delay',600,'lifetime',6000,'fade','both','styleClass','niceTitle', 'fadeMax',87, 'maxWidth', 500); \" " ;
}
$count_dispname = mb_strlen ( $dispname , " UTF-8 " );
if ( ! $displaysmalldescr || $row [ " small_descr " ] == " " ) // maximum length of torrent name
2021-06-23 20:20:34 +08:00
$max_length_of_torrent_name = 200 ;
2020-12-26 01:42:23 +08:00
elseif ( $CURUSER [ 'fontsize' ] == 'large' )
2021-06-23 20:20:34 +08:00
$max_length_of_torrent_name = 120 ;
2020-12-26 01:42:23 +08:00
elseif ( $CURUSER [ 'fontsize' ] == 'small' )
2021-06-23 20:20:34 +08:00
$max_length_of_torrent_name = 160 ;
else $max_length_of_torrent_name = 140 ;
2020-12-26 01:42:23 +08:00
if ( $count_dispname > $max_length_of_torrent_name )
$dispname = mb_substr ( $dispname , 0 , $max_length_of_torrent_name - 2 , " UTF-8 " ) . " .. " ;
2021-06-01 01:28:46 +08:00
if ( $CURUSER [ 'appendsticky' ] == 'yes' ) {
$posStates = \App\Models\Torrent :: listPosStates ();
$stickyicon = str_repeat ( " <img class= \" sticky \" src= \" pic/trans.gif \" alt= \" Sticky \" title= \" " . $posStates [ $row [ 'pos_state' ]][ 'text' ] . " \" /> " , $posStates [ $row [ 'pos_state' ]][ 'icon_counts' ] ? ? 0 );
} else {
$stickyicon = " " ;
}
2022-06-08 14:15:59 +08:00
$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 );
2022-10-22 20:52:08 +08:00
$hrImg = get_hr_img ( $row , $row [ 'search_box_id' ]);
2021-06-21 02:01:26 +08:00
2022-08-31 23:08:26 +08:00
//cover
2022-09-02 19:49:41 +08:00
$coverSrc = $tdCover = '' ;
if ( $showCover ) {
if ( $imdb_id = parse_imdb_id ( $row [ " url " ])) {
try {
if ( $imdb -> getCacheStatus ( $imdb_id ) == 1 ) {
$coverSrc = $imdb -> getMovie ( $imdb_id ) -> photo ( false );
}
} catch ( \Exception $exception ) {
do_log ( " torrent: { $row [ 'id' ] } get cover from imdb error: " . $exception -> getMessage () . " \n [stacktrace] \n " . $exception -> getTraceAsString (), 'error' );
2022-09-01 02:47:17 +08:00
}
2022-08-31 23:08:26 +08:00
}
2022-09-02 19:49:41 +08:00
if ( empty ( $coverSrc ) && ! empty ( $row [ 'cover' ])) {
$coverSrc = $row [ 'cover' ];
}
$tdCover = sprintf ( '<td class="embedded" style="text-align: center;width: 46px;height: 46px"><img src="pic/misc/spinner.svg" data-src="%s" class="nexus-lazy-load" style="max-height: 46px;max-width: 46px" /></td>' , $coverSrc );
2022-08-31 23:08:26 +08:00
}
2022-09-02 19:49:41 +08:00
2022-08-31 23:08:26 +08:00
print ( " <td class= \" rowfollow \" width= \" 100% \" align= \" left \" style='padding: 0px'><table class= \" torrentname \" width= \" 100% \" ><tr " . $sphighlight . " > $tdCover <td class= \" embedded \" style='padding-left: 5px'> " . $stickyicon . " <a $short_torrent_name_alt $mouseovertorrent href= \" details.php?id= " . $id . " &hit=1 \" ><b> " . htmlspecialchars ( $dispname ) . " </b></a> " );
2020-12-26 01:42:23 +08:00
$picked_torrent = " " ;
if ( $CURUSER [ 'appendpicked' ] != 'no' ){
if ( $row [ 'picktype' ] == " hot " )
$picked_torrent = " <b>[<font class='hot'> " . $lang_functions [ 'text_hot' ] . " </font>]</b> " ;
elseif ( $row [ 'picktype' ] == " classic " )
$picked_torrent = " <b>[<font class='classic'> " . $lang_functions [ 'text_classic' ] . " </font>]</b> " ;
elseif ( $row [ 'picktype' ] == " recommended " )
$picked_torrent = " <b>[<font class='recommended'> " . $lang_functions [ 'text_recommended' ] . " </font>]</b> " ;
}
if ( $CURUSER [ 'appendnew' ] != 'no' && strtotime ( $row [ " added " ]) >= $last_browse )
print ( " <b> (<font class='new'> " . $lang_functions [ 'text_new_uppercase' ] . " </font>)</b> " );
$banned_torrent = ( $row [ " banned " ] == 'yes' ? " <b>(<font class= \" striking \" > " . $lang_functions [ 'text_banned' ] . " </font>)</b> " : " " );
2022-06-08 14:15:59 +08:00
$sp_torrent_sub = get_torrent_promotion_append_sub ( $row [ 'sp_state' ], " " , true , $row [ 'added' ], $row [ 'promotion_time_type' ], $row [ 'promotion_until' ], $row [ '__ignore_global_sp_state' ] ? ? false );
2022-06-24 14:55:10 +08:00
$approvalStatusIcon = $torrentRep -> renderApprovalStatus ( $row [ 'approval_status' ]);
2022-09-12 20:00:07 +08:00
if ( $showSeedBoxIcon && $seedBoxPeerInfo -> has ( $row [ 'id' ])) {
$seedBoxIcon = $seedBoxRep -> getSeedBoxIcon ();
2022-09-02 19:49:41 +08:00
} else {
$seedBoxIcon = '' ;
}
2023-02-11 16:08:48 +08:00
$paidIcon = $torrentRep -> getPaidIcon ( $row );
$titleSuffix = $banned_torrent . $paidIcon . $picked_torrent . $sp_torrent . $sp_torrent_sub . $hrImg . $seedBoxIcon . $approvalStatusIcon ;
2022-06-08 14:15:59 +08:00
$titleSuffix = apply_filter ( 'torrent_title_suffix' , $titleSuffix , $row );
print ( $titleSuffix );
2022-03-08 15:08:56 +08:00
/**
* render tags
*/
2022-03-08 21:01:12 +08:00
$tagOwns = $torrentTagResult -> get ( $id );
if ( $tagOwns ) {
2022-10-30 17:30:24 +08:00
$tags = $tagRep -> renderSpan ( $row [ 'search_box_id' ], $tagOwns -> pluck ( 'tag_id' ) -> toArray ());
2022-03-08 21:01:12 +08:00
} else {
$tags = '' ;
}
2020-12-26 01:42:23 +08:00
if ( $displaysmalldescr ){
//small descr
$dissmall_descr = trim ( $row [ " small_descr " ]);
$count_dissmall_descr = mb_strlen ( $dissmall_descr , " UTF-8 " );
$max_lenght_of_small_descr = $max_length_of_torrent_name ; // maximum length
if ( $count_dissmall_descr > $max_lenght_of_small_descr )
{
$dissmall_descr = mb_substr ( $dissmall_descr , 0 , $max_lenght_of_small_descr - 2 , " UTF-8 " ) . " .. " ;
}
2021-03-18 20:32:35 +08:00
$dissmall_descr = $tags . htmlspecialchars ( $dissmall_descr );
print ( $dissmall_descr == " " ? " " : " <br /> " . $dissmall_descr );
2021-02-20 18:22:19 +08:00
} else {
2021-03-18 20:32:35 +08:00
print ( $tags ? " <br /> $tags " : " " );
2021-03-16 21:12:27 +08:00
}
2021-03-17 01:21:35 +08:00
//progress bar
2021-03-16 21:12:27 +08:00
if ( isset ( $torrentSeedingLeechingStatus [ $row [ 'id' ]])) {
2021-03-17 01:21:35 +08:00
echo $torrent -> renderProgressBar ( $torrentSeedingLeechingStatus [ $row [ 'id' ]][ 'active_status' ], $torrentSeedingLeechingStatus [ $row [ 'id' ]][ 'progress' ]);
2021-02-20 18:22:19 +08:00
}
2020-12-26 01:42:23 +08:00
print ( " </td> " );
2022-04-14 00:52:28 +08:00
2023-04-13 01:33:35 +08:00
if ( $enableImdb || $enablePtGen ) {
echo $torrent -> renderTorrentsPageAverageRating ( $row );
}
2020-12-26 01:42:23 +08:00
$act = " " ;
if ( $CURUSER [ " dlicon " ] != 'no' && $CURUSER [ " downloadpos " ] != " no " )
$act .= " <a href= \" download.php?id= " . $id . " \" ><img class= \" download \" src= \" pic/trans.gif \" style='padding-bottom: 2px;' alt= \" download \" title= \" " . $lang_functions [ 'title_download_torrent' ] . " \" /></a> " ;
if ( $CURUSER [ " bmicon " ] == 'yes' ){
$bookmark = " href= \" javascript: bookmark( " . $id . " , " . $counter . " ); \" " ;
$act .= ( $act ? " <br /> " : " " ) . " <a id= \" bookmark " . $counter . " \" " . $bookmark . " > " . get_torrent_bookmark_state ( $CURUSER [ 'id' ], $id ) . " </a> " ;
}
2022-08-31 23:08:26 +08:00
print ( " <td width= \" 20 \" class= \" embedded \" style= \" text-align: right;padding-right: 5px \" valign= \" middle \" > " . $act . " </td> \n " );
2020-12-26 01:42:23 +08:00
print ( " </tr></table></td> " );
if ( $wait )
{
$elapsed = floor (( TIMENOW - strtotime ( $row [ " added " ])) / 3600 );
if ( $elapsed < $wait )
{
$color = dechex ( floor ( 127 * ( $wait - $elapsed ) / 48 + 128 ) * 65536 );
print ( " <td class= \" rowfollow nowrap \" ><a href= \" faq.php#id46 \" ><font color= \" " . $color . " \" > " . number_format ( $wait - $elapsed ) . $lang_functions [ 'text_h' ] . " </font></a></td> \n " );
}
else
print ( " <td class= \" rowfollow nowrap \" > " . $lang_functions [ 'text_none' ] . " </td> \n " );
}
2021-04-22 03:24:59 +08:00
2020-12-26 01:42:23 +08:00
if ( $CURUSER [ 'showcomnum' ] != 'no' )
{
print ( " <td class= \" rowfollow \" > " );
$nl = " " ;
//comments
$nl = " <br /> " ;
if ( ! $row [ " comments " ]) {
print ( " <a href= \" comment.php?action=add&pid= " . $id . " &type=torrent \" title= \" " . $lang_functions [ 'title_add_comments' ] . " \" > " . $row [ " comments " ] . " </a> " );
} else {
if ( $enabletooltip_tweak == 'yes' && $CURUSER [ 'showlastcom' ] != 'no' )
{
if ( ! $lastcom = $Cache -> get_value ( 'torrent_' . $id . '_last_comment_content' )){
$res2 = sql_query ( " SELECT user, added, text FROM comments WHERE torrent = $id ORDER BY id DESC LIMIT 1 " );
$lastcom = mysql_fetch_array ( $res2 );
$Cache -> cache_value ( 'torrent_' . $id . '_last_comment_content' , $lastcom , 1855 );
}
$timestamp = strtotime ( $lastcom [ " added " ]);
$hasnewcom = ( $lastcom [ 'user' ] != $CURUSER [ 'id' ] && $timestamp >= $last_browse );
if ( $lastcom )
{
if ( $CURUSER [ 'timetype' ] != 'timealive' )
$lastcomtime = $lang_functions [ 'text_at_time' ] . $lastcom [ 'added' ];
else
$lastcomtime = $lang_functions [ 'text_blank' ] . gettime ( $lastcom [ " added " ], true , false , true );
$lastcom_tooltip [ $counter ][ 'id' ] = " lastcom_ " . $counter ;
$lastcom_tooltip [ $counter ][ 'content' ] = ( $hasnewcom ? " <b>(<font class='new'> " . $lang_functions [ 'text_new_uppercase' ] . " </font>)</b> " : " " ) . $lang_functions [ 'text_last_commented_by' ] . get_username ( $lastcom [ 'user' ]) . $lastcomtime . " <br /> " . format_comment ( mb_substr ( $lastcom [ 'text' ], 0 , 100 , " UTF-8 " ) . ( mb_strlen ( $lastcom [ 'text' ], " UTF-8 " ) > 100 ? " ...... " : " " ), true , false , false , true , 600 , false , false );
$onmouseover = " onmouseover= \" domTT_activate(this, event, 'content', document.getElementById(' " . $lastcom_tooltip [ $counter ][ 'id' ] . " '), 'trail', false, 'delay', 500,'lifetime',3000,'fade','both','styleClass','niceTitle','fadeMax', 87,'maxWidth', 400); \" " ;
}
} else {
$hasnewcom = false ;
$onmouseover = " " ;
}
print ( " <b><a href= \" details.php?id= " . $id . " &hit=1&cmtpage=1#startcomments \" " . $onmouseover . " > " . ( $hasnewcom ? " <font class='new'> " : " " ) . $row [ " comments " ] . ( $hasnewcom ? " </font> " : " " ) . " </a></b> " );
}
print ( " </td> " );
}
$time = $row [ " added " ];
$time = gettime ( $time , false , true );
print ( " <td class= \" rowfollow nowrap \" > " . $time . " </td> " );
//size
print ( " <td class= \" rowfollow \" > " . mksize_compact ( $row [ " size " ]) . " </td> " );
if ( $row [ " seeders " ]) {
$ratio = ( $row [ " leechers " ] ? ( $row [ " seeders " ] / $row [ " leechers " ]) : 1 );
$ratiocolor = get_slr_color ( $ratio );
print ( " <td class= \" rowfollow \" align= \" center \" ><b><a href= \" details.php?id= " . $id . " &hit=1&dllist=1#seeders \" > " . ( $ratiocolor ? " <font color= \" " .
$ratiocolor . " \" > " . number_format ( $row [ " seeders " ]) . " </font> " : number_format ( $row [ " seeders " ])) . " </a></b></td> \n " );
}
else
print ( " <td class= \" rowfollow \" ><span class= \" " . linkcolor ( $row [ " seeders " ]) . " \" > " . number_format ( $row [ " seeders " ]) . " </span></td> \n " );
if ( $row [ " leechers " ]) {
print ( " <td class= \" rowfollow \" ><b><a href= \" details.php?id= " . $id . " &hit=1&dllist=1#leechers \" > " .
number_format ( $row [ " leechers " ]) . " </a></b></td> \n " );
}
else
print ( " <td class= \" rowfollow \" >0</td> \n " );
if ( $row [ " times_completed " ] >= 1 )
2020-12-29 21:49:37 +08:00
print ( " <td class= \" rowfollow \" ><a href= \" viewsnatches.php?id= " . $row [ 'id' ] . " \" ><b> " . number_format ( $row [ " times_completed " ]) . " </b></a></td> \n " );
2020-12-26 01:42:23 +08:00
else
print ( " <td class= \" rowfollow \" > " . number_format ( $row [ " times_completed " ]) . " </td> \n " );
2022-09-05 01:46:38 +08:00
if (
$row [ " anonymous " ] == " yes "
2022-10-12 01:42:43 +08:00
&& ( user_can ( 'viewanonymous' ) || ( isset ( $row [ 'owner' ]) && $row [ 'owner' ] == $CURUSER [ 'id' ]))
2022-09-05 01:46:38 +08:00
) {
2020-12-26 01:42:23 +08:00
print ( " <td class= \" rowfollow \" align= \" center \" ><i> " . $lang_functions [ 'text_anonymous' ] . " </i><br /> " . ( isset ( $row [ " owner " ]) ? " ( " . get_username ( $row [ " owner " ]) . " ) " : " <i> " . $lang_functions [ 'text_orphaned' ] . " </i> " ) . " </td> \n " );
}
elseif ( $row [ " anonymous " ] == " yes " )
{
print ( " <td class= \" rowfollow \" ><i> " . $lang_functions [ 'text_anonymous' ] . " </i></td> \n " );
}
else
{
print ( " <td class= \" rowfollow \" > " . ( isset ( $row [ " owner " ]) ? get_username ( $row [ " owner " ]) : " <i> " . $lang_functions [ 'text_orphaned' ] . " </i> " ) . " </td> \n " );
}
2022-08-20 19:11:28 +08:00
if ( user_can ( 'torrentmanage' ))
2020-12-26 01:42:23 +08:00
{
2024-03-03 00:49:18 +08:00
if ( user_can ( 'torrent-delete' )) {
print ( " <td class= \" rowfollow \" ><a href= \" " . htmlspecialchars ( " fastdelete.php?id= " . $row [ 'id' ]) . " \" ><img class= \" staff_delete \" src= \" pic/trans.gif \" alt= \" D \" title= \" " . $lang_functions [ 'text_delete' ] . " \" /></a> " );
}
2020-12-26 01:42:23 +08:00
print ( " <br /><a href= \" edit.php?returnto= " . rawurlencode ( $_SERVER [ " REQUEST_URI " ]) . " &id= " . $row [ " id " ] . " \" ><img class= \" staff_edit \" src= \" pic/trans.gif \" alt= \" E \" title= \" " . $lang_functions [ 'text_edit' ] . " \" /></a></td> \n " );
}
print ( " </tr> \n " );
$counter ++ ;
}
print ( " </table> " );
if ( $CURUSER [ 'appendpromotion' ] == 'highlight' )
print ( " <p align= \" center \" > " . $lang_functions [ 'text_promoted_torrents_note' ] . " </p> \n " );
if ( $enabletooltip_tweak == 'yes' && ( ! isset ( $CURUSER ) || $CURUSER [ 'showlastcom' ] == 'yes' ))
create_tooltip_container ( $lastcom_tooltip , 400 );
create_tooltip_container ( $torrent_tooltip , 500 );
}
function get_username ( $id , $big = false , $link = true , $bold = true , $target = false , $bracket = false , $withtitle = false , $link_ext = " " , $underline = false )
{
static $usernameArray = array ();
2020-12-29 21:49:37 +08:00
$id = ( int ) $id ;
2020-12-26 01:42:23 +08:00
2020-12-28 20:52:54 +08:00
if ( func_num_args () == 1 && isset ( $usernameArray [ $id ])) { //One argument=is default display of username. Get it directly from static array if available
2020-12-26 01:42:23 +08:00
return $usernameArray [ $id ];
}
$arr = get_user_row ( $id );
if ( $arr ){
if ( $big )
{
$donorpic = " starbig " ;
$leechwarnpic = " leechwarnedbig " ;
$warnedpic = " warnedbig " ;
$disabledpic = " disabledbig " ;
2022-08-11 18:49:37 +08:00
$marginLeft = '4pt' ;
$medalSize = '16px' ;
2022-08-25 01:39:47 +08:00
$medalClass = 'nexus-username-medal-big' ;
2022-08-11 18:49:37 +08:00
$style = " style='margin-left: $marginLeft ' " ;
2020-12-26 01:42:23 +08:00
}
else
{
$donorpic = " star " ;
$leechwarnpic = " leechwarned " ;
$warnedpic = " warned " ;
$disabledpic = " disabled " ;
2022-08-11 18:49:37 +08:00
$marginLeft = '2pt' ;
$medalSize = '11px' ;
2022-08-25 01:39:47 +08:00
$medalClass = 'nexus-username-medal' ;
2022-08-11 18:49:37 +08:00
$style = " style='margin-left: $marginLeft ' " ;
2020-12-26 01:42:23 +08:00
}
2022-08-10 17:38:05 +08:00
$pics = $arr [ " donor " ] == " yes " && ( $arr [ 'donoruntil' ] === null || $arr [ 'donoruntil' ] < '1970' || $arr [ 'donoruntil' ] >= date ( 'Y-m-d H:i:s' )) ? " <img class= \" " . $donorpic . " \" src= \" /pic/trans.gif \" alt= \" Donor \" " . $style . " /> " : " " ;
2020-12-26 01:42:23 +08:00
if ( $arr [ " enabled " ] == " yes " )
2022-08-10 17:38:05 +08:00
$pics .= ( $arr [ " leechwarn " ] == " yes " ? " <img class= \" " . $leechwarnpic . " \" src= \" /pic/trans.gif \" alt= \" Leechwarned \" " . $style . " /> " : " " ) . ( $arr [ " warned " ] == " yes " ? " <img class= \" " . $warnedpic . " \" src= \" /pic/trans.gif \" alt= \" Warned \" " . $style . " /> " : " " );
2020-12-26 01:42:23 +08:00
else
2022-08-10 17:38:05 +08:00
$pics .= " <img class= \" " . $disabledpic . " \" src= \" /pic/trans.gif \" alt= \" Disabled \" " . $style . " /> \n " ;
//Rainbow effect
$username = $arr [ 'username' ];
$rainbow = " " ;
$hasSetRainbow = false ;
if ( isset ( $arr [ '__is_rainbow' ]) && $arr [ '__is_rainbow' ]) {
$rainbow = ' class="rainbow"' ;
}
if ( $underline ) {
$hasSetRainbow = true ;
$username = " <u { $rainbow } > { $username } </u> " ;
}
if ( $bold ) {
if ( $hasSetRainbow ) {
$username = " <b> { $username } </b> " ;
} else {
2022-08-11 17:12:36 +08:00
$hasSetRainbow = true ;
2022-08-10 17:38:05 +08:00
$username = " <b { $rainbow } > { $username } </b> " ;
}
}
// $username = ($underline == true ? "<u>" . $arr['username'] . "</u>" : $arr['username']);
// $username = ($bold == true ? "<b>" . $username . "</b>" : $username);
//medal
$medalHtml = '' ;
2022-08-25 02:05:34 +08:00
foreach ( $arr [ 'wearing_medals' ] ? ? [] as $medal ) {
2022-08-11 18:49:37 +08:00
$medalHtml .= sprintf (
2022-08-25 01:39:47 +08:00
'<img src="%s" title="%s" class="%s preview" style="max-height: %s;max-width: %s;margin-left: %s"/>' ,
$medal [ 'image_large' ], $medal [ 'name' ], $medalClass , $medalSize , $medalSize , $marginLeft
2022-08-11 18:49:37 +08:00
);
2022-08-10 17:38:05 +08:00
}
2020-12-26 01:42:23 +08:00
2022-06-12 15:15:09 +08:00
$href = getSchemeAndHttpHost () . " /userdetails.php?id= $id " ;
2023-02-09 18:14:51 +08:00
$username = ( $link == true ? " <a " . $link_ext . " href= \" " . $href . " \" " . ( $target == true ? " target= \" _blank \" " : " " ) . " class=' " . get_user_class_name ( $arr [ 'class' ], true , false , false ) . " _Name'> " . $username . " </a> " : $username ) . $pics . ( $withtitle == true ? " ( " . ( $arr [ 'title' ] == " " ? get_user_class_name ( $arr [ 'class' ], false , true , true , [ 'with_alias' => true ]) : " <span class=' " . get_user_class_name ( $arr [ 'class' ], true , false , false ) . " _Name'><b> " . htmlspecialchars ( $arr [ 'title' ])) . " </b></span>) " : " " );
2020-12-26 01:42:23 +08:00
2022-08-11 03:57:53 +08:00
$username = " <span class= \" nowrap \" > " . ( $bracket == true ? " ( " . $username . " ) " : $username ) . " $medalHtml </span> " ;
2020-12-26 01:42:23 +08:00
}
else
{
2022-10-06 18:34:33 +08:00
$username = " <i> " . nexus_trans ( 'nexus.user_not_exists' ) . " </i> " ;
2020-12-26 01:42:23 +08:00
$username = " <span class= \" nowrap \" > " . ( $bracket == true ? " ( " . $username . " ) " : $username ) . " </span> " ;
}
if ( func_num_args () == 1 ) { //One argument=is default display of username, save it in static array
$usernameArray [ $id ] = $username ;
}
return $username ;
}
function get_percent_completed_image ( $p ) {
$maxpx = " 45 " ; // Maximum amount of pixels for the progress bar
if ( $p == 0 ) $progress = " <img class= \" progbarrest \" src= \" pic/trans.gif \" style= \" width: " . ( $maxpx ) . " px; \" alt= \" \" /> " ;
if ( $p == 100 ) $progress = " <img class= \" progbargreen \" src= \" pic/trans.gif \" style= \" width: " . ( $maxpx ) . " px; \" alt= \" \" /> " ;
if ( $p >= 1 && $p <= 30 ) $progress = " <img class= \" progbarred \" src= \" pic/trans.gif \" style= \" width: " . ( $p * ( $maxpx / 100 )) . " px; \" alt= \" \" /><img class= \" progbarrest \" src= \" pic/trans.gif \" style= \" width: " . (( 100 - $p ) * ( $maxpx / 100 )) . " px; \" alt= \" \" /> " ;
if ( $p >= 31 && $p <= 65 ) $progress = " <img class= \" progbaryellow \" src= \" pic/trans.gif \" style= \" width: " . ( $p * ( $maxpx / 100 )) . " px; \" alt= \" \" /><img class= \" progbarrest \" src= \" pic/trans.gif \" style= \" width: " . (( 100 - $p ) * ( $maxpx / 100 )) . " px; \" alt= \" \" /> " ;
if ( $p >= 66 && $p <= 99 ) $progress = " <img class= \" progbargreen \" src= \" pic/trans.gif \" style= \" width: " . ( $p * ( $maxpx / 100 )) . " px; \" alt= \" \" /><img class= \" progbarrest \" src= \" pic/trans.gif \" style= \" width: " . (( 100 - $p ) * ( $maxpx / 100 )) . " px; \" alt= \" \" /> " ;
return " <img class= \" bar_left \" src= \" pic/trans.gif \" alt= \" \" /> " . $progress . " <img class= \" bar_right \" src= \" pic/trans.gif \" alt= \" \" /> " ;
}
function get_ratio_img ( $ratio )
{
if ( $ratio >= 16 )
$s = " 163 " ;
else if ( $ratio >= 8 )
$s = " 117 " ;
else if ( $ratio >= 4 )
$s = " 5 " ;
else if ( $ratio >= 2 )
$s = " 3 " ;
else if ( $ratio >= 1 )
$s = " 2 " ;
else if ( $ratio >= 0.5 )
$s = " 34 " ;
else if ( $ratio >= 0.25 )
$s = " 10 " ;
else
$s = " 52 " ;
return " <img src= \" pic/smilies/ " . $s . " .gif \" alt= \" \" /> " ;
}
function GetVar ( $name ) {
if ( is_array ( $name ) ) {
foreach ( $name as $var ) GetVar ( $var );
} else {
if ( ! isset ( $_REQUEST [ $name ]) )
return false ;
$GLOBALS [ $name ] = $_REQUEST [ $name ];
return $GLOBALS [ $name ];
}
}
function ssr ( $arg ) {
if ( is_array ( $arg )) {
foreach ( $arg as $key => $arg_bit ) {
$arg [ $key ] = ssr ( $arg_bit );
}
} else {
$arg = stripslashes ( $arg );
}
return $arg ;
}
function parked ()
{
global $lang_functions ;
global $CURUSER ;
if ( $CURUSER [ " parked " ] == " yes " )
stderr ( $lang_functions [ 'std_access_denied' ], $lang_functions [ 'std_your_account_parked' ]);
}
function validusername ( $username )
{
if ( $username == " " )
return false ;
// The following characters are allowed in user names
$allowedchars = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 " ;
2022-08-10 17:38:05 +08:00
$length = strlen ( $username );
for ( $i = 0 ; $i < $length ; ++ $i )
2020-12-26 01:42:23 +08:00
if ( strpos ( $allowedchars , $username [ $i ]) === false )
return false ;
2022-12-08 20:43:33 +08:00
if ( $length < 3 || $length > 20 ) {
2022-08-10 17:38:05 +08:00
return false ;
}
2020-12-26 01:42:23 +08:00
return true ;
}
//Code for Viewing NFO file
// code: Takes a string and does a IBM-437-to-HTML-Unicode-Entities-conversion.
// swedishmagic specifies special behavior for Swedish characters.
// Some Swedish Latin-1 letters collide with popular DOS glyphs. If these
// characters are between ASCII-characters (a-zA-Z and more) they are
// treated like the Swedish letters, otherwise like the DOS glyphs.
2022-09-27 22:06:05 +08:00
function code ( $ibm_437 , $view ) {
$swedishmagic = false ;
if ( $view == " magic " ) {
$swedishmagic = true ;
}
2020-12-26 01:42:23 +08:00
$table437 = array ( " \200 " , " \201 " , " \202 " , " \203 " , " \204 " , " \205 " , " \206 " , " \207 " ,
" \210 " , " \211 " , " \212 " , " \213 " , " \214 " , " \215 " , " \216 " , " \217 " , " \220 " ,
" \221 " , " \222 " , " \223 " , " \224 " , " \225 " , " \226 " , " \227 " , " \230 " , " \231 " ,
" \232 " , " \233 " , " \234 " , " \235 " , " \236 " , " \237 " , " \240 " , " \241 " , " \242 " ,
" \243 " , " \244 " , " \245 " , " \246 " , " \247 " , " \250 " , " \251 " , " \252 " , " \253 " ,
" \254 " , " \255 " , " \256 " , " \257 " , " \260 " , " \261 " , " \262 " , " \263 " , " \264 " ,
" \265 " , " \266 " , " \267 " , " \270 " , " \271 " , " \272 " , " \273 " , " \274 " , " \275 " ,
" \276 " , " \277 " , " \300 " , " \301 " , " \302 " , " \303 " , " \304 " , " \305 " , " \306 " ,
" \307 " , " \310 " , " \311 " , " \312 " , " \313 " , " \314 " , " \315 " , " \316 " , " \317 " ,
" \320 " , " \321 " , " \322 " , " \323 " , " \324 " , " \325 " , " \326 " , " \327 " , " \330 " ,
" \331 " , " \332 " , " \333 " , " \334 " , " \335 " , " \336 " , " \337 " , " \340 " , " \341 " ,
" \342 " , " \343 " , " \344 " , " \345 " , " \346 " , " \347 " , " \350 " , " \351 " , " \352 " ,
" \353 " , " \354 " , " \355 " , " \356 " , " \357 " , " \360 " , " \361 " , " \362 " , " \363 " ,
" \364 " , " \365 " , " \366 " , " \367 " , " \370 " , " \371 " , " \372 " , " \373 " , " \374 " ,
" \375 " , " \376 " , " \377 " );
$tablehtml = array ( " Ç " , " ü " , " é " , " â " , " ä " ,
" à " , " å " , " ç " , " ê " , " ë " , " è " ,
" ï " , " î " , " ì " , " Ä " , " Å " , " É " ,
" æ " , " Æ " , " ô " , " ö " , " ò " , " û " ,
" ù " , " ÿ " , " Ö " , " Ü " , " ¢ " , " £ " ,
" ¥ " , " ₧ " , " ƒ " , " á " , " í " , " ó " ,
" ú " , " ñ " , " Ñ " , " ª " , " º " , " ¿ " ,
" ⌐ " , " ¬ " , " ½ " , " ¼ " , " ¡ " , " « " ,
" » " , " ░ " , " ▒ " , " ▓ " , " │ " , " ┤ " ,
" ╡ " , " ╢ " , " ╖ " , " ╕ " , " ╣ " , " ║ " ,
" ╗ " , " ╝ " , " ╜ " , " ╛ " , " ┐ " , " └ " ,
" ┴ " , " ┬ " , " ├ " , " ─ " , " ┼ " , " ╞ " ,
" ╟ " , " ╚ " , " ╔ " , " ╩ " , " ╦ " , " ╠ " ,
" ═ " , " ╬ " , " ╧ " , " ╨ " , " ╤ " , " ╥ " ,
" ╙ " , " ╘ " , " ╒ " , " ╓ " , " ╫ " , " ╪ " ,
" ┘ " , " ┌ " , " █ " , " ▄ " , " ▌ " , " ▐ " ,
" ▀ " , " α " , " ß " , " Γ " , " π " , " Σ " ,
" σ " , " μ " , " τ " , " Φ " , " Θ " , " Ω " ,
" δ " , " ∞ " , " φ " , " ε " , " ∩ " , " ≡ " ,
" ± " , " ≥ " , " ≤ " , " ⌠ " , " ⌡ " , " ÷ " ,
" ≈ " , " ° " , " ∙ " , " · " , " √ " , " ⁿ " ,
" ² " , " ■ " , "   " );
$s = htmlspecialchars ( $ibm_437 );
// 0-9, 11-12, 14-31, 127 (decimalt)
$control =
array ( " \000 " , " \001 " , " \002 " , " \003 " , " \004 " , " \005 " , " \006 " , " \007 " ,
" \010 " , " \011 " , /*"\012",*/ " \013 " , " \014 " , /*"\015",*/ " \016 " , " \017 " ,
" \020 " , " \021 " , " \022 " , " \023 " , " \024 " , " \025 " , " \026 " , " \027 " ,
" \030 " , " \031 " , " \032 " , " \033 " , " \034 " , " \035 " , " \036 " , " \037 " ,
" \177 " );
/* Code control characters to control pictures .
http :// www . unicode . org / charts / PDF / U2400 . pdf
( This is somewhat the Right Thing , but looks crappy with Courier New . )
$controlpict = array ( " ␣ " , " ␄ " );
$s = str_replace ( $control , $controlpict , $s ); */
// replace control chars with space - feel free to fix the regexp smile.gif
/* echo " [a \\ x00- \\ x1F] " ;
//$s = preg_replace("/[ \\x00-\\x1F]/", " ", $s);
$s = preg_replace ( " /[ \000 - \037 ]/ " , " " , $s ); */
$s = str_replace ( $control , " " , $s );
if ( $swedishmagic ){
$s = str_replace ( " \345 " , " \206 " , $s );
$s = str_replace ( " \344 " , " \204 " , $s );
$s = str_replace ( " \366 " , " \224 " , $s );
// $s = str_replace("\304","\216",$s);
//$s = "[ -~]\\xC4[a-za-z]";
// couldn't get ^ and $ to work, even through I read the man-pages,
// i'm probably too tired and too unfamiliar with posix regexps right now.
$s = preg_replace ( " /([ -~]) \305 ([ -~])/ " , " \\ 1 \217 \\ 2 " , $s );
$s = preg_replace ( " /([ -~]) \304 ([ -~])/ " , " \\ 1 \216 \\ 2 " , $s );
$s = preg_replace ( " /([ -~]) \326 ([ -~])/ " , " \\ 1 \231 \\ 2 " , $s );
$s = str_replace ( " \311 " , " \220 " , $s ); //
$s = str_replace ( " \351 " , " \202 " , $s ); //
}
$s = str_replace ( $table437 , $tablehtml , $s );
return $s ;
}
2022-10-01 19:54:19 +08:00
/**
* @ param $ibm_437
* @ param $view
* @ return array | string | string []
* @ ref https :// github . com / HDInnovations / UNIT3D - Community - Edition / blob / master / app / Helpers / Nfo . php
*/
function code_new ( $ibm_437 , $view )
{
$swedishmagic = false ;
if ( $view == " magic " ) {
$swedishmagic = true ;
}
$cf = array ( 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 8962 , 199 , 252 , 233 , 226 , 228 , 224 , 229 , 231 , 234 , 235 , 232 , 239 , 238 , 236 , 196 , 197 , 201 , 230 , 198 , 244 , 246 , 242 , 251 , 249 , 255 , 214 , 220 , 162 , 163 , 165 , 8359 , 402 , 225 , 237 , 243 , 250 , 241 , 209 , 170 , 186 , 191 , 8976 , 172 , 189 , 188 , 161 , 171 , 187 , 9617 , 9618 , 9619 , 9474 , 9508 , 9569 , 9570 , 9558 , 9557 , 9571 , 9553 , 9559 , 9565 , 9564 , 9563 , 9488 , 9492 , 9524 , 9516 , 9500 , 9472 , 9532 , 9566 , 9567 , 9562 , 9556 , 9577 , 9574 , 9568 , 9552 , 9580 , 9575 , 9576 , 9572 , 9573 , 9561 , 9560 , 9554 , 9555 , 9579 , 9578 , 9496 , 9484 , 9608 , 9604 , 9612 , 9616 , 9600 , 945 , 223 , 915 , 960 , 931 , 963 , 181 , 964 , 934 , 920 , 937 , 948 , 8734 , 966 , 949 , 8745 , 8801 , 177 , 8805 , 8804 , 8992 , 8993 , 247 , 8776 , 176 , 8729 , 183 , 8730 , 8319 , 178 , 9632 , 160 );
$s = " " ;
for ( $c = 0 ; $c < strlen ( $ibm_437 ); $c ++ ) { // cyctle through the whole file doing a byte at a time.
$byte = $ibm_437 [ $c ];
$ob = ord ( $byte );
if ( $ob >= 127 ) { // is it in the normal ascii range
$s .= '&#' . $cf [ $ob ] . ';' ;
} else {
$s .= $byte ;
}
}
if ( $swedishmagic ) {
$s = str_replace ( " \345 " , " \206 " , $s );
$s = str_replace ( " \344 " , " \204 " , $s );
$s = str_replace ( " \366 " , " \224 " , $s );
$s = preg_replace ( " /([ -~]) \305 ([ -~])/ " , " \\ 1 \217 \\ 2 " , $s );
$s = preg_replace ( " /([ -~]) \304 ([ -~])/ " , " \\ 1 \216 \\ 2 " , $s );
$s = preg_replace ( " /([ -~]) \326 ([ -~])/ " , " \\ 1 \231 \\ 2 " , $s );
$s = str_replace ( " \311 " , " \220 " , $s ); //
$s = str_replace ( " \351 " , " \202 " , $s ); //
}
return $s ;
}
2020-12-26 01:42:23 +08:00
//Tooltip container for hot movie, classic movie, etc
function create_tooltip_container ( $id_content_arr , $width = 400 )
{
if ( count ( $id_content_arr ))
{
2022-04-04 17:26:26 +08:00
$result = " <div style= \" display: none \" > " ;
2020-12-26 01:42:23 +08:00
foreach ( $id_content_arr as $id_content_arr_each )
{
$result .= " <div id= \" " . $id_content_arr_each [ 'id' ] . " \" > " . $id_content_arr_each [ 'content' ] . " </div> " ;
}
$result .= " </div> " ;
print ( $result );
}
}
function getimdb ( $imdb_id , $cache_stamp , $mode = 'minor' )
{
global $lang_functions ;
global $showextinfo ;
$thenumbers = $imdb_id ;
2022-04-04 17:26:26 +08:00
$imdb = new Nexus\Imdb\Imdb ();
$movie = $imdb -> getMovie ( $imdb_id );
2020-12-26 01:42:23 +08:00
$movieid = $thenumbers ;
2022-04-04 17:26:26 +08:00
// $movie->setid ($movieid);
2020-12-26 01:42:23 +08:00
$target = array ( 'Title' , 'Credits' , 'Plot' );
2022-04-04 17:26:26 +08:00
switch ( $imdb -> getCacheStatus ( $imdb_id ))
2020-12-26 01:42:23 +08:00
{
case " 0 " : //cache is not ready
{
return false ;
break ;
}
case " 1 " : //normal
{
$title = $movie -> title ();
$year = $movie -> year ();
$country = $movie -> country ();
$countries = " " ;
$temp = " " ;
for ( $i = 0 ; $i < count ( $country ); $i ++ )
{
$temp .= " $country[$i] , " ;
}
$countries = rtrim ( trim ( $temp ), " , " );
$director = $movie -> director ();
$director_or_creator = " " ;
if ( $director )
{
$temp = " " ;
for ( $i = 0 ; $i < count ( $director ); $i ++ )
{
$temp .= $director [ $i ][ " name " ] . " , " ;
}
$director_or_creator = " <strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_director' ] . " : </font></strong> " . rtrim ( trim ( $temp ), " , " );
}
else { //for tv series
$creator = $movie -> creator ();
$director_or_creator = " <strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_creator' ] . " : </font></strong> " . $creator ;
}
$cast = $movie -> cast ();
$temp = " " ;
for ( $i = 0 ; $i < count ( $cast ); $i ++ ) //get names of first three casts
{
if ( $i > 2 )
{
break ;
}
$temp .= $cast [ $i ][ " name " ] . " , " ;
}
$casts = rtrim ( trim ( $temp ), " , " );
$gen = $movie -> genres ();
$genres = $gen [ 0 ] . ( count ( $gen ) > 1 ? " , " . $gen [ 1 ] : " " ); //get first two genres;
$rating = $movie -> rating ();
$votes = $movie -> votes ();
if ( $votes )
$imdbrating = " <b> " . $rating . " </b>/10 ( " . $votes . $lang_functions [ 'text_votes' ] . " ) " ;
else $imdbrating = $lang_functions [ 'text_awaiting_five_votes' ];
$tagline = $movie -> tagline ();
switch ( $mode )
{
2021-04-22 03:24:59 +08:00
case 'minor' :
2020-12-26 01:42:23 +08:00
{
$autodata = " <font class= \" big \" ><b> " . $title . " </b></font> ( " . $year . " ) <br /><strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_imdb' ] . " : </font></strong> " . $imdbrating . " <strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_country' ] . " : </font></strong> " . $countries . " <strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_genres' ] . " : </font></strong> " . $genres . " <br /> " . $director_or_creator . " <strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_starring' ] . " : </font></strong> " . $casts . " <br /><p><strong> " . $tagline . " </strong></p> " ;
break ;
}
case 'median' :
{
2022-04-04 17:26:26 +08:00
if (( $photo_url = $movie -> photo () ) != FALSE )
2020-12-26 01:42:23 +08:00
$smallth = " <img src= \" " . $photo_url . " \" width= \" 105 \" alt= \" poster \" /> " ;
else $smallth = " " ;
$runtime = $movie -> runtime ();
$language = $movie -> language ();
$plot = $movie -> plot ();
$plots = " " ;
if ( count ( $plot ) != 0 ){ //get plots from plot page
$plots .= " <font color= \" DarkRed \" >*</font> " . strip_tags ( $plot [ 0 ], '<br /><i>' );
$plots = mb_substr ( $plots , 0 , 300 , " UTF-8 " ) . ( mb_strlen ( $plots , " UTF-8 " ) > 300 ? " ... " : " " );
$plots .= ( strpos ( $plots , " <i> " ) == true && strpos ( $plots , " </i> " ) == false ? " </i> " : " " ); //sometimes <i> is open and not ended because of mb_substr;
$plots = " <font class= \" small \" > " . $plots . " </font> " ;
}
elseif ( $plotoutline = $movie -> plotoutline ()){ //get plot from title page
$plots .= " <font color= \" DarkRed \" >*</font> " . strip_tags ( $plotoutline , '<br /><i>' );
$plots = mb_substr ( $plots , 0 , 300 , " UTF-8 " ) . ( mb_strlen ( $plots , " UTF-8 " ) > 300 ? " ... " : " " );
$plots .= ( strpos ( $plots , " <i> " ) == true && strpos ( $plots , " </i> " ) == false ? " </i> " : " " ); //sometimes <i> is open and not ended because of mb_substr;
$plots = " <font class= \" small \" > " . $plots . " </font> " ;
}
$autodata = " <table style= \" background-color: transparent; \" border= \" 0 \" cellspacing= \" 0 \" cellpadding= \" 3 \" >
" .( $smallth ? " < td class = \ " clear \" valign= \" top \" align= \" right \" >
$smallth
</ td > " : " " )
. " <td class= \" clear \" valign= \" top \" align= \" left \" >
< table style = \ " background-color: transparent; \" border= \" 0 \" cellspacing= \" 0 \" cellpadding= \" 3 \" width= \" 350 \" >
< tr >< td class = \ " clear \" colspan= \" 2 \" ><img class= \" imdb \" src= \" pic/trans.gif \" alt= \" imdb \" /> <font class= \" big \" ><b> " . $title . " </b></font> ( " . $year . " ) </td></tr>
< tr >< td class = \ " clear \" ><strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_imdb' ] . " : </font></strong> " . $imdbrating . " </td>
" .( $runtime ? " < td class = \ " clear \" ><strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_runtime' ] . " : </font></strong> " . $runtime . $lang_functions [ 'text_min' ] . " </td> " : " <td class= \" clear \" ></td> " ) . " </tr>
< tr >< td class = \ " clear \" ><strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_country' ] . " : </font></strong> " . $countries . " </td>
" .( $language ? " < td class = \ " clear \" ><strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_language' ] . " : </font></strong> " . $language . " </td> " : " <td class= \" clear \" ></td> " ) . " </tr>
< tr >< td class = \ " clear \" > " . $director_or_creator . " </td>
< td class = \ " clear \" ><strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_genres' ] . " : </font></strong> " . $genres . " </td></tr>
< tr >< td class = \ " clear \" colspan= \" 2 \" ><strong><font color= \" DarkRed \" > " . $lang_functions [ 'text_starring' ] . " : </font></strong> " . $casts . " </td></tr>
" .( $plots ? " < tr >< td class = \ " clear \" colspan= \" 2 \" > " . $plots . " </td></tr> " : " " ) . "
</ table >
</ td >
</ table > " ;
break ;
}
}
return $autodata ;
}
2021-04-22 03:24:59 +08:00
case " 2 " :
2020-12-26 01:42:23 +08:00
{
return false ;
break ;
}
case " 3 " :
{
return false ;
break ;
}
}
}
function quickreply ( $formname , $taname , $submit ){
print ( " <textarea name=' " . $taname . " ' cols= \" 100 \" rows= \" 8 \" style= \" width: 450px \" onkeydown= \" ctrlenter(event,'compose','qr') \" ></textarea> " );
print ( smile_row ( $formname , $taname ));
print ( " <br /> " );
print ( " <input type= \" submit \" id= \" qr \" class= \" btn \" value= \" " . $submit . " \" /> " );
}
function smile_row ( $formname , $taname ){
$quickSmilesNumbers = array ( 4 , 5 , 39 , 25 , 11 , 8 , 10 , 15 , 27 , 57 , 42 , 122 , 52 , 28 , 29 , 30 , 176 );
$smilerow = " <div align= \" center \" > " ;
foreach ( $quickSmilesNumbers as $smilyNumber ) {
$smilerow .= getSmileIt ( $formname , $taname , $smilyNumber );
}
$smilerow .= " </div> " ;
return $smilerow ;
}
function getSmileIt ( $formname , $taname , $smilyNumber ) {
return " <a href= \" javascript: SmileIT('[em $smilyNumber ]',' " . $formname . " ',' " . $taname . " ') \" onmouseover= \" domTT_activate(this, event, 'content', ' " . htmlspecialchars ( " <table><tr><td><img src= \ 'pic/smilies/ $smilyNumber .gif \ ' alt= \ ' \ ' /></td></tr></table> " ) . " ', 'trail', false, 'delay', 0,'lifetime',10000,'styleClass','smilies','maxWidth', 400); \" ><img style= \" max-width: 25px; \" src= \" pic/smilies/ $smilyNumber .gif \" alt= \" \" /></a> " ;
}
2023-01-07 19:34:59 +08:00
function classlist ( $selectname , $maxclass , $selected , $minClass = 0 , $includeNoClass = false , $disabled = false ){
2022-08-20 19:11:28 +08:00
global $lang_functions ;
2023-01-07 19:34:59 +08:00
$disabledText = '' ;
if ( $disabled ) {
$disabledText = ' disabled = "disabled"' ;
}
$list = " <select name= \" " . $selectname . " \" $disabledText > " ;
2022-08-20 19:11:28 +08:00
if ( $includeNoClass ) {
$list .= sprintf ( '<option value="%s">%s</option>' , \App\Models\Setting :: PERMISSION_NO_CLASS , $lang_functions [ 'select_an_user_class' ]);
}
2020-12-26 01:42:23 +08:00
for ( $i = $minClass ; $i <= $maxclass ; $i ++ )
$list .= " <option value= \" " . $i . " \" " . ( $selected == $i ? " selected= \" selected \" " : " " ) . " > " . get_user_class_name ( $i , false , false , true ) . " </option> \n " ;
$list .= " </select> " ;
return $list ;
}
2022-06-13 15:52:23 +08:00
function permissiondenied ( $allowMinimumClass = null ){
2020-12-26 01:42:23 +08:00
global $lang_functions ;
2022-06-13 15:52:23 +08:00
if ( $allowMinimumClass === null ) {
stderr ( $lang_functions [ 'std_error' ], $lang_functions [ 'std_permission_denied' ]);
} else {
stderr ( $lang_functions [ 'std_sorry' ], $lang_functions [ 'std_permission_denied_only' ] . get_user_class_name ( $allowMinimumClass , false , true , true ) . $lang_functions [ 'std_or_above_can_view' ], false );
}
2020-12-26 01:42:23 +08:00
}
function gettime ( $time , $withago = true , $twoline = false , $forceago = false , $oneunit = false , $isfuturetime = false ){
global $lang_functions , $CURUSER ;
2022-05-06 17:42:18 +08:00
if ( isset ( $CURUSER ) && $CURUSER [ 'timetype' ] != 'timealive' && ! $forceago ){
2020-12-26 01:42:23 +08:00
$newtime = $time ;
if ( $twoline ){
$newtime = str_replace ( " " , " <br /> " , $newtime );
}
}
else {
$timestamp = strtotime ( $time );
if ( $isfuturetime && $timestamp < TIMENOW )
$newtime = false ;
else
{
$newtime = get_elapsed_time ( $timestamp , $oneunit ) . ( $withago ? $lang_functions [ 'text_ago' ] : " " );
if ( $twoline ){
$newtime = str_replace ( " " , " <br /> " , $newtime );
}
elseif ( $oneunit ){
if ( $length = strpos ( $newtime , " " ))
$newtime = substr ( $newtime , 0 , $length );
}
else $newtime = str_replace ( " " , $lang_functions [ 'text_space' ], $newtime );
$newtime = " <span title= \" " . $time . " \" > " . $newtime . " </span> " ;
}
}
return $newtime ;
}
function get_forum_pic_folder (){
global $CURLANGDIR ;
return " pic/forum_pic/ " . $CURLANGDIR ;
}
function get_category_icon_row ( $typeid )
{
global $Cache ;
static $rows ;
if ( ! $typeid ) {
$typeid = 1 ;
}
if ( ! $rows && ! $rows = $Cache -> get_value ( 'category_icon_content' )){
$rows = array ();
$res = sql_query ( " SELECT * FROM caticons ORDER BY id ASC " );
while ( $row = mysql_fetch_array ( $res )) {
$rows [ $row [ 'id' ]] = $row ;
}
$Cache -> cache_value ( 'category_icon_content' , $rows , 156400 );
}
return $rows [ $typeid ];
}
function get_category_row ( $catid = NULL )
{
global $Cache ;
static $rows ;
2022-06-14 01:07:05 +08:00
if ( ! $rows && ! $rows = $Cache -> get_value ( 'category_content' )){
$rows = [];
2020-12-26 01:42:23 +08:00
$res = sql_query ( " SELECT categories.*, searchbox.name AS catmodename FROM categories LEFT JOIN searchbox ON categories.mode=searchbox.id " );
while ( $row = mysql_fetch_array ( $res )) {
$rows [ $row [ 'id' ]] = $row ;
}
$Cache -> cache_value ( 'category_content' , $rows , 126400 );
}
if ( $catid ) {
return $rows [ $catid ];
} else {
return $rows ;
}
}
2022-03-19 16:47:46 +08:00
function get_second_icon ( $row ) //for CHDBits
2020-12-26 01:42:23 +08:00
{
global $CURUSER , $Cache ;
$source = $row [ 'source' ];
$medium = $row [ 'medium' ];
$codec = $row [ 'codec' ];
$standard = $row [ 'standard' ];
$processing = $row [ 'processing' ];
$team = $row [ 'team' ];
$audiocodec = $row [ 'audiocodec' ];
2022-10-27 20:21:54 +08:00
$mode = $row [ 'search_box_id' ];
2022-03-19 16:47:46 +08:00
$cacheKey = 'secondicon_' . $source . '_' . $medium . '_' . $codec . '_' . $standard . '_' . $processing . '_' . $team . '_' . $audiocodec . '_content' ;
if ( ! $sirow = $Cache -> get_value ( $cacheKey )){
2022-10-27 20:21:54 +08:00
$res = sql_query ( " SELECT * FROM secondicons WHERE (mode = " . sqlesc ( $mode ) . " OR mode = 0) AND (source = " . sqlesc ( $source ) . " OR source=0) AND (medium = " . sqlesc ( $medium ) . " OR medium=0) AND (codec = " . sqlesc ( $codec ) . " OR codec = 0) AND (standard = " . sqlesc ( $standard ) . " OR standard = 0) AND (processing = " . sqlesc ( $processing ) . " OR processing = 0) AND (team = " . sqlesc ( $team ) . " OR team = 0) AND (audiocodec = " . sqlesc ( $audiocodec ) . " OR audiocodec = 0) LIMIT 1 " );
2020-12-26 01:42:23 +08:00
$sirow = mysql_fetch_array ( $res );
if ( ! $sirow )
$sirow = 'not allowed' ;
2022-03-19 16:47:46 +08:00
$Cache -> cache_value ( $cacheKey , $sirow , 600 );
2020-12-26 01:42:23 +08:00
}
$catimgurl = get_cat_folder ( $row [ 'category' ]);
if ( $sirow == 'not allowed' )
2022-03-19 16:47:46 +08:00
return " <img src= \" pic/cattrans.gif \" style= \" background-image: url(pic/ " . $catimgurl . " /additional/notallowed.png); \" title= \" Not Allowed \" alt= \" Not Allowed \" /> " ;
2020-12-26 01:42:23 +08:00
else {
2022-03-19 16:47:46 +08:00
return " <img " . ( $sirow [ 'class_name' ] ? " class= \" " . $sirow [ 'class_name' ] . " \" " : " " ) . " src= \" pic/cattrans.gif \" style= \" background-image: url(pic/ " . $catimgurl . " /additional/ " . $sirow [ 'image' ] . " ); \" alt= \" " . $sirow [ " name " ] . " \" title= \" " . $sirow [ 'name' ] . " \" /> " ;
2020-12-26 01:42:23 +08:00
}
}
2022-08-10 17:38:05 +08:00
function get_torrent_bg_color ( $promotion = 1 , $posState = " " , array $torrent = [])
2020-12-26 01:42:23 +08:00
{
global $CURUSER ;
2021-06-05 15:50:23 +08:00
$sphighlight = null ;
2020-12-26 01:42:23 +08:00
if ( $CURUSER [ 'appendpromotion' ] == 'highlight' ){
$global_promotion_state = get_global_sp_state ();
if ( $global_promotion_state == 1 ){
if ( $promotion == 1 )
$sphighlight = " " ;
elseif ( $promotion == 2 )
$sphighlight = " class='free_bg' " ;
elseif ( $promotion == 3 )
$sphighlight = " class='twoup_bg' " ;
elseif ( $promotion == 4 )
$sphighlight = " class='twoupfree_bg' " ;
elseif ( $promotion == 5 )
$sphighlight = " class='halfdown_bg' " ;
elseif ( $promotion == 6 )
$sphighlight = " class='twouphalfdown_bg' " ;
elseif ( $promotion == 7 )
$sphighlight = " class='thirtypercentdown_bg' " ;
}
elseif ( $global_promotion_state == 2 )
$sphighlight = " class='free_bg' " ;
elseif ( $global_promotion_state == 3 )
$sphighlight = " class='twoup_bg' " ;
elseif ( $global_promotion_state == 4 )
$sphighlight = " class='twoupfree_bg' " ;
elseif ( $global_promotion_state == 5 )
$sphighlight = " class='halfdown_bg' " ;
elseif ( $global_promotion_state == 6 )
$sphighlight = " class='twouphalfdown_bg' " ;
elseif ( $global_promotion_state == 7 )
$sphighlight = " class='thirtypercentdown_bg' " ;
}
2021-06-05 15:50:23 +08:00
if ( is_null ( $sphighlight )) {
$torrentSettings = get_setting ( 'torrent' );
2021-06-05 16:02:01 +08:00
if ( $posState == \App\Models\Torrent :: POS_STATE_STICKY_FIRST && ! empty ( $torrentSettings [ 'sticky_first_level_background_color' ])) {
2021-06-05 15:50:23 +08:00
$sphighlight = sprintf ( ' style="background-color: %s"' , $torrentSettings [ 'sticky_first_level_background_color' ]);
} elseif ( $posState == \App\Models\Torrent :: POS_STATE_STICKY_SECOND && ! empty ( $torrentSettings [ 'sticky_second_level_background_color' ])) {
$sphighlight = sprintf ( ' style="background-color: %s"' , $torrentSettings [ 'sticky_second_level_background_color' ]);
}
}
2022-08-10 17:38:05 +08:00
return apply_filter ( 'torrent_background_color' , ( string ) $sphighlight , $torrent );
2020-12-26 01:42:23 +08:00
}
2022-06-08 14:15:59 +08:00
function get_torrent_promotion_append ( $promotion = 1 , $forcemode = " " , $showtimeleft = false , $added = " " , $promotionTimeType = 0 , $promotionUntil = '' , $ignoreGlobal = false ){
2020-12-26 01:42:23 +08:00
global $CURUSER , $lang_functions ;
global $expirehalfleech_torrent , $expirefree_torrent , $expiretwoup_torrent , $expiretwoupfree_torrent , $expiretwouphalfleech_torrent , $expirethirtypercentleech_torrent ;
2022-06-08 14:15:59 +08:00
$globalSpState = get_global_sp_state ();
2020-12-26 01:42:23 +08:00
$sp_torrent = " " ;
$onmouseover = " " ;
2021-06-14 12:49:16 +08:00
$log = " [GET_PROMOTION], promotion: $promotion , forcemode: $forcemode , showtimeleft: $showtimeleft , added: $added , promotionTimeType: $promotionTimeType , promotionUntil: $promotionUntil " ;
2022-06-08 14:15:59 +08:00
if ( $ignoreGlobal ) {
$globalSpState = 1 ;
$log .= " , [IGNORE_GLOBAL] " ;
}
$log .= " , globalSpState == " . $globalSpState ;
if ( $globalSpState == 1 ) {
2020-12-26 01:42:23 +08:00
switch ( $promotion ){
case 2 :
{
if ( $showtimeleft && (( $expirefree_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expirefree_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " onmouseover= \" domTT_activate(this, event, 'content', ' " . htmlspecialchars ( " <b><font class= \" free \" > " . $lang_functions [ 'text_free' ] . " </font></b> " . $lang_functions [ 'text_will_end_in' ] . " <b> " . $timeout . " </b> " ) . " ', 'trail', false, 'delay',500,'lifetime',3000,'fade','both','styleClass','niceTitle', 'fadeMax',87, 'maxWidth', 300); \" " ;
else $promotion = 1 ;
}
break ;
}
case 3 :
{
if ( $showtimeleft && (( $expiretwoup_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expiretwoup_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " onmouseover= \" domTT_activate(this, event, 'content', ' " . htmlspecialchars ( " <b><font class= \" twoup \" > " . $lang_functions [ 'text_two_times_up' ] . " </font></b> " . $lang_functions [ 'text_will_end_in' ] . " <b> " . $timeout . " </b> " ) . " ', 'trail', false, 'delay',500,'lifetime',3000,'fade','both','styleClass','niceTitle', 'fadeMax',87, 'maxWidth', 300); \" " ;
else $promotion = 1 ;
}
break ;
}
case 4 :
{
if ( $showtimeleft && (( $expiretwoupfree_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expiretwoupfree_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " onmouseover= \" domTT_activate(this, event, 'content', ' " . htmlspecialchars ( " <b><font class= \" twoupfree \" > " . $lang_functions [ 'text_free_two_times_up' ] . " </font></b> " . $lang_functions [ 'text_will_end_in' ] . " <b> " . $timeout . " </b> " ) . " ', 'trail', false, 'delay',500,'lifetime',3000,'fade','both','styleClass','niceTitle', 'fadeMax',87, 'maxWidth', 300); \" " ;
else $promotion = 1 ;
}
break ;
}
case 5 :
{
if ( $showtimeleft && (( $expirehalfleech_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expirehalfleech_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " onmouseover= \" domTT_activate(this, event, 'content', ' " . htmlspecialchars ( " <b><font class= \" halfdown \" > " . $lang_functions [ 'text_half_down' ] . " </font></b> " . $lang_functions [ 'text_will_end_in' ] . " <b> " . $timeout . " </b> " ) . " ', 'trail', false, 'delay',500,'lifetime',3000,'fade','both','styleClass','niceTitle', 'fadeMax',87, 'maxWidth', 300); \" " ;
else $promotion = 1 ;
}
break ;
}
case 6 :
{
if ( $showtimeleft && (( $expiretwouphalfleech_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expiretwouphalfleech_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " onmouseover= \" domTT_activate(this, event, 'content', ' " . htmlspecialchars ( " <b><font class= \" twouphalfdown \" > " . $lang_functions [ 'text_half_down_two_up' ] . " </font></b> " . $lang_functions [ 'text_will_end_in' ] . " <b> " . $timeout . " </b> " ) . " ', 'trail', false, 'delay',500,'lifetime',3000,'fade','both','styleClass','niceTitle', 'fadeMax',87, 'maxWidth', 300); \" " ;
else $promotion = 1 ;
}
break ;
}
case 7 :
{
if ( $showtimeleft && (( $expirethirtypercentleech_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expirethirtypercentleech_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " onmouseover= \" domTT_activate(this, event, 'content', ' " . htmlspecialchars ( " <b><font class= \" thirtypercent \" > " . $lang_functions [ 'text_thirty_percent_down' ] . " </font></b> " . $lang_functions [ 'text_will_end_in' ] . " <b> " . $timeout . " </b> " ) . " ', 'trail', false, 'delay',500,'lifetime',3000,'fade','both','styleClass','niceTitle', 'fadeMax',87, 'maxWidth', 300); \" " ;
else $promotion = 1 ;
}
break ;
}
}
}
if (( $CURUSER [ 'appendpromotion' ] == 'word' && $forcemode == " " ) || $forcemode == 'word' ){
2021-06-14 12:49:16 +08:00
$log .= " , user appendpromotion = word " ;
2022-06-08 14:15:59 +08:00
if (( $promotion == 2 && $globalSpState == 1 ) || $globalSpState == 2 ){
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 2 " ;
2020-12-26 01:42:23 +08:00
$sp_torrent = " <b>[<font class='free' " . $onmouseover . " > " . $lang_functions [ 'text_free' ] . " </font>]</b> " ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 3 && $globalSpState == 1 ) || $globalSpState == 3 ){
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 3 " ;
2020-12-26 01:42:23 +08:00
$sp_torrent = " <b>[<font class='twoup' " . $onmouseover . " > " . $lang_functions [ 'text_two_times_up' ] . " </font>]</b> " ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 4 && $globalSpState == 1 ) || $globalSpState == 4 ){
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 4 " ;
2020-12-26 01:42:23 +08:00
$sp_torrent = " <b>[<font class='twoupfree' " . $onmouseover . " > " . $lang_functions [ 'text_free_two_times_up' ] . " </font>]</b> " ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 5 && $globalSpState == 1 ) || $globalSpState == 5 ){
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 5 " ;
2020-12-26 01:42:23 +08:00
$sp_torrent = " <b>[<font class='halfdown' " . $onmouseover . " > " . $lang_functions [ 'text_half_down' ] . " </font>]</b> " ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 6 && $globalSpState == 1 ) || $globalSpState == 6 ){
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 6 " ;
2020-12-26 01:42:23 +08:00
$sp_torrent = " <b>[<font class='twouphalfdown' " . $onmouseover . " > " . $lang_functions [ 'text_half_down_two_up' ] . " </font>]</b> " ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 7 && $globalSpState == 1 ) || $globalSpState == 7 ){
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 7 " ;
2020-12-26 01:42:23 +08:00
$sp_torrent = " <b>[<font class='thirtypercent' " . $onmouseover . " > " . $lang_functions [ 'text_thirty_percent_down' ] . " </font>]</b> " ;
}
}
elseif (( $CURUSER [ 'appendpromotion' ] == 'icon' && $forcemode == " " ) || $forcemode == 'icon' ){
2021-06-14 12:49:16 +08:00
$log .= " , user appendpromotion = icon " ;
2022-06-08 14:15:59 +08:00
if (( $promotion == 2 && $globalSpState == 1 ) || $globalSpState == 2 ) {
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 2 " ;
$sp_torrent = " <img class= \" pro_free \" src= \" pic/trans.gif \" alt= \" Free \" " . ( $onmouseover ? $onmouseover : " title= \" " . $lang_functions [ 'text_free' ] . " \" " ) . " /> " ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 3 && $globalSpState == 1 ) || $globalSpState == 3 ) {
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 3 " ;
$sp_torrent = " <img class= \" pro_2up \" src= \" pic/trans.gif \" alt= \" 2X \" " . ( $onmouseover ? $onmouseover : " title= \" " . $lang_functions [ 'text_two_times_up' ] . " \" " ) . " /> " ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 4 && $globalSpState == 1 ) || $globalSpState == 4 ) {
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 4 " ;
$sp_torrent = " <img class= \" pro_free2up \" src= \" pic/trans.gif \" alt= \" 2X Free \" " . ( $onmouseover ? $onmouseover : " title= \" " . $lang_functions [ 'text_free_two_times_up' ] . " \" " ) . " /> " ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 5 && $globalSpState == 1 ) || $globalSpState == 5 ) {
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 5 " ;
$sp_torrent = " <img class= \" pro_50pctdown \" src= \" pic/trans.gif \" alt= \" 50% \" " . ( $onmouseover ? $onmouseover : " title= \" " . $lang_functions [ 'text_half_down' ] . " \" " ) . " /> " ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 6 && $globalSpState == 1 ) || $globalSpState == 6 ) {
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 6 " ;
$sp_torrent = " <img class= \" pro_50pctdown2up \" src= \" pic/trans.gif \" alt= \" 2X 50% \" " . ( $onmouseover ? $onmouseover : " title= \" " . $lang_functions [ 'text_half_down_two_up' ] . " \" " ) . " /> " ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 7 && $globalSpState == 1 ) || $globalSpState == 7 ) {
2021-06-14 12:49:16 +08:00
$log .= " , promotion or global_sp_state = 7 " ;
$sp_torrent = " <img class= \" pro_30pctdown \" src= \" pic/trans.gif \" alt= \" 30% \" " . ( $onmouseover ? $onmouseover : " title= \" " . $lang_functions [ 'text_thirty_percent_down' ] . " \" " ) . " /> " ;
}
2020-12-26 01:42:23 +08:00
}
2021-06-14 12:49:16 +08:00
do_log ( " $log , sp_torrent: $sp_torrent " );
2020-12-26 01:42:23 +08:00
return $sp_torrent ;
}
2022-06-08 14:15:59 +08:00
function get_torrent_promotion_append_sub ( $promotion = 1 , $forcemode = " " , $showtimeleft = false , $added = " " , $promotionTimeType = 0 , $promotionUntil = '' , $ignoreGlobal = false ){
2021-06-23 20:20:34 +08:00
global $CURUSER , $lang_functions ;
global $expirehalfleech_torrent , $expirefree_torrent , $expiretwoup_torrent , $expiretwoupfree_torrent , $expiretwouphalfleech_torrent , $expirethirtypercentleech_torrent ;
2022-06-08 14:15:59 +08:00
$globalSpState = get_global_sp_state ();
2021-06-23 20:20:34 +08:00
$sp_torrent = " " ;
$onmouseover = " " ;
$log = " [GET_PROMOTION], promotion: $promotion , forcemode: $forcemode , showtimeleft: $showtimeleft , added: $added , promotionTimeType: $promotionTimeType , promotionUntil: $promotionUntil " ;
2022-06-08 14:15:59 +08:00
if ( $ignoreGlobal ) {
$globalSpState = 1 ;
$log .= " , [IGNORE_GLOBAL] " ;
}
$log .= " , globalSpState == " . $globalSpState ;
if ( $globalSpState == 1 ) {
2021-06-23 20:20:34 +08:00
switch ( $promotion ){
case 2 :
{
if ( $showtimeleft && (( $expirefree_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expirefree_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " <font color='#0000FF'> " . $lang_functions [ 'text_will_end_in' ] . $timeout . " </font> " ; //free类型字符显示为蓝色, 可以更改它
else $promotion = 1 ;
}
break ;
}
case 3 :
{
if ( $showtimeleft && (( $expiretwoup_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expiretwoup_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " " . $lang_functions [ 'text_will_end_in' ] . $timeout ;
else $promotion = 1 ;
}
break ;
}
case 4 :
{
if ( $showtimeleft && (( $expiretwoupfree_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expiretwoupfree_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " <font color='#00CC66'> " . $lang_functions [ 'text_will_end_in' ] . $timeout . " </font> " ; //2XFree 显示为青色,可以更改它
else $promotion = 1 ;
}
break ;
}
case 5 :
{
if ( $showtimeleft && (( $expirehalfleech_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expirehalfleech_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " " . $lang_functions [ 'text_will_end_in' ] . $timeout ;
else $promotion = 1 ;
}
break ;
}
case 6 :
{
if ( $showtimeleft && (( $expiretwouphalfleech_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expiretwouphalfleech_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " " . $lang_functions [ 'text_will_end_in' ] . $timeout ;
else $promotion = 1 ;
}
break ;
}
case 7 :
{
if ( $showtimeleft && (( $expirethirtypercentleech_torrent && $promotionTimeType == 0 ) || $promotionTimeType == 2 ))
{
if ( $promotionTimeType == 2 ) {
$futuretime = strtotime ( $promotionUntil );
} else {
$futuretime = strtotime ( $added ) + $expirethirtypercentleech_torrent * 86400 ;
}
$timeout = gettime ( date ( " Y-m-d H:i:s " , $futuretime ), false , false , true , false , true );
if ( $timeout )
$onmouseover = " " . $lang_functions [ 'text_will_end_in' ] . $timeout ;
else $promotion = 1 ;
}
break ;
}
}
}
if (( $CURUSER [ 'appendpromotion' ] == 'word' && $forcemode == " " ) || $forcemode == 'word' ){
$log .= " , user appendpromotion = word " ;
2022-06-08 14:15:59 +08:00
if (( $promotion == 2 && $globalSpState == 1 ) || $globalSpState == 2 ){
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 2 " ;
$sp_torrent = $onmouseover ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 3 && $globalSpState == 1 ) || $globalSpState == 3 ){
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 3 " ;
$sp_torrent = $onmouseover ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 4 && $globalSpState == 1 ) || $globalSpState == 4 ){
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 4 " ;
$sp_torrent = $onmouseover ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 5 && $globalSpState == 1 ) || $globalSpState == 5 ){
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 5 " ;
$sp_torrent = $onmouseover ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 6 && $globalSpState == 1 ) || $globalSpState == 6 ){
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 6 " ;
$sp_torrent = $onmouseover ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 7 && $globalSpState == 1 ) || $globalSpState == 7 ){
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 7 " ;
$sp_torrent = $onmouseover ;
}
}
elseif (( $CURUSER [ 'appendpromotion' ] == 'icon' && $forcemode == " " ) || $forcemode == 'icon' ){
$log .= " , user appendpromotion = icon " ;
2022-06-08 14:15:59 +08:00
if (( $promotion == 2 && $globalSpState == 1 ) || $globalSpState == 2 ) {
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 2 " ;
$sp_torrent = $onmouseover ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 3 && $globalSpState == 1 ) || $globalSpState == 3 ) {
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 3 " ;
$sp_torrent = $onmouseover ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 4 && $globalSpState == 1 ) || $globalSpState == 4 ) {
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 4 " ;
$sp_torrent = $onmouseover ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 5 && $globalSpState == 1 ) || $globalSpState == 5 ) {
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 5 " ;
$sp_torrent = $onmouseover ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 6 && $globalSpState == 1 ) || $globalSpState == 6 ) {
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 6 " ;
$sp_torrent = $onmouseover ;
}
2022-06-08 14:15:59 +08:00
elseif (( $promotion == 7 && $globalSpState == 1 ) || $globalSpState == 7 ) {
2021-06-23 20:20:34 +08:00
$log .= " , promotion or global_sp_state = 7 " ;
$sp_torrent = $onmouseover ;
}
}
do_log ( " $log , sp_torrent: $sp_torrent " );
return $sp_torrent ;
}
2022-10-01 00:11:22 +08:00
function get_hr_img ( array $torrent , $searchBoxId )
2021-06-21 02:01:26 +08:00
{
2022-10-01 00:11:22 +08:00
// $mode = get_setting('hr.mode');
$mode = \App\Models\HitAndRun :: getConfig ( 'mode' , $searchBoxId );
2021-06-21 02:01:26 +08:00
$result = '' ;
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" />' ;
}
2022-10-22 20:52:08 +08:00
do_log ( " searchBoxId: $searchBoxId , mode: $mode , result: $result " );
2021-06-21 02:01:26 +08:00
return $result ;
}
2020-12-26 01:42:23 +08:00
function get_user_id_from_name ( $username ){
global $lang_functions ;
$res = sql_query ( " SELECT id FROM users WHERE LOWER(username)=LOWER( " . sqlesc ( $username ) . " ) " );
$arr = mysql_fetch_array ( $res );
if ( ! $arr ){
stderr ( $lang_functions [ 'std_error' ], $lang_functions [ 'std_no_user_named' ] . " ' " . $username . " ' " );
}
else return $arr [ 'id' ];
}
function is_forum_moderator ( $id , $in = 'post' ){
global $CURUSER ;
switch ( $in ){
case 'post' : {
$res = sql_query ( " SELECT topicid FROM posts WHERE id= $id " ) or sqlerr ( __FILE__ , __LINE__ );
if ( $arr = mysql_fetch_array ( $res )){
if ( is_forum_moderator ( $arr [ 'topicid' ], 'topic' ))
return true ;
}
return false ;
break ;
}
case 'topic' : {
$modcount = sql_query ( " SELECT COUNT(forummods.userid) FROM forummods LEFT JOIN topics ON forummods.forumid = topics.forumid WHERE topics.id= $id AND forummods.userid= " . sqlesc ( $CURUSER [ 'id' ])) or sqlerr ( __FILE__ , __LINE__ );
$arr = mysql_fetch_array ( $modcount );
if ( $arr [ 0 ])
return true ;
else return false ;
break ;
}
case 'forum' : {
$modcount = get_row_count ( " forummods " , " WHERE forumid= $id AND userid= " . sqlesc ( $CURUSER [ 'id' ]));
if ( $modcount )
return true ;
else return false ;
break ;
}
default : {
return false ;
}
}
}
function get_guest_lang_id (){
global $CURLANGDIR ;
$langfolder = $CURLANGDIR ;
$res = sql_query ( " SELECT id FROM language WHERE site_lang_folder= " . sqlesc ( $langfolder ) . " AND site_lang=1 " );
$row = mysql_fetch_array ( $res );
if ( $row ){
return $row [ 'id' ];
}
else return 6 ; //return English
}
function set_forum_moderators ( $name , $forumid , $limit = 3 ){
$name = rtrim ( trim ( $name ), " , " );
$users = explode ( " , " , $name );
$userids = array ();
foreach ( $users as $user ){
$userids [] = get_user_id_from_name ( trim ( $user ));
}
$max = count ( $userids );
sql_query ( " DELETE FROM forummods WHERE forumid= " . sqlesc ( $forumid )) or sqlerr ( __FILE__ , __LINE__ );
for ( $i = 0 ; $i < $limit && $i < $max ; $i ++ ){
sql_query ( " INSERT INTO forummods (forumid, userid) VALUES ( " . sqlesc ( $forumid ) . " , " . sqlesc ( $userids [ $i ]) . " ) " ) or sqlerr ( __FILE__ , __LINE__ );
}
}
function get_plain_username ( $id ){
2021-04-22 03:24:59 +08:00
$row = get_user_row ( $id );
2020-12-26 01:42:23 +08:00
if ( $row )
$username = $row [ 'username' ];
else $username = " " ;
return $username ;
}
function get_searchbox_value ( $mode = 1 , $item = 'showsubcat' ){
global $Cache ;
static $rows ;
2022-11-06 16:12:15 +08:00
$cacheKey = " search_box_content " ;
2022-09-14 19:05:29 +08:00
if ( ! $rows && ! $rows = $Cache -> get_value ( $cacheKey )){
2020-12-26 01:42:23 +08:00
$rows = array ();
$res = sql_query ( " SELECT * FROM searchbox ORDER BY id ASC " );
while ( $row = mysql_fetch_array ( $res )) {
2022-09-02 19:49:41 +08:00
if ( isset ( $row [ 'extra' ])) {
$row [ 'extra' ] = json_decode ( $row [ 'extra' ], true );
2022-10-27 20:21:54 +08:00
}
if ( isset ( $row [ 'section_name' ])) {
$row [ 'section_name' ] = json_decode ( $row [ 'section_name' ], true );
2022-09-02 19:49:41 +08:00
}
2020-12-26 01:42:23 +08:00
$rows [ $row [ 'id' ]] = $row ;
}
2022-09-14 19:05:29 +08:00
$Cache -> cache_value ( $cacheKey , $rows , 100500 );
2020-12-26 01:42:23 +08:00
}
2020-12-28 20:52:54 +08:00
return $rows [ $mode ][ $item ] ? ? '' ;
2020-12-26 01:42:23 +08:00
}
function get_ratio ( $userid , $html = true ){
global $lang_functions ;
$row = get_user_row ( $userid );
$uped = $row [ 'uploaded' ];
$downed = $row [ 'downloaded' ];
if ( $html == true ){
if ( $downed > 0 )
{
$ratio = $uped / $downed ;
$color = get_ratio_color ( $ratio );
$ratio = number_format ( $ratio , 3 );
if ( $color )
$ratio = " <font color= \" " . $color . " \" > " . $ratio . " </font> " ;
}
elseif ( $uped > 0 )
$ratio = $lang_functions [ 'text_inf' ];
else
$ratio = " --- " ;
}
else {
if ( $downed > 0 )
{
$ratio = $uped / $downed ;
}
else $ratio = 1 ;
}
return $ratio ;
}
function add_s ( $num , $es = false )
{
global $lang_functions ;
2020-12-29 03:02:34 +08:00
return ( $num > 1 ? ( $es ? ( $lang_functions [ 'text_es' ] ? ? '' ) : $lang_functions [ 'text_s' ]) : " " );
2020-12-26 01:42:23 +08:00
}
function is_or_are ( $num )
{
global $lang_functions ;
return ( $num > 1 ? $lang_functions [ 'text_are' ] : $lang_functions [ 'text_is' ]);
}
function getmicrotime (){
list ( $usec , $sec ) = explode ( " " , microtime ());
return (( float ) $usec + ( float ) $sec );
}
function get_user_class_image ( $class ){
$UC = array (
" Staff Leader " => " pic/staffleader.gif " ,
" SysOp " => " pic/sysop.gif " ,
" Administrator " => " pic/administrator.gif " ,
" Moderator " => " pic/moderator.gif " ,
" Forum Moderator " => " pic/forummoderator.gif " ,
" Uploader " => " pic/uploader.gif " ,
" Retiree " => " pic/retiree.gif " ,
" VIP " => " pic/vip.gif " ,
" Nexus Master " => " pic/nexus.gif " ,
" Ultimate User " => " pic/ultimate.gif " ,
" Extreme User " => " pic/extreme.gif " ,
" Veteran User " => " pic/veteran.gif " ,
" Insane User " => " pic/insane.gif " ,
" Crazy User " => " pic/crazy.gif " ,
" Elite User " => " pic/elite.gif " ,
" Power User " => " pic/power.gif " ,
" User " => " pic/user.gif " ,
" Peasant " => " pic/peasant.gif "
);
2022-04-22 15:54:56 +08:00
if ( isset ( $class )) {
2022-04-22 15:59:17 +08:00
$className = get_user_class_name ( $class , false , false , false );
if ( str_contains ( $className , '(' )) {
$className = strstr ( $className , '(' , true );
}
2022-04-22 15:54:56 +08:00
$uclass = $UC [ $className ];
} else {
$uclass = " pic/banned.gif " ;
}
2020-12-26 01:42:23 +08:00
return $uclass ;
}
function user_can_upload ( $where = " torrents " ){
2022-12-04 00:22:43 +08:00
global $CURUSER , $upload_class , $enablespecial , $uploadspecial_class , $lang_functions ;
if ( $CURUSER [ " uploadpos " ] != 'yes' ) {
return false ;
}
$uploadDenyApprovalDenyCount = get_setting ( 'main.upload_deny_approval_deny_count' );
$approvalDenyCount = \App\Models\Torrent :: query () -> where ( 'owner' , $CURUSER [ 'id' ])
-> where ( 'approval_status' , \App\Models\Torrent :: APPROVAL_STATUS_DENY )
-> count ()
;
if ( $uploadDenyApprovalDenyCount > 0 && $approvalDenyCount >= $uploadDenyApprovalDenyCount ) {
stderr ( $lang_functions [ 'std_sorry' ], sprintf ( $lang_functions [ 'approval_deny_reach_upper_limit' ], $uploadDenyApprovalDenyCount ), false );
}
2020-12-26 01:42:23 +08:00
if ( $where == " torrents " )
{
2022-12-04 00:22:43 +08:00
$offerSkipApprovedCount = get_setting ( 'main.offer_skip_approved_count' );
if ( $CURUSER [ 'offer_allowed_count' ] >= $offerSkipApprovedCount ) {
return true ;
}
2022-08-20 19:11:28 +08:00
if ( user_can ( 'upload' ))
2020-12-26 01:42:23 +08:00
return true ;
if ( get_if_restricted_is_open ())
return true ;
}
if ( $where == " music " )
{
2022-08-20 19:11:28 +08:00
if ( $enablespecial == 'yes' && user_can ( 'uploadspecial' ))
2020-12-26 01:42:23 +08:00
return true ;
}
return false ;
}
2022-09-14 19:05:29 +08:00
function torrent_selection ( $name , $selname , $listname , $selectedid = 0 , $mode = 0 )
2020-12-26 01:42:23 +08:00
{
global $lang_functions ;
$selection = " <b> " . $name . " </b> <select name= \" " . $selname . " \" > \n <option value= \" 0 \" > " . $lang_functions [ 'select_choose_one' ] . " </option> \n " ;
2022-09-14 19:05:29 +08:00
$listarray = searchbox_item_list ( $listname , $mode );
2020-12-26 01:42:23 +08:00
foreach ( $listarray as $row )
$selection .= " <option value= \" " . $row [ " id " ] . " \" " . ( $row [ " id " ] == $selectedid ? " selected= \" selected \" " : " " ) . " > " . htmlspecialchars ( $row [ " name " ]) . " </option> \n " ;
$selection .= " </select> \n " ;
return $selection ;
}
function get_hl_color ( $color = 0 )
{
switch ( $color ){
case 0 : return false ;
case 1 : return " Black " ;
case 2 : return " Sienna " ;
case 3 : return " DarkOliveGreen " ;
case 4 : return " DarkGreen " ;
case 5 : return " DarkSlateBlue " ;
case 6 : return " Navy " ;
case 7 : return " Indigo " ;
case 8 : return " DarkSlateGray " ;
case 9 : return " DarkRed " ;
case 10 : return " DarkOrange " ;
case 11 : return " Olive " ;
case 12 : return " Green " ;
case 13 : return " Teal " ;
case 14 : return " Blue " ;
case 15 : return " SlateGray " ;
case 16 : return " DimGray " ;
case 17 : return " Red " ;
case 18 : return " SandyBrown " ;
case 19 : return " YellowGreen " ;
case 20 : return " SeaGreen " ;
case 21 : return " MediumTurquoise " ;
case 22 : return " RoyalBlue " ;
case 23 : return " Purple " ;
case 24 : return " Gray " ;
case 25 : return " Magenta " ;
case 26 : return " Orange " ;
case 27 : return " Yellow " ;
case 28 : return " Lime " ;
case 29 : return " Cyan " ;
case 30 : return " DeepSkyBlue " ;
case 31 : return " DarkOrchid " ;
case 32 : return " Silver " ;
case 33 : return " Pink " ;
case 34 : return " Wheat " ;
case 35 : return " LemonChiffon " ;
case 36 : return " PaleGreen " ;
case 37 : return " PaleTurquoise " ;
case 38 : return " LightBlue " ;
case 39 : return " Plum " ;
case 40 : return " White " ;
default : return false ;
}
}
function get_forum_moderators ( $forumid , $plaintext = true )
{
global $Cache ;
static $moderatorsArray ;
if ( ! $moderatorsArray && ! $moderatorsArray = $Cache -> get_value ( 'forum_moderator_array' )) {
$moderatorsArray = array ();
$res = sql_query ( " SELECT forumid, userid FROM forummods ORDER BY forumid ASC " ) or sqlerr ( __FILE__ , __LINE__ );
while ( $row = mysql_fetch_array ( $res )) {
$moderatorsArray [ $row [ 'forumid' ]][] = $row [ 'userid' ];
}
$Cache -> cache_value ( 'forum_moderator_array' , $moderatorsArray , 86200 );
}
2020-12-29 03:02:34 +08:00
$ret = $moderatorsArray [ $forumid ] ? ? [];
2020-12-26 01:42:23 +08:00
$moderators = " " ;
foreach ( $ret as $userid ) {
if ( $plaintext )
$moderators .= get_plain_username ( $userid ) . " , " ;
else $moderators .= get_username ( $userid ) . " , " ;
}
$moderators = rtrim ( trim ( $moderators ), " , " );
return $moderators ;
}
function key_shortcut ( $page = 1 , $pages = 1 )
{
$currentpage = " var currentpage= " . $page . " ; " ;
$maxpage = " var maxpage= " . $pages . " ; " ;
$key_shortcut_block = " \n <script type= \" text/javascript \" > \n //<![CDATA[ \n " . $maxpage . " \n " . $currentpage . " \n //]]> \n </script> \n " ;
return $key_shortcut_block ;
}
function promotion_selection ( $selected = 0 , $hide = 0 )
{
global $lang_functions ;
$selection = " " ;
if ( $hide != 1 )
$selection .= " <option value= \" 1 \" " . ( $selected == 1 ? " selected= \" selected \" " : " " ) . " > " . $lang_functions [ 'text_normal' ] . " </option> " ;
if ( $hide != 2 )
$selection .= " <option value= \" 2 \" " . ( $selected == 2 ? " selected= \" selected \" " : " " ) . " > " . $lang_functions [ 'text_free' ] . " </option> " ;
if ( $hide != 3 )
$selection .= " <option value= \" 3 \" " . ( $selected == 3 ? " selected= \" selected \" " : " " ) . " > " . $lang_functions [ 'text_two_times_up' ] . " </option> " ;
if ( $hide != 4 )
$selection .= " <option value= \" 4 \" " . ( $selected == 4 ? " selected= \" selected \" " : " " ) . " > " . $lang_functions [ 'text_free_two_times_up' ] . " </option> " ;
if ( $hide != 5 )
$selection .= " <option value= \" 5 \" " . ( $selected == 5 ? " selected= \" selected \" " : " " ) . " > " . $lang_functions [ 'text_half_down' ] . " </option> " ;
if ( $hide != 6 )
$selection .= " <option value= \" 6 \" " . ( $selected == 6 ? " selected= \" selected \" " : " " ) . " > " . $lang_functions [ 'text_half_down_two_up' ] . " </option> " ;
if ( $hide != 7 )
$selection .= " <option value= \" 7 \" " . ( $selected == 7 ? " selected= \" selected \" " : " " ) . " > " . $lang_functions [ 'text_thirty_percent_down' ] . " </option> " ;
return $selection ;
}
function get_post_row ( $postid )
{
global $Cache ;
if ( ! $row = $Cache -> get_value ( 'post_' . $postid . '_content' )){
$res = sql_query ( " SELECT * FROM posts WHERE id= " . sqlesc ( $postid ) . " LIMIT 1 " ) or sqlerr ( __FILE__ , __LINE__ );
$row = mysql_fetch_array ( $res );
$Cache -> cache_value ( 'post_' . $postid . '_content' , $row , 7200 );
}
if ( ! $row )
return false ;
else return $row ;
}
function get_country_row ( $id )
{
global $Cache ;
if ( ! $row = $Cache -> get_value ( 'country_' . $id . '_content' )){
$res = sql_query ( " SELECT * FROM countries WHERE id= " . sqlesc ( $id ) . " LIMIT 1 " ) or sqlerr ( __FILE__ , __LINE__ );
$row = mysql_fetch_array ( $res );
$Cache -> cache_value ( 'country_' . $id . '_content' , $row , 86400 );
}
if ( ! $row )
return false ;
else return $row ;
}
function get_downloadspeed_row ( $id )
{
global $Cache ;
if ( ! $row = $Cache -> get_value ( 'downloadspeed_' . $id . '_content' )){
$res = sql_query ( " SELECT * FROM downloadspeed WHERE id= " . sqlesc ( $id ) . " LIMIT 1 " ) or sqlerr ( __FILE__ , __LINE__ );
$row = mysql_fetch_array ( $res );
$Cache -> cache_value ( 'downloadspeed_' . $id . '_content' , $row , 86400 );
}
if ( ! $row )
return false ;
else return $row ;
}
function get_uploadspeed_row ( $id )
{
global $Cache ;
if ( ! $row = $Cache -> get_value ( 'uploadspeed_' . $id . '_content' )){
$res = sql_query ( " SELECT * FROM uploadspeed WHERE id= " . sqlesc ( $id ) . " LIMIT 1 " ) or sqlerr ( __FILE__ , __LINE__ );
$row = mysql_fetch_array ( $res );
$Cache -> cache_value ( 'uploadspeed_' . $id . '_content' , $row , 86400 );
}
if ( ! $row )
return false ;
else return $row ;
}
function get_isp_row ( $id )
{
global $Cache ;
if ( ! $row = $Cache -> get_value ( 'isp_' . $id . '_content' )){
$res = sql_query ( " SELECT * FROM isp WHERE id= " . sqlesc ( $id ) . " LIMIT 1 " ) or sqlerr ( __FILE__ , __LINE__ );
$row = mysql_fetch_array ( $res );
$Cache -> cache_value ( 'isp_' . $id . '_content' , $row , 86400 );
}
if ( ! $row )
return false ;
else return $row ;
}
function valid_file_name ( $filename )
{
$allowedchars = " abcdefghijklmnopqrstuvwxyz0123456789_./ " ;
$total = strlen ( $filename );
for ( $i = 0 ; $i < $total ; ++ $i )
if ( strpos ( $allowedchars , $filename [ $i ]) === false )
return false ;
return true ;
}
function valid_class_name ( $filename )
{
$allowedfirstchars = " abcdefghijklmnopqrstuvwxyz " ;
$allowedchars = " abcdefghijklmnopqrstuvwxyz0123456789_ " ;
if ( strpos ( $allowedfirstchars , $filename [ 0 ]) === false )
return false ;
$total = strlen ( $filename );
for ( $i = 1 ; $i < $total ; ++ $i )
if ( strpos ( $allowedchars , $filename [ $i ]) === false )
return false ;
return true ;
}
function return_avatar_image ( $url )
{
global $CURLANGDIR ;
return " <img src= \" " . $url . " \" alt= \" avatar \" width= \" 150px \" onload= \" check_avatar(this, ' " . $CURLANGDIR . " '); \" /> " ;
}
function return_category_image ( $categoryid , $link = " " )
{
static $catImg = array ();
2020-12-28 20:52:54 +08:00
if ( isset ( $catImg [ $categoryid ])) {
2020-12-26 01:42:23 +08:00
$catimg = $catImg [ $categoryid ];
} else {
$categoryrow = get_category_row ( $categoryid );
$catimgurl = get_cat_folder ( $categoryid );
2021-02-26 00:46:11 +08:00
$catImg [ $categoryid ] = $catimg = " <img " . ( $categoryrow [ 'class_name' ] ? " class= \" " . $categoryrow [ 'class_name' ] . " \" " : " " ) . " src= \" pic/cattrans.gif \" alt= \" " . $categoryrow [ " name " ] . " \" title= \" " . $categoryrow [ " name " ] . " \" style= \" background-image: url(pic/ " . $catimgurl . '/' . $categoryrow [ " image " ] . " ); \" /> " ;
2020-12-26 01:42:23 +08:00
}
if ( $link ) {
$catimg = " <a href= \" " . $link . " cat= " . $categoryid . " \" > " . $catimg . " </a> " ;
}
return $catimg ;
}
2020-12-26 20:09:15 +08:00
2021-02-03 18:41:53 +08:00
/******************************************** bellow functioons avaliable since v1.6 ***********************************************************/
2021-02-20 18:22:19 +08:00
function get_requestcount ()
{
global $CURUSER , $Cache ;
//return;
$CURUSERID = 0 + $CURUSER [ 'id' ];
if ( ! $count = $Cache -> get_value ( $CURUSERID . '_get_requestcount' )) {
$row = @ mysql_fetch_array ( sql_query ( " SELECT count(*) FROM requests LEFT JOIN resreq ON reqid=requests.id WHERE reqid>0 and finish = 'no' and userid= " . $CURUSERID ));
$count = ( $row [ 0 ] ? " style='background: none red;' " : " style='' " );
$Cache -> cache_value ( $CURUSERID . '_get_requestcount' , $count , 120 );
}
return $count ;
}
function torrentTags ( $tags = 0 , $type = 'checkbox' )
{
global $lang_functions ;
$tagsOptions = [
[
'text' => $lang_functions [ 'text_tag_no_release_to_any_other' ],
2021-04-21 22:31:35 +08:00
'color' => '#ff0000' ,
2021-02-20 18:22:19 +08:00
],
[
'text' => $lang_functions [ 'text_tag_first_release' ],
'color' => '#8F77B5' ,
],
[
'text' => $lang_functions [ 'text_tag_official' ],
2021-04-21 22:04:05 +08:00
'color' => '#0000ff' ,
2021-02-20 18:22:19 +08:00
],
[
'text' => $lang_functions [ 'text_tag_diy' ],
2021-04-21 22:04:05 +08:00
'color' => '#46d5ff' ,
2021-02-20 18:22:19 +08:00
],
[
'text' => $lang_functions [ 'text_tag_mother_language' ],
2021-04-21 22:04:05 +08:00
'color' => '#6a3906' ,
2021-02-20 18:22:19 +08:00
],
[
'text' => $lang_functions [ 'text_tag_mother_language_subtitle' ],
2021-04-21 22:04:05 +08:00
'color' => '#006400' ,
],
[
'text' => $lang_functions [ 'text_tag_hdr' ],
'color' => '#38b03f' ,
2021-02-20 18:22:19 +08:00
],
];
$html = '' ;
foreach ( $tagsOptions as $key => $value ) {
$currentValue = pow ( 2 , $key );
if ( $type == 'checkbox' ) {
$checked = '' ;
if ( $currentValue & $tags ) {
$checked = 'checked' ;
}
$html .= sprintf (
'<label><input type="checkbox" name="tags[]" value="%s" %s />%s</label>' ,
$currentValue , $checked , $value [ 'text' ]
);
}
if ( $type == 'span' && ( $currentValue & $tags )) {
$html .= " <span style= \" background-color: { $value [ 'color' ] } ;color:white;border-radius:15% \" > { $value [ 'text' ] } </span> " ;
}
}
return $html ;
}
2022-05-06 22:25:00 +08:00
function saveSetting ( $prefix , $nameAndValue , $autoload = 'yes' )
2021-01-22 19:43:15 +08:00
{
$prefix = strtolower ( $prefix );
$datetimeNow = date ( 'Y-m-d H:i:s' );
2022-08-14 22:20:15 +08:00
$sql = " insert into `settings` (name, value, created_at, updated_at, autoload) values " ;
2021-01-22 19:43:15 +08:00
$data = [];
foreach ( $nameAndValue as $name => $value ) {
if ( is_array ( $value )) {
$value = json_encode ( $value );
}
2022-05-06 22:25:00 +08:00
$data [] = sprintf ( " (%s, %s, %s, %s, '%s') " , sqlesc ( " $prefix . $name " ), sqlesc ( $value ), sqlesc ( $datetimeNow ), sqlesc ( $datetimeNow ), $autoload );
2021-01-22 19:43:15 +08:00
}
$sql .= implode ( " , " , $data ) . " on duplicate key update value = values(value) " ;
2022-05-13 14:40:59 +08:00
\Nexus\Database\NexusDB :: statement ( $sql );
2022-09-08 22:01:30 +08:00
clear_setting_cache ();
2022-10-01 00:11:22 +08:00
do_action ( " nexus_setting_update " );
2021-01-22 19:43:15 +08:00
}
2021-01-23 17:39:17 +08:00
function getFullDirectory ( $dir )
{
2023-07-31 11:32:24 +08:00
if ( is_file ( $dir ) && file_exists ( $dir )) {
return $dir ;
}
2021-01-23 17:39:17 +08:00
if ( ! is_dir ( $dir )) {
$dir = ROOT_PATH . $dir ;
}
2021-03-05 19:43:40 +08:00
if ( is_dir ( $dir )) {
return realpath ( $dir );
}
return $dir ;
2021-01-23 17:39:17 +08:00
}
2021-02-03 18:41:53 +08:00
function checkGuestVisit ()
{
if ( userlogin ()) {
//already login
return ;
}
$setting = get_setting ( 'security' );
//all type: normal, static_page, custom_content, redirect
$guestVisitType = $setting [ 'guest_visit_type' ] ? ? '' ;
if ( empty ( $guestVisitType ) || $guestVisitType == 'normal' ) {
return ;
}
2022-08-24 21:21:47 +08:00
2022-03-20 22:14:00 +08:00
if ( in_array ( nexus () -> getScript (), [ 'login' , 'takelogin' , 'image' ]) && canDoLogin ()) {
2021-02-03 18:41:53 +08:00
return ;
}
$valueKey = " guest_visit_value_ $guestVisitType " ;
if ( empty ( $setting [ $valueKey ])) {
do_log ( " setting: security. $valueKey empty " );
die ( 0 );
}
$guestVisitValue = $setting [ $valueKey ];
if ( $guestVisitType == 'static_page' ) {
$pageFile = ROOT_PATH . 'resources/static-pages/' . $guestVisitValue ;
if ( ! file_exists ( $pageFile ) || ! is_readable ( $pageFile )) {
do_log ( " pageFile: $pageFile is not exists or readable " );
die ( 0 );
}
$content = file_get_contents ( $pageFile );
die ( $content );
}
if ( $guestVisitType == 'custom_content' ) {
$content = format_comment ( $guestVisitValue );
render ( 'resources/templates/guest-visit-custom-content' , [ 'content' => $content ]);
}
if ( $guestVisitType == 'redirect' ) {
header ( 'Location: ' . $guestVisitValue );
die ( 0 );
}
}
2023-07-04 01:00:02 +08:00
function render ( $view , $data = [], $return = false )
2021-02-03 18:41:53 +08:00
{
extract ( $data );
if ( ! file_exists ( $view )) {
$view = ROOT_PATH . $view ;
}
if ( substr ( $view , - 4 ) !== '.php' ) {
$view .= " .php " ;
}
ob_start ();
ob_implicit_flush ( 0 );
require $view ;
$result = ob_get_clean ();
if ( $return ) {
return $result ;
}
die ( $result );
}
function canDoLogin ()
{
$setting = get_setting ( 'security' );
if ( empty ( $setting [ 'login_type' ]) || $setting [ 'login_type' ] == 'normal' ) {
return true ;
}
$loginType = $setting [ 'login_type' ];
if ( $loginType == 'secret' ) {
if ( empty ( $_REQUEST [ 'secret' ])) {
do_log ( " no secret " );
return false ;
}
if ( $_REQUEST [ 'secret' ] != $setting [ 'login_secret' ]) {
do_log ( " invlaid secret: " . $_REQUEST [ 'secret' ]);
return false ;
}
if ( $setting [ 'login_secret_deadline' ] < date ( 'Y-m-d H:i:s' )) {
do_log ( " secret: { $_REQUEST [ 'secret' ] } expires(deadline: { $setting [ 'login_secret_deadline' ] } ) " );
return false ;
}
2022-08-24 21:21:47 +08:00
return true ;
}
if ( $loginType == 'passkey' ) {
return false ;
2021-02-03 18:41:53 +08:00
}
return true ;
}
2021-03-05 02:05:27 +08:00
function displayHotAndClassic ()
{
2022-06-08 14:15:59 +08:00
global $showextinfo , $showmovies , $Cache , $lang_functions , $browsecatmode , $specialcatmode ;
2021-03-05 02:05:27 +08:00
2022-05-03 23:58:27 +08:00
if ( $showmovies [ 'hot' ] == " yes " || $showmovies [ 'classic' ] == " yes " )
2021-03-05 02:05:27 +08:00
{
2022-06-08 14:15:59 +08:00
if ( nexus () -> getScript () == 'special' ) {
$mode = $specialcatmode ;
} else {
$mode = $browsecatmode ;
}
2021-03-05 02:05:27 +08:00
$imdb = new \Nexus\Imdb\Imdb ();
$type = array ( 'hot' , 'classic' );
foreach ( $type as $type_each )
{
if ( $showmovies [ $type_each ] == 'yes' && ( ! isset ( $CURUSER ) || $CURUSER [ 'show' . $type_each ] == 'yes' ))
{
2022-06-08 15:50:12 +08:00
$Cache -> new_page ( " { $type_each } _ { $mode } _resources " , 900 , true );
2021-03-05 02:05:27 +08:00
if ( ! $Cache -> get_page ())
{
$Cache -> add_whole_row ();
2022-06-08 14:15:59 +08:00
$res = sql_query ( " SELECT torrents.sp_state, torrents.url, torrents.id, torrents.name, torrents.small_descr, torrents.cover FROM torrents LEFT JOIN categories ON torrents.category = categories.id WHERE categories.mode = $mode AND picktype = " . sqlesc ( $type_each ) . " AND seeders > 0 AND (url != '' OR cover != '') ORDER BY id DESC LIMIT 30 " ) or sqlerr ( __FILE__ , __LINE__ );
2021-03-05 02:05:27 +08:00
if ( mysql_num_rows ( $res ) > 0 )
{
$movies_list = " " ;
$count = 0 ;
$allImdb = array ();
2022-05-03 23:58:27 +08:00
$width = 101 ;
$height = 140 ;
2021-03-05 02:05:27 +08:00
while ( $array = mysql_fetch_array ( $res ))
{
2022-06-08 14:15:59 +08:00
$pro_torrent = get_torrent_promotion_append ( $array [ 'sp_state' ], 'word' , false , '' , 0 , '' , $array [ '__ignore_global_sp_state' ] ? ? false );
2022-07-25 00:37:23 +08:00
$photo_url = '' ;
if ( $imdb_id = parse_imdb_id ( $array [ " url " ])) {
2021-03-05 02:05:27 +08:00
if ( array_search ( $imdb_id , $allImdb ) !== false ) { //a torrent with the same IMDb url already exists
continue ;
}
$allImdb [] = $imdb_id ;
2021-03-17 18:46:40 +08:00
try {
$photo_url = $imdb -> getMovie ( $imdb_id ) -> photo ( true );
if ( empty ( $photo_url )) {
do_log ( " torrent: { $array [ 'id' ] } , url: { $array [ 'url' ] } , imdb_id: $imdb_id can not get photo " , 'error' );
}
} catch ( \Exception $exception ) {
do_log ( $exception -> getMessage () . " \n [stacktrace] \n " . $exception -> getTraceAsString (), 'error' );
}
2022-07-25 00:37:23 +08:00
}
if ( empty ( $photo_url ) && ! empty ( $array [ 'cover' ])) {
$photo_url = $array [ 'cover' ];
}
if ( empty ( $photo_url )) {
2022-05-03 23:58:27 +08:00
continue ;
2021-03-05 02:05:27 +08:00
}
2022-07-25 00:37:23 +08:00
$thumbnail = " <img width= \" { $width } \" height= \" { $height } \" src= \" " . $photo_url . " \" border= \" 0 \" alt= \" poster \" /> " ;
2021-03-17 18:46:40 +08:00
$thumbnail = " <a style= \" margin-right: 2px \" href= \" details.php?id= " . $array [ 'id' ] . " &hit=1 \" onmouseover= \" domTT_activate(this, event, 'content', ' " . htmlspecialchars ( " <font class= \ 'big \ '><b> " . ( addslashes ( $array [ 'name' ] . $pro_torrent )) . " </b></font><br /><font class= \ 'medium \ '> " . ( addslashes ( $array [ 'small_descr' ])) . " </font> " ) . " ', 'trail', true, 'delay', 0,'lifetime',5000,'styleClass','niceTitle','maxWidth', 600); \" > " . $thumbnail . " </a> " ;
2021-03-05 02:05:27 +08:00
$movies_list .= $thumbnail ;
$count ++ ;
2021-06-12 23:21:40 +08:00
if ( $count >= 10 )
2021-03-05 02:05:27 +08:00
break ;
}
?>
< h2 >< ? php echo $lang_functions [ 'text_' . $type_each ] ?> </h2>
< table width = " 100% " border = " 1 " cellspacing = " 0 " cellpadding = " 5 " >< tr >< td class = " text nowrap " align = " center " >
< ? php echo $movies_list ?> </td></tr></table>
< ? php
}
$Cache -> end_whole_row ();
$Cache -> cache_page ();
}
echo $Cache -> next_row ();
}
}
}
}
2021-05-13 21:31:09 +08:00
function build_table ( array $header , array $rows , array $options = [])
{
$table = '<table border="1" cellspacing="0" cellpadding="5" width="100%"><thead><tr>' ;
foreach ( $header as $key => $value ) {
$table .= sprintf ( '<td class="colhead">%s</td>' , $value );
}
$table .= '</tr></thead><tbody>' ;
$tdClass = '' ;
if ( isset ( $options [ 'td-center' ]) && $options [ 'td-center' ]) {
$tdClass = 'colfollow' ;
}
foreach ( $rows as $row ) {
$table .= '<tr>' ;
foreach ( $header as $headerKey => $headerValue ) {
$table .= sprintf ( '<td class="%s">%s</td>' , $tdClass , $row [ $headerKey ] ? ? '' );
}
$table .= '</tr>' ;
}
$table .= '</tbody></table>' ;
return $table ;
}
2021-05-15 19:29:44 +08:00
/**
* 返回链接中附件的key
*
* @ param $url
* @ return string
*/
function attachmentKey ( $url )
{
if ( ! filter_var ( $url , FILTER_VALIDATE_URL ))
{
throw new \InvalidArgumentException ( " URL: ' $url ' invalid. " );
}
$parsed = parse_url ( $url );
$driver = config ( 'admin.upload.disk' );
if ( $driver == 'qiniu' ) {
return trim ( $parsed [ 'path' ], " / " );
} elseif ( $driver == 'cloudinary' ) {
$parts = explode ( '/' , $parsed [ 'path' ]);
$key = end ( $parts );
if ( \Illuminate\Support\Str :: contains ( $key , '.' )) {
$key = strstr ( $key , '.' , true );
}
return $key ;
} else {
throw new \RuntimeException ( '不支持的云盘驱动' );
}
}
/**
* 根据key返回链接
*
* @ param $location
* @ param null $width
* @ param null $height
* @ param array $options
* @ return string
*/
function attachmentUrl ( $location , $width = null , $height = null , $options = [])
{
return sprintf ( '%s/attachments/%s' , getSchemeAndHttpHost (), trim ( $location , '/' ));
}
function strip_all_tags ( $text )
{
//替换掉无参数标签
$bbTags = [
'[*]' , '[b]' , '[/b]' , '[i]' , '[/i]' , '[u]' , '[/u]' , '[pre]' , '[/pre]' , '[quote]' , '[/quote]' ,
2022-04-12 15:33:53 +08:00
'[/color]' , '[/font]' , '[/size]' , '[/url]' , '[/youtube]' , '[/spoiler]' ,
2021-05-15 19:29:44 +08:00
];
$text = str_replace ( $bbTags , '' , $text );
//替换掉有参数标签
2022-04-12 15:33:53 +08:00
$pattern = '/\[url=.*\]|\[color=.*\]|\[font=.*\]|\[size=.*\]|\[youtube.*\]|\[spoiler.*\]/isU' ;
2021-05-15 19:29:44 +08:00
$text = preg_replace ( $pattern , " " , $text );
//去掉表情
static $emoji = null ;
if ( is_null ( $emoji )) {
2022-05-03 23:58:27 +08:00
$emoji = nexus_config ( 'emoji' );
2021-05-15 19:29:44 +08:00
}
// $text = preg_replace("/\[em([1-9][0-9]*)\]/isU", "", $text);
$text = preg_replace_callback ( " / \ [em([1-9][0-9]*) \ ]/isU " , function ( $matches ) use ( $emoji ) {
return $emoji [ $matches [ 1 ]] ? ? '' ;
}, $text );
$text = strip_tags ( $text );
return trim ( $text );
}
2022-06-08 14:15:59 +08:00
function format_description ( $description )
2021-05-15 19:29:44 +08:00
{
//替换附件
$pattern = '/(\[attach\](.*)\[\/attach\])/isU' ;
$matchCount = preg_match_all ( $pattern , $description , $matches );
if ( $matchCount ) {
$attachments = \App\Models\Attachment :: query () -> whereIn ( 'dlkey' , $matches [ 2 ]) -> get () -> keyBy ( 'dlkey' );
if ( $attachments -> isNotEmpty ()) {
$description = preg_replace_callback ( $pattern , function ( $matches ) use ( $attachments ) {
$item = $attachments -> get ( $matches [ 2 ]);
$url = attachmentUrl ( $item -> location );
return str_replace ( $matches [ 2 ], $url , $matches [ 1 ]);
}, $description );
}
}
//去除引用
// $pattern = '/\[quote.*\].*\[\/quote\]/is';
// $description = preg_replace($pattern, '', $description);
//去掉引用自
$pattern = '/\[quote=.*\]/isU' ;
$description = preg_replace_callback ( $pattern , function ( $matches ) {
return '[quote]' ;
}, $description );
//过虑多层引用
$delimiter = '__CYLX__' ;
$pattern = '/(\[quote\]){2,}(((?!\[quote\]).)*)\[\/quote\]/isU' ;
$description = preg_replace_callback ( $pattern , function ( $matches ) use ( $delimiter ) {
return $delimiter ;
}, $description );
$pattern = " / $delimiter (((?! \ [quote \ ]).)+) \ [ \ /quote \ ]/is " ;
$description = preg_replace_callback ( $pattern , function ( $matches ) use ( $delimiter ) {
$arr = array_reverse ( explode ( '[/quote]' , $matches [ 0 ]));
foreach ( $arr as $value ) {
$value = trim ( str_replace ( $delimiter , '' , $value ));
if ( ! empty ( $value )) {
return " [quote] { $value } [/quote] " ;
}
}
}, $description );
//匹配不同块
$attachPattern = '\[attach\].*\[\/attach\]' ;
$imgPattern = '\[img\].*\[\/img\]' ;
2023-03-26 23:42:17 +08:00
$imgPattern2 = '\[img=.*\]' ;
2021-05-15 19:29:44 +08:00
$urlPattern = '\[url=.*\].*\[\/url\]' ;
$quotePattern = '\[quote.*\].*\[\/quote\]' ;
2023-03-26 23:42:17 +08:00
$pattern = " /( $attachPattern )|( $imgPattern )|( $imgPattern2 )|( $urlPattern )|( $quotePattern )/isU " ;
2021-05-15 19:29:44 +08:00
// $pattern = "/($attachPattern)|($imgPattern)|($urlPattern)/isU";
2021-05-16 03:04:58 +08:00
$delimiter = '{{{}}}' ;
2021-05-15 19:29:44 +08:00
$description = preg_replace_callback ( $pattern , function ( $matches ) use ( $delimiter ) {
return $delimiter . $matches [ 0 ] . $delimiter ;
}, $description );
//再进行分割
$descriptionArr = preg_split ( " /[ $delimiter ]+/ " , $description );
$results = [];
foreach ( $descriptionArr as $item ) {
if ( preg_match ( '/\[attach\](.*)\[\/attach\]/isU' , $item , $matches )) {
//是否附件
$results [] = [
'type' => 'attachment' ,
'data' => [
'url' => $matches [ 1 ]
]
];
} elseif ( preg_match ( '/\[img\](.*)\[\/img\]/isU' , $item , $matches )) {
//是否图片
$results [] = [
'type' => 'image' ,
'data' => [
'url' => $matches [ 1 ]
]
];
2023-03-26 23:42:17 +08:00
} elseif ( preg_match ( '/\[img=(.*)\]/isU' , $item , $matches )) {
//是否图片
$results [] = [
'type' => 'image' ,
'data' => [
'url' => $matches [ 1 ]
]
];
2021-05-15 19:29:44 +08:00
} elseif ( preg_match ( '/\[url=(.*)\](.*)\[\/url\]/isU' , $item , $matches )) {
$results [] = [
'type' => 'url' ,
'data' => [
'url' => $matches [ 1 ],
'text' => strip_all_tags ( $matches [ 2 ])
]
];
} elseif ( preg_match ( '/\[quote=?(.*)\](.*)\[\/quote\]/isU' , $item , $matches )) {
$results [] = [
'type' => 'quote' ,
'data' => [
'quote_text' => $matches [ 1 ],
'text' => strip_all_tags ( $matches [ 2 ]),
]
];
} elseif ( ! empty ( $item )) {
$results [] = [
'type' => 'text' ,
'data' => [
'text' => strip_all_tags ( $item )
]
];
}
}
// dd($description, $results);
return $results ;
}
2022-05-03 23:58:27 +08:00
function get_image_from_description ( array $descriptionArr , $first = false , $useDefault = true )
2021-05-15 19:29:44 +08:00
{
$imageType = [ 'attachment' , 'image' ];
$images = [];
foreach ( $descriptionArr as $value ) {
if ( ! in_array ( $value [ 'type' ], $imageType )) {
continue ;
}
$url = $value [ 'data' ][ 'url' ] ? ? '' ;
if ( ! $url ) {
continue ;
}
if ( $first ) {
return $url ;
} else {
$images [] = $url ;
}
}
if ( $first ) {
2022-05-03 23:58:27 +08:00
if ( $useDefault ) {
return getSchemeAndHttpHost () . " /pic/imdb_pic/nophoto.gif " ;
} else {
return '' ;
}
2021-05-15 19:29:44 +08:00
}
return $images ;
}
2022-05-03 23:58:27 +08:00
function resize_image ( $url , $with = null , $height = null , $fit = " cover " )
{
$scheme = parse_url ( $url , PHP_URL_SCHEME );
if ( $scheme === false ) {
return $url ;
}
$url = " $scheme ://images.weserv.nl/?url= $url " ;
if ( $with !== null ) {
$url .= " &w= $with " ;
}
if ( $height !== null ) {
$url .= " &h= $height " ;
}
$url .= " &fit= $fit " ;
return $url ;
}
2021-05-15 19:29:44 +08:00
function get_share_ratio ( $uploaded , $downloaded )
{
if ( $downloaded ) {
$ratio = floor (( $uploaded / $downloaded ) * 1000 ) / 1000 ;
} elseif ( $uploaded ) {
//@todo 读语言文件
2024-04-05 22:40:06 +08:00
$ratio = 'Infinity' ;
2021-05-15 19:29:44 +08:00
} else {
$ratio = '---' ;
}
return $ratio ;
}
2022-05-06 17:42:18 +08:00
function EchoRow ( $class = '' ){
if ( func_num_args () < 2 ) return '<tr></tr>' ;
$args = func_get_args ();
$cells = array_splice ( $args , 1 );
$class = empty ( $class ) ? '' : sprintf ( ' class="%s"' , $class );
$s = '<tr>' ;
foreach ( $cells as $cell ) $s .= sprintf ( '<td%s>%s</td>' , $class , $cell );
$s .= " </tr> \n " ;
return $s ;
}
2021-05-29 18:26:04 +08:00
function list_require_search_box_id ()
{
$setting = get_setting ( 'main' );
$maps = [
'torrents' => [ $setting [ 'browsecat' ]],
'special' => [ $setting [ 'specialcat' ]],
'usercp' => [ $setting [ 'browsecat' ], $setting [ 'specialcat' ]],
'getrss' => [ $setting [ 'browsecat' ], $setting [ 'specialcat' ]],
2021-06-17 19:33:23 +08:00
'userdetails' => [ $setting [ 'browsecat' ], $setting [ 'specialcat' ]],
'offers' => [ $setting [ 'browsecat' ], $setting [ 'specialcat' ]],
2022-05-23 01:09:06 +08:00
'details' => [ $setting [ 'browsecat' ], $setting [ 'specialcat' ]],
2022-10-22 23:53:02 +08:00
'search' => [ $setting [ 'browsecat' ], $setting [ 'specialcat' ]],
2021-05-29 18:26:04 +08:00
];
2022-03-20 22:14:00 +08:00
return $maps [ nexus () -> getScript ()] ? ? [];
2021-05-29 18:26:04 +08:00
}
2023-02-08 13:33:25 +08:00
function can_access_torrent ( $torrent , $uid )
2021-05-29 18:26:04 +08:00
{
global $specialcatmode ;
if ( get_setting ( 'main.spsct' ) != 'yes' ) {
return true ;
}
if ( is_array ( $torrent ) && isset ( $torrent [ 'search_box_id' ])) {
$searchBoxId = $torrent [ 'search_box_id' ];
} elseif ( is_numeric ( $torrent )) {
2022-11-05 01:39:20 +08:00
$torrent = \App\Models\Torrent :: query () -> findOrFail ( intval ( $torrent ), [ 'id' , 'category' ]);
$searchBoxId = $torrent -> basic_category -> mode ? ? 0 ;
if ( $searchBoxId == 0 ) {
do_log ( " [INVALID_CATEGORY], torrent: " . $torrent -> id , 'error' );
return false ;
}
2021-05-29 18:26:04 +08:00
} else {
throw new \InvalidArgumentException ( " Unsupported argument: " . json_encode ( $torrent ));
}
if ( $searchBoxId != $specialcatmode ) {
return true ;
}
2023-02-08 13:33:25 +08:00
if ( user_can ( 'view_special_torrent' , false , $uid )) {
2021-05-29 18:26:04 +08:00
return true ;
}
return false ;
}
2022-07-23 15:05:32 +08:00
function get_ip_location_from_geoip ( $ip ) : bool | array
2021-06-07 15:41:47 +08:00
{
$database = nexus_env ( 'GEOIP2_DATABASE' );
2021-06-07 23:08:56 +08:00
if ( empty ( $database )) {
do_log ( " no geoip2 database. " );
return false ;
}
if ( ! is_readable ( $database )) {
do_log ( " geoip2 database: $database is not readable. " );
2021-06-07 15:41:47 +08:00
return false ;
}
static $reader ;
if ( is_null ( $reader )) {
$reader = new \GeoIp2\Database\Reader ( $database );
}
$lang = get_langfolder_cookie ();
$langMap = [
'chs' => 'zh-CN' ,
'cht' => 'zh-CN' ,
'en' => 'en' ,
];
$locale = $langMap [ $lang ] ? ? $lang ;
2022-07-23 15:05:32 +08:00
$locationInfo = \Nexus\Database\NexusDB :: remember ( " locations_ { $ip } " , 3600 , function () use ( $locale , $ip , $reader ) {
$info = [
'ip' => $ip ,
'version' => '' ,
'country' => '' ,
'city' => '' ,
2023-01-31 16:38:21 +08:00
'country_en' => '' ,
'city_en' => '' ,
2022-07-23 15:05:32 +08:00
];
try {
$record = $reader -> city ( $ip );
$countryName = $record -> country -> names [ $locale ] ? ? $record -> country -> names [ 'en' ] ? ? '' ;
$cityName = $record -> city -> names [ $locale ] ? ? $record -> city -> names [ 'en' ] ? ? '' ;
if ( isIPV4 ( $ip )) {
$info [ 'version' ] = 4 ;
} elseif ( isIPV6 ( $ip )) {
$info [ 'version' ] = 6 ;
2022-04-18 19:07:35 +08:00
}
2022-07-23 15:05:32 +08:00
$info [ 'country' ] = $countryName ;
2023-01-31 16:38:21 +08:00
$info [ 'country_en' ] = $record -> country -> names [ 'en' ] ? ? '' ;
2022-07-23 15:05:32 +08:00
$info [ 'city' ] = $cityName ;
2023-01-31 16:38:21 +08:00
$info [ 'city_en' ] = $record -> city -> names [ 'en' ] ? ? '' ;
2022-07-23 15:05:32 +08:00
} catch ( \Exception $exception ) {
do_log ( $exception -> getMessage () . $exception -> getTraceAsString (), 'error' );
2022-04-18 19:07:35 +08:00
}
2022-07-23 15:05:32 +08:00
return $info ;
2022-04-18 19:07:35 +08:00
});
2022-07-23 15:05:32 +08:00
do_log ( " ip: $ip , locale: $locale , result: " . nexus_json_encode ( $locationInfo ));
$name = sprintf ( '%s[v%s]' , $locationInfo [ 'city' ] ? ( $locationInfo [ 'city' ] . " · " . $locationInfo [ 'country' ]) : $locationInfo [ 'country' ], $locationInfo [ 'version' ]);
2021-06-07 15:41:47 +08:00
return [
2022-07-23 15:05:32 +08:00
'name' => $name ,
2021-06-07 15:41:47 +08:00
'location_main' => '' ,
'location_sub' => '' ,
'flagpic' => '' ,
'start_ip' => $ip ,
'end_ip' => $ip ,
2023-01-31 16:38:21 +08:00
'ip_version' => $locationInfo [ 'version' ],
'country_en' => $locationInfo [ 'country_en' ],
'city_en' => $locationInfo [ 'city_en' ],
2021-06-07 15:41:47 +08:00
];
}
2021-06-21 02:01:26 +08:00
function msgalert ( $url , $text , $bgcolor = " red " )
{
2022-04-17 21:54:25 +08:00
print ( " <table border= \" 0 \" cellspacing= \" 0 \" cellpadding= \" 10 \" ><tr><td style='border: none; padding: 10px; background: " . $bgcolor . " '> \n " );
2022-10-22 23:53:02 +08:00
print ( " <b><a href= \" " . $url . " \" target='_blank'><font color= \" white \" > " . $text . " </font></a></b> " );
2022-04-17 21:54:25 +08:00
print ( " </td></tr></table><br /> " );
2021-06-21 02:01:26 +08:00
}
2022-03-19 14:55:43 +08:00
function build_medal_image ( \Illuminate\Support\Collection $medals , $maxHeight = 200 , $withActions = false ) : string
2022-01-19 23:54:55 +08:00
{
$medalImages = [];
2023-01-29 20:00:58 +08:00
$wrapBefore = '<form><div style="display: flex;justify-content: center;margin-top: 10px;">' ;
$wrapAfter = '</div></form>' ;
2022-01-19 23:54:55 +08:00
foreach ( $medals as $medal ) {
2023-02-09 16:34:38 +08:00
$html = sprintf ( '<div style="display: flex;flex-direction: column;justify-content: space-between;margin-right: 10px"><div><img src="%s" title="%s" class="preview" style="max-height: %spx;max-width: %spx"/></div>' , $medal -> image_large , $medal -> name , $maxHeight , $maxHeight );
2022-03-19 14:55:43 +08:00
if ( $withActions ) {
2023-01-29 20:00:58 +08:00
$html .= sprintf (
'<div style="display: flex;flex-direction: column;align-items:flex-start"><span>%s: %s</span><span>%s: %s</span><label>%s: <input type="number" name="priority_%s" value="%s" style="width: 50px" placeholder="%s"></label>' ,
nexus_trans ( 'label.expire_at' ),
$medal -> pivot -> expire_at ? format_datetime ( $medal -> pivot -> expire_at ) : nexus_trans ( 'label.permanent' ),
nexus_trans ( 'medal.fields.bonus_addition_factor' ),
$medal -> bonus_addition_factor ? ? 0 ,
nexus_trans ( 'label.priority' ),
$medal -> pivot -> id ,
$medal -> pivot -> priority ? ? 0 ,
nexus_trans ( 'label.priority_help' )
);
2022-03-19 14:55:43 +08:00
$checked = '' ;
if ( $medal -> pivot -> status == \App\Models\UserMedal :: STATUS_WEARING ) {
$checked = ' checked' ;
}
2023-01-29 20:00:58 +08:00
$html .= sprintf ( '<label>%s<input type="checkbox" name="status_%s" value="1"%s></label>' , nexus_trans ( 'medal.action_wearing' ), $medal -> pivot -> id , $checked );
$html .= '</div>' ;
2022-03-19 14:55:43 +08:00
}
$html .= '</div>' ;
$medalImages [] = $html ;
2022-01-19 23:54:55 +08:00
}
2023-01-29 21:53:56 +08:00
if ( $withActions ) {
2023-02-10 16:52:30 +08:00
$medalImages [] = sprintf ( '<div style="display: flex;flex-direction: column;justify-content: space-between;margin-right: 10px"><div></div><div><input type="button" id="save-user-medal-btn" value="%s"/></div></div>' , nexus_trans ( 'label.save' ));
2023-01-29 21:53:56 +08:00
}
2022-03-19 14:55:43 +08:00
return $wrapBefore . implode ( '' , $medalImages ) . $wrapAfter ;
2022-01-19 23:54:55 +08:00
}
2022-03-08 15:08:56 +08:00
function insert_torrent_tags ( $torrentId , $tagIdArr , $sync = false )
{
2022-10-02 21:14:11 +08:00
$specialTags = \App\Models\Tag :: listSpecial ();
$canSetSpecialTag = user_can ( 'torrent-set-special-tag' );
2022-03-08 15:08:56 +08:00
$dateTimeStringNow = date ( 'Y-m-d H:i:s' );
if ( $sync ) {
sql_query ( " delete from torrent_tags where torrent_id = $torrentId " );
}
2022-03-18 21:50:42 +08:00
if ( empty ( $tagIdArr )) {
return ;
}
2022-03-08 15:08:56 +08:00
$insertTagsSql = 'insert into torrent_tags (`torrent_id`, `tag_id`, `created_at`, `updated_at`) values ' ;
$values = [];
foreach ( $tagIdArr as $tagId ) {
2022-10-02 21:14:11 +08:00
if ( in_array ( $tagId , $specialTags ) && ! $canSetSpecialTag ) {
do_log ( " special tag: $tagId , and user no permission " );
continue ;
}
2022-03-08 15:08:56 +08:00
$values [] = sprintf ( " (%s, %s, '%s', '%s') " , $torrentId , $tagId , $dateTimeStringNow , $dateTimeStringNow );
}
$insertTagsSql .= implode ( ', ' , $values );
do_log ( " [INSERT_TAGS], torrent: $torrentId with tags: " . nexus_json_encode ( $tagIdArr ));
sql_query ( $insertTagsSql );
}
2022-04-04 17:26:26 +08:00
function get_smile ( $num )
{
static $all ;
if ( is_null ( $all )) {
$all = [];
$prefix = getFullDirectory ( 'public' );
foreach ( glob ( getFullDirectory ( 'public/pic/smilies' ) . '/*' ) as $value ) {
$subPath = substr ( $value , strlen ( $prefix ));
$basename = basename ( $subPath );
$all [ strstr ( $basename , '.' , true )] = $subPath ;
}
}
return $all [ $num ] ? ? null ;
}
2022-08-04 00:48:42 +08:00
function get_filament_class_alias ( $class ) : string
2022-06-12 15:15:09 +08:00
{
2022-08-04 00:48:42 +08:00
return Str :: of ( $class )
-> replace ([ '/' , '\\' ], '.' )
-> explode ( '.' )
-> map ([ Str :: class , 'kebab' ])
-> implode ( '.' );
2022-06-12 15:15:09 +08:00
}
2022-04-21 20:41:29 +08:00
/**
* Calculate user seed bonus per hour
*
* @ param $uid
2022-05-05 22:19:48 +08:00
* @ param $torrentIdArr
2022-04-21 20:41:29 +08:00
* @ return array
* @ throws \Nexus\Database\DatabaseException
*/
2022-05-05 22:19:48 +08:00
function calculate_seed_bonus ( $uid , $torrentIdArr = null ) : array
2022-04-20 00:52:12 +08:00
{
2022-04-21 20:02:08 +08:00
$settingBonus = \App\Models\Setting :: get ( 'bonus' );
$donortimes_bonus = $settingBonus [ 'donortimes' ];
$perseeding_bonus = $settingBonus [ 'perseeding' ];
$maxseeding_bonus = $settingBonus [ 'maxseeding' ];
$tzero_bonus = $settingBonus [ 'tzero' ];
$nzero_bonus = $settingBonus [ 'nzero' ];
$bzero_bonus = $settingBonus [ 'bzero' ];
$l_bonus = $settingBonus [ 'l' ];
2022-04-20 00:52:12 +08:00
$sqrtof2 = sqrt ( 2 );
$logofpointone = log ( 0.1 );
$valueone = $logofpointone / $tzero_bonus ;
$pi = 3.141592653589793 ;
$valuetwo = $bzero_bonus * ( 2 / $pi );
$valuethree = $logofpointone / ( $nzero_bonus - 1 );
2022-04-21 20:02:08 +08:00
$timenow = time ();
2023-01-29 20:00:58 +08:00
$nowStr = date ( 'Y-m-d H:i:s' );
2022-04-20 00:52:12 +08:00
$sectoweek = 7 * 24 * 60 * 60 ;
2022-10-12 19:37:02 +08:00
$A = $official_a = $size = $official_size = 0 ;
$count = $torrent_peer_count = $official_torrent_peer_count = 0 ;
2022-05-05 22:19:48 +08:00
$logPrefix = " [CALCULATE_SEED_BONUS], uid: $uid , torrentIdArr: " . json_encode ( $torrentIdArr );
if ( $torrentIdArr !== null ) {
if ( empty ( $torrentIdArr )) {
$torrentIdArr = [ - 1 ];
}
2022-05-06 18:18:36 +08:00
$idStr = implode ( ',' , \Illuminate\Support\Arr :: wrap ( $torrentIdArr ));
2022-12-05 17:35:39 +08:00
$sql = " select torrents.id, torrents.added, torrents.size, torrents.seeders, 'NO_PEER_ID' as peerID, '' as last_action from torrents WHERE id in ( $idStr ) " ;
2022-05-06 18:18:36 +08:00
} else {
2022-12-05 17:35:39 +08:00
$sql = " select torrents.id, torrents.added, torrents.size, torrents.seeders, peers.id as peerID, peers.last_action from torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid = $uid AND peers.seeder ='yes' group by peers.torrent, peers.peer_id " ;
2022-05-05 22:19:48 +08:00
}
2022-09-25 16:33:52 +08:00
$tagGrouped = [];
2022-04-21 20:02:08 +08:00
$torrentResult = \Nexus\Database\NexusDB :: select ( $sql );
2022-09-25 16:33:52 +08:00
if ( ! empty ( $torrentResult )) {
$torrentIdArrReal = array_column ( $torrentResult , 'id' );
$tagResult = \Nexus\Database\NexusDB :: select ( sprintf ( " select torrent_id, tag_id from torrent_tags where torrent_id in (%s) " , implode ( ',' , $torrentIdArrReal )));
foreach ( $tagResult as $tagItem ) {
$tagGrouped [ $tagItem [ 'torrent_id' ]][ $tagItem [ 'tag_id' ]] = 1 ;
}
}
2022-09-25 16:49:56 +08:00
$officialTag = \App\Models\Setting :: get ( 'bonus.official_tag' );
2022-09-25 16:33:52 +08:00
$officialAdditionalFactor = \App\Models\Setting :: get ( 'bonus.official_addition' );
$zeroBonusTag = \App\Models\Setting :: get ( 'bonus.zero_bonus_tag' );
$zeroBonusFactor = \App\Models\Setting :: get ( 'bonus.zero_bonus_factor' );
2023-01-29 20:00:58 +08:00
$userMedalResult = \Nexus\Database\NexusDB :: select ( " select sum(bonus_addition_factor) as factor from medals where id in (select medal_id from user_medals where uid = $uid and (expire_at is null or expire_at > ' $nowStr ')) " );
$medalAdditionalFactor = floatval ( $userMedalResult [ 0 ][ 'factor' ] ? ? 0 );
2023-01-26 23:08:49 +08:00
do_log ( " $logPrefix , sql: $sql , count: " . count ( $torrentResult ) . " , officialTag: $officialTag , officialAdditionalFactor: $officialAdditionalFactor , zeroBonusTag: $zeroBonusTag , zeroBonusFactor: $zeroBonusFactor , medalAdditionalFactor: $medalAdditionalFactor " );
2022-12-05 17:35:39 +08:00
$last_action = " " ;
2022-04-21 20:02:08 +08:00
foreach ( $torrentResult as $torrent )
2022-04-20 00:52:12 +08:00
{
2022-12-05 17:35:39 +08:00
if ( $torrent [ 'last_action' ] > $last_action ) {
$last_action = $torrent [ 'last_action' ];
}
2022-10-12 19:37:02 +08:00
$size = bcadd ( $size , $torrent [ 'size' ]);
2022-04-20 00:52:12 +08:00
$weeks_alive = ( $timenow - strtotime ( $torrent [ 'added' ])) / $sectoweek ;
2022-09-25 16:33:52 +08:00
$gb_size = $gb_size_raw = $torrent [ 'size' ] / 1073741824 ;
if ( $zeroBonusTag && isset ( $tagGrouped [ $torrent [ 'id' ]][ $zeroBonusTag ]) && is_numeric ( $zeroBonusFactor )) {
$gb_size = $gb_size * $zeroBonusFactor ;
}
2022-04-20 00:52:12 +08:00
$temp = ( 1 - exp ( $valueone * $weeks_alive )) * $gb_size * ( 1 + $sqrtof2 * exp ( $valuethree * ( $torrent [ 'seeders' ] - 1 )));
$A += $temp ;
$count ++ ;
2022-04-21 20:02:08 +08:00
$torrent_peer_count ++ ;
2022-09-25 16:33:52 +08:00
$officialAIncrease = 0 ;
if ( $officialTag && isset ( $tagGrouped [ $torrent [ 'id' ]][ $officialTag ])) {
$officialAIncrease = $temp ;
2022-10-12 19:37:02 +08:00
$official_torrent_peer_count ++ ;
$official_size = bcadd ( $official_size , $torrent [ 'size' ]);
2022-09-25 16:33:52 +08:00
}
$official_a += $officialAIncrease ;
do_log ( sprintf (
" $logPrefix , torrent: %s, peer ID: %s, weeks: %s, size_raw: %s GB, size: %s GB, increase A: %s, increase official A: %s " ,
$torrent [ 'id' ], $torrent [ 'peerID' ], $weeks_alive , $gb_size_raw , $gb_size , $temp , $officialAIncrease
));
2022-04-20 00:52:12 +08:00
}
if ( $count > $maxseeding_bonus )
$count = $maxseeding_bonus ;
2022-09-25 16:33:52 +08:00
$seed_bonus = $seed_points = $valuetwo * atan ( $A / $l_bonus ) + ( $perseeding_bonus * $count );
2022-09-25 17:17:08 +08:00
//Official addition don't think about the minimum value
$official_bonus = $valuetwo * atan ( $official_a / $l_bonus );
2023-01-26 23:08:49 +08:00
$medal_bonus = $valuetwo * atan ( $A / $l_bonus );
2022-10-12 19:37:02 +08:00
$result = compact (
2022-12-05 17:35:39 +08:00
'seed_points' , 'seed_bonus' , 'A' , 'count' , 'torrent_peer_count' , 'size' , 'last_action' ,
2023-01-26 23:08:49 +08:00
'official_bonus' , 'official_a' , 'official_torrent_peer_count' , 'official_size' , 'medal_bonus'
2022-10-12 19:37:02 +08:00
);
2022-09-25 16:33:52 +08:00
$result [ 'donor_times' ] = $donortimes_bonus ;
$result [ 'official_additional_factor' ] = $officialAdditionalFactor ;
2023-01-26 23:08:49 +08:00
$result [ 'medal_additional_factor' ] = $medalAdditionalFactor ;
2022-09-25 16:33:52 +08:00
do_log ( " $logPrefix , result: " . json_encode ( $result ));
2022-04-20 00:52:12 +08:00
return $result ;
}
2022-08-04 13:02:55 +08:00
function calculate_harem_addition ( $uid )
{
2023-07-12 03:17:19 +08:00
// $harems = \App\Models\User::query()
// ->where('invited_by', $uid)
// ->where('status', \App\Models\User::STATUS_CONFIRMED)
// ->where('enabled', \App\Models\User::ENABLED_YES)
// ->get(['id']);
// $addition = 0;
// $haremsCount = $harems->count();
// foreach ($harems as $harem) {
// $result = calculate_seed_bonus($harem->id);
// $addition += $result['seed_points'];
// }
// do_log("[HAREM_ADDITION], user: $uid, haremsCount: $haremsCount ,addition: $addition");
$addition = \Nexus\Database\NexusDB :: table ( " users " )
-> where ( " invited_by " , $uid )
2022-08-04 13:02:55 +08:00
-> where ( 'status' , \App\Models\User :: STATUS_CONFIRMED )
-> where ( 'enabled' , \App\Models\User :: ENABLED_YES )
2023-07-12 03:17:19 +08:00
-> sum ( " seed_points_per_hour " )
;
do_log ( " [HAREM_ADDITION], user: $uid , addition: $addition " );
2022-08-04 13:02:55 +08:00
return $addition ;
}
2022-09-14 19:05:29 +08:00
2022-10-27 20:21:54 +08:00
function build_search_box_category_table ( $mode , $checkboxValue , $categoryHrefPrefix , $taxonomyHrefPrefix , $taxonomyNameLength , $checkedValues = '' , array $options = [])
2022-09-14 19:05:29 +08:00
{
2022-11-28 18:07:18 +08:00
parse_str ( $checkedValues , $checkedValuesArr );
2022-09-14 19:05:29 +08:00
$searchBox = \App\Models\SearchBox :: query () -> with ([ 'categories' , 'categories.icon' ]) -> findOrFail ( $mode );
2022-10-27 20:21:54 +08:00
$lang = get_langfolder_cookie ();
2022-09-14 19:05:29 +08:00
$withTaxonomies = [];
2022-10-27 20:21:54 +08:00
if ( $searchBox -> showsubcat ) {
//Keep the order
if ( ! empty ( $searchBox -> extra [ SearchBox :: EXTRA_TAXONOMY_LABELS ])) {
foreach ( $searchBox -> extra [ SearchBox :: EXTRA_TAXONOMY_LABELS ] as $taxonomyLabelInfo ) {
$torrentField = $taxonomyLabelInfo [ " torrent_field " ];
$showField = " show " . $torrentField ;
if ( $searchBox -> { $showField }) {
2022-11-14 19:02:42 +08:00
$withTaxonomies [ $torrentField ] = \App\Models\SearchBox :: $taxonomies [ $torrentField ][ 'table' ];
2022-10-27 20:21:54 +08:00
}
}
} else {
2022-11-14 19:02:42 +08:00
foreach ( \App\Models\SearchBox :: $taxonomies as $torrentField => $taxonomyTableModel ) {
2022-10-27 20:21:54 +08:00
$showField = " show " . $torrentField ;
if ( $searchBox -> { $showField }) {
2022-11-14 19:02:42 +08:00
$withTaxonomies [ $torrentField ] = $taxonomyTableModel [ 'table' ];
2022-10-27 20:21:54 +08:00
}
}
2022-09-14 19:05:29 +08:00
}
}
$html = '<table>' ;
2022-10-27 20:21:54 +08:00
if ( ! empty ( $options [ 'section_name' ])) {
$html .= sprintf ( '<caption><font class="big">%s</font></caption>' , $searchBox -> section_name [ $lang ] ? ? '' );
}
2022-09-14 19:05:29 +08:00
//Category
$html .= sprintf ( '<tr><td class="embedded" align="left">%s</td></tr>' , nexus_trans ( 'label.search_box.category' ));
2022-11-14 19:02:42 +08:00
/** @var \Illuminate\DataBase\Eloquent\Collection $categoryCollection */
2023-04-21 00:50:10 +08:00
$categoryCollection = $searchBox -> categories () -> orderBy ( 'sort_index' , 'desc' ) -> get ();
2022-11-14 19:02:42 +08:00
if ( ! empty ( $options [ 'select_unselect' ])) {
$categoryCollection -> push ( new \App\Models\Category ([ 'mode' => - 1 ]));
}
$categoryChunks = $categoryCollection -> chunk ( $searchBox -> catsperrow );
$checkPrefix = 'cat' ;
2022-09-14 19:05:29 +08:00
foreach ( $categoryChunks as $chunk ) {
$html .= '<tr>' ;
foreach ( $chunk as $item ) {
2022-11-14 19:02:42 +08:00
if ( $item -> mode != - 1 ) {
$checked = '' ;
2022-11-26 13:24:30 +08:00
if ( $checkedValues ) {
if (
str_contains ( $checkedValues , " [cat { $item -> id } ] " )
2022-11-28 18:07:18 +08:00
|| ( isset ( $checkedValuesArr [ " cat { $item -> id } " ]) && $checkedValuesArr [ " cat { $item -> id } " ] == 1 )
|| ( isset ( $checkedValuesArr [ " cat " ]) && $checkedValuesArr [ " cat " ] == $item -> id )
2022-11-26 13:24:30 +08:00
) {
$checked = " checked " ;
}
} elseif ( ! empty ( $options [ 'user_notifs' ])) {
$userNotifsKey = sprintf ( '[%s%s]' , 'cat' , $item -> id );
if ( str_contains ( $options [ 'user_notifs' ], $userNotifsKey )) {
$checked = ' checked' ;
}
2022-11-14 19:02:42 +08:00
}
$icon = $item -> icon ;
$iconFolder = trim ( $icon -> folder , '/' );
2022-11-26 02:15:36 +08:00
$langAndFile = sprintf ( '%s%s' , $icon -> multilang == 'yes' ? " $lang / " : " " , $item -> image );
if ( file_exists ( getFullDirectory ( " pic/category/ $iconFolder / $langAndFile " ))) {
$backgroundImagePath = " pic/category/ $iconFolder / $langAndFile " ;
2022-11-14 19:02:42 +08:00
} else {
2022-11-26 02:15:36 +08:00
$backgroundImagePath = " pic/category/ { $searchBox -> name } / $iconFolder / $langAndFile " ;
2022-11-14 19:02:42 +08:00
}
$tdContent = <<< TDCONTENT
< input type = " checkbox " id = " cat { $item -> id } " name = " cat { $item -> id } " value = " { $checkboxValue } " { $checked } />
< a href = " { $categoryHrefPrefix } cat= { $item -> id } " >< img src = " pic/cattrans.gif " class = " { $item -> class_name } " alt = " { $item -> name } " title = " { $item -> name } " style = " background-image: url( { $backgroundImagePath } ) " /></ a >
TDCONTENT ;
} else {
$tdContent = sprintf (
" <input name= \" %s_check \" value= \" %s \" class= \" btn medium \" type= \" button \" onclick= \" javascript:SetChecked('%s','%s_check','%s','%s',-1,10) \" > " ,
$checkPrefix , nexus_trans ( 'nexus.select_all' ), $checkPrefix , $checkPrefix , nexus_trans ( 'nexus.select_all' ), nexus_trans ( 'nexus.unselect_all' )
);
2022-09-14 19:05:29 +08:00
}
$td = <<< TD
< td align = " left " class = " bottom " style = " padding-bottom: 4px;padding-left: { $searchBox -> catpadding } px " >
2022-11-14 19:02:42 +08:00
$tdContent
2022-09-14 19:05:29 +08:00
</ td >
TD ;
$html .= $td ;
}
$html .= '</tr>' ;
}
//Taxonomy
2022-10-27 20:21:54 +08:00
foreach ( $withTaxonomies as $torrentField => $tableName ) {
2022-09-14 19:05:29 +08:00
if ( $taxonomyNameLength > 0 ) {
$namePrefix = substr ( $torrentField , 0 , $taxonomyNameLength );
} else {
$namePrefix = $torrentField ;
}
$html .= sprintf ( '<tr><td class="embedded" align="left">%s</td></tr>' , $searchBox -> getTaxonomyLabel ( $torrentField ));
2022-11-14 19:02:42 +08:00
/** @var \Illuminate\DataBase\Eloquent\Collection $taxonomyCollection */
$taxonomyCollection = \Nexus\Database\NexusDB :: table ( $tableName )
2022-10-27 20:21:54 +08:00
-> where ( function ( \Illuminate\Database\Query\Builder $query ) use ( $mode ) {
return $query -> where ( 'mode' , $mode ) -> orWhere ( 'mode' , 0 );
})
2023-04-21 00:50:10 +08:00
-> orderBy ( 'sort_index' , 'desc' )
2022-10-27 20:21:54 +08:00
-> get ()
2022-11-14 19:02:42 +08:00
;
$modelName = \App\Models\SearchBox :: $taxonomies [ $torrentField ][ 'model' ];
$checkPrefix = $torrentField ;
if ( ! empty ( $options [ 'select_unselect' ])) {
$taxonomyCollection -> push ( new $modelName ([ 'mode' => - 1 ]));
}
$taxonomyChunks = $taxonomyCollection -> chunk ( $searchBox -> catsperrow );
2022-09-14 19:05:29 +08:00
foreach ( $taxonomyChunks as $chunk ) {
$html .= '<tr>' ;
foreach ( $chunk as $item ) {
2022-11-14 19:02:42 +08:00
if ( $item -> mode != - 1 ) {
if ( $taxonomyHrefPrefix ) {
$afterInput = sprintf ( '<a href="%s%s=%s">%s</a>' , $taxonomyHrefPrefix , $namePrefix , $item -> id , $item -> name );
} else {
$afterInput = $item -> name ;
}
$checked = '' ;
2022-11-28 18:07:18 +08:00
do_log ( " toCheck: $checkedValues , $namePrefix - { $item -> id } " );
2022-11-26 13:24:30 +08:00
if ( $checkedValues ) {
if (
str_contains ( $checkedValues , " [ { $namePrefix } { $item -> id } ] " )
2022-11-28 18:07:18 +08:00
|| ( isset ( $checkedValuesArr [ " { $namePrefix } { $item -> id } " ]) && $checkedValuesArr [ " { $namePrefix } { $item -> id } " ] == 1 )
|| ( isset ( $checkedValuesArr [ $namePrefix ]) && $checkedValuesArr [ $namePrefix ] == $item -> id )
2022-11-26 13:24:30 +08:00
) {
$checked = ' checked' ;
}
2022-11-24 18:51:03 +08:00
} elseif ( ! empty ( $options [ 'user_notifs' ])) {
$userNotifsKey = sprintf ( '[%s%s]' , substr ( $torrentField , 0 , 3 ), $item -> id );
if ( str_contains ( $options [ 'user_notifs' ], $userNotifsKey )) {
$checked = ' checked' ;
}
2022-11-14 19:02:42 +08:00
}
$tdContent = <<< TDCONTENT
< label >< input type = " checkbox " id = " { $namePrefix } { $item -> id } " name = " { $namePrefix } { $item -> id } " value = " { $checkboxValue } " { $checked } /> $afterInput </ label >
TDCONTENT ;
2022-09-14 19:05:29 +08:00
} else {
2022-11-14 19:02:42 +08:00
$tdContent = sprintf (
" <input name= \" %s_check \" value= \" %s \" class= \" btn medium \" type= \" button \" onclick= \" javascript:SetChecked('%s','%s_check','%s','%s',-1,10) \" > " ,
$checkPrefix , nexus_trans ( 'nexus.select_all' ), $checkPrefix , $checkPrefix , nexus_trans ( 'nexus.select_all' ), nexus_trans ( 'nexus.unselect_all' )
);
2022-09-14 19:05:29 +08:00
}
$td = <<< TD
2022-10-27 20:21:54 +08:00
< td align = " left " class = " bottom " style = " padding-bottom: 4px;padding-left: { $searchBox -> catpadding } px " >
2022-11-14 19:02:42 +08:00
$tdContent
2022-09-14 19:05:29 +08:00
</ td >
TD ;
$html .= $td ;
}
$html .= '</tr>' ;
}
$html .= '</tr>' ;
}
$html .= '</table>' ;
return $html ;
}
2022-12-20 22:24:31 +08:00
function datetimepicker_input ( $name , $value = '' , $label = '' , array $options = [])
2022-09-17 18:55:26 +08:00
{
$lang = get_langfolder_cookie ( true );
if ( $lang == 'zh_CN' ) {
$lang = 'zh' ;
}
$lang = str_replace ( '_' , '-' , $lang );
2022-12-20 22:24:31 +08:00
$js = '' ;
if ( ! empty ( $options [ 'require_files' ])) {
\Nexus\Nexus :: css ( 'vendor/jquery-datetimepicker/jquery.datetimepicker.min.css' , 'footer' , true );
\Nexus\Nexus :: js ( 'vendor/jquery-datetimepicker/jquery.datetimepicker.full.min.js' , 'footer' , true );
$js = " jQuery.datetimepicker.setLocale(' { $lang } '); " ;
}
$id = " datetime-picker- $name " ;
$input = sprintf ( '%s<input type="text" id="%s" name="%s" value="%s" autocomplete="off" style="%s">' , $label , $id , $name , $value , $options [ 'style' ] ? ? '' );
$format = $options [ 'format' ] ? ? 'Y-m-d H:i' ;
$js .= <<< JS
2022-09-17 18:55:26 +08:00
jQuery ( " # { $id } " ) . datetimepicker ({
2022-12-20 22:24:31 +08:00
format : '{$format}'
2022-09-17 18:55:26 +08:00
})
JS ;
\Nexus\Nexus :: js ( $js , 'footer' , false );
return $input ;
}
2022-10-13 18:52:10 +08:00
function build_bonus_table ( array $user , array $bonusResult = [], array $options = [])
{
if ( empty ( $bonusResult )) {
$bonusResult = calculate_seed_bonus ( $user [ 'id' ]);
}
$officialTag = get_setting ( 'bonus.official_tag' );
$officialAdditionalFactor = get_setting ( 'bonus.official_addition' , 0 );
$haremFactor = get_setting ( 'bonus.harem_addition' );
$haremAddition = calculate_harem_addition ( $user [ 'id' ]);
$isDonor = is_donor ( $user );
$donortimes_bonus = get_setting ( 'bonus.donortimes' );
$baseBonusFactor = 1 ;
if ( $isDonor ) {
$baseBonusFactor = $donortimes_bonus ;
}
$baseBonus = $bonusResult [ 'seed_bonus' ] * $baseBonusFactor ;
2023-01-26 23:08:49 +08:00
$totalBonus = number_format (
$baseBonus
+ $haremAddition * $haremFactor
+ $bonusResult [ 'official_bonus' ] * $officialAdditionalFactor
+ $bonusResult [ 'medal_bonus' ] * $bonusResult [ 'medal_additional_factor' ]
, 3
);
2022-10-13 18:52:10 +08:00
$rowSpan = 1 ;
2023-01-26 23:08:49 +08:00
$hasHaremAddition = $hasOfficialAddition = $hasMedalAddition = false ;
2022-10-13 18:52:10 +08:00
if ( $haremFactor > 0 ) {
$rowSpan ++ ;
$hasHaremAddition = true ;
}
if ( $officialAdditionalFactor > 0 && $officialTag ) {
$rowSpan ++ ;
$hasOfficialAddition = true ;
}
2023-01-26 23:08:49 +08:00
if ( $bonusResult [ 'medal_additional_factor' ] > 0 ) {
$rowSpan ++ ;
$hasMedalAddition = true ;
}
2022-10-13 18:52:10 +08:00
$table = sprintf ( '<table cellpadding="5" style="%s">' , $options [ 'table_style' ] ? ? '' );
$table .= '<tr>' ;
$table .= sprintf ( '<td class="colhead">%s</td>' , nexus_trans ( 'bonus.table_thead.reward_type' ));
$table .= sprintf ( '<td class="colhead">%s</td>' , nexus_trans ( 'bonus.table_thead.count' ));
$table .= sprintf ( '<td class="colhead">%s</td>' , nexus_trans ( 'bonus.table_thead.size' ));
$table .= sprintf ( '<td class="colhead">%s</td>' , nexus_trans ( 'bonus.table_thead.a_value' ));
$table .= sprintf ( '<td class="colhead">%s</td>' , nexus_trans ( 'bonus.table_thead.bonus_base' ));
$table .= sprintf ( '<td class="colhead">%s</td>' , nexus_trans ( 'bonus.table_thead.factor' ));
$table .= sprintf ( '<td class="colhead">%s</td>' , nexus_trans ( 'bonus.table_thead.got_bonus' ));
$table .= sprintf ( '<td class="colhead">%s</td>' , nexus_trans ( 'bonus.table_thead.total' ));
$table .= '</tr>' ;
$table .= sprintf (
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td rowspan="%s">%s</td></tr>' ,
nexus_trans ( 'bonus.reward_types.basic' ),
$bonusResult [ 'torrent_peer_count' ],
mksize ( $bonusResult [ 'size' ]),
number_format ( $bonusResult [ 'A' ], 3 ),
number_format ( $bonusResult [ 'seed_bonus' ], 3 ),
$baseBonusFactor ,
number_format ( $baseBonus , 3 ),
$rowSpan ,
$totalBonus
);
2023-01-26 23:08:49 +08:00
if ( $hasMedalAddition ) {
$table .= sprintf (
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>' ,
nexus_trans ( 'bonus.reward_types.medal_addition' ),
$bonusResult [ 'torrent_peer_count' ],
mksize ( $bonusResult [ 'size' ]),
number_format ( $bonusResult [ 'A' ], 3 ),
number_format ( $bonusResult [ 'medal_bonus' ], 3 ),
$bonusResult [ 'medal_additional_factor' ],
number_format ( $bonusResult [ 'medal_bonus' ] * $bonusResult [ 'medal_additional_factor' ], 3 )
);
}
2022-10-13 18:52:10 +08:00
if ( $hasOfficialAddition ) {
$table .= sprintf (
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>' ,
nexus_trans ( 'bonus.reward_types.official_addition' ),
$bonusResult [ 'official_torrent_peer_count' ],
mksize ( $bonusResult [ 'official_size' ]),
number_format ( $bonusResult [ 'official_a' ], 3 ),
number_format ( $bonusResult [ 'official_bonus' ], 3 ),
$officialAdditionalFactor ,
number_format ( $bonusResult [ 'official_bonus' ] * $officialAdditionalFactor , 3 )
);
}
if ( $hasHaremAddition ) {
$table .= sprintf (
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>' ,
nexus_trans ( 'bonus.reward_types.harem_addition' ),
'--' ,
'--' ,
'--' ,
number_format ( $haremAddition , 3 ),
$haremFactor ,
number_format ( $haremAddition * $haremFactor , 3 )
);
}
2023-01-26 23:08:49 +08:00
2022-10-13 18:52:10 +08:00
$table .= '</table>' ;
return [
'table' => $table ,
'has_harem_addition' => $hasHaremAddition ,
'harem_addition_factor' => $haremFactor ,
'has_official_addition' => $hasOfficialAddition ,
'official_addition_factor' => $officialAdditionalFactor ,
2023-01-26 23:08:49 +08:00
'has_medal_addition' => $hasMedalAddition ,
'medal_addition_factor' => $bonusResult [ 'medal_additional_factor' ],
2022-10-13 18:52:10 +08:00
];
}
2022-10-22 20:52:08 +08:00
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 ;
}
2022-12-08 03:48:20 +08:00
2023-02-11 16:08:48 +08:00
function torrent_name_for_admin ( \App\Models\Torrent | null $torrent , $withTags = false , $length = 40 )
2022-12-08 03:48:20 +08:00
{
2023-01-11 05:05:18 +08:00
if ( empty ( $torrent )) {
return '' ;
}
2022-12-08 03:48:20 +08:00
$name = sprintf (
'<div class="text-primary-600 transition hover:underline hover:text-primary-500 focus:underline focus:text-primary-500"><a href="/details.php?id=%s" target="_blank" title="%s">%s</a></div>' ,
2023-02-11 16:08:48 +08:00
$torrent -> id , $torrent -> name , Str :: limit ( $torrent -> name , $length )
2022-12-08 03:48:20 +08:00
);
$tags = '' ;
if ( $withTags ) {
$tags = sprintf ( ' <div>%s</div>' , $torrent -> tagsFormatted );
}
return new HtmlString ( '<div class="flex">' . $name . $tags . '</div>' );
}
function username_for_admin ( int $id )
{
return new HtmlString ( get_username ( $id , false , true , true , true ));
}
2023-04-20 02:08:09 +08:00
function can_view_post ( $uid , $post )
{
static $topics = [];
static $protectedForumIdArr ;
static $forumMods ;
if ( ! is_array ( $post )) {
$post = \App\Models\Post :: query () -> findOrFail ( intval ( $post )) -> toArray ();
}
$topicId = $post [ 'topicid' ];
if ( ! isset ( $topics [ $topicId ])) {
$topics [ $topicId ] = \App\Models\Topic :: query () -> findOrFail ( $topicId );
}
/** @var \App\Models\Topic $topicInfo */
$topicInfo = $topics [ $topicId ];
$forumId = $topicInfo -> forumid ;
if ( is_null ( $protectedForumIdArr )) {
$protectedForumIdArr = [];
$protectedForumIds = \Nexus\Database\NexusDB :: remember ( " setting_protected_forum " , 600 , function () {
return \App\Models\Setting :: getByName ( 'misc.protected_forum' );
});
$protectedForumIdArr = $protectedForumIds ? preg_split ( " /[, \ s]+/ " , $protectedForumIds ) : [];
}
if ( is_null ( $forumMods )) {
$forumMods = [];
$results = \App\Models\ForumMod :: query () -> get ();
foreach ( $results as $item ) {
$forumMods [ $item -> forumid ] = $item -> userid ;
}
}
$isForumMod = isset ( $forumMods [ $forumId ]) && $forumMods [ $forumId ] == $uid ;
$log = sprintf (
" uid: $uid , class: %s, post: { $post [ 'id' ] } , forumId: $forumId , protectedForumIdArr: %s, forumMods: %s, isForumMod: %s " ,
get_user_class (), json_encode ( $protectedForumIdArr ), json_encode ( $forumMods ), $isForumMod
);
if (
in_array ( $forumId , $protectedForumIdArr )
&& get_user_class () < \App\Models\User :: CLASS_ADMINISTRATOR
&& $uid != $post [ 'userid' ]
&& $uid != $topicInfo -> userid
&& ! $isForumMod
) {
do_log ( " $log , FALSE " );
return false ;
}
do_log ( " $log , TRUE " );
return true ;
}
2020-12-26 01:42:23 +08:00
?>