Mercurial > hg > batmud > maputils
changeset 1387:2b6b38e94bb2
Various minor code cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 23 Dec 2013 16:49:09 +0200 |
parents | 5cd1c7ef4b31 |
children | f9461dc572be |
files | www/common.inc.php www/index.php www/info.php www/latest.php www/loc.php www/query.php www/quests.php www/ss.php |
diffstat | 8 files changed, 466 insertions(+), 432 deletions(-) [+] |
line wrap: on
line diff
--- a/www/common.inc.php Sat Dec 21 00:20:47 2013 +0200 +++ b/www/common.inc.php Mon Dec 23 16:49:09 2013 +0200 @@ -1,4 +1,6 @@ <? +require "mcommon.inc.php"; + $wizFileList = array( "wizards.txt" ); @@ -25,29 +27,10 @@ function printPageHeader($title, $extra = "") { - global $pageCharset, $pageAuthor, $pageCSS; - -if (!isset($pageCSS)) - $pageCSS = "maps.css"; - - 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="<? echo $pageAuthor ?>" /> - <title><? echo strip_tags($title) ?></title> - <link href="<? echo $pageCSS ?>" rel="stylesheet" type="text/css" /> - <meta name="keywords" content="batmud,map,laenor,lucentium,rothikgen,desolathya,furnachia,mud,mush,mmorpg,mmo,massively,multiplayer,online,network,game,ggr,pupunen"/> - <link rel="shortcut icon" href="/maps/favicon.ico" type="image/x-icon" /> - <? - echo $extra; - require "urchin.inc.php"; - ?> -</head> -<body> -<? + cmPrintPageHeader($title, + " <meta name=\"keywords\" content=\"batmud,map,laenor,lucentium,rothikgen,desolathya,furnachia,mud,mush,mmorpg,mmo,massively,multiplayer,online,network,game,ggr,pupunen\"/>\n". + " <link rel=\"shortcut icon\" href=\"/maps/favicon.ico\" type=\"image/x-icon\" />\n". + $extra, FALSE); } @@ -64,10 +47,19 @@ } -function printURL($url) +function stGetURLLink($url, $name) { global $pageMapURL; - echo "<a href=\"".$pageMapURL.$url."\">"; + return "<a href=\"".$pageMapURL.$url."\">".chentities($name)."</a>"; +} + + +function stGetMapLink($data, $link) +{ + if ($link) + return stGetURLLink($data["continent"].".html#loc".$data["x"]."_".$data["y"], $data["name"]); + else + return "<b>".chentities($data["name"])."</b>"; } @@ -77,22 +69,17 @@ return iconv("ISO-8859-1", $pageCharset, $str); } -function chentities($str) -{ - global $pageCharset; - return htmlentities($str, ENT_COMPAT, $pageCharset); -} - - -function addLocNames(&$list, $input) +function stAddLocNames(&$list, $input) { $list = array(); - foreach ($input as $name) { + foreach ($input as $name) + { $nflags = 0; $npos = 0; - switch (substr($name, 0, 1)) { + switch (substr($name, 0, 1)) + { case "@": $npos++; $nflags |= NAME_ORIG; break; case "!": $npos++; $nflags |= NAME_RECODER; break; case "%": $npos++; $nflags |= NAME_MAINTAINER; break; @@ -107,7 +94,7 @@ } -function parseLocFile($filename, &$locations, $applyFilter, $filter) +function stParseLocFile($filename, &$locations, $applyFilter, $filter) { global $locationTypes; @@ -121,51 +108,61 @@ if (strlen($inLine) == 0 || $inLine[0] == "#") continue; - if (preg_match("/^(\d+)\s*;\s*(\d+)\s*;\s*([0-3][A-Za-z%!\?\-]*)\s*;\s*([^;]+)\s*;(.+)$/", $inLine, $record)) { + if (preg_match("/^(\d+)\s*;\s*(\d+)\s*;\s*([0-3][A-Za-z%!\?\-]*)\s*;\s*([^;]+)\s*;(.+)$/", $inLine, $record)) + { // Split fields of the record $addInfo = preg_split("/\s*;\s*/", $record[5]); // Split coder names - if (strlen($addInfo[0]) > 0) { - addLocNames($coders, preg_split("/\s*,\s*/", $addInfo[0])); - } else + if (strlen($addInfo[0]) > 0) + stAddLocNames($coders, preg_split("/\s*,\s*/", $addInfo[0])); + else $coders = array(); // Get timestamp - if (strlen($addInfo[1]) > 0) { - if (sscanf($addInfo[1], "%02d.%02d.%04d", $aday, $amonth, $ayear) == 3) { + if (strlen($addInfo[1]) > 0) + { + if (sscanf($addInfo[1], "%02d.%02d.%04d", $aday, $amonth, $ayear) == 3) + { if (($added = mktime(0, 0, 0, $amonth, $aday, $ayear)) === FALSE) $added = -1; - } else { - echo "Error: Location <b>".$record[4]."</b> has invalid timestamp '".$addInfo[1]."'"; + } + else + { + stError("Location <b>".$record[4]."</b> has invalid timestamp '".$addInfo[1]."'"); $added = -1; } - } else + } + else $added = -1; // Check flags, completely ignore records with "-" flag - if (!strstr($record[3], "-")) { + if (!strstr($record[3], "-")) + { $flags = $record[3]; // $filterMatch = preg_match("/^[0-3]+[".$filter."]\$/", $flags); // ATTENTION! This regexp is bit hacky, but should work because location // should ONLY have one type flag (city, shrine, etc.) $filterMatch = preg_match("/^[0-9]+[\%\?]*[".$filter."][\%\?]*\$/", $flags); - if (($applyFilter && $filterMatch) || (!$applyFilter && !$filterMatch)) { - + if (($applyFilter && $filterMatch) || (!$applyFilter && !$filterMatch)) + { // Get location names - addLocNames($names, preg_split("/\s*\|\s*/", $record[4])); + stAddLocNames($names, preg_split("/\s*\|\s*/", $record[4])); // Check for duplicate locations $id = $flags.$names[0]["name"]; - if (isset($locations[$id])) { - echo $inLine."<br />Error: Location '<b>".$id."</b>' already defined (".$locations[$id]["continent"]." <=> ".$filename.")<br />\n"; + if (isset($locations[$id])) + { + stError("Location '<b>".$id."</b>' already defined (".$locations[$id]["continent"]." <=> ".$filename.")"); return FALSE; } // Create primary location name - for ($s = "", $found = FALSE, $i = 0; $found === FALSE && $i < strlen($flags); $i++) { - if (array_key_exists($flags[$i], $locationTypes)) { + for ($s = "", $found = FALSE, $i = 0; $found === FALSE && $i < strlen($flags); $i++) + { + if (array_key_exists($flags[$i], $locationTypes)) + { $found = $flags[$i]; if (!$filterMatch && $locationTypes[$found][0]) $s = $locationTypes[$found][1]." "; @@ -185,12 +182,13 @@ "coders" => $coders, "added" => $added, ); - if (strlen($addInfo[2]) > 0) { $locations[$id]["url"] = $addInfo[2]; } - if (strlen($addInfo[3]) > 0) { $locations[$id]["freeform"] = $addInfo[3]; } + if (strlen($addInfo[2]) > 0) $locations[$id]["url"] = $addInfo[2]; + if (strlen($addInfo[3]) > 0) $locations[$id]["freeform"] = $addInfo[3]; } } - } else { - echo "Error: <b>$inLine</b><br>\n"; + } else + { + stError($inLine); //return FALSE; } } @@ -200,74 +198,83 @@ } -function readLocationFiles($applyFilter = FALSE, $filter = "CF") +function stReadLocationFiles($applyFilter = FALSE, $filter = "CF") { global $continentList; $locations = array(); - foreach ($continentList as $id => $data) { - if ($data[7]) { - parseLocFile($id, $locations, $applyFilter, $filter); - } + foreach ($continentList as $id => $data) + { + if ($data[7]) + stParseLocFile($id, $locations, $applyFilter, $filter); } return $locations; } -function submitWizField(&$table, $field, $data) +function stSubmitWizField(&$table, $field, $data) { $s = trim($data); - if (strlen($s) > 0) $table[$field] = $s; + if (strlen($s) > 0) + $table[$field] = $s; } -function submitWizInfo(&$table, $record) +function stSubmitWizInfo(&$table, $record) { $s = trim($record[1]); - if (isset($table[$s])) { - echo "Error: <b>".$s."</b> is already set!<br />\n"; + if (isset($table[$s])) + { + stError("Item ".$s." is already set!"); return FALSE; - } else { + } + else + { $tmp = array("name" => $s, "areas" => 0); - submitWizField($tmp, "homeURL", $record[2]); - submitWizField($tmp, "imageURL", $record[3]); - submitWizField($tmp, "desc", $record[4]); - + stSubmitWizField($tmp, "homeURL", $record[2]); + stSubmitWizField($tmp, "imageURL", $record[3]); + stSubmitWizField($tmp, "desc", $record[4]); + if (count($tmp) > 1) $table[$s] = $tmp; + return TRUE; } } -function parseWizInfoFile($filename, &$table) +function stParseWizInfoFile($filename, &$table) { - $file = @fopen($filename, "r"); - if (!$file) return FALSE; + if (($file = @fopen($filename, "r")) === false) + return FALSE; $contMode = FALSE; - while (!feof($file)) { + while (!feof($file)) + { $line = chsetconv(trim(fgets($file))); + + if (strlen($line) == 0 || $line[0] == "#") + continue; - if ($contMode) { - if (substr($line, -1, 1) == '$') { + if ($contMode) + { + if (substr($line, -1, 1) == '$') + { $record[4] .= " ".substr($line, 0, -1); $contMode = FALSE; - submitWizInfo($table, $record); + stSubmitWizInfo($table, $record); } else $record[4] .= " ".$line; - } else - if (strlen($line) == 0 || $line[0] == "#") { - } else - if (preg_match("/^([A-Z][a-z]+);(http:\/\/[^;]+|bat)?;(http:\/\/[^;]+|bat:\/\/[^;]+|img\/[^;]+)?;([^\$]*)\\\$$/", $line, $record)) { - submitWizInfo($table, $record); - } else - if (preg_match("/^([A-Z][a-z]+);(http:\/\/[^;]+|bat)?;(http:\/\/[^;]+|bat:\/\/[^;]+|img\/[^;]+)?;(.*)$/", $line, $record)) { + } + else + if (preg_match("/^([A-Z][a-z]+);(http:\/\/[^;]+|bat)?;(http:\/\/[^;]+|bat:\/\/[^;]+|img\/[^;]+)?;([^\$]*)\\\$$/", $line, $record)) + stSubmitWizInfo($table, $record); + else + if (preg_match("/^([A-Z][a-z]+);(http:\/\/[^;]+|bat)?;(http:\/\/[^;]+|bat:\/\/[^;]+|img\/[^;]+)?;(.*)$/", $line, $record)) $contMode = TRUE; - } else { - echo "Error: <b>$line</b><br>\n"; - } + else + stError($line); } fclose($file); @@ -275,19 +282,20 @@ } -function readWizInfoFiles() +function stReadWizInfoFiles() { global $wizFileList; $wizInfo = array(); foreach ($wizFileList as $id) - parseWizInfoFile($id, $wizInfo); + stParseWizInfoFile($id, $wizInfo); return $wizInfo; } -function printExtraBoxAlphaList($table) + +function stPrintExtraBoxAlphaList($table) { echo "<div id=\"extrabox\">\n". " <div style=\"font-size: 12pt; padding: 5pt;\">\n"; @@ -301,28 +309,4 @@ "</div>\n"; } - -function fetchPageFromCache() -{ - global $cacheEnabled, $cacheFilename; - if (!$cacheEnabled) return; - - $cacheFilename = "cache/".md5($_SERVER["REQUEST_URI"]); - $cacheCreated = (file_exists($cacheFilename)) ? filemtime($cacheFilename) : 0; - if ((time() - $cacheCreated) < 3600) { - readfile($cacheFilename); - exit; - } else { - ob_start(); - } -} - -function storePageToCache() -{ - global $cacheEnabled, $cacheFilename; - if ($cacheEnabled && isset($cacheFilename)) { - file_put_contents($cacheFilename, ob_get_contents()); - ob_end_flush(); - } -} ?> \ No newline at end of file
--- a/www/index.php Sat Dec 21 00:20:47 2013 +0200 +++ b/www/index.php Mon Dec 23 16:49:09 2013 +0200 @@ -3,37 +3,38 @@ require "world.inc.php"; require "common.inc.php"; + function printFileTD($fileName, $mapName, $useTD = TRUE) { if ($useTD) echo " <td>"; - if (file_exists($fileName)) { + if (file_exists($fileName)) + { $fileStat = stat($fileName); $q = $fileStat[7]; - printURL($fileName); - echo $mapName."</a>, <b>"; + echo stGetURLLink($fileName, $mapName).", <b>"; if ($q < 1024) printf("%d</b> bytes", $q); - else if ($q < (1024*1024)) - printf("%d</b>kB", $q/1024); - else printf("%1.2f</b>MB", $q/(1024.0*1024.0)); + else + if ($q < (1024*1024)) + printf("%d</b>kB", $q / 1024); + else + printf("%1.2f</b>MB", $q / (1024.0*1024.0)); } - if ($useTD) echo "</td>\n"; + if ($useTD) echo "</td>\n"; } + function printTR($n, $fileName, $mapName) { echo " <tr class=\"line".(($n & 1) + 1)."\">\n"; + if (file_exists($fileName.".html")) + echo " <td>".stGetURLLink($fileName.".html", $mapName)."</td>\n\n"; + else + echo " <td>".$mapName."</td>\n"; +} - if (file_exists($fileName.".html")) { - echo " <td>"; - printURL($fileName.".html"); - echo $mapName."</a></td>\n\n"; - } else { - echo " <td>".$mapName."</td>\n"; - } -} function printLine($n, $fileName, $mapName, $noExtra = FALSE) { @@ -63,8 +64,6 @@ echo " </tr>\n"; } -fetchPageFromCache(); - printPageHeader($pageTitle, "<link rel=\"search\" type=\"application/opensearchdescription+xml\" href=\"/maps/opensearch.xml\" title=\"PupuMaps\" />\n"); @@ -73,6 +72,9 @@ <div id="contents"> <h1><? echo $pageTitle; ?></h1> +<div class="advert"> +<a href="https://www.hdd.fi/">hdd.fi - Edullista etƤlevytilaa</a> +</div> <div id="intro"> Maps and information about <a href="http://www.bat.org/">BatMUD realm</a>, including @@ -105,8 +107,10 @@ <? $n = 0; foreach ($continentList as $continent => $data) +{ if (!$data[3]) printLine($n++, $continent, $data[0]); +} ?> </table> @@ -157,7 +161,7 @@ <h1>Ggr's BatMUD con pictures</h1> <? static $conpics = array( - + "Kepucon'13" => "kepucon2013", "Kepucon'12" => "kepucon2012", "Kepucon'11" => "kepucon2011", "Kepucon'10" => "kepucon2010", @@ -165,7 +169,8 @@ "Kepucon'07" => "kepucon2007", "Kuopiocon'04" => "kuopiocon04" ); -foreach ($conpics as $id => $url) { +foreach ($conpics as $id => $url) +{ echo " <a href=\"http://tnsp.org/kuvia/bile/".$url."/\">".$id."</a>\n"; } ?> @@ -173,9 +178,6 @@ <a href="http://tnsp.org/~ccr/ggrtf/">GgrTF</a> <a href="http://tnsp.org/~ccr/bat/">Ggr's Bat page</a> </div> - -</body> -</html> <? -storePageToCache(); +cmPrintPageFooter(); ?> \ No newline at end of file
--- a/www/info.php Sat Dec 21 00:20:47 2013 +0200 +++ b/www/info.php Mon Dec 23 16:49:09 2013 +0200 @@ -38,18 +38,21 @@ <? $locTable = apc_fetch("info_locTable"); -if (empty($locTable)) { - $locTable = readLocationFiles(); +if (empty($locTable)) +{ + $locTable = stReadLocationFiles(); apc_store("info_locTable", $locTable, 3600); } $wizTable = apc_fetch("wizTable"); -if (empty($wizTable)) { - $wizTable = readWizInfoFiles(); +if (empty($wizTable)) +{ + $wizTable = stReadWizInfoFiles(); apc_store("wizTable", $wizTable, 3600); } -if (isset($_GET["a"])) { +if (isset($_GET["a"])) +{ $coderName = basename($_GET["a"]); $coderName = strtoupper(substr($coderName, 0, 1)).strtolower(substr($coderName, 1)); } @@ -74,7 +77,8 @@ } } -if (count($wizTable) > 0) { +if (count($wizTable) > 0) +{ /* Make alphabetically sorted table of wizards */ foreach ($wizTable as $alpha => $data) @@ -87,53 +91,56 @@ */ $totalWiz = 0; $maxRow = 6; - foreach ($alphaTable as $alpha => $data) { - if (count($data) > 0) { - usort($data, "wizardSort"); + foreach ($alphaTable as $alpha => $data) + if (count($data) > 0) + { + usort($data, "wizardSort"); + + $letter = strtoupper($alpha); + echo "<h3><a name=\"".$letter."\"></a>".$letter."</h3>\n"; + echo "<table class=\"loc\">\n"; + $n = 0; + + foreach ($data as $wizard) + { + if ($n == 0) echo " <tr>\n"; - $letter = strtoupper($alpha); - echo "<h3><a name=\"".$letter."\"></a>".$letter."</h3>\n"; - echo "<table class=\"loc\">\n"; - $n = 0; - - foreach ($data as $wizard) { - if ($n == 0) echo " <tr>\n"; - - $totalWiz++; + $totalWiz++; - printf(" <td width=\"%d%%\" style=\"background: %s;\"><a href=\"loc.php?a=%s\">%s</a> <span style=\"color: #f80;\">", - (100 / $maxRow), (count($wizard) > 2 || isset($wizard["desc"])) ? "#474" : "#744", $wizard["name"], $wizard["name"]); + printf(" <td width=\"%d%%\" style=\"background: %s;\"><a href=\"loc.php?a=%s\">%s</a> <span style=\"color: #f80;\">", + (100 / $maxRow), (count($wizard) > 2 || isset($wizard["desc"])) ? "#474" : "#744", $wizard["name"], $wizard["name"]); - if ($wizard["areas"] > 0) - echo " (".$wizard["areas"].")"; + if ($wizard["areas"] > 0) + echo " (".$wizard["areas"].")"; - echo "</span></td>\n"; - - $n++; - if ($n >= $maxRow) { - echo " </tr>\n"; - $n = 0; - } - } - if ($n > 0) { - while ($n++ < $maxRow) - echo " <td></td>\n"; + echo "</span></td>\n"; + $n++; + if ($n >= $maxRow) + { echo " </tr>\n"; - } - echo "</table>\n"; + $n = 0; + } } + + if ($n > 0) + { + while ($n++ < $maxRow) + echo " <td></td>\n"; + echo " </tr>\n"; + } + echo "</table>\n"; } echo "<p><b>".$totalWiz."</b> wizards.</p>\n"; - /* Print out the alpha link index - */ - printExtraBoxAlphaList($alphaTable); -} else { + // Print out the alpha link index + stPrintExtraBoxAlphaList($alphaTable); +} +else +{ echo "<p><b>No wizards known!</b></p>\n"; } -?> -</div> -</body> -</html> + +cmPrintPageFooter(); +?> \ No newline at end of file
--- a/www/latest.php Sat Dec 21 00:20:47 2013 +0200 +++ b/www/latest.php Mon Dec 23 16:49:09 2013 +0200 @@ -3,7 +3,7 @@ require "world.inc.php"; require "common.inc.php"; -$locTable = readLocationFiles(FALSE); +$locTable = stReadLocationFiles(FALSE); /* Page start */ @@ -35,19 +35,25 @@ { if ($a["added"] > $b["added"]) return -1; - else if ($a["added"] == $b["added"]) { + else + if ($a["added"] == $b["added"]) return strcmp($a["name"], $b["name"]); - } else + else return 1; } -if (count($locTable) > 0) { +if (count($locTable) > 0) +{ // Sort locations by timestamp .. - foreach ($locTable as $location) { - if (isset($_GET["nodate"])) { + foreach ($locTable as $location) + { + if (isset($_GET["nodate"])) + { if ($location["added"] < 0) $sortedLocs[] = $location; - } else { + } + else + { if ($location["added"] > 0) $sortedLocs[] = $location; } @@ -58,49 +64,43 @@ // Print the list $totalLoc = 0; echo - "<table class=\"loc\">\n". - " <tr>\n". - " <th>Date</th>\n". - " <th>Location name</th>\n". - " <th>Continent</th>\n". - " <th>Coder(s)</th>\n". - " <th>Information</th>\n". - " </tr>\n"; + "<table class=\"loc\">\n". + " <tr>\n". + " <th>Date</th>\n". + " <th>Location name</th>\n". + " <th>Continent</th>\n". + " <th>Coder(s)</th>\n". + " <th>Information</th>\n". + " </tr>\n"; - foreach ($sortedLocs as $ik => $iv) { - - $totalLoc++; + foreach ($sortedLocs as $ik => $iv) + { + $totalLoc++; - echo - " <tr>\n". - " <td>".strftime("%d %b %Y", $iv["added"])."</td>\n". - " <td class=\"".$iv["continent"]."\">"; - - printURL($iv["continent"].".html#loc".$iv["x"]."_".$iv["y"]); - - echo chentities($iv["name"])."</a></td>\n". - " <td>".$continentList[$iv["continent"]][0]."</td>\n". - " <td>"; - - $fs = ""; - foreach ($iv["coders"] as $name) { - if ($fs != "") $fs .= ", "; - $fs .= "<a href=\"loc.php?a=".chentities($name["name"])."\">".chentities($name["name"])."</a>"; - } - - echo "$fs</td>\n". - " <td>"; - if (isset($iv["freeform"])) - echo chentities($iv["freeform"]); - echo "</td>\n". - " </tr>\n"; + $fs = ""; + foreach ($iv["coders"] as $name) + { + if ($fs != "") $fs .= ", "; + $fs .= "<a href=\"loc.php?a=".chentities($name["name"])."\">".chentities($name["name"])."</a>"; + } + + echo + " <tr>\n". + " <td>".strftime("%d %b %Y", $iv["added"])."</td>\n". + " <td class=\"".$iv["continent"]."\">".stGetMapLink($iv, TRUE)."</td>\n". + " <td>".$continentList[$iv["continent"]][0]."</td>\n". + " <td>".$fs."</td>\n". + " <td>".(isset($iv["freeform"]) ? chentities($iv["freeform"]) : "")."</td>\n". + " </tr>\n"; } - echo "</table>\n". - "<p><b>".$totalLoc."</b> locations.</p>\n"; -} else { + echo + "</table>\n". + "<p><b>".$totalLoc."</b> locations.</p>\n"; +} +else +{ echo "<p><b>No locations known!</b></p>\n"; } -?> -</div> -</body> -</html> + +cmPrintPageFooter(); +?> \ No newline at end of file
--- a/www/loc.php Sat Dec 21 00:20:47 2013 +0200 +++ b/www/loc.php Mon Dec 23 16:49:09 2013 +0200 @@ -40,70 +40,81 @@ /* Initialization */ -if (isset($_GET["c"])) { +if (isset($_GET["c"])) +{ $filter = "C"; $applyFilter = TRUE; -} else { - if (isset($_GET["f"]) && $_GET["f"] != "") { - $filter = $_GET["f"]; - if (!preg_match("/^[\^A-Za-z]+\$/", $filter)) { - $errorStr = "Invalid filter rule '".chentities($filter)."'"; - $filter = "C"; - $applyFilter = FALSE; - } else { - $applyFilter = TRUE; - } - } else { - $filter = "CF"; +} +else +if (($filter = stGetRequestItem("f", "", TRUE)) != "") +{ + if (!preg_match("/^[\^A-Za-z]+\$/", $filter)) + { + stError("Invalid filter rule '".chentities($filter)."'"); + $filter = "C"; $applyFilter = FALSE; } + else + $applyFilter = TRUE; +} +else +{ + $filter = "CF"; + $applyFilter = FALSE; } $showCoders = !isset($_GET["s"]); -if (isset($_GET["a"])) { - if (preg_match("#^([a-z]{1,15})#i", $_GET["a"], $m)) { +if (($tmpName = stGetRequestItem("a", FALSE, TRUE)) !== false) +{ + if (preg_match("#^([a-z]{1,15})#i", $tmpName, $m)) + { $coderName = $m[1]; $coderName = strtoupper(substr($coderName, 0, 1)).strtolower(substr($coderName, 1)); $wizTable = apc_fetch("wizTable"); - if (empty($wizTable)) { - $wizTable = readWizInfoFiles(); + if (empty($wizTable)) + { + $wizTable = stReadWizInfoFiles(); apc_store("wizTable", $wizTable, 3600); } - } else { + } + else + { $coderName = "???"; - $errorStr = "Invalid wizard name."; + stError("Invalid wizard name."); } } -if (isset($_GET["n"])) { +if (isset($_GET["n"])) +{ $locTable = array(); $setName = strtolower(basename($_GET["n"])); - if (file_exists($setName.".loc")) { + if (file_exists($setName.".loc")) + { $locTable = apc_fetch("loc_".$setName); - if (empty($locTable)) { + if (empty($locTable)) + { $locTable = array(); - parseLocFile($setName, $locTable, $applyFilter, $filter); + stParseLocFile($setName, $locTable, $applyFilter, $filter); apc_store("loc_".$setName, $locTable, 3600); } - } else { - $errorStr = "No such continent ID!"; + } + else + { + stError("No such continent ID!"); unset($setName); } } else { $locTable = apc_fetch("loc_locTable"); if (empty($locTable)) { - $locTable = readLocationFiles($applyFilter, $filter); + $locTable = stReadLocationFiles($applyFilter, $filter); apc_store("loc_locTable", $locTable, 3600); } } /* Start of the page */ -if (empty($errorStr)) - fetchPageFromCache(); - printPageHeader($pageTitle." - Locations", "<script type=\"text/javascript\" src=\"tooltip.js\"></script>\n". "<meta name=\"robots\" content=\"nofollow\" />\n"); @@ -111,30 +122,36 @@ require "menu.inc.php"; echo -"<div id=\"contents\">\n". -"<h1>"; + "<div id=\"contents\">\n". + "<h1>"; -if ($applyFilter) { +if ($applyFilter) +{ if (array_key_exists($filter, $locationTypes)) echo $locationTypes[$filter][2]; else echo "Filter '$filter'"; -} else +} +else echo "Locations"; echo " of "; -if (isset($setName) && isset($continentList[$setName])) { +if (isset($setName) && isset($continentList[$setName])) +{ echo $continentList[$setName][0]. - ($continentList[$setName][3] ? " in " : " continent in "); + ($continentList[$setName][3] ? " in " : " continent in "); } echo "BatMUD"; if (isset($coderName)) echo " by ".chentities($coderName); echo "</h1>\n"; -if (isset($errorStr)) - echo "<p style=\"color: red;\"><b>Error: ".$errorStr."</b>.</p>\n"; +if ($errorSet) +{ + echo "<div style=\"color: red;\">Errors: "; + echo "</div>\n"; +} ?> <div class="selbar"> @@ -182,35 +199,43 @@ /* Wizard/coder/creator information box */ -if (isset($coderName)) { - if (isset($wizTable[$coderName]) && count($wizTable[$coderName]) > 1) { +if (isset($coderName)) +{ + if (isset($wizTable[$coderName]) && count($wizTable[$coderName]) > 1) + { // Profile picture - if (qcheck($wizTable[$coderName], "imageURL", &$s)) { + if (qcheck($wizTable[$coderName], "imageURL", &$s)) + { // XXX: backwards compatibility check if (substr($s, 0, 6) == "bat://") $s = "img/unknown.png"; - } else + } + else $s = "img/unknown.png"; - echo "<div class=\"wizinfo\">\n <table>\n <tr>\n". - " <td class=\"img\"><img src=\"".$s."\" alt=\"".$coderName."\" /></td>\n". - " <td class=\"info\">\n". - " <h2>".$coderName."</h2>\n"; + echo + "<div class=\"wizinfo\">\n <table>\n <tr>\n". + " <td class=\"img\"><img src=\"".$s."\" alt=\"".$coderName."\" /></td>\n". + " <td class=\"info\">\n". + " <h2>".$coderName."</h2>\n"; // Description block - if (qcheck($wizTable[$coderName], "desc", &$s)) { - $s = preg_replace("/\~([A-Z][a-z]+)\~/i", "<a href=\"".$_SERVER["PHP_SELF"]."?a=\${1}\">\${1}</a>", $s); + if (qcheck($wizTable[$coderName], "desc", &$str)) + { + // Handle special tags + $str = preg_replace("/\~([A-Z][a-z]+)\~/i", "<a href=\"".$_SERVER["PHP_SELF"]."?a=\${1}\">\${1}</a>", $str); foreach ($specTags as $tag => $rep) - $s = preg_replace("/\[".$tag."\]/i", $rep, $s); + $str = preg_replace("/\[".$tag."\]/i", $rep, $str); - echo " <p>".$s."</p>\n"; + echo " <p>".$str."</p>\n"; } // Links, etc. echo " [<a href=\"".fingerURL($coderName)."\">Finger</a>]\n"; - if (qcheck($wizTable[$coderName], "homeURL", &$s)) { + if (qcheck($wizTable[$coderName], "homeURL", &$s)) + { if ($s == "bat") $s = "http://wiz.bat.org/~".strtolower($coderName)."/"; @@ -218,30 +243,39 @@ } echo " </td>\n </tr>\n </table>\n</div>\n"; - } else - $errorStr = "No such wizard."; + } + else + stError("No such wizard."); } /* Print list of locations */ -if (count($locTable) > 0) { +if (count($locTable) > 0) +{ /* Make alphabetically sorted table of locations */ $alphaTable = array(); foreach ($locTable as $id => $data) - if (isset($data["name"])) { + if (isset($data["name"])) + { $idx = $data["name"][0]; - if (isset($_GET["nocoders"])) { + if (isset($_GET["nocoders"])) + { if (count($data["coders"]) == 0 && !preg_match("/[SPG]/", $data["flags"])) $alphaTable[$idx][] = $data; - } else { - if (isset($coderName)) { - foreach ($data["coders"] as $coder) { + } + else + { + if (isset($coderName)) + { + foreach ($data["coders"] as $coder) + { if ($coderName == $coder["name"]) $alphaTable[$idx][] = $data; } - } else + } + else $alphaTable[$idx][] = $data; } } @@ -253,17 +287,20 @@ $locationTips = array(); $totalLoc = 0; $maxRow = 6; - foreach ($alphaTable as $alpha => $alphaLocs) { + foreach ($alphaTable as $alpha => $alphaLocs) + { if (count($alphaLocs) <= 0) continue; $letter = strtoupper($alpha); asort($alphaLocs); - echo "<h3><a name=\"".$letter."\"></a>".$letter."</h3>\n". - "<table class=\"loc\" width=\"95%\">\n"; + echo + "<h3><a name=\"".$letter."\"></a>".$letter."</h3>\n". + "<table class=\"loc\" width=\"95%\">\n"; $n = 0; - foreach ($alphaLocs as $ik => $iv) { + foreach ($alphaLocs as $ik => $iv) + { if ($n == 0) echo " <tr>\n"; @@ -273,15 +310,11 @@ printf(" <td width=\"%d%%\" class=\"%s\">", (100 / $maxRow), $iv["continent"]); - if (!$continentList[$iv["continent"]][4]) { - echo "<b>".chentities($iv["name"])."</b>"; - } else { - printURL($iv["continent"].".html#loc".$iv["x"]."_".$iv["y"]); - echo chentities($iv["name"])."</a>"; - } + echo stGetMapLink($iv, $continentList[$iv["continent"]][4]); // If either freeform desc or URL field are set, we add those - if (isset($iv["url"]) || isset($iv["freeform"])) { + if (isset($iv["url"]) || isset($iv["freeform"])) + { // Free form description $desc = isset($iv["freeform"]) ? chentities($iv["freeform"]) : ""; @@ -346,13 +379,15 @@ echo "</td>\n"; - if (++$n >= $maxRow) { + if (++$n >= $maxRow) + { echo " </tr>\n"; $n = 0; } } - if ($n > 0) { + if ($n > 0) + { while ($n++ < $maxRow) echo " <td></td>\n"; echo " </tr>\n"; @@ -360,30 +395,28 @@ echo "</table>\n"; } - echo "<p><b>".$totalLoc."</b> locations.</p>\n"; - - echo "</div>\n"; + echo + "<p><b>".$totalLoc."</b> locations.</p>\n". + "</div>\n"; - /* Print out location tooltip HTML code - */ - foreach ($locationTips as $tipID => $tip) { - echo "<div class=\"tooltip\" id=\"tt".$tipID. - "\"><div class=\"holder\"><b>".chentities($tip["title"]). - "</b><br />".$tip["desc"]."</div></div>\n"; + // Print out location tooltip HTML code + foreach ($locationTips as $tipID => $tip) + { + echo + "<div class=\"tooltip\" id=\"tt".$tipID. + "\"><div class=\"holder\"><b>".chentities($tip["title"]). + "</b><br />".$tip["desc"]."</div></div>\n"; } - /* Print out the alpha link index - */ - printExtraBoxAlphaList($alphaTable); -} else { + // Print out the alpha link index + stPrintExtraBoxAlphaList($alphaTable); +} +else +{ echo "<p><b>No locations known!</b></p>\n"; echo "</div>\n"; - $errorStr = "No locations known!"; + stError("No locations known!"); } -?> -</body> -</html> -<? -if (empty($errorStr)) - storePageToCache(); + +cmPrintPageFooter(); ?> \ No newline at end of file
--- a/www/query.php Sat Dec 21 00:20:47 2013 +0200 +++ b/www/query.php Mon Dec 23 16:49:09 2013 +0200 @@ -6,9 +6,11 @@ require "world.inc.php"; require "common.inc.php"; -function myerr() { +function myerr() +{ global $locWebPage; - if ($locWebPage) { + if ($locWebPage) + { printPageHeader("Search results"); require "menu.inc.php"; echo " @@ -18,7 +20,9 @@ </div> </body> </html>\n"; - } else { + } + else + { header("Status: 404 Not Found"); echo "Location not found."; } @@ -26,7 +30,7 @@ } // Read in location data, etc. -$locTable = readLocationFiles(FALSE, "Q"); +$locTable = stReadLocationFiles(FALSE, "Q"); $locExact = FALSE; $locFound = FALSE; $locJSMap = FALSE; @@ -58,12 +62,15 @@ $locRegEx = "/".preg_quote($locName, "/")."/i"; // OpenSearch mode? -if ($locOpenSearch) { +if ($locOpenSearch) +{ header("Content-Type: application/json; charset=".$pageCharset); $locResult = array(); - foreach ($locTable as $data) { + foreach ($locTable as $data) + { $match = FALSE; - foreach ($data["names"] as $n) { + foreach ($data["names"] as $n) + { if (preg_match($locRegEx, $n["name"])) $locResult[] = $n["name"]; } @@ -80,31 +87,43 @@ echo "[\"".$locName."\",[".$str."]]"; -} else { +} +else +{ // Match location exactly (non-case sensitive tho) reset($locTable); - while (!$locFound && (list($id, $data) = each($locTable))) { - if (!strcasecmp($locName, $data["name"])) { + while (!$locFound && (list($id, $data) = each($locTable))) + { + if (!strcasecmp($locName, $data["name"])) $locFound = TRUE; - } else { - foreach ($data["names"] as $n) { - if (!strcasecmp($locName, $n)) - $locFound = TRUE; + else + { + foreach ($data["names"] as $n) + if (!strcasecmp($locName, $n)) + { + $locFound = TRUE; + break; } } - if ($locFound) $locData = $data; + if ($locFound) + $locData = $data; } // If not exact matching mode specified, try non-exact also - if (!$locExact) { + if (!$locExact) + { reset($locTable); - while (!$locFound && (list($id, $data) = each($locTable))) { + while (!$locFound && (list($id, $data) = each($locTable))) + { if (preg_match($locRegEx, $data["name"])) $locFound = TRUE; - else { - foreach ($data["names"] as $n) { - if (preg_match($locRegEx, $n["name"])) - $locFound = TRUE; + else + { + foreach ($data["names"] as $n) + if (preg_match($locRegEx, $n["name"])) + { + $locFound = TRUE; + break; } } if ($locFound) @@ -113,11 +132,13 @@ } // Set result - if ($locFound) { + if ($locFound) + { header("Location: ".$pageMapURL.$locData["continent"].".". ($locJSMap ? "htm" : "html"). "#loc".$locData["x"]."_".$locData["y"]); - } else + } + else myerr(); }
--- a/www/quests.php Sat Dec 21 00:20:47 2013 +0200 +++ b/www/quests.php Mon Dec 23 16:49:09 2013 +0200 @@ -8,12 +8,12 @@ if (isset($_GET["hcbat"])) { $locTable = array(); - parseLocFile("hcbat", $locTable, FALSE, "C"); + stParseLocFile("hcbat", $locTable, FALSE, "C"); $hcbat = TRUE; } else { - $locTable = readLocationFiles(FALSE); + $locTable = stReadLocationFiles(FALSE); $hcbat = FALSE; } @@ -36,7 +36,8 @@ //======================================================================== // Create quest data tables -if (count($locTable) > 0) { +if (count($locTable) > 0) +{ $lqTable = array(); $aqTable = array(); @@ -65,21 +66,11 @@ { global $batQuestURL, $continentList, $hcbat; echo - "<td><a href=\"".$batQuestURL.urlencode($name)."\">".chentities($name)."</a></td>". - "<td class=\"".$area["continent"]."\">"; - if (isset($continentList[$area["continent"]]) && - !$continentList[$area["continent"]][4]) - { - echo "<b>".chentities($area["name"])."</b>"; - } - else - { - printURL($area["continent"].".html#loc".$area["x"]."_".$area["y"]); - echo chentities($area["name"])."</a>"; - } - echo "</td>"; - if (!$hcbat) - echo "<td>".$continentList[$area["continent"]][0]."</td>"; + "<td><a href=\"".$batQuestURL.urlencode($name)."\">".chentities($name)."</a></td>". + "<td class=\"".$area["continent"]."\">". + stGetMapLink($area, !isset($continentList[$area["continent"]]) || $continentList[$area["continent"]][4]). + "</td>". + (!$hcbat ? "<td>".$continentList[$area["continent"]][0]."</td>" : ""); } //======================================================================== @@ -92,7 +83,7 @@ { $totalLQ = 0; echo - "<table class=\"loc\">\n". + "<table class=\"quests\">\n". " <tr>\n". " <th>Level</th>\n". " <th>Quest name</th>\n". @@ -118,19 +109,20 @@ //======================================================================== -echo "</td><td valign=\"top\">\n". -"<h2>Area Quests</h2>\n"; +echo + "</td><td valign=\"top\">\n". + "<h2>Area Quests</h2>\n"; if (count($aqTable) > 0) { $totalAQ = 0; echo - "<table class=\"loc\">\n". - " <tr>\n". - " <th>Quest name</th>\n". - " <th>Location</th>\n". - ($hcbat ? "" : " <th>Continent</th>\n"). - " </tr>\n"; + "<table class=\"quests\">\n". + " <tr>\n". + " <th>Quest name</th>\n". + " <th>Location</th>\n". + ($hcbat ? "" : " <th>Continent</th>\n"). + " </tr>\n"; foreach ($aqTable as $name => $area) { @@ -139,13 +131,15 @@ printQuestData($name, $area); echo "</tr>\n"; } - echo "</table>\n". - "<p><b>".$totalAQ."</b> area quests.</p>\n"; -} else { + echo + "</table>\n". + "<p><b>".$totalAQ."</b> area quests.</p>\n"; +} +else +{ echo "<p><b>No area quests known!</b></p>\n"; } echo "</td></tr></table>\n"; + +cmPrintPageFooter(); ?> -</div> -</body> -</html>
--- a/www/ss.php Sat Dec 21 00:20:47 2013 +0200 +++ b/www/ss.php Mon Dec 23 16:49:09 2013 +0200 @@ -4,75 +4,68 @@ require "common.inc.php"; $locTable = apc_fetch("ss_locTable"); -if (empty($locTable)) { - $locTable = readLocationFiles(TRUE, "C", TRUE); - parseLocFile("limbo", $locTable, TRUE, "C"); +if (empty($locTable)) +{ + $locTable = stReadLocationFiles(TRUE, "C", TRUE); + stParseLocFile("limbo", $locTable, TRUE, "C"); apc_store("ss_locTable", $locTable, 3600); } -/* Page start - */ +// Page start printPageHeader($pageTitle." - Secret societies"); require "menu.inc.php"; -?> -<div id="contents"> -<h1>Secret societies of BatMUD</h1> -<? -/* Print list of societies - */ -if (count($locTable) > 0) { - /* Make the list array */ - foreach ($locTable as $key => $value) { - if (count($value["coders"]) > 0) { - foreach ($value["coders"] as $name) { - $sortTable[$name["name"]] = array( - "name" => $value["name"], - "x" => $value["x"], - "y" => $value["y"], - "continent" => $value["continent"], - ); - } +echo + "<div id=\"contents\">\n". + "<h1>Secret societies of BatMUD</h1>\n"; + +// Print list of societies +if (count($locTable) > 0) +{ + // Make the list array + foreach ($locTable as $key => $value) + { + foreach ($value["coders"] as $name) + { + $sortTable[$name["name"]] = array( + "name" => $value["name"], + "x" => $value["x"], + "y" => $value["y"], + "continent" => $value["continent"], + ); } } ksort($sortTable); echo - "<table class=\"loc\" style=\"width: 80%;\">\n". - " <tr>\n". - " <th>Society name</th>\n". - " <th>Player city</th>\n". - " <th>Continent</th>\n". - " </tr>\n"; - - foreach ($sortTable as $name => $data) { - $t = $data["continent"]; - echo + "<table class=\"societies\">\n". " <tr>\n". - " <td>".chentities($name)."</td>\n". - " <td class=\"".$t."\">"; -// chentities($data["name"])."</td>\n"; - - if (!$continentList[$data["continent"]][4]) { - echo "<b>".chentities($data["name"])."</b>"; - } else { - printURL($data["continent"].".html#loc".$data["x"]."_".$data["y"]); - echo chentities($data["name"])."</a>"; - } - + " <th>Society name</th>\n". + " <th>Player city</th>\n". + " <th>Continent</th>\n". + " </tr>\n"; + + foreach ($sortTable as $name => $data) + { echo - "</td>\n". - " <td>".chentities($continentList[$t][0])."</td>\n". - " </tr>\n"; + " <tr>\n". + " <td>".chentities($name)."</td>\n". + " <td class=\"".$data["continent"]."\">". + stGetMapLink($data, $continentList[$data["continent"]][4]). + "</td>\n". + " <td>".chentities($continentList[$data["continent"]][0])."</td>\n". + " </tr>\n"; } - echo "</table>\n". - "<p><b>".count($sortTable)."</b> societies.</p>\n"; -} else { + echo + "</table>\n". + "<p><b>".count($sortTable)."</b> societies.</p>\n"; +} +else +{ echo "<p><b>No societies known!</b></p>\n"; } -?> -</div> -</body> -</html> + +cmPrintPageFooter(); +?> \ No newline at end of file