Merge branch '1.7' into php8

This commit is contained in:
xiaomlove
2022-03-31 16:43:51 +08:00
140 changed files with 21731 additions and 273 deletions
+29
View File
@@ -0,0 +1,29 @@
<?php
require "../include/bittorrent.php";
dbconn();
loggedinorreturn();
$action = $_POST['action'] ?? 'noAction';
$params = $_POST['params'] ?? [];
function noAction()
{
throw new \RuntimeException("no Action");
}
try {
$result = call_user_func($action, $params);
exit(json_encode(success($result)));
} catch (\Throwable $exception) {
exit(json_encode(fail($exception->getMessage(), $_POST)));
}
function toggleUserMedalStatus($params)
{
global $CURUSER;
$rep = new \App\Repositories\MedalRepository();
return $rep->toggleUserMedalStatus($params['id'], $CURUSER['id']);
}
+18 -5
View File
@@ -1,6 +1,17 @@
<?php
require_once('../include/bittorrent_announce.php');
//require_once('../include/benc.php');
require '../include/bittorrent_announce.php';
$apiLocalHost = nexus_env('TRACKER_API_LOCAL_HOST');
if ($apiLocalHost) {
do_log("[TRACKER_API_LOCAL_HOST] $apiLocalHost");
$response = request_local_api(trim($apiLocalHost, '/') . '/api/announce');
if (empty($response)) {
err("error from TRACKER_API_LOCAL_HOST");
} else {
exit(benc_resp_raw($response));
}
}
//continue the normal process
require ROOT_PATH . 'include/core.php';
dbconn_announce();
do_log(nexus_json_encode($_SERVER));
//1. BLOCK ACCESS WITH WEB BROWSERS AND CHEATS!
@@ -24,7 +35,9 @@ if (!empty($_REQUEST['authkey'])) {
if (empty($decrypted)) {
err('Invalid authkey');
}
$userInfo = \App\Models\User::query()->where('id', $uid)->first(['id', 'passkey']);
$userInfo = \Nexus\Database\NexusDB::remember("announce_user_passkey_$uid", 600, function () use ($uid) {
return \App\Models\User::query()->where('id', $uid)->first(['id', 'passkey']);
});
if (!$userInfo) {
err('Invalid authkey');
}
@@ -153,7 +166,7 @@ else{
if ($newnumpeers > $rsize)
$limit = " ORDER BY RAND() LIMIT $rsize";
else $limit = "";
$announce_wait = 30;
$announce_wait = \App\Repositories\TrackerRepository::MIN_ANNOUNCE_WAIT_SECOND;
$fields = "seeder, peer_id, ip, port, uploaded, downloaded, (".TIMENOW." - UNIX_TIMESTAMP(last_action)) AS announcetime, UNIX_TIMESTAMP(prev_action) AS prevts";
//$peerlistsql = "SELECT ".$fields." FROM peers WHERE torrent = ".$torrentid." AND connectable = 'yes' ".$only_leech_query.$limit;
@@ -188,7 +201,7 @@ $params = $_GET;
unset($params['key']);
$lockKey = md5(http_build_query($params));
$redis = $Cache->getRedis();
if (!$redis->set($lockKey, TIMENOW, ['nx', 'ex' => $announce_wait])) {
if (!$redis->set($lockKey, TIMENOW, ['nx', 'ex' => 5])) {
do_log('ReAnnounce');
benc_resp($rep_dict);
exit();
+8 -5
View File
@@ -3,24 +3,27 @@ require "../include/bittorrent.php";
dbconn();
//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/xml; charset=utf-8");
$torrentid = intval($_GET['torrentid'] ?? 0);
if(isset($CURUSER))
{
$searchRep = new \App\Repositories\SearchRepository();
$res_bookmark = sql_query("SELECT * FROM bookmarks WHERE torrentid=" . sqlesc($torrentid) . " AND userid=" . sqlesc($CURUSER['id']));
if (mysql_num_rows($res_bookmark) == 1){
$bookmarkResult = mysql_fetch_assoc($res_bookmark);
$searchRep->deleteBookmark($bookmarkResult['id']);
sql_query("DELETE FROM bookmarks WHERE torrentid=" . sqlesc($torrentid) . " AND userid=" . sqlesc($CURUSER['id'])) or sqlerr(__FILE__,__LINE__);
$Cache->delete_value('user_'.$CURUSER['id'].'_bookmark_array');
echo "deleted";
}
else{
} else {
sql_query("INSERT INTO bookmarks (torrentid, userid) VALUES (" . sqlesc($torrentid) . "," . sqlesc($CURUSER['id']) . ")") or sqlerr(__FILE__,__LINE__);
$Cache->delete_value('user_'.$CURUSER['id'].'_bookmark_array');
$searchRep->addBookmark(mysql_insert_id());
echo "added";
}
}
+1 -1
View File
@@ -305,7 +305,7 @@ function print_category_editor($type, $row='')
tr($lang_catmanage['col_name']."<font color=\"red\">*</font>", "<input type=\"text\" name=\"name\" value=\"".htmlspecialchars($name)."\" style=\"width: 300px\" /> " . $lang_catmanage['text_second_icon_name_note'], 1);
tr($lang_catmanage['col_image']."<font color=\"red\">*</font>", "<input type=\"text\" name=\"image\" value=\"".htmlspecialchars($image)."\" style=\"width: 300px\" /><br />" . $lang_catmanage['text_image_note'], 1);
tr($lang_catmanage['text_class_name'], "<input type=\"text\" name=\"class_name\" value=\"".htmlspecialchars($class_name)."\" style=\"width: 300px\" /><br />" . $lang_catmanage['text_class_name_note'], 1);
tr($lang_catmanage['row_selections']."<font color=\"red\">*</font>", torrent_selection(return_type_name('source'), 'source', return_category_db_table_name('source'), $source) . torrent_selection(return_type_name('source'), 'source', return_category_db_table_name('source'), $source) . torrent_selection(return_type_name('medium'), 'medium', return_category_db_table_name('medium'), $medium) . torrent_selection(return_type_name('codec'), 'codec', return_category_db_table_name('codec'), $codec) . torrent_selection(return_type_name('standard'), 'standard', return_category_db_table_name('standard'), $standard) . torrent_selection(return_type_name('processing'), 'processing', return_category_db_table_name('processing'), $processing) . torrent_selection(return_type_name('team'), 'team', return_category_db_table_name('team'), $team) . torrent_selection(return_type_name('audiocodec'), 'audiocodec', return_category_db_table_name('audiocodec'), $audiocodec)."<br />".$lang_catmanage['text_selections_note'], 1);
tr($lang_catmanage['row_selections']."<font color=\"red\">*</font>", torrent_selection(return_type_name('source'), 'source', return_category_db_table_name('source'), $source) . torrent_selection(return_type_name('medium'), 'medium', return_category_db_table_name('medium'), $medium) . torrent_selection(return_type_name('codec'), 'codec', return_category_db_table_name('codec'), $codec) . torrent_selection(return_type_name('standard'), 'standard', return_category_db_table_name('standard'), $standard) . torrent_selection(return_type_name('processing'), 'processing', return_category_db_table_name('processing'), $processing) . torrent_selection(return_type_name('team'), 'team', return_category_db_table_name('team'), $team) . torrent_selection(return_type_name('audiocodec'), 'audiocodec', return_category_db_table_name('audiocodec'), $audiocodec)."<br />".$lang_catmanage['text_selections_note'], 1);
}
elseif ($type=='category')
{
+5 -1
View File
@@ -53,7 +53,11 @@ else
bark($lang_delete['std_enter_reason']);
$reasonstr = trim($reason[3]);
}
$searchRep = new \App\Repositories\SearchRepository();
$deleteEsResult = $searchRep->deleteTorrent($id);
if ($deleteEsResult === false) {
bark('Delete es fail.');
}
deletetorrent($id);
if ($row['anonymous'] == 'yes' && $CURUSER["id"] == $row["owner"]) {
+4 -4
View File
@@ -38,7 +38,7 @@ if (!$row) {
) {
permissiondenied();
} else {
$owner = \App\Models\User::query()->with(['valid_medals'])->find($row['owner']);
$owner = \App\Models\User::query()->with(['wearing_medals'])->find($row['owner']);
if (!$owner) {
$owner = \App\Models\User::defaultUser();
}
@@ -87,10 +87,10 @@ if (!$row) {
if (get_user_class() < $viewanonymous_class)
$uprow = "<i>".$lang_details['text_anonymous']."</i>";
else
$uprow = "<i>".$lang_details['text_anonymous']."</i> (" . build_medal_image($owner->valid_medals, 20) . get_username($row['owner'], false, true, true, false, false, true) . ")";
$uprow = "<i>".$lang_details['text_anonymous']."</i> (" . build_medal_image($owner->wearing_medals, 20) . get_username($row['owner'], false, true, true, false, false, true) . ")";
}
else {
$uprow = (isset($row['owner']) ? build_medal_image($owner->valid_medals, 20) . get_username($row['owner'], false, true, true, false, false, true) : "<i>".$lang_details['text_unknown']."</i>");
$uprow = (isset($row['owner']) ? build_medal_image($owner->wearing_medals, 20) . get_username($row['owner'], false, true, true, false, false, true) : "<i>".$lang_details['text_unknown']."</i>");
}
if ($CURUSER["id"] == $row["owner"])
@@ -413,7 +413,7 @@ echo "</script>";
if(isset($magic_value_bonus)){
$bonus_array = $magic_value_bonus;
}else{
$bonus_array = '50 , 100 , 200 , 500, 1000';
$bonus_array = implode(',', \App\Models\Torrent::BONUS_REWARD_VALUES);
}
echo '<style type="text/css">
ul.magic
+5
View File
@@ -32,6 +32,11 @@ if (!$sure)
stderr($lang_fastdelete['std_delete_torrent'], $lang_fastdelete['std_delete_torrent_note']."<a class=altlink href=fastdelete.php?id=$id&sure=1>".$lang_fastdelete['std_here_if_sure'],false);
}
$searchRep = new \App\Repositories\SearchRepository();
$deleteEsResult = $searchRep->deleteTorrent($id);
if ($deleteEsResult === false) {
bark('Delete es fail.');
}
deletetorrent($id);
KPS("-",$uploadtorrent_bonus,$row["owner"]);
if ($row['anonymous'] == 'yes' && $CURUSER["id"] == $row["owner"]) {
+2 -2
View File
@@ -632,7 +632,7 @@ if ($action == "viewtopic")
$uidArr = array_keys($uidArr);
unset($arr);
$neededColumns = array('id', 'noad', 'class', 'enabled', 'privacy', 'avatar', 'signature', 'uploaded', 'downloaded', 'last_access', 'username', 'donor', 'leechwarn', 'warned', 'title');
$userInfoArr = \App\Models\User::query()->with(['valid_medals'])->find($uidArr, $neededColumns)->keyBy('id');
$userInfoArr = \App\Models\User::query()->with(['wearing_medals'])->find($uidArr, $neededColumns)->keyBy('id');
$pn = 0;
$lpr = get_last_read_post_id($topicid);
@@ -674,7 +674,7 @@ if ($action == "viewtopic")
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($arr2["avatar"]) : "");
$uclass = get_user_class_image($arr2["class"]);
$by = build_medal_image($userInfo->valid_medals, 20) . get_username($posterid,false,true,true,false,false,true);
$by = build_medal_image($userInfo->wearing_medals, 20) . get_username($posterid,false,true,true,false,false,true);
if (!$avatar)
$avatar = "pic/default_avatar.png";
+12
View File
@@ -1,5 +1,17 @@
<?php
require_once('../include/bittorrent_announce.php');
$apiLocalHost = nexus_env('TRACKER_API_LOCAL_HOST');
if ($apiLocalHost) {
do_log("[TRACKER_API_LOCAL_HOST] $apiLocalHost");
$response = request_local_api(trim($apiLocalHost, '/') . '/api/scrape');
if (empty($response)) {
err("error from TRACKER_API_LOCAL_HOST");
} else {
exit(benc_resp_raw($response));
}
}
require ROOT_PATH . 'include/core.php';
//require_once('../include/benc.php');
dbconn_announce();
+4
View File
@@ -241,6 +241,10 @@ else
{
write_log("Torrent $id ($name) was edited by {$CURUSER['username']}, Mod Edit" . $pick_info . $place_info);
}
$searchRep = new \App\Repositories\SearchRepository();
$searchRep->updateTorrent($id);
$returl = "details.php?id=$id&edited=1";
if (isset($_POST["returnto"]))
$returl = $_POST["returnto"];
+3
View File
@@ -372,6 +372,9 @@ KPS("+",$uploadtorrent_bonus,$CURUSER["id"]);
write_log("Torrent $id ($torrent) was uploaded by $anon");
$searchRep = new \App\Repositories\SearchRepository();
$searchRep->addTorrent($id);
//===notify people who voted on offer thanks CoLdFuSiOn :)
if ($is_offer)
{
+30 -16
View File
@@ -12,9 +12,10 @@ parked();
$tagRep = new \App\Repositories\TagRepository();
$tagKeyById = $tagRep->createBasicQuery()->get()->keyBy('id');
$renderKeyArr = $tagKeyById->keys()->toArray();
$elasticsearchEnabled = nexus_env('ELASTICSEARCH_ENABLED');
//check searchbox
switch (CURRENT_SCRIPT) {
switch (nexus()->getScript()) {
case 'torrents':
$sectiontype = $browsecatmode;
break;
@@ -847,10 +848,17 @@ else
$sql = "SELECT COUNT(*), categories.mode FROM torrents LEFT JOIN categories ON category = categories.id " . ($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "") . $tagFilter . $where . " GROUP BY categories.mode";
}
$res = sql_query($sql);
$count = 0;
while($row = mysql_fetch_array($res))
$count += $row[0];
if ($elasticsearchEnabled) {
$searchRep = new \App\Repositories\SearchRepository();
$resultFromElastic = $searchRep->listTorrentFromEs($_GET, $CURUSER['id'], $_SERVER['QUERY_STRING']);
$count = $resultFromElastic['total'];
} else {
$res = sql_query($sql);
$count = 0;
while($row = mysql_fetch_array($res)) {
$count += $row[0];
}
}
if ($CURUSER["torrentsperpage"])
$torrentsperpage = (int)$CURUSER["torrentsperpage"];
@@ -883,17 +891,19 @@ if ($count)
//echo $addparam;
list($pagertop, $pagerbottom, $limit) = pager($torrentsperpage, $count, "?" . $addparam);
if ($allsec == 1 || $enablespecial != 'yes'){
$query = "SELECT torrents.id, torrents.sp_state, torrents.promotion_time_type, torrents.promotion_until, torrents.banned, torrents.picktype, torrents.pos_state, torrents.category, torrents.source, torrents.medium, torrents.codec, torrents.standard, torrents.processing, torrents.team, torrents.audiocodec, torrents.leechers, torrents.seeders, torrents.name, torrents.small_descr, torrents.times_completed, torrents.size, torrents.added, torrents.comments,torrents.anonymous,torrents.owner,torrents.url,torrents.cache_stamp,torrents.pt_gen,torrents.hr FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." $tagFilter $where $orderby $limit";
}
else{
$query = "SELECT torrents.id, torrents.sp_state, torrents.promotion_time_type, torrents.promotion_until, torrents.banned, torrents.picktype, torrents.pos_state, torrents.category, torrents.source, torrents.medium, torrents.codec, torrents.standard, torrents.processing, torrents.team, torrents.audiocodec, torrents.leechers, torrents.seeders, torrents.name, torrents.small_descr, torrents.times_completed, torrents.size, torrents.added, torrents.comments,torrents.anonymous,torrents.owner,torrents.url,torrents.cache_stamp,torrents.pt_gen,torrents.hr FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." LEFT JOIN categories ON torrents.category=categories.id $tagFilter $where $orderby $limit";
if ($allsec == 1 || $enablespecial != 'yes'){
$query = "SELECT torrents.id, torrents.sp_state, torrents.promotion_time_type, torrents.promotion_until, torrents.banned, torrents.picktype, torrents.pos_state, torrents.category, torrents.source, torrents.medium, torrents.codec, torrents.standard, torrents.processing, torrents.team, torrents.audiocodec, torrents.leechers, torrents.seeders, torrents.name, torrents.small_descr, torrents.times_completed, torrents.size, torrents.added, torrents.comments,torrents.anonymous,torrents.owner,torrents.url,torrents.cache_stamp,torrents.pt_gen,torrents.hr FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." $tagFilter $where $orderby $limit";
}
else{
$query = "SELECT torrents.id, torrents.sp_state, torrents.promotion_time_type, torrents.promotion_until, torrents.banned, torrents.picktype, torrents.pos_state, torrents.category, torrents.source, torrents.medium, torrents.codec, torrents.standard, torrents.processing, torrents.team, torrents.audiocodec, torrents.leechers, torrents.seeders, torrents.name, torrents.small_descr, torrents.times_completed, torrents.size, torrents.added, torrents.comments,torrents.anonymous,torrents.owner,torrents.url,torrents.cache_stamp,torrents.pt_gen,torrents.hr FROM torrents ".($search_area == 3 || $column == "owner" ? "LEFT JOIN users ON torrents.owner = users.id " : "")." LEFT JOIN categories ON torrents.category=categories.id $tagFilter $where $orderby $limit";
}
if (!$elasticsearchEnabled) {
$res = sql_query($query);
}
} else {
unset($res);
}
$res = sql_query($query);
}
else
unset($res);
if (isset($searchstr))
stdhead($lang_torrents['head_search_results_for'].$searchstr_ori);
elseif ($sectiontype == $browsecatmode)
@@ -1120,8 +1130,12 @@ elseif($inclbookmarked == 2)
if ($count) {
$rows = [];
while ($row = mysql_fetch_assoc($res)) {
$rows[] = $row;
if ($elasticsearchEnabled) {
$rows = $resultFromElastic['data'];
} else {
while ($row = mysql_fetch_assoc($res)) {
$rows[] = $row;
}
}
print($pagertop);
if ($sectiontype == $browsecatmode)
+17 -1
View File
@@ -275,7 +275,7 @@ if ($user["avatar"])
tr_small($lang_userdetails['row_avatar'], return_avatar_image(htmlspecialchars(trim($user["avatar"]))), 1);
if ($userInfo->valid_medals->isNotEmpty()) {
tr_small($lang_userdetails['row_medal'], build_medal_image($userInfo->valid_medals), 1);
tr_small($lang_userdetails['row_medal'], build_medal_image($userInfo->valid_medals, 200, $CURUSER['id'] == $user['id']), 1);
}
$uclass = get_user_class_image($user["class"]);
@@ -500,5 +500,21 @@ if (get_user_class() >= $prfmanage_class && $user["class"] < get_user_class())
}
}
end_main_frame();
echo <<<EOT
<script>
jQuery('input[type="checkbox"][name="medal_wearing_status"]').on("change", function (e) {
let input = jQuery(this);
let checked = input.prop("checked")
jQuery.post('ajax.php', {params: {id: this.value}, action: 'toggleUserMedalStatus'}, function (response) {
console.log(response)
if (response.ret != 0) {
input.prop("checked", !checked)
alert(response.msg)
}
}, 'json')
})
</script>
EOT;
stdfoot();
?>
+4 -4
View File
@@ -3,9 +3,9 @@ require "../include/bittorrent.php";
dbconn();
require_once(get_langfile_path());
//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/xml; charset=utf-8");
@@ -51,7 +51,7 @@ function dltable($name, $arr, $torrent)
else
$s .= "<td class=rowfollow align=left width=1%>" . get_username($e['userid']);
$secs = max(1, ($e["la"] - $e["st"]));
$secs = max(1, ($e["la"] - $e["st"]));
if ($enablelocation_tweak == 'yes'){
list($loc_pub, $loc_mod) = get_ip_location($e["ip"]);
$location = get_user_class() >= $userprofile_class ? "<div title='" . $loc_mod . "'>" . $loc_pub . "</div>" : $loc_pub;