mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
api scrape + medal wearing status
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
|
||||
|
||||
+7
-12
@@ -1,22 +1,17 @@
|
||||
<?php
|
||||
defined('NEXUS_START') || define('NEXUS_START', microtime(true));
|
||||
defined('IN_NEXUS') || define('IN_NEXUS', true);
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', true);
|
||||
require __DIR__ . '/../include/constants.php';
|
||||
require __DIR__ . '/../include/globalfunctions.php';
|
||||
require __DIR__ . '/../include/functions_announce.php';
|
||||
$announceApiLocalHost = nexus_env('ANNOUNCE_API_LOCAL_HOST');
|
||||
if ($announceApiLocalHost) {
|
||||
do_log("[GOING_TO_REQUEST_LOCAL_ANNOUNCE_URL] $announceApiLocalHost");
|
||||
$response = request_local_announce_api($announceApiLocalHost);
|
||||
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 ANNOUNCE_API_LOCAL_HOST");
|
||||
err("error from TRACKER_API_LOCAL_HOST");
|
||||
} else {
|
||||
exit(benc_resp_raw($response));
|
||||
}
|
||||
}
|
||||
//continue the normal process
|
||||
require_once('../include/bittorrent_announce.php');
|
||||
require ROOT_PATH . 'include/core.php';
|
||||
dbconn_announce();
|
||||
do_log(nexus_json_encode($_SERVER));
|
||||
//1. BLOCK ACCESS WITH WEB BROWSERS AND CHEATS!
|
||||
|
||||
+3
-3
@@ -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"])
|
||||
|
||||
+2
-2
@@ -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";
|
||||
|
||||
@@ -31,9 +31,6 @@ if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
|
||||
|
|
||||
*/
|
||||
|
||||
require dirname(__DIR__) . '/include/globalfunctions.php';
|
||||
require dirname(__DIR__) . '/include/functions.php';
|
||||
|
||||
require __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
/*
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
+17
-1
@@ -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();
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user