From 71dc6209a559b6d8db0e958355ef62f8aa07565a Mon Sep 17 00:00:00 2001 From: Robin Lehrmann Date: Wed, 29 Oct 2014 08:32:10 +0100 Subject: [PATCH 1/3] integrate composer --- composer.json | 14 ++++++++++++++ ab_htmlmin/metadata.php => metadata.php | 0 {ab_htmlmin/models => models}/ab_htmlmin.php | 0 3 files changed, 14 insertions(+) create mode 100644 composer.json rename ab_htmlmin/metadata.php => metadata.php (100%) rename {ab_htmlmin/models => models}/ab_htmlmin.php (100%) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c74165b --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "name": "alfredbez/ab_htmlmin", + "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 100% rename from ab_htmlmin/models/ab_htmlmin.php rename to models/ab_htmlmin.php From dfa681b0125f830b7e8eb902524e73fb2d411f2a Mon Sep 17 00:00:00 2001 From: Robin Lehrmann Date: Wed, 29 Oct 2014 08:37:19 +0100 Subject: [PATCH 2/3] add type --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index c74165b..6c57557 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "name": "alfredbez/ab_htmlmin", + "type": "oxid-module", "description": "entfernt unnötige Whitespaces aus dem HTML-Code", "require": { "composer/installers": "~1.0" From fac36f8954967c299409af3bdf6972ae411e66cf Mon Sep 17 00:00:00 2001 From: Robin Lehrmann Date: Wed, 29 Oct 2014 08:47:25 +0100 Subject: [PATCH 3/3] add plugin to module --- models/ab_htmlmin.php | 13 ++- .../plugins/outputfilter.trimwhitespace.php | 90 +++++++++++++++++++ 2 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 smarty/plugins/outputfilter.trimwhitespace.php diff --git a/models/ab_htmlmin.php b/models/ab_htmlmin.php index 9883820..01d889e 100644 --- a/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