aTemplateRegistry = array( "smarty" => "KTSmartyTemplate", ); $this->aLocationRegistry = array( "core" => "templates", ); } // }}} // {{{ _chooseTemplate function _chooseTemplate($templatename, $aPossibilities) { $aLocs = array_keys($aPossibilities); return $aPossibilities[$aLocs[count($aLocs) - 1]]; } // }}} // {{{ _findTemplate function _findTemplate($templatename) { $aPossibilities = array(); foreach ($this->aLocationRegistry as $loc => $path) { if (KTUtil::isAbsolutePath($path)) { $fulldirectory = $path . "/"; foreach (array_keys($this->aTemplateRegistry) as $suffix) { $fullpath = $fulldirectory . $templatename . "." . $suffix; if (file_exists($fullpath)) { $aPossibilities[$loc] = array($suffix, $fullpath); } } } $fulldirectory = KT_DIR . "/" . $path . "/"; foreach (array_keys($this->aTemplateRegistry) as $suffix) { $fullpath = $fulldirectory . $templatename . "." . $suffix; if (file_exists($fullpath)) { $aPossibilities[$loc] = array($suffix, $fullpath); } } } if (count($aPossibilities) === 0) { return PEAR::raiseError(_kt("No template found")); } return $this->_chooseTemplate($templatename, $aPossibilities); } // }}} // {{{ loadTemplate /** * Create an object that conforms to the template interface, using * the correct template system for the given template. * * KTI: Theoretically, this will do path searching in multiple * locations, allowing the user and possibly third-parties to * replace templates. */ function &loadTemplate($templatename) { $res = $this->_findTemplate($templatename); if (PEAR::isError($res)) { return $res; } list($sLanguage, $sTemplatePath) = $res; $sClass = $this->aTemplateRegistry[$sLanguage]; if (!class_exists($sClass)) { return PEAR::raiseError(_kt("Could not find template language")); } $oTemplate =& new $sClass($sTemplatePath); return $oTemplate; } // }}} // {{{ addLocation function addLocation ($descr, $loc) { $this->aLocationRegistry[$descr] = $loc; } // }}} // {{{ getSingleton function &getSingleton () { if (!KTUtil::arrayGet($GLOBALS['_KT_PLUGIN'], 'oKTTemplating')) { $GLOBALS['_KT_PLUGIN']['oKTTemplating'] = new KTTemplating; } return $GLOBALS['_KT_PLUGIN']['oKTTemplating']; } // }}} function renderTemplate($sTemplate, $aOptions) { $oTemplating =& KTTemplating::getSingleton(); $oTemplate =& $oTemplating->loadTemplate($sTemplate); return $oTemplate->render($aOptions); } } ?>