diff --git a/class.php b/class.php index 8846d1b..01fc2ce 100644 --- a/class.php +++ b/class.php @@ -1,40 +1,16 @@ 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 '
'; @@ -42,7 +18,9 @@ class ps4 while ($row = $result->fetch_assoc()) { echo '
'; $i++; - echo '
' . $this->secondsToDate($row["game_start"]) . '
'; + echo '
' . + $this->secondsToDate($row["game_start"]) . + '
'; echo '
'; if ($row["game_end"] == "") { @@ -54,9 +32,15 @@ class ps4 echo '
'; 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 '
'; @@ -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 "
ERROR
No URL specified.
"; } 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 "
SUCCESS
Updated image URL for " . $gamename . diff --git a/page.php b/page.php index 541fd14..5c35aed 100644 --- a/page.php +++ b/page.php @@ -1,10 +1,10 @@ mysql_conn($sql); +$results = DB::query($sql); $rootpage = $_GET['rootpage']; $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : "lastplayed_desc"; @@ -59,16 +59,19 @@ $details = isset($_GET['details']) ? $_GET['details'] : "";
-num_rows > 0) { + 0) { // 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_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"]; } @@ -76,10 +79,13 @@ $details = isset($_GET['details']) ? $_GET['details'] : ""; 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; + $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 @@ -96,8 +102,16 @@ $details = isset($_GET['details']) ? $_GET['details'] : ""; foreach ($games as $key => $value) { echo "
"; echo "
"; - echo "thumbnailurl($games[$key]["game_id"]) . + $thumbnailurl = $ps4->thumbnailurl($games[$key]["game_id"]); + if ($thumbnailurl == "images/no-thumbnail.png") { + $thumbnailsrc = $thumbnailurl; + } else { + $thumbnailsrc = 'data:image/jpeg;base64,' . base64_encode($thumbnailurl); + } + + $thumbnailurlfinal = + ""; + + echo $thumbnailurlfinal; + echo "
"; echo "
"; echo "" . $games[$key]["game_name"] . ""; @@ -121,7 +138,9 @@ $details = isset($_GET['details']) ? $_GET['details'] : ""; if ($details != $games[$key]["game_id"]) { echo $games[$key]["game_id"]; } - echo "\">" . $ps4->playtime($games[$key]["game_total_time"], true) . "
"; + echo "\">" . + $ps4->playtime($games[$key]["game_total_time"], true) . + "
"; echo "
First Played
" . $ps4->secondsToDate($games[$key]["game_played_first"]) . "
"; diff --git a/post.php b/post.php index c33257e..f6d3933 100644 --- a/post.php +++ b/post.php @@ -6,7 +6,11 @@ $ps4 = new ps4(); if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_POST['what'] == 'thumbnail') { - $ps4->thumbnailupdateurl($_POST['gameid'], $_POST['gamename'], $_POST['url']); + $ps4->thumbnailupdatedb( + $_POST['gameid'], + $_POST['gamename'], + $_POST['url'] + ); } } ?>