moved to MeekroDB and also saving image directly to DB
This commit is contained in:
89
class.php
89
class.php
@@ -1,40 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
include_once "dbconf.php";
|
||||||
|
|
||||||
class ps4
|
class ps4
|
||||||
{
|
{
|
||||||
public function dbconf()
|
|
||||||
{
|
|
||||||
global $dbconf;
|
|
||||||
$dbconf = require "dbconf.php";
|
|
||||||
return $dbconf;
|
|
||||||
}
|
|
||||||
|
|
||||||
function mysql_conn($sql = null)
|
|
||||||
{
|
|
||||||
$db = $this->dbconf();
|
|
||||||
|
|
||||||
// Create connection
|
|
||||||
$conn = new mysqli($db["servername"], $db["username"], $db["password"], $db["dbname"]);
|
|
||||||
$conn->set_charset("utf8");
|
|
||||||
// Check connection
|
|
||||||
if ($conn->connect_error) {
|
|
||||||
die("Connection failed: " . $conn->connect_error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sql == null) {
|
|
||||||
echo "Error: No SQL Request?";
|
|
||||||
$conn->close();
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
$return = $conn->query($sql);
|
|
||||||
$conn->close();
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function gameTimeDetails($gameid)
|
function gameTimeDetails($gameid)
|
||||||
{
|
{
|
||||||
$result = $this->mysql_conn("SELECT * FROM game_time WHERE game_id = '" . $gameid . "' ORDER BY game_start DESC;");
|
$result = DB::query(
|
||||||
|
"SELECT * FROM game_time WHERE game_id = '" .
|
||||||
|
$gameid .
|
||||||
|
"' ORDER BY game_start DESC;"
|
||||||
|
);
|
||||||
if ($result->num_rows > 0) {
|
if ($result->num_rows > 0) {
|
||||||
$i = 0;
|
$i = 0;
|
||||||
echo '<div class="PlaytimeDetails FontSmaller">';
|
echo '<div class="PlaytimeDetails FontSmaller">';
|
||||||
@@ -42,7 +18,9 @@ class ps4
|
|||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
echo '<div class="row">';
|
echo '<div class="row">';
|
||||||
$i++;
|
$i++;
|
||||||
echo '<div class="PlaytimeStart">' . $this->secondsToDate($row["game_start"]) . '</div>';
|
echo '<div class="PlaytimeStart">' .
|
||||||
|
$this->secondsToDate($row["game_start"]) .
|
||||||
|
'</div>';
|
||||||
|
|
||||||
echo '<div class="PlaytimeEnd">';
|
echo '<div class="PlaytimeEnd">';
|
||||||
if ($row["game_end"] == "") {
|
if ($row["game_end"] == "") {
|
||||||
@@ -54,9 +32,15 @@ class ps4
|
|||||||
|
|
||||||
echo '<div class="PlaytimeTotal">';
|
echo '<div class="PlaytimeTotal">';
|
||||||
if ($row["game_end"] == "") {
|
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 {
|
} 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>';
|
||||||
|
|
||||||
@@ -115,31 +99,40 @@ class ps4
|
|||||||
|
|
||||||
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;");
|
$result = DB::queryFirstField(
|
||||||
if ($result->num_rows > 0) {
|
"SELECT thumbnail FROM game_thumbnail2 WHERE game_id = %s",
|
||||||
while ($row = $result->fetch_assoc()) {
|
$game_id
|
||||||
$url = $row["thumbnail_url"];
|
);
|
||||||
}
|
if ($result) {
|
||||||
|
$url = $result;
|
||||||
} else {
|
} else {
|
||||||
$url = "images/no-thumbnail.png";
|
$url = "images/no-thumbnail.png";
|
||||||
}
|
}
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function thumbnailupdateurl($gameid, $gamename, $url)
|
function thumbnailupdatedb($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 . "');";
|
|
||||||
} else {
|
|
||||||
$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>";
|
echo "<div class=\"message-error center500\"><div class=\"message-head\">ERROR</div><div class=\"message-details\">No URL specified.</div>";
|
||||||
} else {
|
} else {
|
||||||
if ($this->isImage($url)) {
|
if ($this->isImage($url)) {
|
||||||
$result = $this->mysql_conn($sql);
|
$imageContents = file_get_contents($url);
|
||||||
|
$actualurl = $this->thumbnailurl($gameid);
|
||||||
|
if ($actualurl == "images/no-thumbnail.png") {
|
||||||
|
$result = DB::query(
|
||||||
|
"INSERT INTO game_thumbnail2 (game_id, thumbnail) VALUES (%s, %?)",
|
||||||
|
$gameid,
|
||||||
|
$imageContents
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$result = DB::query(
|
||||||
|
"UPDATE game_thumbnail2 SET thumbnail = %? WHERE game_id = %s",
|
||||||
|
$imageContents,
|
||||||
|
$gameid
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($result == 1) {
|
if ($result == 1) {
|
||||||
echo "<div class=\"message-success center500\"><div class=\"message-head\">SUCCESS</div><div class=\"message-details\">Updated image URL for <strong>" .
|
echo "<div class=\"message-success center500\"><div class=\"message-head\">SUCCESS</div><div class=\"message-details\">Updated image URL for <strong>" .
|
||||||
$gamename .
|
$gamename .
|
||||||
|
|||||||
45
page.php
45
page.php
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
include_once "dbconf.php";
|
||||||
include_once "class.php";
|
include_once "class.php";
|
||||||
|
|
||||||
$ps4 = new ps4();
|
$ps4 = new ps4();
|
||||||
|
|
||||||
$sql = "SELECT * FROM game_time";
|
$sql = "SELECT * FROM game_time";
|
||||||
$result = $ps4->mysql_conn($sql);
|
$results = DB::query($sql);
|
||||||
|
|
||||||
$rootpage = $_GET['rootpage'];
|
$rootpage = $_GET['rootpage'];
|
||||||
$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : "lastplayed_desc";
|
$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : "lastplayed_desc";
|
||||||
@@ -59,16 +59,19 @@ $details = isset($_GET['details']) ? $_GET['details'] : "";
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if ($result->num_rows > 0) {
|
<?php if (DB::count() > 0) {
|
||||||
// output data of each row
|
// output data of each row
|
||||||
|
|
||||||
while ($row = $result->fetch_assoc()) {
|
foreach ($results as $row) {
|
||||||
$games[$row["game_id"]]["game_id"] = $row["game_id"];
|
$games[$row["game_id"]]["game_id"] = $row["game_id"];
|
||||||
$games[$row["game_id"]]["game_name"] = $row["game_name"];
|
$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_first"]) ?:
|
||||||
isset($games[$row["game_id"]]["game_played_last"]) ?: ($games[$row["game_id"]]["game_played_last"] = $row["game_end"]);
|
($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"]) {
|
if ($row["game_start"] < $games[$row["game_id"]]["game_played_first"]) {
|
||||||
$games[$row["game_id"]]["game_played_first"] = $row["game_start"];
|
$games[$row["game_id"]]["game_played_first"] = $row["game_start"];
|
||||||
}
|
}
|
||||||
@@ -76,10 +79,13 @@ $details = isset($_GET['details']) ? $_GET['details'] : "";
|
|||||||
if ($row["game_end"] == "") {
|
if ($row["game_end"] == "") {
|
||||||
$games[$row["game_id"]]["game_time"][$row["id"]] = -1;
|
$games[$row["game_id"]]["game_time"][$row["id"]] = -1;
|
||||||
$games[$row["game_id"]]["game_played_last"] = -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 {
|
} else {
|
||||||
$games[$row["game_id"]]["game_time"][$row["id"]] = ($row["game_end"] - $row["game_start"]) / 1000;
|
$games[$row["game_id"]]["game_time"][$row["id"]] =
|
||||||
$games[$row["game_id"]]["game_total_time"] += ($row["game_end"] - $row["game_start"]) / 1000;
|
($row["game_end"] - $row["game_start"]) / 1000;
|
||||||
|
$games[$row["game_id"]]["game_total_time"] +=
|
||||||
|
($row["game_end"] - $row["game_start"]) / 1000;
|
||||||
if (
|
if (
|
||||||
$row["game_end"] > $games[$row["game_id"]]["game_played_last"] and
|
$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"] != -1
|
||||||
@@ -96,8 +102,16 @@ $details = isset($_GET['details']) ? $_GET['details'] : "";
|
|||||||
foreach ($games as $key => $value) {
|
foreach ($games as $key => $value) {
|
||||||
echo "<div class=\"game\">";
|
echo "<div class=\"game\">";
|
||||||
echo "<div class=\"thumbnail\">";
|
echo "<div class=\"thumbnail\">";
|
||||||
echo "<img src=\"" .
|
$thumbnailurl = $ps4->thumbnailurl($games[$key]["game_id"]);
|
||||||
$ps4->thumbnailurl($games[$key]["game_id"]) .
|
if ($thumbnailurl == "images/no-thumbnail.png") {
|
||||||
|
$thumbnailsrc = $thumbnailurl;
|
||||||
|
} else {
|
||||||
|
$thumbnailsrc = 'data:image/jpeg;base64,' . base64_encode($thumbnailurl);
|
||||||
|
}
|
||||||
|
|
||||||
|
$thumbnailurlfinal =
|
||||||
|
"<img src=\"" .
|
||||||
|
$thumbnailsrc .
|
||||||
"\" border=0 weight=\"80px\" height=\"80px\" onclick=\"thumbnailupdateurl('" .
|
"\" border=0 weight=\"80px\" height=\"80px\" onclick=\"thumbnailupdateurl('" .
|
||||||
$games[$key]["game_id"] .
|
$games[$key]["game_id"] .
|
||||||
"', '" .
|
"', '" .
|
||||||
@@ -109,6 +123,9 @@ $details = isset($_GET['details']) ? $_GET['details'] : "";
|
|||||||
"', '" .
|
"', '" .
|
||||||
$details .
|
$details .
|
||||||
"');\">";
|
"');\">";
|
||||||
|
|
||||||
|
echo $thumbnailurlfinal;
|
||||||
|
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
echo "<div class=\"info\">";
|
echo "<div class=\"info\">";
|
||||||
echo "<strong>" . $games[$key]["game_name"] . "</strong>";
|
echo "<strong>" . $games[$key]["game_name"] . "</strong>";
|
||||||
@@ -121,7 +138,9 @@ $details = isset($_GET['details']) ? $_GET['details'] : "";
|
|||||||
if ($details != $games[$key]["game_id"]) {
|
if ($details != $games[$key]["game_id"]) {
|
||||||
echo $games[$key]["game_id"];
|
echo $games[$key]["game_id"];
|
||||||
}
|
}
|
||||||
echo "\">" . $ps4->playtime($games[$key]["game_total_time"], true) . "</a></div></div>";
|
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\">" .
|
echo "<div class=\"gameinfoline\"><div class=\"gameinfohead\">First Played</div><div class=\"gameinfoseparator\"></div><div class=\"gameinfodetails\">" .
|
||||||
$ps4->secondsToDate($games[$key]["game_played_first"]) .
|
$ps4->secondsToDate($games[$key]["game_played_first"]) .
|
||||||
"</div></div>";
|
"</div></div>";
|
||||||
|
|||||||
6
post.php
6
post.php
@@ -6,7 +6,11 @@ $ps4 = new ps4();
|
|||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
if ($_POST['what'] == 'thumbnail') {
|
if ($_POST['what'] == 'thumbnail') {
|
||||||
$ps4->thumbnailupdateurl($_POST['gameid'], $_POST['gamename'], $_POST['url']);
|
$ps4->thumbnailupdatedb(
|
||||||
|
$_POST['gameid'],
|
||||||
|
$_POST['gamename'],
|
||||||
|
$_POST['url']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user