Image engine rewritten, cache directories ignored
authorRoland Häder <roland@mxchange.org>
Sun, 5 Apr 2009 09:12:41 +0000 (09:12 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 5 Apr 2009 09:12:41 +0000 (09:12 +0000)
.gitignore [new file with mode: 0644]
inc/classes/main/helper/captcha/images/class_ImageHelper.php
inc/classes/main/template/class_BaseTemplateEngine.php
inc/classes/main/template/image/class_ImageTemplateEngine.php
inc/config.php

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b516802
--- /dev/null
@@ -0,0 +1,2 @@
+templates/_compiled/*.*
+templates/images/_cache/*.*
index 572c85b..c293d0f 100644 (file)
@@ -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());
index 9abcd4b..190e2e8 100644 (file)
@@ -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;
        }
 
@@ -351,6 +351,16 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
        }
 
        /**
+        * 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
         *
         * @param               $templateExtension      The file extension for all uncompiled
@@ -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);
+                       }
+               }
+
        }
 
        /**
index 0c8f4f5..fd321ab 100644 (file)
@@ -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]
index 2b36239..910eff6 100644 (file)
@@ -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');