kyleAI_13

listMaps.api

May 15th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.36 KB | None | 0 0
  1. <?php header('Content-type: application/json; charset=utf8'); header("Access-Control-Allow-Origin: *");
  2. require_once "../core.php"; error_reporting(E_ALL & ~E_NOTICE);
  3. $filter = ''; $and = ''; $WHERE .= ""; $LIMIT = ''; $_PAGE[] =''; $ORDER = 'ORDER by `date` DESC'; $oBY = '';
  4. if (isset($_GET['o']) && $_GET['o'] != 'views') {
  5.     $oBY = preg_replace('/[^0-9a-zA-Z_-]/', '', $_GET['o']);
  6.     $ORDER = "ORDER BY `{$oBY}` DESC";
  7. }
  8. if (isset($_GET['gtype']) && !empty($_GET['gtype'])) {
  9.     $filter = preg_replace('/[^ \w0-9a-zA-Z_-]/', '', $_GET['gtype']);
  10.     $WHERE .= " AND `gametype` = '{$filter}'";
  11. }
  12. if (isset($_GET['map']) && !empty($_GET['map'])) {
  13.     $filter = preg_replace('/[^ \w0-9a-zA-Z_-]/', '', $_GET['map']);
  14.     $WHERE .= " AND `map` = '{$filter}'";
  15. }
  16. if (isset($_GET['creator']) && !empty($_GET['creator'])) {
  17.     $filter = preg_replace('/[^ \w0-9a-zA-Z_-]/', '', $_GET['creator']);
  18.     $WHERE .= " AND `creator` = '{$filter}'";
  19. }
  20. if (isset($_GET['uid']) && !empty($_GET['uid'])) {
  21.     $filter = preg_replace('/[^ \w0-9a-zA-Z_-]/', '', $_GET['uid']);
  22.     $WHERE .= " AND `uid` = '{$filter}'";
  23. }
  24. if (isset($_GET['id']) && is_numeric($_GET['id'])) {
  25.     $filter = (int) $_GET['id'];
  26.     $WHERE .= " AND `id` = '{$filter}'";
  27. }
  28. if (isset($_GET['p']) && is_numeric($_GET['p']) && isset($_GET['r']) && is_numeric($_GET['r'])) {
  29.     $p = (int) $_GET['p'] -1;
  30.     $r = (int) $_GET['r'];
  31.     $s = ($p) ?  ($p * $r) : 0;
  32.     $LIMIT = "LIMIT {$s}, {$r}";
  33.     $tcount = $_SQL->query("SELECT uid FROM `maps` WHERE public != 'n' {$WHERE}") or die($_SQL->error);
  34.     $total = $tcount->num_rows;
  35.     $page['totalMaps'] = "$total";
  36.     $page['currentPage'] = "".($p+1)."";
  37.     $begResult = $s + 1;
  38.     $endResult = $s + $r; if ($endResult > $total) { $endResult = $total; }
  39.     $page['results'] = "".$begResult."-".$endResult." out of ".$page['totalMaps'];
  40.     $tc = $_SQL->query("SELECT uid FROM `maps` WHERE public != 'n' {$WHERE} {$LIMIT}") or die($_SQL->error);
  41.     $t = $tc->num_rows;
  42.     $page['mapsOnPage'] = "$t";
  43.     if ($page['mapsOnPage'] > 0 && $page['mapsOnPage'] < $r) {$page['pagesPossible'] = $page['currentPage'];}
  44.     else { $page['pagesPossible'] = "".ceil($total / $r).""; }
  45.     $_PAGE[] = $page;
  46. }
  47. if (!isset($_GET['map']) && !isset($_GET['creator']) && !isset($_GET['uid']) && !isset($_GET['gtype']) && isset($_GET['search']) && preg_match('/^[a-z0-9.\-\_]+$/i', $_GET['search'])) {
  48.     $sql = $_SQL->query("SELECT *, NULL as url FROM `maps` WHERE `title` LIKE '%{$_GET['search']}%' OR `creator` LIKE '%{$_GET['search']}%' OR `map` LIKE '%{$_GET['search']}%' OR `gametype` LIKE '%{$_GET['search']}%' AND (public != 'n' {$WHERE}) {$ORDER} {$LIMIT}") or die($_SQL->error);
  49.     if ($sql->num_rows < 1) { $sql = $_SQL->query("SELECT *, NULL as url FROM `maps` WHERE public != 'n' {$WHERE} {$ORDER} {$LIMIT}") or die($_SQL->error); }
  50. } else { $sql = $_SQL->query("SELECT *, NULL as url FROM `maps` WHERE public != 'n' {$WHERE} {$ORDER} {$LIMIT}") or die($_SQL->error); }
  51. if (isset ($_GET['o']) && $_GET['o'] == 'views') {
  52.     $sql = $_SQL->query("SELECT m.*, COUNT(v.id) AS views FROM maps AS m LEFT JOIN views AS v ON v.map_id=m.id WHERE public != 'n' {$WHERE} GROUP BY m.id ORDER BY views DESC {$LIMIT}") or die($_SQL->error);
  53. }
  54. while ($forge = $sql->fetch_assoc()) {
  55.     $submitter = $_SQL->query("SELECT uname FROM users WHERE id = '{$forge['uid']}'");
  56.     $sub = $submitter->fetch_assoc(); $forge['submitter'] = $sub['uname'];
  57.     $forge['url'] = "//halovau.lt/forge.php?id=".$forge['id'].""; $forgeIMG = $forge['img'];
  58.     $map = preg_replace('/[^ \w0-9a-zA-Z_-]/', '', $forge['map']);
  59.     $forgeIMG = $forge['img']; if (empty($forge['img'])) { $forgeIMG = "/css/images/".preg_replace('/\s+/', '', $map).".jpg"; }
  60.     $forgeIMG0 = str_replace('/css/', '//halovau.lt/css/', $forgeIMG);
  61.     $forgeIMG2 = str_replace('http://halovau.lt//halovau.lt/css/', '//halovau.lt/css/', $forgeIMG0);
  62.     if ($forge['img'] != Thumb($forge['img'])) { $forge['thumbnail'] = Thumb($forge['img']); }
  63.     $forge['img'] = str_replace(' ', '', $forgeIMG2);
  64.     $forgeCleanInf0 = removeBB($forge['info']);
  65.     $forgeCleanInfo = str_replace('Posted on HaloShare', '', str_ireplace(':controller:', '🎮', $forgeCleanInf0));
  66.     $forge['cleanInfo'] = preg_replace('/:[\s\S]+?:/', '', $forgeCleanInfo);
  67.  
  68.     $fmmcount = $_SQL->query("SELECT `id` FROM `downloads` WHERE `map_id`='{$forge['id']}' AND `user`='4'") or die($_SQL->error);
  69.     $forge['FMMdownloads'] = $fmmcount->num_rows;
  70.     if (isset($_GET['id'])) { $forge['info'] = bb_parse(htmlentities($forge['info'])); }
  71.     if ($forge['map'] == 'diamondback') {
  72.         $forgeQuote = "Hot winds blow over what should be a dead moon. A reminder of the power Forerunners once wielded."; }
  73.     if ($forge['map'] == 'edge') {
  74.         $forgeQuote = "The remote frontier world of Partition has provided this ancient databank with the safety of seclusion."; }
  75.     if ($forge['map'] == 'guardian') {
  76.         $forgeQuote = "Millennia of tending has produced trees as ancient as the Forerunner structures they have grown around."; }
  77.     if ($forge['map'] == 'icebox') {
  78.         $forgeQuote = "Downtown Tyumen's Precinct 13 offers an ideal context for urban combat training."; }
  79.     if ($forge['map'] == 'narrows') {
  80.         $forgeQuote = "Without cooling systems such as these, excess heat from the Ark's forges would render the construct uninhabitable."; }
  81.     if ($forge['map'] == 'reactor') {
  82.         $forgeQuote = "Being constructed just prior to the Invasion, its builders had to evacuate before it was completed."; }
  83.     if ($forge['map'] == 'standoff') {
  84.         $forgeQuote = "Once, nearby telescopes listened for a message from the stars. Now, these silos contain our prepared response."; }
  85.     if ($forge['map'] == 'the pit') {
  86.         $forgeQuote = "Software simulations are held in contempt by the veteran instructors who run these training facilities."; }
  87.     if ($forge['map'] == 'valhalla') {
  88.         $forgeQuote = "The crew of V-398 barely survived their unplanned landing in this gorge, but they know they are not alone."; }
  89.     if ($forge['map'] == 'last resort') {
  90.         $forgeQuote = "Remote industrial sites like this one are routinely requisitioned & used as part of Spartan training exercises."; }
  91.     if ($forge['map'] == 'high ground') {
  92.         $forgeQuote = "A relic of older conflicts, this base was reactivated after the New Mombasa Slipspace Event."; }
  93.     if ($forge['map'] == 'sandtrap') {
  94.         $forgeQuote = "Although the Brute occupiers have been driven from this ancient structure, they left plenty to remember them by."; }
  95.     if ($forge['map'] == 'flatgrass') {
  96.         $forgeQuote = "Modders offering a plain flat map with an extended pallet of items ideal for Forge."; }
  97.     $forge['tdr'] = $forgeQuote;
  98.     $forge['gametype'] = ucwords($forge['gametype']); $isDrive = false;
  99.     $forge['variantName'] = strtok($forge['title'], ':');
  100.     if ($forge['variantName'] == $forge['title']) { $forge['variantName'] = ''; }
  101.     $forge['map'] = ucwords($map);
  102.     $forgeV = $_SQL->query("SELECT * FROM views WHERE map_id = '".$forge['id']."'");
  103.     $forge['views'] = "$forgeV->num_rows";
  104.     $toRemove = substr($forge['title'], 0, strpos($forge['title'], ":")).': ';
  105.     $forge['title'] = str_replace($toRemove, '', $forge['title']);
  106.     if ((isset($_USER['name']) && !empty($forge['directURL'])) && ($forge['public'] != 'r' || $_USER['group'] > 2)) {
  107.         $dURL = "http://dewsha.re/share.php?map={$forge['id']}&key={$_GET['key']}";
  108.     } else { $dURL = ''; }
  109.     $forge['directURL'] = str_ireplace('//sandbox.map', '/sandbox.map', $dURL);
  110.     $urls = [];
  111.     if (preg_match_all('/https?:\/\/drive.google.com.*?(id\=|folders\/|d\/)([0-9A-Za-z-_]+)/si', $forge['info'], $matches)) {
  112.         foreach(array_unique($matches[2]) as $match)
  113.             $urls[] = "https://drive.google.com/uc?export=download&id=" .$match;  
  114.     }
  115.     if (preg_match_all('/https?:\/\/mega.nz\/#!([0-9A-Za-z-_]+)/si', $forge['info'], $_matches)) {
  116.         foreach(array_unique($_matches[1]) as $_match)
  117.             $urls[] = "https://mega.nz/#!" .$_match;  
  118.     }
  119.     $forge['variantURLs'] = $urls;
  120.     $_FORGE[] = $forge;
  121. }
  122. $pageJson1 = json_encode($_PAGE, JSON_PRETTY_PRINT);
  123. $pageJsonX = str_replace('"",', '
  124. "PAGE_RESULTS":', $pageJson1);
  125. $pageJson2 = str_replace('[
  126. ', '{
  127. ', $pageJsonX);
  128. $pageJson = str_replace(']', ',', $pageJson2);
  129. $mapsJson1 = json_encode($_FORGE, JSON_PRETTY_PRINT);
  130. $mapsJsonX = str_replace("\\/", "/", $mapsJson1);
  131. $mapsJson = str_replace('tdr', 'mapQuote', $mapsJsonX);
  132. if (isset($_GET['p']) AND is_numeric($_GET['p']) OR $_FORGE['mapsOnPage'] > 0) {
  133.     print_r("".$pageJson."
  134.  
  135. \"MAP_RESULTS\":
  136. ".$mapsJson."
  137. }");
  138. } else { print_r(rtrim($mapsJson)); }
  139. ?>
Advertisement
Add Comment
Please, Sign In to add comment