--- /dev/null
+RewriteEngine on
+Rewritecond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.+) index.php [L]
<?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"));
-<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) {
<?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>
<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);
?>
<?php
function module_lap($action, $args) {
+ global $uri_root;
$rq = new RaceQuery;
$races = $rq->find();
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) {
-<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";
}
function module_raikogram($action, $args) {
+ global $uri_root;
+
if ($_POST['edit_raikogram']) {
if (edit_raikogram($_POST["race_id"])) unset($_POST);
}
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();
}
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);
}
}
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();
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();
}
function module_station($action, $args) {
+ global $uri_root;
+
if ($_POST['add_station']) {
if (add_station($_POST["system_id"], $_POST["type"], $_POST["name"])) unset($_POST);
}
}
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();
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) {