diff --git a/include/TGDB.API.php b/include/TGDB.API.php index b505106..8f2c34c 100644 --- a/include/TGDB.API.php +++ b/include/TGDB.API.php @@ -25,7 +25,7 @@ public static function getInstance() function GetGameListByPlatform($IDs = 0, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -107,7 +107,7 @@ function GetGameByID($IDs, $offset = 0, $limit = 20, $fields = array()) return array(); } - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -141,7 +141,7 @@ function SearchGamesByName($searchTerm, $offset = 0, $limit = 20, $fields = arra { $dbh = $this->database->dbh; - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -190,7 +190,7 @@ function SearchGamesByNameByPlatformID($searchTerm, $IDs, $offset = 0, $limit = { $dbh = $this->database->dbh; - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -265,7 +265,7 @@ function GetGamesByDate($date, $offset = 0, $limit = 20, $fields = array(), $Ord function GetGamesByDateByPlatform($IDs, $date, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -334,7 +334,7 @@ function GetGamesByDateByPlatform($IDs, $date, $offset = 0, $limit = 20, $fields function GetAllGames($offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -375,7 +375,7 @@ function GetAllGames($offset = 0, $limit = 20, $fields = array(), $OrderBy = '', function GetGamesByLatestUpdatedDate($minutes, $offset = 0, $limit = 20, $fields = array()) { - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -754,7 +754,193 @@ function is_valid_games_col($name) } return isset($this->GamesTblCols[$name]); } -} + /* Everything belowis not planned to be exposed through external API */ + function InsertUserEdits($user_id, $game_id, $type, $diff, $subtype = '') + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("INSERT INTO user_edits (users_id, games_id, type, diff) VALUES (:users_id, :games_id, :type, :diff);"); + $sth->bindValue(':users_id', $user_id, PDO::PARAM_INT); + $sth->bindValue(':games_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':type', $type, PDO::PARAM_INT); + $sth->bindValue(':diff', $diff, PDO::PARAM_STR); + return $sth->execute(); + } + + function UpdateGame($user_id, $game_id, $GameTitle, $Overview, $Youtube, $ReleaseDateRevised, $Players, $coop, $Developer, $Publisher) + { + $dbh = $this->database->dbh; + { + $sth = $dbh->prepare("Select * FROM games WHERE id = :game_id"); + $sth->bindValue(':game_id', $game_id, PDO::PARAM_INT); + + if($sth->execute()) + { + $Game = $sth->fetch(PDO::FETCH_ASSOC); + } + if(!isset($Game) || empty($Game)) + { + return false; + } + } + + { + $dbh->beginTransaction(); + + $sth = $dbh->prepare("UPDATE games SET GameTitle=:GameTitle, Overview=:Overview, ReleaseDateRevised=:ReleaseDateRevised, ReleaseDate=:ReleaseDate, Players=:Players, coop=:coop, + Developer=:Developer, Publisher=:Publisher, Youtube=:YouTube WHERE id=:game_id"); + $sth->bindValue(':game_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':GameTitle', htmlspecialchars($GameTitle), PDO::PARAM_STR); + $sth->bindValue(':Overview', htmlspecialchars($Overview), PDO::PARAM_STR); + $sth->bindValue(':ReleaseDateRevised', $ReleaseDateRevised, PDO::PARAM_STR); + $date = explode('-', $ReleaseDateRevised); + $sth->bindValue(':ReleaseDate', "$date[1]/$date[2]/$date[0]", PDO::PARAM_STR); + $sth->bindValue(':Players', $Players, PDO::PARAM_INT); + $sth->bindValue(':YouTube', htmlspecialchars($Youtube), PDO::PARAM_STR); + $sth->bindValue(':coop', $coop, PDO::PARAM_INT); + + // NOTE: these will be moved to own table, as a single game can have multiple devs/publishers + // it will also mean, we will be able to standardise devs/publishers names + // this will allow their selection from a menu as oppose to being provided by the user + $sth->bindValue(':Developer', htmlspecialchars($Developer), PDO::PARAM_STR); + $sth->bindValue(':Publisher', htmlspecialchars($Publisher), PDO::PARAM_STR); + + $sth->execute(); + { + foreach($Game as $key => $value) + { + if(isset($$key) && htmlspecialchars($$key) != $value) + { + if($key == 'Overview') + { + $diff = xdiff_string_diff($Game['Overview'], htmlspecialchars($Overview), 1); + if(empty($diff)) + { + continue; + } + } + else + { + $diff = htmlspecialchars($$key); + } + $this->InsertUserEdits($user_id, $game_id, $key, $diff); + } + } + } + return $dbh->commit(); + } + } + + function DeleteGameImages($user_id, $game_id, $id, $type) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("DELETE FROM banners WHERE id=:id;"); + $sth->bindValue(':id', $id, PDO::PARAM_INT); + $res = $sth->execute(); + if($dbh->inTransaction() || $res) + { + $this->InsertUserEdits($user_id, $game_id, $type, "[REMOVED]"); + } + return ($dbh->inTransaction() || $res); + } + + function DeleteAllGameImages($user_id, $game_id) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("DELETE FROM banners WHERE keyvalue=:game_id;"); + $sth->bindValue(':game_id', $game_id, PDO::PARAM_INT); + $res = $sth->execute(); + if($dbh->inTransaction() || $res) + { + $this->InsertUserEdits($user_id, $game_id, "all_images", "[REMOVED]"); + } + return ($dbh->inTransaction() || $res); + } + + function DeleteAndInsertGameImages($user_id, $id, $game_id, $type, $filename, $side = NULL) + { + $dbh = $this->database->dbh; + $dbh->beginTransaction(); + $this->DeleteGameImages($user_id, $game_id, $id, $type); + $this->InsertGameImages($user_id, $game_id, $type, $filename, $side); + return $dbh->commit(); + + } + + function InsertGameImages($user_id, $game_id, $type, $filename, $side = NULL) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("INSERT INTO banners (keyvalue, keytype, side, filename, userid) VALUES (:keyvalue, :keytype, :side, :filename, :user_id); "); + $sth->bindValue(':user_id', $user_id, PDO::PARAM_INT); + $sth->bindValue(':keyvalue', $game_id, PDO::PARAM_INT); + $sth->bindValue(':keytype', $type, PDO::PARAM_STR); + $sth->bindValue(':side', $side, PDO::PARAM_STR); + $sth->bindValue(':filename', $filename, PDO::PARAM_STR); + $res = $sth->execute(); + + if($dbh->inTransaction() || $res) + { + $this->InsertUserEdits($user_id, $game_id, $type, $filename); + } + return ($dbh->inTransaction() || $res); + } + function DeleteGame($user_id, $game_id) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("DELETE FROM games WHERE id=:game_id;"); + $sth->bindValue(':game_id', $game_id, PDO::PARAM_INT); + $res = $sth->execute(); + if($dbh->inTransaction() || $res) + { + $this->InsertUserEdits($user_id, $game_id, "game", "[REMOVED]"); + } + return ($dbh->inTransaction() || $res); + } + + function InsertGame($user_id, $GameTitle, $Overview, $Youtube, $ReleaseDateRevised, $Players, $coop, $Developer, $Publisher) + { + $game_id = 0; + $dbh = $this->database->dbh; + { + $sth = $dbh->prepare("INSERT INTO games(GameTitle, Overview, ReleaseDateRevised, ReleaseDate, Players, coop, Developer, Publisher, Youtube, Alternates) + values (:GameTitle, :Overview, :ReleaseDateRevised, :ReleaseDate, :Players, :coop, :Developer, :Publisher, :YouTube, :Alternates)"); + $sth->bindValue(':GameTitle', htmlspecialchars($GameTitle), PDO::PARAM_STR); + $sth->bindValue(':Overview', htmlspecialchars($Overview), PDO::PARAM_STR); + $sth->bindValue(':ReleaseDateRevised', $ReleaseDateRevised, PDO::PARAM_STR); + $date = explode('-', $ReleaseDateRevised); + $sth->bindValue(':ReleaseDate', "$date[1]/$date[2]/$date[0]", PDO::PARAM_STR); + $sth->bindValue(':Players', $Players, PDO::PARAM_INT); + $sth->bindValue(':YouTube', htmlspecialchars($Youtube), PDO::PARAM_STR); + $sth->bindValue(':coop', $coop, PDO::PARAM_INT); + $sth->bindValue(':Alternates', "", PDO::PARAM_STR); + + // NOTE: these will be moved to own table, as a single game can have multiple devs/publishers + // it will also mean, we will be able to standardise devs/publishers names + // this will allow their selection from a menu as oppose to being provided by the user + $sth->bindValue(':Developer', htmlspecialchars($Developer), PDO::PARAM_STR); + $sth->bindValue(':Publisher', htmlspecialchars($Publisher), PDO::PARAM_STR); + + if($sth->execute()) + { + $game_id = $dbh->lastInsertId(); + $dbh->beginTransaction(); + $this->InsertUserEdits($user_id, $game_id, 'game', '[NEW]'); + + $GameArrayFields = ['GameTitle', 'Overview', 'ReleaseDateRevised', 'Players', 'coop', 'Developer', 'Publisher', 'Youtube']; + foreach($GameArrayFields as $key) + { + $diff = htmlspecialchars($$key); + $this->InsertUserEdits($user_id, $game_id, $key, $diff); + } + $dbh->commit(); + } + } + return $game_id; + } +} ?> diff --git a/website/actions/add_game.php b/website/actions/add_game.php new file mode 100644 index 0000000..16769f3 --- /dev/null +++ b/website/actions/add_game.php @@ -0,0 +1,64 @@ + $code, "msg" => $msg)); + die(); +} + +$_user = phpBBuser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} +else +{ + if(!$_user->hasPermission('u_edit_games')) + { + returnJSONAndDie(-1, ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + } +} + + +$GameArrayFields = ['GameTitle', 'Overview', 'ReleaseDateRevised', 'Players', 'coop', 'Developer', 'Publisher', 'Youtube']; +foreach($GameArrayFields as $field) +{ + if(!isset($_REQUEST[$field])) + { + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR . ": ($field)."); + } + if(empty($_REQUEST[$field]) && ($field != 'Youtube' && $field != 'Overview' && $field != 'Publisher')) + { + returnJSONAndDie(-1, "field is empty: ($field)."); + } +} + +$date = explode('-', $_REQUEST['ReleaseDateRevised']); +if(!checkdate($date[1], $date[2], $date[0])) +{ + returnJSONAndDie(-1, "Invalid Date Format"); +} + + +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + $res = $API->InsertGame($_user->GetUserID(), $_REQUEST['GameTitle'], $_REQUEST['Overview'], $_REQUEST['Youtube'], $_REQUEST['ReleaseDateRevised'], + $_REQUEST['Players'], $_REQUEST['coop'], $_REQUEST['Developer'], $_REQUEST['Publisher']); + + if($res) + { + returnJSONAndDie(1, $res); + } + +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); diff --git a/website/actions/delete_game.php b/website/actions/delete_game.php new file mode 100644 index 0000000..3f06f87 --- /dev/null +++ b/website/actions/delete_game.php @@ -0,0 +1,69 @@ + $code, "msg" => $msg)); + die(); +} + +$_user = phpBBuser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} +else +{ + if(!$_user->hasPermission('m_delete_games')) + { + returnJSONAndDie(-1, ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + } +} + +if(!isset($_REQUEST['game_id']) || !is_numeric($_REQUEST['game_id'])) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR); +} + +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + if(empty($API->GetGameByID($_REQUEST['game_id'], 0, 1))) + { + returnJSONAndDie(0, "No game in record to delete."); + } + + $covers = $API->GetGameBoxartByID($_REQUEST['game_id'], 0, 99, 'ALL'); + + if(!empty($covers) && ($covers = $covers[$_REQUEST['game_id']])) + { + $sizes = ["original", "small", "thumb", "cropped_center_thumb", "medium", "large"]; + foreach($covers as $cover) + { + foreach($sizes as $size) + { + $image_to_delete = __DIR__ . "/../../cdn/images/$size/" . $cover->filename; + if(file_exists($image_to_delete)) + { + unlink($image_to_delete); + } + } + } + } + + $API->DeleteAllGameImages($_user->GetUserID(), $_REQUEST['game_id']); + $res = $API->DeleteGame($_user->GetUserID(), $_REQUEST['game_id']); + + returnJSONAndDie(1, "success!!"); + + +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); diff --git a/website/actions/edit_game.php b/website/actions/edit_game.php new file mode 100644 index 0000000..7c052d0 --- /dev/null +++ b/website/actions/edit_game.php @@ -0,0 +1,66 @@ + $code, "msg" => $msg)); + die(); +} + +$_user = phpBBuser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} +else +{ + if(!$_user->hasPermission('u_edit_games')) + { + returnJSONAndDie(-1, ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + } +} + + +$GameArrayFields = ['GameTitle', 'Overview', 'ReleaseDateRevised', 'Players', 'coop', 'Developer', 'Publisher', 'Youtube']; +if(!isset($_REQUEST['game_id']) || !is_numeric($_REQUEST['game_id'])) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR); +} +else +{ + foreach($GameArrayFields as $field) + { + if(!isset($_REQUEST[$field])) + { + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR . ": ($field)."); + } + } + + $date = explode('-', $_REQUEST['ReleaseDateRevised']); + if(!checkdate($date[1], $date[2], $date[0])) + { + returnJSONAndDie(-1, "Invalid Date Format"); + } +} + +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + $res = $API->UpdateGame( $_user->GetUserID(), $_REQUEST['game_id'], $_REQUEST['GameTitle'], $_REQUEST['Overview'], $_REQUEST['Youtube'], $_REQUEST['ReleaseDateRevised'], + $_REQUEST['Players'], $_REQUEST['coop'], $_REQUEST['Developer'], $_REQUEST['Publisher']); + + if($res) + { + returnJSONAndDie(1, "success!!"); + } + +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); diff --git a/website/actions/uploads.php b/website/actions/uploads.php new file mode 100644 index 0000000..be6228f --- /dev/null +++ b/website/actions/uploads.php @@ -0,0 +1,248 @@ +fromFile($original_image); + $type = ($type == 'jpg') ? 'jpeg' : $type; + $image->toFile($dest_image, "image/$type", 100); + return true; + } + catch(Exception $err) + { + error_log($err); + return false; + } + } +} + +function returnJSONAndDie($msg) +{ + global $tmp_image_out_path, $image_out_path; + if(isset($tmp_image_out_path) && file_exists($tmp_image_out_path)) + { + unlink($tmp_image_out_path); + } + if(isset($image_out_path) && file_exists($image_out_path)) + { + unlink($image_out_path); + } + echo json_encode(array("error" => $msg)); + die(); +} + +$_user = phpBBUser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} +else +{ + if(!$_user->hasPermission('u_edit_games')) + { + returnJSONAndDie(ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + } +} +$Fields = ['game_id', 'type', 'subtype']; +{ + foreach($Fields as $field) + { + if(!isset($_REQUEST[$field])) + { + returnJSONAndDie(ErrorPage::$MSG_MISSING_PARAM_ERROR . ": ($field)."); + } + } + // TODO: move these hardcoded values to a table, but this will do for now + switch($_REQUEST['type']) + { + case 'boxart': + if($_REQUEST['subtype'] == 'front' || $_REQUEST['subtype'] == 'back') + { + break; + } + returnJSONAndDie("Invalid subtype selection: " . $_REQUEST['subtype']); + case 'fanart': + case 'series': + case 'screenshot': + case 'platform-banner': + case 'platform-fanart': + case 'platform-boxart': + case 'clearlogo': + if(empty($_REQUEST['subtype'])) + { + break; + } + returnJSONAndDie("Invalid subtype selection: " . $_REQUEST['subtype']); + default: + returnJSONAndDie("Invalid type selection: " . $_REQUEST['type']); + } +} + + +$uploader = new UploadHandler(); + +$uploader->allowedExtensions = array('jpe', 'jpg', 'jpeg', 'gif', 'png', 'bmp'); +$uploader->sizeLimit = 5 * 1024 *1024; + +$uploader->inputName = "qqfile"; + +function get_request_method() +{ + global $HTTP_RAW_POST_DATA; + + if(isset($HTTP_RAW_POST_DATA)) + { + parse_str($HTTP_RAW_POST_DATA, $_POST); + } + + if (isset($_POST["_method"]) && $_POST["_method"] != null) + { + return $_POST["_method"]; + } + + return $_SERVER["REQUEST_METHOD"]; +} + +if (get_request_method() == "POST") +{ + header("Content-Type: text/plain"); + + $tmp_path = __DIR__ . "/../../cdn/images/tmp/original/" . $_REQUEST['type']; + $path = __DIR__ . "/../../cdn/images/original/" . $_REQUEST['type']; + if(!empty($_REQUEST['subtype'])) + { + $tmp_path .= "/" . $_REQUEST['subtype']; + $path .= "/" . $_REQUEST['subtype']; + } + + $API = TGDB::getInstance(); + $covers = $API->GetGameBoxartByID($_REQUEST['game_id'], 0, 30, $_REQUEST['type']); + if(!empty($covers) && ($covers = $covers[$_REQUEST['game_id']]) && count($covers) > 5) + { + returnJSONAndDie("Max (5) allowed uploaded images has been reached."); + } + + if($_REQUEST['type'] == 'clearlogo') + { + $type = "png"; + } + else + { + $type = "jpg"; + if($_REQUEST['type'] == 'boxart') + { + // by forcing the name to "-1.$type", we'll always replace the cover with new upload + $image_name = $_REQUEST['game_id'] . "-1.$type"; + } + } + if(!isset($image_name)) + { + for($i = 1; $i < 6; ++$i) + { + $tmp_name = $_REQUEST['game_id'] . "-$i.$type"; + if(!file_exists($path . "/" . $tmp_name)) + { + $image_name = $tmp_name; + break; + } + } + if(!isset($image_name)) + { + die("Failed to find an image_name"); + } + } + + if(!file_exists($tmp_path)) + { + mkdir($tmp_path, 0755, true); + } + $result = $uploader->handleUpload($tmp_path, $image_name); + $result["uploadName"] = $uploader->getUploadName(); + + if(isset($result['success'])) + { + $tmp_image_out_path = $tmp_path . "/" . $image_name; + $image_out_path = $path . "/" . $image_name; + $result['final_out'] = $image_out_path; + if(save_image($tmp_image_out_path, $image_out_path, $type)) + { + if($_REQUEST['type'] == 'boxart') + { + if(!empty($covers)) + { + foreach($covers as $cover) + { + if($_REQUEST['subtype'] == $cover->side) + { + $sql_image_path = $cover->filename; + break; + } + } + if(isset($sql_image_path)) + { + $sizes = ["small", "thumb", "cropped_center_thumb", "medium", "large"]; + if(basename($sql_image_path) != $image_name) + { + array_push($sizes, 'original'); + } + foreach($sizes as $size) + { + $image_to_delete = __DIR__ . "/../../cdn/images/$size/" . $sql_image_path; + if(file_exists($image_to_delete)) + { + unlink($image_to_delete); + } + } + } + foreach($covers as $cover) + { + if($_REQUEST['subtype'] == $cover->side) + { + $res = $API->DeleteAndInsertGameImages($_user->GetUserID(), $cover->id, $_REQUEST['game_id'], $_REQUEST['type'], + $_REQUEST['type'] . "/" . $_REQUEST['subtype'] . "/" . $image_name, $_REQUEST['subtype']); + break; + } + } + } + else + { + $res = $API->InsertGameImages($_user->GetUserID(), $_REQUEST['game_id'], $_REQUEST['type'], + $_REQUEST['type'] . "/" . $_REQUEST['subtype'] . "/" . $image_name, $_REQUEST['subtype']); + } + } + else + { + $res = $API->InsertGameImages($_user->GetUserID(), $_REQUEST['game_id'], $_REQUEST['type'], + $_REQUEST['type'] . "/" . $image_name); + } + + if(!isset($res) || !$res) + { + returnJSONAndDie("Failed to update database."); + } + } + else + { + returnJSONAndDie("Failed save image." . $image_out_path); + } + } + + echo json_encode($result); +} +else +{ + header("HTTP/1.0 405 Method Not Allowed"); +} \ No newline at end of file diff --git a/website/add_game.php b/website/add_game.php new file mode 100644 index 0000000..f4150b3 --- /dev/null +++ b/website/add_game.php @@ -0,0 +1,245 @@ +isLoggedIn()) +{ + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); + $errorPage->print_die(); +} +else +{ + if(!$_user->hasPermission('u_edit_games')) + { + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + $errorPage->print_die(); + } +} + +require_once __DIR__ . "/include/header.footer.class.php"; +require_once __DIR__ . "/include/TGDBUtils.class.php"; +require_once __DIR__ . "/../include/TGDB.API.php"; +require_once __DIR__ . "/../include/CommonUtils.class.php"; + + +$API = TGDB::getInstance(); +$PlatformList = $API->GetPlatformsList(); + +$Header = new HEADER(); +$Header->setTitle("TGDB - Add Game"); +$Header->appendRawHeader(function() { ?> + + + + + + + + + + + + + + +print(); ?> + +
+ +
+
+
+ +
+
+
+ +
+ +
+
+
+
+ "/> +
+

Platform: +

+

Developer:

+

Publisher:

+

ReleaseDate*:

+

Players: + +

+

Co-op: + +

+

* : safari doesnt support calender input yet, so please keep date format to (yyyy-mm-dd)

+
+
+
+
+
+ +
+
+
+
+
+

+
+
+

+ +

+

YouTube Trailer:

+
+
+
+
+ + +
+
+
+

+ Other Graphic(s) +

+
+
+
+
You can add fanarts/screenshots/banners found, after the game is added.
+
+
+
+ +
+
+
+ + +
+ +
+
+
+
+
+ Control Panel +
+
+

+
+
+
+
+
+ +
+
+ + diff --git a/website/edit_game.php b/website/edit_game.php new file mode 100644 index 0000000..d55c9c2 --- /dev/null +++ b/website/edit_game.php @@ -0,0 +1,599 @@ +SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_MISSING_PARAM_ERROR); + $errorPage->print_die(); +} +require_once __DIR__ . "/include/login.phpbb.class.php"; +$_user = phpBBUser::getInstance(); +if(!$_user->isLoggedIn()) +{ + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); + $errorPage->print_die(); +} +else +{ + if(!$_user->hasPermission('u_edit_games')) + { + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + $errorPage->print_die(); + } +} + +require_once __DIR__ . "/include/header.footer.class.php"; +require_once __DIR__ . "/include/TGDBUtils.class.php"; +require_once __DIR__ . "/../include/TGDB.API.php"; +require_once __DIR__ . "/../include/CommonUtils.class.php"; + + +if(isset($_REQUEST['id']) && !empty($_REQUEST['id']) && is_numeric($_REQUEST['id'])) +{ + $options = array("ReleaseDateRevised" => true, "Overview" => true, "Players" => true, "Rating" => true, "ESRB" => true, "boxart" => true, "coop" => true, + "Genre" => true, "Publisher" => true, "Platform" => true, "Youtube" => true); + $API = TGDB::getInstance(); + $list = $API->GetGameByID($_REQUEST['id'], 0, 1, $options); + if(empty($list)) + { + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_REMOVED_GAME_INVALID_PARAM_ERROR); + $errorPage->print_die(); + } + else + { + $Game = array_shift($list); + $covers = $API->GetGameBoxartByID($_REQUEST['id'], 0, 9999, 'ALL'); + if(!empty($covers)) + { + $Game->boxart = $covers[$_REQUEST['id']]; + } + } + $Platform = $API->GetPlatforms($Game->Platform, array("icon" => true, "overview" => true, "developer" => true)); + if(isset($Platform[$Game->Platform])) + { + $Platform = $Platform[$Game->Platform]; + } +} + + +$fanarts = TGDBUtils::GetAllCovers($Game, 'fanart', ''); +$screenshots = TGDBUtils::GetAllCovers($Game, 'screenshot', ''); +$banners = TGDBUtils::GetAllCovers($Game, 'series', ''); +$is_graphics_empty = empty($fanarts) && empty($screenshots) && empty($banners); + +$box_cover = new \stdClass(); +$box_cover->front = TGDBUtils::GetAllCovers($Game, 'boxart', 'front'); +if(!empty($box_cover->front)) +{ + $box_cover->front = $box_cover->front[0]; +} +$box_cover->back = TGDBUtils::GetAllCovers($Game, 'boxart', 'back'); +if(!empty($box_cover->back)) +{ + $box_cover->back = $box_cover->back[0]; +} + +$Header = new HEADER(); +$Header->setTitle("TGDB - Browse - Game - $Game->GameTitle"); +$Header->appendRawHeader(function() { global $Game, $_user; ?> + + + + " /> + + + + + + + + + + + + + + + + + + + + + + + + + +print(); ?> + +
+ +
+
+
+ + + + + +
+
+
+ +
+ +
+
+
+
+ front)) : ?> + + + + back)): ?> + + + + back)): ?> + + + + + + + +
+

Platform: name; ?>

+

Developer:

+

Publisher:

+

ReleaseDate*:

+

Players: + +

+

Co-op: + +

+

* : safari doesnt support calender input yet, so please keep date format to (yyyy-mm-dd)

+
+
+
+
+
+ +
+
+
+
+
+

+
+
+

+ +

+

YouTube Trailer:

+
+
+
+
+ + +
+
+
+

+ Other Graphic(s) +

+
+
+ +
+ + + + + + + +
+ + +
+ + + + + + + +
+ + + +
+ + + + + + + +
+ + +
+
No fanarts/screenshots/banners found, be the 1st to add them.
+
+ +
+
+ + +
+
+
+ + +
+ +
+
+
+
+
+ Control Panel +
+ +
+

+ hasPermission('m_delete_games')): ?> +

+ +

Back

+
+
+
+
+
+ +
+
+ + diff --git a/website/game.php b/website/game.php index 1e49091..e5f8007 100755 --- a/website/game.php +++ b/website/game.php @@ -154,36 +154,35 @@ - back)): ?> + back)): ?> - + back)): ?> - + - -
- - - - - +
+ + + + +

Platform: name; ?>

- +

Developer: Developer; ?>

Publisher)) : ?>

Publisher: Publisher; ?>

- ReleaseDate)) : ?> -

ReleaseDate: ReleaseDate ;?>

+ ReleaseDateRevised)) : ?> +

ReleaseDateRevised: ReleaseDateRevised ;?>

PlatformDetails)) : ?>

Platform: PlatformDetails->name; ?>

Players)) : ?> @@ -250,21 +249,6 @@
- isValid()) : ?> -
-
-
- -
-
-
getJSON()); ?>
-
-
-
-
- @@ -328,6 +312,24 @@ + isLoggedIn() && $_user->hasPermission('u_edit_games')) : ?> +
+
+ +
+
+ + diff --git a/website/include/ErrorPage.class.php b/website/include/ErrorPage.class.php index 9af5f84..87d0c4e 100755 --- a/website/include/ErrorPage.class.php +++ b/website/include/ErrorPage.class.php @@ -13,6 +13,8 @@ public function __construct() static $MSG_INVALID_PARAM_ERROR = "Invalid Parameters were provided."; static $MSG_PLEASE_GO_BACK_OR_TRY_AGAIN_ERROR = "Please go back or try again"; static $MSG_REMOVED_GAME_INVALID_PARAM_ERROR = "The game you're looking for does not exist or has been removed."; + static $MSG_NOT_LOGGED_IN_EDIT_ERROR = "Please login to be able to edit this page."; + static $MSG_NO_PERMISSION_TO_EDIT_ERROR = "You dont currently have permission to edit this page."; private $_error_header = "Error Has Occured"; private $_error_msg = "Please go back or try again"; diff --git a/website/include/header.footer.class.php b/website/include/header.footer.class.php index 190ea5c..a65321e 100755 --- a/website/include/header.footer.class.php +++ b/website/include/header.footer.class.php @@ -1,6 +1,8 @@ _printExtraHeader = $fun; } public function print() - { ?> + { global $_user;?> @@ -60,6 +62,7 @@ public function print() break; case 5: echo ''; + echo ""; break; default: echo ''; @@ -106,6 +109,27 @@ public function print() + enable_super_globals(); + +class phpBBUser +{ + private function __construct() + { + global $user, $auth; + $user->session_begin(); + $auth->acl($user->data); + $user->setup(); + $this->user = $user; + $this->auth = $auth; + } + + public static function getInstance() + { + static $instance = null; + if (!isset($instance)) + { + $object = __CLASS__; + $instance = new $object; + } + return $instance; + } + + function Login($user, $pass) + { + global $config, $phpbb_root_path, $phpEx; + $ret = $this->auth->login($user, $pass); + if($ret['status'] == LOGIN_ERROR_ATTEMPTS) + { + $ret['error_msg_str'] = "You exceeded the maximum allowed number of login attempts. In addition to your username and password you now also have to solve the CAPTCHA," . + "
CAPTCHA login can only be performed through the forums login.
" . + "You will be automatically redirect to forum login, if it takes longer than 10 seconds Click Here." . + ''; + } + elseif($ret['status'] != LOGIN_SUCCESS) + { + $ret['error_msg_str'] = sprintf( + $this->user->lang[$ret['error_msg']], + ($config['email_enable']) ? '' : '', + ($config['email_enable']) ? '' : '', + '', + '' + ); + } + return $ret; + } + + function isLoggedIn() + { + return ($this->user->data['is_registered'] && $this->user->data['user_id'] != ANONYMOUS); + } + + function Logout() + { + global $request; + if($this->user->data['user_id'] != ANONYMOUS && $request->is_set('sid') && $request->variable('sid', '') === $this->user->session_id) + { + $this->user->session_kill(); + return true; + } + return false; + } + + function GetUsername() + { + return $this->user->data['username']; + } + + function GetAvatar() + { + if(!empty($this->user->data['user_avatar'])) + { + return "https://forums.thegamesdb.net/download/file.php?avatar=" . $this->user->data['user_avatar']; + } + } + + function GetUserID() + { + return $this->user->data['user_id']; + } + + function GetUserSessionID() + { + return $this->user->session_id; + } + + function hasPermission($perm) + { + // we're using permission to post in general forum as a permission to edit covers/platform information + return $this->auth->acl_get($perm) > 0; + } +} + +?> \ No newline at end of file diff --git a/website/index.php b/website/index.php index a1910c9..d92f4cb 100755 --- a/website/index.php +++ b/website/index.php @@ -7,6 +7,10 @@ $API = TGDB::getInstance(); $soon = $API->GetGamesByDate(date("d/m/Y"), 0, 5, array('AFTER' => true), "ReleaseDateRevised", 'ASC'); $recent = $API->GetGamesByDate(date("d/m/Y"), 0, 6, array('BEFORE' => true), "ReleaseDateRevised", 'DESC'); +foreach($soon as $Game) +{ + $PlatformIDs[] = $Game->Platform; +} foreach($recent as $Game) { $IDs[] = $Game->id; @@ -89,6 +93,7 @@
+
Releasing Soon
@@ -110,6 +115,10 @@
+ + + diff --git a/website/listgames.php b/website/listgames.php index b55de88..ae9707b 100755 --- a/website/listgames.php +++ b/website/listgames.php @@ -36,17 +36,19 @@ { unset($list[$limit]); } - foreach($list as $Game) { $IDs[] = $Game->id; } -$covers = $API->GetGameBoxartByID($IDs, 0, 40); -foreach($list as $Game) +if(isset($IDs) && !empty($IDs)) { - if(isset($covers[$Game->id])) + $covers = $API->GetGameBoxartByID($IDs, 0, 40); + foreach($list as $Game) { - $Game->boxart = $covers[$Game->id]; + if(isset($covers[$Game->id])) + { + $Game->boxart = $covers[$Game->id]; + } } } $Header = new HEADER(); @@ -71,7 +73,7 @@
- +
@@ -81,13 +83,21 @@
- + +
+
+
+

No associated games.

+
+
+
+ diff --git a/website/login.php b/website/login.php new file mode 100644 index 0000000..2414f29 --- /dev/null +++ b/website/login.php @@ -0,0 +1,149 @@ +isLoggedIn() && $_user->Logout()) + { + $success_msg[] = "User logged out successfully. You will be automatically redirected, if it takes longer than 10 seconds Click Here." . + ''; + } + else + { + $error_msgs[] = "User is already logged out. You will be automatically redirected, if it takes longer than 10 seconds Click Here." . + ''; + } +} +else if($_user->isLoggedIn()) +{ + $error_msgs[] = "User is already logged in. You will be automatically redirected, if it takes longer than 10 seconds Click Here." . + ''; +} + +if($_SERVER['REQUEST_METHOD'] == "POST" && empty($error_msgs) && empty($success_msg)) +{ + if(!$_user->isLoggedIn()) + { + if(!empty($_POST['username']) && !empty($_POST['password'])) + { + $res = $_user->Login($_POST['username'], $_POST['password'], isset($_POST['autologin']), isset($_POST['viewonline'])); + if($res['status'] == LOGIN_SUCCESS) + { + if(!empty($_POST['redirect']) && strpos($_POST['redirect'], "login") === false) + { + $length = strlen("thegamesdb.net"); + $url = parse_url($_POST['redirect']); + if($length !== 0 && (substr($url['host'], -$length) === "thegamesdb.net")) + { + $success_msg[] = "Login successful, You will be automatically redirected, if it takes longer than 10 seconds Click Here." . + ''; + + } + else + { + $success_msg[] = "Login successful, You will be automatically redirected, if it takes longer than 10 seconds Click Here." . + ''; } + } + else + { + $success_msg[] = "Login successful, You will be automatically redirected, if it takes longer than 10 seconds Click Here." . + ''; + } + } + else + { + $error_msgs[] = $res['error_msgs_str']; + } + } + else + { + $error_msgs[] = "Username or Password fields can't be empty, please try again."; + } + } +} + +require_once __DIR__ . "/include/header.footer.class.php"; + +$Header = new HEADER(); +$Header->setTitle("TGDB - Login"); +$Header->appendRawHeader(function() { global $Game; ?> + + + + +print(); ?> + +
+ +
+
+

Action Failed!

+ +

+ +
+
+ + +
+
+

Action Completed!

+ +

+ +
+
+ +
+
+
+ Login +
+
+
+
+
+
+ Username +
+ +
+
+ +
+
+
+ Password +
+ +
+
+ +
+
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ + diff --git a/website/platform.php b/website/platform.php index 0636cb7..9846797 100755 --- a/website/platform.php +++ b/website/platform.php @@ -43,14 +43,18 @@ { $IDs[] = $Game->id; } -$covers = $API->GetGameBoxartByID($IDs, 0, 9999, 'boxart'); -foreach($recent as $Game) +if(isset($IDs) && !empty($IDs)) { - if(isset($covers[$Game->id])) + $covers = $API->GetGameBoxartByID($IDs, 0, 9999, 'boxart'); + foreach($recent as $Game) { - $Game->boxart = $covers[$Game->id]; + if(isset($covers[$Game->id])) + { + $Game->boxart = $covers[$Game->id]; + } } } + $Header = new HEADER(); $Header->setTitle("TGDB - Browse - Platforms"); $Header->appendRawHeader(function() diff --git a/website/search.php b/website/search.php index 3c06585..77cd1fc 100755 --- a/website/search.php +++ b/website/search.php @@ -101,7 +101,7 @@