<?php

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . '/../' . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . '/../classes/');
require_once 'data/mysql-connection.class.php';
require_once 'context/stoolball-settings.class.php';
require_once 'context/site-context.class.php';
require_once 'stoolball/match-manager.class.php';
require_once 'xhtml/html.class.php';
require_once "Zend/Feed.php";
# set up error handling, unless local and using xdebug
$settings = new StoolballSettings();
if (!SiteContext::IsDevelopment()) {
    require_once 'page/exception-manager.class.php';
    require_once 'page/email-exception-publisher.class.php';
    $errors = new ExceptionManager(array(new EmailExceptionPublisher($settings->GetTechnicalContactEmail())));
    # Use production settings recommended by
    # http://perishablepress.com/advanced-php-error-handling-via-htaccess/
    # Not possible to set in .htaccess because PHP is running as a CGI. This is the
    # next best thing.
    ini_set("display_startup_errors", "off");
    ini_set("display_errors", "off");
    ini_set("html_errors", "off");
    ini_set("log_errors", "on");
    ini_set("ignore_repeated_errors", "off");
    ini_set("ignore_repeated_source", "off");
    ini_set("report_memleaks", "on");
    ini_set("track_errors", "on");
    ini_set("docref_root", "0");
    ini_set("docref_ext", "0");
    ini_set("error_reporting", "-1");
    ini_set("log_errors_max_len", "0");
<?php

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . '/../classes/' . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . "/../");
require_once 'context/stoolball-settings.class.php';
require_once 'data/mysql-connection.class.php';
require_once 'http/short-url-manager.class.php';
$settings = new StoolballSettings();
$db = new MySqlConnection($settings->DatabaseHost(), $settings->DatabaseUser(), $settings->DatabasePassword(), $settings->DatabaseName());
$short_url_manager = new ShortUrlManager($settings, $db);
$real_url = $short_url_manager->ParseRequestUrl();
$db->Disconnect();
if (is_array($real_url)) {
    $hidden_get_vars = array_combine($real_url['param_names'], $real_url['param_values']);
    $_GET = array_merge($_GET, $hidden_get_vars);
    $_SERVER['PHP_SELF'] = '/' . $real_url['script'];
    require $real_url['script'];
} else {
    # Hard-coded URLs which redirect to WordPress and so can't be in .htaccess
    if (strtolower(trim($_SERVER['REQUEST_URI'], '/')) == "insurance") {
        header("Location: /manage/insurance/");
        exit;
    }
    # If page requested starting with /news, make WordPress think it was /category/news
    if (substr(strtolower(trim($_SERVER['REQUEST_URI'], '/')), 0, 4) == "news") {
        if ($_SERVER['REQUEST_URI'] == "/news") {
            $_SERVER['REQUEST_URI'] = "/news/";
        }
        # Keeps the /category bit invisible if just /news requested
        $_SERVER['REQUEST_URI'] = "/category" . $_SERVER['REQUEST_URI'];
    }
    # Does it look suspicious?