Apptrian_Image_Optimizer - Version 2.0.0

Version Notes

* Complete rewrite from the ground up
* Code standards improvements
* Fixed few small issues with admin blocks
* Empty Index is renamed to Clear Index including all block and methods
+ Added separate cron jobs, one for scanning one for optimization
+ Added option to force file permissions after optimization

Download this release

Release Info

Developer Apptrian
Extension Apptrian_Image_Optimizer
Version 2.0.0
Comparing to
See all releases


Code changes from version 1.3.0 to 2.0.0

Files changed (34) hide show
  1. app/code/community/Apptrian/ImageOptimizer/Block/About.php +0 -43
  2. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/About.php +50 -0
  3. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Clear.php +45 -0
  4. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Empty.php +0 -35
  5. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Optimize.php +46 -41
  6. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Scan.php +46 -41
  7. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Info.php +101 -0
  8. app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Stats.php +47 -40
  9. app/code/community/Apptrian/ImageOptimizer/Block/Info.php +0 -70
  10. app/code/community/Apptrian/ImageOptimizer/Helper/Data.php +536 -307
  11. app/code/community/Apptrian/ImageOptimizer/Helper/Utility.php +0 -149
  12. app/code/community/Apptrian/ImageOptimizer/Model/Config/Batchsize.php +51 -50
  13. app/code/community/Apptrian/ImageOptimizer/Model/Config/Cron.php +0 -68
  14. app/code/community/Apptrian/ImageOptimizer/Model/Config/Cron/Optimize.php +75 -0
  15. app/code/community/Apptrian/ImageOptimizer/Model/Config/Cron/Scan.php +75 -0
  16. app/code/community/Apptrian/ImageOptimizer/Model/Config/Exactpath.php +54 -46
  17. app/code/community/Apptrian/ImageOptimizer/Model/Config/Options.php +54 -46
  18. app/code/community/Apptrian/ImageOptimizer/Model/Config/Path.php +51 -46
  19. app/code/community/Apptrian/ImageOptimizer/Model/Config/Paths.php +51 -46
  20. app/code/community/Apptrian/ImageOptimizer/Model/Config/Permissions.php +51 -0
  21. app/code/community/Apptrian/ImageOptimizer/Model/Config/Utility.php +52 -46
  22. app/code/community/Apptrian/ImageOptimizer/Model/Cron.php +97 -105
  23. app/code/community/Apptrian/ImageOptimizer/Model/File.php +17 -17
  24. app/code/community/Apptrian/ImageOptimizer/Model/Resource/File.php +264 -256
  25. app/code/community/Apptrian/ImageOptimizer/Model/Resource/File/Collection.php +18 -17
  26. app/code/community/Apptrian/ImageOptimizer/controllers/Adminhtml/Apptrian/ImgoptController.php +125 -92
  27. app/code/community/Apptrian/ImageOptimizer/etc/config.xml +159 -155
  28. app/code/community/Apptrian/ImageOptimizer/etc/system.xml +421 -379
  29. app/code/community/Apptrian/ImageOptimizer/sql/apptrian_imageoptimizer_setup/install-1.0.0.php +31 -22
  30. app/design/adminhtml/default/default/layout/apptrian_imageoptimizer.xml +20 -20
  31. app/etc/modules/Apptrian_ImageOptimizer.xml +21 -21
  32. app/locale/en_US/Apptrian_ImageOptimizer.csv +18 -8
  33. package.xml +12 -10
  34. skin/adminhtml/default/default/css/apptrian_imageoptimizer.css +19 -19
app/code/community/Apptrian/ImageOptimizer/Block/About.php DELETED
@@ -1,43 +0,0 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Block_About
10
- extends Mage_Adminhtml_Block_Abstract
11
- implements Varien_Data_Form_Element_Renderer_Interface
12
- {
13
-
14
- /**
15
- * Render fieldset html
16
- *
17
- * @param Varien_Data_Form_Element_Abstract $element
18
- * @return string
19
- */
20
- public function render(Varien_Data_Form_Element_Abstract $element)
21
- {
22
- $version = Mage::helper('apptrian_imageoptimizer')->getExtensionVersion();
23
- $logopath = 'http://www.apptrian.com/media/apptrian.gif';
24
- $html = <<<HTML
25
- <div style="background:url('$logopath') no-repeat scroll 15px 15px #e7efef; border:1px solid #ccc; min-height:100px; margin:5px 0; padding:15px 15px 15px 140px;">
26
- <p>
27
- <strong>Apptrian Image Optimizer Extension v$version</strong><br />
28
- Optimize your images, reduce their file size without losing image quality and speed up your site.
29
- </p>
30
- <p>
31
- Website: <a href="http://www.apptrian.com" target="_blank">www.apptrian.com</a><br />
32
- Like, share and follow us on
33
- <a href="https://www.facebook.com/apptrian" target="_blank">Facebook</a>,
34
- <a href="https://plus.google.com/+ApptrianCom" target="_blank">Google+</a>,
35
- <a href="http://www.pinterest.com/apptrian" target="_blank">Pinterest</a>, and
36
- <a href="http://twitter.com/apptrian" target="_blank">Twitter</a>.<br />
37
- If you have any questions send email at <a href="mailto:service@apptrian.com">service@apptrian.com</a>.
38
- </p>
39
- </div>
40
- HTML;
41
- return $html;
42
- }
43
- }
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/About.php ADDED
@@ -0,0 +1,50 @@
1
+ <?php
2
+ /**
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
10
+ extends Mage_Adminhtml_Block_Abstract
11
+ implements Varien_Data_Form_Element_Renderer_Interface
12
+ {
13
+
14
+ /**
15
+ * Render fieldset html
16
+ *
17
+ * @param Varien_Data_Form_Element_Abstract $element
18
+ * @return string
19
+ */
20
+ public function render(Varien_Data_Form_Element_Abstract $element)
21
+ {
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;
29
+ padding:15px 15px 15px 140px;">
30
+ <p>
31
+ <strong>Apptrian Image Optimizer Extension v$version</strong><br />
32
+ Optimize your images, reduce their file size without losing image quality and
33
+ 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>
46
+ </div>
47
+ HTML;
48
+ return $html;
49
+ }
50
+ }
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Clear.php ADDED
@@ -0,0 +1,45 @@
1
+ <?php
2
+ /**
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
10
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
11
+ {
12
+ /**
13
+ * Retrieve element HTML markup
14
+ *
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return string
17
+ */
18
+ protected function _getElementHtml(
19
+ Varien_Data_Form_Element_Abstract $element
20
+ )
21
+ {
22
+ $element = null;
23
+
24
+ $buttonLabel = Mage::helper('apptrian_imageoptimizer')
25
+ ->__('Clear Index');
26
+
27
+ $url = Mage::helper('adminhtml')->getUrl(
28
+ 'adminhtml/apptrian_imgopt/clear'
29
+ );
30
+
31
+ $confirmText = Mage::helper('apptrian_imageoptimizer')
32
+ ->__('Are you sure you want to do this?');
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
+ }
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Empty.php DELETED
@@ -1,35 +0,0 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Empty extends Mage_Adminhtml_Block_System_Config_Form_Field
10
- {
11
- /**
12
- * Import static blocks
13
- *
14
- * @param Varien_Data_Form_Element_Abstract $element
15
- * @return String
16
- */
17
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
18
- {
19
-
20
- $buttonLabel = Mage::helper('apptrian_imageoptimizer')->__('Empty Index');
21
-
22
- $url = Mage::helper('adminhtml')->getUrl(
23
- 'adminhtml/apptrian_imgopt/empty');
24
-
25
- $html = $this->getLayout()->createBlock('adminhtml/widget_button')
26
- ->setType('button')
27
- ->setClass('apptrian-imageoptimizer-admin-button-empty')
28
- ->setLabel($buttonLabel)
29
- ->setOnClick("setLocation('$url')")
30
- ->toHtml();
31
-
32
- return $html;
33
-
34
- }
35
- }
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Optimize.php CHANGED
@@ -1,41 +1,46 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Optimize extends Mage_Adminhtml_Block_System_Config_Form_Field
10
- {
11
- /**
12
- * Import static blocks
13
- *
14
- * @param Varien_Data_Form_Element_Abstract $element
15
- * @return String
16
- */
17
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
18
- {
19
-
20
- $elementOriginalData = $element->getOriginalData();
21
-
22
- if (isset($elementOriginalData['label'])) {
23
- $buttonLabel = $elementOriginalData['label'];
24
- } else {
25
- return '<div>Button label was not specified</div>';
26
- }
27
-
28
- $url = Mage::helper('adminhtml')->getUrl(
29
- 'adminhtml/apptrian_imgopt/optimize');
30
-
31
- $html = $this->getLayout()->createBlock('adminhtml/widget_button')
32
- ->setType('button')
33
- ->setClass('apptrian-imageoptimizer-admin-button-optimize')
34
- ->setLabel($buttonLabel)
35
- ->setOnClick("setLocation('$url')")
36
- ->toHtml();
37
-
38
- return $html;
39
-
40
- }
41
- }
1
+ <?php
2
+ /**
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
10
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
11
+ {
12
+ /**
13
+ * Retrieve element HTML markup
14
+ *
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return string
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'])) {
26
+ $buttonLabel = $elementOriginalData['label'];
27
+ } else {
28
+ return '<div>Button label was not specified</div>';
29
+ }
30
+
31
+ $url = Mage::helper('adminhtml')->getUrl(
32
+ 'adminhtml/apptrian_imgopt/optimize'
33
+ );
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
+ }
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Button/Scan.php CHANGED
@@ -1,41 +1,46 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Block_Adminhtml_Button_Scan extends Mage_Adminhtml_Block_System_Config_Form_Field
10
- {
11
- /**
12
- * Import static blocks
13
- *
14
- * @param Varien_Data_Form_Element_Abstract $element
15
- * @return String
16
- */
17
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
18
- {
19
-
20
- $elementOriginalData = $element->getOriginalData();
21
-
22
- if (isset($elementOriginalData['label'])) {
23
- $buttonLabel = $elementOriginalData['label'];
24
- } else {
25
- return '<div>Button label was not specified</div>';
26
- }
27
-
28
- $url = Mage::helper('adminhtml')->getUrl(
29
- 'adminhtml/apptrian_imgopt/scan');
30
-
31
- $html = $this->getLayout()->createBlock('adminhtml/widget_button')
32
- ->setType('button')
33
- ->setClass('apptrian-imageoptimizer-admin-button-scan')
34
- ->setLabel($buttonLabel)
35
- ->setOnClick("setLocation('$url')")
36
- ->toHtml();
37
-
38
- return $html;
39
-
40
- }
41
- }
1
+ <?php
2
+ /**
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
10
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
11
+ {
12
+ /**
13
+ * Retrieve element HTML markup
14
+ *
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return string
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'])) {
26
+ $buttonLabel = $elementOriginalData['label'];
27
+ } else {
28
+ return '<div>Button label was not specified</div>';
29
+ }
30
+
31
+ $url = Mage::helper('adminhtml')->getUrl(
32
+ 'adminhtml/apptrian_imgopt/scan'
33
+ );
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
+ }
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Info.php ADDED
@@ -0,0 +1,101 @@
1
+ <?php
2
+ /**
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
10
+ extends Mage_Adminhtml_Block_Abstract
11
+ implements Varien_Data_Form_Element_Renderer_Interface
12
+ {
13
+
14
+ /**
15
+ * Render fieldset html
16
+ *
17
+ * @param Varien_Data_Form_Element_Abstract $element
18
+ * @return string
19
+ */
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>
98
+ HTML;
99
+ return $html;
100
+ }
101
+ }
app/code/community/Apptrian/ImageOptimizer/Block/Adminhtml/Stats.php CHANGED
@@ -1,40 +1,47 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Block_Adminhtml_Stats extends Mage_Adminhtml_Block_System_Config_Form_Field
10
- {
11
- /**
12
- * Import static blocks
13
- *
14
- * @param Varien_Data_Form_Element_Abstract $element
15
- * @return String
16
- */
17
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
18
- {
19
-
20
- $r = Mage::getResourceModel('apptrian_imageoptimizer/file');
21
-
22
- $indexed = $r->getFileCount();
23
- $optimized = $r->getFileCount(1);
24
-
25
- // Fix for division by zero possibility
26
- if ($indexed == 0) {
27
- $percent = 0;
28
- } else {
29
- $percent = round((100 * $optimized) / $indexed, 2);
30
- }
31
-
32
- $html = '<div class="apptrian-imageoptimizer-bar-wrapper"><div class="apptrian-imageoptimizer-bar-outer">
33
- <div class="apptrian-imageoptimizer-bar-inner" style="width:' . $percent .'%;"></div>
34
- <div class="apptrian-imageoptimizer-bar-text"><span>' . $percent . '% ' . Mage::helper('apptrian_imageoptimizer')->__('(%s of %s files)', $optimized, $indexed) . '</span></div>
35
- </div></div>';
36
-
37
- return $html;
38
-
39
- }
40
- }
1
+ <?php
2
+ /**
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
10
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
11
+ {
12
+ /**
13
+ * Retrieve element HTML markup.
14
+ *
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return string
17
+ */
18
+ protected function _getElementHtml(
19
+ Varien_Data_Form_Element_Abstract $element
20
+ )
21
+ {
22
+ $element = null;
23
+ $r = Mage::getResourceModel('apptrian_imageoptimizer/file');
24
+
25
+ $indexed = $r->getFileCount();
26
+ $optimized = $r->getFileCount(1);
27
+
28
+ // Fix for division by zero possibility
29
+ if ($indexed == 0) {
30
+ $percent = 0;
31
+ } else {
32
+ $percent = round((100 * $optimized) / $indexed, 2);
33
+ }
34
+
35
+ $html = '<div class="apptrian-imageoptimizer-bar-wrapper">
36
+ <div class="apptrian-imageoptimizer-bar-outer">
37
+ <div class="apptrian-imageoptimizer-bar-inner" style="width:'
38
+ . $percent .'%;"></div>
39
+ <div class="apptrian-imageoptimizer-bar-text"><span>' . $percent . '% '
40
+ . Mage::helper('apptrian_imageoptimizer')
41
+ ->__('(%s of %s files)', $optimized, $indexed) . '</span></div>
42
+ </div></div>';
43
+
44
+ return $html;
45
+
46
+ }
47
+ }
app/code/community/Apptrian/ImageOptimizer/Block/Info.php DELETED
@@ -1,70 +0,0 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Block_Info
10
- extends Mage_Adminhtml_Block_Abstract
11
- implements Varien_Data_Form_Element_Renderer_Interface
12
- {
13
-
14
- /**
15
- * Render fieldset html
16
- *
17
- * @param Varien_Data_Form_Element_Abstract $element
18
- * @return string
19
- */
20
- public function render(Varien_Data_Form_Element_Abstract $element)
21
- {
22
-
23
- $logopath = 'http://www.apptrian.com/media/apptrian.gif';
24
- $html = <<<HTML
25
- <div style="background:url('$logopath') no-repeat scroll 15px 15px #e7efef; border:1px solid #ccc; min-height:100px; margin:5px 0; padding:15px 15px 15px 140px;">
26
- <p>
27
- <strong>Magento Online Stores &amp; Extensions</strong><br />
28
- <a href="http://www.apptrian.com" target="_blank">Apptrian</a> offers a wide choice of products and services for your online business.
29
- </p>
30
- <p>
31
- Website: <a href="http://www.apptrian.com" target="_blank">www.apptrian.com</a><br />
32
- Like, share and follow us on
33
- <a href="https://www.facebook.com/apptrian" target="_blank">Facebook</a>,
34
- <a href="https://plus.google.com/+ApptrianCom" target="_blank">Google+</a>,
35
- <a href="http://www.pinterest.com/apptrian" target="_blank">Pinterest</a>, and
36
- <a href="http://twitter.com/apptrian" target="_blank">Twitter</a>.<br />
37
- If you have any questions send email at <a href="mailto:service@apptrian.com">service@apptrian.com</a>.
38
- </p>
39
- </div>
40
- <div>
41
- <p><strong>Products and services you might be interested in:</strong></p>
42
- <a href="http://www.apptrian.com/image-optimizer-for-magento" target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
43
- <img src="http://www.apptrian.com/media/apptrian-promotional/image-optimizer-for-magento.jpg" alt="Image Optimizer for Magento" style="border:1px solid #ccc;" />
44
- </a>
45
- <a href="http://www.apptrian.com/minify-html-css-js-for-magento" target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
46
- <img src="http://www.apptrian.com/media/apptrian-promotional/minify-html-css-js-for-magento.jpg" alt="Minify HTML CSS JS for Magento" style="border:1px solid #ccc;" />
47
- </a>
48
- <a href="http://www.apptrian.com/professional-magento-installation" target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
49
- <img src="http://www.apptrian.com/media/apptrian-promotional/professional-magento-installation.jpg" alt="Professional Magento Installation" style="border:1px solid #ccc;" />
50
- </a>
51
- <a href="http://www.apptrian.com/quick-search-for-magento" target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
52
- <img src="http://www.apptrian.com/media/apptrian-promotional/quick-search-for-magento.jpg" alt="Quick Search for Magento" style="border:1px solid #ccc;" />
53
- </a>
54
- <a href="http://www.apptrian.com/responsive-product-slider-for-magento" target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
55
- <img src="http://www.apptrian.com/media/apptrian-promotional/responsive-product-slider-for-magento.jpg" alt="Responsive Product Slider for Magento" style="border:1px solid #ccc;" />
56
- </a>
57
- <a href="http://www.apptrian.com/schema-org-microdata-for-magento" target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
58
- <img src="http://www.apptrian.com/media/apptrian-promotional/schema-org-microdata-for-magento.jpg" alt="Schema.org Microdata for Magento" style="border:1px solid #ccc;" />
59
- </a>
60
- <a href="http://www.apptrian.com/social-integrator-for-magento" target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
61
- <img src="http://www.apptrian.com/media/apptrian-promotional/social-integrator-for-magento.jpg" alt="Social Integrator" style="border:1px solid #ccc;" />
62
- </a>
63
- <a href="http://www.apptrian.com/subcategories-grid-list-for-magento" target="_blank" style="margin: 0 15px 15px 0; display: inline-block;">
64
- <img src="http://www.apptrian.com/media/apptrian-promotional/subcategories-grid-list-for-magento.jpg" alt="Subcategories Grid/List" style="border:1px solid #ccc;" />
65
- </a>
66
- </div>
67
- HTML;
68
- return $html;
69
- }
70
- }
app/code/community/Apptrian/ImageOptimizer/Helper/Data.php CHANGED
@@ -1,307 +1,536 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
10
- {
11
- /**
12
- * Logging flag.
13
- *
14
- * @var null|int
15
- */
16
- protected $logging = null;
17
-
18
- /**
19
- * Returns extension version.
20
- *
21
- * @return string
22
- */
23
- public function getExtensionVersion()
24
- {
25
- return (string) Mage::getConfig()->getNode()->modules->Apptrian_ImageOptimizer->version;
26
- }
27
-
28
- /**
29
- * Checks if exec() function is enabled in php and suhosin config.
30
- *
31
- * @return boolean
32
- */
33
- public function isExecFunctionEnabled()
34
- {
35
- $r = false;
36
-
37
- // PHP disabled functions
38
- $phpDisabledFunctions = array_map('strtolower', array_map('trim', explode(',', ini_get('disable_functions'))));
39
- // Suhosin disabled functions
40
- $suhosinDisabledFunctions = array_map('strtolower', array_map('trim', explode(',', ini_get('suhosin.executor.func.blacklist'))));
41
-
42
- $disabledFunctions = array_merge($phpDisabledFunctions, $suhosinDisabledFunctions);
43
-
44
- $disabled = false;
45
-
46
- if (in_array('exec', $disabledFunctions)) {
47
- $disabled = true;
48
- }
49
-
50
- if(function_exists('exec') === true && $disabled === false) {
51
- $r = true;
52
- }
53
-
54
- return $r;
55
- }
56
-
57
- /**
58
- * Optimized way of getting logging flag from config.
59
- *
60
- * @return int
61
- */
62
- public function isLoggingEnabled()
63
- {
64
- if ($this->logging === null) {
65
-
66
- $this->logging = (int) Mage::getConfig()->getNode('apptrian_imageoptimizer/utility/log_output', 'default');
67
-
68
- }
69
-
70
- return $this->logging;
71
- }
72
-
73
- /**
74
- * Based on config returns array of all paths that will be scaned for images.
75
- *
76
- * @return array
77
- */
78
- public function getPaths()
79
- {
80
-
81
- $paths = array();
82
-
83
- $pathsString = trim(trim(Mage::getConfig()->getNode('apptrian_imageoptimizer/general/paths', 'default'), ';'));
84
-
85
- $rawPaths = explode(';', $pathsString);
86
-
87
- foreach ($rawPaths as $p) {
88
-
89
- $trimmed = trim(trim($p), '/');
90
-
91
- $dirs = explode('/', $trimmed);
92
-
93
- $paths[] = implode(DS, $dirs);
94
-
95
- }
96
-
97
- return array_unique($paths);
98
-
99
- }
100
-
101
- /**
102
- * Optimizes single file.
103
- *
104
- * @param string $filePath
105
- * @return boolean
106
- */
107
- public function optimizeFile($filePath)
108
- {
109
-
110
- $info = pathinfo($filePath);
111
-
112
- $output = array();
113
-
114
- switch (strtolower($info['extension'])) {
115
- case 'jpg':
116
- case 'jpeg':
117
- exec(Mage::helper('apptrian_imageoptimizer/utility')->getJpgUtil($filePath), $output, $return_var);
118
- $type = 'jpg';
119
- break;
120
- case 'png':
121
- exec(Mage::helper('apptrian_imageoptimizer/utility')->getPngUtil($filePath), $output, $return_var);
122
- $type = 'png';
123
- break;
124
- case 'gif':
125
- exec(Mage::helper('apptrian_imageoptimizer/utility')->getGifUtil($filePath), $output, $return_var);
126
- $type = 'gif';
127
- break;
128
- }
129
-
130
- if ($return_var == 126) {
131
-
132
- $error = Mage::getConfig()->getNode('apptrian_imageoptimizer/utility/' . $type, 'default') . ' is not executable.';
133
-
134
- Mage::log($error, null, 'apptrian_imageoptimizer.log');
135
-
136
- return false;
137
-
138
- } else {
139
-
140
- if ($this->isLoggingEnabled()) {
141
-
142
- Mage::log($filePath, null, 'apptrian_imageoptimizer.log');
143
- Mage::log($output, null, 'apptrian_imageoptimizer.log');
144
-
145
- }
146
-
147
- return true;
148
-
149
- }
150
-
151
- }
152
-
153
- /**
154
- * Optimization process.
155
- *
156
- * @return boolean
157
- */
158
- public function optimize()
159
- {
160
- // Get Batch Size
161
- $batchSize = Mage::getConfig()->getNode('apptrian_imageoptimizer/general/batch_size', 'default');
162
-
163
- // Get Collection of files for optimization but limited by batch size
164
- $collection = Mage::getModel('apptrian_imageoptimizer/file')
165
- ->getCollection()
166
- ->addFieldToSelect(array('id', 'file_path'))
167
- ->addFieldToFilter('optimized', array('eq' => 0))
168
- ->setPageSize($batchSize)
169
- ->load();
170
-
171
- $toUpdate = array();
172
- $toDelete = array();
173
- $oldFileSize = 0;
174
-
175
- foreach ($collection as $item) {
176
-
177
- $id = $item->getId();
178
- $fPath = $item->getFilePath();
179
-
180
- $filePath = realpath($fPath);
181
-
182
- // If image exists, optimize else remove it from database
183
- if (file_exists($filePath)) {
184
-
185
- $oldFileSize = filesize($filePath);
186
-
187
- if ($this->optimizeFile($filePath)) {
188
-
189
- $toUpdate[$id]['file_path'] = $fPath;
190
- $toUpdate[$id]['old_file_size'] = $oldFileSize;
191
- $toUpdate[$id]['optimized'] = 1;
192
-
193
- }
194
-
195
- } else {
196
-
197
- $toDelete[] = $id;
198
-
199
- }
200
-
201
- }
202
-
203
- // Itereate over $toUpdate array and set modified time and new_file_size
204
- // (mtime etc) takes a split second to update
205
- foreach ($toUpdate as $i => $f) {
206
-
207
- $filePath = realpath($f['file_path']);
208
-
209
- if (file_exists($filePath)) {
210
- $toUpdate[$i]['new_file_size'] = filesize($filePath);
211
- $toUpdate[$i]['optimization_time'] = filemtime($filePath);
212
- }
213
-
214
- }
215
-
216
- $resource = Mage::getResourceModel('apptrian_imageoptimizer/file');
217
-
218
- $result1 = $resource->deleteFiles($toDelete);
219
- $result2 = $resource->updateFiles($toUpdate);
220
-
221
- if ($result1 === true && $result2 === true) {
222
- return true;
223
- } else {
224
- return false;
225
- }
226
-
227
- }
228
-
229
- /**
230
- * Scan and reindex process.
231
- *
232
- * @return boolean
233
- */
234
- public function scanAndReindex()
235
- {
236
-
237
- $collection = Mage::getModel('apptrian_imageoptimizer/file')
238
- ->getCollection()
239
- ->addFieldToSelect(array('id', 'file_path', 'optimization_time'))
240
- ->load();
241
-
242
- $inIndex = array();
243
- $toAdd = array();
244
- $toUpdate = array();
245
- $toDelete = array();
246
- $id = 0;
247
- $filePath = '';
248
-
249
- foreach ($collection as $item) {
250
-
251
- $id = $item->getId();
252
-
253
- $inIndex[$id] = 0;
254
-
255
- $filePath = realpath($item->getFilePath());
256
-
257
- if (file_exists($filePath)) {
258
- if (filemtime($filePath) != $item->getOptimizationTime()) {
259
- $toUpdate[] = $id;
260
- }
261
- } else {
262
- $toDelete[] = $id;
263
- }
264
-
265
- }
266
-
267
-
268
- $files = array();
269
- $paths = $this->getPaths();
270
-
271
- foreach ($paths as $path) {
272
-
273
- $iterator = new RecursiveIteratorIterator(
274
- new RecursiveDirectoryIterator(Mage::getBaseDir() . DS . $path, RecursiveDirectoryIterator::FOLLOW_SYMLINKS));
275
-
276
- foreach ( $iterator as $filename => $file ) {
277
- if ($file->isFile() && preg_match( '/^.+\.(jpe?g|gif|png)#x2F;i', $file->getFilename())) {
278
- $filePath = $file->getRealPath();
279
- if (!is_writable($filePath)) {
280
- continue;
281
- }
282
-
283
- $files[md5($filePath)] = $filePath;
284
-
285
- }
286
- }
287
-
288
- }
289
-
290
-
291
- $toAdd = array_diff_key($files, $inIndex);
292
-
293
- $resource = Mage::getResourceModel('apptrian_imageoptimizer/file');
294
-
295
- $result1 = $resource->deleteFiles($toDelete);
296
- $result2 = $resource->updateFilesOptimizedField($toUpdate);
297
- $result3 = $resource->addFiles($toAdd);
298
-
299
- if ($result1 === true && $result2 === true && $result3 === true) {
300
- return true;
301
- } else {
302
- return false;
303
- }
304
-
305
- }
306
-
307
- }
1
+ <?php
2
+ /**
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
10
+ {
11
+
12
+ /**
13
+ * Magento Root full path.
14
+ *
15
+ * @var null|string
16
+ */
17
+ protected $_baseDir = null;
18
+
19
+ /**
20
+ * Logging flag.
21
+ *
22
+ * @var null|int
23
+ */
24
+ protected $_logging = null;
25
+
26
+ /**
27
+ * Path to utilities.
28
+ *
29
+ * @var null|string
30
+ */
31
+ protected $_utilPath = null;
32
+
33
+ /**
34
+ * extension (for win binaries)
35
+ *
36
+ * @var null|string
37
+ */
38
+ protected $_utilExt = null;
39
+
40
+ /**
41
+ * Returns extension version.
42
+ *
43
+ * @return string
44
+ */
45
+ public function getExtensionVersion()
46
+ {
47
+ return (string) Mage::getConfig()->getNode()
48
+ ->modules->Apptrian_ImageOptimizer->version;
49
+ }
50
+
51
+ /**
52
+ * Based on provided configuration path returns configuration value.
53
+ *
54
+ * @param string $configPath
55
+ * @return string
56
+ */
57
+ public function getConfig($configPath)
58
+ {
59
+ return Mage::getConfig()->getNode($configPath, 'default');
60
+ }
61
+
62
+ /**
63
+ * Returns Magento Root full path.
64
+ *
65
+ * @return string
66
+ */
67
+ public function getBaseDir()
68
+ {
69
+
70
+ if ($this->_baseDir === null) {
71
+
72
+ $this->_baseDir = Mage::getBaseDir();
73
+
74
+ }
75
+
76
+ return $this->_baseDir;
77
+
78
+ }
79
+
80
+ /**
81
+ * Checks if exec() function is enabled in php and suhosin config.
82
+ *
83
+ * @return boolean
84
+ */
85
+ public function isExecFunctionEnabled()
86
+ {
87
+ $r = false;
88
+
89
+ // PHP disabled functions
90
+ $phpDisabledFunctions = array_map(
91
+ 'strtolower',
92
+ array_map('trim', explode(',', ini_get('disable_functions')))
93
+ );
94
+
95
+ // Suhosin disabled functions
96
+ $suhosinDisabledFunctions = array_map(
97
+ 'strtolower',
98
+ array_map(
99
+ 'trim', explode(',', ini_get('suhosin.executor.func.blacklist'))
100
+ )
101
+ );
102
+
103
+ $disabledFunctions = array_merge(
104
+ $phpDisabledFunctions, $suhosinDisabledFunctions
105
+ );
106
+
107
+ $disabled = false;
108
+
109
+ if (in_array('exec', $disabledFunctions)) {
110
+ $disabled = true;
111
+ }
112
+
113
+ if (function_exists('exec') === true && $disabled === false) {
114
+ $r = true;
115
+ }
116
+
117
+ return $r;
118
+ }
119
+
120
+ /**
121
+ * Optimized way of getting logging flag from config.
122
+ *
123
+ * @return int
124
+ */
125
+ public function isLoggingEnabled()
126
+ {
127
+ if ($this->_logging === null) {
128
+
129
+ $this->_logging = (int) $this->getConfig(
130
+ 'apptrian_imageoptimizer/utility/log_output'
131
+ );
132
+
133
+ }
134
+
135
+ return $this->_logging;
136
+ }
137
+
138
+ /**
139
+ * Based on config returns array of all paths that will be scaned for
140
+ * images.
141
+ *
142
+ * @return array
143
+ */
144
+ public function getPaths()
145
+ {
146
+
147
+ $paths = array();
148
+
149
+ $pathsString = trim(
150
+ trim($this->getConfig('apptrian_imageoptimizer/general/paths'), ';')
151
+ );
152
+
153
+ $rawPaths = explode(';', $pathsString);
154
+
155
+ foreach ($rawPaths as $p) {
156
+
157
+ $trimmed = trim(trim($p), '/');
158
+
159
+ $dirs = explode('/', $trimmed);
160
+
161
+ $paths[] = implode(DS, $dirs);
162
+
163
+ }
164
+
165
+ return array_unique($paths);
166
+
167
+ }
168
+
169
+ /**
170
+ * Optimizes single file.
171
+ *
172
+ * @param string $filePath
173
+ * @return boolean
174
+ */
175
+ public function optimizeFile($filePath)
176
+ {
177
+
178
+ $info = pathinfo($filePath);
179
+
180
+ $output = array();
181
+
182
+ switch (strtolower($info['extension'])) {
183
+ case 'jpg':
184
+ case 'jpeg':
185
+ exec($this->getJpgUtil($filePath), $output, $returnVar);
186
+ $type = 'jpg';
187
+ break;
188
+ case 'png':
189
+ exec($this->getPngUtil($filePath), $output, $returnVar);
190
+ $type = 'png';
191
+ break;
192
+ case 'gif':
193
+ exec($this->getGifUtil($filePath), $output, $returnVar);
194
+ $type = 'gif';
195
+ break;
196
+ }
197
+
198
+ if ($returnVar == 126) {
199
+
200
+ $error = $this->getConfig(
201
+ 'apptrian_imageoptimizer/utility/' . $type
202
+ ) . ' is not executable.';
203
+
204
+ Mage::log($error, null, 'apptrian_imageoptimizer.log');
205
+
206
+ return false;
207
+
208
+ } else {
209
+
210
+ if ($this->isLoggingEnabled()) {
211
+
212
+ Mage::log($filePath, null, 'apptrian_imageoptimizer.log');
213
+ Mage::log($output, null, 'apptrian_imageoptimizer.log');
214
+
215
+ }
216
+
217
+ $permissions = (string) $this->getConfig(
218
+ 'apptrian_imageoptimizer/utility/permissions'
219
+ );
220
+
221
+ if ($permissions) {
222
+ chmod($filePath, octdec($permissions));
223
+ }
224
+
225
+ return true;
226
+
227
+ }
228
+
229
+ }
230
+
231
+ /**
232
+ * Optimization process.
233
+ *
234
+ * @return boolean
235
+ */
236
+ public function optimize()
237
+ {
238
+ // Get Batch Size
239
+ $batchSize = $this->getConfig(
240
+ 'apptrian_imageoptimizer/general/batch_size'
241
+ );
242
+
243
+ // Get Collection of files for optimization but limited by batch size
244
+ $collection = Mage::getModel('apptrian_imageoptimizer/file')
245
+ ->getCollection()
246
+ ->addFieldToSelect(array('id', 'file_path'))
247
+ ->addFieldToFilter('optimized', array('eq' => 0))
248
+ ->setPageSize($batchSize)
249
+ ->load();
250
+
251
+ $toUpdate = array();
252
+ $toDelete = array();
253
+ $oldFileSize = 0;
254
+
255
+ foreach ($collection as $item) {
256
+
257
+ $id = $item->getId();
258
+ $fPath = $item->getFilePath();
259
+
260
+ $filePath = realpath($fPath);
261
+
262
+ // If image exists, optimize else remove it from database
263
+ if (file_exists($filePath)) {
264
+
265
+ $oldFileSize = filesize($filePath);
266
+
267
+ if ($this->optimizeFile($filePath)) {
268
+
269
+ $toUpdate[$id]['file_path'] = $fPath;
270
+ $toUpdate[$id]['old_file_size'] = $oldFileSize;
271
+ $toUpdate[$id]['optimized'] = 1;
272
+
273
+ }
274
+
275
+ } else {
276
+
277
+ $toDelete[] = $id;
278
+
279
+ }
280
+
281
+ }
282
+
283
+ // Itereate over $toUpdate array and set modified time and new_file_size
284
+ // (mtime etc) takes a split second to update
285
+ foreach ($toUpdate as $i => $f) {
286
+
287
+ $filePath = realpath($f['file_path']);
288
+
289
+ if (file_exists($filePath)) {
290
+ $toUpdate[$i]['new_file_size'] = filesize($filePath);
291
+ $toUpdate[$i]['optimization_time'] = filemtime($filePath);
292
+ }
293
+
294
+ }
295
+
296
+ $resource = Mage::getResourceModel('apptrian_imageoptimizer/file');
297
+
298
+ $resultA = $resource->deleteFiles($toDelete);
299
+ $resultB = $resource->updateFiles($toUpdate);
300
+
301
+ if ($resultA === true && $resultB === true) {
302
+ return true;
303
+ } else {
304
+ return false;
305
+ }
306
+
307
+ }
308
+
309
+ /**
310
+ * Scan and reindex process.
311
+ *
312
+ * @return boolean
313
+ */
314
+ public function scanAndReindex()
315
+ {
316
+
317
+ $collection = Mage::getModel('apptrian_imageoptimizer/file')
318
+ ->getCollection()
319
+ ->addFieldToSelect(array('id', 'file_path', 'optimization_time'))
320
+ ->load();
321
+
322
+ $inIndex = array();
323
+ $toAdd = array();
324
+ $toUpdate = array();
325
+ $toDelete = array();
326
+ $id = 0;
327
+ $filePath = '';
328
+
329
+ foreach ($collection as $item) {
330
+
331
+ $id = $item->getId();
332
+
333
+ $inIndex[$id] = 0;
334
+
335
+ $filePath = realpath($item->getFilePath());
336
+
337
+ if (file_exists($filePath)) {
338
+ if (filemtime($filePath) != $item->getOptimizationTime()) {
339
+ $toUpdate[] = $id;
340
+ }
341
+ } else {
342
+ $toDelete[] = $id;
343
+ }
344
+
345
+ }
346
+
347
+
348
+ $files = array();
349
+ $paths = $this->getPaths();
350
+
351
+ foreach ($paths as $path) {
352
+
353
+ $iterator = new RecursiveIteratorIterator(
354
+ new RecursiveDirectoryIterator(
355
+ $this->getBaseDir() . DS . $path,
356
+ RecursiveDirectoryIterator::FOLLOW_SYMLINKS
357
+ )
358
+ );
359
+
360
+ foreach ( $iterator as $filename => $file ) {
361
+ if ($file->isFile()
362
+ && preg_match(
363
+ '/^.+\.(jpe?g|gif|png)#x2F;i', $file->getFilename()
364
+ )
365
+ ) {
366
+ $filePath = $file->getRealPath();
367
+ if (!is_writable($filePath)) {
368
+ continue;
369
+ }
370
+
371
+ $files[md5($filePath)] = $filePath;
372
+
373
+ }
374
+ }
375
+
376
+ }
377
+
378
+
379
+ $toAdd = array_diff_key($files, $inIndex);
380
+
381
+ $resource = Mage::getResourceModel('apptrian_imageoptimizer/file');
382
+
383
+ $resultA = $resource->deleteFiles($toDelete);
384
+ $resultB = $resource->updateFilesOptimizedField($toUpdate);
385
+ $resultC = $resource->addFiles($toAdd);
386
+
387
+ if ($resultA === true && $resultB === true && $resultC === true) {
388
+ return true;
389
+ } else {
390
+ return false;
391
+ }
392
+
393
+ }
394
+
395
+ /**
396
+ * Checks if server OS is Windows
397
+ *
398
+ * @return bool
399
+ */
400
+ public function isWindows()
401
+ {
402
+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
403
+ return true;
404
+ } else {
405
+ return false;
406
+ }
407
+ }
408
+
409
+ /**
410
+ * Alias for getUtil() and .gif
411
+ *
412
+ * @param string $filePath
413
+ * @return string
414
+ */
415
+ public function getGifUtil($filePath)
416
+ {
417
+ return $this->getUtil('gif', $filePath);
418
+ }
419
+
420
+ /**
421
+ * Alias for getUtil() and .jpg
422
+ *
423
+ * @param string $filePath
424
+ * @return string
425
+ */
426
+ public function getJpgUtil($filePath)
427
+ {
428
+ return $this->getUtil('jpg', $filePath);
429
+ }
430
+
431
+ /**
432
+ * Alias for getUtil() and .png
433
+ *
434
+ * @param string $filePath
435
+ * @return string
436
+ */
437
+ public function getPngUtil($filePath)
438
+ {
439
+ return $this->getUtil('png', $filePath);
440
+ }
441
+
442
+ /**
443
+ * Formats and returns the shell command string for an image optimization
444
+ * utility
445
+ *
446
+ * @param string $type - This is image type. Valid values gif|jpg|png
447
+ * @param string $filePath - Path to the image to be optimized
448
+ * @return string
449
+ */
450
+ public function getUtil($type, $filePath)
451
+ {
452
+
453
+ $exactPath = $this->getConfig(
454
+ 'apptrian_imageoptimizer/utility/' . $type . '_path'
455
+ );
456
+
457
+ // If utility exact path is set use it
458
+ if ($exactPath != '') {
459
+
460
+ $cmd = $exactPath;
461
+
462
+ // Use path to extension's local utilities
463
+ } else {
464
+
465
+ $cmd = $this->getUtilPath() . DS . $this->getConfig(
466
+ 'apptrian_imageoptimizer/utility/' . $type
467
+ ) . $this->getUtilExt();
468
+
469
+ }
470
+
471
+ $cmd .= ' ' . $this->getConfig(
472
+ 'apptrian_imageoptimizer/utility/' . $type . '_options'
473
+ );
474
+
475
+ return str_replace('%filepath%', $filePath, $cmd);
476
+
477
+ }
478
+
479
+ /**
480
+ * Gets and stores utility extension.
481
+ * Checks server OS and determine utility extension.
482
+ *
483
+ * @return string
484
+ */
485
+ public function getUtilExt()
486
+ {
487
+ if ($this->_utilExt === null) {
488
+
489
+ $this->_utilExt = $this->isWindows() ? '.exe' : '';
490
+
491
+ }
492
+
493
+ return $this->_utilExt;
494
+ }
495
+
496
+ /**
497
+ * Gets and stores path to utilities.
498
+ * Checks server OS and config to determine the path where
499
+ * image optimization utilities are.
500
+ *
501
+ * @return string
502
+ */
503
+ public function getUtilPath()
504
+ {
505
+ if ($this->_utilPath === null) {
506
+
507
+ $useSixtyFourBit = (int) $this->getConfig(
508
+ 'apptrian_imageoptimizer/utility/use64bit'
509
+ );
510
+
511
+ if ($useSixtyFourBit) {
512
+ $bit = '64';
513
+ } else {
514
+ $bit = '32';
515
+ }
516
+
517
+ $os = $this->isWindows() ? 'win' . $bit : 'elf' . $bit;
518
+
519
+ $pathString = trim(
520
+ trim(
521
+ $this->getConfig('apptrian_imageoptimizer/utility/path')
522
+ ),
523
+ '/'
524
+ );
525
+
526
+ $dirs = explode('/', $pathString);
527
+ $path = implode(DS, $dirs);
528
+
529
+ $this->_utilPath = $this->getBaseDir() . DS . $path . DS . $os;
530
+
531
+ }
532
+
533
+ return $this->_utilPath;
534
+ }
535
+
536
+ }
app/code/community/Apptrian/ImageOptimizer/Helper/Utility.php DELETED
@@ -1,149 +0,0 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Helper_Utility extends Mage_Core_Helper_Abstract {
10
-
11
- /**
12
- * Path to utilities.
13
- *
14
- * @var null|string
15
- */
16
- protected $utilPath = null;
17
-
18
- /**
19
- * extension (for win binaries)
20
- *
21
- * @var null|string
22
- */
23
- protected $utilExt = null;
24
-
25
- /**
26
- * Checks if server OS is Windows
27
- *
28
- * @return bool
29
- */
30
- protected function isWindows()
31
- {
32
- if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
33
- return true;
34
- } else {
35
- return false;
36
- }
37
- }
38
-
39
- /**
40
- * Alias for getUtil() and .gif
41
- *
42
- * @param string $filePath
43
- * @return string
44
- */
45
- public function getGifUtil($filePath)
46
- {
47
- return $this->getUtil('gif', $filePath);
48
- }
49
-
50
- /**
51
- * Alias for getUtil() and .jpg
52
- *
53
- * @param string $filePath
54
- * @return string
55
- */
56
- public function getJpgUtil($filePath)
57
- {
58
- return $this->getUtil('jpg', $filePath);
59
- }
60
-
61
- /**
62
- * Alias for getUtil() and .png
63
- *
64
- * @param string $filePath
65
- * @return string
66
- */
67
- public function getPngUtil($filePath)
68
- {
69
- return $this->getUtil('png', $filePath);
70
- }
71
-
72
- /**
73
- * Formats and returns the shell command string for an image optimization utility
74
- *
75
- * @param string $type - This is image type. Valid values gif|jpg|png
76
- * @param string $filePath - Path to the image to be optimized
77
- * @return string
78
- */
79
- protected function getUtil($type, $filePath)
80
- {
81
-
82
- $exactPath = Mage::getConfig()->getNode('apptrian_imageoptimizer/utility/' . $type . '_path', 'default');
83
-
84
- // If utility exact path is set use it
85
- if ($exactPath != '') {
86
-
87
- $cmd = $exactPath;
88
-
89
- // Use path to extension's local utilities
90
- } else {
91
-
92
- $cmd = $this->getUtilPath() . DS . Mage::getConfig()->getNode('apptrian_imageoptimizer/utility/' . $type, 'default') . $this->getUtilExt();
93
-
94
- }
95
-
96
- $cmd .= ' ' . Mage::getConfig()->getNode('apptrian_imageoptimizer/utility/' . $type . '_options', 'default');
97
-
98
- return str_replace('%filepath%', $filePath, $cmd);
99
-
100
- }
101
-
102
- /**
103
- * Gets and stores utility extension.
104
- * Checks server OS and determine utility extension.
105
- *
106
- * @return string
107
- */
108
- protected function getUtilExt()
109
- {
110
- if ($this->utilExt === null) {
111
-
112
- $this->utilExt = $this->isWindows() ? '.exe' : '';
113
-
114
- }
115
-
116
- return $this->utilExt;
117
- }
118
-
119
- /**
120
- * Gets and stores path to utilities.
121
- * Checks server OS and config to determine the path where image optimization utilities are.
122
- *
123
- * @return string
124
- */
125
- protected function getUtilPath()
126
- {
127
- if ($this->utilPath === null) {
128
-
129
- if ((int) Mage::getConfig()->getNode('apptrian_imageoptimizer/utility/use64bit', 'default')) {
130
- $bit = '64';
131
- } else {
132
- $bit = '32';
133
- }
134
-
135
- $os = $this->isWindows() ? 'win' . $bit : 'elf' . $bit;
136
-
137
- $pathString = trim(trim(Mage::getConfig()->getNode('apptrian_imageoptimizer/utility/path', 'default')), '/');
138
- $dirs = explode('/', $pathString);
139
- $path = implode(DS, $dirs);
140
-
141
- $this->utilPath = Mage::getBaseDir() . DS . $path . DS . $os;
142
-
143
- }
144
-
145
- return $this->utilPath;
146
- }
147
-
148
-
149
- }
app/code/community/Apptrian/ImageOptimizer/Model/Config/Batchsize.php CHANGED
@@ -1,50 +1,51 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Model_Config_Batchsize extends Mage_Core_Model_Config_Data
10
- {
11
-
12
- public function _beforeSave()
13
- {
14
-
15
- $result = $this->validate();
16
-
17
- if ($result !== true) {
18
-
19
- Mage::throwException(implode("\n", $result));
20
-
21
- }
22
-
23
- return parent::_beforeSave();
24
-
25
- }
26
-
27
- public function validate()
28
- {
29
-
30
- $errors = array();
31
- $helper = Mage::helper('apptrian_imageoptimizer');
32
- $value = $this->getValue();
33
-
34
- if (!Zend_Validate::is($value, 'Digits')) {
35
- $errors[] = $helper->__('Batch size must be an integer.');
36
- }
37
-
38
- if (!Zend_Validate::is($value, 'GreaterThan', array(0))) {
39
- $errors[] = $helper->__('Batch size must be greater than 0.');
40
- }
41
-
42
- if (empty($errors)) {
43
- return true;
44
- }
45
-
46
- return $errors;
47
-
48
- }
49
-
50
- }
1
+ <?php
2
+ /**
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();
34
+
35
+ if (!Zend_Validate::is($value, 'Digits')) {
36
+ $errors[] = $helper->__('Batch size must be an integer.');
37
+ }
38
+
39
+ if (!Zend_Validate::is($value, 'GreaterThan', array(0))) {
40
+ $errors[] = $helper->__('Batch size must be greater than 0.');
41
+ }
42
+
43
+ if (empty($errors)) {
44
+ return true;
45
+ }
46
+
47
+ return $errors;
48
+
49
+ }
50
+
51
+ }
app/code/community/Apptrian/ImageOptimizer/Model/Config/Cron.php DELETED
@@ -1,68 +0,0 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Model_Config_Cron extends Mage_Core_Model_Config_Data
10
- {
11
- const CRON_STRING_PATH = 'crontab/jobs/apptrian_imageoptimizer_process/schedule/cron_expr';
12
-
13
- protected function _afterSave()
14
- {
15
-
16
- $cronExprString = $this->getValue();
17
-
18
- try {
19
-
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
-
26
- } catch (Exception $e) {
27
-
28
- throw new Exception(Mage::helper('cron')->__('Unable to save the cron expression.'));
29
-
30
- }
31
-
32
- }
33
-
34
- public function _beforeSave()
35
- {
36
-
37
- $result = $this->validate();
38
-
39
- if ($result !== true) {
40
-
41
- Mage::throwException(implode("\n", $result));
42
-
43
- }
44
-
45
- return parent::_beforeSave();
46
-
47
- }
48
-
49
- public function validate()
50
- {
51
-
52
- $errors = array();
53
- $helper = Mage::helper('apptrian_imageoptimizer');
54
- $value = $this->getValue();
55
-
56
- if (!Zend_Validate::is($value, 'Regex', array('pattern' => '/^[0-9,\-\?\/\*\ ]+#x2F;'))) {
57
- $errors[] = $helper->__('Cron expression is invalid.');
58
- }
59
-
60
- if (empty($errors)) {
61
- return true;
62
- }
63
-
64
- return $errors;
65
-
66
- }
67
-
68
- }
app/code/community/Apptrian/ImageOptimizer/Model/Config/Cron/Optimize.php ADDED
@@ -0,0 +1,75 @@
1
+ <?php
2
+ /**
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) {
64
+ $errors[] = $helper->__('Cron expression is invalid.');
65
+ }
66
+
67
+ if (empty($errors)) {
68
+ return true;
69
+ }
70
+
71
+ return $errors;
72
+
73
+ }
74
+
75
+ }
app/code/community/Apptrian/ImageOptimizer/Model/Config/Cron/Scan.php ADDED
@@ -0,0 +1,75 @@
1
+ <?php
2
+ /**
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) {
64
+ $errors[] = $helper->__('Cron expression is invalid.');
65
+ }
66
+
67
+ if (empty($errors)) {
68
+ return true;
69
+ }
70
+
71
+ return $errors;
72
+
73
+ }
74
+
75
+ }
app/code/community/Apptrian/ImageOptimizer/Model/Config/Exactpath.php CHANGED
@@ -1,46 +1,54 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Model_Config_Exactpath extends Mage_Core_Model_Config_Data
10
- {
11
-
12
- public function _beforeSave()
13
- {
14
-
15
- $result = $this->validate();
16
-
17
- if ($result !== true) {
18
-
19
- Mage::throwException(implode("\n", $result));
20
-
21
- }
22
-
23
- return parent::_beforeSave();
24
-
25
- }
26
-
27
- public function validate()
28
- {
29
-
30
- $errors = array();
31
- $helper = Mage::helper('apptrian_imageoptimizer');
32
- $value = $this->getValue();
33
-
34
- if (!Zend_Validate::is($value, 'Regex', array('pattern' => '/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/\\\\]*#x2F;iu'))) {
35
- $errors[] = $helper->__('One or more of Utility Exact Path fields are invalid.');
36
- }
37
-
38
- if (empty($errors)) {
39
- return true;
40
- }
41
-
42
- return $errors;
43
-
44
- }
45
-
46
- }
1
+ <?php
2
+ /**
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
+ )
39
+ );
40
+
41
+ if (!$validator) {
42
+ $errors[] = $helper
43
+ ->__('One or more of Utility Exact Path fields are invalid.');
44
+ }
45
+
46
+ if (empty($errors)) {
47
+ return true;
48
+ }
49
+
50
+ return $errors;
51
+
52
+ }
53
+
54
+ }
app/code/community/Apptrian/ImageOptimizer/Model/Config/Options.php CHANGED
@@ -1,46 +1,54 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Model_Config_Options extends Mage_Core_Model_Config_Data
10
- {
11
-
12
- public function _beforeSave()
13
- {
14
-
15
- $result = $this->validate();
16
-
17
- if ($result !== true) {
18
-
19
- Mage::throwException(implode("\n", $result));
20
-
21
- }
22
-
23
- return parent::_beforeSave();
24
-
25
- }
26
-
27
- public function validate()
28
- {
29
-
30
- $errors = array();
31
- $helper = Mage::helper('apptrian_imageoptimizer');
32
- $value = $this->getValue();
33
-
34
- if (!Zend_Validate::is($value, 'Regex', array('pattern' => '/^[\p{L}\p{N}_,;:!%&#\=\+\*\$\?\|\'\.\-\ \/]+#x2F;iu'))) {
35
- $errors[] = $helper->__('One or more of Utility Option fields are invalid.');
36
- }
37
-
38
- if (empty($errors)) {
39
- return true;
40
- }
41
-
42
- return $errors;
43
-
44
- }
45
-
46
- }
1
+ <?php
2
+ /**
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
+ )
39
+ );
40
+
41
+ if (!$validator) {
42
+ $errors[] = $helper
43
+ ->__('One or more of Utility Option fields are invalid.');
44
+ }
45
+
46
+ if (empty($errors)) {
47
+ return true;
48
+ }
49
+
50
+ return $errors;
51
+
52
+ }
53
+
54
+ }
app/code/community/Apptrian/ImageOptimizer/Model/Config/Path.php CHANGED
@@ -1,46 +1,51 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Model_Config_Path extends Mage_Core_Model_Config_Data
10
- {
11
-
12
- public function _beforeSave()
13
- {
14
-
15
- $result = $this->validate();
16
-
17
- if ($result !== true) {
18
-
19
- Mage::throwException(implode("\n", $result));
20
-
21
- }
22
-
23
- return parent::_beforeSave();
24
-
25
- }
26
-
27
- public function validate()
28
- {
29
-
30
- $errors = array();
31
- $helper = Mage::helper('apptrian_imageoptimizer');
32
- $value = $this->getValue();
33
-
34
- if (!Zend_Validate::is($value, 'Regex', array('pattern' => '/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/]+#x2F;iu'))) {
35
- $errors[] = $helper->__('Utility Path is invalid.');
36
- }
37
-
38
- if (empty($errors)) {
39
- return true;
40
- }
41
-
42
- return $errors;
43
-
44
- }
45
-
46
- }
1
+ <?php
2
+ /**
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
+
39
+ if (!$validator) {
40
+ $errors[] = $helper->__('Utility Path is invalid.');
41
+ }
42
+
43
+ if (empty($errors)) {
44
+ return true;
45
+ }
46
+
47
+ return $errors;
48
+
49
+ }
50
+
51
+ }
app/code/community/Apptrian/ImageOptimizer/Model/Config/Paths.php CHANGED
@@ -1,46 +1,51 @@
1
- <?php
2
- /**
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 (OSL 3.0)
8
- */
9
- class Apptrian_ImageOptimizer_Model_Config_Paths extends Mage_Core_Model_Config_Data
10
- {
11
-
12
- public function _beforeSave()
13
- {
14
-
15
- $result = $this->validate();
16
-
17
- if ($result !== true) {
18
-
19
- Mage::throwException(implode("\n", $result));
20
-
21
- }
22
-
23
- return parent::_beforeSave();
24
-
25
- }
26
-
27
- public function validate()
28
- {
29
-
30
- $errors = array();
31
- $helper = Mage::helper('apptrian_imageoptimizer');
32
- $value = $this->getValue();
33
-
34
- if (!Zend_Validate::is($value, 'Regex', array('pattern' => '/^[\p{L}\p{N}_,;:!&#\+\*\$\?\|\'\.\-\ \/]+#x2F;iu'))) {
35
- $errors[] = $helper->__('Paths field is invalid.');
36
- }
37
-
38
- if (empty($errors)) {
39
- return true;
40
- }
41
-
42
- return $errors;
43
-
44
- }
45
-
46
- }
1
+ <?php
2
+ /**
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
+
39
+ if (!$validator) {
40
+ $errors[] = $helper->__('Paths field is invalid.');
41
+ }
42
+
43
+ if (empty($errors)) {
44
+ return true;
45
+ }
46
+
47
+ return $errors;
48
+
49
+ }
50
+
51
+ }
app/code/community/Apptrian/ImageOptimizer/Model/Config/Permissions.php ADDED
@@ -0,0 +1,51 @@
1
+ <?php
2
+ /**
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
+
39
+ if (!$validator) {
40
+ $errors[] = $helper->__('Force File Permissions field is invalid.');
41
+ }
42
+
43
+ if (empty($errors)) {
44
+ return true;
45
+ }
46
+
47
+ return $errors;
48
+
49
+ }
50
+
51
+ }