Moved to /race-o-matic URL.
authorCMDR furrycat <elite@furrycat.net>
Fri, 27 May 2016 12:25:57 +0000 (08:25 -0400)
committerCMDR furrycat <elite@furrycat.net>
Fri, 27 May 2016 12:32:32 +0000 (08:32 -0400)
.htaccess [new file with mode: 0644]
index.php
lib/entry.php
lib/footer.php
lib/header.php
lib/lap.php
lib/race.php
lib/raikogram.php
lib/ship.php
lib/station.php
propel/build/classes/BuckyballObject.php

diff --git a/.htaccess b/.htaccess
new file mode 100644 (file)
index 0000000..634a7bb
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1,3 @@
+RewriteEngine on
+Rewritecond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.+) index.php [L]
index a3a4f69..ecaed2a 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,7 +1,8 @@
 <?php
   date_default_timezone_set("UTC");
   $propel_project = "buckyball";
-  $www_root = "members/furrycat/buckyball";
+  $www_root = "race-o-matic";
+  $uri_root = $www_root ? "/$www_root" : "";
   $root = join(DIRECTORY_SEPARATOR, array($_SERVER['DOCUMENT_ROOT'], $www_root));
   $propel_root = join(DIRECTORY_SEPARATOR, array($root, "propel"));
   $lib_root = join(DIRECTORY_SEPARATOR, array($root, "lib"));
   Propel::init("$propel_root/build/conf/$propel_project-conf.php");
   set_include_path(join(PATH_SEPARATOR, array(join(DIRECTORY_SEPARATOR, array($propel_root, "build", "classes")), get_include_path())));
 
-  include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "include.php")));
+  $script_url = substr(array_key_exists('SCRIPT_URL', $_SERVER) ? $_SERVER['SCRIPT_URL'] : $_SERVER['REDIRECT_URL'], strlen($uri_root));
+  $request = preg_replace('!^/branches/[^/]+/!', "", $script_url);
+  $request = preg_replace('!^/+!', "", $request);
+  $request = preg_replace('!/+$!', "", $request);
+
+  # Extract module and parameters from URI.
+  $module = preg_replace('!/.*!', "", $request);
+  $parameters = split("/", preg_replace('!^[^/]*/!', "", $request));
+  if (count($parameters) == 1 && $parameters[0] == $module) $parameters = null;
 
-  parse_str($_SERVER['QUERY_STRING'], $params);
-  $module = $params['module'];
-  $action = $params['action'];
-  $args = $params['args'];
+  # Sanitise module.
+  if (! preg_match('/^[A-Za-z0-9-_]+$/', $module)) $module = null;
+  else if (! file_exists("$lib_root/$module.php")) $module = null;
+  else $module = strtolower($module);
+  if (! is_null($parameters)) list($action, $args) = $parameters;
 
+  $http = (isset($_SERVER['HTTPS'])) ? "https" : "http";
+  include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "include.php")));
   include_once(join(DIRECTORY_SEPARATOR, array($lib_root, "header.php")));
   if ($module) {
     $include = join(DIRECTORY_SEPARATOR, array($lib_root, "$module.php"));
index fcd9774..baf3d2b 100644 (file)
@@ -1,4 +1,4 @@
-<script src="plotly-latest.min.js"></script>
+<script src="<?php echo "$uri_root/"; ?>plotly-latest.min.js"></script>
 <h2>Entries</h2>
 <?php
 
   }
 
   function module_entry($action, $args) {
+    global $uri_root;
+
     if ($action && ! count($_POST)) {
       $eq = new EntryQuery;
       $eq->joinWith('Entry.Race');
     }
     echo "<hr>\n";
     form();
-    echo "<p>Add a <a href=\"?module=race\">race</a> entry: ";
+    echo "<p>Add a <a href=\"$uri_root/race\">race</a> entry: ";
     echo "<select name=\"race_id\">\n";
     option("race_id", 0, "");
     foreach ($races as $race) {
       option("race_id", $id, $name);
     }
     echo "</select>\n";
-    echo "<a href=\"?module=ship\">Ship:</a> <select name=\"ship_id\">\n";
+    echo "<a href=\"$uri_root/ship\">Ship:</a> <select name=\"ship_id\">\n";
     option("ship_id", 0, "");
     $last_competitor = null;
     foreach ($ships as $ship) {
index 3f7b97a..8dd8f54 100644 (file)
@@ -1,6 +1,6 @@
 <?php
   if ($module && file_exists("$root/$module.js")) {
-    echo "<script type=\"text/javascript\" src=\"$module.js\"></script>\n";
+    echo "<script type=\"text/javascript\" src=\"$uri_root/$module.js\"></script>\n";
   }
 ?>
 </body>
index 5e09447..de7b355 100644 (file)
@@ -1,17 +1,19 @@
 <head>
-<link rel="stylesheet" type="text/css" href="style.css">
+<?php
+  echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$uri_root/style.css\">\n";
+?>
 <link href='https://fonts.googleapis.com/css?family=Sintony:400,700' rel='stylesheet' type='text/css'>
 <link href='https://fonts.googleapis.com/css?family=Orbitron:500,700' rel='stylesheet' type='text/css'>
 <title><?php echo "Buckyball Racing Club"; if ($module) echo " - $module"; ?></title>
 </head>
 <body>
 <div id="header">
-<img src="images/logo.png" alt="Buckyball Racing Club" height=100 width=100>
 <?php
+  echo "<img src=\"$uri_root/images/logo.png\" alt=\"Buckyball Racing Club\" height=100 width=100>\n";
   $links = array();
   foreach (array("competitor", "hull", "ship", "system", "station", "race", "raikogram", "entry") as $what) {
     $title = preg_replace('/y$/', 'ie', $what);
-    $links[] =  "<span class=\"menu\"><a href=\"?module=$what\">" . ucfirst($title) . "s</a></span>";
+    $links[] =  "<span class=\"menu\"><a href=\"$uri_root/$what\">" . ucfirst($title) . "s</a></span>";
   }
   echo implode(" // ", $links);
 ?>
index c3bee57..e7a6792 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
   function module_lap($action, $args) {
+    global $uri_root;
 
     $rq = new RaceQuery;
     $races = $rq->find();
@@ -26,7 +27,7 @@
       option("race_id", $id, $name);
     }
     echo "</select>\n";
-    echo "<a href=\"?module=ship\">Ship:</a> <select name=\"ship_id\">\n";
+    echo "<a href=\"$uri_root/ship\">Ship:</a> <select name=\"ship_id\">\n";
     option("ship_id", 0, "");
     $last_competitor = null;
     foreach ($ships as $ship) {
index dac3cbc..7b26b85 100644 (file)
@@ -1,4 +1,4 @@
-<script src="plotly-latest.min.js"></script>
+<script src="<?php echo "$uri_root/"; ?>plotly-latest.min.js"></script>
 <h2>Races</h2>
 <?php
 
     echo "</pre></div>\n";
   }
 
-  function build_args($params, $key, $value, $description, $class = null) {
-    $uri = preg_replace('/&args=[^&]+/', '', $_SERVER['REQUEST_URI']);
+  function build_args($id, $params, $key, $value, $description, $class = null) {
+    global $uri_root;
     if (! is_null($class)) $class = " class=\"$class\"";
-    $uri = " <a$class href=\"$uri&args=";
+    $uri = " <a$class href=\"$uri_root/race/$id/";
     $args = array();
     $keys = array_unique(array_merge($params, array($key => $value)));
     foreach ($keys as $k => $v) {
         foreach ($race->getPrizeKeys() as $p) {
           $Prize = ucfirst($race->PrizeDescription($p));
           $v = $race->PrizeValue($p);
-          if (is_null($prize_filter) || ($prize_filter & $v)) $uri = build_args($params, "prizes", (is_null($prize_filter)) ? $race->getPrizes() & ~$v : $prize_filter & ~$v, $Prize, "disabled");
-          else $uri = build_args($params, "prizes", $prize_filter | $v, $Prize);
+          if (is_null($prize_filter) || ($prize_filter & $v)) $uri = build_args($action, $params, "prizes", (is_null($prize_filter)) ? $race->getPrizes() & ~$v : $prize_filter & ~$v, $Prize, "disabled");
+          else $uri = build_args($action, $params, "prizes", $prize_filter | $v, $Prize);
           $uri_list[] = $uri;
         }
         echo "<p class=\"header\">Show prizes: " . implode(" // ", $uri_list) . ".</p>\n";
       foreach (array_keys($methods) as $method) {
         $Method = preg_replace('/_/', ' ', ucfirst($method));
         if ($method == $sort) $uri = " $Method";
-        else $uri = build_args($params, "sort", $method, $Method);
+        else $uri = build_args($action, $params, "sort", $method, $Method);
         $uri_list[] = $uri;
       }
       echo "<p class=\"header\">Sort by: " . implode(" // ", $uri_list) . "</p>\n";
       foreach (array_keys($formats) as $fmt) {
         $Fmt = ucfirst($formats[$fmt][1]);
         if ($fmt == $format) $uri = " $Fmt";
-        else $uri = build_args($params, "format", $fmt, $Fmt);
+        else $uri = build_args($action, $params, "format", $fmt, $Fmt);
         $uri_list[] = $uri;
       }
       echo "<p class=\"header\">Show: " . implode(" // ", $uri_list) . "</p>\n";
index dd0f7dc..58c4133 100644 (file)
@@ -74,6 +74,8 @@
   }
 
   function module_raikogram($action, $args) {
+    global $uri_root;
+
     if ($_POST['edit_raikogram']) {
       if (edit_raikogram($_POST["race_id"])) unset($_POST);
     }
@@ -88,8 +90,7 @@
     foreach ($races as $race) {
       $id = $race->getId();
       $name = $race->getName();
-      /* XXX */
-      $url = preg_replace('/&action=\d+/', '', $_SERVER['REQUEST_URI']) . "&action=$id";
+      $url = "$uri_root/raikogram/$id";
       echo "<p><a href=\"$url\">$name</a></p>\n";
     }
     form();
index 09f251d..be45881 100644 (file)
@@ -36,6 +36,8 @@
   }
 
   function module_ship($action, $args) {
+    global $uri_root;
+
     if ($_POST['add_ship']) {
       if (add_ship($_POST["competitor_id"], $_POST["hull_id"], $_POST["name"])) unset($_POST);
     }
@@ -71,7 +73,7 @@
     }
     form();
     echo "<p>Add a new ship: ";
-    echo "<a href=\"?module=hull\">Hull:</a> <select name=\"hull_id\">";
+    echo "<a href=\"$uri_root/hull\">Hull:</a> <select name=\"hull_id\">";
     option("hull_id", 0, "");
     foreach ($hulls as $hull) {
       $id = $hull->getId();
@@ -79,7 +81,7 @@
       option("hull_id", $id, $name);
     }
     echo "</select>\n";
-    echo "<a href=\"?module=competitor\">Competitor:</a> <select name=\"competitor_id\">";
+    echo "<a href=\"$uri_root/competitor\">Competitor:</a> <select name=\"competitor_id\">";
     option("competitor_id", 0, "");
     foreach ($competitors as $competitor) {
       $id = $competitor->getId();
index 1f608fa..f40fbfd 100644 (file)
@@ -25,6 +25,8 @@
   }
 
   function module_station($action, $args) {
+    global $uri_root;
+
     if ($_POST['add_station']) {
       if (add_station($_POST["system_id"], $_POST["type"], $_POST["name"])) unset($_POST);
     }
@@ -50,7 +52,7 @@
     }
     form();
     echo "<p>Add a new station: ";
-    echo "<a href=\"?module=system\">System:</a> <select name=\"system_id\">";
+    echo "<a href=\"$uri_root/system\">System:</a> <select name=\"system_id\">";
     option("system_id", 0, "");
     foreach ($systems as $system) {
       $id = $system->getId();
index 12b874e..ef292a4 100644 (file)
@@ -2,10 +2,9 @@
 
   class BuckyballObject extends BaseObject {
     function getURL() {
-      /* XXX */
+      global $uri_root;
       $class = get_class($this->getPeer());
-      return sprintf("?module=%s&action=%s", urlencode(strtolower($class::OM_CLASS)), $this->getId());
-      return sprintf("/%s/%s/%d", urlencode(strtolower($class::OM_CLASS)), urlencode($this->getName()), $this->getId());
+      return sprintf("$uri_root/%s/%s", urlencode(strtolower($class::OM_CLASS)), $this->getId());
     }
 
     function getLink($blurb = null, $url = null, $classes = null) {