Prettier Formatting

This commit is contained in:
2019-09-12 17:15:11 -04:00
parent 37f97054e4
commit 7d72c7c593
6 changed files with 451 additions and 387 deletions

138
class.php
View File

@@ -1,16 +1,16 @@
<?php
class ps4 {
public function dbconf() {
class ps4
{
public function dbconf()
{
global $dbconf;
$dbconf = require "dbconf.php";
return $dbconf;
}
function mysql_conn($sql=null) {
function mysql_conn($sql = null)
{
$db = $this->dbconf();
// Create connection
@@ -32,7 +32,8 @@ class ps4 {
}
}
function gameTimeDetails($gameid) {
function gameTimeDetails($gameid)
{
$result = $this->mysql_conn("SELECT * FROM game_time WHERE game_id = '" . $gameid . "' ORDER BY game_start DESC;");
if ($result->num_rows > 0) {
$i = 0;
@@ -53,21 +54,24 @@ class ps4 {
echo '<div class="PlaytimeTotal">';
if ($row["game_end"] == "") {
echo $this->playtime(((round(microtime(true) * 1000)-$row["game_start"])/1000),true);
echo $this->playtime((round(microtime(true) * 1000) - $row["game_start"]) / 1000, true);
} else {
echo $this->playtime((($row["game_end"]-$row["game_start"])/1000),true);
echo $this->playtime(($row["game_end"] - $row["game_start"]) / 1000, true);
}
echo '</div>';
echo '</div>';
}
echo '<div class="row"><div class="head PlaytimeStart"></div><div class="head PlaytimeEnd"></div><div class="head PlaytimeTotal">'. $i .' sessions</div></div>';
echo '<div class="row"><div class="head PlaytimeStart"></div><div class="head PlaytimeEnd"></div><div class="head PlaytimeTotal">' .
$i .
' sessions</div></div>';
echo '</div>';
echo '<div class="padding-bottom-10"></div>';
}
}
function playtime($seconds, $text=false) {
function playtime($seconds, $text = false)
{
$playtime = null;
$label = null;
@@ -75,33 +79,42 @@ class ps4 {
if ($text == true) {
$label = "second";
}
if ($seconds > 1) { $label .= "s"; }
if ($seconds > 1) {
$label .= "s";
}
$playtime = $seconds;
} else
if ($seconds/60 < 60) {
} elseif ($seconds / 60 < 60) {
if ($text == true) {
$label = "minute";
}
if ($seconds/60 > 1) { $label .= "s"; }
if ($seconds / 60 > 1) {
$label .= "s";
}
$playtime = round($seconds / 60, 2);
} else {
if ($text == true) {
$label = "hour";
}
if ($seconds/60/60 > 1) { $label .= "s"; }
if ($seconds / 60 / 60 > 1) {
$label .= "s";
}
$playtime = round($seconds / 60 / 60, 2);
}
$return = $playtime;
if ($text == true) { $return = $return ." ". $label; }
if ($text == true) {
$return = $return . " " . $label;
}
return $return;
}
function secondsToDate($seconds) {
function secondsToDate($seconds)
{
return date("d M Y H:i:s", $seconds / 1000);
}
function thumbnailurl($game_id) {
function thumbnailurl($game_id)
{
$result = $this->mysql_conn("SELECT thumbnail_url FROM game_thumbnail WHERE game_id = '" . $game_id . "' limit 1;");
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
@@ -113,7 +126,8 @@ class ps4 {
return $url;
}
function thumbnailupdateurl($gameid,$gamename,$url) {
function thumbnailupdateurl($gameid, $gamename, $url)
{
$actualurl = $this->thumbnailurl($gameid);
if ($actualurl == "images/no-thumbnail.png") {
$sql = "INSERT INTO game_thumbnail (game_id, thumbnail_url) VALUES ('" . $gameid . "', '" . $url . "');";
@@ -121,36 +135,45 @@ class ps4 {
$sql = "UPDATE game_thumbnail SET thumbnail_url = '" . $url . "' WHERE game_id = '" . $gameid . "';";
}
if (($url == "") or ($url == "null")) {
if ($url == "" or $url == "null") {
echo "<div class=\"message-error center500\"><div class=\"message-head\">ERROR</div><div class=\"message-details\">No URL specified.</div>";
} else {
if ($this->isImage($url)) {
$result = $this->mysql_conn($sql);
if ($result == 1) {
echo "<div class=\"message-success center500\"><div class=\"message-head\">SUCCESS</div><div class=\"message-details\">Updated image URL for <strong>". $gamename ."</strong> (". $gameid .")</div>";
echo "<div class=\"message-success center500\"><div class=\"message-head\">SUCCESS</div><div class=\"message-details\">Updated image URL for <strong>" .
$gamename .
"</strong> (" .
$gameid .
")</div>";
} else {
echo "<div class=\"message-error center500\"><div class=\"message-head\">ERROR</div><div class=\"message-details\">Can't update image URL for <strong>". $gamename ."</strong> (". $gameid .")</div>";
echo "<div class=\"message-error center500\"><div class=\"message-head\">ERROR</div><div class=\"message-details\">Can't update image URL for <strong>" .
$gamename .
"</strong> (" .
$gameid .
")</div>";
}
} else {
echo "<div class=\"message-error center500\"><div class=\"message-head\">ERROR</div><div class=\"message-details\">Not an image.</div>";
}
}
}
function isImage($url)
{
$params = array('http' => array(
$params = array(
'http' => array(
'method' => 'HEAD'
));
)
);
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp)
return false; // Problem with url
if (!$fp) {
return false;
} // Problem with url
$meta = stream_get_meta_data($fp);
if ($meta === false)
{
if ($meta === false) {
fclose($fp);
return false; // Problem reading data from url
}
@@ -158,8 +181,8 @@ class ps4 {
$wrapper_data = $meta["wrapper_data"];
if (is_array($wrapper_data)) {
foreach (array_keys($wrapper_data) as $hh) {
if (substr($wrapper_data[$hh], 0, 19) == "Content-Type: image") // strlen("Content-Type: image") == 19
{
if (substr($wrapper_data[$hh], 0, 19) == "Content-Type: image") {
// strlen("Content-Type: image") == 19
fclose($fp);
return true;
}
@@ -170,37 +193,50 @@ class ps4 {
return false;
}
function games_reorder($games,$orderby="last_played_desc") {
function totaltime_asc($a,$b) {
return ($a["game_total_time"] <= $b["game_total_time"]) ? -1 : 1;
function games_reorder($games, $orderby = "last_played_desc")
{
function totaltime_asc($a, $b)
{
return $a["game_total_time"] <= $b["game_total_time"] ? -1 : 1;
}
function totaltime_desc($a,$b) {
return ($a["game_total_time"] >= $b["game_total_time"]) ? -1 : 1;
function totaltime_desc($a, $b)
{
return $a["game_total_time"] >= $b["game_total_time"] ? -1 : 1;
}
function firstplayed_asc($a,$b) {
return ($a["game_played_first"] <= $b["game_played_first"]) ? -1 : 1;
function firstplayed_asc($a, $b)
{
return $a["game_played_first"] <= $b["game_played_first"] ? -1 : 1;
}
function firstplayed_desc($a,$b) {
return ($a["game_played_first"] >= $b["game_played_first"]) ? -1 : 1;
function firstplayed_desc($a, $b)
{
return $a["game_played_first"] >= $b["game_played_first"] ? -1 : 1;
}
function lastplayed_asc($a,$b) {
if ($a["game_played_last"] == -1) { $a["game_played_last"] = (round(microtime(true) * 1000)); }
if ($b["game_played_last"] == -1) { $b["game_played_last"] = (round(microtime(true) * 1000)); }
return ($a["game_played_last"] <= $b["game_played_last"]) ? -1 : 1;
function lastplayed_asc($a, $b)
{
if ($a["game_played_last"] == -1) {
$a["game_played_last"] = round(microtime(true) * 1000);
}
function lastplayed_desc($a,$b) {
if ($a["game_played_last"] == -1) { $a["game_played_last"] = (round(microtime(true) * 1000)); }
if ($b["game_played_last"] == -1) { $b["game_played_last"] = (round(microtime(true) * 1000)); }
return ($a["game_played_last"] >= $b["game_played_last"]) ? -1 : 1;
if ($b["game_played_last"] == -1) {
$b["game_played_last"] = round(microtime(true) * 1000);
}
return $a["game_played_last"] <= $b["game_played_last"] ? -1 : 1;
}
function lastplayed_desc($a, $b)
{
if ($a["game_played_last"] == -1) {
$a["game_played_last"] = round(microtime(true) * 1000);
}
if ($b["game_played_last"] == -1) {
$b["game_played_last"] = round(microtime(true) * 1000);
}
return $a["game_played_last"] >= $b["game_played_last"] ? -1 : 1;
}
usort($games, $orderby);
return $games;
}
}
?>

View File

@@ -7,8 +7,6 @@ error_reporting(E_ALL);
$rootpage = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : "index.php";
$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : "lastplayed_desc";
$details = isset($_GET['details']) ? $_GET['details'] : "";
?>
<!DOCTYPE html>
@@ -26,7 +24,7 @@ $details = isset($_GET['details']) ? $_GET['details'] : "";
update();
});
function update() {
$.get('page.php?rootpage=<?php echo $rootpage ?>&orderby=<?php echo $orderby ?>&details=<?php echo $details ?>', function(data) {
$.get('page.php?rootpage=<?php echo $rootpage; ?>&orderby=<?php echo $orderby; ?>&details=<?php echo $details; ?>', function(data) {
$("#page").html(data);
window.setTimeout(update, 10000); // 10 secondes
});

View File

@@ -1,5 +1,5 @@
<?php
include_once("class.php");
include_once "class.php";
$ps4 = new ps4();
@@ -9,45 +9,66 @@ $result = $ps4->mysql_conn($sql);
$rootpage = $_GET['rootpage'];
$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : "lastplayed_desc";
$details = isset($_GET['details']) ? $_GET['details'] : "";
?>
<div class="refresh center500">
<strong>Last refresh : </strong> <?php echo date(DATE_RFC2822) ?>
<strong>Last refresh : </strong> <?php echo date(DATE_RFC2822); ?>
</div>
<div class="center500 padding-bottom-3">
<div class="orderby">
<a href="<?php echo $rootpage ?>?orderby=totaltime_asc"><i class="material-icons md-arrow <?php if ($orderby == "totaltime_asc") { echo "md-active"; } ?> vertical-align-middle padding-bottom-3">arrow_drop_up</i></a>
<a href="<?php echo $rootpage; ?>?orderby=totaltime_asc"><i class="material-icons md-arrow <?php if (
$orderby == "totaltime_asc"
) {
echo "md-active";
} ?> vertical-align-middle padding-bottom-3">arrow_drop_up</i></a>
Total Time
<a href="<?php echo $rootpage ?>?orderby=totaltime_desc"><i class="material-icons md-arrow <?php if ($orderby == "totaltime_desc") { echo "md-active"; } ?> vertical-align-middle padding-bottom-3">arrow_drop_down</i></a>
<a href="<?php echo $rootpage; ?>?orderby=totaltime_desc"><i class="material-icons md-arrow <?php if (
$orderby == "totaltime_desc"
) {
echo "md-active";
} ?> vertical-align-middle padding-bottom-3">arrow_drop_down</i></a>
</div>
<div class="orderby">
<a href="<?php echo $rootpage ?>?orderby=firstplayed_asc"><i class="material-icons md-arrow <?php if ($orderby == "firstplayed_asc") { echo "md-active"; } ?> vertical-align-middle padding-bottom-3">arrow_drop_up</i></a>
<a href="<?php echo $rootpage; ?>?orderby=firstplayed_asc"><i class="material-icons md-arrow <?php if (
$orderby == "firstplayed_asc"
) {
echo "md-active";
} ?> vertical-align-middle padding-bottom-3">arrow_drop_up</i></a>
First Played
<a href="<?php echo $rootpage ?>?orderby=firstplayed_desc"><i class="material-icons md-arrow <?php if ($orderby == "firstplayed_desc") { echo "md-active"; } ?> vertical-align-middle padding-bottom-3">arrow_drop_down</i></a>
<a href="<?php echo $rootpage; ?>?orderby=firstplayed_desc"><i class="material-icons md-arrow <?php if (
$orderby == "firstplayed_desc"
) {
echo "md-active";
} ?> vertical-align-middle padding-bottom-3">arrow_drop_down</i></a>
</div>
<div class="orderby">
<a href="<?php echo $rootpage ?>?orderby=lastplayed_asc"><i class="material-icons md-arrow <?php if ($orderby == "lastplayed_asc") { echo "md-active"; } ?> vertical-align-middle padding-bottom-3">arrow_drop_up</i></a>
<a href="<?php echo $rootpage; ?>?orderby=lastplayed_asc"><i class="material-icons md-arrow <?php if (
$orderby == "lastplayed_asc"
) {
echo "md-active";
} ?> vertical-align-middle padding-bottom-3">arrow_drop_up</i></a>
Last Played
<a href="<?php echo $rootpage ?>?orderby=lastplayed_desc"><i class="material-icons md-arrow vertical-align-middle padding-bottom-3 <?php if ($orderby == "lastplayed_desc") { echo "md-active"; } ?>">arrow_drop_down</i></a>
<a href="<?php echo $rootpage; ?>?orderby=lastplayed_desc"><i class="material-icons md-arrow vertical-align-middle padding-bottom-3 <?php if (
$orderby == "lastplayed_desc"
) {
echo "md-active";
} ?>">arrow_drop_down</i></a>
</div>
</div>
<?php
if ($result->num_rows > 0) {
<?php if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
$games[$row["game_id"]]["game_id"] = $row["game_id"];
$games[$row["game_id"]]["game_name"] = $row["game_name"];
isset($games[$row["game_id"]]["game_total_time"]) ?: $games[$row["game_id"]]["game_total_time"] = 0;
isset($games[$row["game_id"]]["game_total_time"]) ?: ($games[$row["game_id"]]["game_total_time"] = 0);
isset($games[$row["game_id"]]["game_played_first"]) ?: $games[$row["game_id"]]["game_played_first"] = $row["game_start"];
isset($games[$row["game_id"]]["game_played_last"]) ?: $games[$row["game_id"]]["game_played_last"] = $row["game_end"];
isset($games[$row["game_id"]]["game_played_first"]) ?: ($games[$row["game_id"]]["game_played_first"] = $row["game_start"]);
isset($games[$row["game_id"]]["game_played_last"]) ?: ($games[$row["game_id"]]["game_played_last"] = $row["game_end"]);
if ($row["game_start"] < $games[$row["game_id"]]["game_played_first"]) {
$games[$row["game_id"]]["game_played_first"] = $row["game_start"];
}
@@ -55,11 +76,14 @@ if ($result->num_rows > 0) {
if ($row["game_end"] == "") {
$games[$row["game_id"]]["game_time"][$row["id"]] = -1;
$games[$row["game_id"]]["game_played_last"] = -1;
$games[$row["game_id"]]["game_total_time"] += ((round(microtime(true) * 1000)-$row["game_start"])/1000);
$games[$row["game_id"]]["game_total_time"] += (round(microtime(true) * 1000) - $row["game_start"]) / 1000;
} else {
$games[$row["game_id"]]["game_time"][$row["id"]] = (($row["game_end"]-$row["game_start"])/1000);
$games[$row["game_id"]]["game_total_time"] += (($row["game_end"]-$row["game_start"])/1000);
if (($row["game_end"] > $games[$row["game_id"]]["game_played_last"]) AND ($games[$row["game_id"]]["game_played_last"] != -1)) {
$games[$row["game_id"]]["game_time"][$row["id"]] = ($row["game_end"] - $row["game_start"]) / 1000;
$games[$row["game_id"]]["game_total_time"] += ($row["game_end"] - $row["game_start"]) / 1000;
if (
$row["game_end"] > $games[$row["game_id"]]["game_played_last"] and
$games[$row["game_id"]]["game_played_last"] != -1
) {
$games[$row["game_id"]]["game_played_last"] = $row["game_end"];
}
}
@@ -72,17 +96,35 @@ $games = $ps4->games_reorder($games, $orderby);
foreach ($games as $key => $value) {
echo "<div class=\"game\">";
echo "<div class=\"thumbnail\">";
echo "<img src=\"".$ps4->thumbnailurl($games[$key]["game_id"])."\" border=0 weight=\"80px\" height=\"80px\" onclick=\"thumbnailupdateurl('". $games[$key]["game_id"] ."', '". str_replace("'", "", $games[$key]["game_name"]) ."', '". $rootpage ."', '". $orderby ."', '". $details ."');\">";
echo "<img src=\"" .
$ps4->thumbnailurl($games[$key]["game_id"]) .
"\" border=0 weight=\"80px\" height=\"80px\" onclick=\"thumbnailupdateurl('" .
$games[$key]["game_id"] .
"', '" .
str_replace("'", "", $games[$key]["game_name"]) .
"', '" .
$rootpage .
"', '" .
$orderby .
"', '" .
$details .
"');\">";
echo "</div>";
echo "<div class=\"info\">";
echo "<strong>" . $games[$key]["game_name"] . "</strong>";
echo "<br/>";
echo "<div class=\"gameinfoline\"><div class=\"gameinfohead\">Total Time Played</div><div class=\"gameinfoseparator\"></div><div class=\"gameinfodetails\"><a href=\"".$rootpage."?orderby=".$orderby."&details=";
echo "<div class=\"gameinfoline\"><div class=\"gameinfohead\">Total Time Played</div><div class=\"gameinfoseparator\"></div><div class=\"gameinfodetails\"><a href=\"" .
$rootpage .
"?orderby=" .
$orderby .
"&details=";
if ($details != $games[$key]["game_id"]) {
echo $games[$key]["game_id"];
}
echo "\">" . $ps4->playtime($games[$key]["game_total_time"], true) . "</a></div></div>";
echo "<div class=\"gameinfoline\"><div class=\"gameinfohead\">First Played</div><div class=\"gameinfoseparator\"></div><div class=\"gameinfodetails\">". $ps4->secondsToDate($games[$key]["game_played_first"]) ."</div></div>";
echo "<div class=\"gameinfoline\"><div class=\"gameinfohead\">First Played</div><div class=\"gameinfoseparator\"></div><div class=\"gameinfodetails\">" .
$ps4->secondsToDate($games[$key]["game_played_first"]) .
"</div></div>";
echo "<div class=\"gameinfoline\"><div class=\"gameinfohead\">Last Played</div><div class=\"gameinfoseparator\"></div><div class=\"gameinfodetails\">";
if ($games[$key]["game_played_last"] == -1) {
@@ -106,10 +148,7 @@ echo "<pre>";
print_r($games);
echo "</pre>";
*/
} else {
echo "0 results";
}
?>
} ?>

View File

@@ -1,6 +1,6 @@
<?php
include_once("class.php");
include_once "class.php";
$ps4 = new ps4();

View File

@@ -1,6 +1,7 @@
body {
background-color: #1C406A;
font-family: 'Barlow';font-size: 16px;
background-color: #1c406a;
font-family: "Barlow";
font-size: 16px;
}
body:before {
@@ -85,7 +86,6 @@ a {
border-radius: 4px;
}
.message-success {
background: #a7d6ad;
border: 1px solid #034c00;
@@ -121,7 +121,9 @@ a {
.material-icons.md-arrow {
color: #5f94c2;
}
.material-icons.md-arrow.md-active { color: #274a68; }
.material-icons.md-arrow.md-active {
color: #274a68;
}
.vertical-align-middle {
vertical-align: middle;
}
@@ -135,7 +137,6 @@ a {
}
.gameinfoline {
}
.gameinfohead {

View File

@@ -1,41 +1,31 @@
function thumbnailupdateurl(gameid, gamename, rootpage, orderby, details) {
var url = prompt("Enter Image URL for " + gamename + " (" + gameid + ")", "");
if (url === "") {
alert("Enter something !");
} else {
var data = {
'what': 'thumbnail',
'gameid': gameid,
'gamename': gamename,
'url': url
what: "thumbnail",
gameid: gameid,
gamename: gamename,
url: url
};
$.ajax(
{
$.ajax({
type: "POST",
url: "post.php",
data: data,
success: function(data, textStatus, jqXHR)
{
success: function(data, textStatus, jqXHR) {
$(document).ready(function() {
$('#message').html(data);
$('#message').fadeIn('slow', function(){
$('#message').delay(3000).fadeOut();
$("#message").html(data);
$("#message").fadeIn("slow", function() {
$("#message")
.delay(3000)
.fadeOut();
});
$("#page").load('page.php?rootpage=' + rootpage + '&orderby=' + orderby + '&details=' + details);
$("#page").load("page.php?rootpage=" + rootpage + "&orderby=" + orderby + "&details=" + details);
});
}
});
}
}