<?php
/**
* Bootstrap file
*
* This loads all necessary framework classes and instantiates the framework object
* Parse the request, load the appropriate module/controller/action and run the request
* Pass response to View object and display
*
* LICENSE: This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* @package Phritz
* @link http://phritz.fritz-works.com
* @author Michael Collado <mrfritz379@gmail.com>
* @copyright 2006
* @version 0.0.1a
**/
date_default_timezone_set('America/Chicago');
$startTime = microtime(true);
/**
* Constant definitions
*/
define('PHRITZ_ROOT', realpath(dirname(__FILE__)));
$url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
//get rid of trailing slash in the root url
if (substr($url, (strlen($url) - 1), 1) == '/') $url = substr($url, 0, (strlen($url) - 1));
define('PHRITZ_URL', $url);
//Integer group id for anonymous users
define('PHRITZ_GROUP_ANONYMOUS', 3);
//if using request encryption, what is the name of the GET/POST parameter that holds encrypted data
define('PHRITZ_SHIELD_KEY', 'phritzvar');
//Name the default language to be used on the site
define('PHRITZ_DEFAULT_LANG', 'EN');
/**
* Set debug mode for the site-- This sets the error printing, debugging, etc.
* For development, set this to 1
* For production, set this to 0.
*/
define('PHRITZ_DEBUG_MODE', 1);
/**
* End Constant definitions
*/
/**
* Parse the path to define module/controller/action request
*/
//scrap any trailing directory path information in case we are not in the document root
$scrap = dirname($_SERVER['PHP_SELF']);
if ($scrap !== '/') $path = str_replace($scrap, '', $_SERVER['REQUEST_URI']);
else $path = $_SERVER['REQUEST_URI'];
//get rid of the querystring from the request uri
if (strpos($path, '?') !== false) $path = substr($path, 0, strpos($path, '?'));
//if there is a leading / we want to get rid of it
if (substr($path, 0, 1) == '/') $path = substr($path, 1, (strlen($path)-1));
//split the remaining string by /. The request should be in the format module/controller/action.
$args = preg_split("/\//", $path);
$arg_count = count($args);
if ($arg_count > 0 && !empty($args[0])) $_REQUEST['mod'] = $args[0];
if ($arg_count > 1 && !empty($args[1])) $_REQUEST['controller'] = $args[1];
if ($arg_count > 2 && !empty($args[2])) $_REQUEST['action'] = $args[2];
/**
* Begin processing the current request
* Instantiate required objects: Phritz framework, request, sessionhandler, securityguard,
* config array, view
*/
require_once 'include/functions.php';
require_once 'kernel/Phritz.class.php';
$Phritz =& Phritz::getInstance();
$PhritzReq =& Phritz::getRequest();
$PhritzConfig =& Phritz::getConfig();
$PhritzView =& Phritz::getView();
$PhritzLang = Phritz::getLang();
/**
* Set some template parameters
*/
$PhritzView->setParam('PHRITZ_URL', PHRITZ_URL);
$PhritzView->setParam('PHRITZ_ROOT', PHRITZ_ROOT);
$PhritzView->setParam('Request', $PhritzReq->toArray());
$PhritzView->setParam('Lang', $PhritzLang);
if (($mod = $PhritzReq->getVar('mod')) == false) {
$mod = $PhritzConfig['DefaultModule']; //load default module if none requested
$PhritzReq->setVar('mod', $mod);
}
if (($method = $PhritzReq->getVar('action')) === false) { //get controller's default action
$method = 'index';
$PhritzReq->setVar('action', $method);
}
/**
* Is this a request for a WSDL file?
*/
if ($PhritzReq->getVar('wsdl') !== false) {
header('Content-Type: text/xml');
echo file_get_contents(PHRITZ_ROOT."/modules/$mod/$mod.wsdl");
die();
}
/**
* Load module
*/
Phritz::debug("Requesting service $mod::$ct::$method");
try {
Phritz::importModule($mod);
}catch (PhritzException $e) {
Phritz::debug('Module request exception: '.$e->getMessage());
error_log($e->getMessage());
trigger_error($PhritzLang['server_error'], E_USER_ERROR);
}
if (($ct = $PhritzReq->getVar('controller')) === false) { //load default controller if none requested
$ct = $PhritzConfig[$mod]['DefaultController'];
$PhritzReq->setVar('controller', $ct);
}
/**
* Execute the requested action, pass the returned response object to the appropriate view *object
*/
require_once PHRITZ_ROOT."/modules/$mod/actions/$ct.php";
$controller = new $ct($PhritzReq, $PhritzView, $PhritzLang);
try {
$r = $controller->handle($mod, $method);
} catch (PhritzDatabaseException $e) {
error_log($e->getMessage());
Phritz::debug('Database Exception caught: '.$e->getMessage());
$r = $e;
} catch (Exception $e) {
error_log($e->getMessage());
Phritz::debug('Unknown Exception caught: '. $e->getMessage());
$r = $e;
}
$PhritzView->assign('OUTPUT_MESSAGE', $controller->getOutputArray());
$PhritzView->formatResponse($PhritzReq, $r);
/**
* umm...Display
*/
$PhritzView->display();
?>
|