]> git.mxchange.org Git - core.git/commitdiff
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 572c85bfb7794fdecd74261131ae19448648d466..c293d0f18a0dae1be559705379d6793c2cefa42a 100644 (file)
@@ -350,7 +350,7 @@ class ImageHelper extends BaseCaptcha implements HelpableTemplate {
                $templateInstance = $this->getTemplateInstance();
 
                // Get the base image
                $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());
 
                // Assign all the image values with the template
                $templateInstance->assignVariable('image_name'    , $this->getImageName());
index 9abcd4b9fdbdef7a4bac3285c1d1c51742d64b73..190e2e8054085ea72373fc576327dac03cdaf081 100644 (file)
@@ -306,7 +306,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $templateType   The current template's type
         * @return      void
         */
         * @param       $templateType   The current template's type
         * @return      void
         */
-       private final function setTemplateType ($templateType) {
+       protected final function setTemplateType ($templateType) {
                $this->templateType = (string) $templateType;
        }
 
                $this->templateType = (string) $templateType;
        }
 
@@ -350,6 +350,16 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                return $this->templateBasePath;
        }
 
                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
         *
        /**
         * Setter for template extension
         *
@@ -516,30 +526,44 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         *
         * @param       $template       The template we shall load
         * @return      void
         *
         * @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(),
                } // 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
                );
 
                        $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 0c8f4f5aedfd92f4e881beb607b2f5f307bf4915..fd321ab4628f33f7ac44809f9291be63d52ac0e5 100644 (file)
@@ -474,7 +474,15 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
         */
        public function getImageCacheFqfn () {
                // Get the FQFN ready
         */
        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;
 
                // Return it
                return $fqfn;
@@ -490,6 +498,21 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
                // Set the image instance
                $responseInstance->setImageInstance($this->imageInstance);
        }
                // 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]
 }
 
 // [EOF]
index 2b3623907597e162036097e13ad5ae9bb5bfcfac..910eff67df0379bced860741437f21bb81a67425 100644 (file)
@@ -107,6 +107,9 @@ $cfg->setConfigEntry('email_template_type', 'emails');
 // CFG: CODE-TEMPLATE-TYPE
 $cfg->setConfigEntry('code_template_type', 'code');
 
 // 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');
 
 // CFG: WEB-ENGINE
 $cfg->setConfigEntry('output_class', 'WebOutput');