]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/template/class_BaseTemplateEngine.php
Completed decorator, extended interface
[core.git] / inc / classes / main / template / class_BaseTemplateEngine.php
index ecc71c22a7de080950dc59ca6e3fd2527d37c3ee..b64477c4f10b41704cfbe582ba49b11ef1cfbfde 100644 (file)
@@ -590,10 +590,27 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                // Was it found?
                if ($index !== false) {
                        // Remove this variable
-                       $this->varStack->offsetUnset($index);
+                       $this->unsetVariableStackOffset($index);
                } // END - if
        }
 
+       /**
+        * Unsets the given offset in the variable stack
+        *
+        * @param       $index  Index to unset
+        * @return      void
+        */
+       protected final function unsetVariableStackOffset ($index) {
+               // Is the entry there?
+               if (!isset($this->varStack[$this->currGroup][$index])) {
+                       // Abort here, we need fixing!
+                       $this->debugInstance();
+               } // END - if
+
+               // Remove it
+               unset($this->varStack[$this->currGroup][$index]);
+       }
+
        /**
         * Private setter for raw template data
         *
@@ -958,6 +975,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
 
                } // for ($varMatches ...
        }
+
        /**
         * Compiles all loaded raw templates
         *
@@ -1474,6 +1492,32 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
        public final function isXmlCompactingEnabled () {
                return $this->xmlCompacting;
        }
+
+       /**
+        * Removes all commentd, tabs and new-line characters to compact the content
+        *
+        * @param       $content        The uncompacted content
+        * @return      $content        The compacted content
+        */
+       public function compactContent ($content) {
+               // First, remove all tab/new-line/revert characters
+               $content = str_replace("\t", '', str_replace("\n", '', str_replace("\r", '', $content)));
+
+               // Then regex all comments like <!-- //--> away
+               preg_match_all('/<!--[\w\W]*?(\/\/){0,1}-->/', $content, $matches);
+
+               // Do we have entries?
+               if (isset($matches[0][0])) {
+                       // Remove all
+                       foreach ($matches[0] as $match) {
+                               // Remove the match
+                               $content = str_replace($match, '', $content);
+                       } // END - foreach
+               } // END - if
+
+               // Return compacted content
+               return $content;
+       }
 }
 
 // [EOF]