diff --git a/include/functions.php b/include/functions.php index 9d2288ab..5f64dc26 100644 --- a/include/functions.php +++ b/include/functions.php @@ -3115,11 +3115,11 @@ function pager($rpp, $count, $href, $opts = array(), $pagename = "page") { $pagerarr[] = "$text"; } $pagerstr = join(" | ", $pagerarr); - $pagertop = "

$pager
$pagerstr

\n"; - $pagerbottom = "

$pagerstr
$pager

\n"; + $pagertop = "

$pager
$pagerstr

\n"; + $pagerbottom = "

$pagerstr
$pager

\n"; } else { - $pagertop = "

$pager

\n"; + $pagertop = "

$pager

\n"; $pagerbottom = $pagertop; } diff --git a/public/getusertorrentlistajax.php b/public/getusertorrentlistajax.php index edc0fca9..d00b6c12 100644 --- a/public/getusertorrentlistajax.php +++ b/public/getusertorrentlistajax.php @@ -116,7 +116,7 @@ function maketable($res, $mode = 'seeding') ->keyBy('torrentid'); } - $ret = "". + $ret = "
".$lang_getusertorrentlistajax['col_type']."".$lang_getusertorrentlistajax['col_name']."  ".$lang_getusertorrentlistajax['col_added']."  
". ($showsize ? "" : "").($showsenum ? "" : "").($showlenum ? "" : "").($showuploaded ? "" : "") . ($showdownloaded ? "" : "").($showratio ? "" : "").($showsetime ? "" : "").($showletime ? "" : "").($showcotime ? "" : "").($showanonymous ? "" : "")."\n"; $total_size = 0; foreach ($results as $arr) @@ -158,7 +158,7 @@ function maketable($res, $mode = 'seeding') else $dissmall_descr == ""; $ret .= "\n" . ""; - $ret .= sprintf('', substr($arr['added'], 0, 10), substr($arr['added'], 11)); + $ret .= sprintf('', substr($arr['added'], 0, 10), substr($arr['added'], 11)); //size if ($showsize) $ret .= ""; @@ -205,78 +205,95 @@ function maketable($res, $mode = 'seeding') $ret .= "
".$lang_getusertorrentlistajax['col_type']."".$lang_getusertorrentlistajax['col_name']."".$lang_getusertorrentlistajax['col_added']."\"size\"\"seeders\"\"leechers\"".$lang_getusertorrentlistajax['col_uploaded']."".$lang_getusertorrentlistajax['col_downloaded']."".$lang_getusertorrentlistajax['col_ratio']."".$lang_getusertorrentlistajax['col_se_time']."".$lang_getusertorrentlistajax['col_le_time']."".$lang_getusertorrentlistajax['col_time_completed']."".$lang_getusertorrentlistajax['col_anonymous']."
".return_category_image($arr['category'], "torrents.php?allsec=1&")."" . $dispname . "". $banned_torrent . $sp_torrent . $hrImg . $approvalStatusIcon .($dissmall_descr == "" ? "" : "
" . $dissmall_descr) . "
%s
%s
%s
%s
". mksize_compact($arr['size'])."
\n"; return [$ret, $total_size]; } - +$count = 0; +$torrentlist = ""; switch ($type) { case 'uploaded': { // $res = sql_query("SELECT torrents.id AS torrent, torrents.name as torrentname, small_descr, seeders, leechers, anonymous, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, snatched.seedtime, snatched.uploaded FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories ON torrents.category = categories.id WHERE torrents.owner=$id AND snatched.userid=$id " . (($CURUSER["id"] != $id)?((get_user_class() < $viewanonymous_class) ? " AND anonymous = 'no'":""):"") ." ORDER BY torrents.added DESC") or sqlerr(__FILE__, __LINE__); - $res = sql_query("SELECT torrents.id AS torrent, torrents.name as torrentname, small_descr, seeders, leechers, anonymous, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added FROM torrents LEFT JOIN categories ON torrents.category = categories.id WHERE torrents.owner=$id " . (($CURUSER["id"] != $id)?((!user_can('viewanonymous')) ? " AND anonymous = 'no'":""):"") ." ORDER BY torrents.added DESC") or sqlerr(__FILE__, __LINE__); - $count = mysql_num_rows($res); - if ($count > 0) - { - list($torrentlist, $total_size) = maketable ( $res, 'uploaded' ); - } +// $res = sql_query("SELECT torrents.id AS torrent, torrents.name as torrentname, small_descr, seeders, leechers, anonymous, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added FROM torrents LEFT JOIN categories ON torrents.category = categories.id WHERE torrents.owner=$id " . (($CURUSER["id"] != $id)?((!user_can('viewanonymous')) ? " AND anonymous = 'no'":""):"") ." ORDER BY torrents.id DESC") or sqlerr(__FILE__, __LINE__); + $fields = "torrents.id AS torrent, torrents.name as torrentname, small_descr, seeders, leechers, anonymous, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added"; + $tableWhere = "torrents LEFT JOIN categories ON torrents.category = categories.id WHERE torrents.owner=$id"; + if ($CURUSER['id'] != $id && !user_can('viewanonymous')) { + $tableWhere .= " AND anonymous = 'no'"; + } + $order = "torrents.id DESC"; break; } // Current Seeding case 'seeding': { - $res = sql_query("SELECT torrent,added,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, torrents.banned, torrents.approval_status, categories.name as catname,size,torrents.hr,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='yes' ORDER BY torrents.added DESC") or sqlerr(); - $count = mysql_num_rows($res); - if ($count > 0){ - list($torrentlist, $total_size) = maketable ( $res, 'seeding' ); - } +// $res = sql_query("SELECT torrent,added,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, torrents.banned, torrents.approval_status, categories.name as catname,size,torrents.hr,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='yes' ORDER BY torrents.id DESC") or sqlerr(); + $fields = "torrent,added,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, torrents.banned, torrents.approval_status, categories.name as catname,size,torrents.hr,image,category,seeders,leechers"; + $tableWhere = "peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='yes'"; + $order = "torrents.id DESC"; break; } // Current Leeching case 'leeching': { - $res = sql_query("SELECT torrent,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, torrents.banned, torrents.approval_status, categories.name as catname,size,torrents.hr,image,category,seeders,leechers, torrents.added FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='no' ORDER BY torrents.added DESC") or sqlerr(); - $count = mysql_num_rows($res); - if ($count > 0){ - list($torrentlist, $total_size) = maketable ( $res, 'leeching' ); - } +// $res = sql_query("SELECT torrent,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, torrents.banned, torrents.approval_status, categories.name as catname,size,torrents.hr,image,category,seeders,leechers, torrents.added FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='no' ORDER BY torrents.id DESC") or sqlerr(); + $fields = "torrent,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, torrents.banned, torrents.approval_status, categories.name as catname,size,torrents.hr,image,category,seeders,leechers, torrents.added"; + $tableWhere = "peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='no'"; + $order = "torrents.id DESC"; break; } // Completed torrents case 'completed': { - $res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, categories.name AS catname, torrents.banned, torrents.approval_status, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.seedtime, snatched.leechtime, snatched.completedat FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='yes' AND torrents.owner != $id AND userid=$id ORDER BY snatched.completedat DESC") or sqlerr(); - $count = mysql_num_rows($res); - if ($count > 0) - { - list($torrentlist, $total_size) = maketable ( $res, 'completed' ); - } +// $res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, categories.name AS catname, torrents.banned, torrents.approval_status, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.seedtime, snatched.leechtime, snatched.completedat FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='yes' AND torrents.owner != $id AND userid=$id ORDER BY snatched.id DESC") or sqlerr(); + $fields = "torrents.id AS torrent, torrents.name AS torrentname, small_descr, categories.name AS catname, torrents.banned, torrents.approval_status, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.seedtime, snatched.leechtime, snatched.completedat"; + $tableWhere = "torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='yes' AND userid=$id AND torrents.owner != $id"; + $order = "snatched.id DESC"; break; } // Incomplete torrents case 'incomplete': { - $res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.downloaded, snatched.leechtime FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id ORDER BY snatched.startdat DESC") or sqlerr(); - $count = mysql_num_rows($res); - if ($count > 0) - { - list($torrentlist, $total_size) = maketable ( $res, 'incomplete' ); - } - break; - } - default: - { - $count = 0; - $torrentlist = ""; + $res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.downloaded, snatched.leechtime FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id ORDER BY snatched.id DESC") or sqlerr(); + $fields = "torrents.id AS torrent, torrents.name AS torrentname, small_descr, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.downloaded, snatched.leechtime"; + $tableWhere = "torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id"; + $order = "snatched.id DESC"; break; } } +if (isset($tableWhere)) { + $cacheKey = sprintf('user:%s:type:%s:total_size', $id, $type); + $page = $_GET['page'] ?? 0; + $sumSql = "select count(*) as count, sum(torrents.size) as total_size from $tableWhere limit 1"; + if ($page == 0) { + $sumRes = mysql_fetch_assoc(sql_query($sumSql)); + \Nexus\Database\NexusDB::cache_put($cacheKey, $sumRes); + } else { + $sumRes = \Nexus\Database\NexusDB::remember($cacheKey, 3600, function () use ($sumSql) { + return mysql_fetch_assoc(sql_query($sumSql)); + }); + } + + $count = $sumRes['count']; + $total_size = $sumRes['total_size']; +} + +if ($count > 0 && isset($tableWhere, $fields, $order)) +{ + $pageSize = 100; + list($pagertop, $pagerbottom, $limit) = pager($pageSize, $count, "getusertorrentlistajax.php?"); + $sql = "select $fields from $tableWhere order by $order $limit"; + do_log("count: $count, list sql: $sql"); + $res = sql_query($sql); + list($torrentlist, $total_size_this_page) = maketable ( $res, $type); +} + if (isset($total_size) && $total_size){ - echo "
" . $count . "" . $lang_getusertorrentlistajax['text_record'] . add_s ( $count ) . $lang_getusertorrentlistajax['text_total_size'] . mksize($total_size) . "

" . $torrentlist; + echo "
" . $count . "" . $lang_getusertorrentlistajax['text_record'] . add_s ( $count ) . $lang_getusertorrentlistajax['text_total_size'] . mksize($total_size) . $pagertop . $torrentlist . $pagerbottom; } elseif ($count){ - echo "
".$count."".$lang_getusertorrentlistajax['text_record'].add_s($count)."

".$torrentlist; + echo "
".$count."".$lang_getusertorrentlistajax['text_record'].add_s($count). $pagertop . $torrentlist . $pagerbottom; } else { echo $lang_getusertorrentlistajax['text_no_record']; } diff --git a/public/js/nexus.js b/public/js/nexus.js index 3ef65b8d..509fd995 100644 --- a/public/js/nexus.js +++ b/public/js/nexus.js @@ -83,20 +83,20 @@ jQuery(document).ready(function () { if ("IntersectionObserver" in window) { const imgList = [...document.querySelectorAll('.nexus-lazy-load')] var io = new IntersectionObserver((entries) =>{ - entries.forEach(item => { - // isIntersecting是一个Boolean值,判断目标元素当前是否可见 - if (item.isIntersecting) { - item.target.src = item.target.dataset.src - item.target.classList.add('preview') - // 图片加载后即停止监听该元素 - io.unobserve(item.target) + entries.forEach(entry => { + const el = entry.target + const intersectionRatio = entry.intersectionRatio + // console.log(`el, ${el.getAttribute('data-src')}, intersectionRatio: ${intersectionRatio}`) + if (intersectionRatio > 0 && intersectionRatio <= 1 && !el.classList.contains('preview')) { + // console.log(`el, ${el.getAttribute('data-src')}, loadImg`) + const source = el.dataset.src + el.src = source + el.classList.add('preview') } + el.onload = el.onerror = () => io.unobserve(el) }) - }, { - root: document.querySelector('body') }) - // observe遍历监听所有img节点 imgList.forEach(img => io.observe(img)) } diff --git a/public/userdetails.php b/public/userdetails.php index d2468608..d327be1a 100644 --- a/public/userdetails.php +++ b/public/userdetails.php @@ -397,19 +397,19 @@ if ($user["id"] == $CURUSER["id"] || user_can('viewhistory')) { if ($user["ip"] && (user_can('torrenthistory') || $user["id"] == $CURUSER["id"])){ -tr_small($lang_userdetails['row_uploaded_torrents'], "\"Show/Hide\" ".$lang_userdetails['text_show_or_hide']."
", 1); +tr_small($lang_userdetails['row_uploaded_torrents'], "\"Show/Hide\" ".$lang_userdetails['text_show_or_hide']."
", 1); -tr_small($lang_userdetails['row_current_seeding'], "\"Show/Hide\" ".$lang_userdetails['text_show_or_hide']."
", 1); +tr_small($lang_userdetails['row_current_seeding'], "\"Show/Hide\" ".$lang_userdetails['text_show_or_hide']."
", 1); -tr_small($lang_userdetails['row_current_leeching'], "\"Show/Hide\" ".$lang_userdetails['text_show_or_hide']."
", 1); +tr_small($lang_userdetails['row_current_leeching'], "\"Show/Hide\" ".$lang_userdetails['text_show_or_hide']."
", 1); -tr_small($lang_userdetails['row_completed_torrents'], "\"Show/Hide\" ".$lang_userdetails['text_show_or_hide']."
", 1); +tr_small($lang_userdetails['row_completed_torrents'], "\"Show/Hide\" ".$lang_userdetails['text_show_or_hide']."
", 1); -tr_small($lang_userdetails['row_incomplete_torrents'], "\"Show/Hide\" ".$lang_userdetails['text_show_or_hide']."
", 1); +tr_small($lang_userdetails['row_incomplete_torrents'], "\"Show/Hide\" ".$lang_userdetails['text_show_or_hide']."
", 1); } if ($user["info"]) print("" . format_comment($user["info"],false) . "\n"); @@ -620,5 +620,18 @@ JS; } } end_main_frame(); + +$paginationJs = <<