From 835ba59b19e673e5fa9990871788f85d95e26a8b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 5 Apr 2009 09:12:41 +0000 Subject: [PATCH] Image engine rewritten, cache directories ignored --- .gitignore | 2 + .../captcha/images/class_ImageHelper.php | 2 +- .../template/class_BaseTemplateEngine.php | 48 ++++++++++++++----- .../image/class_ImageTemplateEngine.php | 25 +++++++++- inc/config.php | 3 ++ 5 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b516802f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +templates/_compiled/*.* +templates/images/_cache/*.* diff --git a/inc/classes/main/helper/captcha/images/class_ImageHelper.php b/inc/classes/main/helper/captcha/images/class_ImageHelper.php index 572c85bf..c293d0f1 100644 --- a/inc/classes/main/helper/captcha/images/class_ImageHelper.php +++ b/inc/classes/main/helper/captcha/images/class_ImageHelper.php @@ -350,7 +350,7 @@ class ImageHelper extends BaseCaptcha implements HelpableTemplate { $templateInstance = $this->getTemplateInstance(); // Get the base image - $templateInstance->loadCodeTemplate($this->getBaseImage()); + $templateInstance->loadImageTemplate($this->getBaseImage()); // Assign all the image values with the template $templateInstance->assignVariable('image_name' , $this->getImageName()); diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index 9abcd4b9..190e2e80 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -306,7 +306,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @param $templateType The current template's type * @return void */ - private final function setTemplateType ($templateType) { + protected final function setTemplateType ($templateType) { $this->templateType = (string) $templateType; } @@ -350,6 +350,16 @@ class BaseTemplateEngine extends BaseFrameworkSystem { return $this->templateBasePath; } + /** + * Getter for generic base path + * + * @return $templateBasePath The relative base path for all templates + */ + public final function getGenericBasePath () { + // And set it + return $this->genericBasePath; + } + /** * Setter for template extension * @@ -516,30 +526,44 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * * @param $template The template we shall load * @return void + * @throws FileNotFoundException If the template was not found */ - private function loadTemplate ($template) { - // Get extension for the template - $ext = $this->getRawTemplateExtension(); - - // If we shall load a code-template we need to switch the file extension - if ($this->getTemplateType() == $this->getConfigInstance()->readConfig('code_template_type')) { - // Switch over to the code-template extension - $ext = $this->getCodeTemplateExtension(); + protected function loadTemplate ($template, $ext = '') { + // Get extension for the template if empty + if (empty($ext)) { + // None provided, so get the raw one + $ext = $this->getRawTemplateExtension(); } // END - if // Construct the FQFN for the template by honoring the current language $fqfn = sprintf("%s%s%s%s/%s/%s%s", $this->getConfigInstance()->readConfig('base_path'), $this->getTemplateBasePath(), - $this->genericBasePath, + $this->getGenericBasePath(), $this->getLanguageInstance()->getLanguageCode(), $this->getTemplateType(), (string) $template, $ext ); - // Load the raw template data - $this->loadRawTemplateData($fqfn); + // First try this + try { + // Load the raw template data + $this->loadRawTemplateData($fqfn); + } catch (FileNotFoundException $e) { + // If we shall load a code-template we need to switch the file extension + if ($this->getTemplateType() != $this->getConfigInstance()->readConfig('web_template_type')) { + // Switch over to the code-template extension and try it again + $ext = $this->getCodeTemplateExtension(); + + // Try it again... + $this->loadTemplate($template, $ext); + } else { + // Throw it again + throw new FileNotFoundException($fqfn, FrameworkFileInputPointer::EXCEPTION_FILE_NOT_FOUND); + } + } + } /** diff --git a/inc/classes/main/template/image/class_ImageTemplateEngine.php b/inc/classes/main/template/image/class_ImageTemplateEngine.php index 0c8f4f5a..fd321ab4 100644 --- a/inc/classes/main/template/image/class_ImageTemplateEngine.php +++ b/inc/classes/main/template/image/class_ImageTemplateEngine.php @@ -474,7 +474,15 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl */ public function getImageCacheFqfn () { // Get the FQFN ready - $fqfn = $this->getTemplateBasePath().'_cache/' . md5($this->imageInstance->getImageName().':'.$this->__toString().':'.$this->imageInstance->__toString()) . '.' . $this->imageInstance->getImageType(); + $fqfn = sprintf("%s%s%s/%s.%s", + $this->getConfigInstance()->readConfig('base_path'), + $this->getGenericBasePath(), + 'images/_cache', + md5( + $this->imageInstance->getImageName().':'.$this->__toString().':'.$this->imageInstance->__toString() + ), + $this->imageInstance->getImageType() + ); // Return it return $fqfn; @@ -490,6 +498,21 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl // Set the image instance $responseInstance->setImageInstance($this->imageInstance); } + + /** + * Load a specified image template into the engine + * + * @param $template The image template we shall load which is + * located in 'image' by default + * @return void + */ + public function loadImageTemplate ($template) { + // Set template type + $this->setTemplateType($this->getConfigInstance()->readConfig('image_template_type')); + + // Load the special template + $this->loadTemplate($template); + } } // [EOF] diff --git a/inc/config.php b/inc/config.php index 2b362390..910eff67 100644 --- a/inc/config.php +++ b/inc/config.php @@ -107,6 +107,9 @@ $cfg->setConfigEntry('email_template_type', 'emails'); // CFG: CODE-TEMPLATE-TYPE $cfg->setConfigEntry('code_template_type', 'code'); +// CFG: IMAGE-TEMPLATE-TYPE +$cfg->setConfigEntry('image_template_type', 'image'); + // CFG: WEB-ENGINE $cfg->setConfigEntry('output_class', 'WebOutput'); -- 2.39.5