|
// +----------------------------------------------------------------------+
//
// $Id: FlexyFramework.php,v 1.8 2003/02/22 01:52:50 alan Exp $
//
// Description
// A Page (URL) to Object Mapper
// Initialize Static Options
require_once 'PEAR.php';
require_once 'HTML/FlexyFramework/Page.php';
require_once 'HTML/FlexyFramework/Error.php';
// To be removed ?? or made optional or something..
error_reporting(E_ALL);
//PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_ERROR);
/*
* Initialize Globals - since PEAR::setErrorHandling doesnt accept static methods..
* this is currently only used to store the error object.
*/
$GLOBALS['_HTML_FLEXYFRAMEWORK'] = array();
$GLOBALS['_HTML_FLEXYFRAMEWORK']['calls'] = 0;
$m = explode(' ',microtime());
$GLOBALS['_HTML_FLEXYFRAMEWORK']['START'] = $m[0] + $m[1];
/**
* The URL to Object Mapper
*
* Usage:
* Create a index.php and add these lines.
*
* ini_set("include_path", "/path/to/application");
* require_once 'HTML/FlexyFramework.php';
* HTML_FlexyFramework::factory(array("dir"=>"/where/my/config/dir/is");
*
*
* the path could include pear's path, if you dont install all the pear
* packages into the development directory.
*
* It attempts to load a the config file from the includepath,
* looks for ConfigData/default.ini
* or ConfigData/{hostname}.ini
* if your file is called staging.php rather than index.php
* it will try staging.ini
*
*/
class HTML_FlexyFramework {
/**
* The factory method
*
* do all the hard work.
*
*
* @param array config vars (see _loadConfig for values)
*
* @return none
* @access public
* @static
*/
function factory($config = array())
{
$GLOBALS[__CLASS__] = new HTML_FlexyFramework;
// load config
$GLOBALS[__CLASS__]->_loadConfig($config);
// initialize and load config
$GLOBALS[__CLASS__]->_init();
// load and initialize the Auth Class
$GLOBALS[__CLASS__]->_getAuth();
// run the request parser.
if (@$config['run']) {
$GLOBALS[__CLASS__]->_run($config['run'],false);
} else {
$GLOBALS[__CLASS__]->_run($_SERVER['REQUEST_URI'],false);
}
}
/**
* The PEAR Benchmark_Timer Class (if debug is set to on)
*
* @var object
* @access public
*/
var $timer = NULL;
/**
* Quality Redirector
*
* Usage in a page.:
* HTML_FlexyFramework::run('someurl/someother',array('somearg'=>'xxx'));
* ...do clean up...
* exit; <- dont cary on!!!!
*
* You should really
*
* @param string redirect to url
* @param array Args Optional any data you want to send to the next page..
*
*
* @return false
* @access public
* @static
*/
function run($request,$args=array()) {
$GLOBALS[__CLASS__]->_run($request,true,$args);
return false;
}
/**
* The main execution loop
*
* recursivly self called if redirects (eg. return values from page start methods)
*
* @param string from $_REQUEST or redirect from it'self.
* @param boolean isRedirect = is the request a redirect
*
*
* @return none|boolean|string|int|object Description
* @access public|private
* @see see also methods.....
*/
function _run($request,$isRedirect = false,$args = array())
{
// clean the request up.
$GLOBALS['_HTML_FLEXYFRAMEWORK']['calls']++;
if ($GLOBALS['_HTML_FLEXYFRAMEWORK']['calls'] > 5) {
// to many redirections...
trigger_error("FlexyFramework:: too many redirects - backtrace me!",E_USER_ERROR);
exit;
}
$newRequest = $this->_getRequest($request,$isRedirect);
// find the class/file to load
list($classname,$subRequest) = $this->staticGetClassName($newRequest,FALSE);
$this->debug("SUB REQUEST: $subRequest");
// assume that this was handled by getclassname
if (!$classname) {
return;
}
// make page data/object accessable at anypoint in time using this
$classobj = &PEAR::getStaticProperty('HTML_FlexyFramework', 'page');
$classobj = new $classname;
$classobj->auth = &PEAR::getStaticProperty('Auth','singleton');
$bits = explode(basename($_SERVER["SCRIPT_FILENAME"]), $_SERVER["SCRIPT_NAME"]);
$classobj->baseURL = $bits[0].basename($_SERVER["SCRIPT_FILENAME"]);
$classobj->rootURL = dirname($classobj->baseURL);
$classobj->rootURL = ($classobj->rootURL == '/') ? '' : $classobj->rootURL;
//echo "ROOT: {$classobj->rootURL} ";exit;
//if ((strlen( $classobj->rootURL) > 1) && ($classobj->rootURL{strlen($classobj->rootURL)-1} != '/')) {
// $classobj->rootURL .= '/';
// }
$classobj->request = $newRequest;
$classobj->timer = &$this->timer;
$this->loadSession($classobj);
if (!method_exists($classobj, 'getAuth')) {
return $this->fatalError("class $classname does not have a getAuth Method");
}
/* check auth on the page */
if (is_string($redirect = $classobj->getAuth())) {
$this->debug("GOT AUTH REDIRECT".$redirect);
$this->_run($redirect,TRUE);
return;
}
// used HTML_FlexyFramework::run();
if ($redirect === false) {
return;
}
// allow the page to implement caching (for the full page..)
// although normally it should implement caching on the outputBody() method.
if (method_exists($classobj,"getCache")) {
if ($classobj->getCache()) {
return;
}
}
/* allow redirect from start */
if (method_exists($classobj,"start")) {
if (is_string($redirect = $classobj->start($subRequest,$isRedirect,$args))) {
$this->debug("REDIRECT $redirect
");
$this->_run($redirect,TRUE);
return;
}
}
// used HTML_FlexyFramework::run();
if ($redirect === false) {
return;
}
/* load the modules
* Modules are common page components like navigation headers etc.
* that can have dynamic code.
*
*/
if (method_exists($classobj,'loadModules')) {
if (is_string($redirect = $classobj->loadModules($subRequest))) {
$this->debug("REDIRECT $redirect
");
$this->_run($redirect,true);
return;
}
}
if ($this->timer) {
$this->timer->setMarker("After $request loadModules Modules");
}
/* output it */
if (method_exists($classobj,'output')) {
$classobj->output();
}
if ($this->timer) {
$this->timer->setMarker("After $request output");
$this->timer->stop();
}
}
/**
* map the request into an object and run the page.
*
* The core of the work is done here.
*
*
* @param request the request string
* @param boolean isRedirect - indicates that it should not attempt to strip the .../index.php from the request.
*
* @access private
*/
function _getRequest($request, $isRedirect)
{
$options = PEAR::getStaticProperty('HTML_FlexyFramework','options');
if (@$options['cli']) {
return $request;
}
$startRequest = $request;
$rr = explode('?', $request);
$request = $rr[0];
$this->debug("INPUT REQUEST $request
");
if (!$isRedirect) {
$subreq = substr($request,0,strlen($options['base_url']));
if ($subreq != substr($options['base_url'],0,strlen($subreq))) {
$this->fatalError(
"Configuration error: Got base of $subreq which does not
match configuration of: {$options['base_url']} ");
}
$request = substr($request,strlen($options['base_url']));
}
// strip front
// echo "REQUEST WAS: $request
";
// $request = preg_replace('/^'.preg_quote($base_url,'/').'/','',trim($request));
// echo "IS NOW: $request
";
// strip end
// strip valid html stuff
//$request = preg_replace('/\/[.]+/','',$request);
$request = preg_replace('/^[\/]*/','',$request);
$request = preg_replace('/\?.*$/','',$request);
$request = preg_replace('/[\/]*$/','',$request);
$request = preg_replace('/\.([a-z]+)$/','',$request);
if (!$request && !$isRedirect) {
if (@$options['base_url'] && (strlen($startRequest) < strlen($options['base_url'] ))) {
// needs to handle https + port
$http = ((!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on')) ? 'https' : 'http';
$sp = '';
if (!empty($_SERVER['SERVER_PORT'])) {
if ((($http == 'http') && ($_SERVER['SERVER_PORT'] == 80)) || (($http == 'https') && ($_SERVER['SERVER_PORT'] == 443))) {
// standard ports..
} else {
$sp .= ':'.((int) $_SERVER['SERVER_PORT']);
}
}
$host = !empty($_SERVER["HTTP_X_FORWARDED_HOST"]) ? $_SERVER["HTTP_X_FORWARDED_HOST"] : $_SERVER["HTTP_HOST"];
header('Location: '.$http.'://'.$host .$sp . $options['base_url']);
exit;
}
$request = "";
}
$this->debug("OUTPUT REQUEST $request
");
return $request;
}
/**
* load Authentication
*
* Load the use specified Authentication module (eg. PEAR auth.)
* and store it in PEAR::getStaticProperty('Auth','singleton');
*
* @see see also methods.....
*/
function _getAuth() {
$auth = &PEAR::getStaticProperty('Auth','singleton');
if (!$auth) {
$options = PEAR::getStaticProperty('HTML_FlexyFramework','options');
// disable authentication!!
if ($options['auth_class_file'] === false) {
return;
}
if (!$options['auth_class_file']) {
$this->fatalError("No Auth file (auth_class_file) found");
exit;
}
require_once($options['auth_class_file']);
if ($options['auth_class'] == 'Auth') {
// pear auth..
$authOptions = PEAR::getStaticProperty('Auth','options');
//print_R($authOptions);
$auth = new Auth(
$authOptions['driver'],
isset($authOptions['option']) ? $authOptions['option'] : $authOptions,
'', false);
if (PEAR::isError($auth)) {
$this->fatalError("Auth config error " . $auth->getMessage());
}
// if we have a sessoin. or user/pass - start auth..
if (isset($_REQUEST[session_name()]) ||
isset($_COOKIE[session_name()]) ||
isset($_REQUEST['username']) ||
isset($_REQUEST['password'])) {
$auth->start();
}
} else {
$auth = new $options['auth_class']();
}
}
if (@$_GET["logout"]) {
$auth->logout();
}
// only run authentication check if session has started..
if (isset($_REQUEST['sess'])) {
$auth->getAuth();
}
}
/**
* get the Class name and filename to load
*
* Parses the request and converts that into a File + Classname
* if the class doesnt exist it will attempt to find a file below it, and
* call that one with the data.
* Used by the module loader to determine the location of the modules
*
* @param request the request string
* @param boolean showError - if false, allows you to continue if the class doesnt exist.
*
*
* @return array classname, filepath
* @access private
* @static
*/
function staticGetClassName($request,$showError=TRUE)
{
if ($request == "error") {
return array("HTML_FlexyFramework_Error","");
}
$options = PEAR::getStaticProperty('HTML_FlexyFramework','options');
$request_array=explode("/",$request);
$original_request_array = $request_array;
$sub_request_array = array();
$l = count($request_array)-1;
if ($l > 10) {
PEAR::raiseError("Request To Long");
return array("HTML_FlexyFramework_Error","");
}
$classname='';
// tidy up request array
if ($request_array) {
foreach(array_keys($request_array) as $i) {
$request_array[$i] = preg_replace('/[^a-z0-9]/i','_',urldecode($request_array[$i]));
}
}
// echo "
"; print_r($request_array);
// technically each module should do a check here... similar to this..
if (@$request_array[0] == 'FlexyFramework') {
$rr = $request_array;
array_shift($rr);
//print_R($rr);
if (@file_exists(dirname(__FILE__)."/FlexyFramework/". implode('/',$rr).'.php')) {
require_once dirname(__FILE__)."/FlexyFramework/". implode('/',$rr) .'.php';
$classname = 'HTML_FlexyFramework_'. implode('_',$rr);
// echo $classname;
} else {
$this->fatalError("could not find: ".dirname(__FILE__).'/FlexyFramework/'.implode('/',$rr).'.php');
}
}
if (!$classname) {
for ($i=$l;$i >-1;$i--) {
$location = implode('/',$request_array) . ".php";
HTML_FlexyFramework::debug("CHECK $location
");
if (@file_exists($options['base_dir']."/{$location}")) {
require_once $options['base_dir']."/{$location}";
$classname = $options['class_prefix'] . implode('_',$request_array);
break;
}
$sub_request_array[] = $original_request_array[$i];
unset($request_array[$i]);
unset($original_request_array[$i]);
}
}
// is this really needed here!
$classname = preg_replace('/[^a-z0-9]/i','_',$classname);
HTML_FlexyFramework::debug("CLASSNAME is $classname");
// got it ok.
if ($classname && class_exists($classname)) {
HTML_FlexyFramework::debug("using $classname");
//print_r($sub_request_array);
return array($classname,implode('/',array_reverse($sub_request_array)));
}
// stop looping..
if ($showError) {
PEAR::raiseError("INVALID REQUEST: \n $request FILE:".$options['base_dir']. "/{$location} CLASS:{$classname}");
return array("HTML_FlexyFramework_Error","");
}
// try {project name}.php
if (@file_exists($options['base_dir'].'.php')) {
$classname = basename($options['base_dir']);
require_once $options['base_dir'].'.php';
if (!class_exists($classname)) {
HTML_FlexyFramework::fatalError(
"{$options['base_dir']}.php did not contain class $classname");
}
}
// got projectname.php
if ($classname && class_exists($classname)) {
HTML_FlexyFramework::debug("using $classname");
//print_r($sub_request_array);
return array($classname,implode('/',array_reverse($sub_request_array)));
}
if (!@file_exists($options['base_dir']."/index.php")) {
HTML_FlexyFramework::fatalError(
"can not find {$options['base_dir']}.php or {$options['base_dir']}/index.php");
}
require_once($options['base_dir']."/index.php");
$classname = $options['class_prefix'] . 'index';
if (!class_exists($classname)) {
HTML_FlexyFramework::fatalError("can not find class {$classname} in 'base_dir'/index.php = {$options['base_dir']}/index.php");
}
HTML_FlexyFramework::debug("using $classname");
//print_r($sub_request_array);
return array($classname,implode('/',array_reverse($sub_request_array)));
}
/**
* Initialize the error handler and starts the timer if used.
*
* Calls the config loader
* sets up the error handling page object.
*
*
* @access private
*/
function _init() {
/* have I been initialized */
global $_HTML_FLEXYFRAMEWORK;
$options = PEAR::getStaticProperty('HTML_FlexyFramework','options');
if (get_magic_quotes_gpc() && @!$options['cli']) {
$this->fatalError(
"magic quotes is enabled add the line
php_value magic_quotes_gpc 0
to your .htaccess file
(Apache has to be configured to "AllowOverride Options AuthConfig" for the directory)
");
}
// set up error handling -
$_HTML_FLEXYFRAMEWORK['Error'] = new HTML_FlexyFramework_Error;
/// fudge work around bugs in PEAR::setErrorHandling(,)
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK;
$GLOBALS['_PEAR_default_error_options'] = array($_HTML_FLEXYFRAMEWORK['Error'],'raiseError');
$options = PEAR::getStaticProperty('HTML_FlexyFramework','options');
if (@$options['debug']) {
require_once("Benchmark/Timer.php");
$this->timer = new BenchMark_Timer(true);
}
}
/**
* load the config file in PEAR::getStaticProperty($block,'options');
* where $block is the class name to load a config for.
*
* Follows a number of rules to locate the config file.
*
* Parses the input config defaults are
* extension => ini
* path => {somewhere in the include path}/ConfigData
* file => default
* if the boot loader was staging the file = staging
* will also look for hostname.{extension}
* driver => '' (default is to use parse_ini_file
* if used it will try and use PEAR's Config class.
* * => passed to PEAR's config class
*
* @access private
*/
function _loadConfig( $config=array() )
{
global $_HTML_FLEXYFRAMEWORK;
$config_path = @$config['path'];
$file = @$config['file'];
$extension = @$config['extension'];
if ($extension == '') {
$extension = 'ini';
}
if ($config_path == '') {
$path = ini_get("include_path");
/* need to do windows check for ":" here */
$paths = explode(":",$path );
array_unshift($paths,dirname($_SERVER['SCRIPT_FILENAME']));
foreach($paths as $p) {
if (file_exists($p."/ConfigData") && @is_dir($p."/ConfigData")) {
$config_path = $p;
break;
}
}
if ($config_path == '') {
return $this->_mergeConfig( $config);
//$this->fatalError("Could not find ConfigData directory in include path $path");
}
$config_path = $config_path."/ConfigData";
}
if (!$file) {
$file = "default";
if (preg_match("/\/staging.php$/",$_SERVER["SCRIPT_NAME"] )) {
$file= "staging";
}
// try loading host specific file.
$host = preg_replace("/\:[0-9]+$/",'',@$_SERVER["HTTP_HOST"]);
$host = preg_replace("/[^a-z0-9.-]+/i",'',$host);
$tryfile = "{$config_path}/{$host}.{$file}.{$extension}";
$_HTML_FLEXYFRAMEWORK['configattempted'] = $tryfile ;
if (@file_exists($tryfile)) {
$file = "{$host}.{$file}";
}
}
$tryfile = "{$config_path}/{$file}.{$extension}";
if (!@file_exists($tryfile)) {
//echo "NO CONFIG? $tryfile";print_r($config);
return $this->_mergeConfig( $config);
//$this->fatalError("Unable to load Config File {$tryfile}");
}
if (!@file_exists("{$config_path}/.htaccess")) {
$this->fatalError("There is no htaccess file in the configuration folder it should contain
".
nl2br(htmlspecialchars(
"
order deny,allow
deny from ALL
")));
}
// ok done finding the file, now try and load it.
if (isset($config['driver'])) {
require_once 'Config.php';
$conf = new Config($config['driver']);
$conf->parseInput($tryfile,$config);
$blocks = $conf -> getBlocks( "/" ) ;
foreach( $blocks as $block ) {
$data[$block] = $conf -> getValues( "/".$block ) ;
}
} else {
$data = parse_ini_file("{$config_path}/{$file}.ini",TRUE);
}
$_HTML_FLEXYFRAMEWORK['configloaded'] = $tryfile;
// overlay the config..
//echo "";print_r($config); print_r($data);
foreach($config as $k=>$v) {
// flat a=>b
if (!is_array($v)) {
$data['HTML_FlexyFramework'][$k] = $v;
continue;
}
if (!isset($data[$k])) {
$data[$k] = $v;
continue;
}
foreach($v as $kk=>$vv) {
$data[$k][$kk] = $vv;
}
}
return $this->_mergeConfig($data);
}
function _mergeConfig($overlay) {
$is_internal = preg_match('/^\/FlexyFramework/',@$_SERVER["PATH_INFO"]);
foreach($overlay as $k=>$v) {
if (!is_array($k)) {
$overlay['HTML_FlexyFramework'][$k] = $v;
}
}
// standard overlays:
// ['DB_DataObject']['database'] // pretty certian... (variable)
// ['HTML_FlexyFramework']['project'] // must (fixed)
// ['HTML_FlexyFramework']['base_dir'] // if index.php is outside off application....
if (!isset($overlay['HTML_FlexyFramework']['project'])) {
if (!isset($overlay['HTML_FlexyFramework']['class_prefix'])) {
echo "";print_R($overlay);
$this->fatalError("usage:
HTML_FlexyFramework::factory(array(
'project'=>'NameOfProject',
));");
}
$overlay['HTML_FlexyFramework']['project'] = substr($overlay['HTML_FlexyFramework']['class_prefix'],0,-1);
}
$config['HTML_FlexyFramework']['project'] = $overlay['HTML_FlexyFramework']['project'];
$bits = explode(basename($_SERVER["SCRIPT_FILENAME"]), $_SERVER["SCRIPT_NAME"]);
$config['HTML_FlexyFramework']['base_url'] = $bits[0].basename($_SERVER["SCRIPT_FILENAME"]);
$config['HTML_FlexyFramework']['base_dir'] = realpath(dirname($_SERVER["SCRIPT_FILENAME"])) .'/'. $config['HTML_FlexyFramework']['project'];
$config['HTML_FlexyFramework']['class_prefix'] = $config['HTML_FlexyFramework']['project'] . '_';
$config['HTML_FlexyFramework']['auth_class_file'] = 'Auth.php';
$config['HTML_FlexyFramework']['auth_class'] = 'Auth';
$config['HTML_FlexyFramework']['debug'] = 0;
// [ DB_DataObjects ]
//$config['DB_DataObject']['database'] = @$overlay['HTML_FlexyFramework']['database'];
// the default locations are:
// a) dirname(index.php) / DataObjects
switch (true) {
case file_exists($config['HTML_FlexyFramework']['base_dir'] . '/DataObjects'):
$cl = $config['HTML_FlexyFramework']['base_dir'] . '/DataObjects';
$cp = $config['HTML_FlexyFramework']['project'] . '_DataObjects_';
$rp = $config['HTML_FlexyFramework']['project'] . '/DataObjects/';
break;
case file_exists(dirname($_SERVER["SCRIPT_FILENAME"]) . '/DataObjects'):
default:
$cl = dirname($_SERVER["SCRIPT_FILENAME"]) . '/DataObjects';
$cp = 'DataObjects_';
$rp = 'DataObjects/';
break;
}
if (isset($overlay['HTML_FlexyFramework']['databasename'])) {
$config['DB_DataObject']['ini_'.$overlay['HTML_FlexyFramework']['databasename']] =
$cl.'/'.$overlay['HTML_FlexyFramework']['databasename'] . '.ini';
}
//$config['DB_DataObject']['schema_location'] = $cl;
$config['DB_DataObject']['class_location'] = $cl;
$config['DB_DataObject']['require_prefix'] = $rp;
$config['DB_DataObject']['class_prefix'] = $cp;
$config['DB_DataObject'] = (isset($overlay['DB_DataObject']) ? $overlay['DB_DataObject'] : array()) +
$config['DB_DataObject'];
//echo '';print_r($config);
// [ Auth ]
//echo '';print_r($overlay);
$config['Auth'] = isset($overlay['Auth']) ? $overlay['Auth'] : array();
if (!$config['Auth']) {
$config['Auth']['driver'] = isset($overlay['HTML_FlexyFramework']['Auth/driver']) ?
$overlay['HTML_FlexyFramework']['Auth/driver'] :
'File';
}
// in same folder as index.php...
switch($config['Auth']['driver']) {
case 'DB':
//echo "setting db?";
// echo '';print_r($overlay); echo '';print_r($config);
if (isset($overlay['HTML_FlexyFramework']['databasename']) &&
@$overlay['HTML_FlexyFramework']['DB_DataObject']['database_'.$overlay['HTML_FlexyFramework']['databasename']]) {
$config['Auth']['option']['dsn'] = $overlay['HTML_FlexyFramework']['DB_DataObject']['database_'.$overlay['HTML_FlexyFramework']['databasename']];
}
break;
case 'File':
$config['Auth']['option'] = isset($overlay['Auth']['option']) ?$overlay['Auth']['option'] : dirname($_SERVER["SCRIPT_FILENAME"]) . '/.htpasswd';
break;
}
//echo '';print_r($config); exit;
// [ HTML_Template_Flexy ]
// templates : 2 places:
//echo $config['HTML_FlexyFramework']['base_dir'];
$img_rewrite = '';
switch (true) {
// this is {project}/{Project}/templates (new standard)
case file_exists($config['HTML_FlexyFramework']['base_dir'] . '/templates'):
$td = $config['HTML_FlexyFramework']['base_dir'] . '/templates';
$imgbasedir = (dirname($_SERVER["SCRIPT_NAME"]) == '/') ? '' : dirname($_SERVER["SCRIPT_NAME"]);
$img_rewrite = $imgbasedir . '/'. $overlay['HTML_FlexyFramework']['project'] . '/templates/images/';
break;
// this is old standard...
case file_exists(dirname($_SERVER["SCRIPT_FILENAME"]) . '/templates'):
default:
//phpinfo();
$d = (dirname($_SERVER["SCRIPT_FILENAME"]) == '/') ? '' : dirname($_SERVER["SCRIPT_FILENAME"]) ;
$td = $d . '/templates';
$d = (dirname($_SERVER["SCRIPT_NAME"]) == '/') ? '' : dirname($_SERVER["SCRIPT_NAME"]) ;
$img_rewrite = $d . '/templates/images/';
break;
}
//echo $td ;
$config['HTML_Template_Flexy']['templateDir'] = $td;
// base it on the session directroy..
if (empty($overlay['cli']) &&empty( $overlay['HTML_Template_Flexy']['compileDir'])) {
$cd = ini_get('session.save_path') . '/' . $config['HTML_FlexyFramework']['project'];
$config['HTML_Template_Flexy']['compileDir'] = $cd;
}
// if translation2 config is set, use it..
if (isset($overlay['HTML_Template_Flexy']['Translation2'])) {
$config['HTML_Template_Flexy']['Translation2'] = $overlay['HTML_Template_Flexy']['Translation2'];
}
$config['HTML_Template_Flexy']['forceCompile'] = 0;
$config['HTML_Template_Flexy']['filters'] = 'Php,SimpleTags';
$config['HTML_Template_Flexy']['debug'] = 0;
$config['HTML_Template_Flexy']['useTokenizer'] = 1;
if ($img_rewrite) {
$img_rewrite = preg_replace('#^/+#','/',$img_rewrite); // strip extra prefixed slashes
$config['HTML_Template_Flexy']['url_rewrite'] = 'images/:'. $img_rewrite;
}
// [ Mail ]
$config['Mail']['debug'] = 0;
$config['Mail']['driver'] = 'smtp';
$config['Mail']['host'] = 'localhost';
$config['Mail']['port'] = 25;
// merge them...
foreach ($overlay as $class => $o) {
if (!is_array($o)) {
continue;
}
foreach($o as $k=>$v) {
// I think this prevents overriding of settings above..
if (is_array($v) && isset($config[$class][$k])) {
continue;
}
$config[$class][$k] = $v;
}
}
// apply them..
//echo "";print_R($config);
foreach ($config as $class => $o) {
$options = &PEAR::getStaticProperty($class,'options');
$options = $o;
}
// now test them!!!!!
//echo ""; print_R($config);
$options = &PEAR::getStaticProperty('DB_DataObject','options');
$dd = @$options['dont_die'];
$options['dont_die'] = true;
//echo '';print_r($overlay);
if (empty($options['nocheck'])) {
switch(true) {
case (isset($overlay['HTML_FlexyFramework']['databasename']) &&
@$config['DB_DataObject']['database_'.$overlay['HTML_FlexyFramework']['databasename']] ):
require_once 'DB/DataObject.php';
$x = new DB_Dataobject;
$x->_database = $overlay['HTML_FlexyFramework']['databasename'];
if (PEAR::isError($err = $x->getDatabaseConnection()) && !$is_internal) {
$this->fatalError("Configuration or Database Error: could not connect to Database,
Please check the value given to HTML_FlexyFramework, or set in
{$GLOBALS['_HTML_FLEXYFRAMEWORK']['configloaded']}
".$err->toString());
}
break;
case (isset($overlay['DB_DataObject']['database'])):
require_once 'DB/DataObject.php';
$x = new DB_Dataobject;
$x->_database = $overlay['DB_DataObject']['database'];
if (PEAR::isError($err = $x->getDatabaseConnection()) && !$is_internal) {
$this->fatalError("Configuration or Database Error: could not connect to Database,
Please check the value given to HTML_FlexyFramework, or set in
{$GLOBALS['_HTML_FLEXYFRAMEWORK']['configloaded']}
".$err->toString());
}
break;
case (empty($config['HTML_FlexyFramework']['no_database']) && !$is_internal):
// print_r($overlay);
$this->fatalError("Configuration Error: you must set up the database DSN either in:
HTML_FlexyFramework::factory(array(
'project'=>'NameOfProject',
'databasename'=>'nameofmyproject',
));
or inside this file:". dirname($_SERVER["SCRIPT_FILENAME"]) ."ConfigData/default.ini\n'
");
break;
}
}
$options['dont_die'] = $dd ;
// check that we have a writeable directory for flexy's compiled templates.
if (!empty($config['HTML_Template_Flexy']['compileDir']) &&
!file_exists($config['HTML_Template_Flexy']['compileDir']) &&
!$is_internal &&
!empty($overlay['cli']))
{
if (!file_exists($config['HTML_Template_Flexy']['compileDir'])) {
require_once 'System.php';
System::mkDir(array('-p',$config['HTML_Template_Flexy']['compileDir']));
clearstatcache();
}
if (!file_exists($config['HTML_Template_Flexy']['compileDir'])) {
$this->fatalError("Configuration Error: you specified a directory that does not exist for
[HTML_Template_Flexy]
CompileDir = {$config['HTML_Template_Flexy']['compileDir']}
\n"
);
}
}
if (!empty($config['HTML_Template_Flexy']['compileDir']) &&
!is_writeable(dirname($config['HTML_Template_Flexy']['compileDir'])) // check parent?!
&& !$is_internal
&& !@$overlay['HTML_FlexyFramework']['cli'])
{
$this->fatalError("Configuration Error: Please make sure the template cache directory is writeable
eg.
chmod 700 {$config['HTML_Template_Flexy']['compileDir']}
chgrp apache_user {$config['HTML_Template_Flexy']['compileDir']}
\n"
);
}
//echo "";print_R($config);
}
/**
* Initialize the sessoin handler
*
* Use [HTML_FlexyFramework]
* use_cookies = 1 to use cookies, otherwise
* sess=XXX will be appended to the url, (which is marginally more reliable)
*
* @access private
*/
function _initSession() {
global $_HTML_FLEXYFRAMEWORK;
$options = &PEAR::getStaticProperty('HTML_FlexyFramework','options');
$_HTML_FLEXYFRAMEWORK['sessionInit'] = 1;
if (!@$options['use_cookies']) {
ini_set("session.use_cookies",0);
ini_set("session.use_trans_sid",1);
}
//flush();
session_name("sess");
@session_start();
//flush();
}
/**
* connect the session var of the current page to a session variable.
* !!!!!! This should not be used, it was a stupid idea....!!!!!!!!!!!!
*
*
* @access public
*/
function loadSession(&$object) {
global $_HTML_FLEXYFRAMEWORK;
$classVars = get_class_vars(get_class($object));
if (@$classVars['session'] !== true) {
return;
}
if (empty($_HTML_FLEXYFRAMEWORK['sessionInit'])) {
HTML_FlexyFramework::_initSession();
}
//HTML_FlexyFramework::debug("SESSION :" .serialize($_SESSION));
$options = PEAR::getStaticProperty('HTML_FlexyFramework','options');
if (!@$_SESSION['HTML_FlexyFramework_Session']) {
$_SESSION['HTML_FlexyFramework_Session'] = array();
}
if (!isset($_SESSION['HTML_FlexyFramework_Session'][get_class($object)])) {
$_SESSION['HTML_FlexyFramework_Session'][get_class($object)] = new stdClass;
}
$object->session = &$_SESSION['HTML_FlexyFramework_Session'][get_class($object)];
}
/**
* Debugging
*
* @param string text to output.
* @access public
*/
function debug($output) {
$options = PEAR::getStaticProperty('HTML_FlexyFramework','options');
if (!@$options['debug']) {
return;
}
echo "HTML_FlexyFramework::debug".$output."
\n";
}
/**
* Raises a fatal error. - normally only used when setting up to help get the config right.
*
* @param string text to output.
* @access public
*/
function fatalError($msg,$showConfig = 0) {
global $_HTML_FLEXYFRAMEWORK;
$options = &PEAR::getStaticProperty('HTML_FlexyFramework','options');
if (@$options['fatalAction']) {
HTML_FlexyFramework::run($options['fatalAction'],$msg);
exit;
}
echo "$msg
configuration information";
if ($showConfig) {
print_r($_HTML_FLEXYFRAMEWORK);
print_r(PEAR::getStaticProperty('HTML_FlexyFramework','options'));
}
echo "";
exit;
}
}