Compare commits
No commits in common. "master" and "v0.1" have entirely different histories.
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,6 +0,0 @@
|
|||||||
# Created by .ignore support plugin (hsz.mobi)
|
|
||||||
vendor
|
|
||||||
composer.lock
|
|
||||||
source
|
|
||||||
.phpstorm-oxid.meta.php
|
|
||||||
ab_htmlmin.iml
|
|
40
README.md
40
README.md
@ -2,35 +2,53 @@ HTML minify
|
|||||||
=============================
|
=============================
|
||||||
Enables Smarty 'trimwhitespace' Outputfilter to minify HTML Code
|
Enables Smarty 'trimwhitespace' Outputfilter to minify HTML Code
|
||||||
|
|
||||||
Versions
|
|
||||||
------------
|
|
||||||
| OXID eShop Version | Module Version |
|
|
||||||
|------|------|
|
|
||||||
| v5.x | v0.x |
|
|
||||||
| v6.x | v1.x |
|
|
||||||
|
|
||||||
|
|
||||||
Download
|
Download
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
There are several ways to download the module:
|
||||||
|
### Download-Option 1: Download via composer (recommended)
|
||||||
first you need [composer](https://getcomposer.org/download/)
|
first you need [composer](https://getcomposer.org/download/)
|
||||||
|
|
||||||
add the module to your composer.json
|
add the module to your composer.json
|
||||||
* via command line ```composer require alfredbez/ab_htmlmin:"^1.0"```
|
* via command line ```composer.phar require alfredbez/ab_htmlmin dev-master```
|
||||||
* OR
|
* OR
|
||||||
* manually
|
* manually
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"alfredbez/ab_htmlmin": "^1.0""
|
"alfredbez/ab_htmlmin": "dev-master"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This will install the OXID-v6 module. If you need the module for an older shop just use `v0.1` instead of `v1.0`.
|
### Download-Option 2: Download using git clone
|
||||||
|
```git clone https://github.com/alfredbez/ab_htmlmin.git```
|
||||||
|
|
||||||
|
### Download-Option 3: Download ZIP
|
||||||
|
[download](https://github.com/alfredbez/ab_htmlmin/archive/master.zip) and extract zip
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
If you downloaded the module manually or via git:
|
||||||
|
* rename the folder to 'ab_htmlmin' if the folder name is 'ab_htmlmin-master'
|
||||||
|
* you have to move the folder 'ab_htmlmin' to your 'modules'-folder.
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
**Don't forget to activate module in the OXID backend**
|
**Don't forget to activate module in the OXID backend**
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
After uploading the module, your directory should look like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
├── index.php
|
||||||
|
├── bootstrap.php
|
||||||
|
├── config.inc.php
|
||||||
|
├── ...
|
||||||
|
└── modules
|
||||||
|
└── ab_htmlmin
|
||||||
|
├── README.md
|
||||||
|
├── metadata.php
|
||||||
|
└── models
|
||||||
|
```
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "alfredbez/ab_htmlmin",
|
"name": "alfredbez/ab_htmlmin",
|
||||||
"type": "oxideshop-module",
|
"type": "oxid-module",
|
||||||
"keywords": ["oxid", "modules", "eShop"],
|
|
||||||
"description": "entfernt unnötige Whitespaces aus dem HTML-Code",
|
"description": "entfernt unnötige Whitespaces aus dem HTML-Code",
|
||||||
"require": {
|
"require": {
|
||||||
"oxid-esales/oxideshop-ce": "7.0 - 7.0"
|
"composer/installers": "~1.0"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
@ -12,11 +11,5 @@
|
|||||||
"email": "alfred.bez@gmail.com"
|
"email": "alfred.bez@gmail.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"extra": {},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"AlfredBez\\HtmlMin\\": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"minimum-stability": "dev"
|
"minimum-stability": "dev"
|
||||||
}
|
}
|
||||||
|
28
metadata.php
28
metadata.php
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Version: 2.0
|
* Version: 1.0
|
||||||
* Author: Alfred Bez <alfred.bez@gmail.com>
|
* Author: Alfred Bez <alfred.bez@gmail.com>
|
||||||
* Author URI: http://www.alfredbez.de
|
* Author URI: http://www.alfredbez.de
|
||||||
*/
|
*/
|
||||||
@ -9,20 +9,20 @@
|
|||||||
/**
|
/**
|
||||||
* Metadata version
|
* Metadata version
|
||||||
*/
|
*/
|
||||||
$sMetadataVersion = '2.1';
|
$sMetadataVersion = '1.1';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module information
|
* Module information
|
||||||
*/
|
*/
|
||||||
$aModule = [
|
$aModule = array(
|
||||||
'id' => 'ab_htmlmin',
|
'id' => 'ab_htmlmin',
|
||||||
'title' => 'Alfred Bez :: HTML minify',
|
'title' => 'Alfred Bez :: HTML minify',
|
||||||
'description' => 'entfernt unnötige Whitespaces aus dem HTML-Code',
|
'description' => 'entfernt unnötige Whitespaces aus dem HTML-Code',
|
||||||
'version' => '2.0',
|
'version' => '1.0',
|
||||||
'author' => 'Alfred Bez',
|
'author' => 'Alfred Bez',
|
||||||
'url' => 'https://www.alfredbez.de',
|
'url' => 'http://www.alfredbez.de',
|
||||||
'email' => 'alfred.bez@gmail.com',
|
'email' => 'alfred.bez@gmail.com',
|
||||||
'extend' => [
|
'extend' => array(
|
||||||
\OxidEsales\Eshop\Core\UtilsView::class => \AlfredBez\HtmlMin\Modules\Core\UtilsView::class,
|
'oxutilsview' => 'ab_htmlmin/models/ab_htmlmin'
|
||||||
],
|
)
|
||||||
];
|
);
|
||||||
|
@ -11,14 +11,17 @@
|
|||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
* You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>
|
* You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
class ab_htmlmin extends ab_htmlmin_parent {
|
||||||
namespace AlfredBez\HtmlMin\Modules\Core;
|
|
||||||
|
|
||||||
class UtilsView extends UtilsView_parent {
|
|
||||||
|
|
||||||
protected function _fillCommonSmartyProperties($oSmarty)
|
protected function _fillCommonSmartyProperties($oSmarty)
|
||||||
{
|
{
|
||||||
parent::_fillCommonSmartyProperties($oSmarty);
|
parent::_fillCommonSmartyProperties($oSmarty);
|
||||||
|
$cfg = oxRegistry::getConfig();
|
||||||
|
|
||||||
|
$aPluginsDir = $oSmarty->plugins_dir;
|
||||||
|
$aPluginsDir[] = $cfg->getModulesDir()."/ab_htmlmin/smarty/plugins/";
|
||||||
$oSmarty->load_filter('output' , 'trimwhitespace');
|
$oSmarty->load_filter('output' , 'trimwhitespace');
|
||||||
|
|
||||||
|
$oSmarty->plugins_dir = $aPluginsDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
90
smarty/plugins/outputfilter.trimwhitespace.php
Normal file
90
smarty/plugins/outputfilter.trimwhitespace.php
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Smarty plugin
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage PluginsFilter
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty trimwhitespace outputfilter plugin
|
||||||
|
* Trim unnecessary whitespace from HTML markup.
|
||||||
|
*
|
||||||
|
* @author Rodney Rehm
|
||||||
|
*
|
||||||
|
* @param string $source input string
|
||||||
|
*
|
||||||
|
* @return string filtered output
|
||||||
|
* @todo substr_replace() is not overloaded by mbstring.func_overload - so this function might fail!
|
||||||
|
*/
|
||||||
|
function smarty_outputfilter_trimwhitespace($source)
|
||||||
|
{
|
||||||
|
$store = array();
|
||||||
|
$_store = 0;
|
||||||
|
$_offset = 0;
|
||||||
|
|
||||||
|
// Unify Line-Breaks to \n
|
||||||
|
$source = preg_replace("/\015\012|\015|\012/", "\n", $source);
|
||||||
|
|
||||||
|
// capture Internet Explorer Conditional Comments
|
||||||
|
if (preg_match_all('#<!--\[[^\]]+\]>.*?<!\[[^\]]+\]-->#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 <script> - see http://stackoverflow.com/a/808850/515124
|
||||||
|
$source = preg_replace('#<!--.*?-->#ms', '', $source);
|
||||||
|
|
||||||
|
// capture html elements not to be messed with
|
||||||
|
$_offset = 0;
|
||||||
|
if (preg_match_all('#<(script|pre|textarea)[^>]*>.*?</\\1>#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 ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$expressions = array(
|
||||||
|
// replace multiple spaces between tags by a single space
|
||||||
|
// can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements
|
||||||
|
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
|
||||||
|
// remove spaces between attributes (but not in attribute values!)
|
||||||
|
'#(([a-z0-9]\s*=\s*(["\'])[^\3]*?\3)|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \4',
|
||||||
|
// note: for some very weird reason trim() seems to remove spaces inside attributes.
|
||||||
|
// maybe a \0 byte or something is interfering?
|
||||||
|
'#^\s+<#Ss' => '<',
|
||||||
|
'#>\s+$#Ss' => '>',
|
||||||
|
);
|
||||||
|
|
||||||
|
$source = preg_replace(array_keys($expressions), array_values($expressions), $source);
|
||||||
|
// note: for some very weird reason trim() seems to remove spaces inside attributes.
|
||||||
|
// maybe a \0 byte or something is interfering?
|
||||||
|
// $source = trim( $source );
|
||||||
|
|
||||||
|
$_offset = 0;
|
||||||
|
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
|
||||||
|
foreach ($matches as $match) {
|
||||||
|
$_length = strlen($match[0][0]);
|
||||||
|
$replace = $store[$match[1][0]];
|
||||||
|
$source = substr_replace($source, $replace, $match[0][1] + $_offset, $_length);
|
||||||
|
|
||||||
|
$_offset += strlen($replace) - $_length;
|
||||||
|
$_store ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $source;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user