diff www/loc.php @ 1387:2b6b38e94bb2

Various minor code cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 23 Dec 2013 16:49:09 +0200
parents 2f142b33e4ed
children 7fcea2fce0be
line wrap: on
line diff
--- 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