Upgrade für OXID6 (#4)

updated module for OXID6
This commit is contained in:
Ivo Bathke 2019-04-18 11:39:09 +02:00 committed by Alfred Bez
parent 1783e1f2e5
commit 5a9f8d2111
6 changed files with 38 additions and 142 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# Created by .ignore support plugin (hsz.mobi)
vendor
composer.lock
source
.phpstorm-oxid.meta.php
ab_htmlmin.iml

View File

@ -11,17 +11,14 @@
* 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/>
*/
class ab_htmlmin extends ab_htmlmin_parent {
namespace AlfredBez\HtmlMin\Core;
class UtilsView extends UtilsView_parent {
protected function _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->plugins_dir = $aPluginsDir;
}
}

View File

@ -5,8 +5,6 @@ Enables Smarty 'trimwhitespace' Outputfilter to minify HTML Code
Download
------------
There are several ways to download the module:
### Download-Option 1: Download via composer (recommended)
first you need [composer](https://getcomposer.org/download/)
add the module to your composer.json
@ -21,34 +19,8 @@ add the module to your composer.json
}
```
### 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**
----
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
```

View File

@ -1,9 +1,10 @@
{
"name": "alfredbez/ab_htmlmin",
"type": "oxid-module",
"type": "oxideshop-module",
"keywords": ["oxid", "modules", "eShop"],
"description": "entfernt unnötige Whitespaces aus dem HTML-Code",
"require": {
"composer/installers": "~1.0"
"oxid-esales/oxideshop-ce": "^v6.0"
},
"authors": [
{
@ -11,5 +12,15 @@
"email": "alfred.bez@gmail.com"
}
],
"extra": {
"oxideshop": {
"target-directory": "ab/htmlmin"
}
},
"autoload": {
"psr-4": {
"AlfredBez\\HtmlMin\\": "../../../source/modules/ab/htmlmin"
}
},
"minimum-stability": "dev"
}

View File

@ -1,7 +1,7 @@
<?php
/**
* Version: 1.0
* Version: 2.0
* Author: Alfred Bez <alfred.bez@gmail.com>
* Author URI: http://www.alfredbez.de
*/
@ -9,20 +9,20 @@
/**
* Metadata version
*/
$sMetadataVersion = '1.1';
$sMetadataVersion = '2';
/**
* Module information
*/
$aModule = array(
$aModule = [
'id' => 'ab_htmlmin',
'title' => 'Alfred Bez :: HTML minify',
'description' => 'entfernt unnötige Whitespaces aus dem HTML-Code',
'version' => '1.0',
'version' => '2.0',
'author' => 'Alfred Bez',
'url' => 'http://www.alfredbez.de',
'email' => 'alfred.bez@gmail.com',
'extend' => array(
'oxutilsview' => 'ab_htmlmin/models/ab_htmlmin'
)
);
'extend' => [
\OxidEsales\Eshop\Core\UtilsView::class => \AlfredBez\HtmlMin\Core\UtilsView::class,
],
];

View File

@ -1,90 +0,0 @@
<?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;
}