]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/template/class_BaseTemplateEngine.php
die() removed... :(
[core.git] / inc / classes / main / template / class_BaseTemplateEngine.php
index 79981fb6d5bcbf5b6366f5a0744f60f25a25357a..fe332f2dcd7b40adef72e8512b031dc373d16db1 100644 (file)
@@ -131,6 +131,11 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private $codeEnd = '?>';
 
+       /**
+        * Language support is enabled by default
+        */
+       private $languageSupport = true;
+
        // Exception codes for the template engine
        const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED   = 0x110;
        const EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR = 0x111;
@@ -523,7 +528,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $template       The template we shall load
         * @param       $extOther       An other extension to use
         * @return      void
-        * @throws      FileNotFoundException   If the template was not found
+        * @throws      FileIoException If the template was not found
         */
        protected function loadTemplate ($template, $extOther = '') {
                // Get extension for the template if empty
@@ -535,22 +540,35 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                        $ext = (string) $extOther;
                }
 
-               // Construct the FQFN for the template by honoring the current language
-               $fqfn = sprintf("%s%s%s%s/%s/%s%s",
-                       $this->getConfigInstance()->getConfigEntry('base_path'),
-                       $this->getTemplateBasePath(),
-                       $this->getGenericBasePath(),
-                       $this->getLanguageInstance()->getLanguageCode(),
-                       $this->getTemplateType(),
-                       (string) $template,
-                       $ext
-               );
+               // Is language support enabled?
+               if ($this->isLanguageSupportEnabled()) {
+                       // Construct the FQFN for the template by honoring the current language
+                       $fqfn = sprintf("%s%s%s%s/%s/%s%s",
+                               $this->getConfigInstance()->getConfigEntry('base_path'),
+                               $this->getTemplateBasePath(),
+                               $this->getGenericBasePath(),
+                               $this->getLanguageInstance()->getLanguageCode(),
+                               $this->getTemplateType(),
+                               (string) $template,
+                               $ext
+                       );
+               } else {
+                       // Construct the FQFN for the template without language
+                       $fqfn = sprintf("%s%s%s%s/%s%s",
+                               $this->getConfigInstance()->getConfigEntry('base_path'),
+                               $this->getTemplateBasePath(),
+                               $this->getGenericBasePath(),
+                               $this->getTemplateType(),
+                               (string) $template,
+                               $ext
+                       );
+               }
 
                // First try this
                try {
                        // Load the raw template data
                        $this->loadRawTemplateData($fqfn);
-               } catch (FileNotFoundException $e) {
+               } catch (FileIoException $e) {
                        // If we shall load a code-template we need to switch the file extension
                        if (($this->getTemplateType() != $this->getConfigInstance()->getConfigEntry('web_template_type')) && (empty($extOther))) {
                                // Switch over to the code-template extension and try it again
@@ -560,7 +578,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                $this->loadTemplate($template, $ext);
                        } else {
                                // Throw it again
-                               throw new FileNotFoundException($fqfn, FrameworkFileInputPointer::EXCEPTION_FILE_NOT_FOUND);
+                               throw new FileIoException($fqfn, FrameworkFileInputPointer::EXCEPTION_FILE_NOT_FOUND);
                        }
                }
 
@@ -689,10 +707,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                                // Remember this template for recursion detection
                                                // RECURSIVE PROTECTION!
                                                $this->loadedTemplates[] = $template;
-                                       } catch (FileNotFoundException $e) {
-                                               // Even this is not done... :/
-                                               $this->rawTemplates[] = $template;
-                                       } catch (FilePointerNotOpenedException $e) {
+                                       } catch (FileIoException $e) {
                                                // Even this is not done... :/
                                                $this->rawTemplates[] = $template;
                                        }
@@ -791,10 +806,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                        // Remember this template for recursion detection
                                        // RECURSIVE PROTECTION!
                                        $this->loadedTemplates[] = $template;
-                               } catch (FileNotFoundException $e) {
-                                       // This template was never found. We silently ignore it
-                                       unset($this->rawTemplates[$key]);
-                               } catch (FilePointerNotOpenedException $e) {
+                               } catch (FileIoException $e) {
                                        // This template was never found. We silently ignore it
                                        unset($this->rawTemplates[$key]);
                                }
@@ -950,6 +962,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $template       The email template we shall load which is located in
         *                                              'emails' by default
         * @return      void
+        * @deprecated
+        * @see         See loadCodeTemplate()
         */
        public function loadEmailTemplate ($template) {
                // Set template type
@@ -1289,43 +1303,37 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @return      void
         * @throws      XmlParserException      If an XML error was found
         */
-       public final function renderXmlContent ($content = null) {
+       public function renderXmlContent ($content = null) {
                // Is the content set?
                if (is_null($content)) {
                        // Get current content
                        $content = $this->getRawTemplateData();
                } // END - if
 
-               // Convert all to UTF8
-               if (function_exists('recode')) {
-                       $content = recode("html..utf8", $content);
-               } else {
-                       // @TODO We need to find a fallback solution here
-                       $this->partialStub('Cannot find recode extension!');
-               } // END - if
-
-               // Get an XML parser
-               $xmlParser = xml_parser_create();
-
-               // Force case-folding to on
-               xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, true);
-
-               // Set object
-               xml_set_object($xmlParser, $this);
+               // Get a XmlParser instance
+               $parserInstance = ObjectFactory::createObjectByConfiguredName('xml_parser_class', array($this));
 
-               // Set handler call-backs
-               xml_set_element_handler($xmlParser, 'startElement', 'endElement');
-               xml_set_character_data_handler($xmlParser, 'characterHandler');
+               // Parse the XML document
+               $parserInstance->parseXmlContent($content);
+       }
 
-               // Now parse the XML tree
-               if (!xml_parse($xmlParser, $content)) {
-                       // Error found in XML!
-                       //die('<pre>'.htmlentities($content).'</pre>');
-                       throw new XmlParserException(array($this, $xmlParser), BaseHelper::EXCEPTION_XML_PARSER_ERROR);
-               } // END - if
+       /**
+        * Enables or disables language support
+        *
+        * @param       $languageSupport        New language support setting
+        * @return      void
+        */
+       public final function enableLanguageSupport ($languageSupport = true) {
+               $this->languageSupport = (bool) $languageSupport;
+       }
 
-               // Free the parser
-               xml_parser_free($xmlParser);
+       /**
+        * Checks wether language support is enabled
+        *
+        * @return      $languageSupport        Wether language support is enabled or disabled
+        */
+       public final function isLanguageSupportEnabled () {
+               return $this->languageSupport;
        }
 }