X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Ftemplate%2Fclass_BaseTemplateEngine.php;h=89570fd2c52d37249340a975d61deb54457b039d;hp=ecc71c22a7de080950dc59ca6e3fd2527d37c3ee;hb=4b88c118b615335d06bd74e444173d21aef4406c;hpb=bd8a0f8e45a51ded51fd3afb2996c5e29f6852aa diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index ecc71c22..89570fd2 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -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 * @@ -1227,8 +1245,11 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * count has been found */ public function compileTemplate () { + // Get code type to make things shorter + $codeType = $this->getConfigInstance()->getConfigEntry('code_template_type'); + // We will only work with template type "code" from configuration - if ($this->getTemplateType() != $this->getConfigInstance()->getConfigEntry('code_template_type')) { + if (substr($this->getTemplateType(), 0, strlen($codeType)) != $codeType) { // Abort here throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->getConfigEntry('code_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED); } // END - if @@ -1474,6 +1495,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 $uncompactedContent The uncompacted content + * @return $compactedContent The compacted content + */ + public function compactContent ($uncompactedContent) { + // First, remove all tab/new-line/revert characters + $compactedContent = str_replace("\t", '', str_replace("\n", '', str_replace("\r", '', $uncompactedContent))); + + // Then regex all comments like away + preg_match_all('//', $compactedContent, $matches); + + // Do we have entries? + if (isset($matches[0][0])) { + // Remove all + foreach ($matches[0] as $match) { + // Remove the match + $compactedContent = str_replace($match, '', $compactedContent); + } // END - foreach + } // END - if + + // Return compacted content + return $compactedContent; + } } // [EOF]