Version Notes
+ Added option for removing important comments
* Improved extension configuration
Download this release
Release Info
Developer | Apptrian |
Extension | Apptrian_Minify_HTML_CSS_JS |
Version | 1.4.0 |
Comparing to | |
See all releases |
Code changes from version 1.3.0 to 1.4.0
- app/code/community/Apptrian/Minify/Helper/Data.php +63 -5
- app/code/community/Apptrian/Minify/Model/Observer.php +6 -6
- app/code/community/Apptrian/Minify/etc/config.xml +7 -4
- app/code/community/Apptrian/Minify/etc/system.xml +35 -21
- app/locale/en_US/Apptrian_Minify.csv +6 -3
- lib/JSMinMax.php +460 -0
- package.xml +6 -7
app/code/community/Apptrian/Minify/Helper/Data.php
CHANGED
@@ -8,7 +8,11 @@
|
|
8 |
*/
|
9 |
class Apptrian_Minify_Helper_Data extends Mage_Core_Helper_Abstract
|
10 |
{
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
protected $paths = null;
|
13 |
|
14 |
/**
|
@@ -21,7 +25,11 @@ class Apptrian_Minify_Helper_Data extends Mage_Core_Helper_Abstract
|
|
21 |
return (string) Mage::getConfig()->getNode()->modules->Apptrian_Minify->version;
|
22 |
}
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
public function getPaths()
|
26 |
{
|
27 |
if ($this->paths === null) {
|
@@ -43,7 +51,9 @@ class Apptrian_Minify_Helper_Data extends Mage_Core_Helper_Abstract
|
|
43 |
*/
|
44 |
public function process()
|
45 |
{
|
46 |
-
|
|
|
|
|
47 |
foreach ($this->getPaths() as $path) {
|
48 |
|
49 |
$iterator = new RecursiveIteratorIterator(
|
@@ -58,8 +68,56 @@ class Apptrian_Minify_Helper_Data extends Mage_Core_Helper_Abstract
|
|
58 |
Mage::log('Minification failed for ' . $filePath . ' File is not writable.');
|
59 |
continue;
|
60 |
}
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
Mage::log('Minification failed for ' . $filePath);
|
65 |
|
8 |
*/
|
9 |
class Apptrian_Minify_Helper_Data extends Mage_Core_Helper_Abstract
|
10 |
{
|
11 |
+
/**
|
12 |
+
* Array of paths that will be scaned for css and js files.
|
13 |
+
*
|
14 |
+
* @var array
|
15 |
+
*/
|
16 |
protected $paths = null;
|
17 |
|
18 |
/**
|
25 |
return (string) Mage::getConfig()->getNode()->modules->Apptrian_Minify->version;
|
26 |
}
|
27 |
|
28 |
+
/**
|
29 |
+
* Returns array of paths that will be scaned for css and js files.
|
30 |
+
*
|
31 |
+
* @return array
|
32 |
+
*/
|
33 |
public function getPaths()
|
34 |
{
|
35 |
if ($this->paths === null) {
|
51 |
*/
|
52 |
public function process()
|
53 |
{
|
54 |
+
// Get remove important comments option
|
55 |
+
$removeComments = (int) Mage::getConfig()->getNode('apptrian_minify/minify_css_js/remove_comments', 'default');
|
56 |
+
|
57 |
foreach ($this->getPaths() as $path) {
|
58 |
|
59 |
$iterator = new RecursiveIteratorIterator(
|
68 |
Mage::log('Minification failed for ' . $filePath . ' File is not writable.');
|
69 |
continue;
|
70 |
}
|
71 |
+
|
72 |
+
//This is available from php v5.3.6
|
73 |
+
//$ext = $file->getExtension();
|
74 |
+
// Using this for compatibility
|
75 |
+
$ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
|
76 |
+
$optimized = '';
|
77 |
+
$unoptimized = file_get_contents($filePath);
|
78 |
+
|
79 |
+
// If it is 0 byte file or cannot be read
|
80 |
+
if (!$unoptimized) {
|
81 |
+
Mage::log('File ' . $filePath . ' cannot be read.');
|
82 |
+
continue;
|
83 |
+
}
|
84 |
+
|
85 |
+
// CSS files
|
86 |
+
if ($ext == 'css') {
|
87 |
+
|
88 |
+
if ($removeComments == 1) {
|
89 |
+
|
90 |
+
$optimized = Minify_CSS::minify($unoptimized, array('preserveComments' => false));
|
91 |
+
|
92 |
+
} else {
|
93 |
+
|
94 |
+
$optimized = Minify_CSS::minify($unoptimized);
|
95 |
+
|
96 |
+
}
|
97 |
+
|
98 |
+
// JS files
|
99 |
+
} else {
|
100 |
+
|
101 |
+
if ($removeComments == 1) {
|
102 |
+
|
103 |
+
$optimized = JSMinMax::minify($unoptimized);
|
104 |
+
|
105 |
+
} else {
|
106 |
+
|
107 |
+
$optimized = JSMin::minify($unoptimized);
|
108 |
+
|
109 |
+
}
|
110 |
+
|
111 |
+
}
|
112 |
+
|
113 |
+
// If optimization failed
|
114 |
+
if (!$optimized) {
|
115 |
+
Mage::log('File ' . $filePath . ' was not minified.');
|
116 |
+
continue;
|
117 |
+
}
|
118 |
+
|
119 |
+
|
120 |
+
if (file_put_contents($filePath, $optimized, LOCK_EX) === false) {
|
121 |
|
122 |
Mage::log('Minification failed for ' . $filePath);
|
123 |
|
app/code/community/Apptrian/Minify/Model/Observer.php
CHANGED
@@ -41,8 +41,8 @@ class Apptrian_Minify_Model_Observer
|
|
41 |
|
42 |
if ($this->blockMinifyFlag === null) {
|
43 |
|
44 |
-
if (Mage::getStoreConfigFlag('apptrian_minify/
|
45 |
-
&& Mage::getStoreConfigFlag('apptrian_minify/
|
46 |
) {
|
47 |
|
48 |
$this->blockMinifyFlag = true;
|
@@ -69,7 +69,7 @@ class Apptrian_Minify_Model_Observer
|
|
69 |
|
70 |
if ($this->maxMinifyFlag === null) {
|
71 |
|
72 |
-
$this->maxMinifyFlag = Mage::getStoreConfigFlag('apptrian_minify/
|
73 |
|
74 |
}
|
75 |
|
@@ -111,8 +111,8 @@ class Apptrian_Minify_Model_Observer
|
|
111 |
public function minifyPageHtml(Varien_Event_Observer $observer)
|
112 |
{
|
113 |
|
114 |
-
if (Mage::getStoreConfigFlag('apptrian_minify/
|
115 |
-
&& !Mage::getStoreConfigFlag('apptrian_minify/
|
116 |
) {
|
117 |
|
118 |
$response = $observer->getEvent()->getControllerAction()->getResponse();
|
@@ -140,7 +140,7 @@ class Apptrian_Minify_Model_Observer
|
|
140 |
|
141 |
if ($type) {
|
142 |
|
143 |
-
if (Mage::getStoreConfigFlag('apptrian_minify/
|
144 |
$response->setBody(Minify_HTMLMax::minify($html, $this->minifyOptions));
|
145 |
} else {
|
146 |
$response->setBody(Minify_HTML::minify($html, $this->minifyOptions));
|
41 |
|
42 |
if ($this->blockMinifyFlag === null) {
|
43 |
|
44 |
+
if (Mage::getStoreConfigFlag('apptrian_minify/minify_html/enabled')
|
45 |
+
&& Mage::getStoreConfigFlag('apptrian_minify/minify_html/compatibility')
|
46 |
) {
|
47 |
|
48 |
$this->blockMinifyFlag = true;
|
69 |
|
70 |
if ($this->maxMinifyFlag === null) {
|
71 |
|
72 |
+
$this->maxMinifyFlag = Mage::getStoreConfigFlag('apptrian_minify/minify_html/max_minification');
|
73 |
|
74 |
}
|
75 |
|
111 |
public function minifyPageHtml(Varien_Event_Observer $observer)
|
112 |
{
|
113 |
|
114 |
+
if (Mage::getStoreConfigFlag('apptrian_minify/minify_html/enabled')
|
115 |
+
&& !Mage::getStoreConfigFlag('apptrian_minify/minify_html/compatibility')
|
116 |
) {
|
117 |
|
118 |
$response = $observer->getEvent()->getControllerAction()->getResponse();
|
140 |
|
141 |
if ($type) {
|
142 |
|
143 |
+
if (Mage::getStoreConfigFlag('apptrian_minify/minify_html/max_minification')) {
|
144 |
$response->setBody(Minify_HTMLMax::minify($html, $this->minifyOptions));
|
145 |
} else {
|
146 |
$response->setBody(Minify_HTML::minify($html, $this->minifyOptions));
|
app/code/community/Apptrian/Minify/etc/config.xml
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
<config>
|
12 |
<modules>
|
13 |
<Apptrian_Minify>
|
14 |
-
<version>1.
|
15 |
</Apptrian_Minify>
|
16 |
</modules>
|
17 |
<global>
|
@@ -43,11 +43,14 @@
|
|
43 |
</global>
|
44 |
<default>
|
45 |
<apptrian_minify>
|
46 |
-
<
|
47 |
-
<
|
48 |
<max_minification>0</max_minification>
|
49 |
<compatibility>0</compatibility>
|
50 |
-
</
|
|
|
|
|
|
|
51 |
</apptrian_minify>
|
52 |
</default>
|
53 |
<frontend>
|
11 |
<config>
|
12 |
<modules>
|
13 |
<Apptrian_Minify>
|
14 |
+
<version>1.4.0</version>
|
15 |
</Apptrian_Minify>
|
16 |
</modules>
|
17 |
<global>
|
43 |
</global>
|
44 |
<default>
|
45 |
<apptrian_minify>
|
46 |
+
<minify_html>
|
47 |
+
<enabled>0</enabled>
|
48 |
<max_minification>0</max_minification>
|
49 |
<compatibility>0</compatibility>
|
50 |
+
</minify_html>
|
51 |
+
<minify_css_js>
|
52 |
+
<remove_comments>0</remove_comments>
|
53 |
+
</minify_css_js>
|
54 |
</apptrian_minify>
|
55 |
</default>
|
56 |
<frontend>
|
app/code/community/Apptrian/Minify/etc/system.xml
CHANGED
@@ -60,64 +60,78 @@
|
|
60 |
</info>
|
61 |
</fields>
|
62 |
</about>
|
63 |
-
<
|
64 |
-
<label>
|
65 |
<frontend_type>text</frontend_type>
|
66 |
<sort_order>2</sort_order>
|
67 |
<show_in_default>1</show_in_default>
|
68 |
<show_in_website>1</show_in_website>
|
69 |
<show_in_store>1</show_in_store>
|
70 |
-
<comment><![CDATA[
|
71 |
<fields>
|
72 |
-
<
|
73 |
-
<label>Minify HTML Settings</label>
|
74 |
-
<frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
|
75 |
-
<sort_order>1</sort_order>
|
76 |
-
<show_in_default>1</show_in_default>
|
77 |
-
<show_in_website>1</show_in_website>
|
78 |
-
<show_in_store>1</show_in_store>
|
79 |
-
</heading_html>
|
80 |
-
<minify_html translate="label comment">
|
81 |
<label>Minify HTML</label>
|
82 |
<frontend_type>select</frontend_type>
|
83 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
84 |
-
<sort_order>
|
85 |
<show_in_default>1</show_in_default>
|
86 |
<show_in_website>1</show_in_website>
|
87 |
<show_in_store>1</show_in_store>
|
88 |
<comment><![CDATA[Enables or disables HTML minification.<br />WARNING! Before you enable this option you must have valid HTML code on all of the pages on your site. Use W3C Validator to check.]]></comment>
|
89 |
-
</
|
90 |
<max_minification translate="label comment tooltip">
|
91 |
<label>Enable Maximum Minification</label>
|
92 |
<frontend_type>select</frontend_type>
|
93 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
94 |
-
<sort_order>
|
95 |
<show_in_default>1</show_in_default>
|
96 |
<show_in_website>1</show_in_website>
|
97 |
<show_in_store>1</show_in_store>
|
98 |
<comment><![CDATA[Enables or disables Maximum HTML Minification.<br />WARNING! Slower and unsafe. See tooltip for more information.]]></comment>
|
99 |
<tooltip>If you enable this option all multiple spaces will be eliminated and replaced with one space. All new line characters will be substituted with one space character. Your entire code will be on one line. This is not recommended, you should keep this option disabled.</tooltip>
|
100 |
<depends>
|
101 |
-
<
|
102 |
</depends>
|
103 |
</max_minification>
|
104 |
<compatibility translate="label comment">
|
105 |
<label>Enable Cache Compatibility Mode</label>
|
106 |
<frontend_type>select</frontend_type>
|
107 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
108 |
-
<sort_order>
|
109 |
<show_in_default>1</show_in_default>
|
110 |
<show_in_website>1</show_in_website>
|
111 |
<show_in_store>1</show_in_store>
|
112 |
<comment><![CDATA[Enables or disables Cache Compatibility Mode.<br />WARNING! You should enable this if you use third party FPC or Varnish cache extensions.]]></comment>
|
113 |
<depends>
|
114 |
-
<
|
115 |
</depends>
|
116 |
</compatibility>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
<heading_minify_files translate="label">
|
118 |
<label>Minify CSS and JavaScript Files</label>
|
119 |
<frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
|
120 |
-
<sort_order>
|
121 |
<show_in_default>1</show_in_default>
|
122 |
<show_in_website>0</show_in_website>
|
123 |
<show_in_store>0</show_in_store>
|
@@ -126,14 +140,14 @@
|
|
126 |
<label>Minify</label>
|
127 |
<frontend_type>button</frontend_type>
|
128 |
<frontend_model>apptrian_minify/adminhtml_button_minify</frontend_model>
|
129 |
-
<sort_order>
|
130 |
<show_in_default>1</show_in_default>
|
131 |
<show_in_website>0</show_in_website>
|
132 |
<show_in_store>0</show_in_store>
|
133 |
<comment><![CDATA[WARNING! Follow instructions on the top.]]></comment>
|
134 |
</minify_files>
|
135 |
</fields>
|
136 |
-
</
|
137 |
</groups>
|
138 |
</apptrian_minify>
|
139 |
</sections>
|
60 |
</info>
|
61 |
</fields>
|
62 |
</about>
|
63 |
+
<minify_html translate="label comment">
|
64 |
+
<label>Minify HTML</label>
|
65 |
<frontend_type>text</frontend_type>
|
66 |
<sort_order>2</sort_order>
|
67 |
<show_in_default>1</show_in_default>
|
68 |
<show_in_website>1</show_in_website>
|
69 |
<show_in_store>1</show_in_store>
|
70 |
+
<comment><![CDATA[<h4>WARNING! Use validator to check your pages code before using our extension. You must have error-free HTML code if you want minification to work.</h4>]]></comment>
|
71 |
<fields>
|
72 |
+
<enabled translate="label comment">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
<label>Minify HTML</label>
|
74 |
<frontend_type>select</frontend_type>
|
75 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
76 |
+
<sort_order>1</sort_order>
|
77 |
<show_in_default>1</show_in_default>
|
78 |
<show_in_website>1</show_in_website>
|
79 |
<show_in_store>1</show_in_store>
|
80 |
<comment><![CDATA[Enables or disables HTML minification.<br />WARNING! Before you enable this option you must have valid HTML code on all of the pages on your site. Use W3C Validator to check.]]></comment>
|
81 |
+
</enabled>
|
82 |
<max_minification translate="label comment tooltip">
|
83 |
<label>Enable Maximum Minification</label>
|
84 |
<frontend_type>select</frontend_type>
|
85 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
86 |
+
<sort_order>2</sort_order>
|
87 |
<show_in_default>1</show_in_default>
|
88 |
<show_in_website>1</show_in_website>
|
89 |
<show_in_store>1</show_in_store>
|
90 |
<comment><![CDATA[Enables or disables Maximum HTML Minification.<br />WARNING! Slower and unsafe. See tooltip for more information.]]></comment>
|
91 |
<tooltip>If you enable this option all multiple spaces will be eliminated and replaced with one space. All new line characters will be substituted with one space character. Your entire code will be on one line. This is not recommended, you should keep this option disabled.</tooltip>
|
92 |
<depends>
|
93 |
+
<enabled>1</enabled>
|
94 |
</depends>
|
95 |
</max_minification>
|
96 |
<compatibility translate="label comment">
|
97 |
<label>Enable Cache Compatibility Mode</label>
|
98 |
<frontend_type>select</frontend_type>
|
99 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
100 |
+
<sort_order>3</sort_order>
|
101 |
<show_in_default>1</show_in_default>
|
102 |
<show_in_website>1</show_in_website>
|
103 |
<show_in_store>1</show_in_store>
|
104 |
<comment><![CDATA[Enables or disables Cache Compatibility Mode.<br />WARNING! You should enable this if you use third party FPC or Varnish cache extensions.]]></comment>
|
105 |
<depends>
|
106 |
+
<enabled>1</enabled>
|
107 |
</depends>
|
108 |
</compatibility>
|
109 |
+
</fields>
|
110 |
+
</minify_html>
|
111 |
+
<minify_css_js translate="label comment">
|
112 |
+
<label>Minify CSS and JavaScript</label>
|
113 |
+
<frontend_type>text</frontend_type>
|
114 |
+
<sort_order>3</sort_order>
|
115 |
+
<show_in_default>1</show_in_default>
|
116 |
+
<show_in_website>1</show_in_website>
|
117 |
+
<show_in_store>1</show_in_store>
|
118 |
+
<comment><![CDATA[<h4>WARNING! Use validators to check your pages code before using our extension. You must have error-free code in your CSS and JS files if you want minification to work.</h4><p>1. Enable <strong>System > Configuration > Developer > CSS Settings > Merge CSS Files</strong><br />2. Enable <strong>System > Configuration > Developer > JavaScript Settings > Merge JavaScript Files</strong><br />3. Flush and Refresh Magento cache <strong>System > Cache Management</strong><br />4. Visit several pages of your site on the frontend and wait for them to fully load. (Visit home page, one CMS page, one category page, one product page, cart page, and checkout page. This is done so Magento default merger can merge CSS and JS files, and some extensions add CSS and/or JS files only on specific pages not globally.)<br />5. Click <strong>Minify</strong> button and wait for CSS/JS files to be minified.<br />6. If you are using <strong>Expires</strong> header for CSS and JS files remember to empty your web browser's cache.<br />7. If you are using <strong>CDN</strong> make sure you flush/empty CDN cache.</p><p>(Our extension scans following directories:<br /><strong>/media/css/</strong><br /><strong>/media/css_secure/</strong><br /><strong>/media/js/</strong><br />for CSS and JS files and minifies them. If after minification your pages break or show any errors, just delete all files from above mentioned directories. This happens when there are errors in CSS and JS files. Use validators to check your CSS and JS code, find errors and fix them before you use our extension.)</p>]]></comment>
|
119 |
+
<fields>
|
120 |
+
<remove_comments translate="label comment tooltip">
|
121 |
+
<label>Remove Important Comments</label>
|
122 |
+
<frontend_type>select</frontend_type>
|
123 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
124 |
+
<sort_order>1</sort_order>
|
125 |
+
<show_in_default>1</show_in_default>
|
126 |
+
<show_in_website>0</show_in_website>
|
127 |
+
<show_in_store>0</show_in_store>
|
128 |
+
<comment><![CDATA[WARNING! See tooltip for more information.]]></comment>
|
129 |
+
<tooltip>If you enable this option important comments will be removed. Sometimes important comments hold copyright information and removing them is considered copyright infringement violation. If you are sure your CSS and JS files do not have important comments with copyright information you can enable this option.</tooltip>
|
130 |
+
</remove_comments>
|
131 |
<heading_minify_files translate="label">
|
132 |
<label>Minify CSS and JavaScript Files</label>
|
133 |
<frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
|
134 |
+
<sort_order>2</sort_order>
|
135 |
<show_in_default>1</show_in_default>
|
136 |
<show_in_website>0</show_in_website>
|
137 |
<show_in_store>0</show_in_store>
|
140 |
<label>Minify</label>
|
141 |
<frontend_type>button</frontend_type>
|
142 |
<frontend_model>apptrian_minify/adminhtml_button_minify</frontend_model>
|
143 |
+
<sort_order>3</sort_order>
|
144 |
<show_in_default>1</show_in_default>
|
145 |
<show_in_website>0</show_in_website>
|
146 |
<show_in_store>0</show_in_store>
|
147 |
<comment><![CDATA[WARNING! Follow instructions on the top.]]></comment>
|
148 |
</minify_files>
|
149 |
</fields>
|
150 |
+
</minify_css_js>
|
151 |
</groups>
|
152 |
</apptrian_minify>
|
153 |
</sections>
|
app/locale/en_US/Apptrian_Minify.csv
CHANGED
@@ -4,16 +4,19 @@
|
|
4 |
"Minify HTML CSS JS","Minify HTML CSS JS"
|
5 |
"Apptrian Extensions","Apptrian Extensions"
|
6 |
"About","About"
|
7 |
-
"General","General"
|
8 |
-
"1. Enable <strong>System > Configuration > Developer > CSS Settings > Merge CSS Files</strong><br />2. Enable <strong>System > Configuration > Developer > JavaScript Settings > Merge JavaScript Files</strong><br />3. Flush and Refresh Magento cache <strong>System > Cache Management</strong><br />4. Visit several pages of your site on the frontend and wait for them to fully load. (Visit home page, one CMS page, one category page, one product page, cart page, and checkout page. This is done so Magento default merger can merge CSS and JS files, and some extensions add CSS and/or JS files only on specific pages not globally.)<br />5. Click <strong>Minify</strong> button and wait for CSS/JS files to be minified.<br />6. If you are using <strong>Expires</strong> header for CSS and JS files remember to empty your web browser's cache.<br />7. If you are using <strong>CDN</strong> make sure you flush/empty CDN cache.","1. Enable <strong>System > Configuration > Developer > CSS Settings > Merge CSS Files</strong><br />2. Enable <strong>System > Configuration > Developer > JavaScript Settings > Merge JavaScript Files</strong><br />3. Flush and Refresh Magento cache <strong>System > Cache Management</strong><br />4. Visit several pages of your site on the frontend and wait for them to fully load. (Visit home page, one CMS page, one category page, one product page, cart page, and checkout page. This is done so Magento default merger can merge CSS and JS files, and some extensions add CSS and/or JS files only on specific pages not globally.)<br />5. Click <strong>Minify</strong> button and wait for CSS/JS files to be minified.<br />6. If you are using <strong>Expires</strong> header for CSS and JS files remember to empty your web browser's cache.<br />7. If you are using <strong>CDN</strong> make sure you flush/empty CDN cache."
|
9 |
-
"Minify HTML Settings","Minify HTML Settings"
|
10 |
"Minify HTML","Minify HTML"
|
|
|
11 |
"Enables or disables HTML minification.<br />WARNING! Before you enable this option you must have valid HTML code on all of the pages on your site. Use W3C Validator to check.","Enables or disables HTML minification.<br />WARNING! Before you enable this option you must have valid HTML code on all of the pages on your site. Use W3C Validator to check."
|
12 |
"Enable Maximum Minification","Enable Maximum Minification"
|
13 |
"Enables or disables Maximum HTML Minification.<br />WARNING! Slower and unsafe. See tooltip for more information.","Enables or disables Maximum HTML Minification.<br />WARNING! Slower and unsafe. See tooltip for more information."
|
14 |
"If you enable this option all multiple spaces will be eliminated and replaced with one space. All new line characters will be substituted with one space character. Your entire code will be on one line. This is not recommended, you should keep this option disabled.","If you enable this option all multiple spaces will be eliminated and replaced with one space. All new line characters will be substituted with one space character. Your entire code will be on one line. This is not recommended, you should keep this option disabled."
|
15 |
"Enable Cache Compatibility Mode","Enable Cache Compatibility Mode"
|
16 |
"Enables or disables Cache Compatibility Mode.<br />WARNING! You should enable this if you use third party FPC or Varnish cache extensions.","Enables or disables Cache Compatibility Mode.<br />WARNING! You should enable this if you use third party FPC or Varnish cache extensions."
|
|
|
|
|
|
|
|
|
|
|
17 |
"Minify CSS and JavaScript Files","Minify CSS and JavaScript Files"
|
18 |
"Minify","Minify"
|
19 |
"WARNING! Follow instructions on the top.","WARNING! Follow instructions on the top."
|
4 |
"Minify HTML CSS JS","Minify HTML CSS JS"
|
5 |
"Apptrian Extensions","Apptrian Extensions"
|
6 |
"About","About"
|
|
|
|
|
|
|
7 |
"Minify HTML","Minify HTML"
|
8 |
+
"<h4>WARNING! Use validator to check your pages code before using our extension. You must have error-free HTML code if you want minification to work.</h4>","<h4>WARNING! Use validator to check your pages code before using our extension. You must have error-free HTML code if you want minification to work.</h4>"
|
9 |
"Enables or disables HTML minification.<br />WARNING! Before you enable this option you must have valid HTML code on all of the pages on your site. Use W3C Validator to check.","Enables or disables HTML minification.<br />WARNING! Before you enable this option you must have valid HTML code on all of the pages on your site. Use W3C Validator to check."
|
10 |
"Enable Maximum Minification","Enable Maximum Minification"
|
11 |
"Enables or disables Maximum HTML Minification.<br />WARNING! Slower and unsafe. See tooltip for more information.","Enables or disables Maximum HTML Minification.<br />WARNING! Slower and unsafe. See tooltip for more information."
|
12 |
"If you enable this option all multiple spaces will be eliminated and replaced with one space. All new line characters will be substituted with one space character. Your entire code will be on one line. This is not recommended, you should keep this option disabled.","If you enable this option all multiple spaces will be eliminated and replaced with one space. All new line characters will be substituted with one space character. Your entire code will be on one line. This is not recommended, you should keep this option disabled."
|
13 |
"Enable Cache Compatibility Mode","Enable Cache Compatibility Mode"
|
14 |
"Enables or disables Cache Compatibility Mode.<br />WARNING! You should enable this if you use third party FPC or Varnish cache extensions.","Enables or disables Cache Compatibility Mode.<br />WARNING! You should enable this if you use third party FPC or Varnish cache extensions."
|
15 |
+
"Minify CSS and JavaScript","Minify CSS and JavaScript"
|
16 |
+
"<h4>WARNING! Use validators to check your pages code before using our extension. You must have error-free code in your CSS and JS files if you want minification to work.</h4><p>1. Enable <strong>System > Configuration > Developer > CSS Settings > Merge CSS Files</strong><br />2. Enable <strong>System > Configuration > Developer > JavaScript Settings > Merge JavaScript Files</strong><br />3. Flush and Refresh Magento cache <strong>System > Cache Management</strong><br />4. Visit several pages of your site on the frontend and wait for them to fully load. (Visit home page, one CMS page, one category page, one product page, cart page, and checkout page. This is done so Magento default merger can merge CSS and JS files, and some extensions add CSS and/or JS files only on specific pages not globally.)<br />5. Click <strong>Minify</strong> button and wait for CSS/JS files to be minified.<br />6. If you are using <strong>Expires</strong> header for CSS and JS files remember to empty your web browser's cache.<br />7. If you are using <strong>CDN</strong> make sure you flush/empty CDN cache.</p><p>(Our extension scans following directories:<br /><strong>/media/css/</strong><br /><strong>/media/css_secure/</strong><br /><strong>/media/js/</strong><br />for CSS and JS files and minifies them. If after minification your pages break or show any errors, just delete all files from above mentioned directories. This happens when there are errors in CSS and JS files. Use validators to check your CSS and JS code, find errors and fix them before you use our extension.)</p>","<h4>WARNING! Use validators to check your pages code before using our extension. You must have error-free code in your CSS and JS files if you want minification to work.</h4><p>1. Enable <strong>System > Configuration > Developer > CSS Settings > Merge CSS Files</strong><br />2. Enable <strong>System > Configuration > Developer > JavaScript Settings > Merge JavaScript Files</strong><br />3. Flush and Refresh Magento cache <strong>System > Cache Management</strong><br />4. Visit several pages of your site on the frontend and wait for them to fully load. (Visit home page, one CMS page, one category page, one product page, cart page, and checkout page. This is done so Magento default merger can merge CSS and JS files, and some extensions add CSS and/or JS files only on specific pages not globally.)<br />5. Click <strong>Minify</strong> button and wait for CSS/JS files to be minified.<br />6. If you are using <strong>Expires</strong> header for CSS and JS files remember to empty your web browser's cache.<br />7. If you are using <strong>CDN</strong> make sure you flush/empty CDN cache.</p><p>(Our extension scans following directories:<br /><strong>/media/css/</strong><br /><strong>/media/css_secure/</strong><br /><strong>/media/js/</strong><br />for CSS and JS files and minifies them. If after minification your pages break or show any errors, just delete all files from above mentioned directories. This happens when there are errors in CSS and JS files. Use validators to check your CSS and JS code, find errors and fix them before you use our extension.)</p>"
|
17 |
+
"Remove Important Comments","Remove Important Comments"
|
18 |
+
"WARNING! See tooltip for more information.","WARNING! See tooltip for more information."
|
19 |
+
"If you enable this option important comments will be removed. Sometimes important comments hold copyright information and removing them is considered copyright infringement violation. If you are sure your CSS and JS files do not have important comments with copyright information you can enable this option.","If you enable this option important comments will be removed. Sometimes important comments hold copyright information and removing them is considered copyright infringement violation. If you are sure your CSS and JS files do not have important comments with copyright information you can enable this option."
|
20 |
"Minify CSS and JavaScript Files","Minify CSS and JavaScript Files"
|
21 |
"Minify","Minify"
|
22 |
"WARNING! Follow instructions on the top.","WARNING! Follow instructions on the top."
|
lib/JSMinMax.php
ADDED
@@ -0,0 +1,460 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* JSMinMax.php - modified PHP implementation of Douglas Crockford's JSMinMax.
|
4 |
+
*
|
5 |
+
* <code>
|
6 |
+
* $minifiedJs = JSMinMax::minify($js);
|
7 |
+
* </code>
|
8 |
+
*
|
9 |
+
* This is a modified port of jsmin.c. Improvements:
|
10 |
+
*
|
11 |
+
* Does not choke on some regexp literals containing quote characters. E.g. /'/
|
12 |
+
*
|
13 |
+
* Spaces are preserved after some add/sub operators, so they are not mistakenly
|
14 |
+
* converted to post-inc/dec. E.g. a + ++b -> a+ ++b
|
15 |
+
*
|
16 |
+
* Preserves multi-line comments that begin with /*!
|
17 |
+
*
|
18 |
+
* PHP 5 or higher is required.
|
19 |
+
*
|
20 |
+
* Permission is hereby granted to use this version of the library under the
|
21 |
+
* same terms as jsmin.c, which has the following license:
|
22 |
+
*
|
23 |
+
* --
|
24 |
+
* Copyright (c) 2002 Douglas Crockford (www.crockford.com)
|
25 |
+
*
|
26 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
27 |
+
* this software and associated documentation files (the "Software"), to deal in
|
28 |
+
* the Software without restriction, including without limitation the rights to
|
29 |
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
30 |
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
31 |
+
* so, subject to the following conditions:
|
32 |
+
*
|
33 |
+
* The above copyright notice and this permission notice shall be included in all
|
34 |
+
* copies or substantial portions of the Software.
|
35 |
+
*
|
36 |
+
* The Software shall be used for Good, not Evil.
|
37 |
+
*
|
38 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
39 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
40 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
41 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
42 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
43 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
44 |
+
* SOFTWARE.
|
45 |
+
* --
|
46 |
+
*
|
47 |
+
* @package JSMinMax
|
48 |
+
* @author Ryan Grove <ryan@wonko.com> (PHP port)
|
49 |
+
* @author Steve Clay <steve@mrclay.org> (modifications + cleanup)
|
50 |
+
* @author Andrea Giammarchi <http://www.3site.eu> (spaceBeforeRegExp)
|
51 |
+
* @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
|
52 |
+
* @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
|
53 |
+
* @license http://opensource.org/licenses/mit-license.php MIT License
|
54 |
+
* @link http://code.google.com/p/jsmin-php/
|
55 |
+
*/
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Modified version of a class for max minification (Removes important comments).
|
59 |
+
*
|
60 |
+
* @category Apptrian
|
61 |
+
* @package Apptrian_Minify
|
62 |
+
* @author Apptrian
|
63 |
+
* @copyright Copyright (c) 2015 Apptrian (http://www.apptrian.com)
|
64 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
65 |
+
*/
|
66 |
+
|
67 |
+
class JSMinMax {
|
68 |
+
const ORD_LF = 10;
|
69 |
+
const ORD_SPACE = 32;
|
70 |
+
const ACTION_KEEP_A = 1;
|
71 |
+
const ACTION_DELETE_A = 2;
|
72 |
+
const ACTION_DELETE_A_B = 3;
|
73 |
+
|
74 |
+
protected $a = "\n";
|
75 |
+
protected $b = '';
|
76 |
+
protected $input = '';
|
77 |
+
protected $inputIndex = 0;
|
78 |
+
protected $inputLength = 0;
|
79 |
+
protected $lookAhead = null;
|
80 |
+
protected $output = '';
|
81 |
+
protected $lastByteOut = '';
|
82 |
+
protected $keptComment = '';
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Minify Javascript.
|
86 |
+
*
|
87 |
+
* @param string $js Javascript to be minified
|
88 |
+
*
|
89 |
+
* @return string
|
90 |
+
*/
|
91 |
+
public static function minify($js)
|
92 |
+
{
|
93 |
+
$jsmin = new JSMinMax($js);
|
94 |
+
return $jsmin->min();
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* @param string $input
|
99 |
+
*/
|
100 |
+
public function __construct($input)
|
101 |
+
{
|
102 |
+
$this->input = $input;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Perform minification, return result
|
107 |
+
*
|
108 |
+
* @return string
|
109 |
+
*/
|
110 |
+
public function min()
|
111 |
+
{
|
112 |
+
if ($this->output !== '') { // min already run
|
113 |
+
return $this->output;
|
114 |
+
}
|
115 |
+
|
116 |
+
$mbIntEnc = null;
|
117 |
+
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
118 |
+
$mbIntEnc = mb_internal_encoding();
|
119 |
+
mb_internal_encoding('8bit');
|
120 |
+
}
|
121 |
+
$this->input = str_replace("\r\n", "\n", $this->input);
|
122 |
+
$this->inputLength = strlen($this->input);
|
123 |
+
|
124 |
+
$this->action(self::ACTION_DELETE_A_B);
|
125 |
+
|
126 |
+
while ($this->a !== null) {
|
127 |
+
// determine next command
|
128 |
+
$command = self::ACTION_KEEP_A; // default
|
129 |
+
if ($this->a === ' ') {
|
130 |
+
if (($this->lastByteOut === '+' || $this->lastByteOut === '-')
|
131 |
+
&& ($this->b === $this->lastByteOut)) {
|
132 |
+
// Don't delete this space. If we do, the addition/subtraction
|
133 |
+
// could be parsed as a post-increment
|
134 |
+
} elseif (! $this->isAlphaNum($this->b)) {
|
135 |
+
$command = self::ACTION_DELETE_A;
|
136 |
+
}
|
137 |
+
} elseif ($this->a === "\n") {
|
138 |
+
if ($this->b === ' ') {
|
139 |
+
$command = self::ACTION_DELETE_A_B;
|
140 |
+
|
141 |
+
// in case of mbstring.func_overload & 2, must check for null b,
|
142 |
+
// otherwise mb_strpos will give WARNING
|
143 |
+
} elseif ($this->b === null
|
144 |
+
|| (false === strpos('{[(+-!~', $this->b)
|
145 |
+
&& ! $this->isAlphaNum($this->b))) {
|
146 |
+
$command = self::ACTION_DELETE_A;
|
147 |
+
}
|
148 |
+
} elseif (! $this->isAlphaNum($this->a)) {
|
149 |
+
if ($this->b === ' '
|
150 |
+
|| ($this->b === "\n"
|
151 |
+
&& (false === strpos('}])+-"\'', $this->a)))) {
|
152 |
+
$command = self::ACTION_DELETE_A_B;
|
153 |
+
}
|
154 |
+
}
|
155 |
+
$this->action($command);
|
156 |
+
}
|
157 |
+
$this->output = trim($this->output);
|
158 |
+
|
159 |
+
if ($mbIntEnc !== null) {
|
160 |
+
mb_internal_encoding($mbIntEnc);
|
161 |
+
}
|
162 |
+
return $this->output;
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
|
167 |
+
* ACTION_DELETE_A = Copy B to A. Get the next B.
|
168 |
+
* ACTION_DELETE_A_B = Get the next B.
|
169 |
+
*
|
170 |
+
* @param int $command
|
171 |
+
* @throws JSMinMax_UnterminatedRegExpException|JSMinMax_UnterminatedStringException
|
172 |
+
*/
|
173 |
+
protected function action($command)
|
174 |
+
{
|
175 |
+
// make sure we don't compress "a + ++b" to "a+++b", etc.
|
176 |
+
if ($command === self::ACTION_DELETE_A_B
|
177 |
+
&& $this->b === ' '
|
178 |
+
&& ($this->a === '+' || $this->a === '-')) {
|
179 |
+
// Note: we're at an addition/substraction operator; the inputIndex
|
180 |
+
// will certainly be a valid index
|
181 |
+
if ($this->input[$this->inputIndex] === $this->a) {
|
182 |
+
// This is "+ +" or "- -". Don't delete the space.
|
183 |
+
$command = self::ACTION_KEEP_A;
|
184 |
+
}
|
185 |
+
}
|
186 |
+
|
187 |
+
switch ($command) {
|
188 |
+
case self::ACTION_KEEP_A: // 1
|
189 |
+
$this->output .= $this->a;
|
190 |
+
|
191 |
+
if ($this->keptComment) {
|
192 |
+
$this->output = rtrim($this->output, "\n");
|
193 |
+
$this->output .= $this->keptComment;
|
194 |
+
$this->keptComment = '';
|
195 |
+
}
|
196 |
+
|
197 |
+
$this->lastByteOut = $this->a;
|
198 |
+
|
199 |
+
// fallthrough intentional
|
200 |
+
case self::ACTION_DELETE_A: // 2
|
201 |
+
$this->a = $this->b;
|
202 |
+
if ($this->a === "'" || $this->a === '"') { // string literal
|
203 |
+
$str = $this->a; // in case needed for exception
|
204 |
+
for(;;) {
|
205 |
+
$this->output .= $this->a;
|
206 |
+
$this->lastByteOut = $this->a;
|
207 |
+
|
208 |
+
$this->a = $this->get();
|
209 |
+
if ($this->a === $this->b) { // end quote
|
210 |
+
break;
|
211 |
+
}
|
212 |
+
if ($this->isEOF($this->a)) {
|
213 |
+
$byte = $this->inputIndex - 1;
|
214 |
+
throw new JSMinMax_UnterminatedStringException(
|
215 |
+
"JSMinMax: Unterminated String at byte {$byte}: {$str}");
|
216 |
+
}
|
217 |
+
$str .= $this->a;
|
218 |
+
if ($this->a === '\\') {
|
219 |
+
$this->output .= $this->a;
|
220 |
+
$this->lastByteOut = $this->a;
|
221 |
+
|
222 |
+
$this->a = $this->get();
|
223 |
+
$str .= $this->a;
|
224 |
+
}
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
// fallthrough intentional
|
229 |
+
case self::ACTION_DELETE_A_B: // 3
|
230 |
+
$this->b = $this->next();
|
231 |
+
if ($this->b === '/' && $this->isRegexpLiteral()) {
|
232 |
+
$this->output .= $this->a . $this->b;
|
233 |
+
$pattern = '/'; // keep entire pattern in case we need to report it in the exception
|
234 |
+
for(;;) {
|
235 |
+
$this->a = $this->get();
|
236 |
+
$pattern .= $this->a;
|
237 |
+
if ($this->a === '[') {
|
238 |
+
for(;;) {
|
239 |
+
$this->output .= $this->a;
|
240 |
+
$this->a = $this->get();
|
241 |
+
$pattern .= $this->a;
|
242 |
+
if ($this->a === ']') {
|
243 |
+
break;
|
244 |
+
}
|
245 |
+
if ($this->a === '\\') {
|
246 |
+
$this->output .= $this->a;
|
247 |
+
$this->a = $this->get();
|
248 |
+
$pattern .= $this->a;
|
249 |
+
}
|
250 |
+
if ($this->isEOF($this->a)) {
|
251 |
+
throw new JSMinMax_UnterminatedRegExpException(
|
252 |
+
"JSMinMax: Unterminated set in RegExp at byte "
|
253 |
+
. $this->inputIndex .": {$pattern}");
|
254 |
+
}
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
if ($this->a === '/') { // end pattern
|
259 |
+
break; // while (true)
|
260 |
+
} elseif ($this->a === '\\') {
|
261 |
+
$this->output .= $this->a;
|
262 |
+
$this->a = $this->get();
|
263 |
+
$pattern .= $this->a;
|
264 |
+
} elseif ($this->isEOF($this->a)) {
|
265 |
+
$byte = $this->inputIndex - 1;
|
266 |
+
throw new JSMinMax_UnterminatedRegExpException(
|
267 |
+
"JSMinMax: Unterminated RegExp at byte {$byte}: {$pattern}");
|
268 |
+
}
|
269 |
+
$this->output .= $this->a;
|
270 |
+
$this->lastByteOut = $this->a;
|
271 |
+
}
|
272 |
+
$this->b = $this->next();
|
273 |
+
}
|
274 |
+
// end case ACTION_DELETE_A_B
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* @return bool
|
280 |
+
*/
|
281 |
+
protected function isRegexpLiteral()
|
282 |
+
{
|
283 |
+
if (false !== strpos("(,=:[!&|?+-~*{;", $this->a)) {
|
284 |
+
// we obviously aren't dividing
|
285 |
+
return true;
|
286 |
+
}
|
287 |
+
|
288 |
+
// we have to check for a preceding keyword, and we don't need to pattern
|
289 |
+
// match over the whole output.
|
290 |
+
$recentOutput = substr($this->output, -10);
|
291 |
+
|
292 |
+
// check if return/typeof directly precede a pattern without a space
|
293 |
+
foreach (array('return', 'typeof') as $keyword) {
|
294 |
+
if ($this->a !== substr($keyword, -1)) {
|
295 |
+
// certainly wasn't keyword
|
296 |
+
continue;
|
297 |
+
}
|
298 |
+
if (preg_match("~(^|[\\s\\S])" . substr($keyword, 0, -1) . "$~", $recentOutput, $m)) {
|
299 |
+
if ($m[1] === '' || !$this->isAlphaNum($m[1])) {
|
300 |
+
return true;
|
301 |
+
}
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
// check all keywords
|
306 |
+
if ($this->a === ' ' || $this->a === "\n") {
|
307 |
+
if (preg_match('~(^|[\\s\\S])(?:case|else|in|return|typeof)$~', $recentOutput, $m)) {
|
308 |
+
if ($m[1] === '' || !$this->isAlphaNum($m[1])) {
|
309 |
+
return true;
|
310 |
+
}
|
311 |
+
}
|
312 |
+
}
|
313 |
+
|
314 |
+
return false;
|
315 |
+
}
|
316 |
+
|
317 |
+
/**
|
318 |
+
* Return the next character from stdin. Watch out for lookahead. If the character is a control character,
|
319 |
+
* translate it to a space or linefeed.
|
320 |
+
*
|
321 |
+
* @return string
|
322 |
+
*/
|
323 |
+
protected function get()
|
324 |
+
{
|
325 |
+
$c = $this->lookAhead;
|
326 |
+
$this->lookAhead = null;
|
327 |
+
if ($c === null) {
|
328 |
+
// getc(stdin)
|
329 |
+
if ($this->inputIndex < $this->inputLength) {
|
330 |
+
$c = $this->input[$this->inputIndex];
|
331 |
+
$this->inputIndex += 1;
|
332 |
+
} else {
|
333 |
+
$c = null;
|
334 |
+
}
|
335 |
+
}
|
336 |
+
if (ord($c) >= self::ORD_SPACE || $c === "\n" || $c === null) {
|
337 |
+
return $c;
|
338 |
+
}
|
339 |
+
if ($c === "\r") {
|
340 |
+
return "\n";
|
341 |
+
}
|
342 |
+
return ' ';
|
343 |
+
}
|
344 |
+
|
345 |
+
/**
|
346 |
+
* Does $a indicate end of input?
|
347 |
+
*
|
348 |
+
* @param string $a
|
349 |
+
* @return bool
|
350 |
+
*/
|
351 |
+
protected function isEOF($a)
|
352 |
+
{
|
353 |
+
return ord($a) <= self::ORD_LF;
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* Get next char (without getting it). If is ctrl character, translate to a space or newline.
|
358 |
+
*
|
359 |
+
* @return string
|
360 |
+
*/
|
361 |
+
protected function peek()
|
362 |
+
{
|
363 |
+
$this->lookAhead = $this->get();
|
364 |
+
return $this->lookAhead;
|
365 |
+
}
|
366 |
+
|
367 |
+
/**
|
368 |
+
* Return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.
|
369 |
+
*
|
370 |
+
* @param string $c
|
371 |
+
*
|
372 |
+
* @return bool
|
373 |
+
*/
|
374 |
+
protected function isAlphaNum($c)
|
375 |
+
{
|
376 |
+
return (preg_match('/^[a-z0-9A-Z_\\$\\\\]$/', $c) || ord($c) > 126);
|
377 |
+
}
|
378 |
+
|
379 |
+
/**
|
380 |
+
* Consume a single line comment from input (possibly retaining it)
|
381 |
+
*/
|
382 |
+
protected function consumeSingleLineComment()
|
383 |
+
{
|
384 |
+
$comment = '';
|
385 |
+
while (true) {
|
386 |
+
$get = $this->get();
|
387 |
+
$comment .= $get;
|
388 |
+
if (ord($get) <= self::ORD_LF) { // end of line reached
|
389 |
+
// if IE conditional comment
|
390 |
+
if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
391 |
+
$this->keptComment .= "/{$comment}";
|
392 |
+
}
|
393 |
+
return;
|
394 |
+
}
|
395 |
+
}
|
396 |
+
}
|
397 |
+
|
398 |
+
/**
|
399 |
+
* Consume a multiple line comment from input (possibly retaining it)
|
400 |
+
*
|
401 |
+
* @throws JSMinMax_UnterminatedCommentException
|
402 |
+
*/
|
403 |
+
protected function consumeMultipleLineComment()
|
404 |
+
{
|
405 |
+
$this->get();
|
406 |
+
$comment = '';
|
407 |
+
for(;;) {
|
408 |
+
$get = $this->get();
|
409 |
+
if ($get === '*') {
|
410 |
+
if ($this->peek() === '/') { // end of comment reached
|
411 |
+
$this->get();
|
412 |
+
if (0 === strpos($comment, '!')) {
|
413 |
+
// preserved by YUI Compressor
|
414 |
+
if (!$this->keptComment) {
|
415 |
+
// don't prepend a newline if two comments right after one another
|
416 |
+
$this->keptComment = "\n";
|
417 |
+
}
|
418 |
+
//$this->keptComment .= "/*!" . substr($comment, 1) . "*/\n";
|
419 |
+
$this->keptComment .= "\n";
|
420 |
+
} else if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
421 |
+
// IE conditional
|
422 |
+
$this->keptComment .= "/*{$comment}*/";
|
423 |
+
}
|
424 |
+
return;
|
425 |
+
}
|
426 |
+
} elseif ($get === null) {
|
427 |
+
throw new JSMinMax_UnterminatedCommentException(
|
428 |
+
"JSMinMax: Unterminated comment at byte {$this->inputIndex}: /*{$comment}");
|
429 |
+
}
|
430 |
+
$comment .= $get;
|
431 |
+
}
|
432 |
+
}
|
433 |
+
|
434 |
+
/**
|
435 |
+
* Get the next character, skipping over comments. Some comments may be preserved.
|
436 |
+
*
|
437 |
+
* @return string
|
438 |
+
*/
|
439 |
+
protected function next()
|
440 |
+
{
|
441 |
+
$get = $this->get();
|
442 |
+
if ($get === '/') {
|
443 |
+
switch ($this->peek()) {
|
444 |
+
case '/':
|
445 |
+
$this->consumeSingleLineComment();
|
446 |
+
$get = "\n";
|
447 |
+
break;
|
448 |
+
case '*':
|
449 |
+
$this->consumeMultipleLineComment();
|
450 |
+
$get = ' ';
|
451 |
+
break;
|
452 |
+
}
|
453 |
+
}
|
454 |
+
return $get;
|
455 |
+
}
|
456 |
+
}
|
457 |
+
|
458 |
+
class JSMinMax_UnterminatedStringException extends Exception {}
|
459 |
+
class JSMinMax_UnterminatedCommentException extends Exception {}
|
460 |
+
class JSMinMax_UnterminatedRegExpException extends Exception {}
|
package.xml
CHANGED
@@ -1,20 +1,19 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Apptrian_Minify_HTML_CSS_JS</name>
|
4 |
-
<version>1.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Minify HTML CSS JS including inline CSS/JS and speed up your site. Works with default Magento CSS/JS merger.</summary>
|
10 |
<description>Apptrian Minify HTML CSS JS is a very small and efficient extension. It will minify HTML including inline CSS and JS code. Minification of CSS and JS files is compatible with default Magento CSS and JS file merger. There are no complex setups nor query strings on minified CSS and JS files. Extension is very easy to install and use. Compatible with FPC and Varnish cache extensions.</description>
|
11 |
-
<notes>+
|
12 |
-
*
|
13 |
-
- Versioning of CSS and JS files</notes>
|
14 |
<authors><author><name>Apptrian</name><user>apptrian</user><email>apptrian@yahoo.com</email></author></authors>
|
15 |
-
<date>2015-06-
|
16 |
-
<time>
|
17 |
-
<contents><target name="magecommunity"><dir name="Apptrian"><dir name="Minify"><dir name="Block"><file name="About.php" hash="55714f78c451f529f64261efc28ba407"/><dir name="Adminhtml"><dir name="Button"><file name="Minify.php" hash="4d16be7cfa93b9eba7da21108747e38d"/></dir></dir><file name="Info.php" hash="d967c088301c8e90ada86e8fd8d009bd"/></dir><dir name="Helper"><file name="Data.php" hash="
|
18 |
<compatible/>
|
19 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
20 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Apptrian_Minify_HTML_CSS_JS</name>
|
4 |
+
<version>1.4.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Minify HTML CSS JS including inline CSS/JS and speed up your site. Works with default Magento CSS/JS merger.</summary>
|
10 |
<description>Apptrian Minify HTML CSS JS is a very small and efficient extension. It will minify HTML including inline CSS and JS code. Minification of CSS and JS files is compatible with default Magento CSS and JS file merger. There are no complex setups nor query strings on minified CSS and JS files. Extension is very easy to install and use. Compatible with FPC and Varnish cache extensions.</description>
|
11 |
+
<notes>+ Added option for removing important comments
|
12 |
+
* Improved extension configuration</notes>
|
|
|
13 |
<authors><author><name>Apptrian</name><user>apptrian</user><email>apptrian@yahoo.com</email></author></authors>
|
14 |
+
<date>2015-06-21</date>
|
15 |
+
<time>15:38:30</time>
|
16 |
+
<contents><target name="magecommunity"><dir name="Apptrian"><dir name="Minify"><dir name="Block"><file name="About.php" hash="55714f78c451f529f64261efc28ba407"/><dir name="Adminhtml"><dir name="Button"><file name="Minify.php" hash="4d16be7cfa93b9eba7da21108747e38d"/></dir></dir><file name="Info.php" hash="d967c088301c8e90ada86e8fd8d009bd"/></dir><dir name="Helper"><file name="Data.php" hash="658da016ad02230dc1333b653274be01"/></dir><dir name="Model"><file name="Cron.php" hash="deb94ca0e0d4fc84e7f3b8ec93270e1e"/><file name="Observer.php" hash="34114a1af8a5dded1cd62e3c77ba069b"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="MinifyController.php" hash="3554f1ef8be979bc2170635485d613ba"/></dir></dir><dir name="etc"><file name="config.xml" hash="2a9b2a91b48b1c4c2c24bd7e0041e9ee"/><file name="system.xml" hash="611feb105fa72eb38cc9a772c7c657e6"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Apptrian_Minify.xml" hash="93ef03671067cf44a0b02f0100c8d2d0"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Apptrian_Minify.csv" hash="694d5a244eeaaa7293520581b82ffcf7"/></dir></target><target name="magelib"><dir name="HTTP"><file name="ConditionalGet.php" hash="84d5f4e0b97e37228310a31a4bdc1240"/><file name="Encoder.php" hash="d697f04651d6363d1dd5dd8c2ce94cbd"/></dir><dir name="Minify"><file name="Build.php" hash="99800ab664e1fb0ff46a7133ab13bb1b"/><dir name="CSS"><file name="Compressor.php" hash="6f1d5d8c3f7ac47cabaca9d6ee923206"/><file name="UriRewriter.php" hash="d6c800c1b9b0603c3386f84074bc41a0"/></dir><file name="CSS.php" hash="c585f82e0a6f8af12da2d3337aa7e901"/><file name="CSSmin.php" hash="7e0549e63f49b99aac0f6688bfcf99ef"/><dir name="Cache"><file name="APC.php" hash="f83c096f1ea3eb712bf020371b7d3755"/><file name="File.php" hash="5550b7ad5d3cc20710a0835fdf20e3ec"/><file name="Memcache.php" hash="a572e300270f5cdb535de67eb1d9ce3b"/><file name="WinCache.php" hash="037003b972c8f648880b43b2c912afb7"/><file name="XCache.php" hash="a3239040e672955a8a520eef6e251d68"/><file name="ZendPlatform.php" hash="a20755bc554cfef6733ac64574c4f90e"/></dir><file name="ClosureCompiler.php" hash="0d04a74dae339bd8d2d0465503590819"/><file name="CommentPreserver.php" hash="f9fbae74aea3125d25f375942846d9c0"/><dir name="Controller"><file name="Base.php" hash="756cd27141da15f6bc0a9d34960e0338"/><file name="Files.php" hash="a0bc419aa48d256e19a64596dee53991"/><file name="Groups.php" hash="bf35ccd3d384c40033b978a402eaf917"/><file name="MinApp.php" hash="0910bc4af5280098b8411a8a23aa3e91"/><file name="Page.php" hash="c54a4b19474f9d0e9beb8ccb4e3678b3"/><file name="Version1.php" hash="0e4bce53a0b66c79aa6d15e52cf8ec50"/></dir><file name="DebugDetector.php" hash="d1bee7f6ab4dcf7be5d36dbcd1b81354"/><dir name="HTML"><file name="Helper.php" hash="af89e2e30f70dd935dd86d31649159e6"/></dir><file name="HTML.php" hash="d48eabaae177099a264b5a97379b0abf"/><file name="HTMLComp.php" hash="a2929a26f75e6877fd5f58e6fdc5f2d0"/><file name="HTMLMax.php" hash="63b191db9ce4b878809c33e5cc74323e"/><file name="HTMLMaxComp.php" hash="c6c76d9106d38c3a3fcd7c4ae4ff571a"/><file name="ImportProcessor.php" hash="075c561afa4825021fa44c3cac68ab94"/><dir name="JS"><file name="ClosureCompiler.php" hash="0d6d0017c3b9decdf0e1f647c0b53f17"/></dir><file name="Lines.php" hash="526499d43d682432dac9483da4509179"/><file name="Loader.php" hash="5e84b0e739587d8df742f47953f135d5"/><file name="Logger.php" hash="ee493543ebb47aa06f976f23a0f3d86a"/><file name="Packer.php" hash="e91f63a82c4fbd660c2341163e87dd4b"/><file name="Source.php" hash="f7055f963f00e5ae9f5b0005d5e4a5ec"/><dir name="YUI"><file name="CssCompressor.java" hash="cb15a586f2dcc4fead535bc982e3f91e"/><file name="CssCompressor.php" hash="12d5b4e38488c68bc84cc0efba6eb338"/></dir><file name="YUICompressor.php" hash="3ada081677d0cf118bba1f4b533b97cf"/></dir><dir name="."><file name="CSSmin.php" hash="b88ddd36d0ff681aa8a221467c0c71c1"/><file name="DooDigestAuth.php" hash="9d66abc8cfa37b5f593fc09c734f0269"/><file name="FirePHP.php" hash="f619b5a77fee4b21e4397e98d858fbf4"/><file name="JavaScriptPacker.php" hash="84900da372a375d3b2f117c5abe740a9"/><file name="JSMin.php" hash="63ada69cc753fe4136c67e1d3daabca3"/><file name="JSMinMax.php" hash="2fed0d2f38ae28220da56216ec2fe38f"/><file name="JSMinPlus.php" hash="13d47b54dd73ef825e5d86e6cc633e32"/><file name="Minify.php" hash="df50518e69c132b1354eb8ba73a8ed7c"/></dir></target></contents>
|
17 |
<compatible/>
|
18 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
19 |
</package>
|