New folder structure, HTTP response, <a> css & more

Better error codes in PHP
HTTP response codes
CSS changed to <a> elements
Changed folder structure of html files to folder with index.html
Linking between main, admin and caching pages
Added footer to caching page
This commit is contained in:
aunefyren 2021-10-11 14:25:19 +02:00
parent 00f1bd48e3
commit b098bc88ad
12 changed files with 98 additions and 71 deletions

View file

@ -1,8 +0,0 @@
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]

View file

@ -395,7 +395,7 @@ function test_tautulli_connection() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", 'api/get_connection.php');
xhttp.open("post", root + 'api/get_connection.php');
xhttp.send(config_data);
}

View file

@ -8,13 +8,13 @@
<title>Plex Wrapped</title>
<!-- Bootstrap 4 CSS and custom CSS -->
<link rel="stylesheet" type="text/css" href="assets/css/wrapped.css" />
<link rel="shortcut icon" href="assets/img/favicons/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../assets/css/wrapped.css" />
<link rel="shortcut icon" href="../assets/img/favicons/favicon.ico" />
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="./admin.js"></script>
<script src="./get_config.js"></script>
<script src="./set_config.js"></script>
<script src="../admin.js"></script>
<script src="../get_config.js"></script>
<script src="../set_config.js"></script>
</head>
<body>
@ -26,7 +26,7 @@
<div class="boks3" id="search_input" style="padding: 0 !important;">
<div class="boks2" style="float: none !important; display: block; padding: 0; margin-top: 0em;">
<img src="assets/img/gift.svg" onclick="window.location.href = './';" style="width: 15em; cursor: pointer;">
<img src="../assets/img/gift.svg" onclick="window.location.href = '../';" style="width: 15em; cursor: pointer;">
</div>
<div class="boks2" style="float: none !important; display: block; margin-top: 0em; padding-top: 0;">
@ -49,13 +49,16 @@
</div>
<div class="footer" id="footer">
<a style="color: white; font-weight: normal; font-size: 0.75em; text-decoration: none;" href="https://github.com/aunefyren/Plex-Wrapped">Powered by Plex Wrapped</a>
<a style="color: white; font-weight: normal; font-size: 0.75em; text-decoration: none;" href="https://github.com/aunefyren/Plex-Wrapped" target="_blank">Powered by Plex Wrapped</a>
</div>
<div class="content" id="search_results">
</div>
<script type="text/javascript">
var root = "../";
var first_time = false;
var tautulli_apikey = "";
@ -96,7 +99,7 @@ var current_username = "";
$(document).ready(function() {
get_config_initial();
get_config_initial("../");
});
</script>

View file

@ -15,6 +15,7 @@ $arrContextOptions= [
];
if (empty($config)) {
http_response_code(400);
echo json_encode(array("message" => "Plex Wrapped is not configured.", "error" => true));
exit(0);
}
@ -28,22 +29,20 @@ $connection = create_url();
//Declare given inputs
if(!empty($data)){
$p_identity = htmlspecialchars(trim($data->p_identity));
$caching = htmlspecialchars(trim($data->caching));
} else if(isset($_GET["p_identity"]) && isset($_GET["caching"])) {
} else if(isset($_GET["p_identity"])) {
$p_identity = htmlspecialchars(trim($_GET["p_identity"]));
$caching = htmlspecialchars(trim($_GET["caching"]));
} else {
http_response_code(400);
echo json_encode(array("message" => "Input error.", "error" => true));
exit(0);
}
if($caching == "False" || $caching == "false") {
$caching = False;
} else if($caching == "True" || $caching == "true") {
$caching = True;
if(!empty($data)){
$caching = filter_var(htmlspecialchars(trim($data->caching)), FILTER_VALIDATE_BOOLEAN);
} else if(isset($_GET["caching"])) {
$caching = filter_var(htmlspecialchars(trim($_GET["caching"])), FILTER_VALIDATE_BOOLEAN);
} else {
echo json_encode(array("message" => "Can't parse caching parameter.", "error" => true));
exit(0);
$caching = False;
}
// Confirm input variables
@ -53,7 +52,8 @@ if($caching) {
} else if(isset($_GET["cache_limit"])) {
$cache_limit = htmlspecialchars(trim($_GET["cache_limit"]));
} else {
echo json_encode(array("message" => "No cache_limit input.", "error" => true));
http_response_code(400);
echo json_encode(array("message" => "Caching enabled. No 'cache_limit' input.", "error" => true));
exit(0);
}
}
@ -64,6 +64,7 @@ if($caching) {
log_activity($id, "Caching mode enabled");
if(!$config->use_cache) {
http_response_code(400);
echo json_encode(array("message" => "Caching is disabled.", "error" => true));
exit(0);
}
@ -102,6 +103,7 @@ if($caching) {
update_cache($tautulli_data);
}
http_response_code(200);
echo json_encode(array("message" => "Caching complete.", "caching_complete" => $complete_date_loop, "error" => False));
exit(0);
@ -110,6 +112,7 @@ if($caching) {
// Get user ID
$id = tautulli_get_user($p_identity);
if (!$id) {
http_response_code(400);
echo json_encode(array("message" => "No user found.", "error" => true));
exit(0);
}
@ -120,6 +123,7 @@ log_activity($id, "User found");
// Get user name
$name = tautulli_get_name($id);
if(!$name) {
http_response_code(400);
echo json_encode(array("message" => "Could not find username.", "error" => true));
exit(0);
}
@ -214,8 +218,6 @@ if($config->get_user_movie_stats || $config->get_user_show_stats || $config->get
if($config->get_year_stats_shows && $config->get_user_show_buddy && count($user_shows["data"]["shows"]) > 0) {
log_activity($id, "Getting show buddy");
//print_r($tautulli_data);
//exit();
$user_shows["data"] = $user_shows["data"] + array("show_buddy" => data_get_user_show_buddy($id, $user_shows["data"]["shows"][0]["title"], $tautulli_data));
} else {
$user_shows["data"] = $user_shows["data"] + array("show_buddy" => array("message" => "Disabled in config.", "error" => True));
@ -245,6 +247,7 @@ $result = json_encode(array("error" => False,
));
http_response_code(200);
echo $result;
exit(0);
@ -291,7 +294,8 @@ function tautulli_get_user($input) {
if(!isset($response)) {
throw new Exception('Could not reach Tautulli.');
}
} catch (Exception $e) {
} catch (Error $e) {
http_response_code(500);
echo json_encode(array("message" => $e->getMessage(), "error" => true));
exit(0);
}
@ -358,24 +362,30 @@ function log_activity($id, $message) {
global $config;
if($config->use_logs) {
$date = date('Y-m-d H:i:s');
try {
$date = date('Y-m-d H:i:s');
$path = "../config/wrapped.log";
if(!file_exists($path)) {
$temp = fopen($path, "w");
fwrite($temp, 'Plex Wrapped');
fclose($temp);
$path = "../config/wrapped.log";
if(@!file_exists($path)) {
$temp = @fopen($path, "w");
fwrite($temp, 'Plex Wrapped');
fclose($temp);
}
$log_file = @fopen($path, 'a');
@fwrite($log_file, PHP_EOL . $date . ' - get_stats.php - ID: ' . $id . ' - ' . $message);
if(@fclose($log_file)) {
return True;
}
} catch(Error $e) {
http_response_code(500);
echo json_encode(array("error" => True, "message" => "Failed to log event."));
exit();
}
$log_file = fopen($path, 'a');
fwrite($log_file, PHP_EOL . $date . ' - get_stats.php - ID: ' . $id . ' - ' . $message);
if(fclose($log_file)) {
return True;
} else {
echo json_encode(array("error" => True, "message" => "Failed to log event"));
}
}
}
return True;
}

View file

@ -63,6 +63,11 @@ p{
margin: 0;
}
a {
color: inherit;
text-decoration: underline;
}
img {
max-width: 100%;
}

View file

@ -41,7 +41,7 @@ function cache() {
<form id='stats_form' class='form' onsubmit='return false' action="" method="post">
<div class='form-group'>
<img id="loading_icon" src="assets/loading.gif" style="border-radius: 25px; background-color: white; padding: 1em; width: 4em; height: 4em; display: inline;">
<img id="loading_icon" src="../assets/loading.gif" style="border-radius: 25px; background-color: white; padding: 1em; width: 4em; height: 4em; display: inline;">
</div>
<h3>Caching log:</h3>
@ -80,7 +80,7 @@ function get_stats(days) {
stats_form = {
"p_identity" : '0',
"caching" : "True",
"caching" : true,
"cache_limit" : days
};
@ -110,7 +110,7 @@ function get_stats(days) {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/get_stats.php", );
xhttp.open("post", root + "api/get_stats.php", );
xhttp.send(stats_data);
return;
}
@ -137,11 +137,12 @@ function get_config_cache() {
login_menu();
} else {
alert(result.message);
window.location.href = "../admin";
}
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/get_config.php");
xhttp.open("post", root + "api/get_config.php");
xhttp.send(config_data);
}
@ -172,7 +173,7 @@ function get_config() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/get_config.php");
xhttp.open("post", root + "api/get_config.php");
xhttp.send(config_data);
}

View file

@ -8,11 +8,11 @@
<title>Plex Wrapped</title>
<!-- Bootstrap 4 CSS and custom CSS -->
<link rel="stylesheet" type="text/css" href="assets/css/wrapped.css" />
<link rel="shortcut icon" href="assets/img/favicons/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../assets/css/wrapped.css" />
<link rel="shortcut icon" href="../assets/img/favicons/favicon.ico" />
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="./caching.js"></script>
<script src="../caching.js"></script>
</head>
<body>
@ -24,7 +24,7 @@
<div class="boks3" id="search_input" style="padding: 0 !important;">
<div class="boks2" style="float: none !important; display: block; padding: 0; margin-top: 0em;">
<img src="assets/img/gift.svg" onclick="window.location.href = './';" style="width: 15em; cursor: pointer;">
<img src="../assets/img/gift.svg" onclick="window.location.href = '../';" style="width: 15em; cursor: pointer;">
</div>
<div class="boks2" style="float: none !important; display: block; margin-top: 0em; padding-top: 0;">
@ -32,7 +32,7 @@
<div class="stats_tekst" style="height: auto;">
<p>
If you want to decrease loadtime for your users you can pre-cache their results.
<br><br>Remember to configure the system first.
<br><br><a href="../admin">Remember to configure the system first.</a>
</p>
</div>
@ -45,19 +45,27 @@
<div class="search" id="cache">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="content" id="search_results">
</div>
<div class="content" id="search_results">
</div>
<div class="footer" id="footer">
<a style="color: white; font-weight: normal; font-size: 0.75em; text-decoration: none;" href="https://github.com/aunefyren/Plex-Wrapped" target="_blank">Powered by Plex Wrapped</a>
</div>
<script type="text/javascript">
var root = "../";
$(document).ready(function() {
get_config_cache();

View file

@ -21,7 +21,7 @@ function get_config_initial() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/get_config.php");
xhttp.open("post", root + "api/get_config.php");
xhttp.send(config_data);
}
@ -83,6 +83,6 @@ function get_config() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/get_config.php");
xhttp.open("post", root + "api/get_config.php");
xhttp.send(config_data);
}

View file

@ -9,7 +9,11 @@ function get_functions() {
if (this.readyState == 4 && this.status == 200) {
var result = JSON.parse(this.responseText);
if(result.error) {
document.getElementById('results_error').innerHTML = '<p style="color:inherit; text-shadow: none;">' + result.message + '</p>';
if(result.message == 'Plex Wrapped is not configured.') {
document.getElementById('results_error').innerHTML = '<a href="./admin"><p style="color:inherit; text-shadow: none;">' + result.message + '</p></a>';
} else {
document.getElementById('results_error').innerHTML = '<p style="color:inherit; text-shadow: none;">' + result.message + '</p>';
}
} else {
functions = result;
get_stats();
@ -17,6 +21,6 @@ function get_functions() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/get_functions.php");
xhttp.open("post", root + "api/get_functions.php");
xhttp.send(config_data);
}

View file

@ -7,20 +7,21 @@ function get_stats() {
stats_form = {
"p_identity" : p_identity.trim(),
"caching" : "False"
"caching" : false
};
var stats_data = JSON.stringify(stats_form);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (this.readyState == 4 && (this.status == 200 || this.status == 400 || this.status == 500)) {
try {
var result= JSON.parse(this.responseText);
if(result.error) {
loading_icon.style.display = "none";
search_button("SEARCH");
document.getElementById('results_error').innerHTML = '<p style="color:inherit; text-shadow: none;">' + result.message + '</p>';
document.getElementById('results_error').innerHTML = '<p style="color:inherit; text-shadow: none;">' + result.message + '</p>';
} else {
load_page(this.responseText);
}
@ -555,7 +556,7 @@ function load_longest_episode(array) {
html += "<div class='status' id='list3' style='padding:1em;min-width:15em;'>";
html += "<div class='stats'>";
html += "Your really liked the episode <b>" + array.title + "</b> from " + array.grandparent_title + "<br>";
html += "<br>It recieved " + play_plays(array.plays) + " and was endured for " + seconds_to_time(array.duration, false) + ".";
html += "<br>It recieved " + play_plays(array.plays) + " and was endured for " + seconds_to_time(array.duration, false) + "";
html += "</div>";
html += "</div>";

View file

@ -82,7 +82,7 @@
</div>
<div class="footer" id="footer">
<a style="color: white; font-weight: normal; font-size: 0.75em; text-decoration: none;" href="https://github.com/aunefyren/Plex-Wrapped">Powered by Plex Wrapped</a>
<a style="color: white; font-weight: normal; font-size: 0.75em; text-decoration: none;" href="https://github.com/aunefyren/Plex-Wrapped" target="_blank">Powered by Plex Wrapped</a>
</div>
</div>
@ -90,6 +90,9 @@
</div>
<script type="text/javascript">
var root = "./";
$(document).ready(function() {
});

View file

@ -41,11 +41,11 @@ function set_config() {
alert(result.message);
} else {
alert(result.message);
window.location.href = "./";
window.location.href = "../";
}
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/set_config.php");
xhttp.open("post", root + "api/set_config.php");
xhttp.send(config_data);
}