function getUnattachedGame(AdminService $ad, CouchService $cs, Request $req, $dir = false, $genre = false, $game = false, $theScenario = false) { $gamesAvail = $ad->getAvailGames($dir, $genre, $game); $plainGenre = rawurldecode($genre); $cs->setDb("games"); $seq = $cs->get("_design/newFilter/_view/getLobbies"); $games = array(); $theGame = false; $siteUrl = url("wargame/unattached-game/"); $editor = false; if ($req->session()->get("editor")) { $editor = true; } $backgroundImage = "Egyptian_Pharaoh_in_a_War-Chariot,_Warrior,_and_Horses._(1884)_-_TIMEA.jpg"; $backgroundAttr = 'By Unknown author [<a href="http://creativecommons.org/licenses/by-sa/2.5">CC BY-SA 2.5</a>], <a href="http://commons.wikimedia.org/wiki/File%3AEgyptian_Pharaoh_in_a_War-Chariot%2C_Warrior%2C_and_Horses._(1884)_-_TIMEA.jpg">via Wikimedia Commons</a>'; if ($genre) { if (preg_match("/18%27th/", urlencode($genre))) { $backgroundImage = "18th_century_gun.jpg"; $backgroundAttr = 'By MKFI (Own work) [Public domain], <a href="http://commons.wikimedia.org/wiki/File%3ASwedish_18th_century_6_pound_cannon_front.JPG">via Wikimedia Commons</a>'; } if (preg_match("/Americas/", $genre)) { $backgroundImage = "Yorktown80.jpg"; $backgroundAttr = 'John Trumbull [Public domain], <a target="_blank" href="https://commons.wikimedia.org/wiki/File%3AYorktown80.JPG">via Wikimedia Commons</a>'; } if (preg_match("/Napoleonic/", $genre)) { $backgroundImage = "Napoleon.jpg"; $backgroundAttr = 'Jacques-Louis David [Public domain], <a href="https://commons.wikimedia.org/wiki/File%3AJacques-Louis_David_-_Napoleon_at_the_St._Bernard_Pass_-_WGA06083.jpg">via Wikimedia Commons</a>'; } if (preg_match("/19%27th/", urlencode($genre))) { if (preg_match("/Europe/", $genre)) { $backgroundImage = "Grande_Armée_-_10th_Regiment_of_Cuirassiers_-_Colonel.jpg"; $backgroundAttr = 'By Carle Vernet (Carle Vernet, La Grande Armée de 1812) [Public domain], <a target="blank" href="https://commons.wikimedia.org/wiki/File%3AGrande_Arm%C3%A9e_-_10th_Regiment_of_Cuirassiers_-_Colonel.jpg">via Wikimedia Commons</a>'; } else { $backgroundImage = "1280px-1864_Johnson_s_Map_of_India_(Hindostan_or_British_India)_-_Geographicus_-_India-j-64.jpg"; $backgroundAttr = 'Alvin Jewett Johnson [Public domain], <a target="blank" href="http://commons.wikimedia.org/wiki/File%3A1864_Johnson's_Map_of_India_(Hindostan_or_British_India)_-_Geographicus_-_India-j-64.jpg">via Wikimedia Commons</a>'; } } if (preg_match("/20'th/", $genre)) { $backgroundImage = "M110_howitzer.jpg"; $backgroundAttr = 'By Greg Goebel [Public domain], <a target="blank" href="http://commons.wikimedia.org/wiki/File%3AM110_8_inch_self_propelled_howitzer_tank_military.jpg">via Wikimedia Commons</a>'; } if (preg_match("/early/", $genre)) { $backgroundImage = "French-Marne-Machinegun.jpg"; $backgroundAttr = 'By Unknown or not provided (U.S. National Archives and Records Administration) [Public domain], <a target="_blank" href="https://commons.wikimedia.org/wiki/File%3AFrench_troopers_under_General_Gouraud%2C_with_their_machine_guns_amongst_the_ruins_of_a_cathedral_near_the_Marne..._-_NARA_-_533679.tif">via Wikimedia Commons</a>'; } } if ($game !== false) { $terrainName = "terrain-" . $game; if ($theScenario) { $terrainName .= ".{$theScenario}"; } try { $terrain = $cs->get($terrainName); } catch (\GuzzleHttp\Exception\BadResponseException $e) { echo $terrainName . " " . $e->getMessage(); } if (!$terrain) { $terrain = $cs->get("terrain-" . $game); } $bigMapUrl = $mapUrl = $terrain->terrain->mapUrl; if (isset($terrain->terrain->smallMapUrl)) { $mapUrl = $terrain->terrain->smallMapUrl; } $theGame = $gamesAvail[0]; $theScenarios = []; foreach ($theGame->value->scenarios as $theScenario => $scenario) { $terrainName = "terrain-" . $game; if ($theScenario) { $terrainName .= ".{$theScenario}"; } try { $terrain = $cs->get($terrainName); } catch (\GuzzleHttp\Exception\BadResponseException $e) { } if (!$terrain) { $terrain = $cs->get("terrain-" . $game); } $thisScenario = $theGame->value->scenarios->{$theScenario}; $thisScenario->sName = $theScenario; $thisScenario->mapUrl = $terrain->terrain->mapUrl; $theGame->value->scenarios->{$theScenario}->mapUrl = $terrain->terrain->mapUrl; $thisScenario->bigMapUrl = $terrain->terrain->mapUrl; if (isset($terrain->terrain->smallMapUrl)) { $thisScenario->mapUrl = $terrain->terrain->smallMapUrl; } $theScenarios[] = $thisScenario; } $customScenarios = $ad->getCustomScenarios($dir, $genre, $game); foreach ($customScenarios as $customScenario) { $terrainName = "terrain-" . $game; $theScenario = $customScenario->scenario; if ($theScenario) { $terrainName .= ".{$theScenario}"; } try { $terrain = $cs->get($terrainName); } catch (\GuzzleHttp\Exception\BadResponseException $e) { } if (!$terrain) { $terrain = $cs->get("terrain-" . $game); } $thisScenario = $customScenario->value; $thisScenario->sName = $theScenario; $thisScenario->mapUrl = $terrain->terrain->mapUrl; // $theGame->value->scenarios->$theScenario->mapUrl = $terrain->terrain->mapUrl; $thisScenario->bigMapUrl = $terrain->terrain->mapUrl; if (isset($terrain->terrain->smallMapUrl)) { $thisScenario->mapUrl = $terrain->terrain->smallMapUrl; } $theScenarios[] = $thisScenario; } // $theGame->value->scenarios = $theScenarios; $gameFeed = strtolower($game); $feed = file_get_contents("http://davidrodal.com/pubs/category/{$gameFeed}/feed"); $theGameMeta = (array) $theGame->value; $theGameMeta['options'] = isset($theGameMeta['options']) ? $theGameMeta['options'] : []; unset($theGameMeta->scenarios); if ($feed !== false) { $xml = new \SimpleXmlElement($feed); foreach ($xml->channel->item as $entry) { if (preg_match("/Historical/", $entry->title)) { $matches = []; preg_match("/p=(\\d+)\$/", $entry->guid, $matches); $editLink = "http://davidrodal.com/pubs/wp-admin/post.php?post=" . $matches[1] . "&action=edit"; $content = $entry->children('http://purl.org/rss/1.0/modules/content/'); $str = $content->encoded; // http://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string-in-php $str = preg_replace('/[[:^print:]]/', '', $str); // should be aA $str = preg_replace("/></", "> <", $str); // $theGame->value->longDesc = $str; // $theGame->value->histEditLink = $editLink; $theGameMeta['longDesc'] = $str; $theGameMeta['histEditLink'] = $editLink; } if (preg_match("/Player/", $entry->title)) { $content = $entry->children('http://purl.org/rss/1.0/modules/content/'); $str = $content->encoded; // http://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string-in-php $str = preg_replace('/[[:^print:]]/', '', $str); // should be aA $matches = []; if (preg_match("/p=(\\d+)\$/", $entry->guid, $matches)) { $editLink = "http://davidrodal.com/pubs/wp-admin/post.php?post=" . $matches[1] . "&action=edit"; // $theGame->value->playerEditLink = "<a target='blank' href='$editLink'>edit</a>"; $theGameMeta['playerEditLink'] = "<a target='blank' href='{$editLink}'>edit</a>"; } $theGameMeta['playerNotes'] = $str; $theGame->value->playerNotes = $str; } } } unset($theGame->value); $theGame = (array) $theGame; $theGameMeta['description'] = ''; return view("wargame/wargame-unattached-game", compact("theScenarios", "editor", "backgroundImage", "backgroundAttr", "bigMapUrl", "mapUrl", "theScenario", "plainGenre", "theGame", "games", "nest", "siteUrl", "theGameMeta")); } else { foreach ($gamesAvail as $gameAvail) { if ($gameAvail->game) { $terrainName = "terrain-" . $gameAvail->game; $terrain = ""; try { $terrain = $cs->get($terrainName); } catch (\GuzzleHttp\Exception\BadResponseException $e) { continue; echo "EXCEPTION {$terrainName} "; } $mapUrl = $terrain->terrain->mapUrl; if (isset($terrain->terrain->smallMapUrl)) { $mapUrl = $terrain->terrain->smallMapUrl; } $gameAvail->maxCol = $terrain->terrain->maxCol; $gameAvail->maxRow = $terrain->terrain->maxRow; $gameAvail->name = $gameAvail->value->name; $gameAvail->mapUrl = $mapUrl; $gameAvail->longDescription = isset($gameAvail->value->longDescription) ? $gameAvail->value->longDescription : ''; $gameAvail->description = isset($gameAvail->value->description) ? $gameAvail->value->description : ''; } $gameAvail->urlGenre = rawurlencode($gameAvail->genre); if (!is_numeric($gameAvail->value)) { $nScenarios = count((array) $gameAvail->value->scenarios); unset($gameAvail->value); $gameAvail->value = $nScenarios; } $games[] = $gameAvail; } $theScenarios = []; $theGameMeta = []; $theGameMeta['description'] = ''; $theGameMeta['name'] = ''; $theGameMeta['histEditLink'] = ''; $theGameMeta['options'] = []; if (count($games) > 0 && !empty($games[0]->game)) { return view("wargame/wargame-unattached-games", compact("theScenarios", "theGameMeta", "editor", "backgroundAttr", "backgroundImage", "theScenario", "plainGenre", "theGame", "games", "nest", "siteUrl")); } return view("wargame/wargame-unattached", compact("theScenarios", "theGameMeta", "editor", "backgroundAttr", "backgroundImage", "theScenario", "plainGenre", "theGame", "games", "nest", "siteUrl")); } // echo "<pre>"; var_dump(compact("mapUrl","theScenario", "plainGenre", "theGame", "games", "nest","siteUrl"));die('did'); }
function getGames(AdminService $ad) { $games = $ad->getAvailGames(true); return view('admin.games', ['games' => $games]); }