From e80a2610d5b29b35fa7a787bb5e8ae72c856c2c8 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 14 Nov 2018 00:02:29 +0100 Subject: Matching tournament prefixes and rounds in board DB against URI parts, not the other way around. Fixes #1 --- tdd/tdd-protocol.php | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'tdd/tdd-protocol.php') 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 @@ 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(); } -- cgit v1.2.3