Mercurial > hg > batmud > maputils
changeset 975:af0fc3a965dc
Fix all the web-interface PHP crap to work with the new LOC file format. Urgh. This shit could really use some refactoring cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 13 Jun 2010 23:39:52 +0000 |
parents | fa0323011e1d |
children | 047fa29bc07e |
files | www/common.inc.php www/info.php www/latest.php www/loc.php www/ss.php |
diffstat | 5 files changed, 75 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/www/common.inc.php Sun Jun 13 22:52:02 2010 +0000 +++ b/www/common.inc.php Sun Jun 13 23:39:52 2010 +0000 @@ -41,6 +41,32 @@ ); +define("NAME_ORIG", 1); +define("NAME_RECODER", 2); +define("NAME_MAINTAINER", 4); +define("NAME_EXPANDER", 8); + +function addLocNames(&$list, $input) +{ + $list = array(); + foreach ($input as $name) { + $nflags = 0; + $npos = 0; + + switch (substr($name, 0, 1)) { + case "@": $npos++; $nflags |= NAME_ORIG; break; + case "!": $npos++; $nflags |= NAME_RECODER; break; + case "%": $npos++; $nflags |= NAME_MAINTAINER; break; + case "&": $npos++; $nflags |= NAME_EXPANDER; break; + } + + $list[] = array( + "name" => substr($name, $npos), + "flags" => $nflags + ); + } +} + function parseLocFile($filename, &$locations, $applyFilter, $filter) { global $locationTypes; @@ -55,14 +81,14 @@ 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) - $coders = preg_split("/\s*,\s*/", $addInfo[0]); - else + if (strlen($addInfo[0]) > 0) { + addLocNames($coders, preg_split("/\s*,\s*/", $addInfo[0])); + } else $coders = array(); // Get timestamp @@ -85,31 +111,28 @@ // 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 - $names = preg_split("/\s*\|\s*/", $record[4]); + addLocNames($names, preg_split("/\s*\|\s*/", $record[4])); // Check for duplicate locations - $id = $flags.$names[0]; + $id = $flags.$names[0]["name"]; if (isset($locations[$id])) { - echo $inLine; - echo "Error: Location '<b>".$id."</b>' already defined (".$locations[$id]["continent"]." <=> ".$filename.")<br />\n"; + echo $inLine."<br />Error: Location '<b>".$id."</b>' already defined (".$locations[$id]["continent"]." <=> ".$filename.")<br />\n"; return FALSE; } // Create primary location name - $s = ""; - $found = FALSE; - for ($i = 0; $found === FALSE && $i < strlen($flags); $i++) { + 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]." "; } } - $s .= $names[0]; - unset($names[0]); + $s .= $names[0]["name"]; +// unset($names[0]); // Add location to array of locations $locations[$id] = array(
--- a/www/info.php Sun Jun 13 22:52:02 2010 +0000 +++ b/www/info.php Sun Jun 13 23:39:52 2010 +0000 @@ -67,14 +67,11 @@ /* Print table of wizards */ foreach ($locTable as $key => $value) { - foreach ($value["coders"] as $ik => $iv) { - if (!isset($wizTable[$iv])) - $wizTable[$iv] = array("name" => $iv); - - if (!isset($wizTable[$iv]["areas"])) - $wizTable[$iv]["areas"] = 1; - else - $wizTable[$iv]["areas"]++; + foreach ($value["coders"] as $wiz) { + $name = $wiz["name"]; + if (!isset($wizTable[$name])) + $wizTable[$name] = array("name" => $name); + $wizTable[$name]["areas"]++; } }
--- a/www/latest.php Sun Jun 13 22:52:02 2010 +0000 +++ b/www/latest.php Sun Jun 13 23:39:52 2010 +0000 @@ -96,15 +96,13 @@ " <td>".$continentList[$iv["continent"]][0]."</td>\n". " <td>"; - if (count($iv["coders"]) > 0) { - $fs = ""; - while (list($fKey, $fVal) = each($iv["coders"])) { - if ($fs != "") $fs .= ", "; - $fs .= "<a href=\"loc.php?a=".chentities($fVal)."\">".chentities($fVal)."</a>"; - } - echo $fs; + $fs = ""; + foreach ($iv["coders"] as $name) { + if ($fs != "") $fs .= ", "; + $fs .= "<a href=\"loc.php?a=".chentities($name["name"])."\">".chentities($name["name"])."</a>"; } - echo "</td>\n". + + echo "$fs</td>\n". " <td>"; if (isset($iv["freeform"])) echo chentities($iv["freeform"]);
--- a/www/loc.php Sun Jun 13 22:52:02 2010 +0000 +++ b/www/loc.php Sun Jun 13 23:39:52 2010 +0000 @@ -189,8 +189,10 @@ $alphaTable[$idx][] = $data; } else { if (isset($coderName)) { - if (array_search($coderName, $data["coders"]) !== FALSE) - $alphaTable[$idx][] = $data; + foreach ($data["coders"] as $coder) { + if ($coderName == $coder["name"]) + $alphaTable[$idx][] = $data; + } } else $alphaTable[$idx][] = $data; } @@ -256,8 +258,17 @@ } // Alternative names - if (count($iv["names"]) > 0) { - echo "<br />".chentities(implode(" | ", $iv["names"])); + $nnames = count($iv["names"]); + if ($nnames > 1) { + echo "<br />"; + for ($nname = 1; $nname < $nnames; $nname++) { + if ($iv["names"][$nname]["flags"] & NAME_ORIG) + echo "<b>"; + echo chentities($iv["names"][$nname]["name"]); + if ($iv["names"][$nname]["flags"] & NAME_ORIG) + echo "</b>"; + if ($nname < $nnames - 1) echo " | "; + } } // Coder / society names @@ -265,12 +276,19 @@ $isSG = preg_match("/[SG]/", $iv["flags"]); if ((!isset($coderName) && !$isSG) || isset($coderName)) { $fs = ""; - foreach ($iv["coders"] as $fKey => $fVal) { + foreach ($iv["coders"] as $name) { if ($fs != "") $fs .= ", "; + switch ($name["flags"]) { + case NAME_ORIG: $qs = "title=\"Original creator\""; break; + case NAME_RECODER: $qs = "title=\"Converter, recoder\""; break; + case NAME_MAINTAINER: $qs = "title=\"Maintainer\""; break; + case NAME_EXPANDER: $qs = "title=\"Implemented new content, expansion(s)\""; break; + default: $qs = ""; + } if ($filter != "C" || !$applyFilter) - $fs .= "<a href=\"".$_SERVER["PHP_SELF"]."?a=".$fVal."\">".$fVal."</a>"; + $fs .= "<a ".$qs." href=\"".$_SERVER["PHP_SELF"]."?a=".$name["name"]."\">".$name["name"]."</a>"; else - $fs .= $fVal; + $fs .= $name["name"]; } echo "<br />[".$fs."]"; }
--- a/www/ss.php Sun Jun 13 22:52:02 2010 +0000 +++ b/www/ss.php Sun Jun 13 23:39:52 2010 +0000 @@ -24,8 +24,8 @@ /* Make a list */ foreach ($locTable as $key => $value) { if (count($value["coders"]) > 0) { - foreach ($value["coders"] as $qvalue) { - $sortTable[$qvalue] = array( + foreach ($value["coders"] as $name) { + $sortTable[$name["name"]] = array( "name" => $value["name"], "continent" => $value["continent"], );