* it will try staging.ini
*
*/
-
+#[AllowDynamicProperties]
class HTML_FlexyFramework2 {
/**
// use $this->run($_SERVER['REQUEST_URI'],false); to manually boot it..
+ var $isDev = false; // is development mode (can debug sql?)
// derived.
var $cli = false; // from cli
var $run = false; // from cli
var $ext; // the striped extention.
var $dataObjectsOriginalIni = ''; // 1 houre..
+
+ var $locale = 'en';
// used to be $_GLOBALS[__CLASS__]
static $singleton;
*/
function loadModuleConfig($cfg)
{
- if (empty($cfg['enable'])) {
- return $cfg;
- }
+
+
$proj = $cfg['project'];
$rootDir = realpath(dirname($_SERVER["SCRIPT_FILENAME"]));
- foreach(explode(',',$cfg['enable']) as $m) {
- $cls = $proj.'_'. $m . '_Config';
+ $cls = $proj.'_Config';
+ if (file_exists($rootDir . '/'.str_replace('_','/', $cls). '.php')) {
+ require_once str_replace('_','/', $cls). '.php';
+ $c = new $cls();
+ if (method_exists($c,'init')) {
+ $cfg = $c->init($this,$cfg);
+ }
+ }
+
+ $mods = empty($cfg['enable']) ? array() : explode(',',$cfg['enable']);
+ array_unshift($mods,'');
+
+ foreach($mods as $m) {
+ $cls = $proj. (strlen($m) ? '_'. $m : '' ) . '_Config';
if (!file_exists($rootDir . '/'.str_replace('_','/', $cls). '.php')) {
continue;
if (!$this->cli) {
$bits[0] = str_replace('%2F','/',urlencode($bits[0]));
$this->baseURL = $bits[0] . basename($_SERVER["SCRIPT_FILENAME"]);
- //phpinfo();exit;
+
if (empty($_SERVER['SCRIPT_NAME'])) {
-
$this->baseURL = ''; // ??? this is if we replace top level...
}
}
}
$lang = isset($_COOKIE[$cfg['cookie']]) ? $_COOKIE[$cfg['cookie']] : $default;
-
+
+ //print_r($_COOKIE); print_R($cfg['cookie']);print_R($lang);exit;
+
+ $lang = preg_replace('/^s:/','', $lang); // for some reason roo's library prefixes values with s:
if (isset($_REQUEST[$cfg['param']])) {
$lang = $_REQUEST[$cfg['param']];
}
$iniCache = $this->PDO_DataObject['schema_location'];
- if ($force && file_exists($iniCache)) {
+
+ $replace = array();
+
+ if (file_exists($iniCache)) {
$files = glob(dirname($iniCache).'/*.ini');
foreach($files as $f) {
- echo "Remove {$f}\n";
- unlink($f);
- }
- clearstatcache();
+ $replace[$f] = md5(file_get_contents($f)); // hash it..
+
+ }
}
+
+
$iniCacheTmp = $iniCache . '.tmp' .md5(rand()); // random to stop two processes using the same file.
// has it expired..
$force = ($force ? $force : !file_exists($iniCache)) || !$this->dataObjectsCacheExpires;
}
-
+ $this->debug('generateDataobjectsCache', 'dataObjectsCache generating');
//echo "GENERATE?";
// force quoting of column names..
}
$this->PDO_DataObject['schema_location'] = $iniCacheTmp;
+
+ PDO_DataObject::reset();
+
PDO_DataObject::config($this->PDO_DataObject);
$generator = new HTML_FlexyFramework2_Generator();
$generator->start();
- HTML_FlexyFramework2_Generator::writeCache($iniCacheTmp, $iniCache);
+ $this->debug('generateDataobjectsCache', 'dataObjectsCache writing');
+ HTML_FlexyFramework2_Generator::writeCache($iniCacheTmp, $iniCache, $replace);
// reset the cache to the correct lcoation.
PDO_DataObject::config('schema_location', $iniCache);
$this->PDO_DataObject['schema_location'] = $iniCache;
//$GLOBALS['_DB_DATAOBJECT']['INI'][$this->database] = parse_ini_file($iniCache, true);
//$GLOBALS['_DB_DATAOBJECT']['SEQUENCE']
// clear any dataobject cache..
-
+
//die("done");
{
/* have I been initialized */
-
+ /*
if (get_magic_quotes_gpc() && !$this->cli) {
$this->fatalError(
"magic quotes is enabled add the line<BR>
");
}
+ */
// set up error handling -
//$this->error = new HTML_FlexyFramework2_Error();
<BR> ".$e->getMessage());
}
+
+ if (preg_match('/^mysql/', $this->database)) {
+ $res = $x->PDO()->query("SELECT @@global.read_only as ro");
+
+ $row = !is_a($res, 'PDOStatement') ? false : $res->fetch(PDO::FETCH_ASSOC);
+
+
+ if (!$row || !empty($row['ro'])) {
+ if (empty($options['skip-read-only-check'])) {
+ $this->fatalError("Database is configured to be read-only - please check database<BR>");
+ }
+ $this->database_is_readonly = true;
+ }
+ }
}
}
if ( !file_exists($this->HTML_Template_Flexy['compileDir'])) {
- @mkdir($this->HTML_Template_Flexy['compileDir'], 0700, true);
+ mkdir($this->HTML_Template_Flexy['compileDir'], 0700, true);
clearstatcache();
if ( !file_exists($this->HTML_Template_Flexy['compileDir'])) {
if (!$classname) {
return false;
}
+
// make page data/object accessable at anypoint in time using this
// not sure if this is used anymore - or even works..?
$classobj = $this->initPage($request,$isRedirect,$args);
+ $classobj->cli = $this->cli;
+
if ($this->cli && !$isRedirect ) { // redirect always just takes redirect args..
require_once 'HTML/FlexyFramework2/Cli.php';
$fcli = new HTML_FlexyFramework2_Cli($this);
}
$startRequest = $request;
- $request =@ array_shift(explode('?', $request));
+ $rq = explode('?', $request);
+ $request = array_shift($rq);
$this->debug("INPUT REQUEST $request<BR>");
if (!$isRedirect) {
// check that request forms contains baseurl????
// REDIRECT ROO to index.php! for example..
+ // this has a slight issue when we are using 'hidden index.php' mod_rewrite..
+
+ /*
+ normal (non-mod_rewrite)
+ $_SERVER['REQUEST_URI'] start with baseURL..
+ */
+ if (isset($_SERVER['REQUEST_URI']) && substr($_SERVER['REQUEST_URI'], 0, strlen($this->baseURL)) != $this->baseURL) {
+ // then we are rewriting?
+ $this->baseURL = $this->rootURL;
+ return $request;
+ }
+
+ //var_dump(array($this->baseURL, $this->rootURL, $request ,$isRedirect, $_SERVER['REQUEST_URI'])); phpinfo();exit;
if (!$request && !$isRedirect) {
+
+
if ($this->baseURL && (strlen($startRequest) < strlen($this->baseURL))) {
// needs to handle https + port
$this->debug("baseDIR = {$this->baseDir}");
$floc = "{$this->baseDir}/$location";
- $this->debug("CHECK LOCATION = $location");
+ $this->debug("CHECK LOCATION = $floc");
if (!empty($location) && $location != '.php' && @file_exists($floc )) { // hide? error???
require_once $floc ;
$classname = $this->classPrefix . implode('_',$request_array);
- $this->debug("FOUND FILE - SET CLASS = $classname <BR>");
- break;
+
+ if (class_exists($classname) &&
+ (is_a($classname, 'HTML_FlexyFramework2_Page', true) ||
+ is_a($classname, 'HTML_FlexyFramework_Page', true))
+ ) {
+
+ $this->debug("FOUND FILE - SET CLASS = $classname <BR>");
+ break;
+ }
}
// in here check the 'projectExtends' versions..?
if(!empty($this->projectExtends)){
- $this->debug("Trying project Extends<BR>");
+ $this->debug("Trying project Extends <BR>");
$has_extend_class = false;
foreach ($this->projectExtends as $e){
if (!empty($location) && @file_exists($floc)) { // hide? error???
require_once $floc ;
$classname = $e . '_' . implode('_',$request_array);
- $has_extend_class = true;
- $this->debug("FOUND FILE - SET CLASS = $classname <BR>");
- break;
+
+ if (class_exists($classname) &&
+ (is_a($classname, 'HTML_FlexyFramework2_Page', true) ||
+ is_a($classname, 'HTML_FlexyFramework_Page', true)) ) {
+ $has_extend_class = true;
+ $this->debug("FOUND FILE - SET CLASS = $classname <BR>");
+ break;
+ }
}
}
$classname = preg_replace('/[^a-z0-9]/i','_',$classname);
$this->debug("CLASSNAME is '$classname'");
// got it ok.
- if ($classname && class_exists($classname)) {
+ if ($classname && class_exists($classname) &&
+ (is_a($classname, 'HTML_FlexyFramework2_Page', true) ||
+ is_a($classname, 'HTML_FlexyFramework_Page', true))) {
$this->debug("using $classname");
//print_r($sub_request_array);
return array($classname,implode('/',array_reverse($sub_request_array)));
}
+ $this->debug("$classname did not exist - using base");
// stop looping..
if ($showError) {
$this->fatalError("INVALID REQUEST: \n $request FILE:".$this->baseDir. "/{$location} CLASS:{$classname}");
}
}
// got projectname.php
- if ($classname && class_exists($classname)) {
+ if ($classname && class_exists($classname) ) {
$this->debug("using $classname");
//print_r($sub_request_array);
return true;
}
// file exists, but process might not be the same..
- $name = array_pop(explode('_', get_class($class)));
+ $ca = explode('_', get_class($class));
+ $name = array_pop($ca);
$cmd = file_get_contents('/proc/' . $oldpid.'/cmdline');
if (!preg_match('/php/i',$cmd) || !preg_match('/'.$name.'/i',$cmd)) {
file_put_contents($lock, getmypid());
HTML_FlexyFramework2::run($this->fatalAction,$msg);
exit;
}
-
+ header('HTTP/1.1 503 Service Temporarily Unavailable');
+ header('Status: 503 Service Temporarily Unavailable');
+ header('Retry-After: 300');
echo $this->cli ? $msg ."\n" : "<H1>$msg</H1>configuration information<PRE>";
if ($showConfig) {