Kraken_Image_Optimizer - Version 2.0.0

Version Notes

Rewritten image cache optimization now uses AJAX requests to optimize images in the background.

Download this release

Release Info

Developer Nekkra UG
Extension Kraken_Image_Optimizer
Version 2.0.0
Comparing to
See all releases


Code changes from version 1.0.0 to 2.0.0

Files changed (23) hide show
  1. app/code/local/Welance/Kraken/Block/Adminhtml/Image.php +0 -50
  2. app/code/local/Welance/Kraken/Block/Adminhtml/Image/Grid.php +0 -164
  3. app/code/local/Welance/Kraken/Block/Adminhtml/Image/Renderer/Size.php +0 -11
  4. app/code/local/Welance/Kraken/Block/Adminhtml/Image/View.php +0 -105
  5. app/code/local/Welance/Kraken/Block/Product/Image.php +62 -0
  6. app/code/local/Welance/Kraken/Model/Image.php +0 -193
  7. app/code/local/Welance/Kraken/Model/Image/Cache.php +22 -1
  8. app/code/local/Welance/Kraken/Model/Observer.php +20 -36
  9. app/code/local/Welance/Kraken/Model/Resource/Image.php +0 -9
  10. app/code/local/Welance/Kraken/Model/Resource/Image/Collection.php +0 -9
  11. app/code/local/Welance/Kraken/controllers/OptimizeController.php +61 -0
  12. app/code/local/Welance/Kraken/etc/config.xml +22 -3
  13. app/code/local/Welance/Kraken/etc/system.xml +12 -2
  14. app/code/local/Welance/Kraken/sql/welance_kraken_setup/mysql4-upgrade-0.0.5-0.0.6.php +27 -0
  15. app/code/local/Welance/Kraken/sql/welance_kraken_setup/mysql4-upgrade-0.0.6-2.0.0.php +40 -0
  16. app/code/local/Welance/Kraken/sql/welance_kraken_setup/mysql4-upgrade-1.0.0-2.0.0.php +40 -0
  17. app/design/adminhtml/default/default/template/kraken/image.phtml +0 -44
  18. app/design/adminhtml/default/default/template/kraken/image/view.phtml +0 -55
  19. app/design/frontend/base/default/layout/kraken.xml +13 -0
  20. app/design/frontend/base/default/template/kraken/product/image.phtml +9 -0
  21. js/kraken/optimize.js +22 -0
  22. package.xml +5 -5
  23. skin/adminhtml/default/default/kraken/kraken-tile.png +0 -0
app/code/local/Welance/Kraken/Block/Adminhtml/Image.php DELETED
@@ -1,50 +0,0 @@
1
- <?php
2
-
3
- class Welance_Kraken_Block_Adminhtml_Image extends Mage_Adminhtml_Block_Widget_Container
4
- {
5
- public function __construct()
6
- {
7
- parent::__construct();
8
- $this->setTemplate('kraken/image.phtml');
9
- }
10
-
11
- protected function _prepareLayout()
12
- {
13
- $helper = Mage::helper('welance_kraken');
14
- $this->_addButton('get_images', array(
15
- 'label' => $helper->__('Get all images'),
16
- 'onclick' => "setLocation('{$this->getUrl('*/*/getImages')}')",
17
- 'class' => 'add'
18
- ));
19
-
20
- if(Mage::getResourceModel('welance_kraken/image_collection')->getSize() >0){
21
- $this->_addButton('add_images_to_queue', array(
22
- 'label' => $helper->__('Add all images to queue'),
23
- 'onclick' => "setLocation('{$this->getUrl('*/*/addToQueue')}')",
24
- 'class' => 'add'
25
- ));
26
- }
27
-
28
- if(Mage::helper('welance_kraken')->canShowBackupButton()){
29
- $this->_addButton('restore_images', array(
30
- 'label' => $helper->__('Restore all images from backup files'),
31
- 'onclick' => "setLocation('{$this->getUrl('*/*/restore')}')",
32
- 'class' => 'add'
33
- ));
34
- }
35
-
36
- $this->setChild('grid', $this->getLayout()->createBlock('welance_kraken/adminhtml_image_grid', 'welance_kraken_image.grid'));
37
- return parent::_prepareLayout();
38
- }
39
-
40
- /**
41
- * Render grid
42
- *
43
- * @return string
44
- */
45
- public function getGridHtml()
46
- {
47
- return $this->getChildHtml('grid');
48
- }
49
-
50
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Welance/Kraken/Block/Adminhtml/Image/Grid.php DELETED
@@ -1,164 +0,0 @@
1
- <?php
2
-
3
- class Welance_Kraken_Block_Adminhtml_Image_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
- {
5
-
6
- public function __construct()
7
- {
8
- parent::__construct();
9
- $this->setId('kraken_image_grid');
10
- $this->setUseAjax(true);
11
- $this->setDefaultSort('id');
12
- $this->setDefaultDir('ASC');
13
- $this->setSaveParametersInSession(true);
14
-
15
- }
16
-
17
- protected function _getCollectionClass()
18
- {
19
- return 'welance_kraken/image_collection';
20
- }
21
-
22
- protected function _prepareCollection()
23
- {
24
- $collection = Mage::getResourceModel($this->_getCollectionClass());
25
- $this->setCollection($collection);
26
-
27
- return parent::_prepareCollection();
28
- }
29
-
30
-
31
- protected function _prepareColumns()
32
- {
33
- $_helper = Mage::helper('welance_kraken');
34
-
35
- $this->addColumn('created_at',
36
- array(
37
- 'header' => $_helper->__('Created at'),
38
- 'type' => 'datetime',
39
- 'filter_index' => 'created_at',
40
- 'index' => 'created_at'
41
- )
42
- );
43
-
44
- $this->addColumn('path',
45
- array(
46
- 'header' => $_helper->__('Path'),
47
- 'filter_index' => 'path',
48
- 'index' => 'path'
49
- )
50
- );
51
-
52
- $this->addColumn('image_name',
53
- array(
54
- 'header' => $_helper->__('Image Name'),
55
- 'filter_index' => 'image_name',
56
- 'index' => 'image_name'
57
- )
58
- );
59
-
60
- $this->addColumn('original_size',
61
- array(
62
- 'header' => $_helper->__('Original Size'),
63
- 'type' => 'number',
64
- 'filter_index' => 'original_size',
65
- 'index' => 'original_size',
66
- 'renderer' => 'Welance_Kraken_Block_Adminhtml_Image_Renderer_Size'
67
- )
68
- );
69
-
70
- $this->addColumn('uploaded_at',
71
- array(
72
- 'header' => $_helper->__('Uploaded At'),
73
- 'type' => 'datetime',
74
- 'filter_index' => 'uploaded_at',
75
- 'index' => 'uploaded_at'
76
- )
77
- );
78
-
79
-
80
- $this->addColumn('size_after_upload',
81
- array(
82
- 'header' => $_helper->__('Size after Upload'),
83
- 'type' => 'number',
84
- 'filter_index' => 'size_after_upload',
85
- 'index' => 'size_after_upload',
86
- 'renderer' => 'Welance_Kraken_Block_Adminhtml_Image_Renderer_Size'
87
- )
88
- );
89
-
90
- $this->addColumn('saved_file_size',
91
- array(
92
- 'header' => $_helper->__('Saved File Size'),
93
- 'type' => 'number',
94
- 'filter_index' => 'saved_file_size',
95
- 'index' => 'saved_file_size',
96
- 'renderer' => 'Welance_Kraken_Block_Adminhtml_Image_Renderer_Size'
97
- )
98
- );
99
-
100
- $this->addColumn('percent_saved',
101
- array(
102
- 'header' => $_helper->__('Saved %'),
103
- 'type' => 'number',
104
- 'filter_index' => 'percent_saved',
105
- 'index' => 'percent_saved'
106
- )
107
- );
108
-
109
- $this->addColumn('response_error',
110
- array(
111
- 'header' => $_helper->__('Message'),
112
- 'filter_index' => 'response_error',
113
- 'index' => 'response_error'
114
- )
115
- );
116
-
117
- $this->addColumn('in_queue',
118
- array(
119
- 'header' => $_helper->__('In Queue'),
120
- 'filter_index' => 'in_queue',
121
- 'index' => 'in_queue'
122
- )
123
- );
124
-
125
-
126
- return parent::_prepareColumns();
127
- }
128
-
129
- protected function _prepareMassaction()
130
- {
131
- $_helper = Mage::helper('welance_kraken');
132
-
133
- $this->setMassactionIdField('id');
134
- $this->getMassactionBlock()->setUseSelectAll(false);
135
- $this->getMassactionBlock()->setFormFieldName('image');
136
-
137
- $this->getMassactionBlock()->addItem('optimize', array(
138
- 'label'=> $_helper->__('Add selected images to queue'),
139
- 'url' => $this->getUrl('*/*/addToQueueMass'),
140
- ));
141
-
142
- $this->getMassactionBlock()->addItem('restore', array(
143
- 'label'=> $_helper->__('Restore selected images from backup'),
144
- 'url' => $this->getUrl('*/*/restoreMass'),
145
- ));
146
-
147
- return $this;
148
- }
149
-
150
-
151
- public function getRowUrl($row)
152
- {
153
- return $this->getUrl('*/*/view', array(
154
- 'id'=>$row->getId())
155
- );
156
- }
157
-
158
- public function getGridUrl()
159
- {
160
- return $this->getUrl('*/*/grid', array('_current' => true));
161
- }
162
-
163
-
164
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Welance/Kraken/Block/Adminhtml/Image/Renderer/Size.php DELETED
@@ -1,11 +0,0 @@
1
- <?php
2
-
3
- class Welance_Kraken_Block_Adminhtml_Image_Renderer_Size extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
- {
5
- public function render(Varien_Object $row)
6
- {
7
- $size = $row->getData($this->getColumn()->getIndex());
8
-
9
- return Mage::helper('welance_kraken')->getImageSizeConverted($size);
10
- }
11
- }
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Welance/Kraken/Block/Adminhtml/Image/View.php DELETED
@@ -1,105 +0,0 @@
1
- <?php
2
-
3
- class Welance_Kraken_Block_Adminhtml_Image_View extends Mage_Adminhtml_Block_Widget
4
- {
5
- public function __construct()
6
- {
7
- parent::__construct();
8
- $this->setTemplate('kraken/image/view.phtml');
9
- $this->setId('image_view');
10
- }
11
-
12
- protected function _prepareLayout()
13
- {
14
- $this->setChild('optimize_button',
15
- $this->getLayout()->createBlock('adminhtml/widget_button')
16
- ->setData(array(
17
- 'label' => Mage::helper('welance_kraken')->__('Optimize Image'),
18
- 'onclick' => 'setLocation(\'' . $this->getOptimizeUrl() . '\')',
19
- 'class' => 'add'
20
- ))
21
- );
22
-
23
- $this->setChild('queue_button',
24
- $this->getLayout()->createBlock('adminhtml/widget_button')
25
- ->setData(array(
26
- 'label' => Mage::helper('welance_kraken')->__('Add Image To Queue'),
27
- 'onclick' => 'setLocation(\'' . $this->getQueueUrl() . '\')',
28
- 'class' => 'add'
29
- ))
30
- );
31
-
32
- $this->setChild('restore_button',
33
- $this->getLayout()->createBlock('adminhtml/widget_button')
34
- ->setData(array(
35
- 'label' => Mage::helper('welance_kraken')->__('Restore Backup'),
36
- 'onclick' => 'setLocation(\'' . $this->getRestoreUrl() . '\')',
37
- 'class' => 'add'
38
- ))
39
- );
40
-
41
- $this->setChild('back_button',
42
- $this->getLayout()->createBlock('adminhtml/widget_button')
43
- ->setData(array(
44
- 'label' => Mage::helper('welance_kraken')->__('Back'),
45
- 'onclick' => 'setLocation(\''.$this->getBackUrl() .'\')',
46
- 'class' => 'back'
47
- ))
48
- );
49
-
50
-
51
- }
52
-
53
- public function getImage()
54
- {
55
- return Mage::registry('current_image');
56
- }
57
-
58
- public function getOptimizeUrl()
59
- {
60
- return $this->getUrl('*/*/uploadSingleImage', array('_current'=>true));
61
- }
62
-
63
- public function getBackUrl()
64
- {
65
- return $this->getUrl('*/*/index');
66
- }
67
-
68
- public function getRestoreUrl()
69
- {
70
- return $this->getUrl('*/*/restoreSingleImage', array('_current'=>true));
71
- }
72
-
73
- public function getQueueUrl()
74
- {
75
- return $this->getUrl('*/*/addSingleImageToQueue', array('_current'=>true));
76
- }
77
-
78
-
79
- public function getOptimizeButtonHtml()
80
- {
81
- return $this->getChildHtml('optimize_button');
82
- }
83
-
84
- public function getRestoreButtonHtml()
85
- {
86
- return $this->getChildHtml('restore_button');
87
- }
88
-
89
- public function getBackButtonHtml()
90
- {
91
- return $this->getChildHtml('back_button');
92
- }
93
-
94
- public function getQueueButtonHtml()
95
- {
96
- return $this->getChildHtml('queue_button');
97
- }
98
-
99
- public function backupFileExists()
100
- {
101
- $_image = $this->getImage();
102
-
103
- return file_exists(Mage::getBaseDir().DS.Mage::getStoreConfig('welance_kraken/kraken_config/backup_dir').DS.$_image->getPath().DS.$_image->getImageName());
104
- }
105
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Welance/Kraken/Block/Product/Image.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Welance_Kraken_Block_Product_Image extends Mage_Catalog_Block_Product_View
4
+ {
5
+ public function getConcurrency(){
6
+ return Mage::getStoreConfig('welance_kraken/kraken_config/frontend_concurrency');
7
+ }
8
+
9
+ public function getImagesToOptimize()
10
+ {
11
+ $product = $this->getProduct();
12
+
13
+ $productImages = $this->_getProductImages($product);
14
+
15
+ $resource = Mage::getSingleton('core/resource');
16
+
17
+ $readConnection = $resource->getConnection('core_read');
18
+
19
+ $table = $resource->getTableName('welance_kraken/image_cache');
20
+
21
+ $query = "SELECT * FROM {$table} WHERE (`is_running` = 0 AND `is_processed` = 0) AND (`file_name` LIKE ";
22
+ $i = 0;
23
+ $productImagesCount = count($productImages);
24
+
25
+ foreach ($productImages as $productImage) {
26
+ $query .= "'%".$productImage."%'";
27
+
28
+ $i++;
29
+
30
+ if($i < $productImagesCount){
31
+ $query .= " OR `file_name` LIKE ";
32
+ } else {
33
+ $query .= ")";
34
+ }
35
+
36
+
37
+ }
38
+
39
+ $cacheImages = array();
40
+ foreach($readConnection->fetchAll($query) as $cacheImage){
41
+ $cacheImages[] = array(
42
+ 'id' =>$cacheImage['id'],
43
+ 'product_id' => $product->getId()
44
+ );
45
+ }
46
+
47
+ return json_encode($cacheImages);
48
+ }
49
+
50
+ protected function _getProductImages($product)
51
+ {
52
+ $images = $product->getMediaGalleryImages();
53
+
54
+ $productImages = array();
55
+
56
+ foreach($images as $image){
57
+ $productImages[] = $image['file'];
58
+ }
59
+
60
+ return $productImages;
61
+ }
62
+ }
app/code/local/Welance/Kraken/Model/Image.php DELETED
@@ -1,193 +0,0 @@
1
- <?php
2
- /**
3
- * Class Welance_Kraken_Model_Image
4
- *
5
- * @method datetime setCreatedAt()
6
- * @method datetime getCreatedAt()
7
- * @method string setPath()
8
- * @method string getPath()
9
- * @method string setImageName()
10
- * @method string getImageName()
11
- * @method string setOriginalChecksum()
12
- * @method string getOriginalChecksum()
13
- * @method int setOriginalSize()
14
- * @method int getOriginalSize()
15
- * @method datetime setUploadedAt()
16
- * @method datetime getUploadedAt()
17
- * @method string setUploadedChecksum()
18
- * @method string getUploadedChecksum()
19
- * @method int setUploadedSize()
20
- * @method int getUploadedSize()
21
- * @method int setUploadedSaved()
22
- * @method int getUploadedSaved()
23
- * @method setUploadedSavedPercent()
24
- * @method getUploadedSavedPercent()
25
- * @method boolean getSuccess()
26
- * @method boolean setSuccess()
27
- * @method array setResponseError()
28
- * @method array getResponseError()
29
- */
30
- class Welance_Kraken_Model_Image extends Mage_Core_Model_Abstract
31
- {
32
- const KRAKEN_UPLOAD_API_URL = 'https://api.kraken.io/v1/upload';
33
- const KRAKEN_USER_STATUS_API_URL = 'https://api.kraken.io/user_status';
34
-
35
- protected function _construct()
36
- {
37
- $this->_init('welance_kraken/image');
38
- }
39
-
40
- public function saveImageInQueue($dir,$imageName,$checksum)
41
- {
42
- $this->setCreatedAt(time())
43
- ->setPath($dir)
44
- ->setImageName($imageName)
45
- ->setOriginalChecksum($checksum);
46
- try {
47
-
48
- $this->save();
49
-
50
- } catch(Exception $e){
51
-
52
- Mage::log($e->getMessage(),null,'kraken.log');
53
-
54
- }
55
-
56
- return $this;
57
- }
58
-
59
- public function imageExits($path,$imageName,$checksum)
60
- {
61
- $imageCollection = Mage::getResourceModel('welance_kraken/image_collection')
62
- ->addFieldToFilter('path',$path)
63
- ->addFieldToFilter('image_name',$imageName)
64
- ->addFieldToFilter('original_checksum',$checksum);
65
-
66
- if($imageCollection->getSize() > 0){
67
- return true;
68
- }
69
-
70
- return false;
71
- }
72
-
73
- public function saveResponse($response)
74
- {
75
- if($response->success == true){
76
- if($response->original_size <= $response->kraked_size == false){
77
- $path = Mage::getBaseDir() . DS . $this->getPath() . DS . $this->getImageName();
78
- try{
79
- copy($response->kraked_url,$path);
80
- } catch(Exception $e){
81
- Mage::log($e->getMessage(),null,'kraken_response.log');
82
- }
83
-
84
-
85
- $this->setUploadedAt(time())
86
- ->setOriginalSize($response->original_size)
87
- ->setSuccess($response->success)
88
- ->setSizeAfterUpload($response->kraked_size)
89
- ->setSavedFileSize($response->saved_bytes)
90
- ->setPercentSaved(round(($response->saved_bytes/$this->getOriginalSize())*100,2))
91
- ->setChecksumAfterUpload(sha1_file($path))
92
- ->setResponseError(null)
93
- ->setInQueue(0);
94
- } else {
95
- $this->setUploadedAt(time())
96
- ->setOriginalSize($response->original_size)
97
- ->setSizeAfterUpload($response->original_size)
98
- ->setPercentSaved(0)
99
- ->setSuccess(0)
100
- ->setResponseError(Mage::helper('welance_kraken')->__('No Savings found.'))
101
- ->setInQueue(0);
102
- }
103
-
104
- } else{
105
- $this->setResponseError($response->message)
106
- ->setSuccess(0);
107
- }
108
-
109
- try{
110
- $this->setResponseTime(microtime(true) - $response->startTime);
111
- $this->save();
112
- } catch(Exception $e){
113
- Mage::log($e->getMessage(),null,'kraken_response.log');
114
- }
115
-
116
- return $this;
117
- }
118
-
119
- public function getImages($limit = null, $imageIds = null)
120
- {
121
- $imageCollection = $this->getCollection()
122
- ->addFieldToSelect('*');
123
-
124
- if($imageIds){
125
- $imageCollection->addFieldToFilter('id',array('in' => $imageIds));
126
- } else {
127
- $imageCollection->addFieldToFilter('success',array('null' => true));
128
- }
129
-
130
- if($limit){
131
- $imageCollection->getSelect()->limit($limit);
132
- }
133
-
134
- return $imageCollection;
135
-
136
- }
137
-
138
- public function getImagesFromQueue($limit)
139
- {
140
- $imageCollection = $this->getCollection()
141
- ->addFieldToSelect('*')
142
- ->addFieldToFilter('in_queue',1);
143
-
144
- $imageCollection->getSelect()->limit($limit);
145
-
146
- return $imageCollection;
147
-
148
- }
149
-
150
-
151
- public function clearUploadQueue()
152
- {
153
- $this->setUploadedAt(null)
154
- ->setOriginalSize(null)
155
- ->setSuccess(null)
156
- ->setSizeAfterUpload(null)
157
- ->setSavedFileSize(null)
158
- ->setPercentSaved(null)
159
- ->setChecksumAfterUpload(null)
160
- ->setResponseError(null)
161
- ->setInQueue(0)
162
- ->save();
163
-
164
- return $this;
165
- }
166
-
167
- public function addImagesToQueue($imageIds = null)
168
- {
169
- $imageCollection = $this->getImages(null,$imageIds);
170
-
171
- foreach ($imageCollection as $image){
172
- $image->setInQueue(1)
173
- ->save();
174
- }
175
-
176
- return $this;
177
- }
178
-
179
- public function addAllImagesToQueue()
180
- {
181
- $resource = Mage::getSingleton('core/resource');
182
-
183
- $writeConnection = $resource->getConnection('core_write');
184
-
185
- $table = $resource->getTableName('welance_kraken/image');
186
-
187
- $query = "UPDATE {$table} SET in_queue = 1 WHERE success IS NULL";
188
-
189
- $writeConnection->query($query);
190
-
191
- return $this;
192
- }
193
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Welance/Kraken/Model/Image/Cache.php CHANGED
@@ -8,9 +8,28 @@ class Welance_Kraken_Model_Image_Cache extends Mage_Core_Model_Abstract
8
  }
9
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  /**
12
  * @param $response
13
- * @return bool
14
  */
15
 
16
  public function saveResponse($response)
@@ -20,6 +39,8 @@ class Welance_Kraken_Model_Image_Cache extends Mage_Core_Model_Abstract
20
  $this->setOriginalSize($response->original_size)
21
  ->setSizeAfterUpload($response->kraked_size)
22
  ->setSavedFileSize($response->saved_bytes)
 
 
23
  ->save();
24
 
25
  return $this;
8
  }
9
 
10
 
11
+ /**
12
+ * @param $image
13
+ * @return $this
14
+ */
15
+
16
+ public function saveCacheImage($image)
17
+ {
18
+ $finfo = finfo_open(FILEINFO_MIME_TYPE);
19
+ $mimeType = finfo_file($finfo, $image);
20
+ finfo_close($finfo);
21
+
22
+ $this->setFileName($image)
23
+ ->setMimeType($mimeType)
24
+ ->save();
25
+
26
+ return $this;
27
+ }
28
+
29
+
30
  /**
31
  * @param $response
32
+ * @return mixed
33
  */
34
 
35
  public function saveResponse($response)
39
  $this->setOriginalSize($response->original_size)
40
  ->setSizeAfterUpload($response->kraked_size)
41
  ->setSavedFileSize($response->saved_bytes)
42
+ ->setIsProcessed(1)
43
+ ->setProductId($response->product_id)
44
  ->save();
45
 
46
  return $this;
app/code/local/Welance/Kraken/Model/Observer.php CHANGED
@@ -3,6 +3,11 @@
3
  class Welance_Kraken_Model_Observer
4
  {
5
 
 
 
 
 
 
6
  public function checkVersion($observer)
7
  {
8
  $section = $observer->getEvent()->getControllerAction()->getRequest()->getParam('section');
@@ -28,6 +33,12 @@ class Welance_Kraken_Model_Observer
28
  return $this;
29
  }
30
 
 
 
 
 
 
 
31
  public function checkPlan($observer)
32
  {
33
  $apiKey = Mage::getStoreConfig('welance_kraken/kraken_auth/api_user');
@@ -37,18 +48,7 @@ class Welance_Kraken_Model_Observer
37
  $helper = Mage::helper('welance_kraken/api');
38
  $response = $helper->getUserStatus();
39
  $config = Mage::getModel('core/config');
40
-
41
- if ($response->plan_name == 'Micro' || $response->plan_name == 'Basic') {
42
- $config->saveConfig('welance_kraken/kraken_auth/api_user', null);
43
- $config->saveConfig('welance_kraken/kraken_auth/api_secret', null);
44
- $config->saveConfig('welance_kraken/kraken_auth/kraken_status', 0);
45
-
46
- Mage::getSingleton('adminhtml/session')->addError($helper->__('
47
- We support Magento only from the Advanced plan up. Your current plan is %s.
48
- ', $response->plan_name));
49
- } else {
50
- $config->saveConfig('welance_kraken/kraken_auth/kraken_status',1);
51
- }
52
  }
53
 
54
  return $this;
@@ -63,34 +63,18 @@ class Welance_Kraken_Model_Observer
63
  public function optimizeCacheImage($observer)
64
  {
65
  $cacheImage = $observer->getEvent()->getObject()->getNewFile();
66
- $helper = Mage::helper('welance_kraken/api');
67
-
68
- $auth = $helper->getAuthentication();
69
- $options = $helper->getOptions();
70
-
71
- $data = array_merge(array(
72
- "file" => $cacheImage,
73
- "data" => json_encode(array_merge(
74
- $auth, $options
75
- ))
76
- ));
77
-
78
- try {
79
- $response = $helper->krakenRequest($data, Welance_Kraken_Model_Abstract::KRAKEN_UPLOAD_API_URL);
80
-
81
- if ($response->success == true) {
82
- copy($response->kraked_url,$cacheImage);
83
- Mage::getModel('welance_kraken/image_cache')->saveResponse($response);
84
- } else {
85
- Mage::log($response, null, 'kraken_response.log');
86
- }
87
- } catch (Exception $e) {
88
- Mage::log($e->getMessage(), null, 'kraken_response.log');
89
- }
90
 
91
  return $this;
92
  }
93
 
 
 
 
 
 
 
94
  public function cacheRedirect($observer)
95
  {
96
  $request = Mage::app()->getRequest();
3
  class Welance_Kraken_Model_Observer
4
  {
5
 
6
+ /**
7
+ * @param $observer
8
+ * @return $this
9
+ */
10
+
11
  public function checkVersion($observer)
12
  {
13
  $section = $observer->getEvent()->getControllerAction()->getRequest()->getParam('section');
33
  return $this;
34
  }
35
 
36
+
37
+ /**
38
+ * @param $observer
39
+ * @return $this
40
+ */
41
+
42
  public function checkPlan($observer)
43
  {
44
  $apiKey = Mage::getStoreConfig('welance_kraken/kraken_auth/api_user');
48
  $helper = Mage::helper('welance_kraken/api');
49
  $response = $helper->getUserStatus();
50
  $config = Mage::getModel('core/config');
51
+ $config->saveConfig('welance_kraken/kraken_auth/kraken_status',1);
 
 
 
 
 
 
 
 
 
 
 
52
  }
53
 
54
  return $this;
63
  public function optimizeCacheImage($observer)
64
  {
65
  $cacheImage = $observer->getEvent()->getObject()->getNewFile();
66
+
67
+ Mage::getModel('welance_kraken/image_cache')->saveCacheImage($cacheImage);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  return $this;
70
  }
71
 
72
+
73
+ /**
74
+ * @param $observer
75
+ * @return void
76
+ */
77
+
78
  public function cacheRedirect($observer)
79
  {
80
  $request = Mage::app()->getRequest();
app/code/local/Welance/Kraken/Model/Resource/Image.php DELETED
@@ -1,9 +0,0 @@
1
- <?php
2
-
3
- class Welance_Kraken_Model_Resource_Image extends Mage_Core_Model_Resource_Db_Abstract
4
- {
5
- protected function _construct()
6
- {
7
- $this->_init('welance_kraken/image','id');
8
- }
9
- }
 
 
 
 
 
 
 
 
 
app/code/local/Welance/Kraken/Model/Resource/Image/Collection.php DELETED
@@ -1,9 +0,0 @@
1
- <?php
2
-
3
- class Welance_Kraken_Model_Resource_Image_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
- {
5
- protected function _construct()
6
- {
7
- $this->_init('welance_kraken/image');
8
- }
9
- }
 
 
 
 
 
 
 
 
 
app/code/local/Welance/Kraken/controllers/OptimizeController.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Welance_Kraken_OptimizeController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ private function _initCacheImage($id)
6
+ {
7
+ $cacheImage = Mage::getModel('welance_kraken/image_cache')->load($id);
8
+
9
+ if ($cacheImage->getIsRunning() != 1) {
10
+ $cacheImage->setIsRunning(1)->save();
11
+ } else {
12
+ $cacheImage = false;
13
+ }
14
+
15
+ return $cacheImage;
16
+ }
17
+
18
+ public function cacheAction()
19
+ {
20
+ $request = $this->getRequest();
21
+
22
+ if ($request->isPost()) {
23
+ $cacheImage = $this->_initCacheImage($request->getParam('id'));
24
+
25
+ if ($cacheImage != false) {
26
+ $fileName = $cacheImage->getFileName();
27
+
28
+ $helper = Mage::helper('welance_kraken/api');
29
+
30
+ $auth = $helper->getAuthentication();
31
+ $options = $helper->getOptions();
32
+
33
+ $data = array_merge(array(
34
+ "file" => $fileName,
35
+ "data" => json_encode(array_merge(
36
+ $auth, $options
37
+ ))
38
+ ));
39
+
40
+ try {
41
+ $response = $helper->krakenRequest($data, Welance_Kraken_Model_Abstract::KRAKEN_UPLOAD_API_URL);
42
+
43
+ if ($response->success == true) {
44
+ $response->product_id = $request->getParam('product_id');
45
+
46
+ copy($response->kraked_url,$fileName);
47
+
48
+ $cacheImage->saveResponse($response);
49
+
50
+ $this->getResponse()->setHeader('Content-type', 'application/json');
51
+ $this->getResponse()->setBody(json_encode($response));
52
+ } else {
53
+ Mage::log($response, null, 'kraken_response.log');
54
+ }
55
+ } catch(Exception $e) {
56
+ Mage::log($e->getMessage(), null, 'kraken_response.log');
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
app/code/local/Welance/Kraken/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Welance_Kraken>
5
- <version>0.0.5</version>
6
  </Welance_Kraken>
7
  </modules>
8
  <global>
@@ -65,10 +65,10 @@
65
  </admin_system_config_section_save_after>
66
  <catalog_product_image_save_after>
67
  <observers>
68
- <tiny_compressimages>
69
  <class>welance_kraken/observer</class>
70
  <method>optimizeCacheImage</method>
71
- </tiny_compressimages>
72
  </observers>
73
  </catalog_product_image_save_after>
74
  <clean_catalog_images_cache_after>
@@ -108,6 +108,24 @@
108
  </updates>
109
  </layout>
110
  </adminhtml>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  <default>
112
  <welance_kraken>
113
  <kraken_config>
@@ -115,6 +133,7 @@
115
  <compression>0</compression>
116
  <quality>80</quality>
117
  <concurrency>4</concurrency>
 
118
  </kraken_config>
119
  </welance_kraken>
120
  </default>
2
  <config>
3
  <modules>
4
  <Welance_Kraken>
5
+ <version>2.0.0</version>
6
  </Welance_Kraken>
7
  </modules>
8
  <global>
65
  </admin_system_config_section_save_after>
66
  <catalog_product_image_save_after>
67
  <observers>
68
+ <welance_kraken_cache>
69
  <class>welance_kraken/observer</class>
70
  <method>optimizeCacheImage</method>
71
+ </welance_kraken_cache>
72
  </observers>
73
  </catalog_product_image_save_after>
74
  <clean_catalog_images_cache_after>
108
  </updates>
109
  </layout>
110
  </adminhtml>
111
+ <frontend>
112
+ <routers>
113
+ <welance_kraken>
114
+ <use>standard</use>
115
+ <args>
116
+ <module>Welance_Kraken</module>
117
+ <frontName>kraken</frontName>
118
+ </args>
119
+ </welance_kraken>
120
+ </routers>
121
+ <layout>
122
+ <updates>
123
+ <welance_kraken>
124
+ <file>kraken.xml</file>
125
+ </welance_kraken>
126
+ </updates>
127
+ </layout>
128
+ </frontend>
129
  <default>
130
  <welance_kraken>
131
  <kraken_config>
133
  <compression>0</compression>
134
  <quality>80</quality>
135
  <concurrency>4</concurrency>
136
+ <frontend_concurrency>3</frontend_concurrency>
137
  </kraken_config>
138
  </welance_kraken>
139
  </default>
app/code/local/Welance/Kraken/etc/system.xml CHANGED
@@ -113,8 +113,8 @@
113
  </depends>
114
  </quality>
115
  <concurrency>
116
- <label>Concurrency (advanced)</label>
117
- <comment>Number of concurrent HTTP requests to Kraken.io API when optimizing Skin and Media folders</comment>
118
  <frontend_type>select</frontend_type>
119
  <source_model>welance_kraken/adminhtml_system_config_source_concurrency</source_model>
120
  <sort_order>40</sort_order>
@@ -122,6 +122,16 @@
122
  <show_in_website>1</show_in_website>
123
  <show_in_store>1</show_in_store>
124
  </concurrency>
 
 
 
 
 
 
 
 
 
 
125
  </fields>
126
  </kraken_config>
127
  </groups>
113
  </depends>
114
  </quality>
115
  <concurrency>
116
+ <label>HTTP Concurrency for Media and Skin images (advanced)</label>
117
+ <comment>Number of concurrent HTTP requests to Kraken.io API when optimizing Media and Skin images</comment>
118
  <frontend_type>select</frontend_type>
119
  <source_model>welance_kraken/adminhtml_system_config_source_concurrency</source_model>
120
  <sort_order>40</sort_order>
122
  <show_in_website>1</show_in_website>
123
  <show_in_store>1</show_in_store>
124
  </concurrency>
125
+ <frontend_concurrency>
126
+ <label>HTTP Concurrency for Product images (advanced)</label>
127
+ <comment>Number of concurrent HTTP requests to Kraken.io API when optimizing Product images</comment>
128
+ <frontend_type>select</frontend_type>
129
+ <source_model>welance_kraken/adminhtml_system_config_source_concurrency</source_model>
130
+ <sort_order>50</sort_order>
131
+ <show_in_default>1</show_in_default>
132
+ <show_in_website>1</show_in_website>
133
+ <show_in_store>1</show_in_store>
134
+ </frontend_concurrency>
135
  </fields>
136
  </kraken_config>
137
  </groups>
app/code/local/Welance/Kraken/sql/welance_kraken_setup/mysql4-upgrade-0.0.5-0.0.6.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $table = $installer->getTable('welance_kraken/image_cache');
7
+ $installer->getConnection()
8
+ ->addColumn($table,
9
+ 'file_name',
10
+ array(
11
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
12
+ 'nullable' => true,
13
+ 'comment' => 'File Name'
14
+ )
15
+ );
16
+
17
+ $installer->getConnection()
18
+ ->addColumn($table,
19
+ 'mime_type',
20
+ array(
21
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
22
+ 'nullable' => true,
23
+ 'comment' => 'Mime Type'
24
+ )
25
+ );
26
+
27
+ $installer->endSetup();
app/code/local/Welance/Kraken/sql/welance_kraken_setup/mysql4-upgrade-0.0.6-2.0.0.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $table = $installer->getTable('welance_kraken/image_cache');
7
+ $installer->getConnection()
8
+ ->addColumn($table,
9
+ 'is_running',
10
+ array(
11
+ 'type' => Varien_Db_Ddl_Table::TYPE_BOOLEAN,
12
+ 'nullable' => true,
13
+ 'default' => 0,
14
+ 'comment' => 'Is Running'
15
+ )
16
+ );
17
+
18
+ $installer->getConnection()
19
+ ->addColumn($table,
20
+ 'is_processed',
21
+ array(
22
+ 'type' => Varien_Db_Ddl_Table::TYPE_BOOLEAN,
23
+ 'nullable' => true,
24
+ 'default' => 0,
25
+ 'comment' => 'Is Processed'
26
+ )
27
+ );
28
+
29
+ $installer->getConnection()
30
+ ->addColumn($table,
31
+ 'product_id',
32
+ array(
33
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
34
+ 'nullable' => true,
35
+ 'unsigned' => true,
36
+ 'comment' => 'Product Id'
37
+ )
38
+ );
39
+
40
+ $installer->endSetup();
app/code/local/Welance/Kraken/sql/welance_kraken_setup/mysql4-upgrade-1.0.0-2.0.0.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $table = $installer->getTable('welance_kraken/image_cache');
7
+ $installer->getConnection()
8
+ ->addColumn($table,
9
+ 'is_running',
10
+ array(
11
+ 'type' => Varien_Db_Ddl_Table::TYPE_BOOLEAN,
12
+ 'nullable' => true,
13
+ 'default' => 0,
14
+ 'comment' => 'Is Running'
15
+ )
16
+ );
17
+
18
+ $installer->getConnection()
19
+ ->addColumn($table,
20
+ 'is_processed',
21
+ array(
22
+ 'type' => Varien_Db_Ddl_Table::TYPE_BOOLEAN,
23
+ 'nullable' => true,
24
+ 'default' => 0,
25
+ 'comment' => 'Is Processed'
26
+ )
27
+ );
28
+
29
+ $installer->getConnection()
30
+ ->addColumn($table,
31
+ 'product_id',
32
+ array(
33
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
34
+ 'nullable' => true,
35
+ 'unsigned' => true,
36
+ 'comment' => 'Product Id'
37
+ )
38
+ );
39
+
40
+ $installer->endSetup();
app/design/adminhtml/default/default/template/kraken/image.phtml DELETED
@@ -1,44 +0,0 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package default_default
23
- * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
- */
26
- ?>
27
- <?php
28
- /**
29
- * @see Mage_Adminhtml_Block_Catalog_Product
30
- */
31
- ?>
32
- <div class="content-header">
33
- <table cellspacing="0">
34
- <tr>
35
- <td style="width:50%;"><h3 class="icon-head head-images"><?php echo Mage::helper('welance_kraken')->__('Manage Images') ?></h3></td>
36
- <td class="a-right">
37
- <?php echo $this->getButtonsHtml() ?>
38
- </td>
39
- </tr>
40
- </table>
41
- </div>
42
- <div>
43
- <?php echo $this->getGridHtml() ?>
44
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/design/adminhtml/default/default/template/kraken/image/view.phtml DELETED
@@ -1,55 +0,0 @@
1
- <?php
2
- $_image = $this->getImage();
3
- $image = $_image->getData();
4
- $helper = Mage::helper('welance_kraken');
5
-
6
- //unset not needed columns
7
- unset($image['original_checksum']);
8
- unset($image['checksum_after_upload']);
9
- unset($image['success']);
10
- unset($image['response_time']);
11
-
12
- //convert sizes
13
- $image['original_size'] = $helper->getImageSizeConverted($image['original_size']);
14
- $image['size_after_upload'] = $helper->getImageSizeConverted($image['size_after_upload']);
15
- $image['saved_file_size'] = $helper->getImageSizeConverted($image['saved_file_size']);
16
-
17
- $header = array_keys($image);
18
- $columns = array_values($image);
19
-
20
- ?>
21
- <div class="content-header">
22
- <h3 class="icon-head head-images"><?php echo $this->__('View Image') ?></h3>
23
- <p class="content-buttons form-buttons">
24
- <?php echo $this->getBackButtonHtml() ?>
25
- <?php if($this->backupFileExists()): ?>
26
- <?php echo $this->getRestoreButtonHtml() ?>
27
- <?php endif; ?>
28
- <?php echo $this->getOptimizeButtonHtml() ?>
29
- <?php echo $this->getQueueButtonHtml() ?>
30
- </p>
31
- </div>
32
- <div class="grid">
33
- <table class="data-table" cellspacing="0">
34
- <thead>
35
- <tr class="headings">
36
- <th><?php echo $this->__('Image') ?></th>
37
- <?php foreach($header as $head): ?>
38
- <th><?php echo $helper->mapTableHeader($head) ?></th>
39
- <?php endforeach; ?>
40
- </tr>
41
- </thead>
42
- <tbody>
43
- <tr>
44
- <td width="300">
45
- <a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).$image['path'] . DS . $image['image_name'] ?>">
46
- <img width="300" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).$image['path'] . DS . $image['image_name'] ?>" alt="<?php echo $image['image_name'] ?>"/>
47
- </a>
48
- </td>
49
- <?php foreach($columns as $column): ?>
50
- <td><?php echo $column ?></td>
51
- <?php endforeach; ?>
52
- </tr>
53
- </tbody>
54
- </table>
55
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/design/frontend/base/default/layout/kraken.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <layout>
4
+ <catalog_product_view>
5
+ <reference name="head">
6
+ <action method="addJs"><script>kraken/async.js</script></action>
7
+ <action method="addJs"><script>kraken/optimize.js</script></action>
8
+ </reference>
9
+ <reference name="before_body_end">
10
+ <block type="welance_kraken/product_image" name="welance.kraken.cache.optimizer" as="cacheOptimizer" template="kraken/product/image.phtml" />
11
+ </reference>
12
+ </catalog_product_view>
13
+ </layout>
app/design/frontend/base/default/template/kraken/product/image.phtml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ var cacheImages = <?php echo $this->getImagesToOptimize(); ?>;
3
+ var requestUrl = '<?php echo Mage::getUrl('kraken/optimize/cache') ?>';
4
+ var cacheConcurrency = <?php echo $this->getConcurrency() ?>;
5
+
6
+ document.observe("dom:loaded", function() {
7
+ optimizeImages.optimizeCache(cacheImages);
8
+ });
9
+ </script>
js/kraken/optimize.js CHANGED
@@ -3,6 +3,7 @@
3
  /* global Ajax:true */
4
  /* global requestUrl:true */
5
  /* global concurrency:true */
 
6
 
7
  "use strict";
8
 
@@ -116,5 +117,26 @@ window.optimizeImages = {
116
  .addClass("with-success");
117
  }, 500);
118
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  }
120
  };
3
  /* global Ajax:true */
4
  /* global requestUrl:true */
5
  /* global concurrency:true */
6
+ /* global cacheConcurrency:true */
7
 
8
  "use strict";
9
 
117
  .addClass("with-success");
118
  }, 500);
119
  };
120
+ },
121
+
122
+ optimizeCache: function (images) {
123
+ var queue = async.queue(function (task, callback) {
124
+ new Ajax.Request(requestUrl, {
125
+ method: "post",
126
+ parameters: {
127
+ id: task.file.id,
128
+ product_id: task.file.product_id
129
+ },
130
+ onComplete: function () {
131
+ callback();
132
+ }
133
+ });
134
+ }, cacheConcurrency);
135
+
136
+ for (var i = 0, ii = images.length; i < ii; i++) {
137
+ queue.push({
138
+ file: images[i]
139
+ });
140
+ }
141
  }
142
  };
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Kraken_Image_Optimizer</name>
4
- <version>1.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/GPL-3.0">GNU General Public License (GPL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>This extension enables Magento users to optimize their product, skin and media images by consuming the Kraken.io image optimization API. (https://kraken.io)</summary>
10
  <description>This extension exists for the sole purpose of allowing Magento users to optimize their product, skin and media images by consuming the Kraken.io image optimization API. (https://kraken.io)</description>
11
- <notes>Initial release</notes>
12
  <authors><author><name>Nekkra UG</name><user>KrakenIO</user><email>support@kraken.io</email></author></authors>
13
- <date>2015-08-26</date>
14
- <time>13:45:24</time>
15
- <contents><target name="magelocal"><dir name="Welance"><dir name="Kraken"><dir name="Block"><dir name="Adminhtml"><dir name="Api"><file name="Signup.php" hash="56a9ee65c5d9fd769b7a5a0854b71a16"/><file name="Status.php" hash="99dd2cb6da9d62e4d8cab36ea29d13e5"/><dir name="User"><file name="Status.php" hash="f33827a151d7ccd76684dde79599c3a2"/></dir></dir><dir name="Image"><file name="Grid.php" hash="72f544e5cfd2159ee7e09b08a1bc4694"/><dir name="Renderer"><file name="Size.php" hash="63bb76f50cf43957b5bcbbb6a07999de"/></dir><file name="View.php" hash="74fd64e723cbd690a0b70679f7d9f76f"/></dir><file name="Image.php" hash="ef98bece02eadf713971cb749821889d"/><dir name="Images"><file name="Media.php" hash="77eb4d764772f688e00f56b6e843a0dc"/><file name="Skin.php" hash="64fc3067df5e8a70d502e54e21f15408"/></dir><file name="Images.php" hash="77fe1a1c7a0fb28209a741266467db69"/><file name="Statistics.php" hash="6cdae1bc41185b93c49d97465ee75704"/></dir></dir><dir name="Helper"><file name="Api.php" hash="bdad47443f357c6241005b76304d985e"/><file name="Data.php" hash="b0821b62fd1bb1629e1fced76e1c9ee4"/></dir><dir name="Model"><file name="Abstract.php" hash="46ad69f601aa392e44fadf43dc8ff558"/><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Backend"><dir name="Validation"><file name="File.php" hash="03b116c93529a00f064c428519415b90"/><file name="Quality.php" hash="63919067f4576cc1a0c6ef663b1d1779"/></dir></dir><dir name="Source"><file name="Compression.php" hash="516d83f51e2216b45e51d20d6d1f8575"/><file name="Concurrency.php" hash="436d106916fae3d01bd7272e34d9771c"/></dir></dir></dir></dir><dir name="Image"><file name="Cache.php" hash="3c1c837621f705459fe6ba70746e64f7"/></dir><file name="Image.php" hash="91ab7ef31025523e12b3815a7a86e636"/><dir name="Images"><file name="Media.php" hash="3d73a5ba9276744d92de042f4ca5d228"/><file name="Skin.php" hash="d6181c6772baa9a84d26e6adda5c87be"/></dir><file name="Observer.php" hash="2b2fb4d4eda770c9c9df88b27bb00b1a"/><dir name="Product"><file name="Image.php" hash="11c24a47125de4787bf082a2227c1e77"/></dir><dir name="Resource"><dir name="Image"><dir name="Cache"><file name="Collection.php" hash="4f29016539f9586ba707c1815f1e12b6"/></dir><file name="Cache.php" hash="7058d029a436aa3d0be1dc6f3c7fae57"/><file name="Collection.php" hash="b51abb91b1d08c3b99ca589b8ed58ca7"/></dir><file name="Image.php" hash="6240d7d9812e13280b37c2d2c586c8f9"/><dir name="Images"><dir name="Media"><file name="Collection.php" hash="e77abb3c2122a0f5582bf14739935d85"/></dir><file name="Media.php" hash="c6aa05e4362b645b001854e9578ee5d1"/><dir name="Skin"><file name="Collection.php" hash="2e81919a1fa3014a9083b12382fc46e0"/></dir><file name="Skin.php" hash="420d0b85798bbd5eb52d40d96eff2868"/></dir></dir></dir><dir name="controllers"><file name="KrakenController.php" hash="d00de7431a787527e6b84b79dc5df547"/></dir><dir name="etc"><file name="adminhtml.xml" hash="71d3f77d2a29e267a1b3b172ac457ccc"/><file name="config.xml" hash="f7c4a0dc5ab2775af069693d987d14f2"/><file name="system.xml" hash="80f0b05bf2cb449789e2f0f63df0522d"/></dir><dir name="sql"><dir name="welance_kraken_setup"><file name="mysql4-install-0.0.1.php" hash="c672010d8288677aea0d008a4ec49d0f"/><file name="mysql4-upgrade-0.0.1-0.0.2.php" hash="f6ec9a39c730faa436d29338b35a21b2"/><file name="mysql4-upgrade-0.0.2-0.0.3.php" hash="884f018b06073d09cd38094251316a12"/><file name="mysql4-upgrade-0.0.3-0.0.4.php" hash="21b4fed490c176909fc54d36f49b6caa"/><file name="mysql4-upgrade-0.0.4-0.0.5.php" hash="3399d922082321a9c9fdb3f4d8ddbbb0"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="kraken"><dir name="image"><file name="view.phtml" hash="a6a5728d7d42a8fc1681acced43655be"/></dir><file name="image.phtml" hash="81fc875eef9809755cf822c45de0dfb2"/><dir name="images"><file name="media.phtml" hash="662b54090542b27b1a4b150c0cf11af7"/><file name="skin.phtml" hash="6210665eeb18370b4afb942c72d84a21"/></dir><file name="images.phtml" hash="f4a3760c6340e2a83569a715975c0a88"/><file name="statistics.phtml" hash="f2ac7696fcdc49f3ce74970059ee486e"/></dir></dir><dir name="layout"><file name="kraken.xml" hash="835ecb50d3589a96a696221c59cb9827"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Welance_Kraken.xml" hash="5924028abd4db847049907d0685fe928"/></dir></target><target name="mageweb"><dir name="js"><dir name="kraken"><file name="async.js" hash="69a9fc4244b4ed9465d9dc17bfec7e8e"/><file name="jquery.js" hash="895323ed2f7258af4fae2c738c8aea49"/><file name="optimize.js" hash="f115b32b3ea738233d2c7ceabaa60823"/></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="kraken"><file name="images.css" hash="4efcb99215e85cea9ef8904594b35d06"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Kraken_Image_Optimizer</name>
4
+ <version>2.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/GPL-3.0">GNU General Public License (GPL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>This extension enables Magento users to optimize their product, skin and media images by consuming the Kraken.io image optimization API. (https://kraken.io)</summary>
10
  <description>This extension exists for the sole purpose of allowing Magento users to optimize their product, skin and media images by consuming the Kraken.io image optimization API. (https://kraken.io)</description>
11
+ <notes>Rewritten image cache optimization now uses AJAX requests to optimize images in the background.</notes>
12
  <authors><author><name>Nekkra UG</name><user>KrakenIO</user><email>support@kraken.io</email></author></authors>
13
+ <date>2015-09-10</date>
14
+ <time>19:44:38</time>
15
+ <contents><target name="magelocal"><dir name="Welance"><dir name="Kraken"><dir name="Block"><dir name="Adminhtml"><dir name="Api"><file name="Signup.php" hash="56a9ee65c5d9fd769b7a5a0854b71a16"/><file name="Status.php" hash="99dd2cb6da9d62e4d8cab36ea29d13e5"/><dir name="User"><file name="Status.php" hash="f33827a151d7ccd76684dde79599c3a2"/></dir></dir><dir name="Images"><file name="Media.php" hash="77eb4d764772f688e00f56b6e843a0dc"/><file name="Skin.php" hash="64fc3067df5e8a70d502e54e21f15408"/></dir><file name="Images.php" hash="77fe1a1c7a0fb28209a741266467db69"/><file name="Statistics.php" hash="6cdae1bc41185b93c49d97465ee75704"/></dir><dir name="Product"><file name="Image.php" hash="b364f7c7b20ee504de167fac52cb770d"/></dir></dir><dir name="Helper"><file name="Api.php" hash="bdad47443f357c6241005b76304d985e"/><file name="Data.php" hash="b0821b62fd1bb1629e1fced76e1c9ee4"/></dir><dir name="Model"><file name="Abstract.php" hash="46ad69f601aa392e44fadf43dc8ff558"/><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Backend"><dir name="Validation"><file name="File.php" hash="03b116c93529a00f064c428519415b90"/><file name="Quality.php" hash="63919067f4576cc1a0c6ef663b1d1779"/></dir></dir><dir name="Source"><file name="Compression.php" hash="516d83f51e2216b45e51d20d6d1f8575"/><file name="Concurrency.php" hash="436d106916fae3d01bd7272e34d9771c"/></dir></dir></dir></dir><dir name="Image"><file name="Cache.php" hash="b1405ed2975e5b2fa0136f7722f03828"/></dir><dir name="Images"><file name="Media.php" hash="3d73a5ba9276744d92de042f4ca5d228"/><file name="Skin.php" hash="d6181c6772baa9a84d26e6adda5c87be"/></dir><file name="Observer.php" hash="8e27670e4c5ce3d62d0fcc5b27b6972a"/><dir name="Product"><file name="Image.php" hash="11c24a47125de4787bf082a2227c1e77"/></dir><dir name="Resource"><dir name="Image"><dir name="Cache"><file name="Collection.php" hash="4f29016539f9586ba707c1815f1e12b6"/></dir><file name="Cache.php" hash="7058d029a436aa3d0be1dc6f3c7fae57"/></dir><dir name="Images"><dir name="Media"><file name="Collection.php" hash="e77abb3c2122a0f5582bf14739935d85"/></dir><file name="Media.php" hash="c6aa05e4362b645b001854e9578ee5d1"/><dir name="Skin"><file name="Collection.php" hash="2e81919a1fa3014a9083b12382fc46e0"/></dir><file name="Skin.php" hash="420d0b85798bbd5eb52d40d96eff2868"/></dir></dir></dir><dir name="controllers"><file name="KrakenController.php" hash="d00de7431a787527e6b84b79dc5df547"/><file name="OptimizeController.php" hash="d4a7b8d09b951960c6afd93ea4a3bda9"/></dir><dir name="etc"><file name="adminhtml.xml" hash="71d3f77d2a29e267a1b3b172ac457ccc"/><file name="config.xml" hash="67cae4fb5a3e87dcef4887381ca14989"/><file name="system.xml" hash="083bab919a0a16a8ab546815d7526850"/></dir><dir name="sql"><dir name="welance_kraken_setup"><file name="mysql4-install-0.0.1.php" hash="c672010d8288677aea0d008a4ec49d0f"/><file name="mysql4-upgrade-0.0.1-0.0.2.php" hash="f6ec9a39c730faa436d29338b35a21b2"/><file name="mysql4-upgrade-0.0.2-0.0.3.php" hash="884f018b06073d09cd38094251316a12"/><file name="mysql4-upgrade-0.0.3-0.0.4.php" hash="21b4fed490c176909fc54d36f49b6caa"/><file name="mysql4-upgrade-0.0.4-0.0.5.php" hash="3399d922082321a9c9fdb3f4d8ddbbb0"/><file name="mysql4-upgrade-0.0.5-0.0.6.php" hash="8084b2f3b1fe2bad7bbbbd1136974289"/><file name="mysql4-upgrade-0.0.6-2.0.0.php" hash="a62483557a3d026e7c2b57999f8924a4"/><file name="mysql4-upgrade-1.0.0-2.0.0.php" hash="a62483557a3d026e7c2b57999f8924a4"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="kraken.xml" hash="835ecb50d3589a96a696221c59cb9827"/></dir><dir name="template"><dir name="kraken"><dir name="images"><file name="media.phtml" hash="662b54090542b27b1a4b150c0cf11af7"/><file name="skin.phtml" hash="6210665eeb18370b4afb942c72d84a21"/></dir><file name="images.phtml" hash="f4a3760c6340e2a83569a715975c0a88"/><file name="statistics.phtml" hash="f2ac7696fcdc49f3ce74970059ee486e"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="kraken.xml" hash="2aba104d03acad3a4703a9b5c7d527b3"/></dir><dir name="template"><dir name="kraken"><dir name="product"><file name="image.phtml" hash="bc755f1aba5bccf9777cc34e1b0b403c"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Welance_Kraken.xml" hash="5924028abd4db847049907d0685fe928"/></dir></target><target name="mageweb"><dir name="js"><dir name="kraken"><file name="async.js" hash="69a9fc4244b4ed9465d9dc17bfec7e8e"/><file name="jquery.js" hash="895323ed2f7258af4fae2c738c8aea49"/><file name="optimize.js" hash="25610ab8c84a9f24b9982b96d95e6096"/></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="kraken"><file name="images.css" hash="4efcb99215e85cea9ef8904594b35d06"/><file name="kraken-tile.png" hash="dca7a9d6784bf34d32d71560f1744fae"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
skin/adminhtml/default/default/kraken/kraken-tile.png ADDED
Binary file