fix image text
[pear] / HTML / FlexyFramework.php
index 27b39ac..8cad346 100755 (executable)
@@ -71,7 +71,7 @@ error_reporting(E_ALL & ~E_STRICT );
 * it will try staging.ini
 *
 */
+#[AllowDynamicProperties]
 class HTML_FlexyFramework {
     
     /**
@@ -95,7 +95,8 @@ class HTML_FlexyFramework {
     var $dataObjectsCacheExpires = 72000; // 20 hours..
     var $languages = false; // language settings -- see _handlelanguage
     var $projectExtends = false; // if this is an array, it's a fallback of 'Projects' that can be called
-    
+    var $database_is_readonly = false;
+     
 
     
     // derived.
@@ -208,12 +209,24 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
      */
     function loadModuleConfig($cfg)
     {
+         
+        $proj = $cfg['project'];
+        $rootDir = realpath(dirname($_SERVER["SCRIPT_FILENAME"]));
+        
+        $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);
+            }
+        }
         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';
 
@@ -495,7 +508,13 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
     function _configDataObjectsCache()
     {
         // cli works under different users... it may cause problems..
+        
         $this->debug(__METHOD__);
+        
+        if ($this->database === false) {
+            return;
+        }
+        
         if (function_exists('posix_getpwuid')) {
             $uinfo = posix_getpwuid( posix_getuid () ); 
             $user = $uinfo['name'];
@@ -506,7 +525,7 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
         
 
         $iniCache = ini_get('session.save_path') .'/' . 
-               'dbcfg-' . $user . '/'. str_replace('/', '_', $this->project) ;
+               'dbcfg-' . $user . '/'. str_replace('/', '_', $this->project);
         
         
         if ($this->appNameShort) {
@@ -515,9 +534,7 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
         if ($this->version) {
             $iniCache .= '.' . $this->version;
         }
-        if ($this->database === false) {
-            return;
-        }
+       
         
         $dburl = parse_url($this->database);
         if (!empty($dburl['path'])) {
@@ -535,10 +552,8 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
             $this->dataObjectsOriginalIni = $this->DB_DataObject[$dbini];
             ///print_r($this->DB_DataObject);exit;
         }
-        // 
-        
-        
-        
+          
+         
         $this->DB_DataObject[$dbini] =   $iniCache;
         // we now have the configuration file name..
         
@@ -575,13 +590,15 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
         
         $iniCache = $this->DB_DataObject[$dbini];
         $this->debug('generateDataobjectsCache:' .dirname($iniCache).'/*.ini');
-        if ($force && file_exists($iniCache)) {
-            
+        
+        $replace = array();
+        
+        if (file_exists($iniCache)) {
             $files = glob(dirname($iniCache).'/*.ini');
             foreach($files as $f) {
-                unlink($f);
+                $replace[$f] = md5(file_get_contents($f)); // hash it..
+               
             }
-            clearstatcache();
         }
         $this->debug('generateDataobjectsCache: DONE ini delete');
         
@@ -624,7 +641,7 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
         $generator->start();
         $this->debug('generateDataobjectsCache: done generator');
 
-        HTML_FlexyFramework_Generator::writeCache($iniCacheTmp, $iniCache); 
+        HTML_FlexyFramework_Generator::writeCache($iniCacheTmp, $iniCache, $replace); 
         // reset the cache to the correct lcoation.
         $this->DB_DataObject[$dbini] = $iniCache;
         
@@ -853,7 +870,7 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
         /* have I been initialized */
         
         
-        if (get_magic_quotes_gpc() && !$this->cli) {
+        if (version_compare(PHP_VERSION, '7.0.0') < 0  && get_magic_quotes_gpc() && !$this->cli) {
             $this->fatalError(
                 "magic quotes is enabled add the line<BR>
                    php_value magic_quotes_gpc 0<BR>
@@ -898,9 +915,22 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
         if (PEAR::isError($err = $x->getDatabaseConnection())) {
                                 
 
-                $this->fatalError("Configuration or Database Error: could not connect to Database, <BR>
-                    Please check the value given to HTML_FlexyFramework, or run with debug on!<BR>
-                     <BR> ".$err->toString());
+            $this->fatalError("Configuration or Database Error: could not connect to Database, <BR>
+                Please check the value given to HTML_FlexyFramework, or run with debug on!<BR>
+                 <BR> ".$err->toString());
+        }
+        // only applies to mysql...
+        
+        if (preg_match('/^mysql/', $this->database)) {
+            $res = $err->query("SELECT @@global.read_only as ro");
+            
+            $row = is_a($res, 'DB_Error') ? false : $res->fetchRow(DB_FETCHMODE_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> ".$err->toString());
+                }
+                $this->database_is_readonly = true;
+            }
         }
         // reset dont die!
         $options['dont_die'] = $dd ;
@@ -914,10 +944,9 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
         if (empty($this->HTML_Template_Flexy['compileDir'])) {
             return;
         }
-        
+        clearstatcache();
         if ( !file_exists($this->HTML_Template_Flexy['compileDir']))  {
-            mkdir($this->HTML_Template_Flexy['compileDir'], 0700);
-            @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']))  {
@@ -1140,7 +1169,8 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
         }
         
         $startRequest = $request;
-        $request =@ array_shift(explode('?', $request));
+        $ra = explode('?', $request);
+        $request =  array_shift($ra);
         $this->debug("INPUT REQUEST $request<BR>");
         if (!$isRedirect) {
             // check that request forms contains baseurl????
@@ -1201,7 +1231,10 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
                         $sp .= ':'.((int) $_SERVER['SERVER_PORT']);
                     }
                 }
-                $host = !empty($_SERVER["HTTP_X_FORWARDED_HOST"]) ? $_SERVER["HTTP_X_FORWARDED_HOST"] : $_SERVER["HTTP_HOST"];
+                // not sure why http host would not be set?
+                $host = !empty($_SERVER["HTTP_X_FORWARDED_HOST"]) ? $_SERVER["HTTP_X_FORWARDED_HOST"] :
+                    (!isset($_SERVER["HTTP_HOST"]) ? 'localhost' : $_SERVER["HTTP_HOST"]);
+                    
                 header('Location: '.$http.'://'.$host .$sp . $this->baseURL);
  
                 exit;
@@ -1251,7 +1284,7 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
         }
         
         
-        $request_array=explode("/",$request);
+        $request_array = explode("/",$request);
         $original_request_array = $request_array;
         $sub_request_array = array();
         $l = count($request_array)-1;
@@ -1415,7 +1448,8 @@ RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
             return true;
         }
         // file exists, but process might not be the same..
-        $name = array_pop(explode('_', get_class($class)));
+        $ea = explode('_', get_class($class));
+        $name = array_pop($ea);
         $cmd = file_get_contents('/proc/' . $oldpid.'/cmdline');
         if (!preg_match('/php/i',$cmd) || !preg_match('/'.$name.'/i',$cmd)) {
             file_put_contents($lock, getmypid());