changeset 246:0e429d8facdd misc

Upstream sync.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 07 Mar 2015 22:49:25 +0200
parents be51093a5e50
children 8d394425c71e
files materials/index.php
diffstat 1 files changed, 75 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/materials/index.php	Sat Mar 07 22:41:24 2015 +0200
+++ b/materials/index.php	Sat Mar 07 22:49:25 2015 +0200
@@ -1,24 +1,21 @@
 <?
 $pageTitle = "Pupunen BatMUD Material Browser";
 $pageIndex = "index.php";
-require "mcommon.inc.php";
+require "msitegen.inc.php";
 require "materials.inc.php";
 $sortDirs = array("asc", "desc");
 
-// Sorting column
-if (isset($_GET["s"])) {
-  $sortColumn = intval($_GET["s"]);
-} else
-  $sortColumn = 0;
-
+// Horrible kludge
+$agent = $_SERVER["HTTP_USER_AGENT"];
+if (stristr($agent, "GoogleBot") !== FALSE)
+{
+  header("HTTP/1.1 403 Forbidden");
+  exit;
+}
 
-// Sorting direction
-if (isset($_GET["d"])) {
-  $s = substr(strtolower($_GET["d"]), 0, 1);
-  $sortDirection = ($s == "d") ? 1 : 0;
-} else
-  $sortDirection = 0;
-
+// Sorting column
+$sortColumn = intval(stGetRequestItem("s", 0, TRUE));
+$sortDirection = substr(strtolower(stGetRequestItem("d", "", TRUE)), 0, 1) == "d";
 
 // Material column hiding
 if (isset($_GET["h"]) && is_array($_GET["h"]))
@@ -34,14 +31,14 @@
   $attrFilters = array();
 
 
-function printTC($a, $column)
+function stGetTC($a, $column)
 {
   global $sortColumn;
-  echo "<".$a.($column == $sortColumn ? " class=\"hilite\"" : "").">";
+  return "<".$a.($column == $sortColumn ? " class=\"hilite\"" : "").">";
 }
 
 
-function getURLStr($cfilters, $col, $dir)
+function stGetURLStr($cfilters, $col, $dir)
 {
   global $sortDirs, $hideColumns;
 
@@ -57,7 +54,7 @@
 }
 
 
-function sortMatFunc($a, $b)
+function stSortMatFunc($a, $b)
 {
   global $sortDirection, $sortColumn;
   $index = $sortColumn - 1;
@@ -74,17 +71,18 @@
 }
 
 
-if ($sortColumn <= 0 || $sortColumn >= 18) {
+if ($sortColumn <= 0 || $sortColumn >= 18)
+{
   $sortColumn = 0;
   if ($sortDirection)
     krsort($matTable, SORT_STRING);
   else
     ksort($matTable, SORT_STRING);
 } else
-  uasort($matTable, "sortMatFunc");
+  uasort($matTable, "stSortMatFunc");
 
 
-printPageHeader($pageTitle,
+cmPrintPageHeader($pageTitle,
   "<meta name=\"robots\" content=\"nofollow\" />\n");
 ?>
 <h1><? echo $pageTitle; ?></h1>
@@ -94,9 +92,9 @@
   <th>Hide columns</th>
   <th>Show only type</th>
   <td rowspan="3" class="infobox">
-   [<a href="<? echo $pageIndex; ?>">Reset/Clear</a>] [<a href="alloy.php">Alloy browser</a>]
+   [<a href="<? echo $pageIndex; ?>">Reset/Clear</a>] [<a href="info.php">Alloy browser</a>]
    - <b>CHANGE COLOURS/STYLE: <?
-   for ($i = 1; $i <= 3; $i++)
+   for ($i = 1; $i <= 4; $i++)
      echo "<a href=\"?css=".$i."\">(".$i.")</a> "
    ?></b>
    <br />
@@ -120,10 +118,11 @@
 <?
 reset($transNameTable);
 next($transNameTable);
-while (list($key, $value) = each($transNameTable)) {
+while (list($key, $value) = each($transNameTable))
+{
   echo "    <option".
-  (isset($hideColumns[$key]) ? " selected=\"selected\"" : "").
-  " value=\"$key\">".htmlentities($value)."</option>\n";
+    (isset($hideColumns[$key]) ? " selected=\"selected\"" : "").
+    " value=\"$key\">".chentities($value)."</option>\n";
 }
 ?>
    </select>
@@ -136,10 +135,11 @@
 $typeTable = $transTable[14];
 $typeTable[-1] = "EVERYTHING";
 ksort($typeTable);
-foreach ($typeTable as $key => $value) {
+foreach ($typeTable as $key => $value)
+{
   echo "    <option value=\"$key\"".
     ($typeFilter == $key ? " selected=\"selected\"" : "").
-    ">".htmlentities($value)."</option>\n";
+    ">".chentities($value)."</option>\n";
 }
 ?>
    </select>
@@ -151,61 +151,70 @@
 </table>
 </form>
 <?
-if (count($attrFilters) > 0) {
-  $str = "";
-  foreach ($attrFilters as $fkey => $fval) {
-    if ($str != "") $str .= ", ";
-    $str .= "<b>".strtolower($transNameTable[$fkey + 1])."</b>=".strtolower($transTable[$fkey][$fval]);
+if (count($attrFilters) > 0)
+{
+  $filters = array();
+  foreach ($attrFilters as $fkey => $fval)
+  {
+    $filters[] = "<b>".strtolower($transNameTable[$fkey + 1])."</b>=".strtolower($transTable[$fkey][$fval]);
   }
-  echo "<p>Filtering: ".$str."</p>\n";
+  echo "<p>Filtering: ".implode(", ", $filters)."</p>\n";
 }
 ?>
+<div class="matTable">
 <table class="matTable">
  <tr>
 <?
-foreach ($transNameTable as $key => $value) {
-  if (!isset($hideColumns[$key])) {
-    echo "  ";
-    printTC("th", $key);
-    echo "<a href=\"?".
-      getURLStr($attrFilters, $key, ($key == $sortColumn) ? !$sortDirection : $sortDirection).
-      "\">".htmlentities($value)."</a></th>\n";
+foreach ($transNameTable as $key => $value)
+{
+  if (!isset($hideColumns[$key]))
+  {
+    echo
+      "  ".stGetTC("th", $key).
+      "<a href=\"?".
+      stGetURLStr($attrFilters, $key, ($key == $sortColumn) ? !$sortDirection : $sortDirection).
+      "\">".chentities($value)."</a></th>\n";
   }
 }
 echo " </tr>\n";
 
-foreach ($matTable as $key => $value) {
-
+foreach ($matTable as $key => $value)
+{
   $doShow = TRUE;
-  foreach ($attrFilters as $fkey => $fval) {
-    if ($fval >= 0 && $value[$fkey] != $fval) {
-      $doShow = FALSE;
-      break;
-    }
+  foreach ($attrFilters as $fkey => $fval)
+  if ($fval >= 0 && $value[$fkey] != $fval)
+  {
+    $doShow = FALSE;
+    break;
   }
   
-  if ($doShow) {
+  if ($doShow)
+  {
     $col = 0;
-    echo " <tr>";
-    printTC("td", $col++);
+    echo " <tr>".stGetTC("td", $col++);
 
-    echo "<a href=\"alloy.php?m=".urlencode($key)."\">".htmlentities($key)."</a>".
-//    " <a href=\"?".getURLStr($attrFilters, $sortColumn, $sortDirection)."\">&bullet;</a>".
+    echo "<a href=\"/mat/".urlencode($key)."\">".chentities($key)."</a>".
+//    " <a href=\"?".stGetURLStr($attrFilters, $sortColumn, $sortDirection)."\">&bullet;</a>".
     "</td>";
     
-    foreach ($value as $kkey => $kvalue) {
-      if (!isset($hideColumns[$kkey + 1])) {
-        printTC("td", $col);
-        if (is_array($kvalue)) {
+    foreach ($value as $kkey => $kvalue)
+    {
+      if (!isset($hideColumns[$kkey + 1]))
+      {
+        echo stGetTC("td", $col);
+        if (is_array($kvalue))
+        {
           // Arrays need special handling, and is bit messy
           reset($kvalue);
 
           if (list($nam, $lode) = each($kvalue))
-            echo htmlentities($transTable[$kkey][$lode]);
+            echo chentities($transTable[$kkey][$lode]);
 
           while (list($nam, $lode) = each($kvalue))
-            echo ", ".htmlentities($transTable[$kkey][$lode]);
-        } else {
+            echo ", ".chentities($transTable[$kkey][$lode]);
+        }
+        else
+        {
           // A simple entry, just print it out
           $tmpFilters = $attrFilters;
           if (isset($tmpFilters[$kkey]))
@@ -214,8 +223,8 @@
             $tmpFilters[$kkey] = $kvalue;
 
           echo "<a href=\"?".
-            getURLStr($tmpFilters, $sortColumn, $sortDirection).
-            "\">".htmlentities($transTable[$kkey][$kvalue])."</a>";
+            stGetURLStr($tmpFilters, $sortColumn, $sortDirection).
+            "\">".chentities($transTable[$kkey][$kvalue])."</a>";
         }
         echo "</td>";
       }
@@ -224,8 +233,9 @@
     echo "</tr>\n";
   }
 }
-echo "</table>\n";
-
+echo
+  "</table>\n".
+  "</div>\n";
 
-printPageFooter();
+cmPrintPageFooter();
 ?>