Mercurial > hg > batmud > maputils
diff www/loc.php @ 300:edac314ac9bb
Added in the ugly PHP-glue used in http://tnsp.org/maps/
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 19 Jun 2007 14:49:15 +0000 |
parents | |
children | 134dded5369b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/loc.php Tue Jun 19 14:49:15 2007 +0000 @@ -0,0 +1,273 @@ +<? +require "config.inc.php"; + +function readLocations($filename, &$locTable, $showPCities = FALSE) +{ + $inFile = @fopen($filename.".loc", "r"); + if (!$inFile) { + return FALSE; + } + + while (!feof($inFile)) { + $inLine = rtrim(fgets($inFile)); + + if (strlen($inLine) == 0 || $inLine[0] == "#") { + } else + if (preg_match("/^([0-9]+)[ \t]*;[ \t]*([0-9]+)[ \t]*;[ \t]*([0-9][CcMGSP%\?\-]*)[ \t]*;[ \t]*([^;]+)(;(.+))?$/", $inLine, $m)) { + $addInfo = preg_split("/[ \t]*;[ \t]*/", $m[6]); + + if (strlen($addInfo[0]) > 0) { + $coders = preg_split("/[ \t]*,[ \t]*/", $addInfo[0]); + } else { + $coders = array(); + } + + if (!strstr($m[3], "-")) { + + if (strstr($m[3], "C")) + $isPCity = TRUE; + else + $isPCity = FALSE; + + if (($showPCities && $isPCity) || (!$showPCities && !$isPCity)) { + $s = ""; + if (strstr($m[3], "S")) $s = "SHRINE "; + else if (strstr($m[3], "G")) $s = "GUILD "; + else if (strstr($m[3], "P")) $s = "SS "; + else if (strstr($m[3], "M")) $s = "MONSTER "; + else if (strstr($m[3], "c")) $s = "CITY "; + + $s .= $m[4]; + + $locTable[$s] = array( + "name" => $s, + "continent" => $filename, + "x" => $m[1], + "y" => $m[2], + "flags" => $m[3], + "coders" => $coders, + "url" => $addInfo[1], + "freeform" => $addInfo[2] + ); + } + } + } else { + echo "Error: <b>$inLine</b><br>\n"; + //return FALSE; + } + } + + fclose($inFile); + return TRUE; +} + + +echo "<?xml version=\"1.0\" encoding=\"".$pageCharset."\"?>\n"; +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=<? echo $pageCharset ?>" /> + <meta name="Author" content="Matti Hämäläinen aka Ggr Pupunen" /> + <title><? echo $pageTitle ?></title> + <link href="<? echo $pageCSS ?>" rel="stylesheet" type="text/css" /> +</head> + +<body> +<? +$locTable = array(); + +$onlyPCities = isset($_GET["c"]); +$showCoders = !isset($_GET["s"]); + +if (isset($_GET["a"])) { + $coderName = basename($_GET["a"]); +} + +if (isset($_GET["n"])) { + $setName = basename($_GET["n"]); + if (isset($continentList[$setName]) && file_exists($setName.".loc")) { + readLocations($setName, $locTable, $onlyPCities); + } else { + echo "<h1>No such continent ID!</h1>"; + unset($setName); + } +} else { + reset($continentList); + while (list($iKey, $iValue) = each($continentList)) { + readLocations($iKey, $locTable, $onlyPCities); + } +} + + +function makeURL($pcities, $coders, $name, $desc, $class) +{ + $s = ""; + if ($pcities) $s = "c"; + + if (!$coders) { + if ($s != "") $s .= "&"; + $s .= "s"; + } + + if (isset($name)) { + if ($s != "") $s .= "&"; + $s .= "n=".$name; + } + + if (isset($class)) + echo " <td class=\"".$class."\">"; + else + echo " <td>"; + + echo "<a href=\"loc.php?".$s."\">".$desc."</a></td>\n"; +} + +/* Header + */ +echo "<h1>"; +if ($onlyPCities) + echo "Player cities"; +else + echo "Locations"; +echo " of "; +if (isset($continentList[$setName])) + echo $continentList[$setName]." continent in "; +echo "BatMUD"; +if (isset($coderName)) + echo " by ".$coderName; +echo "</h1>\n"; + +echo "<table>\n <tr>\n"; + +echo " <td><a href=\"loc.php\">EVERYTHING</a></td>\n"; + +if (!$onlyPCities) { + makeURL(TRUE, $showCoders, $setName, "PCities"); + + if (!$showCoders) + makeURL($onlyPCities, TRUE, $setName, "Show Coders"); + else + makeURL($onlyPCities, FALSE, $setName, "Hide Coders"); +} else { + makeURL(FALSE, $showCoders, $setName, "Locations"); + + if (!$showCoders) + makeURL($onlyPCities, TRUE, $setName, "Show SS"); + else + makeURL($onlyPCities, FALSE, $setName, "Hide SS"); +} + + +echo " <td></td>\n"; + +reset($continentList); +while (list($iKey, $iValue) = each($continentList)) { + makeURL($onlyPCities, $showCoders, $iKey, $iValue, $iKey); +} +?> + </tr> +</table> +<p> +[<a href="index.php">Back to main map page</a>] +</p> +<? +/* +if (isset($coderName)) { + echo "<a href=\"http://www.bat.org/help/finger.php?str=".$coderName."\"> +} + +if (isset($coderName)) { + $coderList = array( + "Kyo" => "http://www.bat.org/albums/album47/aav.jpg", + "" => ""," + ); + if (isset($coderList[$coderName])) { + echo "<img src=\"".$coderList[$coderName]."\" /><br />\n"; + } +} +*/ + +/* Print list of locations + */ +if (count($locTable) > 0) { + + /* Make alphabetical table of locations + */ + while (list($key, $value) = each($locTable)) { + if (isset($coderName)) { + if (array_search($coderName, $value["coders"]) !== FALSE) { + $alphaTable[$key[0]][] = $value; + } + } else { + $alphaTable[$key[0]][] = $value; + } + } + + ksort($alphaTable, SORT_STRING); + + + /* Print locations per first character + */ + $totalLoc = 0; + $maxRow = 6; + while (list($key, $value) = each($alphaTable)) { + if (count($value) > 0) { + asort($value); + echo "<a name=\"".strtolower($key)."\"></a><h3>".$key."</h3>\n"; + echo "<table width=\"95%\">\n"; + $n = 0; + while (list($ik, $iv) = each($value)) { + if ($n == 0) { + echo " <tr>\n"; + } + + $totalLoc++; + + printf(" <td width=\"%d%%\" class=\"%s\">", + (100 / $maxRow), $iv["continent"]); + + printURL($iv["continent"].".html#loc".$iv["x"]."_".$iv["y"]); + + echo $iv["name"]."</a>"; + + if (count($iv["coders"]) > 0 && $showCoders) { + $fs = ""; + while (list($fKey, $fVal) = each($iv["coders"])) { + if ($fs != "") $fs .= ", "; + if (!$onlyPCities) + $fs .= "<a href=\"loc.php?a=".$fVal."\">".$fVal."</a>"; + else + $fs .= $fVal; + } + echo "<br />[".$fs."]"; + } + + echo "</td>\n"; + + $n++; + if ($n >= $maxRow) { + echo " </tr>\n"; + $n = 0; + } + } + if ($n > 0) { + while ($n++ < $maxRow) + echo " <td></td>\n"; + + echo " </tr>\n"; + } + echo "</table>\n"; + } + } + + echo "<p><b>".$totalLoc."</b> locations.</p>\n"; +} else { + echo "<p><b>No locations known!</b></p>\n"; +} + +// Google Analytics +require "../urchin.inc.php"; +?> +</body> +</html>