function install_fgdgame($gameid) { global $mysqli; $query = yasDB_select("SELECT * FROM `fgdfeed` WHERE `id` = '{$gameid}'", false); $result = $query->fetch_array(MYSQLI_ASSOC); $categories = array('Action' => 2, 'Adventure' => 3, 'Arcade' => 9, 'Defense' => 10, 'Casino' => 6, 'Driving' => 2, 'Fighting' => 2, 'Gadgets' => 10, 'Multiplayer' => 2, 'Puzzle' => 1, 'Rhythm' => 7, 'RPG' => 3, 'Shooter' => 5, 'Sports' => 4, 'Strategy' => 10, 'Other' => 7); //Other // Download and save game file if ($result['gamefile']) { $g_url = str_replace("..", "", $result['gamefile']); $game_file = basename($g_url); $game_file = "fgd_" . $result['uuid'] . "." . GetFileExtension($result['gamefile']); $game_url = '../swf/' . $game_file; download_file($g_url, $game_url); } else { return false; } // Download and save thumbnail pic if ($result['thumbfile']) { $t_url = str_replace("..", "", $result['thumbfile']); $smallthumb = "fgd_" . $result['uuid'] . "." . GetFileExtension($result['thumbfile']); $thumb = '../img/' . $smallthumb; download_file($t_url, $thumb); } $desc = yasDB_clean($result['description']); // Prep for DB insert $gamename = yasDB_clean($result['title']); $gamefile = yasDB_clean(str_replace("../", "", $game_url)); $gamethumb = yasDB_clean(str_replace("../", "", $thumb)); $tags = yasDB_clean($result['tags']); $height = $result['height']; $width = $result['width']; $c = explode(",", $result['categories']); if ($c[0] == "Other" || $c[0] == "Gadgets" || $c[0] == "Rhythm" || $c[0] == "Arcade") { $category = getCategory(wordsArray($result['title'] . ' ' . $result['description'] . ' ' . $result['tags'])); } else { $category = $categories[$c[0]]; } $query->close(); $query = yasDB_insert("INSERT INTO `games` (`id`, `title`, `description`, `instructions`, `keywords`, `file`, `height`, `width`, `category`, `plays`, `code`, `type`, `source`, `sourceid`, `thumbnail`, `thumbnail_200`, `screen1`, `screen2`, `screen3`, `screen4`) VALUES (NULL, '{$gamename}', '{$desc}', '', '{$tags}', '{$gamefile}', {$height}, {$width}, {$category}, 0, '', 'SWF', 'FGD', {$gameid}, '{$gamethumb}', '', '', '','','')", false); if (!$query) { echo 'Error updating Games database'; return false; } $query = yasDB_update("UPDATE fgdfeed SET installed = 1 WHERE id = {$result['id']}", false); if (!query) { echo 'Error updating fgdfeed database'; return false; } return true; }
function get_fogfeed() { global $mysqli; error_reporting(E_ALL ^ E_NOTICE); @ini_set("max_execution_time", 600); @ini_set("default_socket_timeout", 240); // create array of game tags for duplicate checking $query = yasDB_select("SELECT `uid` FROM `fogfeed`", false); $tags = array(); $i = 0; while ($alltags = $query->fetch_array(MYSQLI_ASSOC)) { $tags[$i] = $alltags['uid']; $i++; } unset($alltags); $query->close(); // This is the FOG feed url. For more info go here: http://www.freegamesforyourwebsite.com/feeds.php $feedUrl = 'http://freegamesforyourwebsite.com/feeds/games/?format=json&category=all&limit=all'; $data = get_content_of_url($feedUrl); $json_data = json_decode($data, true); unset($data); $json_count = count($json_data); foreach ($json_data as $json) { if ($json['title'] == NULL) { break; } if (!in_array($json['id'], $tags)) { // little voodo to extract a category from game text as the feed has no game categories $data = $json['title'] . ' ' . $json['description'] . ' ' . $json['tags']; $category = getCategory(wordsArray($data)); // end category voodoo $title = yasDB_clean($json['title']); $uid = yasDB_clean($json['id']); $game_file = yasDB_clean($json['swf_file']); $game_url = yasDB_clean($json['game_url']); $resolution = explode("x", $json['resolution']); $width = $resolution[0]; $height = $resolution[1]; $description = yasDB_clean($json['description']); $small_thumburl = yasDB_clean($json['small_thumbnail_url']); $medium_thumburl = yasDB_clean($json['med_thumbnail_url']); $large_thumburl = yasDB_clean($json['large_thumbnail_url']); $controls = yasDB_clean(stripslashes($json['controls'])); $created = yasDB_clean($json['created']); $updated = yasDB_clean($json['updated']); $sql = "INSERT INTO fogfeed (`id`, `uid`, `title`, `controls`, `updated`, `game_url`, `description`, `category`, `small_thumbnail_url`, `med_thumbnail_url`, `large_thumbnail_url`, `created`, `swf_file`, `width`, `height`, `installed`) \n\t\t\tVALUES (NULL, {$uid}, '{$title}', '{$controls}', '{$updated}', '{$game_url}', '{$description}', {$category}, '{$small_thumburl}', '{$medium_thumburl}', '{$large_thumburl}', '{$created}', '{$game_file}', {$width}, {$height}, '0')"; $return = yasDB_insert($sql, false); if (!$return) { break; } // if there is a db insert error just keep going. } } unset($json); unset($json_data); return true; }