[Phpslash-commit] CVS: phpslash-dev/include/class slashTemplate.class,1.7,1.8
Brought to you by:
joestewart,
nhruby
From: Peter C. <kr...@us...> - 2004-07-29 15:35:50
|
Update of /cvsroot/phpslash/phpslash-dev/include/class In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28976 Modified Files: slashTemplate.class Log Message: Fix set_file bug which caused infinite loop Index: slashTemplate.class =================================================================== RCS file: /cvsroot/phpslash/phpslash-dev/include/class/slashTemplate.class,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** slashTemplate.class 7 Jul 2004 17:22:32 -0000 1.7 --- slashTemplate.class 29 Jul 2004 15:35:42 -0000 1.8 *************** *** 1,12 **** <?php /** ! * slashTemplate.class -> Primary methods for providing Templates ! * @version $Id$ ! * ! * Provides Session functions of PHPSlash ! * ! * Extends the phplib Template class. ! * ! */ class slashTemplate extends Template { --- 1,20 ---- <?php /** ! * slashTemplate.class -> Primary methods for providing Templates ! * ! * Provides specific template handling functions for PHPSlash ! * ! * Main extension is implicit search bath: ! * - given skin, given language ** (to be added) ! * - current skin, current language ! * - parent skin, skin.parent.language (or current language) ! * - parent skin, default language ! * - "module directory"/templates/ ?? Why no language path?? ! * - "module directory" ! * - default skin, default language* ?? Why not check current language first ! * ! * @class slashTemplate ! * @version $Id$ ! */ class slashTemplate extends Template { *************** *** 17,21 **** var $psl; - /** * The slashTemplate Constructor --- 25,28 ---- *************** *** 29,33 **** function slashTemplate($root = ".", $unknowns = "remove") { global $_PSL, $ary; ! $this->psl = &$_PSL; $this->ary = &$ary; --- 36,40 ---- function slashTemplate($root = ".", $unknowns = "remove") { global $_PSL, $ary; ! $this->psl = &$_PSL; $this->ary = &$ary; *************** *** 47,51 **** **/ function set_root($root="") { - } --- 54,57 ---- *************** *** 58,147 **** * skin.ini file. * * @access public ! * @param string varname ! * @param string filename ! **/ function set_file($varname, $filename = "", $skin="", $language="") { ! if (!is_array($varname)) { ! // default to the current skin ! if($skin == "") { ! $skin = $this->psl['skin.current']; } ! // default to the current language ! if($language == "") { ! $language = $this->psl['language.current']; } ! // assemble the templatedir ! // $templatedir = $this->psl['templatedir.main'] ."/". basename($language) ."/". basename($skin); ! $templatedir = $this->psl['templatedir.main'] ."/". $language ."/". $skin; ! // assemble the filepath ! $filepath = $templatedir ."/". $filename; ! // debug("slashTemplate::set_file::filepath", $filepath); ! ! $status = false; ! ! if( file_exists($filepath)) { ! // module templates in skin directory ! $status = Template::set_file($varname, $filepath); ! } elseif(file_exists($templatedir ."/skin.ini")) { ! // parent skin defined ! $skin_cfg = ''; ! $skin_cfg = parse_ini_file($templatedir ."/skin.ini"); ! if(!empty($skin_cfg['skin.parent.language'])) { ! $language = $skin_cfg['skin.parent.language']; ! } ! if($this->set_file($varname, $filename, $skin_cfg['skin.parent'], $language)) { ! // template in current language / parent skin ! $status = true; ! } elseif($this->set_file($varname, $filename, $skin_cfg['skin.parent'], $this->psl['language.default'])) { ! // template in default language / parent skin ! $status = true; ! } ! // $status = false; ! // $this->message = "set_file: set_file: For varname $varname filename $filepath is invalid."; ! // $this->halt($this->message); ! } else { ! // no parent skin ! ! // try to find template in module/template, skin/module, or in ! // defaultskin directory. ! if(file_exists($this->psl['moduledir'] ."/". $this->psl['module'][$this->psl['module']['module.current']] ."/templates/" . basename($filename))) { ! // module templates in module subdirectory ! $filepath = $this->psl['moduledir'] ."/". $this->psl['module'][$this->psl['module']['module.current']] ."/templates/" . basename($filename); ! $status = Template::set_file($varname, $filepath); ! } elseif( file_exists($templatedir ."/". $this->psl['module'][$this->psl['module']['module.current']] ."/". basename($filename))) { ! // module templates in subdirectory of skin ! $filepath = $templatedir ."/". $this->psl['module'][$this->psl['module']['module.current']] ."/". basename($filename); ! $status = Template::set_file($varname, $filepath); ! #Commented out: This leads an infinite loop since the skin directory is not used. ! # } elseif($this->set_file($varname, $filename, $this->psl['defaultskin'], $this->psl['language.default'])) { ! # // template in default language / default skin ! # $status = true; ! } else { ! // template isn't in the defaults either - bail out ! $this->message = "set_file: set_file: For varname $varname filename $filepath is invalid."; ! // $this->halt($this->message); ! $status = false; ! } } ! ! } else { ! reset($varname); ! $status = true; ! while(list($v, $f) = each($varname)) { ! if(!$this->set_file($v, $f)) { ! $status = false; ! break; ! } } } ! return $status; ! } // end of function set_root --- 64,178 ---- * skin.ini file. * + * We have to to check for existence of template file before caling template::set_file + * because it would HALT the code! + * * @access public ! * @param mixed $varname string or array (varname => filename). If array, remaining parameters are ignored ! * @param string $filename ! * @param string $skin ! * @param string $language ! * @return boolean ! */ function set_file($varname, $filename = "", $skin="", $language="") { ! #debug('filename',$filename); ! // If we're given an array of varname=>filename, recurse & attampt to set each ! // - bailing out at first failure ! if (is_array($varname)) { ! foreach ($varname as $v => $f) { ! #debug('setting f',$f); ! if (!$this->set_file($v, $f)) { ! return false; ! } } + return true; + } ! ! // The rest of this function looks for the template in the various places it could be ! ! // Intitialisation: ! // - default to the current skin ! if ($skin == "") { ! $skin = $this->psl['skin.current']; ! } else { ! // belt and braces - make sure noone's messing ! $skin = basename($skin); ! } ! ! // - default to the current language ! if ($language == "") { ! $language = $this->psl['language.current']; ! } else { ! // belt and braces - make sure noone's messing ! $language = basename($language); ! } ! ! // - assemble the templatedir ! $filename = basename($filename); ! $templatedir = $this->psl['templatedir.main'] ."/$language/$skin"; ! // - assemble the filepath ! $filepath = $templatedir .'/'. $filename; ! ! // First: Try given absolute path ! if (file_exists($filepath)) { ! #debug("[1] filepath exists", $filepath); ! // module templates in skin directory ! return Template::set_file($varname, $filepath); ! } ! ! // Second: Recurse up any parent skins ! if (file_exists("$templatedir/skin.ini")) { ! // parent skin defined ! $skin_cfg = parse_ini_file("$templatedir/skin.ini"); ! if (!empty($skin_cfg['skin.parent.language'])) { ! $language = $skin_cfg['skin.parent.language']; ! } ! if ($this->set_file($varname, $filename, $skin_cfg['skin.parent'], $language)) { ! #debug("[2a] Using skin".$skin_cfg['skin.parent'], $filename); ! // template in current language / parent skin ! return true; } ! if ($this->set_file($varname, $filename, $skin_cfg['skin.parent'] , $this->psl['language.default'])) { // template in default language / parent skin ! #debug("[2b] Using skin (with default language)".$skin_cfg['skin.parent'], $filename); ! return true; } ! } ! // Third: Try module directory for skins (module/templates) ! $modulePath = $this->psl['moduledir'] ."/". $this->psl['module'][$this->psl['module']['module.current']] ."/templates/"; ! if (file_exists($modulePath."/$language/$filename")) { ! #debug('[3a] using',$modulePath."/$language/$filename"); ! return Template::set_file($varname, $modulePath."/$language/$filename"); ! } elseif (file_exists($modulePath.'/'.$this->psl['language.default'].'/'.$filename)) { ! #debug('[3b] using',$modulePath.'/'.$this->psl['language.default'].'/'.$filename); ! return Template::set_file($varname, $modulePath.'/'.$this->psl['language.default'].'/'.$filename); ! } elseif (file_exists($modulePath.'/'.$filename)) { ! #debug('[3c] using',$modulePath.'/'.$filename); ! return Template::set_file($varname, $modulePath.'/'.$filename); ! } ! ! // Fourth: Check skin directory for module subdirectory (templatedir/module) ! $modulePath = $templatedir ."/". $this->psl['module'][$this->psl['module']['module.current']] ."/$filename"; ! if (file_exists($modulePath)) { ! #debug('[4] modulepath',$modulePath); ! // module templates in subdirectory of skin ! return Template::set_file($varname, $modulePath); ! } ! ! // Fifth: Try default skin and default language, if we're not already there (this is getting desperate) ! if ($this->psl['defaultskin'] |= $skin && $this->psl['language.default'] != $language) { ! debug('[5] default skin and language',$filename); ! if ($this->set_file($varname, $filename , $this->psl['defaultskin'], $this->psl['language.default'])) { ! return true; } } ! // Finally: Template isn't in the defaults either - bail out ! $this->message = "set_file: set_file: For varname $varname filename $filepath is invalid."; ! return false; ! } // end of function set_file |