Last active
December 11, 2015 08:09
-
-
Save psykzz/4571436 to your computer and use it in GitHub Desktop.
EVE Online - Convert location IDs to the Name counterpart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <? | |
| $ids = (isset($_REQUEST['ids']))?$_REQUEST['ids']:false; | |
| if(!$ids || $ids=="") | |
| die('API - LocationID to Name conversion, supply comma seperated list of location IDs returns results as json.'); | |
| $idList = explode(",", $ids); // Create an array to work with. | |
| array_unique($idList); // Remove duplicates | |
| function sortArray(&$val){$val=intval($val);} | |
| array_walk($idList, "sortArray"); | |
| $ids = implode(",", $idList); // Convert back to string list. | |
| $mysqli = new mysqli('localhost', 'user', 'pass', 'dbname'); | |
| if ($mysqli->connect_error) { | |
| die('Connect Error (' . $mysqli->connect_errno . ') ' | |
| . $mysqli->connect_error); | |
| } $SQL = "SELECT * FROM `staStations` WHERE `stationID` IN ({$ids})"; | |
| if ($result = $mysqli->query($SQL)) { | |
| while ($row = $result->fetch_assoc()) { | |
| $return[$row['stationID']] = array( | |
| 'stationID' => $row['stationID'], | |
| 'stationName' => $row['stationName'] | |
| ); unset($idList[array_search($row['stationID'],$idList)]); // Found the station remove from list. | |
| } $result->free(); | |
| } $mysqli->close(); | |
| $cachefile = 'cache/'.basename($_SERVER['REQUEST_URI']); | |
| $cachetime = 24 * 60 * 60; // 24 hours | |
| if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) { | |
| include($cachefile); exit; // Serve from the cache if it is younger than $cachetime | |
| } ob_start(); // start the output buffer | |
| $xml = simplexml_load_file("https://api.eveonline.com/eve/ConquerableStationList.xml.aspx"); | |
| foreach ($xml->result->rowset->row as $row) { | |
| if (in_array($row['stationID'], $idList)) | |
| $return[$row['stationID']] = array( | |
| 'stationID' => $row['stationID'], | |
| 'stationName' => $row['stationName'] | |
| ); | |
| } echo json_encode($return); | |
| file_put_contents($cachefile, ob_get_contents()); | |
| ob_end_flush(); // Send the output to the browser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment