diff --git a/.gitignore b/.gitignore index c6cab61..9a50b28 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ include/db.config.php .DS_Store +._.DS_Store +.DAV +composer.lock website/banners/ +vendor +cdn +forum \ No newline at end of file diff --git a/API/include/APIAccessDB.class.php b/API/include/APIAccessDB.class.php index c9b1ef6..9233012 100644 --- a/API/include/APIAccessDB.class.php +++ b/API/include/APIAccessDB.class.php @@ -29,9 +29,10 @@ function GetUserAllowanceByAPIKey($key) $dbh = $this->database->dbh; $sth = $dbh->prepare("Select APIU.*, AA.monthly_allowance, sum(AMC.count) as count FROM apiusers APIU LEFT JOIN api_allowance_level AA ON AA.id = APIU.api_allowance_level_id - LEFT JOIN api_month_counter AMC ON AMC.apiusers_id = APIU.id AND AMC.date >= APIU.last_refresh_date AND AMC.is_extra = 0 + LEFT JOIN api_month_counter AMC ON AMC.IP = INET6_ATON(:IP) AND AMC.apiusers_id = APIU.id AND AMC.date >= APIU.last_refresh_date AND AMC.is_extra = 0 WHERE apikey=:apikey GROUP BY APIU.id;"); $sth->bindValue(':apikey', $key, PDO::PARAM_STR); + $sth->bindValue(':IP', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR); if($sth->execute()) { @@ -59,11 +60,12 @@ function countAPIRequest($User, $update_refresh_date, $is_extra) $sth->bindValue(':id', $User->id, PDO::PARAM_INT); $sth->execute(); } - $sth = $dbh->prepare("INSERT INTO api_month_counter (apiusers_id, count, is_extra, date) - VALUES (:id, 1, :is_extra, :date) ON DUPLICATE KEY UPDATE count = count + 1;"); + $sth = $dbh->prepare("INSERT INTO api_month_counter (apiusers_id, count, is_extra, date, IP) + VALUES (:id, 1, :is_extra, :date, INET6_ATON(:IP)) ON DUPLICATE KEY UPDATE count = count + 1;"); $sth->bindValue(':date', date('Y-m-d')); $sth->bindValue(':id', $User->id, PDO::PARAM_INT); $sth->bindValue(':is_extra', $is_extra, PDO::PARAM_INT); + $sth->bindValue(':IP', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR); $sth->execute(); $dbh->commit(); } @@ -73,6 +75,90 @@ function countAPIRequest($User, $update_refresh_date, $is_extra) //Free lunch :P } } + + function RequestPublicAPIKey($user_id) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("Select apikey, is_banned FROM apiusers where userid = :user_id AND is_private_key = 0 LIMIT 1;"); + $sth->bindValue(':user_id', $user_id, PDO::PARAM_INT); + + if($sth->execute()) + { + $res = $sth->fetch(PDO::FETCH_OBJ); + if(!empty($res)) + { + if($res->is_banned == 0) + { + return $res->apikey; + } + else + { + return "Access Denied"; + } + } + else + { + $bytes = openssl_random_pseudo_bytes(64/2); + $key = bin2hex($bytes); + $sth = $dbh->prepare("INSERT INTO apiusers (userid, apikey, api_allowance_level_id, extra_allowance, is_private_key) + VALUES(:user_id, :apikey, 1, 0, 0);"); + $sth->bindValue(':user_id', $user_id, PDO::PARAM_INT); + $sth->bindValue(':apikey', $key, PDO::PARAM_INT); + + if($sth->execute()) + { + return $key; + } + else + { + return "Failed to generate API Key."; + } + } + } + } + + function RequestPrivateAPIKey($user_id) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("Select apikey, extra_allowance, is_banned FROM apiusers where userid = :user_id AND is_private_key != 0 LIMIT 1;"); + $sth->bindValue(':user_id', $user_id, PDO::PARAM_INT); + + if($sth->execute()) + { + $res = $sth->fetch(PDO::FETCH_OBJ); + if(!empty($res)) + { + if($res->is_banned == 0) + { + return $res; + } + else + { + return "Access Denied"; + } + } + else + { + $bytes = openssl_random_pseudo_bytes(64/2); + $key = bin2hex($bytes); + $sth = $dbh->prepare("INSERT INTO apiusers (userid, apikey, api_allowance_level_id, extra_allowance, is_private_key) + VALUES(:user_id, :apikey, 0, 6000, 1);"); + $sth->bindValue(':user_id', $user_id, PDO::PARAM_INT); + $sth->bindValue(':apikey', $key, PDO::PARAM_INT); + + if($sth->execute()) + { + return $this->RequestPrivateAPIKey($user_id); + } + else + { + return "Failed to generate API Key."; + } + } + } + } } ?> diff --git a/API/include/Utils.class.php b/API/include/Utils.class.php index 9b65409..e507dab 100644 --- a/API/include/Utils.class.php +++ b/API/include/Utils.class.php @@ -100,6 +100,21 @@ static function getValidNumericFromArray(array $args, $index) } return $IDs; } + + static function htmlspecialchars_decodeArrayRecursive(&$array) + { + foreach($array as &$sub_array_item) + { + if(is_array($sub_array_item) || is_object($sub_array_item)) + { + Utils::htmlspecialchars_decodeArrayRecursive($sub_array_item); + } + else if(!is_numeric($sub_array_item) && !empty($sub_array_item)) + { + $sub_array_item = htmlspecialchars_decode($sub_array_item); + } + } + } } ?> diff --git a/API/include/routes.php b/API/include/routes.php index 2a75363..ec86b8f 100644 --- a/API/include/routes.php +++ b/API/include/routes.php @@ -42,11 +42,27 @@ $fields = Utils::parseRequestedFields(); $API = TGDB::getInstance(); - $list = $API->SearchGamesByName($searchTerm, $offset, $limit+1, $fields); + if(isset($_REQUEST['filter']['platform']) && (!is_array($_REQUEST['filter']['platform'] || !in_array(0, $_REQUEST['filter']['platform'])))) + { + if(!is_array($_REQUEST['filter']['platform'])) + { + $PlatformsIDs = explode(",",$_REQUEST['filter']['platform']); + } + else + { + $PlatformsIDs = $_REQUEST['filter']['platform']; + } + $list = $API->SearchGamesByNameByPlatformID($searchTerm, $PlatformsIDs, $offset, $limit + 1, $fields); + } + else + { + $list = $API->SearchGamesByName($searchTerm, $offset, $limit+1, $fields); + } if($has_next_page = count($list) > $limit) unset($list[$limit]); + Utils::htmlspecialchars_decodeArrayRecursive($list); $JSON_Response = Utils::getStatus(200); $JSON_Response['data'] = array("count" => count($list), "games" => $list); @@ -62,14 +78,14 @@ $JSON_Response['include']['boxart']['base_url'] = CommonUtils::getImagesBaseURL(); $JSON_Response['include']['boxart']['data'] = $API->GetGameBoxartByID($IDs, 0, 999, 'boxart'); } - if(isset($options['Platform']) && $options['Platform']) + if(isset($options['platform']) && $options['platform']) { $PlatformsIDs = array(); foreach($list as $game) { - $PlatformsIDs[] = $game->Platform; + $PlatformsIDs[] = $game->platform; } - $JSON_Response['include']['Platform'] = $API->GetPlatforms($PlatformsIDs); + $JSON_Response['include']['platform'] = $API->GetPlatforms($PlatformsIDs); } } @@ -100,6 +116,7 @@ if($has_next_page = count($list) > $limit) unset($list[$limit]); + Utils::htmlspecialchars_decodeArrayRecursive($list); $JSON_Response = Utils::getStatus(200); $JSON_Response['data'] = array("count" => count($list), "games" => $list); @@ -110,14 +127,14 @@ $JSON_Response['include']['boxart']['base_url'] = CommonUtils::getImagesBaseURL(); $JSON_Response['include']['boxart']['data'] = $API->GetGameBoxartByID($IDs, 0, 999, 'boxart'); } - if(isset($options['Platform']) && $options['Platform']) + if(isset($options['platform']) && $options['platform']) { $PlatformsIDs = array(); foreach($list as $game) { - $PlatformsIDs[] = $game->Platform; + $PlatformsIDs[] = $game->platform; } - $JSON_Response['include']['Platform']['data'] = $API->GetPlatforms($PlatformsIDs); + $JSON_Response['include']['platform']['data'] = $API->GetPlatforms($PlatformsIDs); } } @@ -148,6 +165,7 @@ if($has_next_page = count($list) > $limit) unset($list[$limit]); + Utils::htmlspecialchars_decodeArrayRecursive($list); $JSON_Response = Utils::getStatus(200); $JSON_Response['data'] = array("count" => count($list), "games" => $list); if(count($list) > 0) @@ -162,44 +180,40 @@ $JSON_Response['include']['boxart']['base_url'] = CommonUtils::getImagesBaseURL(); $JSON_Response['include']['boxart']['data'] = $API->GetGameBoxartByID($GameIDs, 0, 999, 'boxart'); } - if(isset($options['Platform']) && $options['Platform']) + if(isset($options['platform']) && $options['platform']) { - $JSON_Response['include']['Platform']['data'] = $API->GetPlatforms($IDs); + $JSON_Response['include']['platform']['data'] = $API->GetPlatforms($IDs); } } $JSON_Response['pages'] = Utils::getJsonPageUrl($page, $has_next_page); return $response->withJson($JSON_Response); }); - $this->get('/Boxart[/{GameID}]', function($request, $response, $args) + $this->get('/Images[/{games_id}]', function($request, $response, $args) { - $this->logger->info("TGDB '/Games/Boxart' route"); + $this->logger->info("TGDB '/Games/Images' route"); - $GameIDs = Utils::getValidNumericFromArray($args, 'GameID'); + $GameIDs = Utils::getValidNumericFromArray($args, 'games_id'); if(empty($GameIDs)) { $JSON_Response = Utils::getStatus(406); return $response->withJson($JSON_Response, $JSON_Response['code']); } - $limit = 30; + $limit = 20; $page = Utils::getPage(); $offset = ($page - 1) * $limit; $options = Utils::parseRequestOptions(); - $filters = isset($_REQUEST['filter']) ? explode("," , $_REQUEST['filter']) : 'ALL'; + $filters = isset($_REQUEST['filter']['type']) ? explode("," , $_REQUEST['filter']['type']) : 'ALL'; $API = TGDB::getInstance(); $list = $API->GetGameBoxartByID($GameIDs, $offset, $limit+1, $filters); - $count = 0; - foreach($list as $boxarts) - { - $count += count($boxarts); - } - $has_next_page = $count > $limit; + if($has_next_page = count($list) > $limit) + unset($list[end(array_keys($list))]); $JSON_Response = Utils::getStatus(200); - $JSON_Response['data'] = array("count" => count($list), 'base_url' => CommonUtils::getImagesBaseURL(), "boxart" => $list); + $JSON_Response['data'] = array("count" => count($list), 'base_url' => CommonUtils::getImagesBaseURL(), "images" => $list); $JSON_Response['pages'] = Utils::getJsonPageUrl($page, $has_next_page); return $response->withJson($JSON_Response); @@ -208,47 +222,31 @@ { $this->logger->info("TGDB '/Games/Updates' route"); - if(!isset($_REQUEST['time']) && !is_numeric($_REQUEST['time']) && $_REQUEST['time'] < 0) - { - $_REQUEST['time'] = 60*24*365; - } - - $limit = 20; + $limit = 100; $page = Utils::getPage(); $offset = ($page - 1) * $limit; - $options = Utils::parseRequestOptions(); - $fields = Utils::parseRequestedFields(); $API = TGDB::getInstance(); - $list = $API->GetGamesByLatestUpdatedDate($_REQUEST['time'], $offset, $limit+1, $fields); - if($has_next_page = count($list) > $limit) - unset($list[$limit]); - - $JSON_Response = Utils::getStatus(200); - $JSON_Response['data'] = array("count" => count($list), "games" => $list); - if(count($list) > 0) + if(isset($_REQUEST['last_edit_id']) && is_numeric($_REQUEST['last_edit_id']) && ($_REQUEST['last_edit_id'] > -1)) { - if(isset($options['boxart']) && $options['boxart']) + $list = $API->GetUserEditsByID($_REQUEST['last_edit_id'], $offset, $limit+1); + } + else + { + if(!isset($_REQUEST['time']) || !is_numeric($_REQUEST['time']) || $_REQUEST['time'] < 0) { - $GameIDs = array(); - foreach($list as $game) - { - $GameIDs[] = $game->id; - } - $JSON_Response['include']['boxart']['base_url'] = CommonUtils::getImagesBaseURL(); - $JSON_Response['include']['boxart']['data'] = $API->GetGameBoxartByID($GameIDs, 0, 999, 'boxart'); - } - if(isset($options['Platform']) && $options['Platform']) - { - $PlatformsIDs = array(); - foreach($list as $game) - { - $PlatformsIDs[] = $game->Platform; - } - $JSON_Response['include']['Platform']['data'] = $API->GetPlatforms($PlatformsIDs); + $_REQUEST['time'] = 60*24; } + $list = $API->GetUserEditsByTime($_REQUEST['time'], $offset, $limit+1); } + + if($has_next_page = count($list) > $limit) + unset($list[$limit]); + + Utils::htmlspecialchars_decodeArrayRecursive($list); + $JSON_Response = Utils::getStatus(200); + $JSON_Response['data'] = array("count" => count($list), "updates" => $list); $JSON_Response['pages'] = Utils::getJsonPageUrl($page, $has_next_page); return $response->withJson($JSON_Response); @@ -262,12 +260,24 @@ $this->logger->info("TGDB '/Platforms' route"); $fields = Utils::parseRequestedFields(); + $options = Utils::parseRequestOptions(); $API = TGDB::getInstance(); $list = $API->GetPlatformsList($fields); + Utils::htmlspecialchars_decodeArrayRecursive($list); $JSON_Response = Utils::getStatus(200); $JSON_Response['data'] = array("count" => count($list), "platforms" => $list); + if(isset($options['boxart'])) + { + $PlatformIDs = array(); + foreach($list as &$platform) + { + $PlatformIDs[] = $platform->id; + } + $JSON_Response['include']['images']['base_url'] = CommonUtils::getImagesBaseURL(); + $JSON_Response['include']['images']['data'] = $API->GetPlatformBoxartByID($PlatformIDs, 0, 99999, ['boxart']); + } return $response->withJson($JSON_Response); }); $this->get('/ByPlatformID[/{id}]', function($request, $response, $args) @@ -282,12 +292,24 @@ } $fields = Utils::parseRequestedFields(); + $options = Utils::parseRequestOptions(); $API = TGDB::getInstance(); $list = $API->GetPlatforms($IDs, $fields); + Utils::htmlspecialchars_decodeArrayRecursive($list); $JSON_Response = Utils::getStatus(200); $JSON_Response['data'] = array("count" => count($list), "platforms" => $list); + if(isset($options['boxart'])) + { + $PlatformIDs = array(); + foreach($list as &$platform) + { + $PlatformIDs[] = $platform->id; + } + $JSON_Response['include']['images']['base_url'] = CommonUtils::getImagesBaseURL(); + $JSON_Response['include']['images']['data'] = $API->GetPlatformBoxartByID($PlatformIDs, 0, 99999, ['boxart']); + } return $response->withJson($JSON_Response); }); $this->get('/ByPlatformName[/{name}]', function($request, $response, $args) @@ -309,12 +331,99 @@ } $fields = Utils::parseRequestedFields(); + $options = Utils::parseRequestOptions(); $API = TGDB::getInstance(); $list = $API->SearchPlatformByName($searchTerm, $fields); + Utils::htmlspecialchars_decodeArrayRecursive($list); $JSON_Response = Utils::getStatus(200); $JSON_Response['data'] = array("count" => count($list), "platforms" => $list); + if(isset($options['boxart'])) + { + $PlatformIDs = array(); + foreach($list as &$platform) + { + $PlatformIDs[] = $platform->id; + } + $JSON_Response['include']['images']['base_url'] = CommonUtils::getImagesBaseURL(); + $JSON_Response['include']['images']['data'] = $API->GetPlatformBoxartByID($PlatformIDs, 0, 99999, ['boxart']); + } + return $response->withJson($JSON_Response); + }); + $this->get('/Images[/{platforms_id}]', function($request, $response, $args) + { + $this->logger->info("TGDB '/Platforms/images' route"); + + $GameIDs = Utils::getValidNumericFromArray($args, 'platforms_id'); + if(empty($GameIDs)) + { + $JSON_Response = Utils::getStatus(406); + return $response->withJson($JSON_Response, $JSON_Response['code']); + } + + $limit = 30; + $page = Utils::getPage(); + $offset = ($page - 1) * $limit; + $options = Utils::parseRequestOptions(); + $filters = isset($_REQUEST['filter']['type']) ? explode(",", $_REQUEST['filter']['type']) : 'ALL'; + + $API = TGDB::getInstance(); + $list = $API->GetPlatformBoxartByID($GameIDs, $offset, $limit+1, $filters); + + $count = 0; + foreach($list as $boxarts) + { + $count += count($boxarts); + } + $has_next_page = $count > $limit; + + $JSON_Response = Utils::getStatus(200); + $JSON_Response['data'] = array("count" => count($list), 'base_url' => CommonUtils::getImagesBaseURL(), "images" => $list); + $JSON_Response['pages'] = Utils::getJsonPageUrl($page, $has_next_page); + + return $response->withJson($JSON_Response); + }); +}); + +$app->get('/Genres', function($request, $response, $args) +{ + $this->logger->info("TGDB '/Genres' route"); + $API = TGDB::getInstance(); + $list = $API->GetGenres(); + + Utils::htmlspecialchars_decodeArrayRecursive($list); + $JSON_Response = Utils::getStatus(200); + $JSON_Response['data'] = array("count" => count($list), "genres" => $list); + return $response->withJson($JSON_Response); +}); + +$app->group('/Developers', function() +{ + $this->get('', function($request, $response, $args) + { + $this->logger->info("TGDB '/Developers' route"); + $API = TGDB::getInstance(); + $list = $API->GetDevsList(); + + Utils::htmlspecialchars_decodeArrayRecursive($list); + $JSON_Response = Utils::getStatus(200); + $JSON_Response['data'] = array("count" => count($list), "developers" => $list); + return $response->withJson($JSON_Response); + }); +}); + +$app->group('/Publishers', function() +{ + $this->get('', function($request, $response, $args) + { + $this->logger->info("TGDB '/Publishers' route"); + $API = TGDB::getInstance(); + $list = $API->GetPubsList(); + + Utils::htmlspecialchars_decodeArrayRecursive($list); + $JSON_Response = Utils::getStatus(200); + $JSON_Response['data'] = array("count" => count($list), "publishers" => $list); return $response->withJson($JSON_Response); }); }); diff --git a/API/key.php b/API/key.php new file mode 100644 index 0000000..f729067 --- /dev/null +++ b/API/key.php @@ -0,0 +1,102 @@ +isLoggedIn() && $_user->hasPermission('u_api_access')) +{ + require_once __DIR__ . "/../API/include/APIAccessDB.class.php"; + $auth = APIAccessDB::getInstance(); + $key = $auth->RequestPublicAPIKey($_user->GetUserID()); + $private_key = $auth->RequestPrivateAPIKey($_user->GetUserID()); + if(!is_object($private_key)) + { + $private_key = new stdClass(); + $private_key->key = "NA"; + $private_key->extra_allowance = "NA"; + + } +} + +?> + + + + + + + TheGamesDB API DOCs + + + + + + + + + +

API Keys

+
+ +
+
+
+ isLoggedIn() ) : ?> +

You must login to the forum to view your api key.

+ isLoggedIn() && !$_user->hasPermission('u_api_access')) : ?> +

You must request access to the api via the forum.

+ isLoggedIn() && $_user->hasPermission('u_api_access')) : ?> +
+
+ Public API Key: +
+
+

This key has a limit per IP.

+

This key should be used in your application.

+
+
+ +
+
+ Private API Key: apikey ?> +

Remaining Requests: extra_allowance ?>/6000

+

+
+

This key would contain a higher one time request rate limit, + but the key must not be made available to the general public, as it has a shared limit and not an IP based one.

+

This key can be used to create an initial mirror of the required data on your server, + which you can then subsquantly updated using the Update endpoint using the public key.

+

Please Note: this key should only be used server side. +

+ + +

+
+ + +
+
+ +
+ + + diff --git a/API/templates/doc.html b/API/templates/doc.html index e42c833..631df01 100644 --- a/API/templates/doc.html +++ b/API/templates/doc.html @@ -36,7 +36,6 @@

API DOCS

-
@@ -69,47 +68,47 @@

API DOCS

This API will return a list or a single game entry based the provided parameter(s).

This API call expects `name`, and `apikey`, while `include` and `fields` are optional.

+

This API call can also take argument `filter[platform]=id,id2` to return search for specific platform(s)

Please look at "`/Games/*` Common" section below

- +
- /Games/Updates?time=minutes + `/Games/*` Common (`/Games/Updates`)
-

This API will return a list or a single game entry based the provided parameter(s).

-

This API call expects `time`, and `apikey`, while `include` and `fields` are optional.

-

Please look at "`/Games/*` Common" section below

+

This API will return a list or a single game entry based on the provided parameter(s).

+

This API calls can expects `name`, `id`, and `apikey`, while `include` and `fields` are optional.

+

`include` valid options: `boxart,platform`.

+

`fields` valid options: `id,game_title,players,release_date,developers,publisher(deprecated),publishers,genres,overview,last_updated,rating,platform,coop,youtube,os,processor,ram,hdd,video,sound,alternates(format changed),`

+

Note: these options are subject to change.

+

Note: some of the fields options are reminent of old database and will be removed, while others will be renamed, so please keep an eye on this.

- +
- `/Games/*` Common (excluding `/Games/Boxart`) -
+ /Games/Updates?time=minutes
+ /Games/Updates?last_edit_id=edit_id +
-

This API will return a list or a single game entry based on the provided parameter(s).

-

This API calls can expects `name`, `id`, and `apikey`, while `include` and `fields` are optional.

-

`include` valid options: `boxart,Platform`.

-

`fields` valid options: `id,GameTitle,GameID,Players,ReleaseDate,ReleaseDateRevised,Developer,Publisher,Runtime,Genre,Actors,Overview,bannerrequest,created,lastupdated,lastupdatedRevised,Rating,requestcomment,locked,mirrorupdate,lockedby,Platform,coop,Youtube,os,processor,ram,hdd,video,sound,Alternates,author,updatedby,`

-

Note: these options are subject to change.

-

Note: some of the fields options are reminent of old database and will be removed, while others will be renamed, so please keep an eye on this.

+

This API will return user edits.

+

This API call expects `last_edit_id` or `time`, and `apikey`.

+

`last_edit_id` refers to the edit id and no `games_id`, `last_edit_id` will take preferance over `time` if both are specified.

- /Games/Boxart?GameID=22,15,72 + /Games/Images?games_id=22,15,72&filter[type]=boxart,fanart

This API will return a list or a single graphics entry based the provided parameter(s).

-

This API call expects `GameID`, and `apikey`, while `filter` is optional.

-

`filter` valid options: `fanart,series,boxart,screenshot,platform-banner,platform-fanart,platform-boxart,clearlogo`.

+

This API call expects `games_id`, and `apikey`, while `filter` is optional.

+

`filter` valid options: `fanart,banner,boxart,screenshot,clearlogo`.

`filter` default value is `boxart`.

Note: these options are subject to change.

-

Note: series might also be known as banners, and it's like this will change to reflect that in the future.

-
@@ -152,13 +151,53 @@

API DOCS

These APIs will return a list or a single platform entry based on the provided parameter(s).

-

These API call expects `id`, `name,` and `apikey`, while `fields` are optional.

+

These API call expects `platforms_id`, `name,` and `apikey`, while `fields` are optional.

`fields` valid options: `id,name,alias,icon,console,controller,developer,manufacturer,media,cpu,memory,graphics,sound,maxcontrollers,display,overview,youtube`

Note: these options are subject to change.

Note: some of the fields options are reminent of old database and will be removed, while others will be renamed, so please stay informed for any changes.

+
+
+ /Platforms/images?platforms_id=1,2,4&filter[type]=boxart +
+
+

This API will return a list or a single graphics entry based the provided parameter(s).

+

This API call expects `platforms_id`, and `apikey` param, while `filter` param is optional.

+

`filter[type]` valid options: `banner,fanart,boxart`.

+
+
+ +
+
+ /Genres +
+
+

This API will return the list of genres with associated name and id.

+

This API call expects `apikey`.

+
+
+ +
+
+ /Developers +
+
+

This API will return the list of developers with associated name and id.

+

This API call expects `apikey`.

+
+
+ +
+
+ /Publishers +
+
+

This API will return the list of publishers with associated name and id.

+

This API call expects `apikey`.

+
+
diff --git a/composer.json b/composer.json index de8ff12..f8c7276 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ "slim/slim": "^3.1", "slim/php-view": "^2.0", "monolog/monolog": "^1.17", - "claviska/simpleimage": "^3.3" + "claviska/simpleimage": "^3.3", + "cloudflare/sdk": "^1.1" } } diff --git a/include/CommonUtils.class.php b/include/CommonUtils.class.php index 5b91965..c95caa6 100644 --- a/include/CommonUtils.class.php +++ b/include/CommonUtils.class.php @@ -2,8 +2,8 @@ class CommonUtils { - static public $WEBSITE_BASE_URL = "https://beta.thegamesdb.net/"; - static public $API_BASE_URL = "https://api.beta.thegamesdb.net"; + static public $WEBSITE_BASE_URL = "https://thegamesdb.net/"; + static public $API_BASE_URL = "https://api.thegamesdb.net"; static public $BOXART_BASE_URL = "https://cdn.thegamesdb.net/images/"; static function getImagesBaseURL() diff --git a/include/TGDB.API.php b/include/TGDB.API.php index 8f2c34c..c66e53c 100644 --- a/include/TGDB.API.php +++ b/include/TGDB.API.php @@ -23,9 +23,48 @@ public static function getInstance() return $instance; } + private function PopulateOtherData(&$res, $fields) + { + $GameIDs = array(); + foreach($res as $game) + { + $GameIDs[] = $game->id; + } + $devs = $this->GetGamesDevs($GameIDs, false); + if(isset($fields['genres'])) + { + $genres = $this->GetGamesGenres($GameIDs, false); + } + if(isset($fields['publishers'])) + { + $pubs = $this->GetGamesPubs($GameIDs, false); + } + + if(isset($fields['alternates'])) + { + $alts = $this->GetGamesAlts($GameIDs, false); + } + foreach($res as $game) + { + $game->developers = (!empty($devs[$game->id])) ? $devs[$game->id] : NULL; + if(isset($fields['genres'])) + { + $game->genres = (!empty($genres[$game->id])) ? $genres[$game->id] : NULL; + } + if(isset($fields['publishers'])) + { + $game->publishers = (!empty($pubs[$game->id])) ? $pubs[$game->id] : NULL; + } + if(isset($fields['alternates'])) + { + $game->alternates = !empty($alts[$game->id]) ? $alts[$game->id] : NULL; + } + } + } + function GetGameListByPlatform($IDs = 0, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; + $qry = "Select id, game_title, release_date, platform "; if(!empty($fields)) { @@ -80,6 +119,10 @@ function GetGameListByPlatform($IDs = 0, $offset = 0, $limit = 20, $fields = arr if($sth->execute()) { $res = $sth->fetchAll(PDO::FETCH_OBJ); + if(!empty($res)) + { + $this->PopulateOtherData($res, $fields); + } return $res; } } @@ -107,7 +150,7 @@ function GetGameByID($IDs, $offset = 0, $limit = 20, $fields = array()) return array(); } - $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; + $qry = "Select id, game_title, release_date, platform "; if(!empty($fields)) { @@ -131,6 +174,10 @@ function GetGameByID($IDs, $offset = 0, $limit = 20, $fields = array()) if($sth->execute()) { $res = $sth->fetchAll(PDO::FETCH_OBJ); + if(!empty($res)) + { + $this->PopulateOtherData($res, $fields); + } return $res; } @@ -141,7 +188,7 @@ function SearchGamesByName($searchTerm, $offset = 0, $limit = 20, $fields = arra { $dbh = $this->database->dbh; - $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; + $qry = "Select id, game_title, release_date, platform "; if(!empty($fields)) { @@ -154,14 +201,14 @@ function SearchGamesByName($searchTerm, $offset = 0, $limit = 20, $fields = arra } } - $qry .= " FROM games WHERE GameTitle LIKE :name OR GameTitle=:name2 OR soundex(GameTitle) LIKE soundex(:name3) OR soundex(GameTitle) LIKE soundex(:name4) + $qry .= " FROM games WHERE game_title LIKE :name OR game_title=:name2 OR soundex(game_title) LIKE soundex(:name3) OR soundex(game_title) LIKE soundex(:name4) GROUP BY id ORDER BY CASE - WHEN GameTitle like :name5 THEN 3 - WHEN GameTitle like :name6 THEN 0 - WHEN GameTitle like :name7 THEN 1 - WHEN GameTitle like :name8 THEN 2 + WHEN game_title like :name5 THEN 3 + WHEN game_title like :name6 THEN 0 + WHEN game_title like :name7 THEN 1 + WHEN game_title like :name8 THEN 2 ELSE 4 - END, GameTitle LIMIT :limit OFFSET :offset"; + END, game_title LIMIT :limit OFFSET :offset"; $sth = $dbh->prepare($qry); @@ -182,6 +229,47 @@ function SearchGamesByName($searchTerm, $offset = 0, $limit = 20, $fields = arra if($sth->execute()) { $res = $sth->fetchAll(PDO::FETCH_OBJ); + if(!empty($res)) + { + $this->PopulateOtherData($res, $fields); + } + return $res; + } + } + + function SearchGamesByExactName($searchTerm, $offset = 0, $limit = 20, $fields = array()) + { + $dbh = $this->database->dbh; + + $qry = "Select id, game_title, release_date, platform "; + + if(!empty($fields)) + { + foreach($fields as $key => $enabled) + { + if($enabled && $this->is_valid_games_col($key)) + { + $qry .= ", $key "; + } + } + } + + $qry .= " FROM games WHERE game_title=:game_title LIMIT :limit OFFSET :offset"; + + $sth = $dbh->prepare($qry); + + $sth->bindValue(':game_title', $searchTerm); + + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); + + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ); + if(!empty($res)) + { + $this->PopulateOtherData($res, $fields); + } return $res; } } @@ -190,7 +278,7 @@ function SearchGamesByNameByPlatformID($searchTerm, $IDs, $offset = 0, $limit = { $dbh = $this->database->dbh; - $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; + $qry = "Select id, game_title, release_date, platform "; if(!empty($fields)) { @@ -223,17 +311,17 @@ function SearchGamesByNameByPlatformID($searchTerm, $IDs, $offset = 0, $limit = if(!empty($PlatformIDs)) { - $qry .= " Platform IN ($PlatformIDs) AND "; + $qry .= " platform IN ($PlatformIDs) AND "; } - $qry .= " (GameTitle LIKE :name OR GameTitle=:name2 OR soundex(GameTitle) LIKE soundex(:name3) OR soundex(GameTitle) LIKE soundex(:name4)) + $qry .= " (game_title LIKE :name OR game_title=:name2 OR soundex(game_title) LIKE soundex(:name3) OR soundex(game_title) LIKE soundex(:name4)) GROUP BY id ORDER BY CASE - WHEN GameTitle like :name5 THEN 3 - WHEN GameTitle like :name6 THEN 0 - WHEN GameTitle like :name7 THEN 1 - WHEN GameTitle like :name8 THEN 2 + WHEN game_title like :name5 THEN 3 + WHEN game_title like :name6 THEN 0 + WHEN game_title like :name7 THEN 1 + WHEN game_title like :name8 THEN 2 ELSE 4 - END, GameTitle LIMIT :limit OFFSET :offset"; + END, game_title LIMIT :limit OFFSET :offset"; $sth = $dbh->prepare($qry); @@ -254,6 +342,10 @@ function SearchGamesByNameByPlatformID($searchTerm, $IDs, $offset = 0, $limit = if($sth->execute()) { $res = $sth->fetchAll(PDO::FETCH_OBJ); + if(!empty($res)) + { + $this->PopulateOtherData($res, $fields); + } return $res; } } @@ -265,7 +357,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, ReleaseDateRevised, Platform "; + $qry = "Select id, game_title, release_date, platform "; if(!empty($fields)) { @@ -287,7 +379,7 @@ function GetGamesByDateByPlatform($IDs, $date, $offset = 0, $limit = 20, $fields $BeforeAfterDate = ">"; } - $qry .= " FROM games WHERE ReleaseDateRevised $BeforeAfterDate STR_TO_DATE(:date, '%d/%m/%Y') "; + $qry .= " FROM games WHERE release_date $BeforeAfterDate STR_TO_DATE(:date, '%d/%m/%Y') "; if(is_array($IDs)) { @@ -298,11 +390,11 @@ function GetGamesByDateByPlatform($IDs, $date, $offset = 0, $limit = 20, $fields $PlatformIDsArr[] = $val; } $PlatformIDs = implode(",", $PlatformIDsArr); - $qry .= " AND Platform IN " . implode(",", $PlatformIDsArr) . " "; + $qry .= " AND platform IN " . implode(",", $PlatformIDsArr) . " "; } else if(is_numeric($IDs) && $IDs > 0) { - $qry .= " AND Platform = $IDs "; + $qry .= " AND platform = $IDs "; } @@ -326,6 +418,10 @@ function GetGamesByDateByPlatform($IDs, $date, $offset = 0, $limit = 20, $fields if($sth->execute()) { $res = $sth->fetchAll(PDO::FETCH_OBJ); + if(!empty($res)) + { + $this->PopulateOtherData($res, $fields); + } return $res; } @@ -334,7 +430,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, ReleaseDateRevised, Platform "; + $qry = "Select id, game_title, release_date, platform "; if(!empty($fields)) { @@ -367,6 +463,10 @@ function GetAllGames($offset = 0, $limit = 20, $fields = array(), $OrderBy = '', if($sth->execute()) { $res = $sth->fetchAll(PDO::FETCH_OBJ); + if(!empty($res)) + { + $this->PopulateOtherData($res, $fields); + } return $res; } @@ -375,7 +475,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, ReleaseDateRevised, Platform "; + $qry = "Select id, game_title, release_date, platform "; if(!empty($fields)) { @@ -388,7 +488,7 @@ function GetGamesByLatestUpdatedDate($minutes, $offset = 0, $limit = 20, $fields } } - $qry .= " FROM games WHERE lastupdatedRevised > DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -:minutes MINUTE) ORDER BY lastupdatedRevised DESC LIMIT :limit OFFSET :offset"; + $qry .= " FROM games WHERE last_updated > DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -:minutes MINUTE) ORDER BY last_updated DESC LIMIT :limit OFFSET :offset"; $dbh = $this->database->dbh; $sth = $dbh->prepare($qry); @@ -400,121 +500,130 @@ function GetGamesByLatestUpdatedDate($minutes, $offset = 0, $limit = 20, $fields if($sth->execute()) { $res = $sth->fetchAll(PDO::FETCH_OBJ); + if(!empty($res)) + { + $this->PopulateOtherData($res, $fields); + } return $res; } return array(); } - private function CreateBoxartFilterQuery($filter, &$is_filter) + function GetGamesByDevID($IDs = 0, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $qry = ""; - switch($filter) - { - case 'fanart': - case 'series': - case 'boxart': - case 'screenshot': - case 'platform-banner': - case 'platform-fanart': - case 'platform-boxart': - case 'clearlogo': - if(!$is_filter) - { - $qry .=" AND ("; - $is_filter = true; + $qry = "Select id, game_title, release_date, platform "; - } - else + if(!empty($fields)) + { + foreach($fields as $key => $enabled) + { + if($enabled && $this->is_valid_games_col($key)) { - $qry .=" OR "; + $qry .= ", $key "; } - $qry .=" keytype = '$filter' "; + } } - return $qry; - } - function GetGameBoxartByID($IDs = 0, $offset = 0, $limit = 20, $filters = 'boxart') - { - $GameIDs; + $qry .= " FROM games "; + + $DevIDs = array(); if(is_array($IDs)) { if(!empty($IDs)) { foreach($IDs as $key => $val) if(is_numeric($val)) - $GameIDsArr[] = $val; + $DevIDsArr[] = $val; } - $GameIDs = implode(",", $GameIDsArr); + $DevIDs = implode(",", $DevIDsArr); } else if(is_numeric($IDs)) { - $GameIDs = $IDs; + $DevIDs = $IDs; } - if(empty($GameIDs)) + if(empty($DevIDs)) { return array(); } - $qry = "Select keyvalue as games_id, keytype as type, side, filename, resolution FROM banners WHERE keyvalue IN ($GameIDs) "; - $is_filter = false; - if(is_array($filters)) + $qry .= "WHERE id IN (SELECT games_id from games_devs where dev_id IN ($DevIDs)) "; + if(!empty($OrderBy) && $this->is_valid_games_col($OrderBy)) { - foreach($filters as $filter) + if($ASCDESC != 'ASC' && $ASCDESC != 'DESC') { - $qry .= $this->CreateBoxartFilterQuery($filter, $is_filter); + $ASCDESC == 'ASC'; } - } - else - { - $qry .= $this->CreateBoxartFilterQuery($filters, $is_filter); - } - - if($is_filter) - { - $qry .=" )"; + $qry .= " ORDER BY $OrderBy $ASCDESC "; } $qry .= " LIMIT :limit OFFSET :offset;"; $dbh = $this->database->dbh; $sth = $dbh->prepare($qry); - + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); $sth->bindValue(':limit', $limit, PDO::PARAM_INT); if($sth->execute()) { - $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP); + $res = $sth->fetchAll(PDO::FETCH_OBJ); + if(!empty($res)) + { + $this->PopulateOtherData($res, $fields); + } return $res; } } - function GetLatestGameBoxart($offset = 0, $limit = 20, $filters = 'boxart', $side = '') + function GetGamesByPubID($IDs = 0, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $qry = "Select keyvalue as game_id, keytype as type, side, filename, resolution FROM banners WHERE 1 "; - $is_filter = false; - if(is_array($filters)) + $qry = "Select id, game_title, release_date, platform "; + + if(!empty($fields)) { - foreach($filters as $filter) + foreach($fields as $key => $enabled) { - $qry .= $this->CreateBoxartFilterQuery($filter, $is_filter); + if($enabled && $this->is_valid_games_col($key)) + { + $qry .= ", $key "; + } } } - else + + $qry .= " FROM games "; + + $PubIDs = array(); + if(is_array($IDs)) { - $qry .= $this->CreateBoxartFilterQuery($filters, $is_filter); + if(!empty($IDs)) + { + foreach($IDs as $key => $val) + if(is_numeric($val)) + $PubIDsArr[] = $val; + } + $PubIDs = implode(",", $PubIDsArr); + } + else if(is_numeric($IDs)) + { + $PubIDs = $IDs; } - if($is_filter) + if(empty($PubIDs)) { - $qry .= " )"; + return array(); } - if(!empty($side) && ($side == 'front' || $side == 'back')) + + $qry .= "WHERE id IN (SELECT games_id from games_pubs where pub_id IN ($PubIDs)) "; + if(!empty($OrderBy) && $this->is_valid_games_col($OrderBy)) { - $qry .= " AND side = '$side' "; + if($ASCDESC != 'ASC' && $ASCDESC != 'DESC') + { + $ASCDESC == 'ASC'; + } + $qry .= " ORDER BY $OrderBy $ASCDESC "; } - $qry .= " ORDER BY id DESC LIMIT :limit OFFSET :offset;"; + $qry .= " LIMIT :limit OFFSET :offset;"; $dbh = $this->database->dbh; $sth = $dbh->prepare($qry); @@ -525,249 +634,1158 @@ function GetLatestGameBoxart($offset = 0, $limit = 20, $filters = 'boxart', $sid if($sth->execute()) { $res = $sth->fetchAll(PDO::FETCH_OBJ); + if(!empty($res)) + { + $this->PopulateOtherData($res, $fields); + } return $res; } } - function GetPlatformsList($fields = array()) + function GetMissingGames($field, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $qry = "Select id as n, id, name, alias "; + if(!$this->is_valid_games_col($field)) + { + return array(); + } + $qry = "Select id, game_title, release_date, platform "; - $dbh = $this->database->dbh; if(!empty($fields)) { foreach($fields as $key => $enabled) { - if($enabled && $this->is_valid_platform_col($key)) + if($enabled && $this->is_valid_games_col($key)) { $qry .= ", $key "; } } } - $qry .= " FROM platforms ORDER BY name;"; - - $sth = $dbh->prepare($qry); + $qry .= " FROM games "; - if($sth->execute()) - { - $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP | PDO::FETCH_UNIQUE); - return $res; - } - } - function GetPlatforms($IDs, $fields = array()) - { - $PlatformIDs; - if(is_array($IDs)) + $qry .= "WHERE $field = '' OR $field IS NULL "; + if(!empty($OrderBy) && $this->is_valid_games_col($OrderBy)) { - if(!empty($IDs)) + if($ASCDESC != 'ASC' && $ASCDESC != 'DESC') { - foreach($IDs as $key => $val) - if(is_numeric($val)) - $PlatformIDsArr[] = $val; + $ASCDESC == 'ASC'; } - $PlatformIDs = implode(",", $PlatformIDsArr); - } - else if(is_numeric($IDs)) - { - $PlatformIDs = $IDs; + $qry .= " ORDER BY $OrderBy $ASCDESC "; } + $qry .= " LIMIT :limit OFFSET :offset;"; - if(empty($PlatformIDs)) - { - return array(); - } + $dbh = $this->database->dbh; + $sth = $dbh->prepare($qry); - $qry = "Select id as n, id, name, alias "; + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); - $dbh = $this->database->dbh; - if(!empty($fields)) + if($sth->execute()) { - foreach($fields as $key => $enabled) + $res = $sth->fetchAll(PDO::FETCH_OBJ); { - if($enabled && $this->is_valid_platform_col($key)) + foreach($res as $game) { - $qry .= ", $key "; + $GameIDs[] = $game->id; + } + $devs = $this->GetGamesDevs($GameIDs, false); + foreach($res as $game) + { + $game->developers = (!empty($devs[$game->id])) ? $devs[$game->id] : NULL; + } + if(isset($fields['publishers'])) + { + $pubs = $this->GetGamesPubs($GameIDs, false); + foreach($res as $game) + { + $game->publishers = (!empty($pubs[$game->id])) ? $pubs[$game->id] : NULL; + } } } - } - $qry .= " FROM platforms Where id IN ($PlatformIDs) ORDER BY name;"; - - $sth = $dbh->prepare($qry); - - if($sth->execute()) - { - $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP | PDO::FETCH_UNIQUE); return $res; } } - function SearchPlatformByName($searchTerm, $fields = array()) + function GetMissingGamesImages($type, $sub_type = '', $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $dbh = $this->database->dbh; - - $qry = "Select id, name, alias"; + $qry = "Select id, game_title, release_date, platform "; - $dbh = $this->database->dbh; if(!empty($fields)) { foreach($fields as $key => $enabled) { - if($enabled && $this->is_valid_platform_col($key)) + if($enabled && $this->is_valid_games_col($key)) { $qry .= ", $key "; } } } - $qry .= " FROM platforms WHERE name LIKE :name OR name=:name2 OR soundex(name) LIKE soundex(:name3) OR soundex(name) LIKE soundex(:name4) - GROUP BY id ORDER BY CASE - WHEN name like :name5 THEN 3 - WHEN name like :name6 THEN 0 - WHEN name like :name7 THEN 1 - WHEN name like :name8 THEN 2 - ELSE 4 - END, name"; - - $sth = $dbh->prepare($qry); - - $sth->bindValue(':name', "%$searchTerm%"); - $sth->bindValue(':name2', $searchTerm); - $sth->bindValue(':name3', "$searchTerm%"); - $sth->bindValue(':name4', "% %$searchTerm% %"); + $qry .= " FROM games "; - $sth->bindValue(':name5', "%$searchTerm"); - $sth->bindValue(':name6', $searchTerm); + $side = ''; + if($sub_type != '') + { + $side = 'AND side=:side'; + } + $qry .= "WHERE id NOT IN (select games_id from banners where type=:type $side) "; + if(!empty($OrderBy) && $this->is_valid_games_col($OrderBy)) + { + if($ASCDESC != 'ASC' && $ASCDESC != 'DESC') + { + $ASCDESC == 'ASC'; + } + $qry .= " ORDER BY $OrderBy $ASCDESC "; + } + $qry .= " LIMIT :limit OFFSET :offset;"; + + $dbh = $this->database->dbh; + $sth = $dbh->prepare($qry); + + $sth->bindValue(':type', $type, PDO::PARAM_STR); + if($sub_type != '') + { + $sth->bindValue(':side', $sub_type, PDO::PARAM_STR); + } + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); + + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ); + { + foreach($res as $game) + { + $GameIDs[] = $game->id; + } + $devs = $this->GetGamesDevs($GameIDs, false); + foreach($res as $game) + { + $game->developers = (!empty($devs[$game->id])) ? $devs[$game->id] : NULL; + } + if(isset($fields['publishers'])) + { + $pubs = $this->GetGamesPubs($GameIDs, false); + foreach($res as $game) + { + $game->publishers = (!empty($pubs[$game->id])) ? $pubs[$game->id] : NULL; + } + } + } + return $res; + } + } + + private function CreateBoxartFilterQuery($filter, &$is_filter) + { + $qry = ""; + switch($filter) + { + case 'series': + $filter = 'banner'; + case 'fanart': + case 'banner': + case 'boxart': + case 'screenshot': + case 'icon': + case 'clearlogo': + if(!$is_filter) + { + $qry .=" AND ("; + $is_filter = true; + + } + else + { + $qry .=" OR "; + } + $qry .=" type = '$filter' "; + } + return $qry; + } + + function GetGameBoxartByID($IDs = 0, $offset = 0, $limit = 20, $filters = 'boxart') + { + $GameIDs; + if(is_array($IDs)) + { + if(!empty($IDs)) + { + foreach($IDs as $key => $val) + if(is_numeric($val)) + $GameIDsArr[] = $val; + } + $GameIDs = implode(",", $GameIDsArr); + } + else if(is_numeric($IDs)) + { + $GameIDs = $IDs; + } + + if(empty($GameIDs)) + { + return array(); + } + + $qry = "Select B.games_id, B.id, B.type, B.side, B.filename, B.resolution FROM banners B, (SELECT id FROM games WHERE id IN ($GameIDs) LIMIT :limit OFFSET :offset) T WHERE B.games_id = T.id "; + $is_filter = false; + if(is_array($filters)) + { + foreach($filters as $filter) + { + $qry .= $this->CreateBoxartFilterQuery($filter, $is_filter); + } + } + else + { + $qry .= $this->CreateBoxartFilterQuery($filters, $is_filter); + } + + if($is_filter) + { + $qry .=" )"; + } + $qry .= ";"; + + $dbh = $this->database->dbh; + $sth = $dbh->prepare($qry); + + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); + + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP); + return $res; + } + } + + function GetLatestGameBoxart($offset = 0, $limit = 20, $filters = 'boxart', $side = '') + { + $qry = "Select games_id as game_id, type, side, filename, resolution FROM banners WHERE 1 "; + $is_filter = false; + if(is_array($filters)) + { + foreach($filters as $filter) + { + $qry .= $this->CreateBoxartFilterQuery($filter, $is_filter); + } + } + else + { + $qry .= $this->CreateBoxartFilterQuery($filters, $is_filter); + } + + if($is_filter) + { + $qry .= " )"; + } + if(!empty($side) && ($side == 'front' || $side == 'back')) + { + $qry .= " AND side = '$side' "; + } + $qry .= " ORDER BY id DESC LIMIT :limit OFFSET :offset;"; + + $dbh = $this->database->dbh; + $sth = $dbh->prepare($qry); + + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); + + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ); + return $res; + } + } + + function GetPlatformsList($fields = array()) + { + $qry = "Select id as n, id, name, alias "; + + $dbh = $this->database->dbh; + if(!empty($fields)) + { + foreach($fields as $key => $enabled) + { + if($enabled && $this->is_valid_platform_col($key)) + { + $qry .= ", $key "; + } + } + } + + $qry .= " FROM platforms ORDER BY name;"; + + $sth = $dbh->prepare($qry); + + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP | PDO::FETCH_UNIQUE); + return $res; + } + } + + function GetPlatforms($IDs, $fields = array()) + { + $PlatformIDs; + if(is_array($IDs)) + { + if(!empty($IDs)) + { + foreach($IDs as $key => $val) + if(is_numeric($val)) + $PlatformIDsArr[] = $val; + } + $PlatformIDs = implode(",", $PlatformIDsArr); + } + else if(is_numeric($IDs)) + { + $PlatformIDs = $IDs; + } + + if(empty($PlatformIDs)) + { + return array(); + } + + $qry = "Select id as n, id, name, alias "; + + $dbh = $this->database->dbh; + if(!empty($fields)) + { + foreach($fields as $key => $enabled) + { + if($enabled && $this->is_valid_platform_col($key)) + { + $qry .= ", $key "; + } + } + } + $qry .= " FROM platforms Where id IN ($PlatformIDs) ORDER BY name;"; + + $sth = $dbh->prepare($qry); + + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP | PDO::FETCH_UNIQUE); + return $res; + } + } + + function SearchPlatformByName($searchTerm, $fields = array()) + { + $dbh = $this->database->dbh; + + $qry = "Select id, name, alias"; + + $dbh = $this->database->dbh; + if(!empty($fields)) + { + foreach($fields as $key => $enabled) + { + if($enabled && $this->is_valid_platform_col($key)) + { + $qry .= ", $key "; + } + } + } + + $qry .= " FROM platforms WHERE name LIKE :name OR name=:name2 OR soundex(name) LIKE soundex(:name3) OR soundex(name) LIKE soundex(:name4) + GROUP BY id ORDER BY CASE + WHEN name like :name5 THEN 3 + WHEN name like :name6 THEN 0 + WHEN name like :name7 THEN 1 + WHEN name like :name8 THEN 2 + ELSE 4 + END, name"; + + $sth = $dbh->prepare($qry); + + $sth->bindValue(':name', "%$searchTerm%"); + $sth->bindValue(':name2', $searchTerm); + $sth->bindValue(':name3', "$searchTerm%"); + $sth->bindValue(':name4', "% %$searchTerm% %"); + + $sth->bindValue(':name5', "%$searchTerm"); + $sth->bindValue(':name6', $searchTerm); $sth->bindValue(':name7', "$searchTerm%"); $sth->bindValue(':name8', "% %$searchTerm% %"); - if($sth->execute()) + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ); + return $res; + } + } + + function GetPlatformBoxartByID($IDs = 0, $offset = 0, $limit = 20, $filters = 'boxart') + { + $PlatformIDs; + if(is_array($IDs)) + { + if(!empty($IDs)) + { + foreach($IDs as $key => $val) + if(is_numeric($val)) + $PlatformIDsArr[] = $val; + } + $PlatformIDs = implode(",", $PlatformIDsArr); + } + else if(is_numeric($IDs)) + { + $PlatformIDs = $IDs; + } + + if(empty($PlatformIDs)) + { + return array(); + } + + $qry = "Select platforms_id, id, type, filename FROM platforms_images WHERE platforms_id IN ($PlatformIDs) "; + $is_filter = false; + if(is_array($filters)) + { + foreach($filters as $filter) + { + $qry .= $this->CreateBoxartFilterQuery($filter, $is_filter); + } + } + else + { + $qry .= $this->CreateBoxartFilterQuery($filters, $is_filter); + } + + if($is_filter) + { + $qry .=" )"; + } + $qry .= " LIMIT :limit OFFSET :offset;"; + + $dbh = $this->database->dbh; + $sth = $dbh->prepare($qry); + + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); + + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP); + return $res; + } + } + + function GetGamesStats() + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("SELECT type, count from statistics WHERE type != 'boxart' AND type NOT LIKE 'plat%' ORDER BY type"); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_UNIQUE | PDO::FETCH_COLUMN); + { + $ret = $dbh->query("select count(id) from games where overview is not null", PDO::FETCH_COLUMN, 0); + $res['overview'] = $ret->fetch(); + } + return $res; + } + } + + function GetGenres() + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("SELECT id as n, id, genre as name FROM genres"); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP | PDO::FETCH_UNIQUE); + return $res; + } + } + + function GetPubsList() + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("SELECT id as n, id, name FROM pubs_list order by name"); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP| PDO::FETCH_UNIQUE); + return $res; + } + } + + function GetDevsList() + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("SELECT id as n, id, name FROM devs_list order by name"); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP| PDO::FETCH_UNIQUE); + return $res; + } + } + + function GetDevsListByIDs($IDs) + { + $dbh = $this->database->dbh; + $devs_IDs; + if(is_array($IDs)) + { + if(!empty($IDs)) + { + foreach($IDs as $key => $val) + if(is_numeric($val)) + $valid_ids[] = $val; + } + if(!empty($valid_ids)) + { + $devs_IDs = implode(",", $valid_ids); + } + } + else if(is_numeric($IDs)) + { + $devs_IDs = $IDs; + } + if(empty($devs_IDs)) + { + return array(); + } + $sth = $dbh->prepare("SELECT id as n, id, name FROM devs_list where id IN($devs_IDs) order by name"); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP| PDO::FETCH_UNIQUE); + return $res; + } + } + + function GetGamesGenres($games_id, $include_game_id = true) + { + if(!empty($games_id) && is_array($games_id)) + { + foreach($games_id as $key => $val) + { + if(is_numeric($val)) + { + $valid_games_id[] = $val; + } + } + if(!empty($valid_games_id)) + { + $games_id = implode(",", $valid_games_id); + } + } + else if(empty($games_id) || !is_numeric($games_id)) + { + return array(); + } + $dbh = $this->database->dbh; + $qry = "SELECT games_id as n, genres_id"; + if($include_game_id) + { + $qry .= ", games_id"; + } + $qry .= " FROM games_genre where games_id IN($games_id);"; + $sth = $dbh->prepare($qry); + if($sth->execute()) + { + return $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP | PDO::FETCH_COLUMN); + } + } + + function GetGamesDevs($games_id, $include_game_id = true) + { + if(!empty($games_id) && is_array($games_id)) + { + foreach($games_id as $key => $val) + { + if(is_numeric($val)) + { + $valid_games_id[] = $val; + } + } + $games_id = implode(",", $valid_games_id); + } + else if(empty($games_id) || !is_numeric($games_id)) + { + return array(); + } + $dbh = $this->database->dbh; + $qry = "SELECT games_id as n, dev_id"; + if($include_game_id) + { + $qry .= ", games_id"; + } + $qry .= " FROM games_devs where games_id IN($games_id);"; + $sth = $dbh->prepare($qry); + if($sth->execute()) + { + return $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP | PDO::FETCH_COLUMN); + } + } + + function GetGamesPubs($games_id, $include_game_id = true) + { + if(!empty($games_id) && is_array($games_id)) + { + foreach($games_id as $key => $val) + { + if(is_numeric($val)) + { + $valid_games_id[] = $val; + } + } + $games_id = implode(",", $valid_games_id); + } + else if(empty($games_id) || !is_numeric($games_id)) + { + return array(); + } + $dbh = $this->database->dbh; + $qry = "SELECT games_id as n, pub_id"; + if($include_game_id) + { + $qry .= ", games_id"; + } + $qry .= " FROM games_pubs where games_id IN($games_id);"; + $sth = $dbh->prepare($qry); + if($sth->execute()) + { + return $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP | PDO::FETCH_COLUMN); + } + } + + function GetUserEdits($condition = '', $order = '', $offset = 0, $limit = 100) + { + if(empty($condition)) + { + die("Error, empty condition."); + } + $orderby = ""; + if(!empty($order)) + { + $orderby = "order by $order"; + } + $dbh = $this->database->dbh; + $sth = $dbh->prepare("Select id as edit_id, games_id as game_id, timestamp, type, value FROM user_edits + WHERE $condition $orderby LIMIT :limit OFFSET :offset"); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ); + foreach($res as $edit) + { + if($edit->type == 'genres' || $edit->type == 'developers' || $edit->type == 'publishers') + { + $edit->value = json_decode($edit->value); + } + } + return $res; + } + } + + function GetGamesAlts($games_id, $include_id = true) + { + $dbh = $this->database->dbh; + $Games_IDs; + if(is_array($games_id)) + { + if(!empty($games_id)) + { + foreach($games_id as $key => $val) + if(is_numeric($val)) + $valid_ids[] = $val; + } + $Games_IDs = implode(",", $valid_ids); + } + else if(is_numeric($games_id)) + { + $Games_IDs = $games_id; + } + if(empty($Games_IDs)) + { + return array(); + } + $qry = "SELECT games_id as n, name"; + if($include_id) + { + $qry .= ", id, games_id"; + } + $qry .= " FROM games_alts where games_id IN($Games_IDs);"; + $sth = $dbh->prepare($qry); + if($sth->execute()) + { + return $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP | PDO::FETCH_COLUMN); + return $res; + } + } + + function GetUserEditsByTime($minutes = 1440, $offset = 0, $limit = 100) + { + + return $this->GetUserEdits("timestamp > DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -$minutes MINUTE)", "id DESC", $offset, $limit); + + + $dbh = $this->database->dbh; + $sth = $dbh->prepare("Select id as edit_id, games_id as game_id, timestamp, type, value FROM user_edits + WHERE timestamp > DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -:minutes MINUTE) order by id LIMIT :limit OFFSET :offset"); + $sth->bindValue(':minutes', $minutes, PDO::PARAM_INT); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + if($sth->execute()) + { + return $sth->fetchAll(PDO::FETCH_OBJ); + } + } + + function GetUserEditsByID($id, $offset = 0, $limit = 100) + { + return $this->GetUserEdits("id > $id", "", $offset, $limit); + + $dbh = $this->database->dbh; + $sth = $dbh->prepare("Select id as edit_id, games_id as game_id, timestamp, type, value FROM user_edits + WHERE id > :id LIMIT :limit OFFSET :offset"); + $sth->bindValue(':id', $id, PDO::PARAM_INT); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + if($sth->execute()) + { + return $sth->fetchAll(PDO::FETCH_OBJ); + } + } + + function GetPubsListByIDs($IDs) + { + $dbh = $this->database->dbh; + $devs_IDs; + if(is_array($IDs)) + { + if(!empty($IDs)) + { + foreach($IDs as $key => $val) + if(is_numeric($val)) + $valid_ids[] = $val; + } + if(!empty($valid_ids)) + { + $devs_IDs = implode(",", $valid_ids); + } + } + else if(is_numeric($IDs)) + { + $devs_IDs = $IDs; + } + if(empty($devs_IDs)) + { + return array(); + } + $sth = $dbh->prepare("SELECT id as n, id, name FROM pubs_list where id IN($devs_IDs) order by name"); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP| PDO::FETCH_UNIQUE); + return $res; + } + } + + function GetESRBrating() + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("SELECT id as n, id, name FROM ESRB_rating"); + if($sth->execute()) + { + return $sth->fetchAll(PDO::FETCH_OBJ | PDO::FETCH_GROUP | PDO::FETCH_UNIQUE); + } + } + + //TO SLOW, so instead create a DB that I'd update periodically cron job + function UpdateStats() + { + $dbh = $this->database->dbh; + + $Total = array(); + $sth = $dbh->prepare("SELECT DISTINCT type from banners"); + if($sth->execute()) + { + $types = $sth->fetchAll(PDO::FETCH_COLUMN); + foreach($types as $type) + { + $sth = $dbh->prepare("SELECT 1 as total FROM `banners` where type = :type and games_id IN (select id from games) GROUP BY games_id"); + $sth->bindValue(':type', $type, PDO::PARAM_STR); + if($sth->execute()) + { + $Total[$type] = $sth->rowCount(); + } + } + $Total['boxart'] = array(); + $sth = $dbh->prepare("SELECT 1 as total FROM `banners` where type = 'boxart' and side = 'front' and games_id IN (select id from games) GROUP BY games_id"); + if($sth->execute()) + { + $Total['boxart']['front'] = $sth->rowCount(); + } + $sth = $dbh->prepare("SELECT 1 as total FROM `banners` where type = 'boxart' and side = 'back' and games_id IN (select id from games) GROUP BY games_id"); + if($sth->execute()) + { + $Total['boxart']['back'] = $sth->rowCount(); + } + + foreach($Total as $index => $val) + { + if(!is_array($val)) + { + $sth = $dbh->prepare("UPDATE statistics SET count = :count WHERE type = :type"); + $sth->bindValue(':type', $index, PDO::PARAM_STR); + $sth->bindValue(':count', $val, PDO::PARAM_STR); + $sth->execute(); + } + else + { + foreach($val as $key => $val2) + { + $sth = $dbh->prepare("UPDATE statistics SET count = :count WHERE type = :type"); + $sth->bindValue(':type', "$index-$key", PDO::PARAM_STR); + $sth->bindValue(':count', $val2, PDO::PARAM_STR); + $sth->execute(); + } + } + } + $dbh->query("update statistics set count = (select count(id) from games) where type = 'total';"); + } + } + + function is_valid_platform_col($name) + { + if(empty($this->PlatformsTblCols)) + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("DESCRIBE platforms"); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_COLUMN); + foreach($res as $index => $val) + { + $this->PlatformsTblCols[$val] = true; + } + } + } + return isset($this->PlatformsTblCols[$name]); + } + + function is_valid_games_col($name) + { + if(empty($this->GamesTblCols)) + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("DESCRIBE games"); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_COLUMN); + foreach($res as $index => $val) + { + $this->GamesTblCols[$val] = true; + } + } + } + return isset($this->GamesTblCols[$name]); + } + + /* Everything belowis not planned to be exposed through external API */ + + function InsertUserGameBookmark($users_id, $games_id, $is_booked) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("INSERT INTO `user_games` (users_id, games_id, is_booked) + VALUES (:users_id, :games_id, :is_booked) + ON DUPLICATE KEY UPDATE is_booked = :is_booked2"); + $sth->bindValue(':games_id', $games_id); + $sth->bindValue(':users_id', $users_id); + $sth->bindValue(':is_booked', $is_booked); + $sth->bindValue(':is_booked2', $is_booked); + + return ($sth->execute()); + } + + function GetUserBookmarkedGames($users_id) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("Select G.id, G.game_title, G.release_date FROM `user_games` UG, `games` G where UG.users_id=:users_id AND UG.is_booked=1 AND G.id = UG.games_id ORDER BY UG.added DESC"); + $sth->bindValue(':users_id', $users_id); + + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ); + return $res; + } + } + + function isUserGameBookmarked($users_id, $games_id) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("Select is_booked FROM `user_games` where users_id=:users_id AND games_id=:games_id AND is_booked=1"); + $sth->bindValue(':games_id', $games_id); + $sth->bindValue(':users_id', $users_id); + + if($sth->execute()) + { + $res = $sth->fetch(PDO::FETCH_ASSOC); + return !empty($res) ? 1 : 0; + } + return 0; + } + + function GetGameCount($searchTerm) + { + $dbh = $this->database->dbh; + + $qry = "select count(*) from (select count(id) as count from games where (game_title LIKE :name OR game_title=:name2 OR soundex(game_title) LIKE soundex(:name3) + OR soundex(game_title) LIKE soundex(:name4)) GROUP BY id) search"; + $sth = $dbh->prepare($qry); + $sth->bindValue(':name', "%$searchTerm%"); + $sth->bindValue(':name2', $searchTerm); + $sth->bindValue(':name3', "$searchTerm%"); + $sth->bindValue(':name4', "% %$searchTerm% %"); + if($sth->execute()) + { + return $sth->fetch(PDO::FETCH_COLUMN); + } + return -1; + } + + function InsertUserEdits($user_id, $game_id, $type, $value, $subtype = '') + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("INSERT INTO user_edits (users_id, games_id, type, value) VALUES (:users_id, :games_id, :type, :value);"); + $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(':value', $value, PDO::PARAM_STR); + return $sth->execute(); + } + + function InsertGamesGenre($game_id, $genres_id) + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("INSERT IGNORE INTO games_genre (games_id, genres_id) VALUES (:games_id, :genres_id);"); + $sth->bindValue(':games_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':genres_id', $genres_id, PDO::PARAM_INT); + return $sth->execute(); + } + + function DeleteGamesGenre($game_id, $genres_id) + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("DELETE FROM games_genre WHERE games_id=:games_id AND genres_id=:genres_id"); + $sth->bindValue(':games_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':genres_id', $genres_id, PDO::PARAM_INT); + return $sth->execute(); + } + + function UpdateGamesGenre($user_id, $games_id, $new_ids) + { + $dbh = $this->database->dbh; + $is_changed = false; + + $list = $this->GetGenres(); + + $current_ids = $this->GetGamesGenres($games_id); + if(isset($current_ids[$games_id])) + { + $current_ids = $current_ids[$games_id]; + } + $valid_ids = array(); + + foreach($new_ids as $new_id) + { + if(isset($list[$new_id])) + { + $valid_ids[] = $new_id; + + if(!in_array($new_id, $current_ids)) + { + $res = $this->InsertGamesGenre($games_id, $new_id); + if(!$dbh->inTransaction() && !$res) + { + return false; + } + $is_changed = true; + } + } + } + + foreach($current_ids as $current_id) { - $res = $sth->fetchAll(PDO::FETCH_OBJ); - return $res; + if(isset($list[$new_id]) && !in_array($current_id, $new_ids)) + { + $res = $this->DeleteGamesGenre($games_id, $current_id); + if(!$dbh->inTransaction() && !$res) + { + return false; + } + $is_changed = true; + } } - } - - function GetGamesStats() - { - $dbh = $this->database->dbh; - $sth = $dbh->prepare("SELECT type, count from statistics WHERE type != 'boxart' AND type NOT LIKE 'plat%' ORDER BY type"); - if($sth->execute()) + if($is_changed) { - $res = $sth->fetchAll(PDO::FETCH_UNIQUE | PDO::FETCH_COLUMN); + $valid_ids = array_unique($valid_ids); + if(!empty($valid_ids)) { - $ret = $dbh->query("select count(id) from games where Overview is not null", PDO::FETCH_COLUMN, 0); - $res['overview'] = $ret->fetch(); + $genres_str = implode(",", $valid_ids); + $this->InsertUserEdits($user_id, $games_id, "genres", "[$genres_str]"); } - return $res; } + return true; } - //TO SLOW, so instead create a DB that I'd update periodically cron job - function UpdateStats() + function InsertGamesDev($game_id, $dev_id) { $dbh = $this->database->dbh; + $sth = $dbh->prepare("INSERT IGNORE INTO games_devs (games_id, dev_id) VALUES (:games_id, :dev_id);"); + $sth->bindValue(':games_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':dev_id', $dev_id, PDO::PARAM_INT); + return $sth->execute(); + } - $Total = array(); - $sth = $dbh->prepare("SELECT DISTINCT keytype from banners"); - if($sth->execute()) + function DeleteGamesDev($game_id, $dev_id) + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("DELETE FROM games_devs WHERE games_id=:games_id AND dev_id=:dev_id"); + $sth->bindValue(':games_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':dev_id', $dev_id, PDO::PARAM_INT); + return $sth->execute(); + } + + function UpdateGamesDev($user_id, $games_id, $new_ids) + { + $dbh = $this->database->dbh; + + $is_changed = false; + $list = $this->GetDevsListByIDs($new_ids); + $current_ids = $this->GetGamesDevs($games_id); + if(!empty($current_ids[$games_id])) { - $types = $sth->fetchAll(PDO::FETCH_COLUMN); - foreach($types as $type) + $current_ids = $current_ids[$games_id]; + } + + foreach($new_ids as $new_id) + { + if(isset($list[$new_id])) { - $sth = $dbh->prepare("SELECT 1 as total FROM `banners` where keytype = :type and keyvalue IN (select id from games) GROUP BY keyvalue"); - $sth->bindValue(':type', $type, PDO::PARAM_STR); - if($sth->execute()) + $valid_ids[] = $new_id; + + if(!in_array($new_id, $current_ids)) { - $Total[$type] = $sth->rowCount(); + $res = $this->InsertGamesDev($games_id, $new_id); + if(!$dbh->inTransaction() && !$res) + { + return false; + } + $is_changed = true; } } - $Total['boxart'] = array(); - $sth = $dbh->prepare("SELECT 1 as total FROM `banners` where keytype = 'boxart' and side = 'front' and keyvalue IN (select id from games) GROUP BY keyvalue"); - if($sth->execute()) + } + + foreach($current_ids as $current_id) + { + if(isset($list[$new_id]) && !in_array($current_id, $new_ids)) { - $Total['boxart']['front'] = $sth->rowCount(); + $res = $this->DeleteGamesDev($games_id, $current_id); + if(!$dbh->inTransaction() && !$res) + { + return false; + } + $is_changed = true; } - $sth = $dbh->prepare("SELECT 1 as total FROM `banners` where keytype = 'boxart' and side = 'back' and keyvalue IN (select id from games) GROUP BY keyvalue"); - if($sth->execute()) + } + + if($is_changed) + { + $valid_ids = array_unique($valid_ids); + if(!empty($valid_ids)) { - $Total['boxart']['back'] = $sth->rowCount(); + $ids_str = implode(",", $valid_ids); + $this->InsertUserEdits($user_id, $games_id, "developers", "[$ids_str]"); } + } + return true; + } - foreach($Total as $index => $val) + function InsertGamesPub($game_id, $pub_id) + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("INSERT IGNORE INTO games_pubs (games_id, pub_id) VALUES (:games_id, :pub_id);"); + $sth->bindValue(':games_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':pub_id', $pub_id, PDO::PARAM_INT); + return $sth->execute(); + } + + function DeleteGamesPub($game_id, $pub_id) + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("DELETE FROM games_pubs WHERE games_id=:games_id AND pub_id=:pub_id"); + $sth->bindValue(':games_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':pub_id', $pub_id, PDO::PARAM_INT); + return $sth->execute(); + } + + function UpdateGamesPub($user_id, $games_id, $new_ids) + { + $dbh = $this->database->dbh; + + $is_changed = false; + $list = $this->GetPubsListByIDs($new_ids); + $current_ids = $this->GetGamesPubs($games_id); + if(!empty($current_ids[$games_id])) + { + $current_ids = $current_ids[$games_id]; + } + + foreach($new_ids as $new_id) + { + if(isset($list[$new_id])) { - if(!is_array($val)) - { - $sth = $dbh->prepare("UPDATE statistics SET count = :count WHERE type = :type"); - $sth->bindValue(':type', $index, PDO::PARAM_STR); - $sth->bindValue(':count', $val, PDO::PARAM_STR); - $sth->execute(); - } - else + $valid_ids[] = $new_id; + + if(!in_array($new_id, $current_ids)) { - foreach($val as $key => $val2) + $res = $this->InsertGamesPub($games_id, $new_id); + if(!$dbh->inTransaction() && !$res) { - $sth = $dbh->prepare("UPDATE statistics SET count = :count WHERE type = :type"); - $sth->bindValue(':type', "$index-$key", PDO::PARAM_STR); - $sth->bindValue(':count', $val2, PDO::PARAM_STR); - $sth->execute(); + return false; } + $is_changed = true; } } } - } - function is_valid_platform_col($name) - { - if(empty($this->PlatformsTblCols)) + foreach($current_ids as $current_id) { - $dbh = $this->database->dbh; - $sth = $dbh->prepare("DESCRIBE platforms"); - if($sth->execute()) + if(isset($list[$new_id]) && !in_array($current_id, $new_ids)) { - $res = $sth->fetchAll(PDO::FETCH_COLUMN); - foreach($res as $index => $val) + $res = $this->DeleteGamesPub($games_id, $current_id); + if(!$dbh->inTransaction() && !$res) { - $this->PlatformsTblCols[$val] = true; + return false; } + $is_changed = true; } } - return isset($this->PlatformsTblCols[$name]); - } - function is_valid_games_col($name) - { - if(empty($this->GamesTblCols)) + if($is_changed) { - $dbh = $this->database->dbh; - $sth = $dbh->prepare("DESCRIBE games"); - if($sth->execute()) + $valid_ids = array_unique($valid_ids); + if(!empty($valid_ids)) { - $res = $sth->fetchAll(PDO::FETCH_COLUMN); - foreach($res as $index => $val) - { - $this->GamesTblCols[$val] = true; - } + $ids_str = implode(",", $valid_ids); + $this->InsertUserEdits($user_id, $games_id, "publishers", "[$ids_str]"); } } - 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(); + return true; } - function UpdateGame($user_id, $game_id, $GameTitle, $Overview, $Youtube, $ReleaseDateRevised, $Players, $coop, $Developer, $Publisher) + function UpdateGame($user_id, $game_id, $game_title, $overview, $youtube, $release_date, $players, $coop, $new_developers, $new_publishers, $new_genres, $ratings) { $dbh = $this->database->dbh; { @@ -785,25 +1803,61 @@ function UpdateGame($user_id, $game_id, $GameTitle, $Overview, $Youtube, $Releas } { + if(!empty($new_genres)) + { + $this->UpdateGamesGenre($user_id, $game_id, $new_genres); + } + $rating = ""; + $ratingsList = $this->GetESRBrating(); + { + if(isset($ratingsList[$ratings])) + { + $rating = $ratingsList[$ratings]->name; + } + } + + $valid_devs_id = array(); + $developer = ""; + $devs_list = $this->GetDevsListByIDs($new_developers); + foreach($new_developers as $dev_id) + { + if(isset($devs_list[$dev_id])) + { + $valid_devs_id[] = $devs_list[$dev_id]->name; + } + } + if(!empty($valid_devs_id)) + { + $this->UpdateGamesDev($user_id, $game_id, $new_developers); + $developer = implode(" | ", $valid_devs_id); + } + + $valid_pubs_id = array(); + $pubs_list = $this->GetPubsListByIDs($new_publishers); + foreach($new_publishers as $pub_id) + { + if(isset($pubs_list[$pub_id])) + { + $valid_pubs_id[] = $pubs_list[$pub_id]->name; + } + } + if(!empty($valid_pubs_id)) + { + $this->UpdateGamesPub($user_id, $game_id, $new_publishers); + } + $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 = $dbh->prepare("UPDATE games SET game_title=:game_title, overview=:overview, release_date=:release_date, players=:players, + coop=:coop, youtube=:YouTube, rating=:rating 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(':game_title', htmlspecialchars($game_title), PDO::PARAM_STR); + $sth->bindValue(':overview', htmlspecialchars($overview), PDO::PARAM_STR); + $sth->bindValue(':release_date', $release_date, 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->bindValue(':rating', $rating, PDO::PARAM_STR); $sth->execute(); { @@ -811,18 +1865,7 @@ function UpdateGame($user_id, $game_id, $GameTitle, $Overview, $Youtube, $Releas { 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); - } + $diff = htmlspecialchars($$key); $this->InsertUserEdits($user_id, $game_id, $key, $diff); } } @@ -835,8 +1878,9 @@ function DeleteGameImages($user_id, $game_id, $id, $type) { $dbh = $this->database->dbh; - $sth = $dbh->prepare("DELETE FROM banners WHERE id=:id;"); + $sth = $dbh->prepare("DELETE FROM banners WHERE id=:id and games_id=:games_id;"); $sth->bindValue(':id', $id, PDO::PARAM_INT); + $sth->bindValue(':games_id', $game_id, PDO::PARAM_INT); $res = $sth->execute(); if($dbh->inTransaction() || $res) { @@ -849,7 +1893,7 @@ function DeleteAllGameImages($user_id, $game_id) { $dbh = $this->database->dbh; - $sth = $dbh->prepare("DELETE FROM banners WHERE keyvalue=:game_id;"); + $sth = $dbh->prepare("DELETE FROM banners WHERE games_id=:game_id;"); $sth->bindValue(':game_id', $game_id, PDO::PARAM_INT); $res = $sth->execute(); if($dbh->inTransaction() || $res) @@ -873,10 +1917,10 @@ 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 = $dbh->prepare("INSERT INTO banners (games_id, type, side, filename, userid) VALUES (:games_id, :type, :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(':games_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':type', $type, PDO::PARAM_STR); $sth->bindValue(':side', $side, PDO::PARAM_STR); $sth->bindValue(':filename', $filename, PDO::PARAM_STR); $res = $sth->execute(); @@ -887,42 +1931,86 @@ function InsertGameImages($user_id, $game_id, $type, $filename, $side = NULL) } return ($dbh->inTransaction() || $res); } - function DeleteGame($user_id, $game_id) + + function DeleteGame($user_id, $games_id) { + $this->DeleteAllGameImages($user_id, $games_id); + $dbh = $this->database->dbh; - $sth = $dbh->prepare("DELETE FROM games WHERE id=:game_id;"); - $sth->bindValue(':game_id', $game_id, PDO::PARAM_INT); + $dbh->beginTransaction(); + + $sth = $dbh->prepare("DELETE FROM games_pubs WHERE games_id=:games_id;"); + $sth->bindValue(':games_id', $games_id, PDO::PARAM_INT); + $res = $sth->execute(); + + $sth = $dbh->prepare("DELETE FROM games_genre WHERE games_id=:games_id;"); + $sth->bindValue(':games_id', $games_id, PDO::PARAM_INT); + $res = $sth->execute(); + + $sth = $dbh->prepare("DELETE FROM games_devs WHERE games_id=:games_id;"); + $sth->bindValue(':games_id', $games_id, PDO::PARAM_INT); + $res = $sth->execute(); + + $sth = $dbh->prepare("DELETE FROM games WHERE id=:games_id;"); + $sth->bindValue(':games_id', $games_id, PDO::PARAM_INT); $res = $sth->execute(); if($dbh->inTransaction() || $res) { - $this->InsertUserEdits($user_id, $game_id, "game", "[REMOVED]"); + $this->InsertUserEdits($user_id, $games_id, "game", "[REMOVED]"); } - return ($dbh->inTransaction() || $res); + + return $dbh->commit(); } - function InsertGame($user_id, $GameTitle, $Overview, $Youtube, $ReleaseDateRevised, $Players, $coop, $Developer, $Publisher) + function InsertGame($user_id, $game_title, $overview, $youtube, $release_date, $players, $coop, $new_developers, $new_publishers, $platform, $new_genres, $ratings) { $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); + $rating = ""; + $ratingsList = $this->GetESRBrating(); + { + if(isset($ratingsList[$ratings])) + { + $rating = $ratingsList[$ratings]->name; + } + } + + $valid_devs_id = array(); + $developer = ""; + $devs_list = $this->GetDevsList(); + foreach($new_developers as $dev_id) + { + if(isset($devs_list[$dev_id])) + { + $valid_devs_id[] = $devs_list[$dev_id]->name; + } + } + if(!empty($valid_devs_id)) + { + $developer = implode(" | ", $valid_devs_id); + } - // 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); + $valid_pubs_id = array(); + $pubs_list = $this->GetPubsList(); + foreach($new_publishers as $pub_id) + { + if(isset($pubs_list[$pub_id])) + { + $valid_pubs_id[] = $pubs_list[$pub_id]->name; + } + } + $sth = $dbh->prepare("INSERT INTO games(game_title, overview, release_date, players, coop, youtube, platform, rating) + values (:game_title, :overview, :release_date, :players, :coop, :youtube, :platform, :rating)"); + $sth->bindValue(':game_title', htmlspecialchars($game_title), PDO::PARAM_STR); + $sth->bindValue(':overview', htmlspecialchars($overview), PDO::PARAM_STR); + $sth->bindValue(':release_date', $release_date, 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(':platform', $platform, PDO::PARAM_INT); + $sth->bindValue(':rating', $rating, PDO::PARAM_STR); if($sth->execute()) { @@ -930,7 +2018,22 @@ function InsertGame($user_id, $GameTitle, $Overview, $Youtube, $ReleaseDateRevis $dbh->beginTransaction(); $this->InsertUserEdits($user_id, $game_id, 'game', '[NEW]'); - $GameArrayFields = ['GameTitle', 'Overview', 'ReleaseDateRevised', 'Players', 'coop', 'Developer', 'Publisher', 'Youtube']; + if(!empty($new_genres)) + { + $this->UpdateGamesGenre($user_id, $game_id, $new_genres); + } + + if(!empty($new_developers)) + { + $this->UpdateGamesDev($user_id, $game_id, $new_developers); + } + + if(!empty($new_publishers)) + { + $this->UpdateGamesPub($user_id, $game_id, $new_publishers); + } + + $GameArrayFields = ['game_title', 'overview', 'release_date', 'players', 'coop', 'youtube', 'platform', 'rating']; foreach($GameArrayFields as $key) { $diff = htmlspecialchars($$key); @@ -941,6 +2044,85 @@ function InsertGame($user_id, $GameTitle, $Overview, $Youtube, $ReleaseDateRevis } return $game_id; } + + function GetGamesReports($is_resolved, $offset = 0, $limit = 20) + { + $qry = "SELECT games_reports.*, games.game_title, games.platform FROM games_reports left join games on games_reports.games_id = games.id where games_reports.is_resolved = :is_resolved LIMIT :limit OFFSET :offset;"; + + $dbh = $this->database->dbh; + $sth = $dbh->prepare($qry); + $sth->bindValue(':is_resolved', $is_resolved, PDO::PARAM_INT); + $sth->bindValue(':offset', $offset, PDO::PARAM_INT); + $sth->bindValue(':limit', $limit, PDO::PARAM_INT); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ); + return $res; + } + } + + function ReportGame($user_id, $username, $REQUEST) + { + $dbh = $this->database->dbh; + { + $sth = $dbh->prepare("Select * FROM games WHERE id = :game_id"); + $sth->bindValue(':game_id', $REQUEST['game_id'], PDO::PARAM_INT); + + if($sth->execute()) + { + $Game = $sth->fetch(PDO::FETCH_ASSOC); + } + if(!isset($Game) || empty($Game)) + { + return -1; + } + } + if($REQUEST['report_type'] == 1) + { + $sth = $dbh->prepare("Select * FROM games WHERE id = :game_id"); + $sth->bindValue(':game_id', $REQUEST['metadata_0'], PDO::PARAM_INT); + + if($sth->execute()) + { + $Game = $sth->fetch(PDO::FETCH_ASSOC); + } + if(!isset($Game) || empty($Game)) + { + return -2; + } + } + + $qry = "INSERT INTO games_reports (user_id, username, games_id, type, metadata_0, extra, is_resolved) values (:user_id, :username, :games_id, :type, :metadata_0, :extra, 0)"; + + $sth = $dbh->prepare($qry); + + $sth->bindValue(':user_id', $user_id, PDO::PARAM_INT); + $sth->bindValue(':username', $username, PDO::PARAM_STR); + + $sth->bindValue(':games_id', $REQUEST['game_id'], PDO::PARAM_INT); + + $sth->bindValue(':type', $REQUEST['report_type'], PDO::PARAM_INT); + $sth->bindValue(':metadata_0', !empty($REQUEST['metadata_0']) ? $REQUEST['metadata_0'] : null, PDO::PARAM_STR); + $sth->bindValue(':extra', !empty($REQUEST['extra']) ? $REQUEST['extra'] : null, PDO::PARAM_STR); + + return $sth->execute(); + } + + function ResolveGameReport($user_id, $username, $id) + { + $qry = "UPDATE games_reports SET is_resolved = 1, resolver_user_id=:user_id, resolver_username=:username WHERE id=:id;"; + + $dbh = $this->database->dbh; + $sth = $dbh->prepare($qry); + $sth->bindValue(':id', $id, PDO::PARAM_INT); + $sth->bindValue(':user_id', $user_id, PDO::PARAM_INT); + $sth->bindValue(':username', $username, PDO::PARAM_STR); + if($sth->execute()) + { + $res = $sth->fetchAll(PDO::FETCH_OBJ); + return $res; + } + } } ?> diff --git a/website/actions/add_game.php b/website/actions/add_game.php index 16769f3..0188c00 100644 --- a/website/actions/add_game.php +++ b/website/actions/add_game.php @@ -22,20 +22,24 @@ function returnJSONAndDie($code, $msg) } -$GameArrayFields = ['GameTitle', 'Overview', 'ReleaseDateRevised', 'Players', 'coop', 'Developer', 'Publisher', 'Youtube']; +$GameArrayFields = ['game_title', 'overview', 'release_date', 'players', 'coop', 'developers', 'publishers', 'platform', 'youtube', 'genres', 'rating']; 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')) + else if(empty($_REQUEST[$field]) && ($field != 'youtube' && $field != 'overview')) { returnJSONAndDie(-1, "field is empty: ($field)."); } + else if(($field == 'developers' || $field == 'publishers') && (empty($_REQUEST[$field]) || count($_REQUEST[$field]) < 1 || empty($_REQUEST[$field][0]))) + { + //returnJSONAndDie(-2, "$field field is empty, if $field is not listed, please request it on the forum."); + } } -$date = explode('-', $_REQUEST['ReleaseDateRevised']); +$date = explode('-', $_REQUEST['release_date']); if(!checkdate($date[1], $date[2], $date[0])) { returnJSONAndDie(-1, "Invalid Date Format"); @@ -48,8 +52,8 @@ function returnJSONAndDie($code, $msg) { $API = TGDB::getInstance(); - $res = $API->InsertGame($_user->GetUserID(), $_REQUEST['GameTitle'], $_REQUEST['Overview'], $_REQUEST['Youtube'], $_REQUEST['ReleaseDateRevised'], - $_REQUEST['Players'], $_REQUEST['coop'], $_REQUEST['Developer'], $_REQUEST['Publisher']); + $res = $API->InsertGame($_user->GetUserID(), $_REQUEST['game_title'], $_REQUEST['overview'], $_REQUEST['youtube'], $_REQUEST['release_date'], + $_REQUEST['players'], $_REQUEST['coop'], $_REQUEST['developers'], $_REQUEST['publishers'], $_REQUEST['platform'], $_REQUEST['genres'], $_REQUEST['rating']); if($res) { diff --git a/website/actions/add_game_bookmark.php b/website/actions/add_game_bookmark.php new file mode 100644 index 0000000..f44848e --- /dev/null +++ b/website/actions/add_game_bookmark.php @@ -0,0 +1,49 @@ + $code, "msg" => $msg)); + die(); +} + +$_user = phpBBuser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} + +if( + !isset($_REQUEST['games_id']) || !is_numeric($_REQUEST['games_id']) + || !isset($_REQUEST['is_booked']) || !is_numeric($_REQUEST['is_booked']) + ) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR); +} + +require_once __DIR__ . "/../../include/TGDB.API.php"; +try +{ + $API = TGDB::getInstance(); + $list = $API->GetGameByID($_REQUEST['games_id'], 0, 1); + if(empty($Game = array_shift($list))) + { + returnJSONAndDie(-1, ErrorPage::$MSG_REMOVED_GAME_INVALID_PARAM_ERROR); + } + + $is_booked = $_REQUEST['is_booked'] > 0 ? 1 : 0; + $res = $API->InsertUserGameBookmark($_user->GetUserID(), $_REQUEST['games_id'], $is_booked); + if($res) + { + returnJSONAndDie(0, $is_booked); + } +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); + +?> \ No newline at end of file diff --git a/website/actions/delete_art.php b/website/actions/delete_art.php new file mode 100644 index 0000000..bae5674 --- /dev/null +++ b/website/actions/delete_art.php @@ -0,0 +1,72 @@ + $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']) + || !isset($_REQUEST['image_id']) || !is_numeric($_REQUEST['image_id']) + + ) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR); +} + +require_once __DIR__ . "/../../include/TGDB.API.php"; +require_once __DIR__ . "/../include/WebUtils.class.php"; + +try +{ + + $API = TGDB::getInstance(); + $covers = $API->GetGameBoxartByID($_REQUEST['game_id'], 0, 99, $_REQUEST['type']); + + if(!empty($covers) && ($covers = $covers[$_REQUEST['game_id']])) + { + $sizes = ["original", "small", "thumb", "cropped_center_thumb", "cropped_center_thumb_square", "medium", "large"]; + foreach($covers as $cover) + { + if($cover->id == $_REQUEST['image_id']) + { + foreach($sizes as $size) + { + $image_to_delete = __DIR__ . "/../../cdn/images/$size/" . $cover->filename; + if(file_exists($image_to_delete)) + { + unlink($image_to_delete); + } + } + WebUtils::purgeCDNCache($cover->filename); + $res = $API->DeleteGameImages($_user->GetUserID(), $_REQUEST['game_id'], $_REQUEST['image_id'], $cover->type); + if($res) + { + returnJSONAndDie(1, "success!!"); + } + } + } + } + returnJSONAndDie(-1, "Couldnt find image to delete, please refresh page and try again."); +} +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 index 3f06f87..833f847 100644 --- a/website/actions/delete_game.php +++ b/website/actions/delete_game.php @@ -55,7 +55,6 @@ function returnJSONAndDie($code, $msg) } } - $API->DeleteAllGameImages($_user->GetUserID(), $_REQUEST['game_id']); $res = $API->DeleteGame($_user->GetUserID(), $_REQUEST['game_id']); returnJSONAndDie(1, "success!!"); diff --git a/website/actions/edit_game.php b/website/actions/edit_game.php index 7c052d0..7c8dfee 100644 --- a/website/actions/edit_game.php +++ b/website/actions/edit_game.php @@ -21,8 +21,7 @@ function returnJSONAndDie($code, $msg) } } - -$GameArrayFields = ['GameTitle', 'Overview', 'ReleaseDateRevised', 'Players', 'coop', 'Developer', 'Publisher', 'Youtube']; +$GameArrayFields = ['game_title', 'overview', 'release_date', 'players', 'coop', 'developers', 'publishers', 'youtube', 'genres', 'rating']; if(!isset($_REQUEST['game_id']) || !is_numeric($_REQUEST['game_id'])) { returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR); @@ -35,9 +34,17 @@ function returnJSONAndDie($code, $msg) { returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR . ": ($field)."); } + else if(empty($_REQUEST[$field]) && ($field != 'youtube' && $field != 'overview')) + { + returnJSONAndDie(-1, "field is empty: ($field)."); + } + else if(($field == 'developers' || $field == 'publishers') && (empty($_REQUEST[$field]) || count($_REQUEST[$field]) < 1 || empty($_REQUEST[$field][0]))) + { + //returnJSONAndDie(-1, "developers field is empty, if developer is not listed, please request it on the forum."); + } } - $date = explode('-', $_REQUEST['ReleaseDateRevised']); + $date = explode('-', $_REQUEST['release_date']); if(!checkdate($date[1], $date[2], $date[0])) { returnJSONAndDie(-1, "Invalid Date Format"); @@ -50,8 +57,8 @@ function returnJSONAndDie($code, $msg) { $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']); + $res = $API->UpdateGame( $_user->GetUserID(), $_REQUEST['game_id'], $_REQUEST['game_title'], $_REQUEST['overview'], $_REQUEST['youtube'], $_REQUEST['release_date'], + $_REQUEST['players'], $_REQUEST['coop'], $_REQUEST['developers'], $_REQUEST['publishers'], $_REQUEST['genres'], $_REQUEST['rating']); if($res) { diff --git a/website/actions/game_search_count.php b/website/actions/game_search_count.php new file mode 100644 index 0000000..3bcbece --- /dev/null +++ b/website/actions/game_search_count.php @@ -0,0 +1,52 @@ + $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 = ['game_title']; +foreach($GameArrayFields as $field) +{ + if(!isset($_REQUEST[$field]) || empty($_REQUEST[$field])) + { + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR . ": ($field)."); + } +} + +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + $res = $API->GetGameCount($_REQUEST['game_title']); + + if($res > -1) + { + returnJSONAndDie(1, $res); + } + +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); diff --git a/website/actions/report_game.php b/website/actions/report_game.php new file mode 100644 index 0000000..484185c --- /dev/null +++ b/website/actions/report_game.php @@ -0,0 +1,61 @@ + $code, "msg" => $msg)); + die(); +} + +$_user = phpBBuser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} + +$RequiredReportArrayFields = ['game_id', 'report_type', 'metadata_0']; + +foreach($RequiredReportArrayFields as $field) +{ + if(!isset($_REQUEST[$field]) || empty($_REQUEST[$field])) + { + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR . " ($field)"); + } +} + +//TODO: need a better check should we add different types +if($_REQUEST['report_type'] != 1) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_INVALID_PARAM_ERROR . " (report_type)"); +} +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + $res = $API->ReportGame($_user->GetUserID(), $_user->GetUsername(), $_REQUEST); + + switch((integer) $res) + { + case -2: + $msg = "Original game does not exist."; + break; + case -1: + $msg = "Reported game does not exist."; + break; + case 1: + $msg = "Thank You For The Report."; + break; + } + returnJSONAndDie($res, $msg . "($res)"); + +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); + + diff --git a/website/actions/resolve_game_report.php b/website/actions/resolve_game_report.php new file mode 100644 index 0000000..172ee02 --- /dev/null +++ b/website/actions/resolve_game_report.php @@ -0,0 +1,47 @@ + $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['id']) || !is_numeric($_REQUEST['id'])) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR); +} + +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + + + $res = $API->ResolveGameReport($_user->GetUserID(), $_user->GetUsername(), $_REQUEST['id']); + + 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 index be6228f..2d453e6 100644 --- a/website/actions/uploads.php +++ b/website/actions/uploads.php @@ -3,6 +3,7 @@ require_once __DIR__ . "/../include/UploadHandler.fineupload.class.php"; require_once __DIR__ . "/../include/ErrorPage.class.php"; require_once __DIR__ . "/../include/login.phpbb.class.php"; +require_once __DIR__ . "/../include/WebUtils.class.php"; function save_image($original_image, $dest_image, $type) { @@ -75,11 +76,8 @@ function returnJSONAndDie($msg) } returnJSONAndDie("Invalid subtype selection: " . $_REQUEST['subtype']); case 'fanart': - case 'series': + case 'banner': case 'screenshot': - case 'platform-banner': - case 'platform-fanart': - case 'platform-boxart': case 'clearlogo': if(empty($_REQUEST['subtype'])) { @@ -193,7 +191,8 @@ function get_request_method() } if(isset($sql_image_path)) { - $sizes = ["small", "thumb", "cropped_center_thumb", "medium", "large"]; + $sizes = ["small", "thumb", "cropped_center_thumb", "cropped_center_thumb_square", "medium", "large"]; + WebUtils::purgeCDNCache($sql_image_path); if(basename($sql_image_path) != $image_name) { array_push($sizes, 'original'); @@ -206,22 +205,16 @@ function get_request_method() 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; + echo json_encode($result); return; } } } - else - { - $res = $API->InsertGameImages($_user->GetUserID(), $_REQUEST['game_id'], $_REQUEST['type'], - $_REQUEST['type'] . "/" . $_REQUEST['subtype'] . "/" . $image_name, $_REQUEST['subtype']); - } + $res = $API->InsertGameImages($_user->GetUserID(), $_REQUEST['game_id'], $_REQUEST['type'], + $_REQUEST['type'] . "/" . $_REQUEST['subtype'] . "/" . $image_name, $_REQUEST['subtype']); } else { diff --git a/website/add_game.php b/website/add_game.php index f4150b3..db71219 100644 --- a/website/add_game.php +++ b/website/add_game.php @@ -28,17 +28,24 @@ $API = TGDB::getInstance(); $PlatformList = $API->GetPlatformsList(); +$GenreList = $API->GetGenres(); +$ESRBRating = $API->GetESRBRating(); +$devs_list = $API->GetDevsList(); +$pubs_list = $API->GetPubsList(); $Header = new HEADER(); $Header->setTitle("TGDB - Add Game"); -$Header->appendRawHeader(function() { ?> +$Header->appendRawHeader(function() { global $devs_list, $pubs_list; ?> + + + @@ -99,6 +110,7 @@ + @@ -401,32 +512,30 @@ function isJSON(json)
front)) : ?> - + back)): ?> - back)): ?> - + - +

Platform: name; ?>

-

Developer:

-

Publisher:

-

ReleaseDate*:

+

ReleaseDate*:

Players: - - +

@@ -448,14 +557,47 @@ function isJSON(json)
-

+

- +

-

YouTube Trailer:

+

YouTube Trailer:

+
+ + + +
@@ -472,24 +614,24 @@ function isJSON(json)
- + -
- + -
@@ -497,12 +639,24 @@ function isJSON(json)
- + - + +
+ + +
+ + + + + +
@@ -539,7 +693,7 @@ function isJSON(json) data-backdrop="static" data-keyboard="false" data-target="#UploadModal2" class="btn btn-primary margin5px col-4">Upload Fanart - diff --git a/website/game.php b/website/game.php index e5f8007..2d7f3ad 100755 --- a/website/game.php +++ b/website/game.php @@ -11,11 +11,14 @@ require_once __DIR__ . "/include/TGDBUtils.class.php"; require_once __DIR__ . "/../include/TGDB.API.php"; require_once __DIR__ . "/../include/CommonUtils.class.php"; +require_once __DIR__ . "/include/login.phpbb.class.php"; + +$_user = phpBBuser::getInstance(); if(isset($_REQUEST['id']) && !empty($_REQUEST['id']) && is_numeric($_REQUEST['id'])) { - $options = array("Overview" => true, "Players" => true, "Rating" => true, "ESRB" => true, "boxart" => true, "coop" => true, - "Genre" => true, "Publisher" => true, "Platform" => true, "Youtube" => true); + $options = array("overview" => true, "players" => true, "rating" => true, "ESRB" => true, "boxart" => true, "coop" => true, + "genres" => true, "publishers" => true, "platform" => true, "youtube" => true, "alternates" => true); $API = TGDB::getInstance(); $list = $API->GetGameByID($_REQUEST['id'], 0, 1, $options); if(empty($list)) @@ -33,19 +36,27 @@ { $Game->boxart = $covers[$_REQUEST['id']]; } + if($_user->isLoggedIn()) + { + $Game->is_booked = $API->isUserGameBookmarked($_user->GetUserID(), $Game->id); + } } - $Platform = $API->GetPlatforms($Game->Platform, array("icon" => true, "overview" => true, "developer" => true)); - if(isset($Platform[$Game->Platform])) + $Platform = $API->GetPlatforms($Game->platform, array("icon" => true, "overview" => true, "developer" => true)); + if(isset($Platform[$Game->platform])) { - $Platform = $Platform[$Game->Platform]; + $Platform = $Platform[$Game->platform]; } } +$GenresList = $API->GetGenres(); +$DevsList = $API->GetDevsListByIDs($Game->developers); +$PubsList = $API->GetPubsListByIDs($Game->publishers); $fanarts = TGDBUtils::GetAllCovers($Game, 'fanart', ''); $screenshots = TGDBUtils::GetAllCovers($Game, 'screenshot', ''); -$banners = TGDBUtils::GetAllCovers($Game, 'series', ''); -$is_graphics_empty = empty($fanarts) && empty($screenshots) && empty($banners); +$banners = TGDBUtils::GetAllCovers($Game, 'banner', ''); +$clearlogos = TGDBUtils::GetAllCovers($Game, 'clearlogo', ''); +$is_graphics_empty = empty($fanarts) && empty($screenshots) && empty($banners) && empty($clearlogos); $box_cover = new \stdClass(); $box_cover->front = TGDBUtils::GetAllCovers($Game, 'boxart', 'front'); @@ -60,13 +71,13 @@ } $Header = new HEADER(); -$Header->setTitle("TGDB - Browse - Game - $Game->GameTitle"); -$Header->appendRawHeader(function() { global $Game; ?> +$Header->setTitle("TGDB - Browse - Game - $Game->game_title"); +$Header->appendRawHeader(function() { global $Game, $box_cover, $_user; ?> - + " /> - + @@ -84,9 +95,80 @@ { fancyboxOpts.share.descr = function(instance, item) { - return "GameTitle ?>"; + return "game_title ?>"; }; $('[data-fancybox]').fancybox(fancyboxOpts); + + $('#reportbtn').click(function() + { + isLoggedIn()) : ?> + var game_id = parseInt(prompt("Please enter the original game id", "")); + if(isNaN(game_id)) + { + alert('Invalid game id.') + return; + } + $(this).append(''); + $(this).attr("disabled", true); + $.ajax({ + method: "POST", + url: "/actions/report_game.php", + data: { + game_id: id ?>, + report_type:1, + metadata_0: game_id, + } + }) + .done(function( msg ) { + $('#reportbtn').attr("disabled", false); + $('#reportbtn').find('.fa').remove(); + var response = JSON.parse(msg); + alert(msg); + }); + + alert("You must login to use this feature."); + + }); + + $('[data-toggle="bookmark"]').click(function() + { + isLoggedIn()) : ?> + $(this).append(''); + $(this).attr("disabled", true); + $.ajax({ + method: "POST", + url: "/actions/add_game_bookmark.php", + data: { + games_id: id ?>, + is_booked: $('[data-toggle="bookmark"]').data("is-booked"), + } + }) + .done(function( msg ) { + $('[data-toggle="bookmark"]').attr("disabled", false); + $('[data-toggle="bookmark"]').find('.fa').remove(); + var response = JSON.parse(msg); + if (response['code'] == 0 ) + { + if (response['msg'] == 1) + { + $('[data-toggle="bookmark"]')[0].innerHTML='Remove From Collection'; + $('[data-toggle="bookmark"]').removeClass( "btn-secondary" ).addClass( "btn-danger" ); + $('[data-toggle="bookmark"]').data("is-booked", 0); + } + else + { + $('[data-toggle="bookmark"]')[0].innerHTML='Add To Collection'; + $('[data-toggle="bookmark"]').removeClass( "btn-danger" ).addClass( "btn-secondary" ); + $('[data-toggle="bookmark"]').data("is-booked", 1); + } + } else { + alert("Bookmark failed, refresh page and try again."); + } + }); + + alert("You must login to use this feature."); + + }); }); + +print(); ?> + +
+
+
+
+
+ $Dev) : ?> + + +
+
+ Devs + $val_Devlist) : ?> +


+ +
+ + +
+
+
+
+
+ + diff --git a/website/listgames.php b/website/listgames.php index ae9707b..96d91fb 100755 --- a/website/listgames.php +++ b/website/listgames.php @@ -1,6 +1,12 @@ SetHeader(ErrorPage::$HEADER_OOPS_ERROR); @@ -15,23 +21,57 @@ require_once __DIR__ . "/../include/CommonUtils.class.php"; $API = TGDB::getInstance(); -$Platform = $API->GetPlatforms($_REQUEST['platformID'], array("icon" => true, "overview" => true, "developer" => true)); -if(isset($Platform[$_REQUEST['platformID']])) + +$limit = 18; +$page = PaginationUtils::getPage(); +$offset = ($page - 1) * $limit; +if(isset($_REQUEST['dev_id']) && is_numeric($_REQUEST['dev_id'])) +{ + $listed_by = "Developer"; + $list = $API->GetGamesByDevID($_REQUEST['dev_id'], $offset, $limit+1, array(), "game_title"); + $DevInfo = $API->GetDevsListByIDs($_REQUEST['dev_id']); + if(!empty($DevInfo)) + { + $DevInfo = $DevInfo[$_REQUEST['dev_id']]; + } +} +else if(isset($_REQUEST['pub_id']) && is_numeric($_REQUEST['pub_id'])) { - $Platform = $Platform[$_REQUEST['platformID']]; + $listed_by = "Publisher"; + $list = $API->GetGamesByPubID($_REQUEST['pub_id'], $offset, $limit+1, array(), "game_title"); + $DevInfo = $API->GetPubsListByIDs($_REQUEST['pub_id']); + if(!empty($DevInfo)) + { + $DevInfo = $DevInfo[$_REQUEST['pub_id']]; + } +} +else if(isset($_REQUEST['platform_id']) && is_numeric($_REQUEST['platform_id'])) +{ + $listed_by = "Platform"; + $Platform = $API->GetPlatforms($_REQUEST['platform_id'], array("icon" => true, "overview" => true, "developer" => true)); + if(isset($Platform[$_REQUEST['platform_id']])) + { + $Platform = $Platform[$_REQUEST['platform_id']]; + } + else + { + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_INVALID_PARAM_ERROR); + $errorPage->print_die(); + } + $list = $API->GetGameListByPlatform($_REQUEST['platform_id'], $offset, $limit+1, array(), "game_title"); } else { $errorPage = new ErrorPage(); $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); - $errorPage->SetMSG(ErrorPage::$MSG_INVALID_PARAM_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_INVALID_PARAM_ERROR . " (2)"); $errorPage->print_die(); } -$limit = 18; -$page = PaginationUtils::getPage(); -$offset = ($page - 1) * $limit; -$list = $API->GetGameListByPlatform($_REQUEST['platformID'], $offset, $limit+1, array(), "GameTitle"); + + if($has_next_page = count($list) > $limit) { unset($list[$limit]); @@ -52,12 +92,12 @@ } } $Header = new HEADER(); -$Header->setTitle("TGDB - Browser - Game By Platform"); +$Header->setTitle("TGDB - Browser - Game By $listed_by"); ?> print(); ?>
- +
@@ -71,6 +111,20 @@
+ +
+
+
+
+ name ?> +
+
+ s overview have not been added yet. +
+
+
+
+
@@ -82,8 +136,8 @@
diff --git a/website/listplatforms.php b/website/listplatforms.php index 8eeb47f..39bdf05 100755 --- a/website/listplatforms.php +++ b/website/listplatforms.php @@ -1,10 +1,25 @@ GetPlatformsList(array("icon" => true)); + +$PlatformIDs = array(); +foreach($PlatformList as &$platform) +{ + $PlatformIDs[] = $platform->id; +} +$icons = $API->GetPlatformBoxartByID($PlatformIDs, 0, 99999, ['icon']); +foreach($PlatformList as &$platform) +{ + if(isset($icons[$platform->id])) + { + $platform->boxart = &$icons[$platform->id]; + } +} $Header = new HEADER(); $Header->setTitle("TGDB - Browse - Platforms"); $Header->appendRawHeader(function() @@ -57,7 +72,7 @@
- +

name ?>

diff --git a/website/listpubs.php b/website/listpubs.php new file mode 100644 index 0000000..34333af --- /dev/null +++ b/website/listpubs.php @@ -0,0 +1,95 @@ +GetPubsList(); + + + +$alpha_list = array(); +foreach($PubsList as $pub) +{ + $alpha_list[strtoupper($pub->name[0])][] = $pub; +} + + +$Header = new HEADER(); +$Header->setTitle("TGDB - Browse - Publishers"); +$Header->appendRawHeader(function() +{ ?> + + +print(); ?> + +
+
+
+
+
+ $pub) : ?> + + +
+
+ Pubs + $val_publist) : ?> +


+ +
+ + +
+
+
+
+
+ + diff --git a/website/missing.php b/website/missing.php new file mode 100644 index 0000000..43173b6 --- /dev/null +++ b/website/missing.php @@ -0,0 +1,108 @@ +SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_MISSING_PARAM_ERROR); + $errorPage->print_die(); +} +require_once __DIR__ . "/include/header.footer.class.php"; +require_once __DIR__ . "/include/PaginationUtils.class.php"; +require_once __DIR__ . "/include/TGDBUtils.class.php"; +require_once __DIR__ . "/include/WebUtils.class.php"; +require_once __DIR__ . "/../include/TGDB.API.php"; +require_once __DIR__ . "/../include/CommonUtils.class.php"; + +$API = TGDB::getInstance(); + +$limit = 18; +$page = PaginationUtils::getPage(); +$offset = ($page - 1) * $limit; +if(isset($_REQUEST['type'])) +{ + if($_REQUEST['type'] == 'overview') + { + $list = $API->GetMissingGames($_REQUEST['type'], $offset, $limit+1, ['platform'], "game_title"); + } + else + { + $sub_type = ''; + if(isset($_REQUEST['sub_type'])) + { + $sub_type = $_REQUEST['sub_type']; + } + $list = $API->GetMissingGamesImages($_REQUEST['type'], $sub_type ,$offset, $limit+1, ['platform'], "game_title"); + } + $Platforms = $API->GetPlatforms($PlatformIDs); + +} +else +{ + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_INVALID_PARAM_ERROR); + $errorPage->print_die(); +} + + + +if($has_next_page = count($list) > $limit) +{ + unset($list[$limit]); +} +foreach($list as $Game) +{ + $IDs[] = $Game->id; + $PlatformIDs[] = $Game->platform; +} +if(isset($IDs) && !empty($IDs)) +{ + $Platforms = $API->GetPlatforms($PlatformIDs); + $covers = $API->GetGameBoxartByID($IDs, 0, 40); + foreach($list as $Game) + { + if(isset($covers[$Game->id])) + { + $Game->boxart = $covers[$Game->id]; + } + } +} +$Header = new HEADER(); +$Header->setTitle("TGDB - Browser - Game By $listed_by"); +?> +print(); ?> + +
+
+ + + +
+
+
+

No associated games.

+
+
+
+ +
+ +
+ + \ No newline at end of file diff --git a/website/platform.php b/website/platform.php index 9846797..d84bf69 100755 --- a/website/platform.php +++ b/website/platform.php @@ -38,7 +38,7 @@ $Platform->boxart[] = $fanart[$_REQUEST['id']][0]; $fanart = true; } -$recent = $API->GetGamesByDateByPlatform($_REQUEST['id'], date("d/m/Y"), 0, 6, array('BEFORE' => true), "ReleaseDateRevised", 'DESC'); +$recent = $API->GetGamesByDateByPlatform($_REQUEST['id'], date("d/m/Y"), 0, 6, array('BEFORE' => true), "release_date", 'DESC'); foreach($recent as $Game) { $IDs[] = $Game->id; @@ -107,7 +107,7 @@
PosterIMG
- +
@@ -126,24 +126,22 @@ overview;?>

- Developer)) : ?> -

Developer: - Developer; ?>

- Publisher)) : ?> -

Publisher: - Publisher; ?>

- ReleaseDate)) : ?> -

ReleaseDate: - ReleaseDate ;?>

- PlatformDetails)) : ?> -

Platform: - PlatformDetails->name; ?>

- Players)) : ?> -

Players: - Players; ?>

- coop)) : ?> -

Co-op: - coop; ?>

+ manufacturer)) : ?> +

Manufacturer: manufacturer; ?>

+ developer)) : ?> +

Developer: developer; ?>

+ media)) : ?> +

Media Medium: media ;?>

+ cpu)) : ?> +

CPU: cpu ;?>

+ memory)) : ?> +

Memory: memory ;?>

+ graphics)) : ?> +

Graphics: graphics ;?>

+ sound)) : ?> +

Sound: sound ;?>

+ display)) : ?> +

Display: display ;?>

youtube)) : ?>

Watch Trailer

@@ -191,7 +189,7 @@
@@ -199,7 +197,7 @@
diff --git a/website/report_review.php b/website/report_review.php new file mode 100644 index 0000000..fd87663 --- /dev/null +++ b/website/report_review.php @@ -0,0 +1,266 @@ +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('m_delete_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/WebUtils.class.php"; +require_once __DIR__ . "/../include/TGDB.API.php"; +require_once __DIR__ . "/../include/CommonUtils.class.php"; + +$BASE_URL = CommonUtils::getImagesBaseURL(); + +$API = TGDB::getInstance(); +$reports = $API->GetGamesReports(0); +foreach($reports as $Game) +{ + $IDs[] = $Game->games_id; + if($Game->type == 1) + { + $additional_games_id[] = $Game->metadata_0; + } + $PlatformIDs[] = $Game->platform; +} +if(isset($additional_games_id)) +{ + $additional_games = $API->GetGameByID($additional_games_id); +} +if(isset($IDs)) +{ + $games = $API->GetGameByID($IDs); +} + +foreach($additional_games as $Game) +{ + $IDs[] = $Game->id; + $PlatformIDs[] = $Game->platform; +} +$Platforms = $API->GetPlatforms($PlatformIDs); +$covers = $API->GetGameBoxartByID($IDs, 0, 9999); +foreach($reports as $Game) +{ + if(isset($covers[$Game->games_id])) + { + $Game->boxart = $covers[$Game->games_id]; + } +} + +foreach($additional_games as &$Game) +{ + $ref_additional_games[$Game->id] = $Game; + if(isset($covers[$Game->id])) + { + $Game->boxart = $covers[$Game->id]; + } +} +foreach($games as &$Game) +{ + $ref_games[$Game->id] = $Game; +} + +$Game = null; + +function PrintViews(&$report) +{ + switch($report->type) + { + case 1: + PrintDuplicateView($report); + break; + } +} + +function PrintDuplicateView(&$report) +{ global $ref_additional_games, $ref_games, $Platforms; + if(!isset($ref_additional_games[$report->metadata_0]) || !isset($ref_games[$report->games_id])) + { + //TODO: mark as resolved + return; + } + ?> +
+
+
+ + + +
+
+
+ username ?> reports the following game +
+ game_title . "(games_id: $report->games_id)" ?> +
as a duplicate of
+ metadata_0]->game_title . " (games_id: $report->metadata_0)" ?> +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ + + +
+
+ +
+
+
game_title ?>
+

Platform: platform]->name ?>

+
+
+
+
+
metadata_0]->game_title ?>
+

Platform: metadata_0]->platform]->name ?>

+
+
+
+
+ setTitle("TGDB - Games Reports"); +$Header->appendRawHeader(function() { ?> + + + +print(); ?> + +
+
+ +
+

Reports


+
+ +
+ +
+ + diff --git a/website/search.php b/website/search.php index 77cd1fc..7346eb7 100755 --- a/website/search.php +++ b/website/search.php @@ -10,10 +10,10 @@ $API = TGDB::getInstance(); $PlatformList = $API->GetPlatformsList(array("icon" => true)); -if(isset($_GET['platformID']) && !empty($_GET['platformID']) && !in_array(0, $_GET['platformID'])) +if(isset($_GET['platform_id']) && !empty($_GET['platform_id']) && !in_array(0, $_GET['platform_id'])) { - $platformIDs = $_GET['platformID']; - foreach($_GET['platformID'] as $platform_id) + $platformIDs = $_GET['platform_id']; + foreach($_GET['platform_id'] as $platform_id) { $platformIDs[$platform_id] = true; } @@ -23,13 +23,13 @@ $limit = 18; $page = PaginationUtils::getPage(); $offset = ($page - 1) * $limit; - if(!isset($_GET['platformID']) || !is_array($_GET['platformID']) || in_array(0, $_GET['platformID'])) + if(!isset($_GET['platform_id']) || !is_array($_GET['platform_id']) || in_array(0, $_GET['platform_id'])) { $list = $API->SearchGamesByName($_GET['name'], $offset, $limit + 1); } else { - $list = $API->SearchGamesByNameByPlatformID($_GET['name'], $_GET['platformID'], $offset, $limit + 1); + $list = $API->SearchGamesByNameByPlatformID($_GET['name'], $_GET['platform_id'], $offset, $limit + 1); } $search_term = htmlspecialchars($_GET['name']); if($has_next_page = count($list) > $limit) @@ -75,7 +75,7 @@
- $Platform) :?> @@ -100,8 +100,8 @@
diff --git a/website/stats.php b/website/stats.php index ed8b044..a8e6733 100755 --- a/website/stats.php +++ b/website/stats.php @@ -20,7 +20,7 @@ ); $PsudoGame->boxart = array_merge( $PsudoGame->boxart, - $API->GetLatestGameBoxart(0, $limit, 'series') + $API->GetLatestGameBoxart(0, $limit, 'banner') ); $PsudoGame->boxart = array_merge( $PsudoGame->boxart, @@ -37,7 +37,7 @@ $fanarts = TGDBUtils::GetAllCovers($PsudoGame, 'fanart', ''); $screenshots = TGDBUtils::GetAllCovers($PsudoGame, 'screenshot', ''); -$banners = TGDBUtils::GetAllCovers($PsudoGame, 'series', ''); +$banners = TGDBUtils::GetAllCovers($PsudoGame, 'banner', ''); $clearlogos = TGDBUtils::GetAllCovers($PsudoGame, 'clearlogo', ''); $fboxart = TGDBUtils::GetAllCovers($PsudoGame, 'boxart', 'front'); $bboxart = TGDBUtils::GetAllCovers($PsudoGame, 'boxart', 'back'); @@ -166,55 +166,55 @@
- Latest Front Covers + Latest Front Covers - +
- Latest Back Covers + Latest Back Covers - +
- Latest Fanarts + Latest Fanarts - +
- Latest Screenshots + Latest Screenshots - +
- Latest Banners + Latest Banners - +
- Latest ClearLogos + Latest ClearLogos - +
@@ -232,33 +232,38 @@
+