changeset 1979:3c03ca974e6a

Fix issue with "area" selection in location display not actually showing all areas, also refactor few things. This breaks some backward compatibility as the "filter" option can no longer be used by user for filtering via a direct regexp. But I doubt anyone used that feature anyway.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 19 Nov 2017 21:41:10 +0200
parents 10d074fb441c
children 39729450a96f
files www/common.inc.php www/latest.php www/level.php www/loc.php www/quests.php www/simple.php
diffstat 6 files changed, 53 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/www/common.inc.php	Sun Nov 19 21:13:04 2017 +0200
+++ b/www/common.inc.php	Sun Nov 19 21:41:10 2017 +0200
@@ -6,19 +6,25 @@
 $statusMsg = "";
 
 
+define("LTI_XXX"         , 0);
+define("LTI_NAME_PREFIX" , 1);
+define("LTI_PAGE_DESC"   , 2);
+define("LTI_MENU_TITLE"  , 3);
+define("LTI_REGEXP"      , 4);
+
 $locationTypes =
 [
-//ID  => ?      , Location name prefix, Page title prefix , Menu string, Selector regex
-  ""  => [FALSE , ""         , "ALL"                       , "EVERYTHING" , "*"],
-  "A" => [TRUE  , ""         , "Areas"                     , "Areas"      , "^SGPMcTC"],
-  "S" => [TRUE  , "SHRINE"   , "Race and other shrines"    , "Shrines"    , "S"],
-  "G" => [TRUE  , "GUILD"    , "Guilds"                    , "Guilds"     , "G"],
-  "P" => [TRUE  , "SS"       , "Outworld secret societies" , "SS"         , "P"],
-  "M" => [TRUE  , "MONSTER"  , "Special outworld monsters" , "Monsters"   , "M"],
-  "c" => [TRUE  , "CITY"     , "Major cities"              , "Cities"     , "c"],
-  "T" => [TRUE  , "TRAINER"  , "Guild trainers"            , "Trainers"   , "T"],
-  "C" => [FALSE , "PCITY"    , "Player cities"             , "PCities"    , "C"],
-//"F" => [TRUE  , "FORT"     , "Regional Forts",            "Forts"],
+//ID  => ?      , Loc name prefix, Page description            , Menu title   , Selector regex
+  ""  => [FALSE , ""             , "ALL"                       , "EVERYTHING" , ""],
+  "A" => [TRUE  , ""             , "Areas"                     , "Areas"      , ""],
+  "S" => [TRUE  , "SHRINE"       , "Race and other shrines"    , "Shrines"    , "S"],
+  "G" => [TRUE  , "GUILD"        , "Guilds"                    , "Guilds"     , "G"],
+  "P" => [TRUE  , "SS"           , "Outworld secret societies" , "SS"         , "P"],
+  "M" => [TRUE  , "MONSTER"      , "Special outworld monsters" , "Monsters"   , "M"],
+  "c" => [TRUE  , "CITY"         , "Major cities"              , "Cities"     , "c"],
+  "T" => [TRUE  , "TRAINER"      , "Guild trainers"            , "Trainers"   , "T"],
+  "C" => [FALSE , "PCITY"        , "Player cities"             , "PCities"    , "C"],
+//"F" => [TRUE  , "FORT"         , "Regional Forts"            , "Forts"      , "F"],
 ];
 
 
@@ -202,7 +208,7 @@
 }
 
 
-function mpParseLocFile($filename, &$locations, $matchFilter, $filter)
+function mpParseLocFile($filename, &$locations, $applyFilter, $filter)
 {
   global $locationTypes;
 
@@ -250,13 +256,13 @@
       
       // Check flags, completely ignore records with "-" flag
       $rawflags = $record[3];
-      if (!strstr($rawflags, "-"))
+      if (strstr($rawflags, "-") === FALSE)
       {
         // 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."][\%\?]*\$/", $rawflags);
+        $filterMatch = $applyFilter ? preg_match("/^[0-9]+[\%\?]*".$filter."\$/", $rawflags) : TRUE;
 
-        if (($matchFilter && $filterMatch) || (!$matchFilter && !$filterMatch))
+        if ($filterMatch)
         {
           // Get location names
           mpAddLocNames($names, preg_split("/\s*\|\s*/", $record[4]));
@@ -272,11 +278,12 @@
           // Create primary location name
           for ($s = "", $found = FALSE, $i = 0; $found === FALSE && $i < strlen($rawflags); $i++)
           {
+            // Check
             if (array_key_exists($rawflags[$i], $locationTypes))
             {
               $found = $rawflags[$i];
-              if (!$filterMatch && $locationTypes[$found][0])
-                $s = $locationTypes[$found][1]." ";
+              if (!$filterMatch && $locationTypes[$found][LTI_XXX])
+                $s = $locationTypes[$found][LTI_NAME_PREFIX]." ";
             }
           }
           $s .= $names[0]["name"];
@@ -319,7 +326,7 @@
 }
 
 
-function mpReadLocationFiles($matchFilter = FALSE, $filter = "CF")
+function mpReadLocationFiles($applyFilter = FALSE, $filter = "[^CF]*")
 {
   global $continentList;
   $locations = [];
@@ -327,7 +334,7 @@
   foreach ($continentList as $id => $data)
   {
     if ($data[7])
-      mpParseLocFile($id, $locations, $matchFilter, $filter);
+      mpParseLocFile($id, $locations, $applyFilter, $filter);
   }
 
   return $locations;
--- a/www/latest.php	Sun Nov 19 21:13:04 2017 +0200
+++ b/www/latest.php	Sun Nov 19 21:41:10 2017 +0200
@@ -3,7 +3,8 @@
 require "world.inc.php";
 require "common.inc.php";
 
-$locTable = mpReadLocationFiles(FALSE, isset($_REQUEST["all"]) ? "" : "CF");
+$showAll = isset($_REQUEST["all"]);
+$locTable = mpReadLocationFiles(!$showAll, "[^CF]*");
 
 mpPrintPageHeader($pageTitle." - Latest added locations");
 //echo "<div><b>DEVELOPMENT VERSION</b></div>";
--- a/www/level.php	Sun Nov 19 21:13:04 2017 +0200
+++ b/www/level.php	Sun Nov 19 21:41:10 2017 +0200
@@ -7,7 +7,7 @@
 if (isset($_GET["hcbat"]))
 {
   $locTable = array();
-  mpParseLocFile("hcbat", $locTable, FALSE, "C");
+  mpParseLocFile("hcbat", $locTable, FALSE, "");
   $hcbat = TRUE;
 }
 else
--- a/www/loc.php	Sun Nov 19 21:13:04 2017 +0200
+++ b/www/loc.php	Sun Nov 19 21:41:10 2017 +0200
@@ -58,26 +58,29 @@
 //
 // Initialization
 //
+// Special backwards compatibility case for pcities
 if (isset($_GET["c"]))
 {
-  $filter = "C";
+  $filterID = "C";
   $applyFilter = TRUE;
 }
 else
-if (($filter = mpGetRequestItem("f", "", TRUE)) != "")
+// Try to get the filter ID
+if (($filterID = mpGetRequestItem("f", "", TRUE)) != "")
 {
-  if (!preg_match("/^[\^A-Za-z!]+\$/", $filter))
+  if (!array_key_exists($filterID, $locationTypes))
   {
-    mpError("Invalid filter rule '".chentities($filter)."'");
-    $filter = "C";
+    mpError("Invalid location filter rule '".chentities($filterID)."'.");
+    $filterID = "";
     $applyFilter = FALSE;
   }
   else
     $applyFilter = TRUE;
 }
 else
+// No filter ID specified, default to showing everything
 {
-  $filter = "CF";
+  $filterID = "";
   $applyFilter = FALSE;
 }
 
@@ -115,7 +118,7 @@
     if (empty($locTable))
     {
       $locTable = [];
-      mpParseLocFile($setName, $locTable, $applyFilter, $filter);
+      mpParseLocFile($setName, $locTable, $applyFilter, $applyFilter ? $locationTypes[$filterID][LTI_REGEXP] : "");
       apc_store("loc_".$setName, $locTable, 3600);
     }
   }
@@ -130,7 +133,7 @@
   $locTable = apc_fetch("loc_locTable");
   if (empty($locTable))
   {
-    $locTable = mpReadLocationFiles($applyFilter, $filter);
+    $locTable = mpReadLocationFiles($applyFilter, $applyFilter ? $locationTypes[$filterID][LTI_REGEXP] : "");
     apc_store("loc_locTable", $locTable, 3600);
   }
 }
@@ -167,13 +170,7 @@
 // Start of the page
 //
 if ($applyFilter)
-{
-  if (array_key_exists($filter, $locationTypes))
-  
-    $mtitle = $locationTypes[$filter][2];
-  else
-    $mtitle = "Filter '".$filter."'";
-}
+  $mtitle = $locationTypes[$filterID][LTI_PAGE_DESC];
 else
   $mtitle = "Locations";
 
@@ -198,25 +195,25 @@
   echo "  <input type=\"hidden\" name=\"n\" value=\"".chentities($setName)."\" />\n";
 
 echo "  <select class=\"control dropdown\" name=\"f\" onChange=\"this.form.submit();\">\n";
-foreach ($locationTypes as $id => $type)
+foreach ($locationTypes as $lid => $ldata)
 {
   echo
-    "    <option value=\"".$id."\"".
-    (($applyFilter && $filter == $id) ? " selected=\"selected\"" : "").
-    ">".$type[3]."</option>\n";
+    "    <option value=\"".$lid."\"".
+    (($applyFilter && $filterID == $lid) ? " selected=\"selected\"" : "").
+    ">".$ldata[LTI_MENU_TITLE]."</option>\n";
 }
 echo
   "  </select>\n".
   "  <noscript><input type=\"submit\" value=\" Update \" class=\"control submit\" /></noscript>\n";
 
 
-printTitleLink($applyFilter, $filter, $showCoders, "All&nbsp;continents", "", "all");
+printTitleLink($applyFilter, $filterID, $showCoders, "All&nbsp;continents", "", "all");
 foreach ($continentList as $continent => $data)
 {
   if ($data[4])
-    printTitleLink($applyFilter, $filter, $showCoders, $data[0], $continent, $continent);
+    printTitleLink($applyFilter, $filterID, $showCoders, $data[0], $continent, $continent);
 }
-printTitleLink($applyFilter, $filter, $showCoders, "Special", "special", "special");
+printTitleLink($applyFilter, $filterID, $showCoders, "Special", "special", "special");
 
 echo
   "</div>\n".
@@ -401,7 +398,9 @@
               case NAME_EXPANDER:   $qs = "title=\"Implemented new content, expansion(s)\" class=\"wizexpander\""; break;
               default: $qs = "";
             }
-            if ($filter != "C" || !$applyFilter)
+
+            // Pcity entries do not get "author" links as they are actually SS+
+            if ($filterID != "C" || !$applyFilter)
               $fs[] = "<a ".$qs." href=\"?a=".$name["name"]."\">".$name["name"]."</a>";
             else
               $fs[] = $name["name"];
--- a/www/quests.php	Sun Nov 19 21:13:04 2017 +0200
+++ b/www/quests.php	Sun Nov 19 21:41:10 2017 +0200
@@ -7,7 +7,7 @@
 if (isset($_GET["hcbat"]))
 {
   $locTable = array();
-  mpParseLocFile("hcbat", $locTable, FALSE, "C");
+  mpParseLocFile("hcbat", $locTable, FALSE, "");
   $hcbat = TRUE;
 }
 else
--- a/www/simple.php	Sun Nov 19 21:13:04 2017 +0200
+++ b/www/simple.php	Sun Nov 19 21:41:10 2017 +0200
@@ -6,7 +6,7 @@
 $locTable = apc_fetch("loc_locTable");
 if (empty($locTable))
 {
-  $locTable = mpReadLocationFiles(FALSE, "F");
+  $locTable = mpReadLocationFiles(TRUE, "[^C]*");
   apc_store("loc_locTable", $locTable, 3600);
 }