3e2e1314ae1aeec870ac7cd3b026bfb5f24f6855
[pear] / HTML / FlexyFramework.php
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 // +----------------------------------------------------------------------+
4 // | PHP Version 4                                                        |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2002 The PHP Group                                |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license,      |
9 // | that is bundled with this package in the file LICENSE, and is        |
10 // | available at through the world-wide-web at                           |
11 // | http://www.php.net/license/2_02.txt.                                 |
12 // | If you did not receive a copy of the PHP license and are unable to   |
13 // | obtain it through the world-wide-web, please send a note to          |
14 // | license@php.net so we can mail you a copy immediately.               |
15 // +----------------------------------------------------------------------+
16 // | Authors:  Alan Knowles <alan@akbkhome.com>                           |
17 // +----------------------------------------------------------------------+
18 //
19 // $Id: FlexyFramework.php,v 1.8 2003/02/22 01:52:50 alan Exp $
20 //
21 //  Description
22 //  A Page (URL) to Object Mapper
23 //  Cleaned up version.. - for use on new projects -- not BC!! beware!!!
24
25
26 //-----------------------------------------------------------
27 // Debian APACHE - some idiot disabled AcceptPathInfo - it needs adding back.
28 //-----------------------------------------------------------
29
30  
31  
32 // Initialize Static Options
33 require_once 'PEAR.php';
34 require_once 'HTML/FlexyFramework/Page.php';  
35 require_once 'HTML/FlexyFramework/Error.php';
36 // better done here..
37 require_once 'DB/DataObject.php';
38
39 // To be removed ?? or made optional or something..
40  
41
42 // remove E_ANAL  
43  
44 error_reporting(E_ALL & ~E_STRICT );
45 //ini_set('display_errors','off');
46 //ini_set('log_errors','off');
47
48 //PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_ERROR);
49
50
51
52
53 /**
54 * The URL to Object Mapper
55 *
56 * Usage:
57 * Create a index.php and add these lines.
58 *  
59 * ini_set("include_path", "/path/to/application"); 
60 * require_once 'HTML/FlexyFramework.php';
61 * HTML_FlexyFramework::factory(array("dir"=>"/where/my/config/dir/is");
62 *
63 *
64 * the path could include pear's path, if you dont install all the pear 
65 * packages into the development directory.
66 *
67 * It attempts to load a the config file from the includepath, 
68 * looks for ConfigData/default.ini
69 * or ConfigData/{hostname}.ini
70 * if your file is called staging.php rather than index.php 
71 * it will try staging.ini
72 *
73 */
74  
75 class HTML_FlexyFramework {
76     
77     /**
78      * Confirgurable items..
79      * If we set them to 'true', they must be set, otherwise they are optional.
80      */
81     var $project; // base class name
82     var $database; // set to true even if nodatabase=true
83     
84     // optional
85     var $debug = false;
86     var $enable = false; // modules
87     var $disable = false; // modules or permissions
88     var $appName = false;
89     var $appNameShort = false; // appname (which has templates)
90     var $version = false; // give it a version name. (appended to compile dir)
91     var $nodatabase = false; // set to true to block db config and testing.
92     var $fatalAction = false; // page to redirct to on failure. (eg. databse down etc.)
93     var $charset = false; // default UTF8
94     var $dataObjectsCache = true;  // use dataobjects ini cache.. - let's try this as the default behaviour...
95     var $dataObjectsCacheExpires = 72000; // 20 hours..
96     var $languages = false; // language settings -- see _handlelanguage
97     var $projectExtends = false; // if this is an array, it's a fallback of 'Projects' that can be called
98     
99
100     
101     // derived.
102     var $cli = false; // from cli 
103     var $run = false; // from cli
104     var $enableArray = false; // from enable.
105     var $classPrefix = false; // from prject.
106     var $baseDir = false ; // (directory+project)
107     var $rootDir = false ; // (directory that index.php is in!)
108     
109     var $baseURL = false;
110     var $rootURL = false ; // basename($baseURL)
111     
112     var $page = false; // active page..
113     var $timer = false; // the debug timer
114     var $calls = false; // the number of calls made to run!
115     var $start = false; // the start tiem.
116     
117     var $baseRequest = '';
118     var $ext; // the striped extention.
119     
120     var $dataObjectsOriginalIni = ''; // 1 houre..
121     
122     // used to be $_GLOBALS[__CLASS__]
123     
124     static $singleton; 
125     
126     
127     /**
128      * 
129      * Constructor - with assoc. array of props as option
130      * called by index.php usually, and runs the app code,
131      *
132      * uses 'universal construcor' format, so the argument relates directly to properties of this object.
133      * 
134      */
135     
136     
137     function __construct($config)
138     {
139         if (isset(self::$singleton)) {
140             trigger_error("FlexyFramework Construct called twice!", E_ERROR);
141         }
142         
143         self::$singleton = $this;
144         
145         $this->calls = 0;
146
147         $m = explode(' ',microtime());
148         $this->start = $m[0] + $m[1];
149         
150         $config = $this->loadModuleConfig($config);
151         
152         foreach($config as $k=>$v) {
153             $this->$k = $v;
154         }
155         $this->_parseConfig();
156
157         // echo '<PRE>'; print_r($this);exit;
158         if ($this->cli) {
159             $args = $_SERVER['argv'];
160             array_shift($args );
161             array_shift($args );
162             $this->_run($this->run,false,$args);
163             return;
164         }
165
166         // handle apache mod_rewrite..
167         // it looks like this might not work anymore..
168         
169         /*
170          *
171 <IfModule mod_rewrite.c>
172 RewriteEngine On
173 RewriteBase /
174 RewriteRule ^/web.hpasite/index\.local.php$ - [L]
175 RewriteCond %{REQUEST_FILENAME} !-f
176 RewriteCond %{REQUEST_FILENAME} !-d
177 RewriteRule ^(.+)$ /web.hpasite/index.local.php [L,NC,E=URL:$1]
178 </IfModule>
179 */ 
180         
181         if (!empty($_SERVER['REDIRECT_STATUS'])  && !empty($_SERVER['REDIRECT_URL'])) {
182           // phpinfo();exit;
183             $sn = $_SERVER['SCRIPT_NAME'];
184             $sublen = strlen(substr($sn , 0,  strlen($sn) - strlen(basename($sn)) -1));
185             //var_dump(array($sn,$subdir,basename($sn)));exit;
186           
187             //var_dump($_SERVER['SCRIPT_NAME'] . substr($_SERVER['REDIRECT_URL'],$sublen));
188             $this->_run($_SERVER['SCRIPT_NAME'] .  substr($_SERVER['REDIRECT_URL'], $sublen),false);
189             return ;
190         }
191         // eg... /web.hpasite/index.local.php/Projects
192          $this->_run($_SERVER['REQUEST_URI'],false);
193             
194         
195     }
196     /**
197      * This is the standard way to get information about the application settings.
198      * $ff = HTML_FlexyFramework::get();
199      * if ($ff->SomeVar[...])....
200      *
201      */
202     static function get()
203     {
204         return self::$singleton;
205     }
206     /*
207      * looks for files in the path and load up the default values for config?
208      */
209     function loadModuleConfig($cfg)
210     {
211         if (empty($cfg['enable'])) {
212             return $cfg;
213         }
214         $proj = $cfg['project'];
215         $rootDir = realpath(dirname($_SERVER["SCRIPT_FILENAME"]));
216
217         foreach(explode(',',$cfg['enable']) as $m) {
218             $cls = $proj.'_'. $m . '_Config';
219
220             if (!file_exists($rootDir . '/'.str_replace('_','/', $cls). '.php')) {
221                 continue;
222             }
223             require_once str_replace('_','/', $cls). '.php';
224             $c = new $cls();
225             if (method_exists($c,'init')) {
226                 $cfg = $c->init($this,$cfg);
227             }
228         }
229         return $cfg;
230     }
231     
232   
233     /**
234      * parse the configuration set by the constructor.
235      * 
236      *
237      */
238   
239     function _parseConfig()
240     {
241         
242         // make sure required values are set.. (anything that is not defaulted to false..)
243         foreach(get_class_vars(__CLASS__) as $k =>$v) {
244             if ($v === false && !isset($this->$k)) {
245                 die("$k is not set");
246             }
247         }
248         
249         
250         // enable modules.
251         if (!empty($this->enable)) {
252             $this->enableArray = explode(',', $this->enable);
253             
254             if (!in_array('Core',$this->enableArray ) &&
255                 !in_array('Core', explode(',', $this->disable ? $this->disable : '')))
256             {
257                 $this->enable = 'Core,'. $this->enable ;
258                 $this->enableArray = explode(',', $this->enable);
259             }
260         }
261         // are we running cli?
262         $this->cli = php_sapi_name() == 'cli'; 
263         
264         // will these work ok with cli?
265         $bits = explode(basename($_SERVER["SCRIPT_FILENAME"]), $_SERVER["SCRIPT_NAME"]);
266         if (!$this->cli) {
267             $bits[0] = str_replace('%2F','/',urlencode($bits[0]));
268             $this->baseURL = $bits[0] . basename($_SERVER["SCRIPT_FILENAME"]);
269             // however this is not correct if we are using rewrite..
270             if (!empty($_SERVER['REDIRECT_STATUS'])  && !empty($_SERVER['REDIRECT_URL'])) {
271                 $this->baseURL = substr($bits[0],0,-1); // without the trailing '/' ??
272                 $this->rootURL = $bits[0] == '/' ? '' : $bits[0];
273                 //$this->baseURL = $this->baseURL == '' ? '/' : $this->baseURL;
274                 
275             }
276             //phpinfo();exit;
277             // is this bit used??
278             //if (empty($_SERVER['SCRIPT_NAME'])) {
279                 
280             //    $this->baseURL = ''; // ??? this is if we replace top level...
281             //}
282         }
283         // if cli - you have to have set baseURL...
284         
285         
286         $this->rootDir = realpath(dirname($_SERVER["SCRIPT_FILENAME"]));
287         $this->baseDir = $this->rootDir .'/'. $this->project;
288         if (empty($this->rootURL)) {
289             $this->rootURL = dirname($this->baseURL); 
290             $this->rootURL = ($this->rootURL == '/') ? '' : $this->rootURL;
291         }
292          
293       
294         //var_dump($this->baseURL);
295         
296         if (!isset($this->database) && isset($this->DB_DataObject['database'])) {
297             $this->database = $this->DB_DataObject['database'];
298         }
299         
300          $this->classPrefix   = str_replace('/', '_', $this->project) . '_';
301          // list the available options..
302         if ($this->cli && empty($_SERVER['argv'][1])) {
303             require_once 'HTML/FlexyFramework/Cli.php';
304             $fcli = new HTML_FlexyFramework_Cli($this);
305             $fcli->cliHelp();
306             exit;
307         }
308         
309         
310         // see if it's a framework assignment.
311         $ishelp = false;
312         if ($this->cli) {
313             require_once 'HTML/FlexyFramework/Cli.php';
314             $fcli = new HTML_FlexyFramework_Cli($this);
315             $res = $fcli->parseDefaultOpts();
316             if ($res === true) {
317                 $ishelp = true;
318             }
319              
320         }
321         
322         
323         $this->run = $this->cli ? $_SERVER['argv'][1] : false;
324      
325         
326         $this->_parseConfigDataObjects();
327         if ($this->dataObjectsCache && !$this->nodatabase) {
328             $this->_configDataObjectsCache();
329         }
330         
331         $this->_parseConfigTemplate();
332         $this->_parseConfigMail();
333  
334         //echo '<PRE>';print_r($this);exit;
335         
336         $this->_exposeToPear();
337                 
338
339         $this->_validateEnv();
340         
341         if ($ishelp) {
342             return;
343         }
344
345         $this->_validateDatabase();
346
347         $this->_validateTemplate();
348         
349     }
350     /**
351      *
352      *
353      *'languages' => array(
354             'param' => '_lang',
355             'avail' => array('en','zh_HK', 'zh_CN'),
356             'default' => 'en',
357             'cookie' => 'TalentPricing_lang',
358             'localemap' => array(
359                 'en' => 'en_US.utf8',
360                 'zh_HK' => 'zh_TW.utf8',
361                 'zh_CN' => 'zh_CN.utf8',
362             )
363         ),
364     */
365     
366     function _handleLanguages($request)
367     {
368         if (
369             empty($this->languages) ||
370             (
371                     !isset($this->languages['cookie']) && !isset($this->languages['default'])
372             )
373         ) {
374             return;
375         }
376         
377         $cfg = $this->languages;
378         
379         $default = $cfg['default'];
380         
381         if(!empty($_SERVER["HTTP_ACCEPT_LANGUAGE"])){
382             
383             $brower_langs = explode(",", $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
384             
385             foreach ($brower_langs as $bl) {
386                 $l = preg_replace('/;(.*)/', '', $bl);
387                 
388                 $l = str_replace('-', '_', $l);
389                 
390                 if(!in_array($l, $cfg['avail'])){
391                     continue;
392                 }
393                 
394                 $default = $l;
395                 break;
396             }
397         }
398            
399         $lang = isset($_COOKIE[$cfg['cookie']]) ?  $_COOKIE[$cfg['cookie']] : $default;
400
401         // handle languages in request..
402         $bits = explode('/', $request);
403         $redirect_to = false;
404         if (count($bits) && in_array($bits[0],$cfg['avail'])) {
405             // redirect..
406             $lang = array_shift($bits);
407             $redirect_to = implode('/', $bits);
408         }
409         
410          
411         
412         if (isset($_REQUEST[$cfg['param']])) {
413             $lang = $_REQUEST[$cfg['param']];
414         }
415     
416         if (!in_array($lang, $cfg['avail'])) {
417             $lang = $cfg['default'];
418         }
419         if (isset($cfg['localemap'][$lang])) {
420             setlocale(LC_ALL, $cfg['localemap'][$lang]);
421         }
422         setcookie($cfg['cookie'], $lang, 0, '/');
423         
424         $this->locale = $lang;
425         
426         if (!empty($this->HTML_Template_Flexy)) {
427             $this->HTML_Template_Flexy['locale'] = $lang;   //set a language for template engine
428         }
429         if ($redirect_to !== false) {
430             header('Location: ' . $this->rootURL . '/'.$redirect_to );
431             exit;
432          
433         }
434     }
435     
436     function parseDefaultLanguage($http_accept, $deflang = "en") 
437     {
438         if(isset($http_accept) && strlen($http_accept) > 1)  {
439            # Split possible languages into array
440            $x = explode(",",$http_accept);
441            
442            foreach ($x as $val) {
443               #check for q-value and create associative array. No q-value means 1 by rule
444               if(preg_match("/(.*);q=([0-1]{0,1}.\d{0,4})/i",$val,$matches))
445                  $lang[$matches[1]] = (float)$matches[2];
446               else
447                  $lang[$val] = 1.0;
448            }
449            
450            #return default language (highest q-value)
451            $qval = 0.0;
452            foreach ($lang as $key => $value) {
453               if ($value > $qval) {
454                  $qval = (float)$value;
455                  $deflang = $key;
456               }
457            }
458         }
459         return strtolower($deflang);
460      }
461     
462     /**
463      * overlay array properties..
464      */
465     
466     function applyIf($prop, $ar)
467     {
468         if (!isset($this->$prop)) {
469             $this->$prop = $ar;
470             return;
471         }
472         // add only things that where not set!!!.
473         $this->$prop = array_merge($ar,$this->$prop);
474         
475         return;
476         //foreach($ar as $k=>$v) {
477         //    if (!isset($this->$prop->$k)) {
478          //       $this->$prop->$k = $v;
479           //  }
480        // }
481     }
482     
483     /**
484      * DataObject cache 
485      * - if turned on (dataObjectsCache = true) then 
486      *  a) ini file points to a parsed version of the structure.
487      *  b) links.ini is a merged version of the configured link files.
488      * 
489      * This only will force a generation if no file exists at all.. - after that it has to be called manually 
490      * from the core page.. - which uses the Expires time to determine if regeneration is needed..
491      * 
492      * 
493      */
494     
495     function _configDataObjectsCache()
496     {
497         // cli works under different users... it may cause problems..
498         $this->debug(__METHOD__);
499         if (function_exists('posix_getpwuid')) {
500             $uinfo = posix_getpwuid( posix_getuid () ); 
501             $user = $uinfo['name'];
502         } else {
503             $user = getenv('USERNAME'); // windows.
504         }
505         
506         
507
508         $iniCache = ini_get('session.save_path') .'/' . 
509                'dbcfg-' . $user . '/'. str_replace('/', '_', $this->project) ;
510         
511         
512         if ($this->appNameShort) {
513             $iniCache .= '_' . $this->appNameShort;
514         }
515         if ($this->version) {
516             $iniCache .= '.' . $this->version;
517         }
518         if ($this->database === false) {
519             return;
520         }
521         
522         $dburl = parse_url($this->database);
523         if (!empty($dburl['path'])) {
524             $iniCache .= '-'.ltrim($dburl['path'],'/');
525         }
526         
527         $iniCache .= '.ini';
528         $this->debug(__METHOD__ . " : ini cache : $iniCache");
529         
530         $dburl = parse_url($this->database);
531         $dbini = 'ini_'. basename($dburl['path']);
532         $this->debug(__METHOD__ . " : ini file : $dbini");
533         //override ini setting... - store original..
534         if (isset($this->DB_DataObject[$dbini])) {
535             $this->dataObjectsOriginalIni = $this->DB_DataObject[$dbini];
536             ///print_r($this->DB_DataObject);exit;
537         }
538         // 
539         
540         
541         
542         $this->DB_DataObject[$dbini] =   $iniCache;
543         // we now have the configuration file name..
544         
545         
546         if (!file_exists($iniCache) || empty( $this->dataObjectsCacheExpires)) {
547             $this->debug(__METHOD__ . ':calling generate do cache');
548             $this->generateDataobjectsCache(true);
549             return;
550         }
551      
552         
553         
554     }
555     /**
556      *  _generateDataobjectsCache:
557      * 
558      * create xxx.ini and xxx.links.ini 
559      * 
560      * @arg force (boolean) force generation - default false;
561      * 
562      */
563      
564     function generateDataobjectsCache($force = false)
565     {
566         //$this->debug('generateDataobjectsCache: force=' . ($force ? 'yes' : 'no'));
567         if (!$this->dataObjectsCache) { // does not use dataObjects Caching..
568             $this->debug('generateDataobjectsCache: dataObjectsCache - empty');
569             return;
570         }
571         
572         $dburl = parse_url($this->database);
573         $dbini = 'ini_'. basename($dburl['path']);
574         
575         
576         $iniCache = $this->DB_DataObject[$dbini];
577         $this->debug('generateDataobjectsCache:' .dirname($iniCache).'/*.ini');
578         if ($force && file_exists($iniCache)) {
579             
580             $files = glob(dirname($iniCache).'/*.ini');
581             foreach($files as $f) {
582                 unlink($f);
583             }
584             clearstatcache();
585         }
586         $this->debug('generateDataobjectsCache: DONE ini delete');
587         
588         $iniCacheTmp = $iniCache . '.tmp' .md5(rand());  // random to stop two processes using the same file.
589         // has it expired..
590         $force = ($force ? $force : !file_exists($iniCache)) || !$this->dataObjectsCacheExpires;
591         // $this->debug('generateDataobjectsCache: after check : force=' . ($force ? 'yes' : 'no'));
592          // not force or not expired, do not bother..
593         if (!$force) {
594             if ((filemtime($iniCache) + $this->dataObjectsCacheExpires) >time()) {
595                 return;
596             }
597         }
598         
599         
600         
601          //echo "GENERATE?";
602         
603         // force quoting of column names..
604         // unless it forced off..
605         if (!isset($this->DB_DataObject['quote_identifiers_tableinfo'] )) { 
606             $this->DB_DataObject['quote_identifiers_tableinfo'] = true;
607         }
608         if (!file_exists(dirname($iniCache))) {
609             if (!mkdir(dirname($iniCache),0700, true)) {
610                 die("Failed to make cache directory : $iniCache\n");
611             }
612         }
613         
614         $this->DB_DataObject[$dbini] = $iniCacheTmp;
615         
616         $dl = DB_DataObject::DebugLevel();
617         $this->_exposeToPear(); // this will reset the debug level...
618         DB_DataObject::DebugLevel($dl);
619         
620         $this->debug('generateDataobjectsCache: running generator');
621         // DB_DataObject::debugLevel(1);      
622         require_once 'HTML/FlexyFramework/Generator.php';
623         $generator = new HTML_FlexyFramework_Generator();
624         $generator->start();
625         $this->debug('generateDataobjectsCache: done generator');
626
627         HTML_FlexyFramework_Generator::writeCache($iniCacheTmp, $iniCache); 
628         // reset the cache to the correct lcoation.
629         $this->DB_DataObject[$dbini] = $iniCache;
630         
631          
632
633         $this->_exposeToPear();
634         DB_DataObject::DebugLevel($dl);
635
636         //$GLOBALS['_DB_DATAOBJECT']['INI'][$this->database] =   parse_ini_file($iniCache, true);
637         //$GLOBALS['_DB_DATAOBJECT']['SEQUENCE']
638         // clear any dataobject cache..
639          
640         
641         //die("done");
642         
643     }
644     /**
645      * DataObject Configuration:
646      * Always in Project/DataObjects
647      * unless enableArray is available...
648      * 
649      * 
650      * 
651      */
652     function _parseConfigDataObjects()
653     {
654         if ($this->nodatabase && !$this->database) {
655             return;
656         }
657         $dburl = parse_url($this->database);
658         $dbini = 'ini_'. basename($dburl['path']);
659                 
660         $dbinis =  array(); //array(dirname(__FILE__) . '/Pman/DataObjects/pman.ini');
661         $dbreq =  array(); //array( dirname(__FILE__) . '/Pman/DataObjects/');
662         $dbcls =  array(); //array('Pman_DataObjects_');
663
664         $project = explode('/',$this->project)[0]; 
665         
666         if (!empty($this->enableArray)) {
667                 
668             $tops = array_merge( array($project), empty($this->projectExtends) ? array() : $this->projectExtends);
669             
670             foreach($tops as $td) {
671                     
672                 $bd = $this->rootDir .'/'.$td;
673                 foreach($this->enableArray as $m) {
674                     // look in Pman/MODULE/DataObjects/*
675                      if (file_exists($bd.'/'.$m.'/DataObjects')) {
676                         $dbinis[] = $bd.'/'.$m.'/DataObjects/'. strtolower($project).'.ini';
677                         $dbcls[] = $td.'_'. $m . '_DataObjects_';
678                         $dbreq[] = $bd.'/'.$m.'/DataObjects';
679                         continue;
680                     }
681                     // look in MODULE/DataObjects ?? DO WE SUPPORT THIS ANYMORE???
682                     if (file_exists($bd.'/../'.$m.'/DataObjects')) {
683                         $dbinis[] = $bd.'/../'.$m.'/DataObjects/'. strtolower($project).'.ini';
684                         $dbcls[] = $td. '_DataObjects_';
685                         $dbreq[] = $bd.'/../'.$m.'/DataObjects';
686                     }
687                         
688                         
689                       
690                 }
691             }     
692         } else {
693             
694             if (isset($this->DB_DataObject['schema_location'])) {
695                 $dbinis[] = $this->DB_DataObject['schema_location'] .'/'.basename($dburl['path']).'.ini';
696             } else {
697                 $dbinis[] = $this->baseDir.'/DataObjects/'.basename($dburl['path']).'.ini';
698             }
699             // non modular.
700             
701             $dbcls[] = $project .'_DataObjects_';
702             $dbreq[] = $this->baseDir.'/DataObjects';
703         }
704             
705         
706         $this->applyIf('DB_DataObject', array(   
707         
708             'class_location' =>  implode(PATH_SEPARATOR,$dbreq),
709             'class_prefix' =>  implode(PATH_SEPARATOR,$dbcls),
710             'database'        => $this->database,    
711             ///'require_prefix' => 
712          //   'schema_location' => dirname(__FILE__) . '/Pman/DataObjects/',
713              $dbini=> implode(PATH_SEPARATOR,$dbinis),
714          
715            //   'debug' => 5,
716         ));
717       //  print_r($this->DB_DataObject);exit;
718     }
719     /**
720      Set up thetemplate
721      * 
722      */
723     function _parseConfigTemplate()
724     {
725         
726         // compile.
727         if (function_exists('posix_getpwuid')) {
728             $uinfo = posix_getpwuid( posix_getuid () ); 
729          
730             $user = $uinfo['name'];
731         } else {
732             $user = getenv('USERNAME'); // windows.
733         }
734         
735         $compileDir = ini_get('session.save_path') .'/' . 
736             $user . '_compiled_templates_' . $this->project;
737         
738         if ($this->appNameShort) {
739             $compileDir .= '_' . $this->appNameShort;
740         }
741         if ($this->version) {
742             $compileDir .= '.' . $this->version;
743         }
744         
745         // templates. -- all this should be cached!!!
746         $src = array();
747          
748         
749         if ($this->appNameShort && !in_array('Core', explode(',', $this->disable ? $this->disable : ''))) {
750             // in app based version, template directory is in Core
751             
752             $src = array(  
753                 $this->baseDir . '/Core/templates'
754             );
755         }
756         
757         if(!empty($this->projectExtends)){
758             foreach ($this->projectExtends as $e){
759                 $add = $this->rootDir . '/' . $e .'/templates';
760                 if (!in_array($add,$src) && file_exists($add)) {
761                     $src[] = $add;
762                 }
763             }
764         }
765         
766         $src[] = $this->baseDir . '/templates';
767         
768         
769         
770         if (!empty($this->enableArray)) {
771              
772             
773             foreach($this->enableArray as $m) {
774                 $add = $this->baseDir . '/' . $m .'/templates';
775                 if (!in_array($add,$src) && file_exists($add) && $this->appNameShort != $m) {
776                     $src[] = $add;
777                 }
778                 
779             }
780             if (!empty($this->projectExtends)  )  {
781                 foreach ($this->projectExtends as $extend){
782                     foreach($this->enableArray as $m) {
783                         $add = $this->rootDir . '/' . $extend . '/' . $m .'/templates';
784                         if (!in_array($add,$src) && file_exists($add) && $this->appNameShort != $m) {
785                             $src[] = $add;
786                         }
787                     }
788                 }
789     
790             }
791         }
792          
793         
794         if ($this->appNameShort) {
795             $src[] =  $this->baseDir . '/'. $this->appNameShort. '/templates';
796         }
797         
798         // images may come from multiple places: - if we have multiple template directories.?
799         // how do we deal with this..?
800         // images/ << should always be mapped to master!
801         // for overridden appdir ones we will have to se rootURL etc.
802         
803         $url_rewrite = 'images/:'. $this->rootURL . '/'. $this->project. '/templates/images/';
804         
805         $this->applyIf('HTML_Template_Flexy', array(
806             'templateDir' => implode(PATH_SEPARATOR, $src),
807             'compileDir' => $compileDir,
808             'multiSource' => true,
809             'forceCompile' => 0,
810             'url_rewrite' => $url_rewrite,
811             'filters' => 'Php,SimpleTags', /// for non-tokenizer version?
812             'debug' => $this->debug ? 1 : 0,
813             'useTokenizer' => 1,
814              
815             
816         
817         
818         ));
819     } 
820     
821     function _parseConfigMail()
822     {
823         $this->applyIf('HTML_Template_Flexy', array(
824            'debug' => 0,
825            'driver' => 'smtp',
826            'host' => 'localhost',
827            'port' => 25,
828         ));
829     }
830     function _exposeToPear()
831     {
832         $cls = array_keys(get_class_vars(__CLASS__));
833         $base = array();
834         
835         // anything that get's set, that's not in our default properties
836         // is assumed to be an option set .
837         foreach(get_object_vars($this) as $k=>$v) {
838             if (in_array($k,$cls)) {
839                 $base[$k] = $v;
840                 continue;
841             }
842             $options = &PEAR::getStaticProperty($k,'options');
843             $options = $v;
844         }
845         $options = &PEAR::getStaticProperty('HTML_FlexyFramework','options');
846         $options = $base;
847          //   apply them..
848     }
849     
850     
851     function _validateEnv() 
852     {
853         /* have I been initialized */
854         
855         
856         if (get_magic_quotes_gpc() && !$this->cli) {
857             $this->fatalError(
858                 "magic quotes is enabled add the line<BR>
859                    php_value magic_quotes_gpc 0<BR>
860                    to your .htaccess file <BR>
861                    (Apache has to be configured to &quot;AllowOverride Options AuthConfig&quot; for the directory)
862                    ");
863                 
864         }
865         // set up error handling - 
866         $this->error = new HTML_FlexyFramework_Error();
867         
868         /// fudge work around bugs in PEAR::setErrorHandling(,)
869         $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK;
870         $GLOBALS['_PEAR_default_error_options'] = array($this->error,'raiseError');
871         
872         
873         
874         if ($this->debug) {
875             require_once 'Benchmark/Timer.php'; 
876             $this->timer = new BenchMark_Timer(true);
877             register_shutdown_function(function() { echo $this->timer->getOutput(); });
878         }
879
880     }
881     
882     function _validateDatabase()
883     {
884         //echo "<PRE>"; print_r($this);
885
886         if ($this->nodatabase) {
887             return;
888         }
889         $options = &PEAR::getStaticProperty('DB_DataObject','options');
890         $dd = empty($options['dont_die']) ? false : true;
891         $options['dont_die'] = true;
892         
893         // database is the only setting - we dont support mult databses?
894           
895             
896         $x = new DB_Dataobject;
897         $x->_database = $this->database;
898         if (PEAR::isError($err = $x->getDatabaseConnection())) {
899                                 
900
901                 $this->fatalError("Configuration or Database Error: could not connect to Database, <BR>
902                     Please check the value given to HTML_FlexyFramework, or run with debug on!<BR>
903                      <BR> ".$err->toString());
904         }
905         // reset dont die!
906         $options['dont_die'] = $dd ;
907         
908         
909     }
910     function _validateTemplate()
911     {
912         // check that we have a writeable directory for flexy's compiled templates.
913         
914         if (empty($this->HTML_Template_Flexy['compileDir'])) {
915             return;
916         }
917         
918         if ( !file_exists($this->HTML_Template_Flexy['compileDir']))  {
919             mkdir($this->HTML_Template_Flexy['compileDir'], 0700);
920             @mkdir($this->HTML_Template_Flexy['compileDir'], 0700, true);
921             clearstatcache();
922              
923             if ( !file_exists($this->HTML_Template_Flexy['compileDir']))  {
924             
925                 $this->fatalError("Configuration Error: you specified a directory that does not exist for<BR>
926                     HTML_Template_Flexy => compileDir  {$this->HTML_Template_Flexy['compileDir']}<BR>\n"
927                 );
928             }
929         }
930         
931         if (!is_writeable($this->HTML_Template_Flexy['compileDir'])) {
932             $this->fatalError("Configuration Error: Please make sure the template cache directory is writeable<BR>
933                     eg. <BR>
934                     chmod 700 {$this->HTML_Template_Flexy['compileDir']}<BR>
935                     chgrp apache_user  {$this->HTML_Template_Flexy['compileDir']}<BR>\n"
936             );
937         }
938         //echo "<PRE>";print_R($config);
939         
940         
941          
942           
943         
944         
945     }
946   
947   
948    
949         
950     
951     
952     /**
953     * Quality Redirector
954     *
955     * Usage in a page.:
956     * HTML_FlexyFramework::run('someurl/someother',array('somearg'=>'xxx'));
957     * ...do clean up...
958     * exit; <- dont cary on!!!!
959     *
960     * You should really
961     * 
962     * @param   string           redirect to url 
963     * @param   array Args Optional      any data you want to send to the next page..
964     * 
965     *
966     * @return   false
967     * @access   public
968     * @static
969     */
970   
971     
972     static function run($request,$args=array()) 
973     {
974         self::$singleton->_run($request,true,$args);
975         return false;
976     }
977     
978     
979     /**
980     * The main execution loop
981     *
982     * recursivly self called if redirects (eg. return values from page start methods)
983     * 
984     * @param   string from $_REQUEST or redirect from it'self.
985     * @param   boolean isRedirect  = is the request a redirect 
986     *
987     *
988     * @return   false || other    false indicates no page was served!
989     * @access   public|private
990     * @see      see also methods.....
991     */
992   
993     function _run($request,$isRedirect = false,$args = array()) 
994     {
995         
996         // clean the request up.
997         $this->calls++;
998         
999         if ($this->calls > 5) {
1000             // to many redirections...
1001             trigger_error("FlexyFramework:: too many redirects - backtrace me!",E_USER_ERROR);
1002             exit;
1003         }
1004         
1005         $newRequest = $this->_getRequest($request,$isRedirect);
1006         
1007          
1008         // find the class/file to load
1009         list($classname,$subRequest) = $this->requestToClassName($newRequest,FALSE);
1010         
1011         
1012         $this->debug("requestToClassName return = CLASSNAME: $classname SUB REQUEST: $subRequest");
1013         
1014         // assume that this was handled by getclassname ?????
1015         if (!$classname) {
1016             return false;
1017         }
1018         
1019         // make page data/object accessable at anypoint in time using  this
1020         // not sure if this is used anymore - or even works..?
1021         $classobj = &PEAR::getStaticProperty('HTML_FlexyFramework', 'page');
1022         
1023         $classobj =  new  $classname();  // normally do not have constructors.
1024         
1025         
1026         $classobj->baseURL = $this->baseURL;
1027         $classobj->rootURL = $this->rootURL;
1028         $classobj->rootDir = $this->rootDir;
1029         $classobj->bootLoader  = $this;
1030         $classobj->request = $newRequest;
1031         $classobj->timer = &$this->timer;
1032         $classobj->cli = $this->cli;
1033         
1034         $this->page = $classobj;
1035         if ($this->cli && !$isRedirect ) { // redirect always just takes redirect args..
1036             require_once 'HTML/FlexyFramework/Cli.php';
1037             $fcli = new HTML_FlexyFramework_Cli($this);
1038             $nargs = $fcli->cliParse($classname);
1039             $args = $nargs === false ? $args : $nargs; /// replace if found.
1040             $classobj->cli_args = $nargs;
1041         }
1042         
1043         // echo '<PRE>'; print_r($this);exit;
1044         // echo "CHECK GET AUTH?";
1045
1046         if (!method_exists($classobj, 'getAuth')) {
1047         //    echo "NO GET AUTH?";
1048             $this->fatalError("class $classname does not have a getAuth Method");
1049             return false;
1050         }
1051         
1052         /* check auth on the page */
1053         if (is_string($redirect = $classobj->getAuth())) {
1054             $this->debug("GOT AUTH REDIRECT".$redirect);
1055             return $this->_run($redirect,TRUE);
1056         }
1057         // used HTML_FlexyFramework::run();
1058                  
1059
1060         if ($redirect === false) {
1061             $this->debug("GOT AUTH FALSE");    
1062             return false; /// Access deined!!! - 
1063         }
1064      
1065         // allow the page to implement caching (for the full page..)
1066         // although normally it should implement caching on the outputBody() method.
1067         
1068         if (method_exists($classobj,"getCache")) {
1069             if ($result = $classobj->getCache()) {
1070                 return $result;
1071             }
1072         }
1073                     
1074         /* allow redirect from start */
1075         if (method_exists($classobj,"start")) {
1076             if (is_string($redirect = $classobj->start($subRequest,$isRedirect,$args)))  {
1077                 $this->debug("REDIRECT $redirect <BR>");
1078                 return $this->_run($redirect,TRUE);
1079             }
1080             if ($redirect === false) {
1081                 return false;
1082             }
1083         }
1084                 
1085
1086          // used HTML_FlexyFramework::run();
1087         
1088         /* load the modules 
1089          * Modules are common page components like navigation headers etc.
1090          * that can have dynamic code.
1091          * Code has been removed now..
1092          */
1093         
1094         
1095         if ($this->timer) {
1096             $this->timer->setMarker("After $request loadModules Modules"); 
1097         }
1098         
1099         /* output it  - (our base page does not implement output for cli. */
1100         
1101         if ( method_exists($classobj,'output')) {
1102             $classobj->output(); 
1103         }
1104         
1105         
1106         if ($this->timer) {
1107             $this->timer->setMarker("After $request output"); 
1108             $this->timer->stop(); //?? really - yes...
1109            
1110             
1111         }
1112         
1113         if ($this->cli) {
1114             return true;
1115         }
1116         
1117         
1118         exit; /// die here...
1119         
1120     }
1121     
1122     /**
1123     * map the request into an object and run the page.
1124     *
1125     * The core of the work is done here.
1126     * 
1127     * 
1128     * @param   request  the request string
1129     * @param   boolean isRedirect - indicates that it should not attempt to strip the .../index.php from the request.
1130     * 
1131     * @access  private
1132     */
1133   
1134     function _getRequest($request, $isRedirect) 
1135     {
1136         
1137          
1138         if ($this->cli) {
1139             return $request;
1140         }
1141         
1142         $startRequest = $request;
1143         $request =@ array_shift(explode('?', $request));
1144         $this->debug("INPUT REQUEST $request<BR>");
1145         if (!$isRedirect) {
1146             // check that request forms contains baseurl????
1147             if (!empty($_SERVER['REDIRECT_STATUS'])  && !empty($_SERVER['REDIRECT_URL'])) {
1148                // phpinfo();exit;
1149                 $sn = $_SERVER['SCRIPT_NAME'];
1150                 $sublen = strlen(substr($sn , 0,  strlen($sn) - strlen(basename($sn)) -1 ));
1151                  //var_dump(array($sn,$subdir,basename($sn)));exit;
1152                 $subreq =  $_SERVER['SCRIPT_NAME'];
1153                 $request = substr($_SERVER['REDIRECT_URL'],$sublen);
1154                 
1155                  
1156             } else {
1157                   
1158              
1159                 $subreq = substr($request,0, strlen($this->baseURL));
1160                 if ($subreq != substr($this->baseURL,0,strlen($subreq))) {
1161                     $this->fatalError(
1162                         "Configuration error: Got base of $subreq which does not 
1163                             match configuration of: $this->baseURL} ");
1164                 }
1165                 $request = substr($request,strlen($this->baseURL));
1166                 
1167             }
1168             
1169              
1170         }
1171        // var_Dump(array('req'=>$request,'subreq'=>$subreq));
1172         
1173         // strip front
1174         // echo "REQUEST WAS: $request<BR>";
1175         // $request = preg_replace('/^'.preg_quote($base_url,'/').'/','',trim($request));
1176         // echo "IS NOW: $request<BR>";
1177         // strip end
1178         // strip valid html stuff
1179         //$request = preg_replace('/\/[.]+/','',$request);
1180         
1181
1182         $request = preg_replace('/^[\/]*/','',$request);
1183         $request = preg_replace('/\?.*$/','',$request);
1184         $request = preg_replace('/[\/]*$/','',$request);
1185         $this->baseRequest = $request;
1186         $request = str_replace('&','',$request); // any other invalid characters???
1187         $request = preg_replace('/\.([a-z]+)$/','',$request);
1188         $this->ext = substr($this->baseRequest , strlen($request));
1189         
1190         // REDIRECT ROO to index.php! for example..
1191         
1192         if (!$request && !$isRedirect) {
1193             if ($this->baseURL && (strlen($startRequest) < strlen($this->baseURL))) {
1194                 // needs to handle https + port
1195                 $http = ((!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]  == 'on')) ? 'https' : 'http';
1196                 $sp = '';
1197                 if (!empty($_SERVER['SERVER_PORT'])) {
1198                     if ((($http == 'http') && ($_SERVER['SERVER_PORT'] == 80)) || (($http == 'https') && ($_SERVER['SERVER_PORT'] == 443))) {
1199                         // standard ports..
1200                     } else {
1201                         $sp .= ':'.((int) $_SERVER['SERVER_PORT']);
1202                     }
1203                 }
1204                 $host = !empty($_SERVER["HTTP_X_FORWARDED_HOST"]) ? $_SERVER["HTTP_X_FORWARDED_HOST"] : $_SERVER["HTTP_HOST"];
1205                 header('Location: '.$http.'://'.$host .$sp . $this->baseURL);
1206  
1207                 exit;
1208             }
1209             $request = "";
1210         }
1211        // var_dump(array($startRequest,$request, $this->baseRequest));
1212         
1213         $this->debug("OUTPUT REQUEST $request<BR>");
1214         
1215         $this->_handleLanguages($request);
1216
1217         
1218         return $request;
1219     }
1220     
1221    
1222     
1223     
1224     /**
1225     * get the Class name and filename to load
1226     *
1227     * Parses the request and converts that into a File + Classname
1228     * if the class doesnt exist it will attempt to find a file below it, and
1229     * call that one with the data.
1230     * Used by the module loader to determine the location of the modules
1231     *   
1232     * @param   request  the request string
1233     * @param   boolean showError - if false, allows you to continue if the class doesnt exist.
1234     * 
1235     *
1236     * @return   array classname, filepath
1237     * @access   private
1238     * @static
1239     */
1240   
1241     function requestToClassName($request,$showError=TRUE) 
1242     {
1243        // if ($request == "error") {
1244        //     return array("HTML_FlexyFramework_Error","");
1245        // }
1246         
1247         // special classes ::
1248         if ($this->cli && in_array($request, array('DataObjects'))) {
1249             require_once 'HTML/FlexyFramework/'. $request . '.php';
1250             return array('HTML_FlexyFramework_'. $request,'');
1251         }
1252         
1253         
1254         $request_array=explode("/",$request);
1255         $original_request_array = $request_array;
1256         $sub_request_array = array();
1257         $l = count($request_array)-1;
1258         if ($l > 10) { // ?? configurable?
1259             //PEAR::raiseError("Request To Long");
1260             $this->fatalError("Request To Long - " . $request);
1261         }
1262
1263         
1264         $classname='';
1265         // tidy up request array
1266         
1267         if ($request_array) {
1268             foreach(array_keys($request_array) as $i) {
1269                 $request_array[$i] = preg_replace('/[^a-z0-9]/i','_',urldecode($request_array[$i]));
1270             }
1271         }
1272         //echo "<PRE>"; print_r($request_array);
1273         // technically each module should do a check here... similar to this..
1274         
1275         
1276         for ($i=$l;$i >-1;$i--) {
1277             $location = implode('/',$request_array) . ".php";
1278             if ($location == '.php') {
1279                 $this->debug("SKIP first path check, as request str is empty");
1280                 break;
1281             }
1282             
1283             $this->debug("baseDIR = {$this->baseDir}");
1284             
1285             $floc = "{$this->baseDir}/$location";
1286             $this->debug("CHECK LOCATION = $location");
1287             
1288             
1289             
1290             if (!empty($location) && $location != '.php' && @file_exists($floc )) {             // hide? error???
1291                 require_once $floc ;
1292                 $classname = $this->classPrefix . implode('_',$request_array);
1293                 $this->debug("FOUND FILE - SET CLASS = $classname <BR>");
1294                 break;
1295             } 
1296             
1297             // in here check the 'projectExtends' versions..?
1298             
1299             if(!empty($this->projectExtends)){
1300                 $this->debug("Trying project Extends<BR>");
1301                 $has_extend_class = false;
1302                 
1303                 foreach ($this->projectExtends as $e){
1304                     $floc = "{$this->rootDir}/{$e}/$location";
1305                     $this->debug("Trying file: $floc");
1306                     if (!empty($location) && @file_exists($floc)) {             // hide? error???
1307                         require_once $floc ;
1308                         $classname = $e . '_' . implode('_',$request_array);
1309                         $has_extend_class = true;
1310                         $this->debug("FOUND FILE - SET CLASS = $classname <BR>");
1311                         break;
1312                     } 
1313                 }
1314                 
1315                 if(!empty($has_extend_class)){
1316                     break;
1317                 }
1318                 
1319             }
1320             
1321             
1322             $this->debug("$floc  - !!FOUND NOT FILE!!");
1323             
1324             $sub_request_array[] = $original_request_array[$i];
1325             unset($request_array[$i]);
1326             unset($original_request_array[$i]);
1327         }
1328          
1329         // is this really needed here!
1330         
1331         $classname = preg_replace('/[^a-z0-9]/i','_',$classname);
1332         $this->debug("CLASSNAME is '$classname'");
1333         // got it ok.
1334         if ($classname && class_exists($classname)) {
1335             $this->debug("using $classname");
1336             //print_r($sub_request_array);
1337             return array($classname,implode('/',array_reverse($sub_request_array)));
1338         }
1339         // stop looping..
1340         if ($showError) {
1341             $this->fatalError("INVALID REQUEST: \n $request FILE:".$this->baseDir. "/{$location}  CLASS:{$classname}");
1342             
1343         } 
1344         
1345         
1346         $this->debug("Try base {$this->baseDir}.php");   
1347         // try {project name}.php
1348         // this used to be silenced @ - if this fails we are usually pretty fried..
1349         
1350         if (file_exists($this->baseDir.'.php')) {
1351             
1352             
1353             $classname = str_replace('/', '_', $this->project); //   basename($this->baseDir);
1354             
1355             $this->debug("FOUND {$this->baseDir} requring and checking class $classname");   
1356             require_once $this->baseDir.'.php';
1357             $this->debug("require success");
1358             
1359             if (!class_exists($classname)) {
1360                 $this->fatalError( "{$this->baseDir}.php did not contain class $classname");
1361             }
1362         }
1363         // got projectname.php
1364         if ($classname && class_exists($classname)) {
1365             $this->debug("using $classname");
1366             //print_r($sub_request_array);
1367              
1368             return array($classname,implode('/',array_reverse($sub_request_array)));
1369         }    
1370             
1371         
1372         $this->fatalError( "can not find {$this->baseDir}.php"); // dies..
1373               
1374      
1375     }
1376     
1377     /**
1378     * ensure Single CLi process 
1379     * usage:
1380     * HTML_FlexyFramework::ensureSingle(__FILE__, $this);
1381     * @param string filename of running class
1382     * @param object class
1383     */
1384       
1385     static function ensureSingle($sig, $class) 
1386     {
1387         //echo "check single: $sig / ". get_class($class) ."\n";
1388         $ff = HTML_FlexyFramework::get();
1389         if (function_exists('posix_getpwuid')) {
1390             $uinfo = posix_getpwuid( posix_getuid () ); 
1391             $user = $uinfo['name'];
1392         } else {
1393             $user = getenv('USERNAME'); // windows.
1394         }
1395         $fdir = ini_get('session.save_path') .'/' . 
1396                 $user . '_cli_' . $ff->project ;
1397      
1398         
1399         if (!file_exists($fdir)) {
1400             mkdir($fdir, 0777);
1401         }
1402         
1403         $lock = $fdir.'/'. md5($sig) . '.' . get_class($class);
1404         //echo "check single: lock : $lock\n";
1405         if (!file_exists($lock)) {
1406             file_put_contents($lock, getmypid());
1407             //echo "check single: lock : DOES NOT EXIST\n";
1408             return true;
1409         }
1410         $oldpid = file_get_contents($lock);
1411         if (!file_exists('/proc/' . $oldpid)) {
1412             
1413             file_put_contents($lock, getmypid());
1414           //  echo "check single: lock : PROC NOT EXIST\n";
1415             return true;
1416         }
1417         // file exists, but process might not be the same..
1418         $name = array_pop(explode('_', get_class($class)));
1419         $cmd = file_get_contents('/proc/' . $oldpid.'/cmdline');
1420         if (!preg_match('/php/i',$cmd) || !preg_match('/'.$name.'/i',$cmd)) {
1421             file_put_contents($lock, getmypid());
1422             //echo "check single: lock : CMDLINE !have PHP \n";
1423             return true;
1424         }
1425         die("process " . $sig . " already running\n");
1426         
1427     }
1428     /**
1429      * removes the lock for the applicaiton - use with care...
1430      *
1431      *
1432      */
1433     static function ensureSingleClear($sig, $class)
1434     {
1435         $ff = HTML_FlexyFramework::get();
1436         if (function_exists('posix_getpwuid')) {
1437             $uinfo = posix_getpwuid( posix_getuid () ); 
1438             $user = $uinfo['name'];
1439         } else {
1440             $user = getenv('USERNAME'); // windows.
1441         }
1442         $fdir = ini_get('session.save_path') .'/' . 
1443                 $user . '_cli_' . $ff->project ;
1444      
1445         
1446         if (!file_exists($fdir)) {
1447             mkdir($fdir, 0777);
1448         }
1449         $lock = $fdir.'/'. md5($sig);
1450         if (!file_exists($lock)) {
1451             
1452             return true;
1453         }
1454         unlink($lock);;
1455     }
1456     
1457     
1458     /**
1459     * Debugging 
1460     * 
1461     * @param   string  text to output.
1462     * @access   public
1463     */
1464   
1465     function debug($output) {
1466        
1467         if (empty($this->debug)) {  
1468             return;
1469         }
1470         echo $this->cli ? 
1471               "HTML_FlexyFramework::debug  - ".$output."\n" 
1472             : "<B>HTML_FlexyFramework::debug</B> - ".$output."<BR>\n";
1473     
1474     }
1475     /**
1476     * Raises a fatal error. - normally only used when setting up to help get the config right.
1477     * 
1478     * can redirect to fatal Action page.. - hoepfully not issued before basic vars are set up..
1479     * 
1480     * @param   string  text to output.
1481     * @access   public
1482     */
1483     
1484     function fatalError($msg,$showConfig = 0) 
1485     {
1486         
1487         
1488          if ($this->fatalAction) {
1489             HTML_FlexyFramework::run($this->fatalAction,$msg);
1490             exit;
1491         }
1492         
1493         echo $this->cli ? $msg ."\n" : "<H1>$msg</H1>configuration information<PRE>";
1494         if ($showConfig) {
1495             
1496             print_r($this);
1497         }
1498         $ff = HTML_FlexyFramework::get();
1499         $ff->debug($msg);
1500         exit;
1501     }    
1502 }
1503
1504