diff options
Diffstat (limited to 'tdd/tdd-protocol.php')
-rw-r--r-- | tdd/tdd-protocol.php | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/tdd/tdd-protocol.php b/tdd/tdd-protocol.php index 7130599..f8a6e3e 100644 --- a/tdd/tdd-protocol.php +++ b/tdd/tdd-protocol.php @@ -1,31 +1,39 @@ <?php -$prefix = $_GET['prefix']; -$round = (int)$_GET['round']; -$board = (int)$_GET['board']; - require_once('tdd-bootstrap.php'); refresh_board_database(); -$protocol = new Protocol($prefix, $round, $board); - -// security check -$html_filename = $protocol->get_filename(); -$len = strlen($html_filename); -$request_uri_ending = substr($_SERVER['REQUEST_URI'], -$len-1); -if($request_uri_ending != '/' . $html_filename) { +// parsing URI parts from full request string +$uri = explode('b-', basename($_SERVER['REQUEST_URI'])); +if (count($uri) < 2) { die('This script cannot be called directly!'); } -// -$deals_by_tables = load_deals_for_tables($prefix, $round, $board); -if (count($deals_by_tables) > 0) { - foreach($deals_by_tables as $table => $deal) { - $protocol->set_deal($table, $deal); +$board = (int)(array_pop($uri)); +$roundPrefix = implode('b-', $uri); + +try { + // GET parameters pre-parsed by mod_rewrite are used for HTML fallback + // in case {$prefix}{$round} combo is not matched against board DB + $protocol = new Protocol($_GET['prefix'], $_GET['round'], $board); + $html_filename = $protocol->get_filename(); + foreach ($board_database as $prefix => $rounds) { + foreach ($rounds as $round => $boards) { + if ($prefix . $round === $roundPrefix) { + $deals_by_tables = load_deals_for_tables($board_database, $prefix, $round, $board); + if (count($deals_by_tables) > 0) { + foreach($deals_by_tables as $table => $deal) { + $protocol->set_deal($table, $deal); + } + echo $protocol->output(); + exit(0); + } + } + } } - echo $protocol->output(); -} -else { readfile($html_filename); +} catch (Exception $e) { + header('HTTP/1.0 404 Not Found'); + die(); } |