rejuni_image_optimizer - Version 0.1.1

Version Notes

First public release

Download this release

Release Info

Developer Remco
Extension rejuni_image_optimizer
Version 0.1.1
Comparing to
See all releases


Version 0.1.1

app/code/community/ReJuNi/Core/Helper/Data.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ReJuNi_Core_Helper_Data extends
4
+ Mage_Core_Helper_Abstract
5
+ {
6
+
7
+ }
app/code/community/ReJuNi/Core/etc/config.xml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <ReJuNi_Core>
5
+ <version>0.1.0</version>
6
+ </ReJuNi_Core>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <rejuni>
11
+ <class>ReJuNi_Core_Model</class>
12
+ </rejuni>
13
+ </models>
14
+ <helpers>
15
+ <rejuni>
16
+ <class>ReJuNi_Core_Helper</class>
17
+ </rejuni>
18
+ </helpers>
19
+ </global>
20
+ <default>
21
+ <rejuni>
22
+ <rejuni_group>
23
+ <rejuni_version>0.1.0</rejuni_version>
24
+ </rejuni_group>
25
+ </rejuni>
26
+ </default>
27
+ <adminhtml>
28
+ <acl>
29
+ <resources>
30
+ <all>
31
+ <title>Allow Everything</title>
32
+ </all>
33
+ <admin>
34
+ <children>
35
+ <system>
36
+ <children>
37
+ <config>
38
+ <children>
39
+ <rejuni>
40
+ <title>ReJuNi - All</title>
41
+ </rejuni>
42
+ </children>
43
+ </config>
44
+ </children>
45
+ </system>
46
+ </children>
47
+ </admin>
48
+ </resources>
49
+ </acl>
50
+ </adminhtml>
51
+ </config>
app/code/community/ReJuNi/Core/etc/system.xml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <tabs>
4
+ <rejuni translate="label" module="rejuni">
5
+ <label>ReJuNi Extensions</label>
6
+ <sort_order>100</sort_order>
7
+ </rejuni>
8
+ </tabs>
9
+ <sections>
10
+ <rejuni translate="label" module="rejuni">
11
+ <label>Info</label>
12
+ <tab>rejuni</tab>
13
+ <sort_order>10</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+
18
+ <groups>
19
+ <rejuni_group translate="label" module="rejuni">
20
+ <label>Rejuni Extension Options</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>1</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+
27
+ <fields>
28
+ <rejuni_version translate="label">
29
+ <label>Core Version:</label>
30
+ <frontend_type>label</frontend_type>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </rejuni_version>
36
+ </fields>
37
+ </rejuni_group>
38
+ </groups>
39
+ </rejuni>
40
+ </sections>
41
+ </config>
app/code/community/ReJuNi/Optimizer/Helper/Data.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ReJuNi_Optimizer_Helper_Data extends
4
+ Mage_Core_Helper_Abstract
5
+ {
6
+
7
+ }
app/code/community/ReJuNi/Optimizer/Model/Observer.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class ReJuNi_Optimizer_Model_Observer{
3
+ public function optimizeFilesize(Varien_Event_Observer $observer){
4
+ $enableStatus = Mage::getConfig()->getNode('default/rejuni/rejuni_optimizer_group/rejuni_optimizer_enabled');
5
+ if($enableStatus > 0)
6
+ {
7
+ $event = $observer->getEvent();
8
+ $result = $event->getObject();
9
+
10
+ $newFile = $result->getNewFile();
11
+ Mage::log($newFile, null, 'rejuni.log');
12
+ $this->doApiCall($newFile);
13
+ } else {
14
+ Mage::log("Optimizer not enabled", null, 'rejuni.log');
15
+ }
16
+ }
17
+
18
+ private function doApiCall($image) {
19
+ $target_url = Mage::getConfig()->getNode('default/rejuni/rejuni_optimizer_group/rejuni_optimizer_apiuri');
20
+ $apikey = Mage::getConfig()->getNode('default/rejuni/rejuni_optimizer_group/rejuni_optimizer_apikey');
21
+
22
+ if(empty($target_url)) {
23
+ Mage::log("target uri not set", null, 'rejuni.log');
24
+ return;
25
+ }
26
+ if(empty($apikey)) {
27
+ Mage::log("api key not set", null, 'rejuni.log');
28
+ return;
29
+ }
30
+
31
+ $imageData = getimagesize($image);
32
+ $mimeType = image_type_to_mime_type($imageData[2]);
33
+
34
+ //http://php.net/manual/en/class.curlfile.php#115569 see curl_file_create
35
+ $cfile = new CURLFile($image,$mimeType,basename($image));
36
+
37
+ $imgdata = array('uploaded_file' => $cfile);
38
+
39
+ $header = array(
40
+ "Authorization: Basic " . base64_encode( $apikey ),
41
+ "Content-Type: multipart/form-data",
42
+ );
43
+
44
+ $ch = curl_init();
45
+
46
+ curl_setopt($ch, CURLOPT_URL,$target_url);
47
+ curl_setopt($ch, CURLOPT_POST,1);
48
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
49
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $imgdata);
50
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
51
+
52
+ $result = curl_exec ($ch);
53
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
54
+ curl_close($ch);
55
+
56
+ if( $status !== 200 ) {
57
+ Mage::log("Image mimetype: " . $mimeType, null, 'rejuni.log');
58
+ Mage::log("curl status: " . $status, null, 'rejuni.log');
59
+ } else {
60
+ $writtenBytes = file_put_contents($image, $result);
61
+ if($writtenBytes < 1) Mage::log("zero bytes written", null, 'rejuni.log');
62
+ }
63
+ }
64
+ }
app/code/community/ReJuNi/Optimizer/Model/Product/Image.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ReJuNi_Optimizer_Model_Product_Image extends Mage_Catalog_Model_Product_Image
4
+ {
5
+ /**
6
+ * @return Mage_Catalog_Model_Product_Image
7
+ */
8
+ public function saveFile()
9
+ {
10
+ $filename = $this->getNewFile();
11
+ $this->getImageProcessor()->save($filename);
12
+ Mage::helper('core/file_storage_database')->saveFile($filename);
13
+
14
+ // Run rejuni_catalog_product_save_image_after
15
+ Mage::dispatchEvent('rejuni_catalog_product_save_image_after', array($this->_eventObject => $this));
16
+
17
+ return $this;
18
+ }
19
+
20
+ }
app/code/community/ReJuNi/Optimizer/Model/knowledge.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ catalog_product_gallery_upload_image_after
2
+
3
+ http://magento.stackexchange.com/questions/52497/is-it-possible-to-hook-into-the-image-upload-function-on-the-wysiwyg-editor
4
+ https://www.nicksays.co.uk/magento-events-cheat-sheet-1-7/
app/code/community/ReJuNi/Optimizer/etc/config.xml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <ReJuNi_Optimizer>
5
+ <version>0.1.1</version>
6
+ </ReJuNi_Optimizer>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <rejuni_optimizer>
11
+ <class>ReJuNi_Optimizer_Model</class>
12
+ </rejuni_optimizer>
13
+ <rejuni>
14
+ <class>ReJuNi_Core_Model</class>
15
+ </rejuni>
16
+ <catalog>
17
+ <rewrite>
18
+ <product_image>ReJuNi_Optimizer_Model_Product_Image</product_image>
19
+ </rewrite>
20
+ </catalog>
21
+ </models>
22
+ <events>
23
+ <rejuni_catalog_product_save_image_after>
24
+ <observers>
25
+ <ReJuNi_Optimizer_model_upload>
26
+ <type>model</type>
27
+ <class>ReJuNi_Optimizer_Model_Observer</class>
28
+ <method>optimizeFilesize</method>
29
+ </ReJuNi_Optimizer_model_upload>
30
+ </observers>
31
+ </rejuni_catalog_product_save_image_after>
32
+ </events>
33
+ <helpers>
34
+ <rejuni_optimizer>
35
+ <class>ReJuNi_Optimizer_Helper</class>
36
+ </rejuni_optimizer>
37
+ <rejuni>
38
+ <class>ReJuNi_Core_Helper</class>
39
+ </rejuni>
40
+ </helpers>
41
+ </global>
42
+ <default>
43
+ <rejuni>
44
+ <rejuni_group>
45
+ <rejuni_optimizer_version>0.1.1</rejuni_optimizer_version>
46
+ </rejuni_group>
47
+ </rejuni>
48
+ <rejuni_optimizer>
49
+ <rejuni_optimizer_group>
50
+ <rejuni_optimizer_apiuri>http://api.rejuni.nl/1.0/optimize</rejuni_optimizer_apiuri>
51
+ </rejuni_optimizer_group>
52
+ </rejuni_optimizer>
53
+ </default>
54
+ <adminhtml>
55
+ <acl>
56
+ <resources>
57
+ <all>
58
+ <title>Allow Everything</title>
59
+ </all>
60
+ <admin>
61
+ <children>
62
+ <system>
63
+ <children>
64
+ <config>
65
+ <children>
66
+ <rejuni>
67
+ <title>ReJuNi - All</title>
68
+ </rejuni>
69
+ <rejuni_optimizer>
70
+ <title>ReJuNi - All</title>
71
+ </rejuni_optimizer>
72
+ </children>
73
+ </config>
74
+ </children>
75
+ </system>
76
+ </children>
77
+ </admin>
78
+ </resources>
79
+ </acl>
80
+ </adminhtml>
81
+ </config>
app/code/community/ReJuNi/Optimizer/etc/system.xml ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <rejuni>
5
+ <groups>
6
+ <rejuni_group translate="label" module="rejuni">
7
+ <fields>
8
+ <rejuni_optimizer_version translate="label">
9
+ <label>Optimizer Version: </label>
10
+ <frontend_type>label</frontend_type>
11
+ <sort_order>20</sort_order>
12
+ <show_in_default>1</show_in_default>
13
+ <show_in_website>1</show_in_website>
14
+ <show_in_store>1</show_in_store>
15
+ </rejuni_optimizer_version>
16
+ </fields>
17
+ </rejuni_group>
18
+ </groups>
19
+ </rejuni>
20
+ <rejuni_optimizer>
21
+ <label>Optimizer</label>
22
+ <tab>rejuni</tab>
23
+ <sort_order>20</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>1</show_in_website>
26
+ <show_in_store>1</show_in_store>
27
+ <groups>
28
+ <rejuni_optimizer_group translate="label" module="rejuni_optimizer">
29
+ <label>Rejuni Optimizer Options</label>
30
+ <frontend_type>text</frontend_type>
31
+ <sort_order>20</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ <fields>
36
+ <rejuni_optimizer_enabled translate="label">
37
+ <label>Enabled: </label>
38
+ <comment>Enables/Disables the optimizer</comment>
39
+ <frontend_type>select</frontend_type>
40
+ <sort_order>10</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ <source_model>adminhtml/system_config_source_yesno</source_model>
45
+ </rejuni_optimizer_enabled>
46
+ <rejuni_optimizer_apikey translate="label">
47
+ <label>Api Key: </label>
48
+ <comment>get your API key at api.rejuni.nl</comment>
49
+ <frontend_type>text</frontend_type>
50
+ <sort_order>30</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>1</show_in_website>
53
+ <show_in_store>1</show_in_store>
54
+ </rejuni_optimizer_apikey>
55
+ <rejuni_optimizer_apiuri translate="label">
56
+ <label>Api URI: </label>
57
+ <comment>Default API URI http://api.rejuni.nl/1.0/optimize do not alter this URI unless requested by us.</comment>
58
+ <frontend_type>text</frontend_type>
59
+ <sort_order>40</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>1</show_in_store>
63
+ </rejuni_optimizer_apiuri>
64
+ </fields>
65
+ </rejuni_optimizer_group>
66
+ </groups>
67
+ </rejuni_optimizer>
68
+ </sections>
69
+ </config>
app/code/community/ReJuNi/Optimizer/sql/optimizer_setup/install-1.0.0.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer=$this;
3
+ $installer->startSetup();
4
+
5
+ $installer->run("
6
+ -- DROP TABLE IF EXISTS {$this->getTable('rejuni_optimizer')};
7
+ CREATE TABLE {$this->getTable('rejuni_optimizer')} (
8
+ `rejuni_optimizer_id` int(11) unsigned NOT NULL auto_increment COMMENT 'Q&A ID',
9
+ `image_name` varchar(255) NOT NULL COMMENT 'Image Name',
10
+ `image_path` varchar(255) NOT NULL COMMENT 'Image Path',
11
+ `filesize_before` text NOT NULL COMMENT 'Filesize Before',
12
+ `filesize_after` text NOT NULL COMMENT 'Filesize After',
13
+ `created_time` datetime NULL,
14
+ `update_time` datetime NULL,
15
+ PRIMARY KEY (`custommodule_id`)
16
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
17
+ $installer->endSetup();
18
+ ?>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>rejuni_image_optimizer</name>
4
+ <version>0.1.1</version>
5
+ <stability>stable</stability>
6
+ <license>GNU General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Compresses images so that they will use less data.</summary>
10
+ <description>Save data on your server, lower your webshop load time, improve SEO! All by optimizing your images.</description>
11
+ <notes>First public release</notes>
12
+ <authors><author><name>Remco</name><user>rejuni</user><email>info@rejuni.nl</email></author></authors>
13
+ <date>2015-08-29</date>
14
+ <time>09:49:58</time>
15
+ <contents><target name="magecommunity"><dir name="ReJuNi"><dir name="Core"><dir name="Helper"><file name="Data.php" hash="c25de8cec52f28c75d483ddd8821751f"/></dir><dir name="etc"><file name="config.xml" hash="2694f9abec22840cdf6f1ae65d711994"/><file name="system.xml" hash="d70d2c33dbc265135920ba2319a88c4b"/></dir></dir><dir name="Optimizer"><dir name="Helper"><file name="Data.php" hash="df0125a410ed57094a8b5163ea3b12bd"/></dir><dir name="Model"><file name="Observer.php" hash="eb6453a73036fb443c2e175c42c824f5"/><dir name="Product"><file name="Image.php" hash="2d2c2e95963cd812e9df3135753e1076"/></dir><file name="knowledge.txt" hash="78de2ec1d12ec6747c37fc1684679b52"/></dir><dir name="etc"><file name="config.xml" hash="481060763486b5403e737625852c66fe"/><file name="system.xml" hash="8438cdf840fb286f84ad7ff4ff402761"/></dir><dir name="sql"><dir name="optimizer_setup"><file name="install-1.0.0.php" hash="70b2d072336a89c5b528d7cc7f7748c7"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.3.0</min><max>5.6.0</max></php></required></dependencies>
18
+ </package>