" .
"| ");
}
function end_main_frame()
{
print(" |
\n");
}
function begin_frame($caption = "", $center = false, $padding = 10, $width="100%", $caption_center="left")
{
$tdextra = "";
if ($center)
$tdextra .= " align=\"center\"";
print(($caption ? "\n");
end_frame();
print("
/
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')){
$res3 = sql_query("SELECT connectable FROM peers WHERE userid=" . sqlesc($CURUSER["id"]) . " order by id desc LIMIT 1");
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 = "".$lang_functions['text_yes']."";
elseif ($connect == 'no')
$connectable = "".$lang_functions['text_no']."";
else
$connectable = $lang_functions['text_unknown'];
//// check every 60 seconds //////////////////
$activeseed = $Cache->get_value('user_'.$CURUSER["id"].'_active_seed_count');
if ($activeseed == ""){
$activeseed = get_row_count("peers","WHERE userid=" . sqlesc($CURUSER["id"]) . " AND seeder='yes'");
$Cache->cache_value('user_'.$CURUSER["id"].'_active_seed_count', $activeseed, 60);
}
$activeleech = $Cache->get_value('user_'.$CURUSER["id"].'_active_leech_count');
if ($activeleech == ""){
$activeleech = get_row_count("peers","WHERE userid=" . sqlesc($CURUSER["id"]) . " AND seeder='no'");
$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);
}
$inboxpic = " ";
// $attend_desk = new Attendance($CURUSER['id']);
// $attendance = $attend_desk->check();
$attendanceRep = new \App\Repositories\AttendanceRepository();
$attendance = $attendanceRep->getAttendance($CURUSER['id'], date('Ymd'))
?>
,
[]
[]
= UC_MODERATOR) { ?> []
= UC_SYSOP) { ?> []
[]
[]:
'.$lang_functions['text_attended'].'', $attendance->points, $CURUSER['attendance_card']); }else{ printf(' %s', $lang_functions['text_attendance']);}?>
[]
[]
[]: where('inviter', $CURUSER['id'])->where('invitee', '')->where('expired_at', '>', now())->count())?>
= \App\Models\User::getAccessAdminClassMin()) printf('[%s]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?>
H&R: %s]', (new \App\Repositories\HitAndRunRepository())->getStatusStats($CURUSER['id']))?>
%s]', $CURUSER['id'], (new \App\Repositories\ClaimRepository())->getStats($CURUSER['id']))?>
|
|
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(
" ".$totalcheaters
." ".$totalreports
);
}
print(" ");
print(" ");
print ' ';
//echo $lang_functions['text_the_time_is_now'].$datum['hours'].":".$datum['minutes'] . ' ';
// $cacheKey = "staff_message_count_" . $CURUSER['id'];
// $totalsm = $Cache->get_value($cacheKey);
$totalsm = \App\Repositories\MessageRepository::getStaffMessageCountCache($CURUSER['id'], 'total');
if ($totalsm === false){
$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 (" ".$totalsm." ");
}
print("".$inboxpic." ".($messages ? $messages." (".$unread.$lang_functions['text_message_new'].")" : "0"));
print(" ".($outmessages ? $outmessages : "0"));
?>
|
|
|
|
enable_ad()){
$belownavad=$Advertisement->get_ad('belownav');
if ($belownavad)
echo " ".$belownavad[0]." ";
}
if ($msgalert)
{
$spStateGlobal = get_global_sp_state();
if ($spStateGlobal != \App\Models\Torrent::PROMOTION_NORMAL) {
$torrentGlobalStateRow = \Nexus\Database\NexusDB::cache_get(\App\Models\Setting::TORRENT_GLOBAL_STATE_CACHE_KEY);
$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");
}
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");
}
\App\Utils\MsgAlert::getInstance()->render();
/*
$pending_invitee = $Cache->get_value('user_'.$CURUSER["id"].'_pending_invitee_count');
if ($pending_invitee == ""){
$pending_invitee = get_row_count("users","WHERE status = 'pending' AND invited_by = ".sqlesc($CURUSER['id']));
$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'];
msgalert("invite.php?id=".$CURUSER['id'],$text, "red");
}*/
$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");
}
}
//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');
if ($nummessages === false){
$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");
}
//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');
}
}
//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');
}
}
if (user_can('staffmem'))
{
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);
}
if($complaints) {
msgalert('complains.php?action=list', sprintf($lang_functions['text_complains'], is_or_are($complaints), $complaints, add_s($complaints)), 'darkred');
}
$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");
}
$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");
}
}
//show the exam info
$exam = new \Nexus\Exam\Exam();
$currentExam = $exam->getCurrent($CURUSER['id']);
if (!empty($currentExam['html'])) {
msgalert("messages.php", $currentExam['html'], $currentExam['exam']->background_color ?? 'blue');
}
}
if ($offlinemsg)
{
print("| \n");
print("".$lang_functions['text_website_offline_warning']."");
print(" |
\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;
global $hook;
print(" |
");
print("");
if ($analyticscode_tweak)
print("\n".$analyticscode_tweak."\n");
// $hook->dump();
do_action('nexus_footer');
foreach (\Nexus\Nexus::getAppendFooters() as $value) {
print($value);
}
$js = <<
JS;
print($js);
print('
');
print("");
//echo replacePngTags(ob_get_clean());
// unset($_SESSION['queries']);
}
function genbark($x,$y) {
stdhead($y);
print("" . htmlspecialchars($y) . "
\n");
print("" . htmlspecialchars($x) . "
\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("Not Found
\n");
exit();
}
function logincookie($id, $passhash, $updatedb = 1, $expires = 0x7fffffff, $securelogin=false, $ssl=false, $trackerssl=false)
{
if ($expires != 0x7fffffff)
$expires = time()+$expires;
setcookie("c_secure_uid", base64($id), $expires, "/", "", false, true);
setcookie("c_secure_pass", $passhash, $expires, "/", "", false, true);
if($ssl)
setcookie("c_secure_ssl", base64("yeah"), $expires, "/", "", false, true);
else
setcookie("c_secure_ssl", base64("nope"), $expires, "/", "", false, true);
if($trackerssl)
setcookie("c_secure_tracker_ssl", base64("yeah"), $expires, "/", "", false, true);
else
setcookie("c_secure_tracker_ssl", base64("nope"), $expires, "/", "", false, true);
if ($securelogin)
setcookie("c_secure_login", base64("yeah"), $expires, "/", "", false, true);
else
setcookie("c_secure_login", base64("nope"), $expires, "/", "", false, true);
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;
setcookie("c_lang_folder", $folder, $expires, "/", "", false, true);
}
function get_protocol_prefix()
{
global $securelogin;
if (isHttps()) {
return "https://";
}
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://";
}
}
}
function get_langid_from_langcookie($lang = '')
{
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__);
return $row['id'];
}
function make_folder($pre, $folder_name)
{
$path = $pre . $folder_name;
$path = ROOT_PATH . ltrim($path, './');
do_log($path);
if(!is_dir($path))
mkdir($path,0777,true);
return $path;
}
function logoutcookie() {
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);
}
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) {
if (nexus()->getScript() == 'ajax') {
exit(fail('Not login!', $_POST));
}
if ($mainpage) {
nexus_redirect("login.php");
} else {
$to = $_SERVER["REQUEST_URI"];
$to = basename($to);
nexus_redirect("login.php?returnto=" . rawurlencode($to));
}
exit();
}
// do_log("[USER]: " . $CURUSER['id']);
}
function deletetorrent($id, $notify = false) {
$idArr = is_array($id) ? $id : [$id];
$torrentInfo = \App\Models\Torrent::query()
->whereIn("id", $idArr)
->get()
->KeyBy("id")
;
$torrentRep = new \App\Repositories\TorrentRepository();
$idStr = implode(', ', $idArr ?: [0]);
$torrent_dir = get_setting('main.torrent_dir');
\Nexus\Database\NexusDB::statement("DELETE FROM torrents WHERE id in ($idStr)");
//delete by torrent, make sure user is deleted
\Nexus\Database\NexusDB::statement("DELETE FROM snatched WHERE torrentid in ($idStr) and not exists (select 1 from users where id = snatched.userid)");
foreach(array("peers", "files", "comments") as $x) {
\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)");
foreach ($torrentInfo as $_id => $info) {
if ($torrentInfo->has($_id)) {
$torrentRep->delPiecesHashCache($torrentInfo->get($_id)->pieces_hash);
}
do_log("delete torrent: $_id", "error");
unlink(getFullDirectory("$torrent_dir/$_id.torrent"));
\App\Models\TorrentOperationLog::add([
'torrent_id' => $_id,
'uid' => get_user_id(),
'action_type' => \App\Models\TorrentOperationLog::ACTION_TYPE_DELETE,
'comment' => '',
], $notify);
}
$meiliSearchRep = new \App\Repositories\MeiliSearchRepository();
$meiliSearchRep->deleteDocuments($idArr);
if (is_int($id)) {
do_action("torrent_delete", $id);
fire_event("torrent_deleted", $torrentInfo->get($id));
}
}
function pager($rpp, $count, $href, $opts = array(), $pagename = "page") {
global $lang_functions,$add_key_shortcut;
$pages = ceil($count / $rpp);
if (empty($opts["lastpagedefault"]))
$pagedefault = 0;
else {
$pagedefault = floor(($count - 1) / $rpp);
if ($pagedefault < 0)
$pagedefault = 0;
}
if (isset($_GET[$pagename])) {
$page = intval($_GET[$pagename] ?? 0);
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 = "<< ".$lang_functions['text_prev']."";
if ($page >= 1) {
$pager .= "";
$pager .= $as;
$pager .= "";
}
else
$pager .= "".$as."";
$pager .= " ";
$as = "".$lang_functions['text_next']." >>";
if ($page < $mp && $mp >= 0) {
$pager .= "";
$pager .= $as;
$pager .= "";
}
else
$pager .= "".$as."";
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[] = "$text";
else
$pagerarr[] = "$text";
}
$pagerstr = join(" | ", $pagerarr);
$pagertop = "\n";
$pagerbottom = "\n";
}
else {
$pagertop = "\n";
$pagerbottom = $pagertop;
}
$start = $page * $rpp;
$add_key_shortcut = key_shortcut($page,$pages-1);
return array($pagertop, $pagerbottom, "LIMIT $start,$rpp", $start, $rpp, $page);
}
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');
$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');
$userInfoArr = \App\Models\User::query()->find($uidArr, $neededColumns)->keyBy('id');
foreach ($rows as $row)
{
// $userRow = get_user_row($row['user']);
$userInfo = $userInfoArr->get($row['user'], \App\Models\User::defaultUser());
$userRow = $userInfo->toArray();
if ($count>=1)
{
if ($Advertisement->enable_ad()){
if (!empty($commentad[$count-1]))
echo "".$commentad[$count-1]."
";
}
}
print("| #" . $row["id"] . " ".$lang_functions['text_by']."");
print(get_username($row["user"],false,true,true,false,false,true));
print(" ".$lang_functions['text_at']."".gettime($row["added"]).
($row["editedby"] && user_can('commanage') ? " - [".$lang_functions['text_view_original']."]" : "") . " | |
");
$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 = "
".$lang_functions['text_last_edited_by'].get_username($row['editedby']).$lang_functions['text_edited_at'].$lastedittime."
\n";
}
print("\n");
$secs = 900;
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - $secs))); // calculate date.
print("\n");
print("| ".return_avatar_image($avatar)." | \n");
print(" ".$text.$text_editby." | \n");
print("
\n");
$actionbar = "
".
"
".(user_can('commanage') ? "
" : "").($row["user"] == $CURUSER["id"] || get_user_class() >= $commanage_class ? "
"."" : "");
print(" ".("'".$userRow['last_access']."'"> $dt ? " ":" " )."![\"".$lang_functions['title_send_message_to'].htmlspecialchars($userRow["username"])."\" \"PM\"](\"pic/trans.gif\") ![\"".$lang_functions['title_report_this_comment']."\" \"Report\"](\"pic/trans.gif\") | ".$actionbar." | ");
print("
\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();
$res = sql_query("SELECT id, mode, name, image FROM categories WHERE mode = ".sqlesc($catmode)." ORDER BY sort_index desc");
while ($row = mysql_fetch_array($res))
$ret[] = $row;
$Cache->cache_value('category_list_mode_'.$catmode, $ret, 3600);
}
return $ret;
}
function searchbox_item_list(string $table, int $mode){
global $Cache;
$cacheKey = "{$table}_list_mode_{$mode}";
if (!$ret = $Cache->get_value($cacheKey)){
$ret = array();
$sql = "SELECT * FROM $table";
if ($mode > 0) {
$sql .= " where (mode = '$mode' or mode = 0)";
}
$sql .= " ORDER BY sort_index, id";
$res = sql_query($sql);
while ($row = mysql_fetch_array($res))
$ret[] = $row;
$Cache->cache_value($cacheKey, $ret, 3600);
}
return $ret;
}
function langlist($type, $enabled = null) {
global $Cache;
$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;
}
function linkcolor($num) {
if (!$num)
return "red";
// if ($num == 1)
// return "yellow";
return "green";
}
function writecomment($userid, $comment, $oldModcomment = null) {
\App\Models\UserModifyLog::query()->create(['user_id' => $userid, 'content' => date("Y-m-d") . " - " . $comment]);
// if (is_null($oldModcomment)) {
// $res = sql_query("SELECT modcomment FROM users WHERE id = '$userid'") or sqlerr(__FILE__, __LINE__);
// $arr = mysql_fetch_assoc($res);
// $modcomment = date("Y-m-d") . " - " . $comment . "" . ($arr['modcomment'] != "" ? "\n" : "") . $arr['modcomment'];
// } else {
// $modcomment = date("Y-m-d") . " - " . $comment . "" . ($oldModcomment != "" ? "\n" : "") .$oldModcomment;
// }
// $modcom = sqlesc($modcomment);
// do_log("update user: $userid prepend modcomment: $comment, with oldModcomment: $oldModcomment");
// 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);
$ret[] = 0;
}
}
}
return $ret;
}
function get_torrent_bookmark_state($userid, $torrentid, $text = false)
{
global $lang_functions;
$userid = intval($userid ?? 0);
$torrentid = intval($torrentid ?? 0);
$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'] : "
");
else
$act = ($text == true ? $lang_functions['title_delbookmark_torrent'] : "
");
return $act;
}
function torrenttable($rows, $variant = "torrent", $searchBoxId = 0) {
global $Cache;
global $lang_functions;
global $CURUSER, $waitsystem;
global $showextinfo;
global $torrentmanage_class, $smalldescription_main, $enabletooltip_tweak, $staffmem_class;
global $CURLANGDIR;
$torrent = new Nexus\Torrent\Torrent();
$torrentRep = new \App\Repositories\TorrentRepository();
$imdb = new \Nexus\Imdb\Imdb();
$torrentIdArr = $ownerIdArr = [];
foreach($rows as $row) {
$torrentIdArr[] = $row['id'];
$ownerIdArr[] = $row['owner'];
}
unset($row);
$enableImdb = get_setting("main.showimdbinfo") == 'yes';
$enablePtGen = get_setting('main.enable_pt_gen_systemyes') == 'yes';
$torrentSeedingLeechingStatus = $torrent->listLeechingSeedingStatus($CURUSER['id'], $torrentIdArr);
$tagRep = new \App\Repositories\TagRepository();
$torrentTagCollection = \App\Models\TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->get();
$torrentTagResult = $torrentTagCollection->groupBy('torrent_id');
$showCover = false;
$showSeedBoxIcon = false;
if ($searchBoxId) {
$searchBoxExtra = get_searchbox_value($searchBoxId, "extra");
if (!empty($searchBoxExtra[\App\Models\SearchBox::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST])) {
$showCover = true;
}
$showSeedBoxIcon = get_setting('seed_box.enabled') == 'yes';
if (empty($searchBoxExtra[\App\Models\SearchBox::EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST])) {
$showSeedBoxIcon = false;
}
}
//seedBoxIcon
if ($showSeedBoxIcon) {
$seedBoxRep = new \App\Repositories\SeedBoxRepository();
$seedBoxPeerInfo = \App\Models\Peer::query()
->whereIn('torrent', $torrentIdArr)
->where('seeder', 'yes')
->where('is_seed_box', '1')
->get(['torrent', 'is_seed_box'])
->keyBy('torrent');
}
$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 = "";
// }
$time_now = TIMENOW;
if ($last_browse > $time_now) {
$last_browse=$time_now;
}
$wait = 0;
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;
}
?>
$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 . "&";
}
$sort = $_GET['sort'] ?? '';
$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");
}
?>
|
|
".$lang_functions['col_wait']."\n");
}
if ($CURUSER['showcomnum'] != 'no') { ?>
|
![<?php echo ($CURUSER['timetype'] != 'timealive' ? $lang_functions['title_time_added'] : $lang_functions['title_time_alive'])?> time](pic/trans.gif) |
![<?php echo $lang_functions['title_size'] ?> size](pic/trans.gif) |
![<?php echo $lang_functions['title_number_of_seeders'] ?> seeders](pic/trans.gif) |
![<?php echo $lang_functions['title_number_of_leechers'] ?> leechers](pic/trans.gif) |
![<?php echo $lang_functions['title_number_of_snatched']?> snatched](pic/trans.gif) |
|
|
\n");
print("");
if (isset($row["category"])) {
print(return_category_image($row["category"], "?"));
if ($has_secondicon){
print(get_second_icon($row));
}
}
else
print("-");
print(" | \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
$max_length_of_torrent_name = 200;
elseif ($CURUSER['fontsize'] == 'large')
$max_length_of_torrent_name = 120;
elseif ($CURUSER['fontsize'] == 'small')
$max_length_of_torrent_name = 160;
else $max_length_of_torrent_name = 140;
if($count_dispname > $max_length_of_torrent_name)
$dispname=mb_substr($dispname, 0, $max_length_of_torrent_name-2,"UTF-8") . "..";
if ($CURUSER['appendsticky'] == 'yes') {
$posStates = \App\Models\Torrent::listPosStates();
$stickyicon = str_repeat("
", $posStates[$row['pos_state']]['icon_counts'] ?? 0);
} else {
$stickyicon = "";
}
$stickyicon = apply_filter('sticky_icon', $stickyicon, $row);
$sp_torrent = get_torrent_promotion_append($row['sp_state'],"",true,$row["added"], $row['promotion_time_type'], $row['promotion_until'], $row['__ignore_global_sp_state'] ?? false);
$hrImg = get_hr_img($row, $row['search_box_id']);
//cover
$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');
}
}
if (empty($coverSrc) && !empty($row['cover'])) {
$coverSrc = $row['cover'];
}
$tdCover = sprintf(' | ', $coverSrc);
}
print("$tdCover".$stickyicon."".htmlspecialchars($dispname)."");
$picked_torrent = "";
if ($CURUSER['appendpicked'] != 'no'){
if($row['picktype']=="hot")
$picked_torrent = " [".$lang_functions['text_hot']."]";
elseif($row['picktype']=="classic")
$picked_torrent = " [".$lang_functions['text_classic']."]";
elseif($row['picktype']=="recommended")
$picked_torrent = " [".$lang_functions['text_recommended']."]";
}
if ($CURUSER['appendnew'] != 'no' && strtotime($row["added"]) >= $last_browse)
print(" (".$lang_functions['text_new_uppercase'].")");
$banned_torrent = ($row["banned"] == 'yes' ? " (".$lang_functions['text_banned'].")" : "");
$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);
$approvalStatusIcon = $torrentRep->renderApprovalStatus($row['approval_status']);
if ($showSeedBoxIcon && $seedBoxPeerInfo->has($row['id'])) {
$seedBoxIcon = $seedBoxRep->getSeedBoxIcon();
} else {
$seedBoxIcon = '';
}
$paidIcon = $torrentRep->getPaidIcon($row);
$titleSuffix = $banned_torrent.$paidIcon.$picked_torrent.$sp_torrent.$sp_torrent_sub. $hrImg . $seedBoxIcon . $approvalStatusIcon;
$titleSuffix = apply_filter('torrent_title_suffix', $titleSuffix, $row);
print($titleSuffix);
/**
* render tags
*/
$tagOwns = $torrentTagResult->get($id);
if ($tagOwns) {
$tags = $tagRep->renderSpan($row['search_box_id'], $tagOwns->pluck('tag_id')->toArray());
} else {
$tags = '';
}
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") . "..";
}
$dissmall_descr = $tags . htmlspecialchars($dissmall_descr);
print($dissmall_descr == "" ? "" : " ".$dissmall_descr);
} else {
print($tags ? " $tags" : "");
}
//progress bar
if (isset($torrentSeedingLeechingStatus[$row['id']])) {
echo $torrent->renderProgressBar($torrentSeedingLeechingStatus[$row['id']]['active_status'], $torrentSeedingLeechingStatus[$row['id']]['progress']);
}
print(" | ");
if ($enableImdb || $enablePtGen) {
echo $torrent->renderTorrentsPageAverageRating($row);
}
$act = "";
if ($CURUSER["dlicon"] != 'no' && $CURUSER["downloadpos"] != "no")
$act .= " " ;
if ($CURUSER["bmicon"] == 'yes'){
$bookmark = " href=\"javascript: bookmark(".$id.",".$counter.");\"";
$act .= ($act ? " " : "")."".get_torrent_bookmark_state($CURUSER['id'], $id)."";
}
print("".$act." | \n");
print("
| ");
if ($wait)
{
$elapsed = floor((TIMENOW - strtotime($row["added"])) / 3600);
if ($elapsed < $wait)
{
$color = dechex(floor(127*($wait - $elapsed)/48 + 128)*65536);
print("" . number_format($wait - $elapsed) . $lang_functions['text_h']." | \n");
}
else
print("".$lang_functions['text_none']." | \n");
}
if ($CURUSER['showcomnum'] != 'no')
{
print("");
$nl = "";
//comments
$nl = " ";
if (!$row["comments"]) {
print("" . $row["comments"] . "");
} 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 ? "(".$lang_functions['text_new_uppercase'].") " : "").$lang_functions['text_last_commented_by'].get_username($lastcom['user']) . $lastcomtime." ". 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("". ($hasnewcom ? "" : ""). $row["comments"] .($hasnewcom ? "" : ""). "");
}
print(" | ");
}
$time = $row["added"];
$time = gettime($time,false,true);
print("". $time. " | ");
//size
print("" . mksize_compact($row["size"])." | ");
if ($row["seeders"]) {
$ratio = ($row["leechers"] ? ($row["seeders"] / $row["leechers"]) : 1);
$ratiocolor = get_slr_color($ratio);
print("".($ratiocolor ? "" . number_format($row["seeders"]) . "" : number_format($row["seeders"]))." | \n");
}
else
print("" . number_format($row["seeders"]) . " | \n");
if ($row["leechers"]) {
print("" .
number_format($row["leechers"]) . " | \n");
}
else
print("0 | \n");
if ($row["times_completed"] >=1)
print("" . number_format($row["times_completed"]) . " | \n");
else
print("" . number_format($row["times_completed"]) . " | \n");
if (
$row["anonymous"] == "yes"
&& (user_can('viewanonymous') || (isset($row['owner']) && $row['owner'] == $CURUSER['id']))
) {
print("".$lang_functions['text_anonymous']." ".(isset($row["owner"]) ? "(" . get_username($row["owner"]) .")" : "".$lang_functions['text_orphaned']."") . " | \n");
}
elseif ($row["anonymous"] == "yes")
{
print("".$lang_functions['text_anonymous']." | \n");
}
else
{
print("" . (isset($row["owner"]) ? get_username($row["owner"]) : "".$lang_functions['text_orphaned']."") . " | \n");
}
if (user_can('torrentmanage'))
{
if (user_can('torrent-delete')) {
print(" ");
}
print("
![\"".$lang_functions['text_edit']."\" \"E\"](\"pic/trans.gif\") | \n");
}
print("\n");
$counter++;
}
print("
");
if ($CURUSER['appendpromotion'] == 'highlight')
print(" ".$lang_functions['text_promoted_torrents_note']."
\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();
$id = (int)$id;
if (func_num_args() == 1 && isset($usernameArray[$id])) { //One argument=is default display of username. Get it directly from static array if available
return $usernameArray[$id];
}
$arr = get_user_row($id);
if ($arr){
if ($big)
{
$donorpic = "starbig";
$leechwarnpic = "leechwarnedbig";
$warnedpic = "warnedbig";
$disabledpic = "disabledbig";
$marginLeft = '4pt';
$medalSize = '16px';
$medalClass = 'nexus-username-medal-big';
$style = "style='margin-left: $marginLeft'";
}
else
{
$donorpic = "star";
$leechwarnpic = "leechwarned";
$warnedpic = "warned";
$disabledpic = "disabled";
$marginLeft = '2pt';
$medalSize = '11px';
$medalClass = 'nexus-username-medal';
$style = "style='margin-left: $marginLeft'";
}
$pics = $arr["donor"] == "yes" && ($arr['donoruntil'] === null || $arr['donoruntil'] < '1970' || $arr['donoruntil'] >= date('Y-m-d H:i:s')) ? "
" : "";
if ($arr["enabled"] == "yes")
$pics .= ($arr["leechwarn"] == "yes" ? "
" : "") . ($arr["warned"] == "yes" ? "
" : "");
else
$pics .= "
\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 = "{$username}";
}
if ($bold) {
if ($hasSetRainbow) {
$username = "{$username}";
} else {
$hasSetRainbow = true;
$username = "{$username}";
}
}
// $username = ($underline == true ? "" . $arr['username'] . "" : $arr['username']);
// $username = ($bold == true ? "" . $username . "" : $username);
//medal
$medalHtml = '';
foreach ($arr['wearing_medals'] ?? [] as $medal) {
$medalHtml .= sprintf(
'
',
$medal['image_large'], $medal['name'], $medalClass, $medalSize, $medalSize, $marginLeft
);
}
$href = getSchemeAndHttpHost() . "/userdetails.php?id=$id";
$username = ($link == true ? "" . $username . "" : $username) . $pics . ($withtitle == true ? " (" . ($arr['title'] == "" ? get_user_class_name($arr['class'],false,true,true, ['with_alias' => true]) : "".htmlspecialchars($arr['title'])) . ")" : "");
$username = "" . ( $bracket == true ? "(" . $username . ")" : $username) . "$medalHtml";
}
else
{
$username = "".nexus_trans('nexus.user_not_exists')."";
$username = "" . ( $bracket == true ? "(" . $username . ")" : $username) . "";
}
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 = "
";
if ($p == 100) $progress = "
";
if ($p >= 1 && $p <= 30) $progress = "
";
if ($p >= 31 && $p <= 65) $progress = "
";
if ($p >= 66 && $p <= 99) $progress = "
";
return "
" . $progress ."
";
}
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 "
";
}
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";
$length = strlen($username);
for ($i = 0; $i < $length; ++$i)
if (strpos($allowedchars, $username[$i]) === false)
return false;
if ($length < 3 || $length > 20) {
return false;
}
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.
function code($ibm_437, $view) {
$swedishmagic = false;
if ($view == "magic") {
$swedishmagic = true;
}
$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;
}
/**
* @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;
}
//Tooltip container for hot movie, classic movie, etc
function create_tooltip_container($id_content_arr, $width = 400)
{
if(count($id_content_arr))
{
$result = "";
foreach($id_content_arr as $id_content_arr_each)
{
$result .= "
" . $id_content_arr_each['content'] . "
";
}
$result .= "
";
print($result);
}
}
function getimdb($imdb_id, $cache_stamp, $mode = 'minor')
{
global $lang_functions;
global $showextinfo;
$thenumbers = $imdb_id;
$imdb = new Nexus\Imdb\Imdb();
$movie = $imdb->getMovie($imdb_id);
$movieid = $thenumbers;
// $movie->setid ($movieid);
$target = array('Title', 'Credits', 'Plot');
switch ($imdb->getCacheStatus($imdb_id))
{
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 = "".$lang_functions['text_director'].": ".rtrim(trim($temp), ",");
}
else { //for tv series
$creator = $movie->creator();
$director_or_creator = "".$lang_functions['text_creator'].": ".$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 = "".$rating."/10 (".$votes.$lang_functions['text_votes'].")";
else $imdbrating = $lang_functions['text_awaiting_five_votes'];
$tagline = $movie->tagline ();
switch ($mode)
{
case 'minor' :
{
$autodata = "".$title." (".$year.")
".$lang_functions['text_imdb'].": ".$imdbrating." ".$lang_functions['text_country'].": ".$countries." ".$lang_functions['text_genres'].": ".$genres."
".$director_or_creator." ".$lang_functions['text_starring'].": ".$casts."
".$tagline."
";
break;
}
case 'median':
{
if (($photo_url = $movie->photo() ) != FALSE)
$smallth = "
";
else $smallth = "";
$runtime = $movie->runtime ();
$language = $movie->language ();
$plot = $movie->plot ();
$plots = "";
if(count($plot) != 0){ //get plots from plot page
$plots .= "* ".strip_tags($plot[0], '
');
$plots = mb_substr($plots,0,300,"UTF-8") . (mb_strlen($plots,"UTF-8") > 300 ? " ..." : "" );
$plots .= (strpos($plots,"") == true && strpos($plots,"") == false ? "" : "");//sometimes is open and not ended because of mb_substr;
$plots = "".$plots."";
}
elseif ($plotoutline = $movie->plotoutline ()){ //get plot from title page
$plots .= "* ".strip_tags($plotoutline, '
');
$plots = mb_substr($plots,0,300,"UTF-8") . (mb_strlen($plots,"UTF-8") > 300 ? " ..." : "" );
$plots .= (strpos($plots,"") == true && strpos($plots,"") == false ? "" : "");//sometimes is open and not ended because of mb_substr;
$plots = "".$plots."";
}
$autodata = "
".($smallth ? "|
$smallth
| " : "")
."
".$title." (".$year.") |
| ".$lang_functions['text_imdb'].": ".$imdbrating." |
".( $runtime ? "".$lang_functions['text_runtime'].": ".$runtime.$lang_functions['text_min']." | " : " | ")."
| ".$lang_functions['text_country'].": ".$countries." |
".( $language ? "".$lang_functions['text_language'].": ".$language." | " : " | ")."
| ".$director_or_creator." |
".$lang_functions['text_genres'].": ".$genres." |
| ".$lang_functions['text_starring'].": ".$casts." |
".( $plots ? "| ".$plots." | " : "")."
|
";
break;
}
}
return $autodata;
}
case "2" :
{
return false;
break;
}
case "3" :
{
return false;
break;
}
}
}
function quickreply($formname, $taname,$submit){
print("");
print(smile_row($formname, $taname));
print("
");
print("");
}
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 = "";
foreach ($quickSmilesNumbers as $smilyNumber) {
$smilerow .= getSmileIt($formname, $taname, $smilyNumber);
}
$smilerow .= "
";
return $smilerow;
}
function getSmileIt($formname, $taname, $smilyNumber) {
return " |
")."', 'trail', false, 'delay', 0,'lifetime',10000,'styleClass','smilies','maxWidth', 400);\">
";
}
function classlist($selectname,$maxclass, $selected, $minClass = 0, $includeNoClass = false, $disabled = false){
global $lang_functions;
$disabledText = '';
if ($disabled) {
$disabledText = ' disabled = "disabled"';
}
$list = "";
return $list;
}
function permissiondenied($allowMinimumClass = null){
global $lang_functions;
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);
}
}
function gettime($time, $withago = true, $twoline = false, $forceago = false, $oneunit = false, $isfuturetime = false){
global $lang_functions, $CURUSER;
if (isset($CURUSER) && $CURUSER['timetype'] != 'timealive' && !$forceago){
$newtime = $time;
if ($twoline){
$newtime = str_replace(" ", "
", $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(" ", "
", $newtime);
}
elseif($oneunit){
if ($length = strpos($newtime, " "))
$newtime = substr($newtime,0,$length);
}
else $newtime = str_replace(" ", $lang_functions['text_space'], $newtime);
$newtime = "".$newtime."";
}
}
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;
if (!$rows && !$rows = $Cache->get_value('category_content')){
$rows = [];
$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;
}
}
function get_second_icon($row) //for CHDBits
{
global $CURUSER, $Cache;
$source=$row['source'];
$medium=$row['medium'];
$codec=$row['codec'];
$standard=$row['standard'];
$processing=$row['processing'];
$team=$row['team'];
$audiocodec=$row['audiocodec'];
$mode = $row['search_box_id'];
$cacheKey = 'secondicon_'.$source.'_'.$medium.'_'.$codec.'_'.$standard.'_'.$processing.'_'.$team.'_'.$audiocodec.'_content';
if (!$sirow = $Cache->get_value($cacheKey)){
$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");
$sirow = mysql_fetch_array($res);
if (!$sirow)
$sirow = 'not allowed';
$Cache->cache_value($cacheKey, $sirow, 600);
}
$catimgurl = get_cat_folder($row['category']);
if ($sirow == 'not allowed')
return "
";
else {
return "
";
}
}
function get_torrent_bg_color($promotion = 1, $posState = "", array $torrent = [])
{
global $CURUSER;
$sphighlight = null;
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'";
}
if (is_null($sphighlight)) {
$torrentSettings = get_setting('torrent');
if ($posState == \App\Models\Torrent::POS_STATE_STICKY_FIRST && !empty($torrentSettings['sticky_first_level_background_color'])) {
$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']);
}
}
return apply_filter('torrent_background_color', (string)$sphighlight, $torrent);
}
function get_torrent_promotion_append($promotion = 1,$forcemode = "",$showtimeleft = false, $added = "", $promotionTimeType = 0, $promotionUntil = '', $ignoreGlobal = false){
global $CURUSER,$lang_functions;
global $expirehalfleech_torrent, $expirefree_torrent, $expiretwoup_torrent, $expiretwoupfree_torrent, $expiretwouphalfleech_torrent, $expirethirtypercentleech_torrent;
$globalSpState = get_global_sp_state();
$sp_torrent = "";
$onmouseover = "";
$log = "[GET_PROMOTION], promotion: $promotion, forcemode: $forcemode, showtimeleft: $showtimeleft, added: $added, promotionTimeType: $promotionTimeType, promotionUntil: $promotionUntil";
if ($ignoreGlobal) {
$globalSpState = 1;
$log .= ", [IGNORE_GLOBAL]";
}
$log .= ", globalSpState == " . $globalSpState;
if ($globalSpState == 1) {
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("".$lang_functions['text_free']."".$lang_functions['text_will_end_in']."".$timeout."")."', '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("".$lang_functions['text_two_times_up']."".$lang_functions['text_will_end_in']."".$timeout."")."', '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("".$lang_functions['text_free_two_times_up']."".$lang_functions['text_will_end_in']."".$timeout."")."', '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("".$lang_functions['text_half_down']."".$lang_functions['text_will_end_in']."".$timeout."")."', '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("".$lang_functions['text_half_down_two_up']."".$lang_functions['text_will_end_in']."".$timeout."")."', '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("".$lang_functions['text_thirty_percent_down']."".$lang_functions['text_will_end_in']."".$timeout."")."', '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'){
$log .= ", user appendpromotion = word";
if(($promotion==2 && $globalSpState == 1) || $globalSpState == 2){
$log .= ", promotion or global_sp_state = 2";
$sp_torrent = " [".$lang_functions['text_free']."]";
}
elseif(($promotion==3 && $globalSpState == 1) || $globalSpState == 3){
$log .= ", promotion or global_sp_state = 3";
$sp_torrent = " [".$lang_functions['text_two_times_up']."]";
}
elseif(($promotion==4 && $globalSpState == 1) || $globalSpState == 4){
$log .= ", promotion or global_sp_state = 4";
$sp_torrent = " [".$lang_functions['text_free_two_times_up']."]";
}
elseif(($promotion==5 && $globalSpState == 1) || $globalSpState == 5){
$log .= ", promotion or global_sp_state = 5";
$sp_torrent = " [".$lang_functions['text_half_down']."]";
}
elseif(($promotion==6 && $globalSpState == 1) || $globalSpState == 6){
$log .= ", promotion or global_sp_state = 6";
$sp_torrent = " [".$lang_functions['text_half_down_two_up']."]";
}
elseif(($promotion==7 && $globalSpState == 1) || $globalSpState == 7){
$log .= ", promotion or global_sp_state = 7";
$sp_torrent = " [".$lang_functions['text_thirty_percent_down']."]";
}
}
elseif (($CURUSER['appendpromotion'] == 'icon' && $forcemode == "") || $forcemode == 'icon'){
$log .= ", user appendpromotion = icon";
if(($promotion==2 && $globalSpState == 1) || $globalSpState == 2) {
$log .= ", promotion or global_sp_state = 2";
$sp_torrent = "
";
}
elseif(($promotion==3 && $globalSpState == 1) || $globalSpState == 3) {
$log .= ", promotion or global_sp_state = 3";
$sp_torrent = "
";
}
elseif(($promotion==4 && $globalSpState == 1) || $globalSpState == 4) {
$log .= ", promotion or global_sp_state = 4";
$sp_torrent = "
";
}
elseif(($promotion==5 && $globalSpState == 1) || $globalSpState == 5) {
$log .= ", promotion or global_sp_state = 5";
$sp_torrent = "
";
}
elseif(($promotion==6 && $globalSpState == 1) || $globalSpState == 6) {
$log .= ", promotion or global_sp_state = 6";
$sp_torrent = "
";
}
elseif(($promotion==7 && $globalSpState == 1) || $globalSpState == 7) {
$log .= ", promotion or global_sp_state = 7";
$sp_torrent = "
";
}
}
do_log("$log, sp_torrent: $sp_torrent");
return $sp_torrent;
}
function get_torrent_promotion_append_sub($promotion = 1,$forcemode = "",$showtimeleft = false, $added = "", $promotionTimeType = 0, $promotionUntil = '', $ignoreGlobal = false){
global $CURUSER,$lang_functions;
global $expirehalfleech_torrent, $expirefree_torrent, $expiretwoup_torrent, $expiretwoupfree_torrent, $expiretwouphalfleech_torrent, $expirethirtypercentleech_torrent;
$globalSpState = get_global_sp_state();
$sp_torrent = "";
$onmouseover = "";
$log = "[GET_PROMOTION], promotion: $promotion, forcemode: $forcemode, showtimeleft: $showtimeleft, added: $added, promotionTimeType: $promotionTimeType, promotionUntil: $promotionUntil";
if ($ignoreGlobal) {
$globalSpState = 1;
$log .= ", [IGNORE_GLOBAL]";
}
$log .= ", globalSpState == " . $globalSpState;
if ($globalSpState == 1) {
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 = " ".$lang_functions['text_will_end_in'].$timeout.""; //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 = " ".$lang_functions['text_will_end_in'].$timeout.""; //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";
if(($promotion==2 && $globalSpState == 1) || $globalSpState == 2){
$log .= ", promotion or global_sp_state = 2";
$sp_torrent = $onmouseover;
}
elseif(($promotion==3 && $globalSpState == 1) || $globalSpState == 3){
$log .= ", promotion or global_sp_state = 3";
$sp_torrent = $onmouseover;
}
elseif(($promotion==4 && $globalSpState == 1) || $globalSpState == 4){
$log .= ", promotion or global_sp_state = 4";
$sp_torrent = $onmouseover;
}
elseif(($promotion==5 && $globalSpState == 1) || $globalSpState == 5){
$log .= ", promotion or global_sp_state = 5";
$sp_torrent = $onmouseover;
}
elseif(($promotion==6 && $globalSpState == 1) || $globalSpState == 6){
$log .= ", promotion or global_sp_state = 6";
$sp_torrent = $onmouseover;
}
elseif(($promotion==7 && $globalSpState == 1) || $globalSpState == 7){
$log .= ", promotion or global_sp_state = 7";
$sp_torrent = $onmouseover;
}
}
elseif (($CURUSER['appendpromotion'] == 'icon' && $forcemode == "") || $forcemode == 'icon'){
$log .= ", user appendpromotion = icon";
if(($promotion==2 && $globalSpState == 1) || $globalSpState == 2) {
$log .= ", promotion or global_sp_state = 2";
$sp_torrent = $onmouseover;
}
elseif(($promotion==3 && $globalSpState == 1) || $globalSpState == 3) {
$log .= ", promotion or global_sp_state = 3";
$sp_torrent = $onmouseover;
}
elseif(($promotion==4 && $globalSpState == 1) || $globalSpState == 4) {
$log .= ", promotion or global_sp_state = 4";
$sp_torrent = $onmouseover;
}
elseif(($promotion==5 && $globalSpState == 1) || $globalSpState == 5) {
$log .= ", promotion or global_sp_state = 5";
$sp_torrent = $onmouseover;
}
elseif(($promotion==6 && $globalSpState == 1) || $globalSpState == 6) {
$log .= ", promotion or global_sp_state = 6";
$sp_torrent = $onmouseover;
}
elseif(($promotion==7 && $globalSpState == 1) || $globalSpState == 7) {
$log .= ", promotion or global_sp_state = 7";
$sp_torrent = $onmouseover;
}
}
do_log("$log, sp_torrent: $sp_torrent");
return $sp_torrent;
}
function get_hr_img(array $torrent, $searchBoxId)
{
// $mode = get_setting('hr.mode');
$mode = \App\Models\HitAndRun::getConfig('mode', $searchBoxId);
$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 = '
';
}
do_log("searchBoxId: $searchBoxId, mode: $mode, result: $result");
return $result;
}
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){
$row = get_user_row($id);
if ($row)
$username = $row['username'];
else $username = "";
return $username;
}
function get_searchbox_value($mode = 1, $item = 'showsubcat'){
global $Cache;
static $rows;
$cacheKey = "search_box_content";
if (!$rows && !$rows = $Cache->get_value($cacheKey)){
$rows = array();
$res = sql_query("SELECT * FROM searchbox ORDER BY id ASC");
while ($row = mysql_fetch_array($res)) {
if (isset($row['extra'])) {
$row['extra'] = json_decode($row['extra'], true);
}
if (isset($row['section_name'])) {
$row['section_name'] = json_decode($row['section_name'], true);
}
$rows[$row['id']] = $row;
}
$Cache->cache_value($cacheKey, $rows, 100500);
}
return $rows[$mode][$item] ?? '';
}
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 = "".$ratio."";
}
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;
return ($num > 1 ? ($es ? ($lang_functions['text_es'] ?? '') : $lang_functions['text_s']) : "");
}
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"
);
if (isset($class)) {
$className = get_user_class_name($class,false,false,false);
if (str_contains($className, '(')) {
$className = strstr($className, '(', true);
}
$uclass = $UC[$className];
} else {
$uclass = "pic/banned.gif";
}
return $uclass;
}
function user_can_upload($where = "torrents"){
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);
}
if ($where == "torrents")
{
$offerSkipApprovedCount = get_setting('main.offer_skip_approved_count');
if ($CURUSER['offer_allowed_count'] >= $offerSkipApprovedCount) {
return true;
}
if (user_can('upload'))
return true;
if (get_if_restricted_is_open())
return true;
}
if ($where == "music")
{
if ($enablespecial == 'yes' && user_can('uploadspecial'))
return true;
}
return false;
}
function torrent_selection($name,$selname,$listname,$selectedid = 0, $mode = 0)
{
global $lang_functions;
$selection = "".$name." \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);
}
$ret = $moderatorsArray[$forumid] ?? [];
$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\n";
return $key_shortcut_block;
}
function promotion_selection($selected = 0, $hide = 0)
{
global $lang_functions;
$selection = "";
if ($hide != 1)
$selection .= "";
if ($hide != 2)
$selection .= "";
if ($hide != 3)
$selection .= "";
if ($hide != 4)
$selection .= "";
if ($hide != 5)
$selection .= "";
if ($hide != 6)
$selection .= "";
if ($hide != 7)
$selection .= "";
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 "
";
}
function return_category_image($categoryid, $link="")
{
static $catImg = array();
if (isset($catImg[$categoryid])) {
$catimg = $catImg[$categoryid];
} else {
$categoryrow = get_category_row($categoryid);
$catimgurl = get_cat_folder($categoryid);
$catImg[$categoryid] = $catimg = "
";
}
if ($link) {
$catimg = "".$catimg."";
}
return $catimg;
}
/******************************************** bellow functioons avaliable since v1.6 ***********************************************************/
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'],
'color' => '#ff0000',
],
[
'text' => $lang_functions['text_tag_first_release'],
'color' => '#8F77B5',
],
[
'text' => $lang_functions['text_tag_official'],
'color' => '#0000ff',
],
[
'text' => $lang_functions['text_tag_diy'],
'color' => '#46d5ff',
],
[
'text' => $lang_functions['text_tag_mother_language'],
'color' => '#6a3906',
],
[
'text' => $lang_functions['text_tag_mother_language_subtitle'],
'color' => '#006400',
],
[
'text' => $lang_functions['text_tag_hdr'],
'color' => '#38b03f',
],
];
$html = '';
foreach ($tagsOptions as $key => $value) {
$currentValue = pow(2, $key);
if ($type == 'checkbox') {
$checked = '';
if ($currentValue & $tags) {
$checked = 'checked';
}
$html .= sprintf(
'',
$currentValue, $checked, $value['text']
);
}
if ($type == 'span' && ($currentValue & $tags)) {
$html .= "{$value['text']} ";
}
}
return $html;
}
function saveSetting(string $prefix, array $nameAndValue, string $autoload = 'yes'): void
{
$prefix = strtolower($prefix);
$datetimeNow = date('Y-m-d H:i:s');
$sql = "insert into `settings` (name, value, created_at, updated_at, autoload) values ";
$data = [];
foreach ($nameAndValue as $name => $value) {
if (is_array($value)) {
$value = json_encode($value);
}
$data[] = sprintf("(%s, %s, %s, %s, '%s')", sqlesc("$prefix.$name"), sqlesc($value), sqlesc($datetimeNow), sqlesc($datetimeNow), $autoload);
}
$sql .= implode(",", $data) . " on duplicate key update value = values(value)";
\Nexus\Database\NexusDB::statement($sql);
clear_setting_cache();
do_action("nexus_setting_update");
}
function getFullDirectory($dir)
{
if (is_file($dir) && file_exists($dir)) {
return $dir;
}
if (!is_dir($dir)) {
$dir = ROOT_PATH . $dir;
}
if (is_dir($dir)) {
return realpath($dir);
}
return $dir;
}
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;
}
if (in_array(nexus()->getScript(), ['login', 'takelogin', 'image']) && canDoLogin()) {
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);
}
}
function render($view, $data = [], $return = false)
{
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;
}
return true;
}
if ($loginType == 'passkey') {
return false;
}
return true;
}
function displayHotAndClassic()
{
global $showextinfo, $showmovies, $Cache, $lang_functions, $browsecatmode, $specialcatmode;
if ($showmovies['hot'] == "yes" || $showmovies['classic'] == "yes")
{
if (nexus()->getScript() == 'special') {
$mode = $specialcatmode;
} else {
$mode = $browsecatmode;
}
$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'))
{
$Cache->new_page("{$type_each}_{$mode}_resources", 900, true);
if (!$Cache->get_page())
{
$Cache->add_whole_row();
$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__);
if (mysql_num_rows($res) > 0)
{
$movies_list = "";
$count = 0;
$allImdb = array();
$width = 101;
$height = 140;
while($array = mysql_fetch_array($res))
{
$pro_torrent = get_torrent_promotion_append($array['sp_state'],'word', false, '', 0, '', $array['__ignore_global_sp_state'] ?? false);
$photo_url = '';
if ($imdb_id = parse_imdb_id($array["url"])) {
if (array_search($imdb_id, $allImdb) !== false) { //a torrent with the same IMDb url already exists
continue;
}
$allImdb[]=$imdb_id;
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');
}
}
if (empty($photo_url) && !empty($array['cover'])) {
$photo_url = $array['cover'];
}
if (empty($photo_url)) {
continue;
}
$thumbnail = "
";
$thumbnail = "" . (addslashes($array['name'] . $pro_torrent)) . "