diff --git a/lib/templating/templating.inc.php b/lib/templating/templating.inc.php new file mode 100644 index 0000000..2acdab8 --- /dev/null +++ b/lib/templating/templating.inc.php @@ -0,0 +1,102 @@ +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) { + $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("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("Could not find template language"); + } + + return new $sClass($sTemplatePath); + } + // }}} +} + +?>