Version Notes
stable version V2
Download this release
Release Info
Developer | Ray Zhang |
Extension | rapido_image_optimizer |
Version | 15.98.2 |
Comparing to | |
See all releases |
Version 15.98.2
- app/code/community/Rapido/ImageOptimizer/Block/Api/Check.php +30 -0
- app/code/community/Rapido/ImageOptimizer/Block/Images/List.php +29 -0
- app/code/community/Rapido/ImageOptimizer/Block/Images/List/Grid.php +119 -0
- app/code/community/Rapido/ImageOptimizer/Block/Images/List/Totals.php +61 -0
- app/code/community/Rapido/ImageOptimizer/Helper/Data.php +336 -0
- app/code/community/Rapido/ImageOptimizer/Model/Cron.php +49 -0
- app/code/community/Rapido/ImageOptimizer/Model/Images.php +20 -0
- app/code/community/Rapido/ImageOptimizer/Model/Resource/Images.php +10 -0
- app/code/community/Rapido/ImageOptimizer/Model/Resource/Images/Collection.php +13 -0
- app/code/community/Rapido/ImageOptimizer/Model/Status.php +31 -0
- app/code/community/Rapido/ImageOptimizer/Model/System/Config/Source/Amount.php +16 -0
- app/code/community/Rapido/ImageOptimizer/Model/System/Config/Source/Extensions.php +16 -0
- app/code/community/Rapido/ImageOptimizer/controllers/Tools/Image/OptimizerController.php +36 -0
- app/code/community/Rapido/ImageOptimizer/etc/adminhtml.xml +37 -0
- app/code/community/Rapido/ImageOptimizer/etc/config.xml +106 -0
- app/code/community/Rapido/ImageOptimizer/etc/system.xml +100 -0
- app/code/community/Rapido/ImageOptimizer/sql/rapido_imageoptimizer_setup/install-1.0.0.php +33 -0
- app/design/adminhtml/default/default/layout/rapido/imageoptimizer.xml +8 -0
- app/design/adminhtml/default/default/template/rapido/imageoptimizer/totals.phtml +47 -0
- app/design/adminhtml/default/default/template/rapido/imageoptimizer/widget/grid/container.phtml +40 -0
- app/etc/modules/Rapido_ImageOptimizer.xml +9 -0
- package.xml +18 -0
- shell/imageoptimizer.php +91 -0
- skin/adminhtml/default/default/rapido/imageoptimizer.css +4 -0
app/code/community/Rapido/ImageOptimizer/Block/Api/Check.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Block_Api_Check extends Mage_Adminhtml_Block_System_Config_Form_Field
|
4 |
+
{
|
5 |
+
|
6 |
+
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
7 |
+
{
|
8 |
+
$this->setElement($element);
|
9 |
+
$buttonHtml = $this->_getAddRowButtonHtml($this->__('Check Account'));
|
10 |
+
return $buttonHtml;
|
11 |
+
}
|
12 |
+
|
13 |
+
|
14 |
+
protected function _getAddRowButtonHtml($title)
|
15 |
+
{
|
16 |
+
$buttonBlock = $this->getElement()->getForm()->getParent()->getLayout()->createBlock('adminhtml/widget_button');
|
17 |
+
$url = $this->getUrl("adminhtml/tools_image_optimizer/check");
|
18 |
+
|
19 |
+
$buttonHtml = $this->getLayout()->createBlock('adminhtml/widget_button')
|
20 |
+
->setType('button')
|
21 |
+
->setLabel($this->__($title))
|
22 |
+
->setOnClick("window.location.href='".$url."'")
|
23 |
+
->toHtml();
|
24 |
+
|
25 |
+
return $buttonHtml;
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Block/Images/List.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Block_Images_List extends Mage_Adminhtml_Block_Widget_Grid_Container
|
4 |
+
{
|
5 |
+
|
6 |
+
public function __construct()
|
7 |
+
{
|
8 |
+
parent::__construct();
|
9 |
+
$this->setTemplate('rapido/imageoptimizer/widget/grid/container.phtml');
|
10 |
+
$this->_removeButton('add');
|
11 |
+
|
12 |
+
$this->_headerText = Mage::helper('rapido_imageoptimizer')->__('Image Optimizer Queue');
|
13 |
+
$this->_blockGroup = 'rapido_imageoptimizer';
|
14 |
+
$this->_controller = 'images_list';
|
15 |
+
}
|
16 |
+
|
17 |
+
protected function _prepareLayout()
|
18 |
+
{
|
19 |
+
$this->setChild('totals',
|
20 |
+
$this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_totals',
|
21 |
+
$this->_controller . '.totals') );
|
22 |
+
return parent::_prepareLayout();
|
23 |
+
}
|
24 |
+
|
25 |
+
public function getTotalsHtml()
|
26 |
+
{
|
27 |
+
return $this->getChildHtml('totals');
|
28 |
+
}
|
29 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Block/Images/List/Grid.php
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Block_Images_List_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
4 |
+
{
|
5 |
+
|
6 |
+
public function __construct()
|
7 |
+
{
|
8 |
+
parent::__construct();
|
9 |
+
$this->setId('RapidoImageOptimizerGrid');
|
10 |
+
$this->_controller = 'images';
|
11 |
+
$this->setUseAjax(true);
|
12 |
+
$this->setDefaultSort('converted_date');
|
13 |
+
$this->setDefaultDir('DESC');
|
14 |
+
$this->setSaveParametersInSession(true);
|
15 |
+
$this->setEmptyText(Mage::helper('rapido_imageoptimizer')->__('No Images to Optimize in the Queue!'));
|
16 |
+
}
|
17 |
+
|
18 |
+
protected function _getCollectionClass()
|
19 |
+
{
|
20 |
+
return 'rapido_imageoptimizer/images';
|
21 |
+
}
|
22 |
+
|
23 |
+
protected function _prepareCollection()
|
24 |
+
{
|
25 |
+
$collection = Mage::getModel($this->_getCollectionClass())->getCollection();
|
26 |
+
$this->setCollection($collection);
|
27 |
+
|
28 |
+
return parent::_prepareCollection();
|
29 |
+
}
|
30 |
+
|
31 |
+
|
32 |
+
protected function _prepareColumns()
|
33 |
+
{
|
34 |
+
$this->addColumn('entity_id', array('header' => Mage::helper('rapido_imageoptimizer')->__('ID'),
|
35 |
+
'align' => 'right',
|
36 |
+
'width' => '80px',
|
37 |
+
'filter_index' => 'entity_id',
|
38 |
+
'index' => 'entity_id',));
|
39 |
+
|
40 |
+
$this->addColumn('createdate', array('header' => Mage::helper('rapido_imageoptimizer')
|
41 |
+
->__('Created at'),
|
42 |
+
'align' => 'left',
|
43 |
+
'width' => '160px',
|
44 |
+
'type' => 'datetime',
|
45 |
+
'filter_index' => 'createdate',
|
46 |
+
'index' => 'createdate',));
|
47 |
+
|
48 |
+
$this->addColumn('image_name', array('header' => Mage::helper('rapido_imageoptimizer')->__('Image Name'),
|
49 |
+
'filter_index' => 'image_name',
|
50 |
+
'index' => 'image_name',));
|
51 |
+
|
52 |
+
$this->addColumn('status', array('header' => Mage::helper('rapido_imageoptimizer')->__('Status'),
|
53 |
+
'index' => 'status',
|
54 |
+
'width' => '100px',
|
55 |
+
'type' => 'options',
|
56 |
+
'options' => Mage::getModel('rapido_imageoptimizer/status')
|
57 |
+
->toOptionHash(),));
|
58 |
+
|
59 |
+
$this->addColumn('converted_date', array('header' => Mage::helper('rapido_imageoptimizer')
|
60 |
+
->__('Converted at'),
|
61 |
+
'align' => 'left',
|
62 |
+
'width' => '160px',
|
63 |
+
'type' => 'datetime',
|
64 |
+
'filter_index' => 'converted_date',
|
65 |
+
'index' => 'converted_date',));
|
66 |
+
|
67 |
+
$this->addColumn('original_size', array('header' => Mage::helper('rapido_imageoptimizer')->__('Original Size'),
|
68 |
+
'align' => 'right',
|
69 |
+
'width' => '120px',
|
70 |
+
'type' => 'number',
|
71 |
+
'filter_index' => 'original_size',
|
72 |
+
'index' => 'original_size',));
|
73 |
+
|
74 |
+
$this->addColumn(
|
75 |
+
'converted_size',
|
76 |
+
array(
|
77 |
+
'header' => Mage::helper('rapido_imageoptimizer')->__('Converted Size'),
|
78 |
+
'align' => 'right',
|
79 |
+
'width' => '120px',
|
80 |
+
'type' => 'number',
|
81 |
+
'filter_index' => 'converted_size',
|
82 |
+
'index' => 'converted_size',
|
83 |
+
)
|
84 |
+
);
|
85 |
+
|
86 |
+
$this->addColumn(
|
87 |
+
'converted_saved',
|
88 |
+
array(
|
89 |
+
'header' => Mage::helper('rapido_imageoptimizer')->__('Saved Size'),
|
90 |
+
'align' => 'right',
|
91 |
+
'width' => '120px',
|
92 |
+
'type' => 'number',
|
93 |
+
'filter_index' => 'converted_saved',
|
94 |
+
'index' => 'converted_saved',
|
95 |
+
)
|
96 |
+
);
|
97 |
+
|
98 |
+
$this->addColumn('converted_saved_percent', array(
|
99 |
+
'header' => Mage::helper('rapido_imageoptimizer')->__('Saved %'),
|
100 |
+
'align' => 'right',
|
101 |
+
'width' => '120px',
|
102 |
+
'type' => 'number',
|
103 |
+
'filter_index' => 'converted_saved_percent',
|
104 |
+
'index' => 'converted_saved_percent',));
|
105 |
+
|
106 |
+
return $this;
|
107 |
+
}
|
108 |
+
|
109 |
+
public function getRowUrl($row)
|
110 |
+
{
|
111 |
+
return false;
|
112 |
+
}
|
113 |
+
|
114 |
+
public function getGridUrl()
|
115 |
+
{
|
116 |
+
return $this->getUrl('*/*/grid', array('_current' => true));
|
117 |
+
}
|
118 |
+
|
119 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Block/Images/List/Totals.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Block_Images_List_Totals extends Mage_Core_Block_Template
|
4 |
+
{
|
5 |
+
protected $stats = false;
|
6 |
+
|
7 |
+
public function __construct()
|
8 |
+
{
|
9 |
+
parent::__construct();
|
10 |
+
$this->setTemplate('rapido/imageoptimizer/totals.phtml');
|
11 |
+
}
|
12 |
+
|
13 |
+
protected function getStatistics()
|
14 |
+
{
|
15 |
+
if (!$this->stats) {
|
16 |
+
$collection = Mage::getResourceModel('rapido_imageoptimizer/images_collection');
|
17 |
+
|
18 |
+
$collection->getSelect()
|
19 |
+
->reset(Zend_Db_Select::COLUMNS)
|
20 |
+
->columns('status')
|
21 |
+
->columns('COUNT(status) AS amount_images')
|
22 |
+
->columns('SUM(original_size) AS original_size')
|
23 |
+
->columns('SUM(converted_size) AS converted_size')
|
24 |
+
->columns('SUM(converted_saved) AS converted_saved')
|
25 |
+
->columns('AVG(converted_saved_percent) AS converted_saved_percent')
|
26 |
+
->group(array('status'));
|
27 |
+
|
28 |
+
if ($collection->count()>0) {
|
29 |
+
$this->stats = new Varien_Object();
|
30 |
+
foreach ($collection as $row) {
|
31 |
+
$this->stats->setImagesCollected((int)$this->stats->getImagesCollected()+$row->getAmountImages());
|
32 |
+
$this->stats->setSizeImages((int)$this->stats->getSizeImages()+$row->getOriginalSize());
|
33 |
+
|
34 |
+
if ($row->getStatus()==Rapido_ImageOptimizer_Model_Status::STATUS_NEW) {
|
35 |
+
$this->stats->setImagesWaiting($row->getAmountImages());
|
36 |
+
}
|
37 |
+
|
38 |
+
if ($row->getStatus()==Rapido_ImageOptimizer_Model_Status::STATUS_CONVERTED) {
|
39 |
+
$this->stats->setImagesConverted($row->getAmountImages());
|
40 |
+
|
41 |
+
$this->stats->setSizeOriginal($row->getOriginalSize());
|
42 |
+
$this->stats->setSizeConverted($row->getConvertedSize());
|
43 |
+
$this->stats->setSizeSaved($row->getConvertedSaved());
|
44 |
+
|
45 |
+
$this->stats->setPercentageSaved(round($row->getConvertedSavedPercent(), 2).'%');
|
46 |
+
}
|
47 |
+
}
|
48 |
+
}
|
49 |
+
}
|
50 |
+
return $this->stats;
|
51 |
+
}
|
52 |
+
|
53 |
+
protected function getReadableSize($bytes, $decimals = 2)
|
54 |
+
{
|
55 |
+
|
56 |
+
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
|
57 |
+
$factor = floor((strlen($bytes) - 1) / 3);
|
58 |
+
|
59 |
+
return sprintf("%.{$decimals}f", $bytes/pow(1024, $factor)).@$size[$factor];
|
60 |
+
}
|
61 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Helper/Data.php
ADDED
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
protected $_files = array();
|
7 |
+
protected $_ext = array();
|
8 |
+
protected $_excludedir = array();
|
9 |
+
protected $auth = false;
|
10 |
+
|
11 |
+
public function collectFiles()
|
12 |
+
{
|
13 |
+
$this->_ext = explode(",", $this->getConfig('extensions'));
|
14 |
+
|
15 |
+
$excluded = explode("\n", $this->getConfig('exclude_dirs'));
|
16 |
+
foreach ($excluded as $dir) {
|
17 |
+
$dir = trim($dir, '\\/');
|
18 |
+
$this->_excludedir[] = rtrim(Mage::getBaseDir(), '\\/') . '/' . $dir . '/';
|
19 |
+
}
|
20 |
+
$basepaths = array();
|
21 |
+
$included = explode("\n", $this->getConfig('include_dirs'));
|
22 |
+
foreach ($included as $dir) {
|
23 |
+
$dir = trim($dir, '\\/ ');
|
24 |
+
if ($dir) {
|
25 |
+
$basepaths[] = rtrim(Mage::getBaseDir(), '\\/') . '/' . $dir . '/';
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
foreach ($basepaths as $basepath) {
|
30 |
+
$this->getDirectoryFiles($basepath);
|
31 |
+
}
|
32 |
+
|
33 |
+
$collection = Mage::getResourceModel('rapido_imageoptimizer/images_collection');
|
34 |
+
$hashData = array();
|
35 |
+
foreach ($collection as $images) {
|
36 |
+
$hashData[$images->getFullPath()] = array(
|
37 |
+
'original_checksum' => $images->getOriginalChecksum(),
|
38 |
+
'converted_checksum' => $images->getConvertedChecksum()
|
39 |
+
);
|
40 |
+
}
|
41 |
+
|
42 |
+
$imgModel = Mage::getModel('rapido_imageoptimizer/images');
|
43 |
+
foreach ($this->_files as $id => $file) {
|
44 |
+
$storeNewFile = true;
|
45 |
+
if (isset($hashData[$file['path'] . $file['file']])) {
|
46 |
+
if ($hashData[$file['path'] . $file['file']]['original_checksum'] == $file['checksum'] ||
|
47 |
+
$hashData[$file['path'] . $file['file']]['converted_checksum'] == $file['checksum']
|
48 |
+
) {
|
49 |
+
unset($this->_files[$id]);
|
50 |
+
$storeNewFile = false;
|
51 |
+
}
|
52 |
+
}
|
53 |
+
if ($storeNewFile) {
|
54 |
+
$img = $imgModel
|
55 |
+
->setCreatedate(now())
|
56 |
+
->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_NEW)
|
57 |
+
->setFullPath($file['path'] . $file['file'])
|
58 |
+
->setImageName($file['file'])
|
59 |
+
->setOriginalChecksum($file['checksum'])
|
60 |
+
->setOriginalSize($file['size']);
|
61 |
+
|
62 |
+
try {
|
63 |
+
$img->save();
|
64 |
+
} catch (Exception $ex) {
|
65 |
+
Mage::log($ex->getMessage());
|
66 |
+
}
|
67 |
+
$img->unsetData();
|
68 |
+
}
|
69 |
+
}
|
70 |
+
return count($this->_files);
|
71 |
+
}
|
72 |
+
|
73 |
+
public function getDirectoryFiles($path)
|
74 |
+
{
|
75 |
+
if (in_array($path, $this->_excludedir)) {
|
76 |
+
return;
|
77 |
+
}
|
78 |
+
$tmpFiles = scandir($path);
|
79 |
+
foreach ($tmpFiles as $file) {
|
80 |
+
if ($file == '.' || $file == '..') {
|
81 |
+
continue;
|
82 |
+
}
|
83 |
+
|
84 |
+
if (is_dir($path . $file)) {
|
85 |
+
$this->getDirectoryFiles($path . $file . '/');
|
86 |
+
} else {
|
87 |
+
$ext = substr($file, strrpos($file, '.') + 1);
|
88 |
+
if (in_array($ext, $this->_ext)) {
|
89 |
+
$this->_files[] = array(
|
90 |
+
'path' => $path,
|
91 |
+
'file' => $file,
|
92 |
+
'checksum' => sha1_file($path . $file),
|
93 |
+
'size' => filesize($path . $file),
|
94 |
+
);
|
95 |
+
}
|
96 |
+
}
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
public function convertImage($object)
|
101 |
+
{
|
102 |
+
$params = array();
|
103 |
+
$params['file'] = $object->getFullPath();
|
104 |
+
|
105 |
+
// Upload file to ImageConverter
|
106 |
+
$converted = $this->upload($params);
|
107 |
+
|
108 |
+
if ($converted['success'] == 1) {
|
109 |
+
$object->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_PENDING);
|
110 |
+
|
111 |
+
if (isset($converted['process_id'])) {
|
112 |
+
// Store conversion process_id
|
113 |
+
$object->setConvertedChecksum($converted['process_id'])
|
114 |
+
->setConvertedDate(now());
|
115 |
+
}
|
116 |
+
} else {
|
117 |
+
return false;
|
118 |
+
}
|
119 |
+
try {
|
120 |
+
// Save converted file details
|
121 |
+
$object->save();
|
122 |
+
return true;
|
123 |
+
} catch (Exception $ex) {
|
124 |
+
// Error saving details
|
125 |
+
return false;
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
public function downloadImage($object)
|
130 |
+
{
|
131 |
+
$params = array();
|
132 |
+
$params['process_id'] = $object->getConvertedChecksum();
|
133 |
+
|
134 |
+
// Check if file conversion has completed
|
135 |
+
$converted = $this->download($params);
|
136 |
+
if ($converted['success'] == 1) {
|
137 |
+
// Conversion completed, download file and store on local filesystem
|
138 |
+
|
139 |
+
$converted_size = 0;
|
140 |
+
$saved_bytes = 0;
|
141 |
+
$saved_percent = 0;
|
142 |
+
|
143 |
+
if (isset($converted['optimized_url'])) {
|
144 |
+
try {
|
145 |
+
// Retrieve new/converted file content
|
146 |
+
$newFile = $this->getFile($converted['optimized_url']);
|
147 |
+
|
148 |
+
if (strlen($newFile) > 0) {
|
149 |
+
if ($this->getConfig('keep_original') == 1) {
|
150 |
+
// Rename old file to keep original
|
151 |
+
rename($object->getFullPath(), $object->getFullPath() . '.original');
|
152 |
+
}
|
153 |
+
|
154 |
+
// Store new file
|
155 |
+
file_put_contents($object->getFullPath(), $newFile);
|
156 |
+
} else {
|
157 |
+
return false;
|
158 |
+
}
|
159 |
+
$object->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_CONVERTED);
|
160 |
+
|
161 |
+
// Generate/Store new Checksum
|
162 |
+
$object->setConvertedChecksum(sha1_file($object->getFullPath()))
|
163 |
+
->setConvertedDate(now());
|
164 |
+
|
165 |
+
$converted_size = $converted['optimized_size'];
|
166 |
+
$saved_bytes = $converted['saved_bytes'];
|
167 |
+
$saved_percent = ($converted['saved_bytes'] / $converted['original_size']) * 100;
|
168 |
+
|
169 |
+
} catch (Exception $ex) {
|
170 |
+
$object->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_FAILED);
|
171 |
+
// Error saving new file
|
172 |
+
}
|
173 |
+
} else {
|
174 |
+
$object->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_FAILED);
|
175 |
+
}
|
176 |
+
// Store converted size and savings
|
177 |
+
$object->setConvertedSize($converted_size)
|
178 |
+
->setConvertedSaved($saved_bytes)
|
179 |
+
->setConvertedSavedPercent($saved_percent);
|
180 |
+
|
181 |
+
} elseif ($converted['error'] == 1) {
|
182 |
+
// Conversion failed (no retry to download the file
|
183 |
+
$object->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_FAILED);
|
184 |
+
} else {
|
185 |
+
// Conversion still pending
|
186 |
+
return false;
|
187 |
+
}
|
188 |
+
try {
|
189 |
+
// Save details
|
190 |
+
$object->save();
|
191 |
+
return true;
|
192 |
+
} catch (Exception $ex) {
|
193 |
+
// Error saving details
|
194 |
+
return false;
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
protected function upload($opts = array())
|
199 |
+
{
|
200 |
+
|
201 |
+
if (!isset($opts['file'])) {
|
202 |
+
return array(
|
203 |
+
"success" => false,
|
204 |
+
"error" => "File parameter was not provided"
|
205 |
+
);
|
206 |
+
}
|
207 |
+
|
208 |
+
if (!file_exists($opts['file'])) {
|
209 |
+
return array(
|
210 |
+
"success" => false,
|
211 |
+
"error" => "File `" . $opts['file'] . "` does not exist"
|
212 |
+
);
|
213 |
+
}
|
214 |
+
|
215 |
+
$file = $opts['file'];
|
216 |
+
|
217 |
+
unset($opts['file']);
|
218 |
+
|
219 |
+
$opts['base_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
220 |
+
|
221 |
+
$data = array_merge(array(
|
222 |
+
"file" => $file,
|
223 |
+
"data" => json_encode(
|
224 |
+
array_merge(
|
225 |
+
$this->getAuth(),
|
226 |
+
$opts
|
227 |
+
)
|
228 |
+
)
|
229 |
+
));
|
230 |
+
|
231 |
+
$response = self::request($data, $this->getConfig('api_url'));
|
232 |
+
|
233 |
+
return $response;
|
234 |
+
}
|
235 |
+
|
236 |
+
public function download($opts)
|
237 |
+
{
|
238 |
+
$data = array_merge(array(
|
239 |
+
"data" => json_encode(
|
240 |
+
array_merge(
|
241 |
+
$this->getAuth(),
|
242 |
+
$opts
|
243 |
+
)
|
244 |
+
)
|
245 |
+
));
|
246 |
+
$response = self::request($data, $this->getConfig('status_url'));
|
247 |
+
|
248 |
+
return $response;
|
249 |
+
}
|
250 |
+
|
251 |
+
|
252 |
+
public function checkApi()
|
253 |
+
{
|
254 |
+
$data = array_merge(array(
|
255 |
+
"data" => json_encode(
|
256 |
+
array_merge(
|
257 |
+
$this->getAuth()
|
258 |
+
)
|
259 |
+
)
|
260 |
+
));
|
261 |
+
$response = self::request($data, $this->getConfig('check_url'));
|
262 |
+
return $response;
|
263 |
+
}
|
264 |
+
|
265 |
+
public function request($data, $url)
|
266 |
+
{
|
267 |
+
$client = new Zend_Http_Client();
|
268 |
+
$client->setUri($url);
|
269 |
+
$client->setMethod('POST');
|
270 |
+
$client->setAdapter('Zend_Http_Client_Adapter_Curl');
|
271 |
+
$adapter = $client->getAdapter();
|
272 |
+
$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
|
273 |
+
|
274 |
+
$client->setConfig(
|
275 |
+
array(
|
276 |
+
'strict' => false,
|
277 |
+
'maxredirects' => 0,
|
278 |
+
'timeout' => 120,
|
279 |
+
)
|
280 |
+
);
|
281 |
+
|
282 |
+
if (isset($data['file'])) {
|
283 |
+
$client->setFileUpload($data['file'], 'file');
|
284 |
+
unset($data['file']);
|
285 |
+
}
|
286 |
+
|
287 |
+
foreach ($data as $param => $val) {
|
288 |
+
$client->setParameterPost($param, $val);
|
289 |
+
}
|
290 |
+
$response = $client->request();
|
291 |
+
return json_decode($response->getBody(), true);
|
292 |
+
}
|
293 |
+
|
294 |
+
public function getFile($url)
|
295 |
+
{
|
296 |
+
$client = new Zend_Http_Client();
|
297 |
+
$client->setUri($url);
|
298 |
+
$client->setMethod('GET');
|
299 |
+
$client->setAdapter('Zend_Http_Client_Adapter_Curl');
|
300 |
+
$adapter = $client->getAdapter();
|
301 |
+
$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
|
302 |
+
|
303 |
+
$client->setConfig(
|
304 |
+
array(
|
305 |
+
'strict' => false,
|
306 |
+
'maxredirects' => 0,
|
307 |
+
'timeout' => 120,
|
308 |
+
)
|
309 |
+
);
|
310 |
+
|
311 |
+
$response = $client->request();
|
312 |
+
return $response->getBody();
|
313 |
+
}
|
314 |
+
|
315 |
+
protected function getAuth()
|
316 |
+
{
|
317 |
+
if (!$this->auth) {
|
318 |
+
// Initialize API Authentication
|
319 |
+
if ($this->getConfig('api_user') && $this->getConfig('api_secret')) {
|
320 |
+
$this->auth = array(
|
321 |
+
"auth" => array(
|
322 |
+
"api_key" => $this->getConfig('api_user'),
|
323 |
+
"api_secret" => $this->getConfig('api_secret')
|
324 |
+
)
|
325 |
+
);
|
326 |
+
} else {
|
327 |
+
return false;
|
328 |
+
}
|
329 |
+
}
|
330 |
+
return $this->auth;
|
331 |
+
}
|
332 |
+
protected function getConfig($key)
|
333 |
+
{
|
334 |
+
return Mage::getStoreConfig('cms/rapido_imageoptimizer/' . $key);
|
335 |
+
}
|
336 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Model/Cron.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Model_Cron
|
4 |
+
{
|
5 |
+
|
6 |
+
public function collectFiles()
|
7 |
+
{
|
8 |
+
if (Mage::getStoreConfigFlag('cms/rapido_imageoptimizer/daily_collect_files')) {
|
9 |
+
Mage::helper('rapido_imageoptimizer')->collectFiles();
|
10 |
+
}
|
11 |
+
}
|
12 |
+
|
13 |
+
public function convertFiles()
|
14 |
+
{
|
15 |
+
if (Mage::getStoreConfigFlag('cms/rapido_imageoptimizer/hourly_convert_files')) {
|
16 |
+
$helper = Mage::helper('rapido_imageoptimizer');
|
17 |
+
$amount = Mage::getStoreConfig('cms/rapido_imageoptimizer/max_conversion_amount');
|
18 |
+
|
19 |
+
$collection = Mage::getResourceModel('rapido_imageoptimizer/images_collection')
|
20 |
+
->addFilter('status', array('eq' => Rapido_ImageOptimizer_Model_Status::STATUS_NEW))
|
21 |
+
->setOrder('original_size', 'DESC');
|
22 |
+
if ($amount > 0) {
|
23 |
+
$collection->setPageSize($amount);
|
24 |
+
}
|
25 |
+
|
26 |
+
$converted = 0;
|
27 |
+
foreach ($collection as $file) {
|
28 |
+
if ($helper->convertImage($file)) {
|
29 |
+
$converted++;
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
// Download converted images
|
34 |
+
$collection = Mage::getResourceModel('rapido_imageoptimizer/images_collection')
|
35 |
+
->addFilter('status', array('eq' => Rapido_ImageOptimizer_Model_Status::STATUS_PENDING))
|
36 |
+
->setOrder('original_size', 'DESC');
|
37 |
+
if ($amount > 0) {
|
38 |
+
$collection->setPageSize($amount);
|
39 |
+
}
|
40 |
+
|
41 |
+
$converted = 0;
|
42 |
+
foreach ($collection as $file) {
|
43 |
+
if ($helper->downloadImage($file)) {
|
44 |
+
$converted++;
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
+
}
|
49 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Model/Images.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Model_Images extends Mage_Core_Model_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
protected $_eventPrefix = 'rapido_imageoptimizer_images';
|
7 |
+
protected $_eventObject = 'images';
|
8 |
+
|
9 |
+
protected function _construct()
|
10 |
+
{
|
11 |
+
$this->_init('rapido_imageoptimizer/images');
|
12 |
+
}
|
13 |
+
|
14 |
+
public function loadByAttribute($attribute, $value)
|
15 |
+
{
|
16 |
+
$collection = $this->getCollection()->addFilter($attribute, $value);
|
17 |
+
|
18 |
+
return $collection;
|
19 |
+
}
|
20 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Model/Resource/Images.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Model_Resource_Images extends Mage_Core_Model_Resource_Db_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
protected function _construct()
|
7 |
+
{
|
8 |
+
$this->_init('rapido_imageoptimizer/images', 'entity_id');
|
9 |
+
}
|
10 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Model/Resource/Images/Collection.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Model_Resource_Images_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
protected $_eventPrefix = 'rapido_imageoptimizer_images_collection';
|
7 |
+
protected $_eventObject = 'rapido_imageoptimizer_images_collection';
|
8 |
+
|
9 |
+
protected function _construct()
|
10 |
+
{
|
11 |
+
$this->_init('rapido_imageoptimizer/images');
|
12 |
+
}
|
13 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Model/Status.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Model_Status
|
4 |
+
{
|
5 |
+
|
6 |
+
const STATUS_NEW = 0;
|
7 |
+
const STATUS_CONVERTED = 1;
|
8 |
+
const STATUS_PENDING = 2;
|
9 |
+
const STATUS_FAILED = 3;
|
10 |
+
|
11 |
+
public function toOptionArray()
|
12 |
+
{
|
13 |
+
return
|
14 |
+
array(
|
15 |
+
array('value' => self::STATUS_NEW, 'label' => Mage::helper('rapido_imageoptimizer')->__('New')),
|
16 |
+
array('value' => self::STATUS_PENDING, 'label' => Mage::helper('rapido_imageoptimizer')->__('Converting')),
|
17 |
+
array('value' => self::STATUS_CONVERTED, 'label' => Mage::helper('rapido_imageoptimizer')->__('Converted')),
|
18 |
+
array('value' => self::STATUS_FAILED, 'label' => Mage::helper('rapido_imageoptimizer')->__('Failed')),
|
19 |
+
);
|
20 |
+
}
|
21 |
+
|
22 |
+
public function toOptionHash()
|
23 |
+
{
|
24 |
+
return array(
|
25 |
+
self::STATUS_NEW => Mage::helper('rapido_imageoptimizer')->__('New'),
|
26 |
+
self::STATUS_PENDING => Mage::helper('rapido_imageoptimizer')->__('Converting'),
|
27 |
+
self::STATUS_CONVERTED => Mage::helper('rapido_imageoptimizer')->__('Converted'),
|
28 |
+
self::STATUS_FAILED => Mage::helper('rapido_imageoptimizer')->__('Failed'),
|
29 |
+
);
|
30 |
+
}
|
31 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Model/System/Config/Source/Amount.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Model_System_Config_Source_Amount
|
4 |
+
{
|
5 |
+
|
6 |
+
public function toOptionArray()
|
7 |
+
{
|
8 |
+
return
|
9 |
+
array(
|
10 |
+
array('value' => 5, 'label' => 5),
|
11 |
+
array('value' => 10, 'label' => 10),
|
12 |
+
array('value' => 25, 'label' => 25),
|
13 |
+
array('value' => 50, 'label' => 50),
|
14 |
+
);
|
15 |
+
}
|
16 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Model/System/Config/Source/Extensions.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Model_System_Config_Source_Extensions
|
4 |
+
{
|
5 |
+
|
6 |
+
public function toOptionArray()
|
7 |
+
{
|
8 |
+
return
|
9 |
+
array(
|
10 |
+
array('value' => 'gif', 'label' => 'gif'),
|
11 |
+
array('value' => 'jpg', 'label' => 'jpg'),
|
12 |
+
array('value' => 'jpeg', 'label' => 'jpeg'),
|
13 |
+
array('value' => 'png', 'label' => 'png'),
|
14 |
+
);
|
15 |
+
}
|
16 |
+
}
|
app/code/community/Rapido/ImageOptimizer/controllers/Tools/Image/OptimizerController.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Tools_Image_OptimizerController extends Mage_Adminhtml_Controller_Action
|
4 |
+
{
|
5 |
+
|
6 |
+
public function indexAction()
|
7 |
+
{
|
8 |
+
$this->loadLayout()
|
9 |
+
->_addContent(
|
10 |
+
$this->getLayout()
|
11 |
+
->createBlock('rapido_imageoptimizer/images_list')
|
12 |
+
)
|
13 |
+
->renderLayout();
|
14 |
+
}
|
15 |
+
|
16 |
+
public function gridAction()
|
17 |
+
{
|
18 |
+
$this->loadLayout();
|
19 |
+
$this->getResponse()->setBody($this->getLayout()->createBlock('rapido_imageoptimizer/images_list_grid')
|
20 |
+
->toHtml());
|
21 |
+
}
|
22 |
+
|
23 |
+
public function checkAction()
|
24 |
+
{
|
25 |
+
$response = Mage::helper('rapido_imageoptimizer')->checkApi();
|
26 |
+
|
27 |
+
$session = Mage::getSingleton('adminhtml/session');
|
28 |
+
if (is_array($response) && !$response['error']) {
|
29 |
+
$expireDate = Mage::helper('core')->formatDate($response['expire_date'], 'medium');
|
30 |
+
$session->addSuccess($this->__('Account valid! (Expires: %s)', $expireDate));
|
31 |
+
} else {
|
32 |
+
$session->addError($this->__('Account invalid!'));
|
33 |
+
}
|
34 |
+
$this->_redirectReferer();
|
35 |
+
}
|
36 |
+
}
|
app/code/community/Rapido/ImageOptimizer/etc/adminhtml.xml
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="utf-8"?>
|
2 |
+
<config>
|
3 |
+
<menu>
|
4 |
+
<system>
|
5 |
+
<children>
|
6 |
+
<tools>
|
7 |
+
<children>
|
8 |
+
<imageoptimizer>
|
9 |
+
<title>Image Optimizer</title>
|
10 |
+
<sort_order>100</sort_order>
|
11 |
+
<action>adminhtml/tools_image_optimizer/</action>
|
12 |
+
</imageoptimizer>
|
13 |
+
</children>
|
14 |
+
</tools>
|
15 |
+
</children>
|
16 |
+
</system>
|
17 |
+
</menu>
|
18 |
+
<acl>
|
19 |
+
<resources>
|
20 |
+
<admin>
|
21 |
+
<children>
|
22 |
+
<system>
|
23 |
+
<children>
|
24 |
+
<tools>
|
25 |
+
<children>
|
26 |
+
<imageoptimizer>
|
27 |
+
<title>Image Optimizer</title>
|
28 |
+
</imageoptimizer>
|
29 |
+
</children>
|
30 |
+
</tools>
|
31 |
+
</children>
|
32 |
+
</system>
|
33 |
+
</children>
|
34 |
+
</admin>
|
35 |
+
</resources>
|
36 |
+
</acl>
|
37 |
+
</config>
|
app/code/community/Rapido/ImageOptimizer/etc/config.xml
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" ?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Rapido_ImageOptimizer>
|
5 |
+
<version>15.98.1</version>
|
6 |
+
</Rapido_ImageOptimizer>
|
7 |
+
</modules>
|
8 |
+
|
9 |
+
<global>
|
10 |
+
<helpers>
|
11 |
+
<rapido_imageoptimizer>
|
12 |
+
<class>Rapido_ImageOptimizer_Helper</class>
|
13 |
+
</rapido_imageoptimizer>
|
14 |
+
</helpers>
|
15 |
+
|
16 |
+
<blocks>
|
17 |
+
<rapido_imageoptimizer>
|
18 |
+
<class>Rapido_ImageOptimizer_Block</class>
|
19 |
+
</rapido_imageoptimizer>
|
20 |
+
</blocks>
|
21 |
+
|
22 |
+
<models>
|
23 |
+
<rapido_imageoptimizer>
|
24 |
+
<class>Rapido_ImageOptimizer_Model</class>
|
25 |
+
<resourceModel>rapido_imageoptimizer_resource</resourceModel>
|
26 |
+
</rapido_imageoptimizer>
|
27 |
+
<rapido_imageoptimizer_resource>
|
28 |
+
<class>Rapido_ImageOptimizer_Model_Resource</class>
|
29 |
+
<entities>
|
30 |
+
<images>
|
31 |
+
<table>rapido_imageoptimizer_images</table>
|
32 |
+
</images>
|
33 |
+
</entities>
|
34 |
+
</rapido_imageoptimizer_resource>
|
35 |
+
</models>
|
36 |
+
|
37 |
+
<resources>
|
38 |
+
<rapido_imageoptimizer_setup>
|
39 |
+
<setup>
|
40 |
+
<module>Rapido_ImageOptimizer</module>
|
41 |
+
</setup>
|
42 |
+
</rapido_imageoptimizer_setup>
|
43 |
+
</resources>
|
44 |
+
|
45 |
+
</global>
|
46 |
+
|
47 |
+
<admin>
|
48 |
+
<routers>
|
49 |
+
<adminhtml>
|
50 |
+
<args>
|
51 |
+
<modules>
|
52 |
+
<imageoptimizer after="Mage_Adminhtml">Rapido_ImageOptimizer</imageoptimizer>
|
53 |
+
</modules>
|
54 |
+
</args>
|
55 |
+
</adminhtml>
|
56 |
+
</routers>
|
57 |
+
</admin>
|
58 |
+
|
59 |
+
<adminhtml>
|
60 |
+
<layout>
|
61 |
+
<updates>
|
62 |
+
<rapido_imageoptimizer>
|
63 |
+
<file>rapido/imageoptimizer.xml</file>
|
64 |
+
</rapido_imageoptimizer>
|
65 |
+
</updates>
|
66 |
+
</layout>
|
67 |
+
</adminhtml>
|
68 |
+
|
69 |
+
<crontab>
|
70 |
+
<jobs>
|
71 |
+
<rapido_imageoptimizer_collect>
|
72 |
+
<schedule>
|
73 |
+
<cron_expr>30 3 * * *</cron_expr>
|
74 |
+
</schedule>
|
75 |
+
<run>
|
76 |
+
<model>rapido_imageoptimizer/cron::collectFiles</model>
|
77 |
+
</run>
|
78 |
+
</rapido_imageoptimizer_collect>
|
79 |
+
<rapido_imageoptimizer_convert>
|
80 |
+
<schedule>
|
81 |
+
<cron_expr>* * * * *</cron_expr>
|
82 |
+
</schedule>
|
83 |
+
<run>
|
84 |
+
<model>rapido_imageoptimizer/cron::convertFiles</model>
|
85 |
+
</run>
|
86 |
+
</rapido_imageoptimizer_convert>
|
87 |
+
</jobs>
|
88 |
+
</crontab>
|
89 |
+
|
90 |
+
<default>
|
91 |
+
<cms>
|
92 |
+
<rapido_imageoptimizer>
|
93 |
+
<api_url>https://api.rapido.nu/optimizer/v2/upload/</api_url>
|
94 |
+
<status_url>https://api.rapido.nu/optimizer/v2/status/</status_url>
|
95 |
+
<check_url>https://api.rapido.nu/optimizer/v2/check/</check_url>
|
96 |
+
<daily_collect_files>1</daily_collect_files>
|
97 |
+
<hourly_convert_files>1</hourly_convert_files>
|
98 |
+
<max_conversion_amount>5</max_conversion_amount>
|
99 |
+
<keep_original>1</keep_original>
|
100 |
+
<include_dirs><![CDATA[/media/
|
101 |
+
/skin/]]></include_dirs>
|
102 |
+
<extensions>gif,jpg,jpeg,png</extensions>
|
103 |
+
</rapido_imageoptimizer>
|
104 |
+
</cms>
|
105 |
+
</default>
|
106 |
+
</config>
|
app/code/community/Rapido/ImageOptimizer/etc/system.xml
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<cms>
|
5 |
+
<groups>
|
6 |
+
<rapido_imageoptimizer>
|
7 |
+
<label>Rapido Image Optimizer</label>
|
8 |
+
<frontend_type>text</frontend_type>
|
9 |
+
<sort_order>1000</sort_order>
|
10 |
+
<show_in_default>1</show_in_default>
|
11 |
+
<show_in_website>0</show_in_website>
|
12 |
+
<show_in_store>0</show_in_store>
|
13 |
+
<fields>
|
14 |
+
<api_user translate="label comment">
|
15 |
+
<label>API Username</label>
|
16 |
+
<comment>Supplied API Username</comment>
|
17 |
+
<frontend_type>password</frontend_type>
|
18 |
+
<sort_order>10</sort_order>
|
19 |
+
<show_in_default>1</show_in_default>
|
20 |
+
<show_in_website>0</show_in_website>
|
21 |
+
<show_in_store>0</show_in_store>
|
22 |
+
</api_user>
|
23 |
+
<api_secret translate="label comment">
|
24 |
+
<label>API Secret</label>
|
25 |
+
<comment>Supplied API Secret</comment>
|
26 |
+
<frontend_type>password</frontend_type>
|
27 |
+
<sort_order>11</sort_order>
|
28 |
+
<show_in_default>1</show_in_default>
|
29 |
+
<show_in_website>0</show_in_website>
|
30 |
+
<show_in_store>0</show_in_store>
|
31 |
+
</api_secret>
|
32 |
+
<test translate="label comment">
|
33 |
+
<comment>Save settings before running this test.</comment>
|
34 |
+
<frontend_type>text</frontend_type>
|
35 |
+
<frontend_model>Rapido_ImageOptimizer_Block_Api_Check</frontend_model>
|
36 |
+
<sort_order>12</sort_order>
|
37 |
+
<show_in_default>1</show_in_default>
|
38 |
+
<show_in_website>0</show_in_website>
|
39 |
+
<show_in_store>0</show_in_store>
|
40 |
+
</test>
|
41 |
+
<keep_original translate="label comment">
|
42 |
+
<label>Keep Original File</label>
|
43 |
+
<frontend_type>select</frontend_type>
|
44 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
45 |
+
<sort_order>20</sort_order>
|
46 |
+
<show_in_default>1</show_in_default>
|
47 |
+
<show_in_website>0</show_in_website>
|
48 |
+
<show_in_store>0</show_in_store>
|
49 |
+
</keep_original>
|
50 |
+
<daily_collect_files translate="label comment">
|
51 |
+
<label>Collect files daily (every night)</label>
|
52 |
+
<frontend_type>select</frontend_type>
|
53 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
54 |
+
<sort_order>30</sort_order>
|
55 |
+
<show_in_default>1</show_in_default>
|
56 |
+
<show_in_website>0</show_in_website>
|
57 |
+
<show_in_store>0</show_in_store>
|
58 |
+
</daily_collect_files>
|
59 |
+
<hourly_convert_files translate="label comment">
|
60 |
+
<label>Convert files hourly:</label>
|
61 |
+
<frontend_type>select</frontend_type>
|
62 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
63 |
+
<sort_order>31</sort_order>
|
64 |
+
<show_in_default>1</show_in_default>
|
65 |
+
<show_in_website>0</show_in_website>
|
66 |
+
<show_in_store>0</show_in_store>
|
67 |
+
</hourly_convert_files>
|
68 |
+
<include_dirs translate="label comment">
|
69 |
+
<label>Search directories</label>
|
70 |
+
<comment>Supply directory path (from Magento root), one per line</comment>
|
71 |
+
<frontend_type>textarea</frontend_type>
|
72 |
+
<sort_order>40</sort_order>
|
73 |
+
<show_in_default>1</show_in_default>
|
74 |
+
<show_in_website>0</show_in_website>
|
75 |
+
<show_in_store>0</show_in_store>
|
76 |
+
</include_dirs>
|
77 |
+
<exclude_dirs translate="label comment">
|
78 |
+
<label>Exclude directories</label>
|
79 |
+
<comment>Supply directory path (from Magento root), one per line</comment>
|
80 |
+
<frontend_type>textarea</frontend_type>
|
81 |
+
<sort_order>41</sort_order>
|
82 |
+
<show_in_default>1</show_in_default>
|
83 |
+
<show_in_website>0</show_in_website>
|
84 |
+
<show_in_store>0</show_in_store>
|
85 |
+
</exclude_dirs>
|
86 |
+
<extensions translate="label comment">
|
87 |
+
<label>File extensions</label>
|
88 |
+
<frontend_type>multiselect</frontend_type>
|
89 |
+
<source_model>rapido_imageoptimizer/system_config_source_extensions</source_model>
|
90 |
+
<sort_order>42</sort_order>
|
91 |
+
<show_in_default>1</show_in_default>
|
92 |
+
<show_in_website>0</show_in_website>
|
93 |
+
<show_in_store>0</show_in_store>
|
94 |
+
</extensions>
|
95 |
+
</fields>
|
96 |
+
</rapido_imageoptimizer>
|
97 |
+
</groups>
|
98 |
+
</cms>
|
99 |
+
</sections>
|
100 |
+
</config>
|
app/code/community/Rapido/ImageOptimizer/sql/rapido_imageoptimizer_setup/install-1.0.0.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
|
7 |
+
$table = $installer->getConnection()->newTable($installer->getTable('rapido_imageoptimizer/images'))
|
8 |
+
->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('identity' => true,
|
9 |
+
'unsigned' => true,
|
10 |
+
'nullable' => false,
|
11 |
+
'primary' => true,
|
12 |
+
'auto_increment' => true,), 'Entity Id')
|
13 |
+
->addColumn('createdate', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(), 'Create date')
|
14 |
+
->addColumn('status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(), 'Status')
|
15 |
+
->addColumn('full_path', Varien_Db_Ddl_Table::TYPE_TEXT, 512, array(), 'Full Image Path')
|
16 |
+
->addColumn('image_name', Varien_Db_Ddl_Table::TYPE_TEXT, 128, array(), 'Image Filename')
|
17 |
+
->addColumn('original_checksum', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array(), 'Original File Checksum')
|
18 |
+
->addColumn('original_size', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(), 'Original File Size')
|
19 |
+
->addColumn('converted_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(), 'Conversion Date')
|
20 |
+
->addColumn('converted_checksum', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array(), 'Converted File Checksum')
|
21 |
+
->addColumn('converted_size', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(), 'Converted File Size')
|
22 |
+
->addColumn('converted_saved', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(), 'Converted File Size Saved')
|
23 |
+
->addColumn('converted_saved_percent', Varien_Db_Ddl_Table::TYPE_DECIMAL, '5,2', array(), 'Converted File Size Saved Percentage');
|
24 |
+
|
25 |
+
$installer->getConnection()->createTable($table);
|
26 |
+
|
27 |
+
$installer->getConnection()
|
28 |
+
->addIndex($installer->getTable('rapido_imageoptimizer/images'), $installer->getIdxName('rapido_imageoptimizer/images', array('original_checksum')), array('original_checksum'));
|
29 |
+
|
30 |
+
$installer->getConnection()
|
31 |
+
->addIndex($installer->getTable('rapido_imageoptimizer/images'), $installer->getIdxName('rapido_imageoptimizer/images', array('converted_checksum')), array('converted_checksum'));
|
32 |
+
|
33 |
+
$installer->endSetup();
|
app/design/adminhtml/default/default/layout/rapido/imageoptimizer.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout>
|
3 |
+
<adminhtml_tools_image_optimizer_index>
|
4 |
+
<reference name="head">
|
5 |
+
<action method="addCss"><name>rapido/imageoptimizer.css</name></action>
|
6 |
+
</reference>
|
7 |
+
</adminhtml_tools_image_optimizer_index>
|
8 |
+
</layout>
|
app/design/adminhtml/default/default/template/rapido/imageoptimizer/totals.phtml
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if( $stats = $this->getStatistics() ): ?>
|
2 |
+
<?php if ($stats->getImagesConverted()==0):?>
|
3 |
+
<div id="messages"><ul class="messages"><li class="error-msg"><ul><li><span><?php echo $this->__('Image conversion has not started yet. it will be started thru the Magento cron on the hour. Please check back later!');?></span></li></ul></li></ul></div>
|
4 |
+
<?php endif;?>
|
5 |
+
|
6 |
+
<div class="entry-edit rapido">
|
7 |
+
<div class="entry-edit-head">
|
8 |
+
<h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Rapido Image Optimizer Statistics');?></h4>
|
9 |
+
<div class="form-buttons"></div>
|
10 |
+
</div>
|
11 |
+
<div class="fieldset " id="sales_report_base_fieldset">
|
12 |
+
<div class="hor-scroll">
|
13 |
+
<table cellspacing="0" width="100%" class="form-list">
|
14 |
+
<tbody>
|
15 |
+
<tr>
|
16 |
+
<td class="label"><?php echo $this->__('Images collected:');?></td>
|
17 |
+
<td class="label"><?php echo $this->__('Images converted:');?></td>
|
18 |
+
<td class="label"><?php echo $this->__('Waiting optimisation:');?></td>
|
19 |
+
<td class="label"><?php echo $this->__('Percentage saved:');?></td>
|
20 |
+
</tr>
|
21 |
+
<tr>
|
22 |
+
<td class="value"><?php echo $stats->getImagesCollected();?></td>
|
23 |
+
<td class="value"><?php echo $stats->getImagesConverted();?></td>
|
24 |
+
<td class="value"><?php echo $stats->getImagesWaiting();?></td>
|
25 |
+
<td class="value saved"><?php echo $stats->getPercentageSaved();?></td>
|
26 |
+
</tr>
|
27 |
+
<tr><td colspan="4"> </td></tr>
|
28 |
+
<tr>
|
29 |
+
<td class="label"><?php echo $this->__('Collected file size:');?></td>
|
30 |
+
<td class="label"><?php echo $this->__('Original file size:');?></td>
|
31 |
+
<td class="label"><?php echo $this->__('Converted file size:');?></td>
|
32 |
+
<td class="label"><?php echo $this->__('Saved file size:');?></td>
|
33 |
+
</tr>
|
34 |
+
<tr>
|
35 |
+
<td class="value"><?php echo $this->getReadableSize($stats->getSizeImages());?></td>
|
36 |
+
<td class="value"><?php echo $this->getReadableSize($stats->getSizeOriginal());?></td>
|
37 |
+
<td class="value"><?php echo $this->getReadableSize($stats->getSizeConverted());?></td>
|
38 |
+
<td class="value saved"><?php echo $this->getReadableSize($stats->getSizeSaved());?></td>
|
39 |
+
</tr>
|
40 |
+
</tbody>
|
41 |
+
</table>
|
42 |
+
</div>
|
43 |
+
</div>
|
44 |
+
</div>
|
45 |
+
<?php else:?>
|
46 |
+
<div id="messages"><ul class="messages"><li class="error-msg"><ul><li><span><?php echo $this->__('Image collection has not started yet. it will be started thru the Magento cron every night at 3:30am. Please check back later!');?></span></li></ul></li></ul></div>
|
47 |
+
<?php endif;?>
|
app/design/adminhtml/default/default/template/rapido/imageoptimizer/widget/grid/container.phtml
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) 2014 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 |
+
<div class="content-header">
|
28 |
+
<table cellspacing="0">
|
29 |
+
<tr>
|
30 |
+
<td style="<?php echo $this->getHeaderWidth() ?>"><?php echo $this->getHeaderHtml() ?></td>
|
31 |
+
<td class="form-buttons"><?php echo $this->getButtonsHtml() ?></td>
|
32 |
+
</tr>
|
33 |
+
</table>
|
34 |
+
</div>
|
35 |
+
<div>
|
36 |
+
<?php echo $this->getTotalsHtml() ?>
|
37 |
+
</div>
|
38 |
+
<div>
|
39 |
+
<?php echo $this->getGridHtml() ?>
|
40 |
+
</div>
|
app/etc/modules/Rapido_ImageOptimizer.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" ?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Rapido_ImageOptimizer>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Rapido_ImageOptimizer>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>rapido_image_optimizer</name>
|
4 |
+
<version>15.98.2</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>OSL v.3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Rapido is a robust, ultra-fast image optimizer and compressor with best-in-class algorithms for Magento. </summary>
|
10 |
+
<description>Saving average more than 50% on your catalog, product or theming images. The Magento image optimizer is very easy to install and use. After a initial collection of all your images, Rapido will automatic optimize your image in the cloud and send back your new optimized image in the correct directory.</description>
|
11 |
+
<notes>stable version V2</notes>
|
12 |
+
<authors><author><name>Ray Bogman</name><user>ray</user><email>ray@rapido.nu</email></author><author><name>Vladimir Kerkhoff</name><user>vladimir</user><email>vladimir@rapido.nu</email></author></authors>
|
13 |
+
<date>2015-04-30</date>
|
14 |
+
<time>15:46:52</time>
|
15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Rapido_ImageOptimizer.xml" hash="286537ce1815e69868528298e44823b1"/></dir></target><target name="magecommunity"><dir name="Rapido"><dir name="ImageOptimizer"><dir name="Block"><dir name="Api"><file name="Check.php" hash="60a28dce8ddcaaea2bf56db279def1b6"/></dir><dir name="Images"><dir name="List"><file name="Grid.php" hash="351aac2ae85f704156e80fa33aef4253"/><file name="Totals.php" hash="d6c3748a0f7a0c7706e57cf3895289f6"/></dir><file name="List.php" hash="d7370ef213beea7b47937c938eb5c742"/></dir></dir><dir name="Helper"><file name="Data.php" hash="ff388f9a3e135089b37115070d12701d"/></dir><dir name="Model"><file name="Cron.php" hash="7ad58f715c924fa3bd136a22578d42f4"/><file name="Images.php" hash="cac2e6eba424d2fad5784766a04a37e4"/><dir name="Resource"><dir name="Images"><file name="Collection.php" hash="d1147185c37a76404967ea2b97fda2e4"/></dir><file name="Images.php" hash="2b6103da1da24b25e1753b391c5475f6"/></dir><file name="Status.php" hash="474dab85d3da28ad13096ec3da82935c"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Amount.php" hash="019a0cbd6db1e0a74343aa256186f870"/><file name="Extensions.php" hash="b61b25303820d60a2552948f3446949a"/></dir></dir></dir></dir><dir name="controllers"><dir name="Tools"><dir name="Image"><file name="OptimizerController.php" hash="cf527840d0d97f2e28dab03140f507d0"/></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="9243d31a493db1fd7667d47cb15e1929"/><file name="config.xml" hash="fb7953c7499a92b109591085be125acf"/><file name="system.xml" hash="14f7c018de58e44a58cd5cd21b9ef2e8"/></dir><dir name="sql"><dir name="rapido_imageoptimizer_setup"><file name="install-1.0.0.php" hash="d78f69c5bed79580d8ec87718a9fe664"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="rapido"><file name="imageoptimizer.xml" hash="7d7beb42d6fb83aa4843fcd9e82d7140"/></dir></dir><dir name="template"><dir name="rapido"><dir name="imageoptimizer"><file name="totals.phtml" hash="e5f565e62a6e26383e310c3d02952eac"/><dir name="widget"><dir name="grid"><file name="container.phtml" hash="2d66e4e4d9d6d69ffa40d968c19bc412"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mage"><dir name="shell"><file name="imageoptimizer.php" hash="1ae38fa7d018bdba72838c02e30ba27a"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="rapido"><file name="imageoptimizer.css" hash="cfd060bbe60aae6f0c32af4cd5b00e91"/></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>
|
shell/imageoptimizer.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once 'abstract.php';
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Rapido ImageOptimizer script
|
7 |
+
*
|
8 |
+
* @category Rapido
|
9 |
+
* @package Rapido_ImageOptimizer
|
10 |
+
* @author Rapido <support@rapido.nu>
|
11 |
+
*/
|
12 |
+
class Rapido_Shell_ImageOptimizer extends Mage_Shell_Abstract
|
13 |
+
{
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Run script
|
17 |
+
*
|
18 |
+
*/
|
19 |
+
public function run()
|
20 |
+
{
|
21 |
+
$helper = Mage::helper('rapido_imageoptimizer');
|
22 |
+
if (isset($this->_args['collect'])) {
|
23 |
+
$amount = $helper->collectFiles();
|
24 |
+
echo Mage::helper('rapido_imageoptimizer')->__('%s new image files collected!', $amount) . "\n\n";
|
25 |
+
} else if (isset($this->_args['convert'])) {
|
26 |
+
$amount = $this->getArg('amount');
|
27 |
+
|
28 |
+
if (!$amount || $amount>500) {
|
29 |
+
$amount = 500;
|
30 |
+
}
|
31 |
+
|
32 |
+
$converted = 0;
|
33 |
+
$downloaded = 0;
|
34 |
+
for ($i=0; $i<($amount/5); $i++) {
|
35 |
+
// Convert files
|
36 |
+
$collection = Mage::getResourceModel('rapido_imageoptimizer/images_collection')
|
37 |
+
->addFilter('status', array('eq' => Rapido_ImageOptimizer_Model_Status::STATUS_NEW))
|
38 |
+
->setOrder('original_size', 'DESC')
|
39 |
+
->setPageSize(5);
|
40 |
+
|
41 |
+
foreach ($collection as $file) {
|
42 |
+
if ($helper->convertImage($file)) {
|
43 |
+
$converted++;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
// Download files
|
48 |
+
$collection = Mage::getResourceModel('rapido_imageoptimizer/images_collection')
|
49 |
+
->addFilter('status', array('eq' => Rapido_ImageOptimizer_Model_Status::STATUS_PENDING))
|
50 |
+
->setOrder('original_size', 'DESC');
|
51 |
+
|
52 |
+
foreach ($collection as $file) {
|
53 |
+
if ($helper->downloadImage($file)) {
|
54 |
+
$downloaded++;
|
55 |
+
}
|
56 |
+
}
|
57 |
+
}
|
58 |
+
echo Mage::helper('rapido_imageoptimizer')
|
59 |
+
->__(
|
60 |
+
'%s image uploaded and %s images downloaded!',
|
61 |
+
$converted,
|
62 |
+
$downloaded
|
63 |
+
) . "\n\n";
|
64 |
+
|
65 |
+
} else if (isset($this->_args['test'])) {
|
66 |
+
var_dump($helper->checkApi());
|
67 |
+
} else {
|
68 |
+
echo $this->usageHelp();
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Retrieve Usage Help Message
|
74 |
+
*
|
75 |
+
*/
|
76 |
+
public function usageHelp()
|
77 |
+
{
|
78 |
+
return <<<USAGE
|
79 |
+
Usage: php -f imageoptimzer.php -- [options]
|
80 |
+
|
81 |
+
collect Collect files to convert
|
82 |
+
convert Convert Images in queue
|
83 |
+
--amount [x] Amount of images to convert per run
|
84 |
+
help This help
|
85 |
+
|
86 |
+
USAGE;
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
$shell = new Rapido_Shell_ImageOptimizer();
|
91 |
+
$shell->run();
|
skin/adminhtml/default/default/rapido/imageoptimizer.css
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
.rapido .form-list {width:100%;}
|
2 |
+
.rapido .form-list td.label{width:25% !important;text-align:center;font-weight:bold;}
|
3 |
+
.rapido .form-list td.value{text-align:center;font-weight:bold;font-size: 2em;}
|
4 |
+
.rapido .form-list td.value.saved{color:#008800;}
|