<?php

// Define path to public directory
defined('APPLICATION_PUBLIC_PATH')
    || define('APPLICATION_PUBLIC_PATH', realpath(dirname(__FILE__)));
    
// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
	
// Define whether the application is running HTTPS or not
defined('APPLICATION_HTTPS')
	|| define('APPLICATION_HTTPS', (((isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== "off") || $_SERVER['SERVER_PORT'] == 443 /*|| strpos($_SERVER["HTTP_REFERER"], "https://") !== false*/) ? true : false));
	
// Define what protocol the application is running on
defined('APPLICATION_PROTOCOL')
	|| define('APPLICATION_PROTOCOL', ((APPLICATION_HTTPS) ? "https://" : "http://"));
    
// Define application vhost
defined('APPLICATION_VHOST')
	|| define('APPLICATION_VHOST', $_SERVER["SERVER_NAME"]);

// Try around to find the application's base URL
$dirname = "/".basename(dirname(dirname(__FILE__)));
$baseUrl = "/";
// Are we running in a subdirectory of the webserver?
if(strpos($_SERVER["REQUEST_URI"], $dirname) !== false)
{
	list($baseUrl) = explode($dirname, $_SERVER["REQUEST_URI"]);
	$baseUrl .= $dirname;
}

// Define application's base URL
defined('APPLICATION_BASEURL')
	|| define('APPLICATION_BASEURL', $baseUrl);
	
// Define the full application URL
defined('APPLICATION_URL')
	|| define('APPLICATION_URL', APPLICATION_PROTOCOL . APPLICATION_VHOST . APPLICATION_BASEURL);


// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path()
)));


/** Zend_Application */
require_once 'Zend/Application.php';
require_once 'Zend/Registry.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();