diff www/loc.php @ 337:ca191c3a0ce1

Updates and lots of new ugly glue.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 11 Jul 2007 16:05:32 +0000
parents eeb6167cf81e
children 875548a41c71
line wrap: on
line diff
--- a/www/loc.php	Wed Jul 11 16:05:01 2007 +0000
+++ b/www/loc.php	Wed Jul 11 16:05:32 2007 +0000
@@ -1,155 +1,6 @@
 <?
 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;
-}
-
-
-function submitWizInfo(&$wizTable, $m)
-{
-      $s = trim($m[1]);
-      $wizTable[$s] = array(
-        "name" => $s,
-        "homeURL" => trim($m[2]),
-        "imageURL" => trim($m[3]),
-        "desc" => trim($m[4])
-      );
-}
-
-function readWizInfo($filename, &$wizTable)
-{
-  $inFile = @fopen($filename, "r");
-  if (!$inFile) {
-    return FALSE;
-  }
-  
-  $contMode = FALSE;
-  while (!feof($inFile)) {
-    $inLine = rtrim(fgets($inFile));
-    
-    if ($contMode) {
-      if (substr($inLine, -1, 1) == "$") {
-        $m[4] .= " ".substr($inLine, 0, -1);
-        $contMode = FALSE;
-        submitWizInfo($wizTable, $m);
-      } else
-        $m[4] .= " ".$inLine;
-    } else
-    if (strlen($inLine) == 0 || $inLine[0] == "#") {
-    } else
-    if (preg_match("/^([A-Z][a-z]+);(http:\/\/[^;]+|bat)?;(http:\/\/[^;]+|bat:\/\/[^;]+)?;([^\$]*)\\\$$/", $inLine, $m)) {
-      submitWizInfo($wizTable, $m);
-    } else
-    if (preg_match("/^([A-Z][a-z]+);(http:\/\/[^;]+|bat)?;(http:\/\/[^;]+|bat:\/\/[^;]+)?;(.*)$/", $inLine, $m)) {
-      $contMode = TRUE;
-    } 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();
-$wizTable = array();
-
-$onlyPCities = isset($_GET["c"]);
-$showCoders = !isset($_GET["s"]);
-
-if (isset($_GET["a"])) {
-  $coderName = basename($_GET["a"]);
-  $coderName = strtoupper(substr($coderName, 0, 1)).strtolower(substr($coderName, 1));
-}
-
-if (isset($_GET["n"])) {
-  $setName = strtolower(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);
-  }
-}
-
+require "common.inc.php";
 
 function makeURL($pcities, $coders, $name, $desc, $class)
 {
@@ -172,11 +23,44 @@
     echo "  <td>";
   
   
-  echo "<a href=\"loc.php";
+  echo "<a href=\"".$GLOBALS["SCRIPT_NAME"];
   if (strlen($s) > 0) echo "?".$s;
   echo "\">".$desc."</a></td>\n";
 }
 
+
+/* Page start
+ */
+printPageHeader($pageTitle." - Locations");
+//echo "<div><b>DEVELOPMENT VERSION</b></div>";
+
+$locTable = array();
+$wizTable = array();
+
+$onlyPCities = isset($_GET["c"]);
+$showCoders = !isset($_GET["s"]);
+
+if (isset($_GET["a"])) {
+  $coderName = basename($_GET["a"]);
+  $coderName = strtoupper(substr($coderName, 0, 1)).strtolower(substr($coderName, 1));
+  readWizInfo("wizards.txt", $wizTable);
+}
+
+if (isset($_GET["n"])) {
+  $setName = strtolower(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);
+  }
+}
+
 /* Header
  */
 echo "<h1>";
@@ -218,36 +102,37 @@
   makeURL($onlyPCities, $showCoders, $iKey, $iValue, $iKey);
 }
 ?>
-
    <td>[<a href="index.php">Back to main page</a>]</td>
   </tr>
  </table>
 </div>
 
 <?
-/*
-if ($showCoders && isset($coderName) && isset($wizTable[$coderName])) {
+if ($showCoders && isset($coderName) && isset($wizTable[$coderName]) && count($wizTable[$coderName]) > 1) {
   echo "<div class=\"wizinfo\">\n <table>\n  <tr>\n";
   
   $s = $wizTable[$coderName]["imageURL"];
-  if (strlen($s) > 0) {
+  if (isset($s)) {
     if (substr($s, 0, 6) == "bat://")
       $s = "http://www.bat.org/albums/".substr($s, 6);
-    echo "   <td class=\"img\"><img src=\"".$s."\" alt=\"".$coderName."\" /></td>\n";
-  }
+  } else
+    $s = "img/unknown.png";
+  
+  echo "   <td class=\"img\"><img src=\"".$s."\" alt=\"".$coderName."\" /></td>\n";
+
 
   echo "   <td class=\"info\">\n";
-
   echo "    <h2><a href=\"http://www.bat.org/help/finger.php?str=".$coderName."\">".$coderName."</a></h2>\n";
 
   $s = $wizTable[$coderName]["desc"];
-  if (strlen($s) > 0) {
+  if (isset($s) > 0) {
     echo "    <p>".$s."</p>\n";
   }
 
   echo "    [<a href=\"http://www.bat.org/help/finger.php?str=".$coderName."\">Finger</a>]\n";
+
   $s = $wizTable[$coderName]["homeURL"];
-  if (strlen($s) > 0) {
+  if (isset($s)) {
     if ($s == "bat")
       $s = "http://wiz.bat.org/~".strtolower($coderName)."/";
       
@@ -256,7 +141,7 @@
   
   echo "   </td>\n  </tr>\n </table>\n</div>\n";
 }
-*/
+
 
 /* Print list of locations
  */
@@ -264,12 +149,15 @@
   /* Make alphabetical table of locations
    */
   while (list($key, $value) = each($locTable)) {
-    if (isset($coderName)) {
-      if (array_search($coderName, $value["coders"]) !== FALSE) {
+    if (isset($_GET["nocoders"])) {
+      if (count($value["coders"]) == 0 && !preg_match("/[SPG]/", $value["flags"]))
         $alphaTable[$key[0]][] = $value;
-      }
     } else {
-      $alphaTable[$key[0]][] = $value;
+      if (isset($coderName)) {
+        if (array_search($coderName, $value["coders"]) !== FALSE)
+          $alphaTable[$key[0]][] = $value;
+      } else
+        $alphaTable[$key[0]][] = $value;
     }
   }
 
@@ -293,7 +181,7 @@
         
         $totalLoc++;
 
-        printf("  <td width=\"%d%%\"class=\"%s\">",
+        printf("  <td width=\"%d%%\" class=\"%s\">",
           (100 / $maxRow), $iv["continent"]);
       
         printURL($iv["continent"].".html#loc".$iv["x"]."_".$iv["y"]);