diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6c57557 --- /dev/null +++ b/composer.json @@ -0,0 +1,15 @@ +{ + "name": "alfredbez/ab_htmlmin", + "type": "oxid-module", + "description": "entfernt unnötige Whitespaces aus dem HTML-Code", + "require": { + "composer/installers": "~1.0" + }, + "authors": [ + { + "name": "Alfred Bez", + "email": "alfred.bez@gmail.com" + } + ], + "minimum-stability": "dev" +} diff --git a/ab_htmlmin/metadata.php b/metadata.php similarity index 100% rename from ab_htmlmin/metadata.php rename to metadata.php diff --git a/ab_htmlmin/models/ab_htmlmin.php b/models/ab_htmlmin.php similarity index 69% rename from ab_htmlmin/models/ab_htmlmin.php rename to models/ab_htmlmin.php index 9883820..01d889e 100644 --- a/ab_htmlmin/models/ab_htmlmin.php +++ b/models/ab_htmlmin.php @@ -13,10 +13,15 @@ */ class ab_htmlmin extends ab_htmlmin_parent { - protected function _fillCommonSmartyProperties( $oSmarty ) + protected function _fillCommonSmartyProperties($oSmarty) { parent::_fillCommonSmartyProperties($oSmarty); - include_once dirname(__FILE__).'/smarty/plugins/outputfilter.trimwhitespace.php'; - $oSmarty->load_filter ('output' , 'trimwhitespace'); + $cfg = oxRegistry::getConfig(); + + $aPluginsDir = $oSmarty->plugins_dir; + $aPluginsDir[] = $cfg->getModulesDir()."/ab_htmlmin/smarty/plugins/"; + $oSmarty->load_filter('output' , 'trimwhitespace'); + + $oSmarty->plugins_dir = $aPluginsDir; } -} \ No newline at end of file +} diff --git a/smarty/plugins/outputfilter.trimwhitespace.php b/smarty/plugins/outputfilter.trimwhitespace.php new file mode 100644 index 0000000..62ab4e7 --- /dev/null +++ b/smarty/plugins/outputfilter.trimwhitespace.php @@ -0,0 +1,90 @@ +.*?#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { + foreach ($matches as $match) { + $store[] = $match[0][0]; + $_length = strlen($match[0][0]); + $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; + $source = substr_replace($source, $replace, $match[0][1] - $_offset, $_length); + + $_offset += $_length - strlen($replace); + $_store ++; + } + } + + // Strip all HTML-Comments + // yes, even the ones in