Location: PHPKode > projects > Tv.2 CMS > tv2engine/tv2-start.php
<?php
/**
 * This is a startup file for Tv2
 * 
 * @author Emilis Dambauskas (hide@address.com)
 * @copyright 2002–2003 Emilis Dambauskas under {@link http://opensource.org/licenses/artistic-license.php Artistic license}
 * @version $Id: tv2-start.php,v 1.6 2003/07/12 00:52:15 lunaticlt Exp $
 * @package tv2-engine
 */


/**
 * Loads a specified module
 *
 * @function loadTv2Module
 * @package tv2-engine
 * @return ref object module object
 * @param string name module name, specified in {@link $apps} variable in config
 * @use $apps
 */
function &loadTv2Module($name)
{
	global $apps;
	require_once($apps[$name]['dir'].$apps[$name]['classfile']);
	$mod = &new $apps[$name]['class']();
	return $mod;
}

/**
 * Returns array for the map
 *
 * @function mapTv2Module
 * @package tv2-engine
 * @return array array for the map
 * @param string name module name, specified in {@link $apps} variable in config
 * @param optional string method Module method to call (default 'dispatch')
 * @param optional string site_method Site method to use (default 'passthru')
 * @use $apps
 */
function mapTv2Module($name, $method = 'dispatch', $site_method = 'passthru')
{
	global $apps;
	$m = &$apps[$name];
	return array($m['dir'].$m['classfile'],$m['class'],$method,$site_method);
}


/**
 * Error logger object ({@link ctlErrors} class)
 * @var object $errors
 * @package pyramid-framework
 */
// 1. Load $errors first, because all other objects rely on this:
require_once(ENGINE_DIR.'ctlErrors.class.php');
$errors = &new ctlErrors();


/**
 * Database abstraction object ({@link Cdb} class)
 * @var object $db
 * @package pyramid-framework
 */
// 2. Use CDB as $db:
require_once(ENGINE_DIR.'cdb.class.php');
$db = &new cdb();
// 2.1. Bind CDB error reporting to $errors->add():
$config['db']['err_func']= array('errors', 'add');
// 2.2. Let's connect
$db->connect($config['db']);

/* Possible sample for PEAR::DB loading:
require_once('c:/apache/php/pear/DB.php');
$db = &new DB();
$db = $db->connect('mysql://root:@tcp+localhost/mydb');
*/


/**
 * Protocol abstraction object ({@link ctlHttpProtocol} class)
 * @var object $protocol
 * @package pyramid-framework
 */
// 3. Load $protocol:
require_once(ENGINE_DIR.'ctlHttpProtocol.class.php');
$protocol = &new ctlHttpProtocol();
// 3.1. Load request,client,server vars, start session and so on:
$protocol->start();


/**
 * URL mapper object ({@link ctlUrlMapper} class)
 * @var object $mapper
 * @package pyramid-framework
 */
// 4. Load $mapper:
require_once(ENGINE_DIR.'ctlUrlMapper.class.php');
$mapper = &new ctlUrlMapper();
// 4.1. load map into $mapper:
$mapper->loadMap($config['mapper']['map_file']);


/**
 * View Service object ({@link ctlViewService} class)
 * @var object $vs
 * @package pyramid-framework
 */
// 5. Load ViewService ($vs):
require_once(ENGINE_DIR.'ctlViewService.class.php');
$vs = &new ctlViewService();
// 5.1 Set up some common template vars:
$vs->setVar('burl', 'http://'.SITE_URL);


/**
 * Site object ({@link Site} class)
 * @var object $site
 * @package pyramid-framework
 */
// 6. Load $site:
require_once(CLASS_DIR.'site.class.php');
$site = &new site();

// 7. Get URL:
// 7.1. Lets extract partial URL from the $_SERVER['REQUEST_URI']:
if (preg_match('|^'.preg_quote(SITE_BURL, '|').'|', $protocol->getServerVar('REQUEST_URI')))
	$url = preg_replace('|^'.preg_quote(SITE_BURL, '|').'([^?&]*).*|', '\1', $protocol->getServerVar('REQUEST_URI'));
		
// 7.2. If URL not matched or empty, $url = index page
if (!@$url)
	$url = '/';

// 8. Map URL to module and output result:
$protocol->output($mapper->doMapping($url));

exit();
?>
Return current item: Tv.2 CMS