Apptrian_Image_Optimizer - Version 2.2.0

Version Notes

+ Compliance with Magento's Extension Quality Program (EQP)
WARNING! If you are upgrading from any previous version after installation/upgrade you need to go to extension configuration and for option "Utilities Path" instead of "lib/apptrian/imageoptimizer" type "lib/Apptrian/ImageOptimizer" then save the changes and refresh your Magento cache. Also set execute permissions on files inside lib/Apptrian/ImageOptimizer directory.

Download this release

Release Info

Developer Apptrian
Extension Apptrian_Image_Optimizer
Version 2.2.0
Comparing to
See all releases


Code changes from version 2.1.0 to 2.2.0

Files changed (43) hide show
  1. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/About.php +5 -5
  2. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Clear.php +2 -5
  3. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Optimize.php +2 -6
  4. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Scan.php +2 -6
  5. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Info.php +26 -26
  6. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Stats.php +4 -6
  7. app/code/community/Apptrian/ImageOptimizer/Helper/Data.php +32 -117
  8. app/code/community/Apptrian/ImageOptimizer/Model/Config/Batchsize.php +1 -9
  9. app/code/community/Apptrian/ImageOptimizer/Model/Config/Cron/Optimize.php +6 -17
  10. app/code/community/Apptrian/ImageOptimizer/Model/Config/Cron/Scan.php +6 -17
  11. app/code/community/Apptrian/ImageOptimizer/Model/Config/Exactpath.php +3 -10
  12. app/code/community/Apptrian/ImageOptimizer/Model/Config/Options.php +4 -10
  13. app/code/community/Apptrian/ImageOptimizer/Model/Config/Path.php +3 -10
  14. app/code/community/Apptrian/ImageOptimizer/Model/Config/Paths.php +3 -10
  15. app/code/community/Apptrian/ImageOptimizer/Model/Config/Permissions.php +3 -10
  16. app/code/community/Apptrian/ImageOptimizer/Model/Config/Utility.php +3 -10
  17. app/code/community/Apptrian/ImageOptimizer/Model/Cron.php +3 -25
  18. app/code/community/Apptrian/ImageOptimizer/controllers/Adminhtml/Apptrian/ImgoptController.php +3 -22
  19. app/code/community/Apptrian/ImageOptimizer/etc/config.xml +3 -4
  20. app/code/community/Apptrian/ImageOptimizer/etc/system.xml +2 -2
  21. app/design/adminhtml/default/default/layout/apptrian_imageoptimizer.xml +1 -1
  22. app/etc/modules/Apptrian_ImageOptimizer.xml +1 -1
  23. app/locale/en_US/Apptrian_ImageOptimizer.csv +1 -1
  24. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/elf32/gifsicle +0 -0
  25. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/elf32/jpegoptim +0 -0
  26. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/elf32/jpegtran +0 -0
  27. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/elf32/optipng +0 -0
  28. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/elf64/gifsicle +0 -0
  29. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/elf64/jpegoptim +0 -0
  30. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/elf64/jpegtran +0 -0
  31. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/elf64/optipng +0 -0
  32. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/win32/gifsicle.exe +0 -0
  33. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/win32/jpegoptim.exe +0 -0
  34. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/win32/jpegtran.exe +0 -0
  35. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/win32/libjpeg-62.dll +0 -0
  36. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/win32/optipng.exe +0 -0
  37. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/win64/gifsicle.exe +0 -0
  38. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/win64/jpegoptim.exe +0 -0
  39. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/win64/jpegtran.exe +0 -0
  40. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/win64/libjpeg-62.dll +0 -0
  41. lib/{apptrian/imageoptimizer → Apptrian/ImageOptimizer}/win64/optipng.exe +0 -0
  42. package.xml +7 -7
  43. skin/adminhtml/default/default/css/apptrian_imageoptimizer.css +1 -1
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/About.php CHANGED
@@ -3,7 +3,7 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_About
@@ -22,7 +22,7 @@ class Apptrian_ImageOptimizer_Block_Adminhtml_About
22
$element = null;
23
$version = Mage::helper('apptrian_imageoptimizer')
24
->getExtensionVersion();
25
- $logopath = 'http://www.apptrian.com/media/apptrian.gif';
26
$html = <<<HTML
27
<div style="background:url('$logopath') no-repeat scroll 15px 15px #e7efef;
28
border:1px solid #ccc; min-height:100px; margin:5px 0;
@@ -34,12 +34,12 @@ speed up your site.
34
</p>
35
<p>
36
Website:
37
- <a href="http://www.apptrian.com" target="_blank">www.apptrian.com</a><br />
38
Like, share and follow us on
39
<a href="https://www.facebook.com/apptrian" target="_blank">Facebook</a>,
40
<a href="https://plus.google.com/+ApptrianCom" target="_blank">Google+</a>,
41
- <a href="http://www.pinterest.com/apptrian" target="_blank">Pinterest</a>, and
42
- <a href="http://twitter.com/apptrian" target="_blank">Twitter</a>.<br />
43
If you have any questions send email at
44
<a href="mailto:service@apptrian.com">service@apptrian.com</a>.
45
</p>
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_About
22
$element = null;
23
$version = Mage::helper('apptrian_imageoptimizer')
24
->getExtensionVersion();
25
+ $logopath = 'https://www.apptrian.com/media/apptrian.gif';
26
$html = <<<HTML
27
<div style="background:url('$logopath') no-repeat scroll 15px 15px #e7efef;
28
border:1px solid #ccc; min-height:100px; margin:5px 0;
34
</p>
35
<p>
36
Website:
37
+ <a href="https://www.apptrian.com" target="_blank">www.apptrian.com</a><br />
38
Like, share and follow us on
39
<a href="https://www.facebook.com/apptrian" target="_blank">Facebook</a>,
40
<a href="https://plus.google.com/+ApptrianCom" target="_blank">Google+</a>,
41
+ <a href="https://www.pinterest.com/apptrian" target="_blank">Pinterest</a>, and
42
+ <a href="https://twitter.com/apptrian" target="_blank">Twitter</a>.<br />
43
If you have any questions send email at
44
<a href="mailto:service@apptrian.com">service@apptrian.com</a>.
45
</p>
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Clear.php CHANGED
@@ -3,7 +3,7 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Clear
@@ -17,8 +17,7 @@ class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Clear
17
*/
18
protected function _getElementHtml(
19
Varien_Data_Form_Element_Abstract $element
20
- )
21
- {
22
$element = null;
23
24
$buttonLabel = Mage::helper('apptrian_imageoptimizer')
@@ -33,13 +32,11 @@ class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Clear
33
34
$html = $this->getLayout()->createBlock('adminhtml/widget_button')
35
->setType('button')
36
- //->setId('apptrian_imageoptimizer_general_clear')
37
->setClass('apptrian-imageoptimizer-admin-button-clear')
38
->setLabel($buttonLabel)
39
->setOnClick("confirmSetLocation('".$confirmText."', '".$url."')")
40
->toHtml();
41
42
return $html;
43
-
44
}
45
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Clear
17
*/
18
protected function _getElementHtml(
19
Varien_Data_Form_Element_Abstract $element
20
+ ) {
21
$element = null;
22
23
$buttonLabel = Mage::helper('apptrian_imageoptimizer')
32
33
$html = $this->getLayout()->createBlock('adminhtml/widget_button')
34
->setType('button')
35
->setClass('apptrian-imageoptimizer-admin-button-clear')
36
->setLabel($buttonLabel)
37
->setOnClick("confirmSetLocation('".$confirmText."', '".$url."')")
38
->toHtml();
39
40
return $html;
41
}
42
}
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Optimize.php CHANGED
@@ -3,7 +3,7 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Optimize
@@ -17,9 +17,7 @@ class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Optimize
17
*/
18
protected function _getElementHtml(
19
Varien_Data_Form_Element_Abstract $element
20
- )
21
- {
22
-
23
$elementOriginalData = $element->getOriginalData();
24
25
if (isset($elementOriginalData['label'])) {
@@ -34,13 +32,11 @@ class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Optimize
34
35
$html = $this->getLayout()->createBlock('adminhtml/widget_button')
36
->setType('button')
37
- //->setId('apptrian_imageoptimizer_general_optimize')
38
->setClass('apptrian-imageoptimizer-admin-button-optimize')
39
->setLabel($buttonLabel)
40
->setOnClick("setLocation('$url')")
41
->toHtml();
42
43
return $html;
44
-
45
}
46
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Optimize
17
*/
18
protected function _getElementHtml(
19
Varien_Data_Form_Element_Abstract $element
20
+ ) {
21
$elementOriginalData = $element->getOriginalData();
22
23
if (isset($elementOriginalData['label'])) {
32
33
$html = $this->getLayout()->createBlock('adminhtml/widget_button')
34
->setType('button')
35
->setClass('apptrian-imageoptimizer-admin-button-optimize')
36
->setLabel($buttonLabel)
37
->setOnClick("setLocation('$url')")
38
->toHtml();
39
40
return $html;
41
}
42
}
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Scan.php CHANGED
@@ -3,7 +3,7 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Scan
@@ -17,9 +17,7 @@ class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Scan
17
*/
18
protected function _getElementHtml(
19
Varien_Data_Form_Element_Abstract $element
20
- )
21
- {
22
-
23
$elementOriginalData = $element->getOriginalData();
24
25
if (isset($elementOriginalData['label'])) {
@@ -34,13 +32,11 @@ class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Scan
34
35
$html = $this->getLayout()->createBlock('adminhtml/widget_button')
36
->setType('button')
37
- //->setId('apptrian_imageoptimizer_general_scan')
38
->setClass('apptrian-imageoptimizer-admin-button-scan')
39
->setLabel($buttonLabel)
40
->setOnClick("setLocation('$url')")
41
->toHtml();
42
43
return $html;
44
-
45
}
46
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Scan
17
*/
18
protected function _getElementHtml(
19
Varien_Data_Form_Element_Abstract $element
20
+ ) {
21
$elementOriginalData = $element->getOriginalData();
22
23
if (isset($elementOriginalData['label'])) {
32
33
$html = $this->getLayout()->createBlock('adminhtml/widget_button')
34
->setType('button')
35
->setClass('apptrian-imageoptimizer-admin-button-scan')
36
->setLabel($buttonLabel)
37
->setOnClick("setLocation('$url')")
38
->toHtml();
39
40
return $html;
41
}
42
}
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Info.php CHANGED
@@ -3,7 +3,7 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_Info
@@ -20,78 +20,78 @@ class Apptrian_ImageOptimizer_Block_Adminhtml_Info
20
public function render(Varien_Data_Form_Element_Abstract $element)
21
{
22
$element = null;
23
- $logopath = 'http://www.apptrian.com/media/apptrian.gif';
24
$html = <<<HTML
25
<div style="background:url('$logopath') no-repeat scroll 15px 15px #e7efef;
26
border:1px solid #ccc; min-height:100px; margin:5px 0;
27
padding:15px 15px 15px 140px;">
28
<p>
29
<strong>Magento Online Stores &amp; Extensions</strong><br />
30
- <a href="http://www.apptrian.com" target="_blank">Apptrian</a> offers a wide
31
choice of products and services for your online business.
32
</p>
33
<p>
34
- Website: <a href="http://www.apptrian.com" target="_blank">www.apptrian.com</a>
35
<br />
36
Like, share and follow us on
37
<a href="https://www.facebook.com/apptrian" target="_blank">Facebook</a>,
38
<a href="https://plus.google.com/+ApptrianCom" target="_blank">Google+</a>,
39
- <a href="http://www.pinterest.com/apptrian" target="_blank">Pinterest</a>, and
40
- <a href="http://twitter.com/apptrian" target="_blank">Twitter</a>.<br />
41
If you have any questions send email at
42
<a href="mailto:service@apptrian.com">service@apptrian.com</a>.
43
</p>
44
</div>
45
<div>
46
<p><strong>Products and services you might be interested in:</strong></p>
47
- <a href="http://www.apptrian.com/facebook-pixel-for-magento"
48
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
49
- <img src="http://www.apptrian.com/media/facebook-pixel.jpg"
50
alt="Facebook Pixel" style="border:1px solid #ccc;" />
51
</a>
52
- <a href="http://www.apptrian.com/image-optimizer-for-magento"
53
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
54
- <img src="http://www.apptrian.com/media/image-optimizer.jpg"
55
alt="Image Optimizer" style="border:1px solid #ccc;" />
56
</a>
57
- <a href="http://www.apptrian.com/minify-html-css-js-for-magento"
58
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
59
- <img src="http://www.apptrian.com/media/minify-html-css-js.jpg"
60
alt="Minify HTML CSS JS" style="border:1px solid #ccc;" />
61
</a>
62
- <a href="http://www.apptrian.com/professional-magento-installation"
63
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
64
- <img src="http://www.apptrian.com/media/professional-magento-installation.jpg"
65
alt="Professional Magento Installation" style="border:1px solid #ccc;" />
66
</a>
67
- <a href="http://www.apptrian.com/quick-search-for-magento"
68
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
69
- <img src="http://www.apptrian.com/media/quick-search.jpg"
70
alt="Quick Search" style="border:1px solid #ccc;" />
71
</a>
72
- <a href="http://www.apptrian.com/responsive-product-slider-for-magento"
73
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
74
- <img src="http://www.apptrian.com/media/responsive-product-slider.jpg"
75
alt="Responsive Product Slider" style="border:1px solid #ccc;" />
76
</a>
77
- <a href="http://www.apptrian.com/schema-org-microdata-for-magento"
78
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
79
- <img src="http://www.apptrian.com/media/schema-org-microdata-for-magento.jpg"
80
alt="Schema.org Microdata for Magento" style="border:1px solid #ccc;" />
81
</a>
82
- <a href="http://www.apptrian.com/snippets-generator-for-magento"
83
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
84
- <img src="http://www.apptrian.com/media/snippets-generator.jpg"
85
alt="Snippets Generator" style="border:1px solid #ccc;" />
86
</a>
87
- <a href="http://www.apptrian.com/social-integrator-for-magento"
88
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
89
- <img src="http://www.apptrian.com/media/social-integrator.jpg"
90
alt="Social Integrator" style="border:1px solid #ccc;" />
91
</a>
92
- <a href="http://www.apptrian.com/subcategories-grid-list-for-magento"
93
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
94
- <img src="http://www.apptrian.com/media/subcategories-grid-list.jpg"
95
alt="Subcategories Grid/List" style="border:1px solid #ccc;" />
96
</a>
97
</div>
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_Info
20
public function render(Varien_Data_Form_Element_Abstract $element)
21
{
22
$element = null;
23
+ $logopath = 'https://www.apptrian.com/media/apptrian.gif';
24
$html = <<<HTML
25
<div style="background:url('$logopath') no-repeat scroll 15px 15px #e7efef;
26
border:1px solid #ccc; min-height:100px; margin:5px 0;
27
padding:15px 15px 15px 140px;">
28
<p>
29
<strong>Magento Online Stores &amp; Extensions</strong><br />
30
+ <a href="https://www.apptrian.com" target="_blank">Apptrian</a> offers a wide
31
choice of products and services for your online business.
32
</p>
33
<p>
34
+ Website: <a href="https://www.apptrian.com" target="_blank">www.apptrian.com</a>
35
<br />
36
Like, share and follow us on
37
<a href="https://www.facebook.com/apptrian" target="_blank">Facebook</a>,
38
<a href="https://plus.google.com/+ApptrianCom" target="_blank">Google+</a>,
39
+ <a href="https://www.pinterest.com/apptrian" target="_blank">Pinterest</a>, and
40
+ <a href="https://twitter.com/apptrian" target="_blank">Twitter</a>.<br />
41
If you have any questions send email at
42
<a href="mailto:service@apptrian.com">service@apptrian.com</a>.
43
</p>
44
</div>
45
<div>
46
<p><strong>Products and services you might be interested in:</strong></p>
47
+ <a href="https://www.apptrian.com/facebook-pixel-for-magento"
48
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
49
+ <img src="https://www.apptrian.com/media/facebook-pixel.jpg"
50
alt="Facebook Pixel" style="border:1px solid #ccc;" />
51
</a>
52
+ <a href="https://www.apptrian.com/image-optimizer-for-magento"
53
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
54
+ <img src="https://www.apptrian.com/media/image-optimizer.jpg"
55
alt="Image Optimizer" style="border:1px solid #ccc;" />
56
</a>
57
+ <a href="https://www.apptrian.com/minify-html-css-js-for-magento"
58
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
59
+ <img src="https://www.apptrian.com/media/minify-html-css-js.jpg"
60
alt="Minify HTML CSS JS" style="border:1px solid #ccc;" />
61
</a>
62
+ <a href="https://www.apptrian.com/professional-magento-installation"
63
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
64
+ <img src="https://www.apptrian.com/media/professional-magento-installation.jpg"
65
alt="Professional Magento Installation" style="border:1px solid #ccc;" />
66
</a>
67
+ <a href="https://www.apptrian.com/quick-search-for-magento"
68
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
69
+ <img src="https://www.apptrian.com/media/quick-search.jpg"
70
alt="Quick Search" style="border:1px solid #ccc;" />
71
</a>
72
+ <a href="https://www.apptrian.com/responsive-product-slider-for-magento"
73
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
74
+ <img src="https://www.apptrian.com/media/responsive-product-slider.jpg"
75
alt="Responsive Product Slider" style="border:1px solid #ccc;" />
76
</a>
77
+ <a href="https://www.apptrian.com/schema-org-microdata-for-magento"
78
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
79
+ <img src="https://www.apptrian.com/media/schema-org-microdata-for-magento.jpg"
80
alt="Schema.org Microdata for Magento" style="border:1px solid #ccc;" />
81
</a>
82
+ <a href="https://www.apptrian.com/snippets-generator-for-magento"
83
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
84
+ <img src="https://www.apptrian.com/media/snippets-generator.jpg"
85
alt="Snippets Generator" style="border:1px solid #ccc;" />
86
</a>
87
+ <a href="https://www.apptrian.com/social-integrator-for-magento"
88
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
89
+ <img src="https://www.apptrian.com/media/social-integrator.jpg"
90
alt="Social Integrator" style="border:1px solid #ccc;" />
91
</a>
92
+ <a href="https://www.apptrian.com/subcategories-grid-list-for-magento"
93
target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
94
+ <img src="https://www.apptrian.com/media/subcategories-grid-list.jpg"
95
alt="Subcategories Grid/List" style="border:1px solid #ccc;" />
96
</a>
97
</div>
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Stats.php CHANGED
@@ -3,7 +3,7 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_Stats
@@ -17,8 +17,7 @@ class Apptrian_ImageOptimizer_Block_Adminhtml_Stats
17
*/
18
protected function _getElementHtml(
19
Varien_Data_Form_Element_Abstract $element
20
- )
21
- {
22
$element = null;
23
$r = Mage::helper('apptrian_imageoptimizer')->getFileCount();
24
$indexed = $r['indexed'];
@@ -33,14 +32,13 @@ class Apptrian_ImageOptimizer_Block_Adminhtml_Stats
33
34
$html = '<div class="apptrian-imageoptimizer-bar-wrapper">
35
<div class="apptrian-imageoptimizer-bar-outer">
36
- <div class="apptrian-imageoptimizer-bar-inner" style="width:'
37
. $percent .'%;"></div>
38
- <div class="apptrian-imageoptimizer-bar-text"><span>' . $percent . '% '
39
. Mage::helper('apptrian_imageoptimizer')
40
->__('(%s of %s files)', $optimized, $indexed) . '</span></div>
41
</div></div>';
42
43
return $html;
44
-
45
}
46
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Block_Adminhtml_Stats
17
*/
18
protected function _getElementHtml(
19
Varien_Data_Form_Element_Abstract $element
20
+ ) {
21
$element = null;
22
$r = Mage::helper('apptrian_imageoptimizer')->getFileCount();
23
$indexed = $r['indexed'];
32
33
$html = '<div class="apptrian-imageoptimizer-bar-wrapper">
34
<div class="apptrian-imageoptimizer-bar-outer">
35
+ <div class="apptrian-imageoptimizer-bar-inner" style="width:'
36
. $percent .'%;"></div>
37
+ <div class="apptrian-imageoptimizer-bar-text"><span>' . $percent . '% '
38
. Mage::helper('apptrian_imageoptimizer')
39
->__('(%s of %s files)', $optimized, $indexed) . '</span></div>
40
</div></div>';
41
42
return $html;
43
}
44
}
app/code/community/Apptrian/ImageOptimizer/Helper/Data.php CHANGED
@@ -3,7 +3,7 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
@@ -18,7 +18,7 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
18
19
/**
20
* Logging flag.
21
- *
22
* @var null|int
23
*/
24
protected $_logging = null;
@@ -60,14 +60,14 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
60
61
/**
62
* Total count of files in index.
63
- *
64
* @var integer $_indexTotalCount
65
*/
66
protected $_indexTotalCount = 0;
67
68
/**
69
* Count of files that are optimized.
70
- *
71
* @var integer $_indexOptimizedCount
72
*/
73
protected $_indexOptimizedCount = 0;
@@ -101,20 +101,16 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
101
*/
102
public function getBaseDir()
103
{
104
-
105
if ($this->_baseDir === null) {
106
-
107
$this->_baseDir = Mage::getBaseDir();
108
-
109
}
110
111
return $this->_baseDir;
112
-
113
}
114
115
/**
116
* Checks if exec() function is enabled in php and suhosin config.
117
- *
118
* @return boolean
119
*/
120
public function isExecFunctionEnabled()
@@ -123,20 +119,22 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
123
124
// PHP disabled functions
125
$phpDisabledFunctions = array_map(
126
- 'strtolower',
127
array_map('trim', explode(',', ini_get('disable_functions')))
128
);
129
130
// Suhosin disabled functions
131
$suhosinDisabledFunctions = array_map(
132
- 'strtolower',
133
array_map(
134
- 'trim', explode(',', ini_get('suhosin.executor.func.blacklist'))
135
)
136
);
137
138
$disabledFunctions = array_merge(
139
- $phpDisabledFunctions, $suhosinDisabledFunctions
140
);
141
142
$disabled = false;
@@ -154,31 +152,28 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
154
155
/**
156
* Optimized way of getting logging flag from config.
157
- *
158
* @return int
159
*/
160
public function isLoggingEnabled()
161
{
162
if ($this->_logging === null) {
163
-
164
$this->_logging = (int) $this->getConfig(
165
'apptrian_imageoptimizer/utility/log_output'
166
);
167
-
168
}
169
170
return $this->_logging;
171
}
172
173
/**
174
- * Based on config returns array of all paths that will be scaned for
175
* images.
176
- *
177
* @return array
178
*/
179
public function getPaths()
180
{
181
-
182
$paths = array();
183
184
$pathsString = trim(
@@ -188,28 +183,22 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
188
$rawPaths = explode(';', $pathsString);
189
190
foreach ($rawPaths as $p) {
191
-
192
$trimmed = trim(trim($p), '/');
193
-
194
$dirs = explode('/', $trimmed);
195
-
196
$paths[] = implode(DS, $dirs);
197
-
198
}
199
200
return array_unique($paths);
201
-
202
}
203
204
/**
205
* Optimizes single file.
206
- *
207
* @param string $filePath
208
* @return boolean
209
*/
210
public function optimizeFile($filePath)
211
{
212
-
213
$info = pathinfo($filePath);
214
215
$output = array();
@@ -231,7 +220,6 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
231
}
232
233
if ($returnVar == 126) {
234
-
235
$error = $this->getConfig(
236
'apptrian_imageoptimizer/utility/' . $type
237
) . ' is not executable.';
@@ -239,14 +227,10 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
239
Mage::log($error, null, 'apptrian_imageoptimizer.log');
240
241
return false;
242
-
243
} else {
244
-
245
if ($this->isLoggingEnabled()) {
246
-
247
Mage::log($filePath, null, 'apptrian_imageoptimizer.log');
248
Mage::log($output, null, 'apptrian_imageoptimizer.log');
249
-
250
}
251
252
$permissions = (string) $this->getConfig(
@@ -258,19 +242,16 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
258
}
259
260
return true;
261
-
262
}
263
-
264
}
265
266
/**
267
* Optimization process.
268
- *
269
* @return boolean
270
*/
271
public function optimize()
272
{
273
-
274
$this->loadIndex();
275
276
// Get Batch Size
@@ -290,27 +271,19 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
290
291
// Optimize batch of files
292
foreach ($files as $id => $item) {
293
-
294
$encodedPath = $item['f'];
295
$decodedPath = utf8_decode($encodedPath);
296
$filePath = realpath($decodedPath);
297
298
// If image exists, optimize else remove it from database
299
if (file_exists($filePath)) {
300
-
301
if ($this->optimizeFile($filePath)) {
302
-
303
$toUpdate[$id]['f'] = $encodedPath;
304
-
305
}
306
-
307
} else {
308
-
309
// Remove files that do not exist anymore from the index
310
unset($this->_index[$id]);
311
-
312
}
313
-
314
}
315
316
$i = '';
@@ -319,35 +292,29 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
319
// Itereate over $toUpdate array and set modified time
320
// (mtime) takes a split second to update
321
foreach ($toUpdate as $i => $f) {
322
-
323
$encodedPath = $f['f'];
324
$decodedPath = utf8_decode($encodedPath);
325
$filePath = realpath($decodedPath);
326
327
if (file_exists($filePath)) {
328
-
329
// Update optimized file information in index
330
$this->_index[$i]['t'] = filemtime($filePath);
331
-
332
}
333
334
// Free Memory
335
unset($toUpdate[$i]);
336
-
337
}
338
339
return $this->saveIndex();
340
-
341
}
342
343
/**
344
* Scan and reindex process.
345
- *
346
* @return boolean
347
*/
348
public function scanAndReindex()
349
{
350
-
351
$this->loadIndex();
352
353
$id = '';
@@ -358,25 +325,19 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
358
359
// Check index for files that need to be updated and/or removed
360
foreach ($this->_index as $id => $item) {
361
-
362
$encodedPath = $item['f'];
363
$decodedPath = utf8_decode($encodedPath);
364
$filePath = realpath($decodedPath);
365
366
if (file_exists($filePath)) {
367
if ($item['t'] != 0 && filemtime($filePath) != $item['t']) {
368
-
369
// Update time to 0 in index so it can be optimized again
370
$this->_index[$id]['t'] = 0;
371
-
372
}
373
} else {
374
-
375
// Remove files that do not exist anymore from the index
376
unset($this->_index[$id]);
377
-
378
}
379
-
380
}
381
382
$paths = $this->getPaths();
@@ -384,23 +345,19 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
384
385
// Scan for new files and add them to the index
386
foreach ($paths as $path) {
387
-
388
$this->scanAndReindexPath($path);
389
-
390
}
391
392
return $this->saveIndex();
393
-
394
}
395
396
/**
397
* Scans provided path for images and adds them to index.
398
- *
399
* @param string $path
400
*/
401
public function scanAndReindexPath($path)
402
{
403
-
404
$id = '';
405
$encodedPath = '';
406
$filePath = '';
@@ -414,13 +371,12 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
414
);
415
416
foreach ($iterator as $file) {
417
-
418
if ($file->isFile()
419
&& preg_match(
420
- '/^.+\.(jpe?g|gif|png)#x2F;i', $file->getFilename()
421
)
422
) {
423
-
424
$filePath = $file->getRealPath();
425
if (!is_writable($filePath)) {
426
continue;
@@ -433,17 +389,14 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
433
if (!isset($this->_index[$id])) {
434
$this->_index[$id] = array('f' => $encodedPath, 't' => 0);
435
}
436
-
437
}
438
439
// Free Memory
440
$file = null;
441
-
442
}
443
444
// Free Memory
445
$iterator = null;
446
-
447
}
448
449
/**
@@ -503,23 +456,18 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
503
*/
504
public function getUtil($type, $filePath)
505
{
506
-
507
$exactPath = $this->getConfig(
508
'apptrian_imageoptimizer/utility/' . $type . '_path'
509
);
510
511
// If utility exact path is set use it
512
if ($exactPath != '') {
513
-
514
$cmd = $exactPath;
515
-
516
// Use path to extension's local utilities
517
} else {
518
-
519
$cmd = $this->getUtilPath() . DS . $this->getConfig(
520
'apptrian_imageoptimizer/utility/' . $type
521
) . $this->getUtilExt();
522
-
523
}
524
525
$cmd .= ' ' . $this->getConfig(
@@ -527,7 +475,6 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
527
);
528
529
return str_replace('%filepath%', $filePath, $cmd);
530
-
531
}
532
533
/**
@@ -539,9 +486,7 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
539
public function getUtilExt()
540
{
541
if ($this->_utilExt === null) {
542
-
543
$this->_utilExt = $this->isWindows() ? '.exe' : '';
544
-
545
}
546
547
return $this->_utilExt;
@@ -557,7 +502,6 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
557
public function getUtilPath()
558
{
559
if ($this->_utilPath === null) {
560
-
561
$useSixtyFourBit = (int) $this->getConfig(
562
'apptrian_imageoptimizer/utility/use64bit'
563
);
@@ -573,7 +517,7 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
573
$pathString = trim(
574
trim(
575
$this->getConfig('apptrian_imageoptimizer/utility/path')
576
- ),
577
'/'
578
);
579
@@ -581,7 +525,6 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
581
$path = implode(DS, $dirs);
582
583
$this->_utilPath = $this->getBaseDir() . DS . $path . DS . $os;
584
-
585
}
586
587
return $this->_utilPath;
@@ -589,16 +532,14 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
589
590
/**
591
* Returns index path.
592
- *
593
* @return string
594
*/
595
public function getIndexPath()
596
{
597
if ($this->_indexPath === null) {
598
-
599
- $this->_indexPath = Mage::getBaseDir('var') . DS
600
. $this->_indexFilename;
601
-
602
}
603
604
return $this->_indexPath;
@@ -606,17 +547,15 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
606
607
/**
608
* Returns array of files for optimization limited by $batchSize.
609
- *
610
* @param int $batchSize
611
*/
612
public function getFiles($batchSize)
613
{
614
-
615
$files = array();
616
$counter = 0;
617
618
foreach ($this->_index as $id => $f) {
619
-
620
if ($counter == $batchSize) {
621
break;
622
}
@@ -625,11 +564,9 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
625
$files[$id] = $f;
626
$counter++;
627
}
628
-
629
}
630
631
return $files;
632
-
633
}
634
635
/**
@@ -639,7 +576,6 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
639
*/
640
public function getFileCount()
641
{
642
-
643
$this->loadIndex();
644
645
$r['indexed'] = $this->_indexTotalCount;
@@ -649,7 +585,6 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
649
$this->_index = null;
650
651
return $r;
652
-
653
}
654
655
/**
@@ -659,7 +594,6 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
659
*/
660
public function clearIndex()
661
{
662
-
663
$r = file_put_contents($this->getIndexPath(), '', LOCK_EX);
664
665
if ($r === false) {
@@ -669,20 +603,17 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
669
}
670
671
return $r;
672
-
673
}
674
675
/**
676
* Load index from a file.
677
- *
678
*/
679
public function loadIndex()
680
{
681
-
682
$filePath = $this->getIndexPath();
683
684
if (file_exists($filePath)) {
685
-
686
$line = '';
687
$l = array();
688
$id = '';
@@ -691,7 +622,6 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
691
$str = file_get_contents($filePath);
692
693
if ($str != '') {
694
-
695
$data = explode("\n", $str);
696
697
// Free Memory
@@ -702,7 +632,6 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
702
$i = 0;
703
704
for ($i = 0; $i < $this->_indexTotalCount; $i++) {
705
-
706
$line = $data[$i];
707
$l = explode('|', $line);
708
$id = (string) $l[0];
@@ -717,30 +646,25 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
717
718
// Free Memory
719
unset($data[$i]);
720
-
721
}
722
723
// Free Memory
724
$data = null;
725
-
726
}
727
728
if (!$this->_index) {
729
$this->_index = array();
730
}
731
-
732
}
733
-
734
}
735
736
/**
737
* Save index to a file.
738
- *
739
* @return boolean
740
*/
741
public function saveIndex()
742
{
743
-
744
$id = '';
745
$f = '';
746
$data = array();
@@ -752,17 +676,18 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
752
$this->clearIndex();
753
754
foreach ($this->_index as $id => $f) {
755
-
756
// str_replace() removes | from filename because | is delimiter
757
$data[] = sprintf(
758
- '%s|%s|%d', $id, str_replace('|', '', $f['f']), $f['t']
759
);
760
761
// Free memory
762
unset($this->_index[$id]);
763
764
if ($c == 100000) {
765
-
766
// Save part of the file
767
$r = $this->saveToFile($data, $b);
768
@@ -774,14 +699,10 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
774
775
// Reset count
776
$c = 0;
777
-
778
} else {
779
-
780
// Increment count
781
$c++;
782
-
783
}
784
-
785
}
786
787
// Save last part of the file
@@ -797,22 +718,19 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
797
}
798
799
return $r;
800
-
801
}
802
803
/**
804
* Saves batch of data to a file.
805
- *
806
* @param array $data
807
* @param int $b
808
*/
809
public function saveToFile($data, $b)
810
{
811
-
812
$r = true;
813
814
- if (count($data) > 0) {
815
-
816
$fh = fopen($this->getIndexPath(), 'a');
817
818
if ($b != 0) {
@@ -822,11 +740,8 @@ class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
822
$r = fwrite($fh, implode("\n", $data));
823
824
fclose($fh);
825
-
826
}
827
828
return $r;
829
-
830
}
831
-
832
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
18
19
/**
20
* Logging flag.
21
+ *
22
* @var null|int
23
*/
24
protected $_logging = null;
60
61
/**
62
* Total count of files in index.
63
+ *
64
* @var integer $_indexTotalCount
65
*/
66
protected $_indexTotalCount = 0;
67
68
/**
69
* Count of files that are optimized.
70
+ *
71
* @var integer $_indexOptimizedCount
72
*/
73
protected $_indexOptimizedCount = 0;
101
*/
102
public function getBaseDir()
103
{
104
if ($this->_baseDir === null) {
105
$this->_baseDir = Mage::getBaseDir();
106
}
107
108
return $this->_baseDir;
109
}
110
111
/**
112
* Checks if exec() function is enabled in php and suhosin config.
113
+ *
114
* @return boolean
115
*/
116
public function isExecFunctionEnabled()
119
120
// PHP disabled functions
121
$phpDisabledFunctions = array_map(
122
+ 'strtolower',
123
array_map('trim', explode(',', ini_get('disable_functions')))
124
);
125
126
// Suhosin disabled functions
127
$suhosinDisabledFunctions = array_map(
128
+ 'strtolower',
129
array_map(
130
+ 'trim',
131
+ explode(',', ini_get('suhosin.executor.func.blacklist'))
132
)
133
);
134
135
$disabledFunctions = array_merge(
136
+ $phpDisabledFunctions,
137
+ $suhosinDisabledFunctions
138
);
139
140
$disabled = false;
152
153
/**
154
* Optimized way of getting logging flag from config.
155
+ *
156
* @return int
157
*/
158
public function isLoggingEnabled()
159
{
160
if ($this->_logging === null) {
161
$this->_logging = (int) $this->getConfig(
162
'apptrian_imageoptimizer/utility/log_output'
163
);
164
}
165
166
return $this->_logging;
167
}
168
169
/**
170
+ * Based on config returns array of all paths that will be scaned for
171
* images.
172
+ *
173
* @return array
174
*/
175
public function getPaths()
176
{
177
$paths = array();
178
179
$pathsString = trim(
183
$rawPaths = explode(';', $pathsString);
184
185
foreach ($rawPaths as $p) {
186
$trimmed = trim(trim($p), '/');
187
$dirs = explode('/', $trimmed);
188
$paths[] = implode(DS, $dirs);
189
}
190
191
return array_unique($paths);
192
}
193
194
/**
195
* Optimizes single file.
196
+ *
197
* @param string $filePath
198
* @return boolean
199
*/
200
public function optimizeFile($filePath)
201
{
202
$info = pathinfo($filePath);
203
204
$output = array();
220
}
221
222
if ($returnVar == 126) {
223
$error = $this->getConfig(
224
'apptrian_imageoptimizer/utility/' . $type
225
) . ' is not executable.';
227
Mage::log($error, null, 'apptrian_imageoptimizer.log');
228
229
return false;
230
} else {
231
if ($this->isLoggingEnabled()) {
232
Mage::log($filePath, null, 'apptrian_imageoptimizer.log');
233
Mage::log($output, null, 'apptrian_imageoptimizer.log');
234
}
235
236
$permissions = (string) $this->getConfig(
242
}
243
244
return true;
245
}
246
}
247
248
/**
249
* Optimization process.
250
+ *
251
* @return boolean
252
*/
253
public function optimize()
254
{
255
$this->loadIndex();
256
257
// Get Batch Size
271
272
// Optimize batch of files
273
foreach ($files as $id => $item) {
274
$encodedPath = $item['f'];
275
$decodedPath = utf8_decode($encodedPath);
276
$filePath = realpath($decodedPath);
277
278
// If image exists, optimize else remove it from database
279
if (file_exists($filePath)) {
280
if ($this->optimizeFile($filePath)) {
281
$toUpdate[$id]['f'] = $encodedPath;
282
}
283
} else {
284
// Remove files that do not exist anymore from the index
285
unset($this->_index[$id]);
286
}
287
}
288
289
$i = '';
292
// Itereate over $toUpdate array and set modified time
293
// (mtime) takes a split second to update
294
foreach ($toUpdate as $i => $f) {
295
$encodedPath = $f['f'];
296
$decodedPath = utf8_decode($encodedPath);
297
$filePath = realpath($decodedPath);
298
299
if (file_exists($filePath)) {
300
// Update optimized file information in index
301
$this->_index[$i]['t'] = filemtime($filePath);
302
}
303
304
// Free Memory
305
unset($toUpdate[$i]);
306
}
307
308
return $this->saveIndex();
309
}
310
311
/**
312
* Scan and reindex process.
313
+ *
314
* @return boolean
315
*/
316
public function scanAndReindex()
317
{
318
$this->loadIndex();
319
320
$id = '';
325
326
// Check index for files that need to be updated and/or removed
327
foreach ($this->_index as $id => $item) {
328
$encodedPath = $item['f'];
329
$decodedPath = utf8_decode($encodedPath);
330
$filePath = realpath($decodedPath);
331
332
if (file_exists($filePath)) {
333
if ($item['t'] != 0 && filemtime($filePath) != $item['t']) {
334
// Update time to 0 in index so it can be optimized again
335
$this->_index[$id]['t'] = 0;
336
}
337
} else {
338
// Remove files that do not exist anymore from the index
339
unset($this->_index[$id]);
340
}
341
}
342
343
$paths = $this->getPaths();
345
346
// Scan for new files and add them to the index
347
foreach ($paths as $path) {
348
$this->scanAndReindexPath($path);
349
}
350
351
return $this->saveIndex();
352
}
353
354
/**
355
* Scans provided path for images and adds them to index.
356
+ *
357
* @param string $path
358
*/
359
public function scanAndReindexPath($path)
360
{
361
$id = '';
362
$encodedPath = '';
363
$filePath = '';
371
);
372
373
foreach ($iterator as $file) {
374
if ($file->isFile()
375
&& preg_match(
376
+ '/^.+\.(jpe?g|gif|png)#x2F;i',
377
+ $file->getFilename()
378
)
379
) {
380
$filePath = $file->getRealPath();
381
if (!is_writable($filePath)) {
382
continue;
389
if (!isset($this->_index[$id])) {
390
$this->_index[$id] = array('f' => $encodedPath, 't' => 0);
391
}
392
}
393
394
// Free Memory
395
$file = null;
396
}
397
398
// Free Memory
399
$iterator = null;
400
}
401
402
/**
456
*/
457
public function getUtil($type, $filePath)
458
{
459
$exactPath = $this->getConfig(
460
'apptrian_imageoptimizer/utility/' . $type . '_path'
461
);
462
463
// If utility exact path is set use it
464
if ($exactPath != '') {
465
$cmd = $exactPath;
466
// Use path to extension's local utilities
467
} else {
468
$cmd = $this->getUtilPath() . DS . $this->getConfig(
469
'apptrian_imageoptimizer/utility/' . $type
470
) . $this->getUtilExt();
471
}
472
473
$cmd .= ' ' . $this->getConfig(
475
);
476
477
return str_replace('%filepath%', $filePath, $cmd);
478
}
479
480
/**
486
public function getUtilExt()
487
{
488
if ($this->_utilExt === null) {
489
$this->_utilExt = $this->isWindows() ? '.exe' : '';
490
}
491
492
return $this->_utilExt;
502
public function getUtilPath()
503
{
504
if ($this->_utilPath === null) {
505
$useSixtyFourBit = (int) $this->getConfig(
506
'apptrian_imageoptimizer/utility/use64bit'
507
);
517
$pathString = trim(
518
trim(
519
$this->getConfig('apptrian_imageoptimizer/utility/path')
520
+ ),
521
'/'
522
);
523
525
$path = implode(DS, $dirs);
526
527
$this->_utilPath = $this->getBaseDir() . DS . $path . DS . $os;
528
}
529
530
return $this->_utilPath;
532
533
/**
534
* Returns index path.
535
+ *
536
* @return string
537
*/
538
public function getIndexPath()
539
{
540
if ($this->_indexPath === null) {
541
+ $this->_indexPath = Mage::getBaseDir('var') . DS
542
. $this->_indexFilename;
543
}
544
545
return $this->_indexPath;
547
548
/**
549
* Returns array of files for optimization limited by $batchSize.
550
+ *
551
* @param int $batchSize
552
*/
553
public function getFiles($batchSize)
554
{
555
$files = array();
556
$counter = 0;
557
558
foreach ($this->_index as $id => $f) {
559
if ($counter == $batchSize) {
560
break;
561
}
564
$files[$id] = $f;
565
$counter++;
566
}
567
}
568
569
return $files;
570
}
571
572
/**
576
*/
577
public function getFileCount()
578
{
579
$this->loadIndex();
580
581
$r['indexed'] = $this->_indexTotalCount;
585
$this->_index = null;
586
587
return $r;
588
}
589
590
/**
594
*/
595
public function clearIndex()
596
{
597
$r = file_put_contents($this->getIndexPath(), '', LOCK_EX);
598
599
if ($r === false) {
603
}
604
605
return $r;
606
}
607
608
/**
609
* Load index from a file.
610
+ *
611
*/
612
public function loadIndex()
613
{
614
$filePath = $this->getIndexPath();
615
616
if (file_exists($filePath)) {
617
$line = '';
618
$l = array();
619
$id = '';
622
$str = file_get_contents($filePath);
623
624
if ($str != '') {
625
$data = explode("\n", $str);
626
627
// Free Memory
632
$i = 0;
633
634
for ($i = 0; $i < $this->_indexTotalCount; $i++) {
635
$line = $data[$i];
636
$l = explode('|', $line);
637
$id = (string) $l[0];
646
647
// Free Memory
648
unset($data[$i]);
649
}
650
651
// Free Memory
652
$data = null;
653
}
654
655
if (!$this->_index) {
656
$this->_index = array();
657
}
658
}
659
}
660
661
/**
662
* Save index to a file.
663
+ *
664
* @return boolean
665
*/
666
public function saveIndex()
667
{
668
$id = '';
669
$f = '';
670
$data = array();
676
$this->clearIndex();
677
678
foreach ($this->_index as $id => $f) {
679
// str_replace() removes | from filename because | is delimiter
680
$data[] = sprintf(
681
+ '%s|%s|%d',
682
+ $id,
683
+ str_replace('|', '', $f['f']),
684
+ $f['t']
685
);
686
687
// Free memory
688
unset($this->_index[$id]);
689
690
if ($c == 100000) {
691
// Save part of the file
692
$r = $this->saveToFile($data, $b);
693
699
700
// Reset count
701
$c = 0;
702
} else {
703
// Increment count
704
$c++;
705
}
706
}
707
708
// Save last part of the file
718
}
719
720
return $r;
721
}
722
723
/**
724
* Saves batch of data to a file.
725
+ *
726
* @param array $data
727
* @param int $b
728
*/
729
public function saveToFile($data, $b)
730
{
731
$r = true;
732
733
+ if (!empty($data)) {
734
$fh = fopen($this->getIndexPath(), 'a');
735
736
if ($b != 0) {
740
$r = fwrite($fh, implode("\n", $data));
741
742
fclose($fh);
743
}
744
745
return $r;
746
}
747
}
app/code/community/Apptrian/ImageOptimizer/Model/Config/Batchsize.php CHANGED
@@ -3,31 +3,25 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Batchsize
10
extends Mage_Core_Model_Config_Data
11
{
12
-
13
public function _beforeSave()
14
{
15
-
16
$result = $this->validate();
17
18
if ($result !== true) {
19
-
20
Mage::throwException(implode("\n", $result));
21
-
22
}
23
24
return parent::_beforeSave();
25
-
26
}
27
28
public function validate()
29
{
30
-
31
$errors = array();
32
$helper = Mage::helper('apptrian_imageoptimizer');
33
$value = $this->getValue();
@@ -45,7 +39,5 @@ class Apptrian_ImageOptimizer_Model_Config_Batchsize
45
}
46
47
return $errors;
48
-
49
}
50
-
51
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Batchsize
10
extends Mage_Core_Model_Config_Data
11
{
12
public function _beforeSave()
13
{
14
$result = $this->validate();
15
16
if ($result !== true) {
17
Mage::throwException(implode("\n", $result));
18
}
19
20
return parent::_beforeSave();
21
}
22
23
public function validate()
24
{
25
$errors = array();
26
$helper = Mage::helper('apptrian_imageoptimizer');
27
$value = $this->getValue();
39
}
40
41
return $errors;
42
}
43
}
app/code/community/Apptrian/ImageOptimizer/Model/Config/Cron/Optimize.php CHANGED
@@ -3,61 +3,52 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Cron_Optimize
10
extends Mage_Core_Model_Config_Data
11
{
12
- const CRON_STRING_PATH =
13
'crontab/jobs/apptrian_imageoptimizer_optimize/schedule/cron_expr';
14
15
protected function _afterSave()
16
{
17
-
18
$cronExprString = $this->getValue();
19
20
try {
21
-
22
Mage::getModel('core/config_data')
23
->load(self::CRON_STRING_PATH, 'path')
24
->setValue($cronExprString)
25
->setPath(self::CRON_STRING_PATH)
26
->save();
27
-
28
} catch (Exception $e) {
29
-
30
- throw new Exception(
31
Mage::helper('cron')->__('Unable to save the cron expression.')
32
);
33
-
34
}
35
-
36
}
37
38
public function _beforeSave()
39
{
40
-
41
$result = $this->validate();
42
43
if ($result !== true) {
44
-
45
Mage::throwException(implode("\n", $result));
46
-
47
}
48
49
return parent::_beforeSave();
50
-
51
}
52
53
public function validate()
54
{
55
-
56
$errors = array();
57
$helper = Mage::helper('apptrian_imageoptimizer');
58
$value = $this->getValue();
59
$validator = Zend_Validate::is(
60
- $value, 'Regex', array('pattern' => '/^[0-9,\-\?\/\*\ ]+#x2F;')
61
);
62
63
if (!$validator) {
@@ -69,7 +60,5 @@ class Apptrian_ImageOptimizer_Model_Config_Cron_Optimize
69
}
70
71
return $errors;
72
-
73
}
74
-
75
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Cron_Optimize
10
extends Mage_Core_Model_Config_Data
11
{
12
+ const CRON_STRING_PATH =
13
'crontab/jobs/apptrian_imageoptimizer_optimize/schedule/cron_expr';
14
15
protected function _afterSave()
16
{
17
$cronExprString = $this->getValue();
18
19
try {
20
Mage::getModel('core/config_data')
21
->load(self::CRON_STRING_PATH, 'path')
22
->setValue($cronExprString)
23
->setPath(self::CRON_STRING_PATH)
24
->save();
25
} catch (Exception $e) {
26
+ Mage::throwException(
27
Mage::helper('cron')->__('Unable to save the cron expression.')
28
);
29
}
30
}
31
32
public function _beforeSave()
33
{
34
$result = $this->validate();
35
36
if ($result !== true) {
37
Mage::throwException(implode("\n", $result));
38
}
39
40
return parent::_beforeSave();
41
}
42
43
public function validate()
44
{
45
$errors = array();
46
$helper = Mage::helper('apptrian_imageoptimizer');
47
$value = $this->getValue();
48
$validator = Zend_Validate::is(
49
+ $value,
50
+ 'Regex',
51
+ array('pattern' => '/^[0-9,\-\?\/\*\ ]+#x2F;')
52
);
53
54
if (!$validator) {
60
}
61
62
return $errors;
63
}
64
}
app/code/community/Apptrian/ImageOptimizer/Model/Config/Cron/Scan.php CHANGED
@@ -3,61 +3,52 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Cron_Scan
10
extends Mage_Core_Model_Config_Data
11
{
12
- const CRON_STRING_PATH =
13
'crontab/jobs/apptrian_imageoptimizer_scan/schedule/cron_expr';
14
15
protected function _afterSave()
16
{
17
-
18
$cronExprString = $this->getValue();
19
20
try {
21
-
22
Mage::getModel('core/config_data')
23
->load(self::CRON_STRING_PATH, 'path')
24
->setValue($cronExprString)
25
->setPath(self::CRON_STRING_PATH)
26
->save();
27
-
28
} catch (Exception $e) {
29
-
30
- throw new Exception(
31
Mage::helper('cron')->__('Unable to save the cron expression.')
32
);
33
-
34
}
35
-
36
}
37
38
public function _beforeSave()
39
{
40
-
41
$result = $this->validate();
42
43
if ($result !== true) {
44
-
45
Mage::throwException(implode("\n", $result));
46
-
47
}
48
49
return parent::_beforeSave();
50
-
51
}
52
53
public function validate()
54
{
55
-
56
$errors = array();
57
$helper = Mage::helper('apptrian_imageoptimizer');
58
$value = $this->getValue();
59
$validator = Zend_Validate::is(
60
- $value, 'Regex', array('pattern' => '/^[0-9,\-\?\/\*\ ]+#x2F;')
61
);
62
63
if (!$validator) {
@@ -69,7 +60,5 @@ class Apptrian_ImageOptimizer_Model_Config_Cron_Scan
69
}
70
71
return $errors;
72
-
73
}
74
-
75
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Cron_Scan
10
extends Mage_Core_Model_Config_Data
11
{
12
+ const CRON_STRING_PATH =
13
'crontab/jobs/apptrian_imageoptimizer_scan/schedule/cron_expr';
14
15
protected function _afterSave()
16
{
17
$cronExprString = $this->getValue();
18
19
try {
20
Mage::getModel('core/config_data')
21
->load(self::CRON_STRING_PATH, 'path')
22
->setValue($cronExprString)
23
->setPath(self::CRON_STRING_PATH)
24
->save();
25
} catch (Exception $e) {
26
+ Mage::throwException(
27
Mage::helper('cron')->__('Unable to save the cron expression.')
28
);
29
}
30
}
31
32
public function _beforeSave()
33
{
34
$result = $this->validate();
35
36
if ($result !== true) {
37
Mage::throwException(implode("\n", $result));
38
}
39
40
return parent::_beforeSave();
41
}
42
43
public function validate()
44
{
45
$errors = array();
46
$helper = Mage::helper('apptrian_imageoptimizer');
47
$value = $this->getValue();
48
$validator = Zend_Validate::is(
49
+ $value,
50
+ 'Regex',
51
+ array('pattern' => '/^[0-9,\-\?\/\*\ ]+#x2F;')
52
);
53
54
if (!$validator) {
60
}
61
62
return $errors;
63
}
64
}
app/code/community/Apptrian/ImageOptimizer/Model/Config/Exactpath.php CHANGED
@@ -3,36 +3,31 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Exactpath
10
extends Mage_Core_Model_Config_Data
11
{
12
-
13
public function _beforeSave()
14
{
15
-
16
$result = $this->validate();
17
18
if ($result !== true) {
19
-
20
Mage::throwException(implode("\n", $result));
21
-
22
}
23
24
return parent::_beforeSave();
25
-
26
}
27
28
public function validate()
29
{
30
-
31
$errors = array();
32
$helper = Mage::helper('apptrian_imageoptimizer');
33
$value = $this->getValue();
34
$validator = Zend_Validate::is(
35
- $value, 'Regex',
36
array(
37
'pattern'=>'/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/\\\\]*#x2F;iu'
38
)
@@ -48,7 +43,5 @@ class Apptrian_ImageOptimizer_Model_Config_Exactpath
48
}
49
50
return $errors;
51
-
52
}
53
-
54
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Exactpath
10
extends Mage_Core_Model_Config_Data
11
{
12
public function _beforeSave()
13
{
14
$result = $this->validate();
15
16
if ($result !== true) {
17
Mage::throwException(implode("\n", $result));
18
}
19
20
return parent::_beforeSave();
21
}
22
23
public function validate()
24
{
25
$errors = array();
26
$helper = Mage::helper('apptrian_imageoptimizer');
27
$value = $this->getValue();
28
$validator = Zend_Validate::is(
29
+ $value,
30
+ 'Regex',
31
array(
32
'pattern'=>'/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/\\\\]*#x2F;iu'
33
)
43
}
44
45
return $errors;
46
}
47
}
app/code/community/Apptrian/ImageOptimizer/Model/Config/Options.php CHANGED
@@ -3,36 +3,32 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Options
10
extends Mage_Core_Model_Config_Data
11
{
12
-
13
public function _beforeSave()
14
{
15
-
16
$result = $this->validate();
17
18
if ($result !== true) {
19
-
20
Mage::throwException(implode("\n", $result));
21
-
22
}
23
24
return parent::_beforeSave();
25
-
26
}
27
28
public function validate()
29
{
30
-
31
$errors = array();
32
$helper = Mage::helper('apptrian_imageoptimizer');
33
$value = $this->getValue();
34
$validator = Zend_Validate::is(
35
- $value, 'Regex', array(
36
'pattern'
37
=>'/^[\p{L}\p{N}_,;:!%&#\<\>\=\+\*\$\?\|\'\.\-\ \/]+#x2F;iu'
38
)
@@ -48,7 +44,5 @@ class Apptrian_ImageOptimizer_Model_Config_Options
48
}
49
50
return $errors;
51
-
52
}
53
-
54
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Options
10
extends Mage_Core_Model_Config_Data
11
{
12
public function _beforeSave()
13
{
14
$result = $this->validate();
15
16
if ($result !== true) {
17
Mage::throwException(implode("\n", $result));
18
}
19
20
return parent::_beforeSave();
21
}
22
23
public function validate()
24
{
25
$errors = array();
26
$helper = Mage::helper('apptrian_imageoptimizer');
27
$value = $this->getValue();
28
$validator = Zend_Validate::is(
29
+ $value,
30
+ 'Regex',
31
+ array(
32
'pattern'
33
=>'/^[\p{L}\p{N}_,;:!%&#\<\>\=\+\*\$\?\|\'\.\-\ \/]+#x2F;iu'
34
)
44
}
45
46
return $errors;
47
}
48
}
app/code/community/Apptrian/ImageOptimizer/Model/Config/Path.php CHANGED
@@ -3,36 +3,31 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Path
10
extends Mage_Core_Model_Config_Data
11
{
12
-
13
public function _beforeSave()
14
{
15
-
16
$result = $this->validate();
17
18
if ($result !== true) {
19
-
20
Mage::throwException(implode("\n", $result));
21
-
22
}
23
24
return parent::_beforeSave();
25
-
26
}
27
28
public function validate()
29
{
30
-
31
$errors = array();
32
$helper = Mage::helper('apptrian_imageoptimizer');
33
$value = $this->getValue();
34
$validator = Zend_Validate::is(
35
- $value, 'Regex',
36
array('pattern' => '/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/]+#x2F;iu')
37
);
38
@@ -45,7 +40,5 @@ class Apptrian_ImageOptimizer_Model_Config_Path
45
}
46
47
return $errors;
48
-
49
}
50
-
51
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Path
10
extends Mage_Core_Model_Config_Data
11
{
12
public function _beforeSave()
13
{
14
$result = $this->validate();
15
16
if ($result !== true) {
17
Mage::throwException(implode("\n", $result));
18
}
19
20
return parent::_beforeSave();
21
}
22
23
public function validate()
24
{
25
$errors = array();
26
$helper = Mage::helper('apptrian_imageoptimizer');
27
$value = $this->getValue();
28
$validator = Zend_Validate::is(
29
+ $value,
30
+ 'Regex',
31
array('pattern' => '/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/]+#x2F;iu')
32
);
33
40
}
41
42
return $errors;
43
}
44
}
app/code/community/Apptrian/ImageOptimizer/Model/Config/Paths.php CHANGED
@@ -3,36 +3,31 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Paths
10
extends Mage_Core_Model_Config_Data
11
{
12
-
13
public function _beforeSave()
14
{
15
-
16
$result = $this->validate();
17
18
if ($result !== true) {
19
-
20
Mage::throwException(implode("\n", $result));
21
-
22
}
23
24
return parent::_beforeSave();
25
-
26
}
27
28
public function validate()
29
{
30
-
31
$errors = array();
32
$helper = Mage::helper('apptrian_imageoptimizer');
33
$value = $this->getValue();
34
$validator = Zend_Validate::is(
35
- $value, 'Regex',
36
array('pattern' => '/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/]+#x2F;iu')
37
);
38
@@ -45,7 +40,5 @@ class Apptrian_ImageOptimizer_Model_Config_Paths
45
}
46
47
return $errors;
48
-
49
}
50
-
51
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Paths
10
extends Mage_Core_Model_Config_Data
11
{
12
public function _beforeSave()
13
{
14
$result = $this->validate();
15
16
if ($result !== true) {
17
Mage::throwException(implode("\n", $result));
18
}
19
20
return parent::_beforeSave();
21
}
22
23
public function validate()
24
{
25
$errors = array();
26
$helper = Mage::helper('apptrian_imageoptimizer');
27
$value = $this->getValue();
28
$validator = Zend_Validate::is(
29
+ $value,
30
+ 'Regex',
31
array('pattern' => '/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/]+#x2F;iu')
32
);
33
40
}
41
42
return $errors;
43
}
44
}
app/code/community/Apptrian/ImageOptimizer/Model/Config/Permissions.php CHANGED
@@ -3,36 +3,31 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Permissions
10
extends Mage_Core_Model_Config_Data
11
{
12
-
13
public function _beforeSave()
14
{
15
-
16
$result = $this->validate();
17
18
if ($result !== true) {
19
-
20
Mage::throwException(implode("\n", $result));
21
-
22
}
23
24
return parent::_beforeSave();
25
-
26
}
27
28
public function validate()
29
{
30
-
31
$errors = array();
32
$helper = Mage::helper('apptrian_imageoptimizer');
33
$value = $this->getValue();
34
$validator = Zend_Validate::is(
35
- $value, 'Regex',
36
array('pattern' => '/^[0-7]*#x2F;')
37
);
38
@@ -45,7 +40,5 @@ class Apptrian_ImageOptimizer_Model_Config_Permissions
45
}
46
47
return $errors;
48
-
49
}
50
-
51
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Permissions
10
extends Mage_Core_Model_Config_Data
11
{
12
public function _beforeSave()
13
{
14
$result = $this->validate();
15
16
if ($result !== true) {
17
Mage::throwException(implode("\n", $result));
18
}
19
20
return parent::_beforeSave();
21
}
22
23
public function validate()
24
{
25
$errors = array();
26
$helper = Mage::helper('apptrian_imageoptimizer');
27
$value = $this->getValue();
28
$validator = Zend_Validate::is(
29
+ $value,
30
+ 'Regex',
31
array('pattern' => '/^[0-7]*#x2F;')
32
);
33
40
}
41
42
return $errors;
43
}
44
}
app/code/community/Apptrian/ImageOptimizer/Model/Config/Utility.php CHANGED
@@ -3,36 +3,31 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Utility
10
extends Mage_Core_Model_Config_Data
11
{
12
-
13
public function _beforeSave()
14
{
15
-
16
$result = $this->validate();
17
18
if ($result !== true) {
19
-
20
Mage::throwException(implode("\n", $result));
21
-
22
}
23
24
return parent::_beforeSave();
25
-
26
}
27
28
public function validate()
29
{
30
-
31
$errors = array();
32
$helper = Mage::helper('apptrian_imageoptimizer');
33
$value = $this->getValue();
34
$validator = Zend_Validate::is(
35
- $value, 'Regex',
36
array('pattern' => '/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/]+#x2F;iu')
37
);
38
@@ -46,7 +41,5 @@ class Apptrian_ImageOptimizer_Model_Config_Utility
46
}
47
48
return $errors;
49
-
50
}
51
-
52
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Config_Utility
10
extends Mage_Core_Model_Config_Data
11
{
12
public function _beforeSave()
13
{
14
$result = $this->validate();
15
16
if ($result !== true) {
17
Mage::throwException(implode("\n", $result));
18
}
19
20
return parent::_beforeSave();
21
}
22
23
public function validate()
24
{
25
$errors = array();
26
$helper = Mage::helper('apptrian_imageoptimizer');
27
$value = $this->getValue();
28
$validator = Zend_Validate::is(
29
+ $value,
30
+ 'Regex',
31
array('pattern' => '/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/]+#x2F;iu')
32
);
33
41
}
42
43
return $errors;
44
}
45
}
app/code/community/Apptrian/ImageOptimizer/Model/Cron.php CHANGED
@@ -3,18 +3,16 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Cron
10
{
11
-
12
/**
13
* Cron method for executing scan and reindex process.
14
*/
15
public function scan()
16
{
17
-
18
$helper = Mage::helper('apptrian_imageoptimizer');
19
20
$extensionEnabled = (int) $helper->getConfig(
@@ -26,24 +24,17 @@ class Apptrian_ImageOptimizer_Model_Cron
26
);
27
28
if ($extensionEnabled && $cronJobEnabled) {
29
-
30
try {
31
-
32
$result = $helper->scanAndReindex();
33
34
- if ($result !== true ) {
35
$mPrefix = 'Image Optimizer Cron: Scan and Reindex process';
36
Mage::log($mPrefix . ' failed.');
37
}
38
-
39
} catch (Exception $e) {
40
-
41
Mage::log($e);
42
-
43
}
44
-
45
}
46
-
47
}
48
49
/**
@@ -51,7 +42,6 @@ class Apptrian_ImageOptimizer_Model_Cron
51
*/
52
public function optimize()
53
{
54
-
55
$helper = Mage::helper('apptrian_imageoptimizer');
56
57
$extensionEnabled = (int) $helper->getConfig(
@@ -63,35 +53,23 @@ class Apptrian_ImageOptimizer_Model_Cron
63
);
64
65
if ($extensionEnabled && $cronJobEnabled) {
66
-
67
$mPrefix = 'Image Optimizer Cron: Optimization process ';
68
69
if ($helper->isExecFunctionEnabled()) {
70
-
71
try {
72
-
73
$result = $helper->optimize();
74
75
- if ($result !== true ) {
76
Mage::log($mPrefix . 'failed.');
77
}
78
-
79
} catch (Exception $e) {
80
-
81
Mage::log($e);
82
-
83
}
84
-
85
} else {
86
-
87
Mage::log(
88
$mPrefix . 'failed because PHP exec() function is disabled.'
89
);
90
-
91
}
92
-
93
}
94
-
95
}
96
-
97
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Model_Cron
10
{
11
/**
12
* Cron method for executing scan and reindex process.
13
*/
14
public function scan()
15
{
16
$helper = Mage::helper('apptrian_imageoptimizer');
17
18
$extensionEnabled = (int) $helper->getConfig(
24
);
25
26
if ($extensionEnabled && $cronJobEnabled) {
27
try {
28
$result = $helper->scanAndReindex();
29
30
+ if ($result !== true) {
31
$mPrefix = 'Image Optimizer Cron: Scan and Reindex process';
32
Mage::log($mPrefix . ' failed.');
33
}
34
} catch (Exception $e) {
35
Mage::log($e);
36
}
37
}
38
}
39
40
/**
42
*/
43
public function optimize()
44
{
45
$helper = Mage::helper('apptrian_imageoptimizer');
46
47
$extensionEnabled = (int) $helper->getConfig(
53
);
54
55
if ($extensionEnabled && $cronJobEnabled) {
56
$mPrefix = 'Image Optimizer Cron: Optimization process ';
57
58
if ($helper->isExecFunctionEnabled()) {
59
try {
60
$result = $helper->optimize();
61
62
+ if ($result !== true) {
63
Mage::log($mPrefix . 'failed.');
64
}
65
} catch (Exception $e) {
66
Mage::log($e);
67
}
68
} else {
69
Mage::log(
70
$mPrefix . 'failed because PHP exec() function is disabled.'
71
);
72
}
73
}
74
}
75
}
app/code/community/Apptrian/ImageOptimizer/controllers/Adminhtml/Apptrian/ImgoptController.php CHANGED
@@ -3,7 +3,7 @@
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Adminhtml_Apptrian_ImgoptController
@@ -26,30 +26,26 @@ class Apptrian_ImageOptimizer_Adminhtml_Apptrian_ImgoptController
26
*/
27
public function scanAction()
28
{
29
30
$helper = Mage::helper('apptrian_imageoptimizer');
31
32
try {
33
-
34
$helper->scanAndReindex();
35
36
$message = $this
37
->__('Scan and reindex operations completed successfully.');
38
Mage::getSingleton('adminhtml/session')->addSuccess($message);
39
-
40
} catch (Exception $e) {
41
-
42
$message = $this->__('Scanning and reindexing failed.');
43
Mage::getSingleton('adminhtml/session')->addError($message);
44
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
45
-
46
}
47
48
$url = Mage::helper('adminhtml')->getUrl(
49
'adminhtml/system_config/edit/section/apptrian_imageoptimizer'
50
);
51
Mage::app()->getResponse()->setRedirect($url);
52
-
53
}
54
55
/**
@@ -57,42 +53,34 @@ class Apptrian_ImageOptimizer_Adminhtml_Apptrian_ImgoptController
57
*/
58
public function optimizeAction()
59
{
60
61
$helper = Mage::helper('apptrian_imageoptimizer');
62
63
if ($helper->isExecFunctionEnabled()) {
64
-
65
try {
66
-
67
$helper->optimize();
68
69
$message = $this
70
->__('Optimization operations completed successfully.');
71
Mage::getSingleton('adminhtml/session')->addSuccess($message);
72
-
73
} catch (Exception $e) {
74
-
75
$message = $this->__('Optimization failed.');
76
Mage::getSingleton('adminhtml/session')->addError($message);
77
Mage::getSingleton('adminhtml/session')
78
->addError($e->getMessage());
79
-
80
}
81
-
82
} else {
83
-
84
$message = $this->__(
85
'Optimization failed because PHP exec() function is disabled.'
86
);
87
Mage::getSingleton('adminhtml/session')->addError($message);
88
-
89
}
90
91
$url = Mage::helper('adminhtml')->getUrl(
92
'adminhtml/system_config/edit/section/apptrian_imageoptimizer'
93
);
94
Mage::app()->getResponse()->setRedirect($url);
95
-
96
}
97
98
/**
@@ -100,30 +88,23 @@ class Apptrian_ImageOptimizer_Adminhtml_Apptrian_ImgoptController
100
*/
101
public function clearAction()
102
{
103
-
104
$helper = Mage::helper('apptrian_imageoptimizer');
105
106
try {
107
-
108
$helper->clearIndex();
109
110
$message = $this
111
->__('Clear index operation completed successfully.');
112
Mage::getSingleton('adminhtml/session')->addSuccess($message);
113
-
114
} catch (Exception $e) {
115
-
116
$message = $this->__('Clear index operation failed.');
117
Mage::getSingleton('adminhtml/session')->addError($message);
118
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
119
-
120
}
121
122
$url = Mage::helper('adminhtml')->getUrl(
123
'adminhtml/system_config/edit/section/apptrian_imageoptimizer'
124
);
125
Mage::app()->getResponse()->setRedirect($url);
126
-
127
}
128
-
129
}
3
* @category Apptrian
4
* @package Apptrian_ImageOptimizer
5
* @author Apptrian
6
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
*/
9
class Apptrian_ImageOptimizer_Adminhtml_Apptrian_ImgoptController
26
*/
27
public function scanAction()
28
{
29
+ set_time_limit(18000);
30
31
$helper = Mage::helper('apptrian_imageoptimizer');
32
33
try {
34
$helper->scanAndReindex();
35
36
$message = $this
37
->__('Scan and reindex operations completed successfully.');
38
Mage::getSingleton('adminhtml/session')->addSuccess($message);
39
} catch (Exception $e) {
40
$message = $this->__('Scanning and reindexing failed.');
41
Mage::getSingleton('adminhtml/session')->addError($message);
42
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
43
}
44
45
$url = Mage::helper('adminhtml')->getUrl(
46
'adminhtml/system_config/edit/section/apptrian_imageoptimizer'
47
);
48
Mage::app()->getResponse()->setRedirect($url);
49
}
50
51
/**
53
*/
54
public function optimizeAction()
55
{
56
+ set_time_limit(18000);
57
58
$helper = Mage::helper('apptrian_imageoptimizer');
59
60
if ($helper->isExecFunctionEnabled()) {
61
try {
62
$helper->optimize();
63
64
$message = $this
65
->__('Optimization operations completed successfully.');
66
Mage::getSingleton('adminhtml/session')->addSuccess($message);
67
} catch (Exception $e) {
68
$message = $this->__('Optimization failed.');
69
Mage::getSingleton('adminhtml/session')->addError($message);
70
Mage::getSingleton('adminhtml/session')
71
->addError($e->getMessage());
72
}
73
} else {
74
$message = $this->__(
75
'Optimization failed because PHP exec() function is disabled.'
76
);
77
Mage::getSingleton('adminhtml/session')->addError($message);
78
}
79
80
$url = Mage::helper('adminhtml')->getUrl(
81
'adminhtml/system_config/edit/section/apptrian_imageoptimizer'
82
);
83
Mage::app()->getResponse()->setRedirect($url);
84
}
85
86
/**
88
*/
89
public function clearAction()
90
{
91
$helper = Mage::helper('apptrian_imageoptimizer');
92
93
try {
94
$helper->clearIndex();
95
96
$message = $this
97
->__('Clear index operation completed successfully.');
98
Mage::getSingleton('adminhtml/session')->addSuccess($message);
99
} catch (Exception $e) {
100
$message = $this->__('Clear index operation failed.');
101
Mage::getSingleton('adminhtml/session')->addError($message);
102
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
103
}
104
105
$url = Mage::helper('adminhtml')->getUrl(
106
'adminhtml/system_config/edit/section/apptrian_imageoptimizer'
107
);
108
Mage::app()->getResponse()->setRedirect($url);
109
}
110
}
app/code/community/Apptrian/ImageOptimizer/etc/config.xml CHANGED
@@ -4,14 +4,14 @@
4
* @category Apptrian
5
* @package Apptrian_ImageOptimizer
6
* @author Apptrian
7
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
8
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
9
*/
10
-->
11
<config>
12
<modules>
13
<Apptrian_ImageOptimizer>
14
- <version>2.1.0</version>
15
</Apptrian_ImageOptimizer>
16
</modules>
17
<global>
@@ -58,7 +58,7 @@
58
<use64bit>0</use64bit>
59
<log_output>0</log_output>
60
<permissions></permissions>
61
- <path>lib/apptrian/imageoptimizer</path>
62
<gif>gifsicle</gif>
63
<gif_path></gif_path>
64
<gif_options>-b -O3 %filepath%</gif_options>
@@ -129,7 +129,6 @@
129
<model>apptrian_imageoptimizer/cron::scan</model>
130
</run>
131
</apptrian_imageoptimizer_scan>
132
-
133
<apptrian_imageoptimizer_optimize>
134
<run>
135
<model>apptrian_imageoptimizer/cron::optimize</model>
4
* @category Apptrian
5
* @package Apptrian_ImageOptimizer
6
* @author Apptrian
7
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
8
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
9
*/
10
-->
11
<config>
12
<modules>
13
<Apptrian_ImageOptimizer>
14
+ <version>2.2.0</version>
15
</Apptrian_ImageOptimizer>
16
</modules>
17
<global>
58
<use64bit>0</use64bit>
59
<log_output>0</log_output>
60
<permissions></permissions>
61
+ <path>lib/Apptrian/ImageOptimizer</path>
62
<gif>gifsicle</gif>
63
<gif_path></gif_path>
64
<gif_options>-b -O3 %filepath%</gif_options>
129
<model>apptrian_imageoptimizer/cron::scan</model>
130
</run>
131
</apptrian_imageoptimizer_scan>
132
<apptrian_imageoptimizer_optimize>
133
<run>
134
<model>apptrian_imageoptimizer/cron::optimize</model>
app/code/community/Apptrian/ImageOptimizer/etc/system.xml CHANGED
@@ -4,7 +4,7 @@
4
* @category Apptrian
5
* @package Apptrian_ImageOptimizer
6
* @author Apptrian
7
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
8
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
9
*/
10
-->
@@ -160,7 +160,7 @@
160
<show_in_default>1</show_in_default>
161
<show_in_website>0</show_in_website>
162
<show_in_store>0</show_in_store>
163
- <tooltip><![CDATA[Every time you click "Start Optimization Process" (or cron job executes) depending on "Batch Size" value and number of indexed files, progress bar will move.<br />If progress bar does not move most likely reason is file permissions.<br /><strong>Utility binaries located in lib/apptrian/imageoptimizer must be executable which means you have to set right permissions on files inside this directory.</strong><br />If you are getting less than 100% despite you clicked "Start Optimization Process" button more than several times and the percentage is stuck to same value that means some of your files are corrupt. To find out which files are corrupt in "Utility" section for "Log Utility Output" select "Yes". Refresh your cache and click "Start Optimization Process" button again. After it is done you will find a list of corrupt files in<br />var/log/apptrian_imageoptimizer.log<br />You can inspect the log and fix the files yourself. Do not forget to set "Log Utility Output" back to "No".]]></tooltip>
164
<depends>
165
<enabled>1</enabled>
166
</depends>
4
* @category Apptrian
5
* @package Apptrian_ImageOptimizer
6
* @author Apptrian
7
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
8
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
9
*/
10
-->
160
<show_in_default>1</show_in_default>
161
<show_in_website>0</show_in_website>
162
<show_in_store>0</show_in_store>
163
+ <tooltip><![CDATA[Every time you click "Start Optimization Process" (or cron job executes) depending on "Batch Size" value and number of indexed files, progress bar will move.<br />If progress bar does not move most likely reason is file permissions.<br /><strong>Utility binaries located in lib/Apptrian/ImageOptimizer must be executable which means you have to set right permissions on files inside this directory.</strong><br />If you are getting less than 100% despite you clicked "Start Optimization Process" button more than several times and the percentage is stuck to same value that means some of your files are corrupt. To find out which files are corrupt in "Utility" section for "Log Utility Output" select "Yes". Refresh your cache and click "Start Optimization Process" button again. After it is done you will find a list of corrupt files in<br />var/log/apptrian_imageoptimizer.log<br />You can inspect the log and fix the files yourself. Do not forget to set "Log Utility Output" back to "No".]]></tooltip>
164
<depends>
165
<enabled>1</enabled>
166
</depends>
app/design/adminhtml/default/default/layout/apptrian_imageoptimizer.xml CHANGED
@@ -4,7 +4,7 @@
4
* @category Apptrian
5
* @package Apptrian_ImageOptimizer
6
* @author Apptrian
7
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
8
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
9
*/
10
-->
4
* @category Apptrian
5
* @package Apptrian_ImageOptimizer
6
* @author Apptrian
7
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)
8
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
9
*/
10
-->
app/etc/modules/Apptrian_ImageOptimizer.xml CHANGED
@@ -4,7 +4,7 @@
4
* @category Apptrian
5
* @package Apptrian_ImageOptimizer
6
* @author Apptrian
7
- * @copyright Copyright (c) 2016 Apptrian (http://www.apptrian.com)
8
* @license http://opensource.org/licenses/osl-3.0.php Open Software License
9
*/
10
-->
4
* @category Apptrian
5
* @package Apptrian_ImageOptimizer
6
* @author Apptrian
7
+ * @copyright Copyright (c) 2017 Apptrian (http://www.apptrian.com)