moved to MeekroDB and also saving image directly to DB

This commit is contained in:
2020-08-30 15:40:33 -04:00
parent ca46e463fb
commit 267c513f43
3 changed files with 78 additions and 62 deletions

View File

@@ -1,40 +1,16 @@
<?php
include_once "dbconf.php";
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)
{
$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) {
$i = 0;
echo '<div class="PlaytimeDetails FontSmaller">';
@@ -42,7 +18,9 @@ class ps4
while ($row = $result->fetch_assoc()) {
echo '<div class="row">';
$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">';
if ($row["game_end"] == "") {
@@ -54,9 +32,15 @@ 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>';
@@ -115,31 +99,40 @@ class ps4
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()) {
$url = $row["thumbnail_url"];
}
$result = DB::queryFirstField(
"SELECT thumbnail FROM game_thumbnail2 WHERE game_id = %s",
$game_id
);
if ($result) {
$url = $result;
} else {
$url = "images/no-thumbnail.png";
}
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") {
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);
$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) {
echo "<div class=\"message-success center500\"><div class=\"message-head\">SUCCESS</div><div class=\"message-details\">Updated image URL for <strong>" .
$gamename .