Version Notes
stable version V2
Download this release
Release Info
Developer | Ray Zhang |
Extension | rapido_image_optimizer |
Version | 15.212.1 |
Comparing to | |
See all releases |
Code changes from version 15.125.4 to 15.212.1
- app/code/community/Rapido/ImageOptimizer/Block/Images/List.php +13 -0
- app/code/community/Rapido/ImageOptimizer/Block/System/Config/Form/Directories.php +34 -0
- app/code/community/Rapido/ImageOptimizer/Block/System/Config/Form/Field/Array/Abstract.php +132 -0
- app/code/community/Rapido/ImageOptimizer/Helper/Data.php +189 -62
- app/code/community/Rapido/ImageOptimizer/Model/System/Config/Backend/Serialized.php +22 -0
- app/code/community/Rapido/ImageOptimizer/controllers/Tools/Image/OptimizerController.php +6 -1
- app/code/community/Rapido/ImageOptimizer/data/rapido_imageoptimizer_setup/data-upgrade-15.168.1-15.171.1.php +34 -0
- app/code/community/Rapido/ImageOptimizer/{Helper/.Data.php.swo → etc/.config.xml.swp} +0 -0
- app/code/community/Rapido/ImageOptimizer/etc/config.xml +1 -1
- app/code/community/Rapido/ImageOptimizer/etc/system.xml +5 -13
- app/design/adminhtml/default/default/template/rapido/imageoptimizer/system/config/form/field/array.phtml +156 -0
- package.xml +4 -4
- shell/imageoptimizer.php +110 -0
app/code/community/Rapido/ImageOptimizer/Block/Images/List.php
CHANGED
@@ -9,6 +9,14 @@ class Rapido_ImageOptimizer_Block_Images_List extends Mage_Adminhtml_Block_Widge
|
|
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';
|
@@ -22,6 +30,11 @@ class Rapido_ImageOptimizer_Block_Images_List extends Mage_Adminhtml_Block_Widge
|
|
22 |
return parent::_prepareLayout();
|
23 |
}
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
public function getTotalsHtml()
|
26 |
{
|
27 |
return $this->getChildHtml('totals');
|
9 |
$this->setTemplate('rapido/imageoptimizer/widget/grid/container.phtml');
|
10 |
$this->_removeButton('add');
|
11 |
|
12 |
+
$this->addButton(
|
13 |
+
'config',
|
14 |
+
array(
|
15 |
+
'label' => Mage::helper('rapido_imageoptimizer')->__('Configuration'),
|
16 |
+
'onclick' => 'setLocation(\'' . $this->getConfigUrl() .'\')',
|
17 |
+
)
|
18 |
+
);
|
19 |
+
|
20 |
$this->_headerText = Mage::helper('rapido_imageoptimizer')->__('Image Optimizer Queue');
|
21 |
$this->_blockGroup = 'rapido_imageoptimizer';
|
22 |
$this->_controller = 'images_list';
|
30 |
return parent::_prepareLayout();
|
31 |
}
|
32 |
|
33 |
+
protected function getConfigUrl()
|
34 |
+
{
|
35 |
+
return Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit', array('section'=>'cms'));
|
36 |
+
}
|
37 |
+
|
38 |
public function getTotalsHtml()
|
39 |
{
|
40 |
return $this->getChildHtml('totals');
|
app/code/community/Rapido/ImageOptimizer/Block/System/Config/Form/Directories.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Block_System_Config_Form_Directories
|
4 |
+
extends Rapido_ImageOptimizer_Block_System_Config_Form_Field_Array_Abstract
|
5 |
+
{
|
6 |
+
public function __construct()
|
7 |
+
{
|
8 |
+
$this->addColumn('path', array(
|
9 |
+
'label' => Mage::helper('rapido_imageoptimizer')->__('Path'),
|
10 |
+
));
|
11 |
+
|
12 |
+
$this->addColumn('recur', array(
|
13 |
+
'label' => Mage::helper('rapido_imageoptimizer')->__('Recursive'),
|
14 |
+
'type' => 'select',
|
15 |
+
'options' => array("1" => "Yes", "0" => "No"),
|
16 |
+
'values' => 1,
|
17 |
+
'style' => 'width:50px'
|
18 |
+
));
|
19 |
+
|
20 |
+
$this->addColumn('action', array(
|
21 |
+
'label' => Mage::helper('rapido_imageoptimizer')->__('Action'),
|
22 |
+
'type' => 'select',
|
23 |
+
'options' => array("1" => "Include", "2" => "Exclude", "0" => "Disabled"),
|
24 |
+
'values' => 1,
|
25 |
+
'style' => 'width:50px'
|
26 |
+
));
|
27 |
+
|
28 |
+
$this->_addAfter = false;
|
29 |
+
$this->_addButtonLabel = Mage::helper('rapido_imageoptimizer')->__('Add new');
|
30 |
+
$this->setTemplate('rapido/imageoptimizer/system/config/form/field/array.phtml');
|
31 |
+
parent::__construct();
|
32 |
+
}
|
33 |
+
|
34 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Block/System/Config/Form/Field/Array/Abstract.php
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
abstract class Rapido_ImageOptimizer_Block_System_Config_Form_Field_Array_Abstract
|
4 |
+
extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
|
5 |
+
{
|
6 |
+
protected $_addButton = true;
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Add a column to array-grid
|
10 |
+
*
|
11 |
+
* @param string $name
|
12 |
+
* @param array $params
|
13 |
+
*/
|
14 |
+
public function addColumn($name, $params)
|
15 |
+
{
|
16 |
+
$this->_columns[$name] = array(
|
17 |
+
'label' => empty($params['label']) ? 'Column' : $params['label'],
|
18 |
+
'title' => empty($params['title']) ? null : $params['title'],
|
19 |
+
'action' => empty($params['action']) ? null : $params['action'],
|
20 |
+
'size' => empty($params['size']) ? false : $params['size'],
|
21 |
+
'style' => empty($params['style']) ? null : $params['style'],
|
22 |
+
'class' => empty($params['class']) ? null : $params['class'],
|
23 |
+
'renderer' => false,
|
24 |
+
'type' => 'text',
|
25 |
+
'options' => false,
|
26 |
+
);
|
27 |
+
if ((!empty($params['renderer'])) && ($params['renderer'] instanceof Mage_Core_Block_Abstract)) {
|
28 |
+
$this->_columns[$name]['renderer'] = $params['renderer'];
|
29 |
+
}
|
30 |
+
|
31 |
+
if ((!empty($params['type']))) {
|
32 |
+
$this->_columns[$name]['type'] = $params['type'];
|
33 |
+
}
|
34 |
+
|
35 |
+
if ((!empty($params['options']))) {
|
36 |
+
$this->_columns[$name]['options'] = $params['options'];
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
|
41 |
+
protected function _renderCellTemplate($columnName)
|
42 |
+
{
|
43 |
+
if (empty($this->_columns[$columnName])) {
|
44 |
+
throw new Exception('Wrong column name specified.');
|
45 |
+
}
|
46 |
+
$column = $this->_columns[$columnName];
|
47 |
+
$inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
|
48 |
+
if ($column['renderer']) {
|
49 |
+
return $column['renderer']->setInputName($inputName)->setColumnName($columnName)->setColumn(
|
50 |
+
$column
|
51 |
+
)->toHtml();
|
52 |
+
}
|
53 |
+
|
54 |
+
$html = "";
|
55 |
+
switch ($column['type']) {
|
56 |
+
case "newrow":
|
57 |
+
$html = "</tr><tr>";
|
58 |
+
break;
|
59 |
+
case "hidden":
|
60 |
+
$html = '<input type="hidden" name="' . $inputName .
|
61 |
+
'" value="#{' . $columnName . '}" ' .
|
62 |
+
($column['size'] ? 'size="' . $column['size'] . '"' : '') .
|
63 |
+
' class="' . (isset($column['class']) ? $column['class'] : 'input-text') . '"' .
|
64 |
+
(isset($column['style']) ? ' style="' . $column['style'] . '"' : '') . '/>';
|
65 |
+
break;
|
66 |
+
case "readonly":
|
67 |
+
$html = '<input type="text" readonly name="' . $inputName .
|
68 |
+
'" value="#{' . $columnName . '}" ' .
|
69 |
+
($column['size'] ? 'size="' . $column['size'] . '"' : '') .
|
70 |
+
' class="' . (isset($column['class']) ? $column['class'] : 'input-text') . '"' .
|
71 |
+
(isset($column['style']) ? ' style="' . $column['style'] . '"' : '') . '/>';
|
72 |
+
break;
|
73 |
+
case "text":
|
74 |
+
$html = '<input type="text" name="' . $inputName .
|
75 |
+
'" value="#{' . $columnName . '}" ' .
|
76 |
+
($column['size'] ? 'size="' . $column['size'] . '"' : '') .
|
77 |
+
' class="' . (isset($column['class']) ? $column['class'] : 'input-text') . '"' .
|
78 |
+
(isset($column['style']) ? ' style="' . $column['style'] . '"' : '') . '/>';
|
79 |
+
break;
|
80 |
+
case "textarea":
|
81 |
+
$html = '<textarea name="' . $inputName . ' ' .
|
82 |
+
($column['size'] ? 'size="' . $column['size'] . '"' : '') .
|
83 |
+
' class="' . (isset($column['class']) ? $column['class'] : 'input-text') . '"' .
|
84 |
+
(isset($column['style']) ? ' style="' . $column['style'] . '"' : '') .
|
85 |
+
'">#{' . $columnName . '}</textarea>';
|
86 |
+
break;
|
87 |
+
case "button":
|
88 |
+
$html = '<button type="button" onclick=' . $column['action'] . '><span>' .
|
89 |
+
$column['title'] . '</span></button>';
|
90 |
+
break;
|
91 |
+
case "file":
|
92 |
+
$html = '<input type="file" name="' . $inputName . '"' .
|
93 |
+
($column['size'] ? 'size="' . $column['size'] . '"' : '') .
|
94 |
+
' class="' . (isset($column['class']) ? $column['class'] : '') . '"' .
|
95 |
+
(isset($column['style']) ? ' style="' . $column['style'] . '"' : '') . '/>';
|
96 |
+
$html .= '<br>#{' . $columnName . '}';
|
97 |
+
break;
|
98 |
+
case "multiselect":
|
99 |
+
$html = '<input type="hidden" value="#{' . $columnName .
|
100 |
+
'}" disabled="disabled" class="is-enabled-hidden" />';
|
101 |
+
$html .= '<select name="' . $inputName . '[]" value="#{' . $columnName . '}" ' .
|
102 |
+
($column['size'] ? 'size="' . $column['size'] . '"' : '') .
|
103 |
+
' class="' . (isset($column['class']) ? $column['class'] : 'select multiselect') . '"' .
|
104 |
+
(isset($column['style']) ? ' style="' . $column['style'] . '"' : '') . ' multiple=multiple>';
|
105 |
+
|
106 |
+
if (is_array($column['options'])) {
|
107 |
+
foreach ($column['options'] as $key => $val) {
|
108 |
+
$html .= '<option value="' . $key . '">' . $val . '</option>';
|
109 |
+
}
|
110 |
+
}
|
111 |
+
$html .= "</select>";
|
112 |
+
break;
|
113 |
+
case "select":
|
114 |
+
$html = '<input type="hidden" value="#{' . $columnName .
|
115 |
+
'}" disabled="disabled" class="is-enabled-hidden" />';
|
116 |
+
$html .= '<select name="' . $inputName . '" value="#{' . $columnName . '}" ' .
|
117 |
+
($column['size'] ? 'size="' . $column['size'] . '"' : '') .
|
118 |
+
' class="' . (isset($column['class']) ? $column['class'] : 'select') . '"' .
|
119 |
+
(isset($column['style']) ? ' style="' . $column['style'] . '"' : '') . '>';
|
120 |
+
|
121 |
+
if (is_array($column['options'])) {
|
122 |
+
foreach ($column['options'] as $key => $val) {
|
123 |
+
$html .= '<option value="' . $key . '">' . $val . '</option>';
|
124 |
+
}
|
125 |
+
}
|
126 |
+
$html .= "</select>";
|
127 |
+
break;
|
128 |
+
}
|
129 |
+
return $html;
|
130 |
+
}
|
131 |
+
|
132 |
+
}
|
app/code/community/Rapido/ImageOptimizer/Helper/Data.php
CHANGED
@@ -12,94 +12,221 @@ class Rapido_ImageOptimizer_Helper_Data extends Mage_Core_Helper_Abstract
|
|
12 |
|
13 |
public function collectFiles()
|
14 |
{
|
15 |
-
$
|
|
|
16 |
|
17 |
-
$
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
21 |
}
|
22 |
-
|
23 |
-
$
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
}
|
29 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
}
|
|
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
$collection = Mage::getResourceModel('rapido_imageoptimizer/images_collection');
|
36 |
$hashData = array();
|
37 |
-
|
|
|
38 |
$hashData[$images->getFullPath()] = array(
|
39 |
-
'
|
40 |
-
'
|
41 |
);
|
42 |
}
|
43 |
-
|
44 |
$imgModel = Mage::getModel('rapido_imageoptimizer/images');
|
45 |
-
foreach ($
|
46 |
-
$
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
$
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_NEW)
|
59 |
-
->setFullPath($file['path'] . $file['file'])
|
60 |
-
->setImageName($file['file'])
|
61 |
-
->setOriginalChecksum($file['checksum'])
|
62 |
-
->setOriginalSize($file['size']);
|
63 |
-
|
64 |
-
if ($file['size']>self::MAX_FILE_SIZE) {
|
65 |
-
$img->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_TOBIG);
|
66 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
-
$img->unsetData();
|
74 |
}
|
75 |
}
|
76 |
-
return
|
77 |
}
|
78 |
|
79 |
-
public function getDirectoryFiles($path)
|
80 |
{
|
81 |
if (in_array($path, $this->_excludedir)) {
|
82 |
return;
|
83 |
}
|
84 |
-
$
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
$this->
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
101 |
}
|
102 |
}
|
|
|
103 |
}
|
104 |
}
|
105 |
|
12 |
|
13 |
public function collectFiles()
|
14 |
{
|
15 |
+
$collection = Mage::getResourceModel('rapido_imageoptimizer/images_collection');
|
16 |
+
$hashData = array();
|
17 |
|
18 |
+
while ($images = $collection->fetchItem()) {
|
19 |
+
$hashData[$images->getFullPath()] = array(
|
20 |
+
'o' => $images->getOriginalChecksum(),
|
21 |
+
'c' => $images->getConvertedChecksum()
|
22 |
+
);
|
23 |
}
|
24 |
+
|
25 |
+
$ext = '{*.'.implode(',*.', explode(",", $this->getConfig('extensions'))).'}';
|
26 |
+
|
27 |
+
$dirs = unserialize($this->getConfig('directories'));
|
28 |
+
$basePaths = array();
|
29 |
+
foreach ($dirs as $dir) {
|
30 |
+
$path = trim($dir['path']);
|
31 |
+
$path = trim($path, '\\/');
|
32 |
+
switch ($dir['action']) {
|
33 |
+
case 0: // Disabled
|
34 |
+
break;
|
35 |
+
case 1: // Include path
|
36 |
+
$basePaths[] = array(
|
37 |
+
'path' =>rtrim(Mage::getBaseDir(), '\\/') . DS . $path,
|
38 |
+
'recur' => $dir['recur'],
|
39 |
+
);
|
40 |
+
break;
|
41 |
+
case 2: // Exclude path
|
42 |
+
$this->_excludedir[] = rtrim(Mage::getBaseDir(), '\\/') . DS . $path . DS;
|
43 |
}
|
44 |
}
|
45 |
+
$imgCount = 0;
|
46 |
+
$imgModel = Mage::getModel('rapido_imageoptimizer/images');
|
47 |
+
foreach ($basePaths as $basePath) {
|
48 |
+
if ($basePath['recur']) {
|
49 |
+
$dirs = $this->findAllDirs($basePath['path']);
|
50 |
+
} else {
|
51 |
+
$dirs[] = $basePath['path'];
|
52 |
+
}
|
53 |
+
foreach ($dirs as $dir) {
|
54 |
+
$match = glob($dir . $ext, GLOB_NOSORT|GLOB_BRACE);
|
55 |
+
if (!$match) {
|
56 |
+
continue;
|
57 |
+
}
|
58 |
+
foreach ($match as $image) {
|
59 |
+
$file = array();
|
60 |
+
$file['path'] = $dir;
|
61 |
+
$file['file'] = str_replace($dir, '', $image);
|
62 |
+
$file['crc'] = sha1_file($image);
|
63 |
+
$file['size'] = filesize($image);
|
64 |
+
|
65 |
+
if (isset($hashData[$file['path'] . $file['file']])) {
|
66 |
+
if ($hashData[$file['path'] . $file['file']]['o'] == $file['crc'] ||
|
67 |
+
$hashData[$file['path'] . $file['file']]['c'] == $file['crc']
|
68 |
+
) {
|
69 |
+
continue;
|
70 |
+
}
|
71 |
+
}
|
72 |
+
$img = $imgModel
|
73 |
+
->setCreatedate(now())
|
74 |
+
->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_NEW)
|
75 |
+
->setFullPath($file['path'] . $file['file'])
|
76 |
+
->setImageName($file['file'])
|
77 |
+
->setOriginalChecksum($file['crc'])
|
78 |
+
->setOriginalSize($file['size']);
|
79 |
+
|
80 |
+
if ($file['size'] > self::MAX_FILE_SIZE) {
|
81 |
+
$img->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_TOBIG);
|
82 |
+
}
|
83 |
+
|
84 |
+
try {
|
85 |
+
$img->save();
|
86 |
+
|
87 |
+
$hashData[$img->getFullPath()] = array(
|
88 |
+
'o' => $img->getOriginalChecksum(),
|
89 |
+
'c' => $img->getConvertedChecksum()
|
90 |
+
);
|
91 |
+
$imgCount++;
|
92 |
+
} catch (Exception $ex) {
|
93 |
+
Mage::log($ex->getMessage());
|
94 |
+
}
|
95 |
+
|
96 |
+
$img->unsetData();
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}
|
100 |
+
return $imgCount;
|
101 |
+
}
|
102 |
+
|
103 |
+
protected function findAllDirs($start)
|
104 |
+
{
|
105 |
+
$dirStack=[$start];
|
106 |
+
while ($dir=array_shift($dirStack)) {
|
107 |
+
$ar=glob($dir.'*', GLOB_ONLYDIR|GLOB_NOSORT|GLOB_MARK);
|
108 |
+
if (!$ar) {
|
109 |
+
continue;
|
110 |
+
}
|
111 |
+
foreach ($ar as $id => $path) {
|
112 |
+
if (in_array($path, $this->_excludedir)) {
|
113 |
+
unset($ar[$id]);
|
114 |
+
}
|
115 |
+
}
|
116 |
|
117 |
+
$dirStack=array_merge($dirStack, $ar);
|
118 |
+
foreach ($ar as $DIR) {
|
119 |
+
yield $DIR;
|
120 |
+
}
|
121 |
}
|
122 |
+
}
|
123 |
|
124 |
+
public function collectFilesOld()
|
125 |
+
{
|
126 |
+
$this->_ext = explode(",", $this->getConfig('extensions'));
|
127 |
+
|
128 |
+
$dirs = unserialize($this->getConfig('directories'));
|
129 |
+
$basePaths = array();
|
130 |
+
foreach ($dirs as $dir) {
|
131 |
+
$path = trim($dir['path']);
|
132 |
+
$path = trim($path, '\\/');
|
133 |
+
switch ($dir['action']) {
|
134 |
+
case 0: // Disabled
|
135 |
+
break;
|
136 |
+
case 1: // Include path
|
137 |
+
$basePaths[] = array(
|
138 |
+
'path' =>rtrim(Mage::getBaseDir(), '\\/') . DS . $path . DS,
|
139 |
+
'recur' => $dir['recur'],
|
140 |
+
);
|
141 |
+
break;
|
142 |
+
case 2: // Exclude path
|
143 |
+
$this->_excludedir[] = rtrim(Mage::getBaseDir(), '\\/') . DS . $path . DS;
|
144 |
+
}
|
145 |
+
}
|
146 |
$collection = Mage::getResourceModel('rapido_imageoptimizer/images_collection');
|
147 |
$hashData = array();
|
148 |
+
|
149 |
+
while ($images = $collection->fetchItem()) {
|
150 |
$hashData[$images->getFullPath()] = array(
|
151 |
+
'o' => $images->getOriginalChecksum(),
|
152 |
+
'c' => $images->getConvertedChecksum()
|
153 |
);
|
154 |
}
|
155 |
+
$imgCount = 0;
|
156 |
$imgModel = Mage::getModel('rapido_imageoptimizer/images');
|
157 |
+
foreach ($basePaths as $basePath) {
|
158 |
+
$this->_files = array();
|
159 |
+
$this->getDirectoryFiles($basePath['path'], $basePath['recur']);
|
160 |
+
|
161 |
+
foreach ($this->_files as $id => $file) {
|
162 |
+
$storeNewFile = true;
|
163 |
+
if (isset($hashData[$file['path'] . $file['file']])) {
|
164 |
+
if ($hashData[$file['path'] . $file['file']]['o'] == $file['crc'] ||
|
165 |
+
$hashData[$file['path'] . $file['file']]['c'] == $file['crc']
|
166 |
+
) {
|
167 |
+
unset($this->_files[$id]);
|
168 |
+
$storeNewFile = false;
|
169 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
}
|
171 |
+
if ($storeNewFile) {
|
172 |
+
$img = $imgModel
|
173 |
+
->setCreatedate(now())
|
174 |
+
->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_NEW)
|
175 |
+
->setFullPath($file['path'] . $file['file'])
|
176 |
+
->setImageName($file['file'])
|
177 |
+
->setOriginalChecksum($file['crc'])
|
178 |
+
->setOriginalSize($file['size']);
|
179 |
+
|
180 |
+
if ($file['size'] > self::MAX_FILE_SIZE) {
|
181 |
+
$img->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_TOBIG);
|
182 |
+
}
|
183 |
|
184 |
+
try {
|
185 |
+
$img->save();
|
186 |
+
|
187 |
+
$hashData[$img->getFullPath()] = array(
|
188 |
+
'o' => $img->getOriginalChecksum(),
|
189 |
+
'c' => $img->getConvertedChecksum()
|
190 |
+
);
|
191 |
+
$imgCount++;
|
192 |
+
} catch (Exception $ex) {
|
193 |
+
Mage::log($ex->getMessage());
|
194 |
+
}
|
195 |
+
|
196 |
+
$img->unsetData();
|
197 |
}
|
|
|
198 |
}
|
199 |
}
|
200 |
+
return $imgCount;
|
201 |
}
|
202 |
|
203 |
+
public function getDirectoryFiles($path, $recur = true)
|
204 |
{
|
205 |
if (in_array($path, $this->_excludedir)) {
|
206 |
return;
|
207 |
}
|
208 |
+
if ($handle = opendir($path)) {
|
209 |
+
while (false !== ($file = readdir($handle))) {
|
210 |
+
if ($file == '.' || $file == '..') {
|
211 |
+
continue;
|
212 |
+
}
|
213 |
+
if (is_dir($path . $file)) {
|
214 |
+
if ($recur) {
|
215 |
+
$this->getDirectoryFiles($path . $file . DS, $recur);
|
216 |
+
}
|
217 |
+
} else {
|
218 |
+
$ext = substr($file, strrpos($file, '.') + 1);
|
219 |
+
if (in_array($ext, $this->_ext)) {
|
220 |
+
$this->_files[] = array(
|
221 |
+
'path' => $path,
|
222 |
+
'file' => $file,
|
223 |
+
'crc' => sha1_file($path . $file),
|
224 |
+
'size' => filesize($path . $file),
|
225 |
+
);
|
226 |
+
}
|
227 |
}
|
228 |
}
|
229 |
+
closedir($handle);
|
230 |
}
|
231 |
}
|
232 |
|
app/code/community/Rapido/ImageOptimizer/Model/System/Config/Backend/Serialized.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Rapido_ImageOptimizer_Model_System_Config_Backend_Serialized extends Mage_Adminhtml_Model_System_Config_Backend_Serialized
|
4 |
+
{
|
5 |
+
|
6 |
+
protected function _afterLoad()
|
7 |
+
{
|
8 |
+
$value = (string)$this->getValue();
|
9 |
+
$this->setValue(empty($value) ? false : unserialize($value));
|
10 |
+
}
|
11 |
+
|
12 |
+
protected function _beforeSave()
|
13 |
+
{
|
14 |
+
|
15 |
+
if (is_array($this->getValue())) {
|
16 |
+
$val = $this->getValue();
|
17 |
+
unset($val['__empty']);
|
18 |
+
$this->setValue(serialize($val));
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
}
|
app/code/community/Rapido/ImageOptimizer/controllers/Tools/Image/OptimizerController.php
CHANGED
@@ -3,6 +3,11 @@
|
|
3 |
class Rapido_ImageOptimizer_Tools_Image_OptimizerController extends Mage_Adminhtml_Controller_Action
|
4 |
{
|
5 |
|
|
|
|
|
|
|
|
|
|
|
6 |
public function indexAction()
|
7 |
{
|
8 |
$this->loadLayout()
|
@@ -122,4 +127,4 @@ class Rapido_ImageOptimizer_Tools_Image_OptimizerController extends Mage_Adminht
|
|
122 |
|
123 |
$this->_redirectReferer();
|
124 |
}
|
125 |
-
}
|
3 |
class Rapido_ImageOptimizer_Tools_Image_OptimizerController extends Mage_Adminhtml_Controller_Action
|
4 |
{
|
5 |
|
6 |
+
public function _isAllowed()
|
7 |
+
{
|
8 |
+
return Mage::getSingleton('admin/session')->isAllowed('system/tools/imageoptimizer');
|
9 |
+
}
|
10 |
+
|
11 |
public function indexAction()
|
12 |
{
|
13 |
$this->loadLayout()
|
127 |
|
128 |
$this->_redirectReferer();
|
129 |
}
|
130 |
+
}
|
app/code/community/Rapido/ImageOptimizer/data/rapido_imageoptimizer_setup/data-upgrade-15.168.1-15.171.1.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer=$this;
|
4 |
+
|
5 |
+
$includeDir = explode("\n", Mage::getStoreConfig('cms/rapido_imageoptimizer/include_dirs'));
|
6 |
+
$excludeDir = explode("\n", Mage::getStoreConfig('cms/rapido_imageoptimizer/exclude_dirs'));
|
7 |
+
|
8 |
+
$dirs = array();
|
9 |
+
foreach ($includeDir as $dir) {
|
10 |
+
$dir = trim($dir);
|
11 |
+
if (!$dir) {
|
12 |
+
continue;
|
13 |
+
}
|
14 |
+
$dirs[] = array(
|
15 |
+
'path' => $dir,
|
16 |
+
'recur' => 1,
|
17 |
+
'action' => 1 // Include path
|
18 |
+
);
|
19 |
+
}
|
20 |
+
|
21 |
+
foreach ($excludeDir as $dir) {
|
22 |
+
$dir = trim($dir);
|
23 |
+
if (!$dir) {
|
24 |
+
continue;
|
25 |
+
}
|
26 |
+
$dirs[] = array(
|
27 |
+
'path' => $dir,
|
28 |
+
'recur' => 1,
|
29 |
+
'action' => 2 // Exclude path
|
30 |
+
);
|
31 |
+
}
|
32 |
+
|
33 |
+
$setup = new Mage_Core_Model_Config();
|
34 |
+
$setup->saveConfig('cms/rapido_imageoptimizer/directories', serialize($dirs), 'default', 0);
|
app/code/community/Rapido/ImageOptimizer/{Helper/.Data.php.swo → etc/.config.xml.swp}
RENAMED
Binary file
|
app/code/community/Rapido/ImageOptimizer/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Rapido_ImageOptimizer>
|
5 |
-
<version>15.
|
6 |
</Rapido_ImageOptimizer>
|
7 |
</modules>
|
8 |
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Rapido_ImageOptimizer>
|
5 |
+
<version>15.212.1</version>
|
6 |
</Rapido_ImageOptimizer>
|
7 |
</modules>
|
8 |
|
app/code/community/Rapido/ImageOptimizer/etc/system.xml
CHANGED
@@ -21,7 +21,7 @@
|
|
21 |
</version>
|
22 |
<api_user translate="label comment">
|
23 |
<label>API Username</label>
|
24 |
-
<comment
|
25 |
<frontend_type>password</frontend_type>
|
26 |
<sort_order>10</sort_order>
|
27 |
<show_in_default>1</show_in_default>
|
@@ -73,24 +73,16 @@
|
|
73 |
<show_in_website>0</show_in_website>
|
74 |
<show_in_store>0</show_in_store>
|
75 |
</hourly_convert_files>
|
76 |
-
<
|
77 |
<label>Search directories</label>
|
78 |
<comment>Supply directory path (from Magento root), one per line</comment>
|
79 |
-
<frontend_type>textarea</frontend_type>
|
80 |
<sort_order>40</sort_order>
|
81 |
<show_in_default>1</show_in_default>
|
82 |
<show_in_website>0</show_in_website>
|
83 |
<show_in_store>0</show_in_store>
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
<comment>Supply directory path (from Magento root), one per line</comment>
|
88 |
-
<frontend_type>textarea</frontend_type>
|
89 |
-
<sort_order>41</sort_order>
|
90 |
-
<show_in_default>1</show_in_default>
|
91 |
-
<show_in_website>0</show_in_website>
|
92 |
-
<show_in_store>0</show_in_store>
|
93 |
-
</exclude_dirs>
|
94 |
<extensions translate="label comment">
|
95 |
<label>File extensions</label>
|
96 |
<frontend_type>multiselect</frontend_type>
|
21 |
</version>
|
22 |
<api_user translate="label comment">
|
23 |
<label>API Username</label>
|
24 |
+
<comment><![CDATA[Supplied API Username.<br>No account? Register now on <a target=_blank href='https://www.rapido.nu/?utm_source=magentoconnect&utm_medium=module&utm_campaign=rapido-image-optimizer&utm_content=need-api-key'>Rapido.nu</a> ]]></comment>
|
25 |
<frontend_type>password</frontend_type>
|
26 |
<sort_order>10</sort_order>
|
27 |
<show_in_default>1</show_in_default>
|
73 |
<show_in_website>0</show_in_website>
|
74 |
<show_in_store>0</show_in_store>
|
75 |
</hourly_convert_files>
|
76 |
+
<directories>
|
77 |
<label>Search directories</label>
|
78 |
<comment>Supply directory path (from Magento root), one per line</comment>
|
|
|
79 |
<sort_order>40</sort_order>
|
80 |
<show_in_default>1</show_in_default>
|
81 |
<show_in_website>0</show_in_website>
|
82 |
<show_in_store>0</show_in_store>
|
83 |
+
<frontend_model>rapido_imageoptimizer/system_config_form_directories</frontend_model>
|
84 |
+
<backend_model>rapido_imageoptimizer/system_config_backend_serialized</backend_model>
|
85 |
+
</directories>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
<extensions translate="label comment">
|
87 |
<label>File extensions</label>
|
88 |
<frontend_type>multiselect</frontend_type>
|
app/design/adminhtml/default/default/template/rapido/imageoptimizer/system/config/form/field/array.phtml
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$_htmlId = $this->getHtmlId() ? $this->getHtmlId() : '_' . uniqid();
|
3 |
+
|
4 |
+
$_colspan = 2;
|
5 |
+
if (!$this->_addAfter) {
|
6 |
+
$_colspan -= 1;
|
7 |
+
}
|
8 |
+
$_colspan = $_colspan > 1 ? 'colspan="' . $_colspan . '"' : '';
|
9 |
+
?>
|
10 |
+
|
11 |
+
<div class="grid" id="grid<?php echo $_htmlId ?>">
|
12 |
+
<table cellpadding="0" cellspacing="0" class="border">
|
13 |
+
<tbody>
|
14 |
+
|
15 |
+
<tr class="headings" id="headings<?php echo $_htmlId ?>">
|
16 |
+
<?php foreach ($this->_columns as $columnName => $column): ?>
|
17 |
+
<th><?php echo $column['label'] ?></th>
|
18 |
+
<?php endforeach; ?>
|
19 |
+
<th <?php echo $_colspan ?>></th>
|
20 |
+
</tr>
|
21 |
+
|
22 |
+
<tr id="addRow<?php echo $_htmlId ?>">
|
23 |
+
<td colspan="<?php echo count($this->_columns) ?>"></td>
|
24 |
+
<td <?php echo $_colspan ?>>
|
25 |
+
<?php if ($this->_addButton): ?>
|
26 |
+
<button style="" onclick="" class="scalable add" type="button"
|
27 |
+
id="addToEndBtn<?php echo $_htmlId ?>">
|
28 |
+
<span><span><span><?php echo $this->_addButtonLabel ?></span></span></span>
|
29 |
+
</button>
|
30 |
+
<?php endif; ?>
|
31 |
+
</td>
|
32 |
+
</tr>
|
33 |
+
|
34 |
+
</tbody>
|
35 |
+
</table>
|
36 |
+
<input type="hidden" name="<?php echo $this->getElement()->getName() ?>[__empty]" value=""/>
|
37 |
+
</div>
|
38 |
+
<?php if ($this->_addButton): ?>
|
39 |
+
<div id="empty<?php echo $_htmlId ?>">
|
40 |
+
<button style="" onclick="" class="scalable add" type="button" id="emptyAddBtn<?php echo $_htmlId ?>">
|
41 |
+
<span><span><span><?php echo $this->_addButtonLabel ?></span></span></span>
|
42 |
+
</button>
|
43 |
+
</div>
|
44 |
+
<?php endif; ?>
|
45 |
+
|
46 |
+
<script type="text/javascript">
|
47 |
+
//<![CDATA[
|
48 |
+
// create row creator
|
49 |
+
var arrayRow<?php echo $_htmlId ?> = {
|
50 |
+
// define row prototypeJS template
|
51 |
+
template: new Template(
|
52 |
+
'<tr id="#{_id}">'
|
53 |
+
<?php foreach ($this->_columns as $columnName => $column):?>
|
54 |
+
+ '<td>'
|
55 |
+
+ '<?php echo $this->_renderCellTemplate($columnName)?>'
|
56 |
+
+ '<\/td>'
|
57 |
+
<?php endforeach;?>
|
58 |
+
<?php if ($this->_addAfter):?>
|
59 |
+
+ '<td><button onclick="" class="scalable add" type="button" id="addAfterBtn#{_id}"><span><span><span><?php echo Mage::helper('adminhtml')->__('Add after') ?><\/span><\/span><\/span><\/button><\/td>'
|
60 |
+
<?php endif;?>
|
61 |
+
+ '<td><button onclick="arrayRow<?php echo $_htmlId ?>.del(\'#{_id}\')" class="scalable delete" type="button"><span><span><span><?php echo Mage::helper('adminhtml')->__('Delete') ?><\/span><\/span><\/span><\/button><\/td>'
|
62 |
+
+ '<\/tr>'
|
63 |
+
),
|
64 |
+
|
65 |
+
rowsCount: 0,
|
66 |
+
|
67 |
+
add: function (templateData, insertAfterId) {
|
68 |
+
// generate default template data
|
69 |
+
if ('' == templateData) {
|
70 |
+
var d = new Date();
|
71 |
+
var templateData = {
|
72 |
+
<?php foreach ($this->_columns as $columnName => $column):?>
|
73 |
+
<?php echo $columnName ?> :
|
74 |
+
'',
|
75 |
+
<?php endforeach;?>
|
76 |
+
_id
|
77 |
+
:
|
78 |
+
'_' + d.getTime() + '_' + d.getMilliseconds()
|
79 |
+
}
|
80 |
+
;
|
81 |
+
}
|
82 |
+
|
83 |
+
// insert before last row
|
84 |
+
if ('' == insertAfterId)
|
85 |
+
{
|
86 |
+
Element.insert($('addRow<?php echo $_htmlId ?>'), {before: this.template.evaluate(templateData)});
|
87 |
+
}
|
88 |
+
// insert after specified row
|
89 |
+
else
|
90 |
+
{
|
91 |
+
Element.insert($(insertAfterId), {after: this.template.evaluate(templateData)});
|
92 |
+
}
|
93 |
+
|
94 |
+
<?php if ($this->_addAfter):?>
|
95 |
+
Event.observe('addAfterBtn' + templateData._id, 'click', this.add.bind(this, '', templateData._id));
|
96 |
+
<?php endif;?>
|
97 |
+
|
98 |
+
this.rowsCount += 1;
|
99 |
+
},
|
100 |
+
|
101 |
+
del : function (rowId) {
|
102 |
+
$(rowId).remove();
|
103 |
+
this.rowsCount -= 1;
|
104 |
+
if (0 == this.rowsCount) {
|
105 |
+
this.showButtonOnly();
|
106 |
+
}
|
107 |
+
}
|
108 |
+
,
|
109 |
+
|
110 |
+
showButtonOnly : function () {
|
111 |
+
$('grid<?php echo $_htmlId ?>').hide();
|
112 |
+
$('empty<?php echo $_htmlId ?>').show();
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
<?php if ($this->_addButton):?>
|
117 |
+
// bind add action to "Add" button in last row
|
118 |
+
Event.observe('addToEndBtn<?php echo $_htmlId ?>', 'click', arrayRow<?php echo $_htmlId ?>.add.bind(arrayRow<?php echo $_htmlId ?>, '', ''));
|
119 |
+
<?php endif;?>
|
120 |
+
|
121 |
+
// add existing rows
|
122 |
+
<?php
|
123 |
+
$_addAfterId = "headings{$_htmlId}";
|
124 |
+
foreach ($this->getArrayRows() as $_rowId => $_row) {
|
125 |
+
echo "arrayRow{$_htmlId}.add(" . $_row->toJson() . ", '{$_addAfterId}');\n";
|
126 |
+
$_addAfterId = $_rowId;
|
127 |
+
}
|
128 |
+
?>
|
129 |
+
|
130 |
+
// initialize standalone button
|
131 |
+
$('empty<?php echo $_htmlId ?>').hide();
|
132 |
+
Event.observe('emptyAddBtn<?php echo $_htmlId ?>', 'click', function () {
|
133 |
+
$('grid<?php echo $_htmlId ?>').show();
|
134 |
+
$('empty<?php echo $_htmlId ?>').hide();
|
135 |
+
arrayRow<?php echo $_htmlId ?>.add('', '');
|
136 |
+
});
|
137 |
+
|
138 |
+
// if no rows, hide grid and show button only
|
139 |
+
<?php if (!$this->getArrayRows()):?>
|
140 |
+
arrayRow<?php echo $_htmlId ?>.showButtonOnly();
|
141 |
+
<?php endif;?>
|
142 |
+
|
143 |
+
// toggle the grid, if element is disabled (depending on scope)
|
144 |
+
<?php if ($this->getElement()->getDisabled()):?>
|
145 |
+
toggleValueElements({checked: true}, $('grid<?php echo $_htmlId ?>').parentNode);
|
146 |
+
<?php endif;?>
|
147 |
+
|
148 |
+
$$('.is-enabled-hidden').each(function (el) {
|
149 |
+
var values = el.value.split(',');
|
150 |
+
var count;
|
151 |
+
for (count = 0; count < values.length; count += 1) {
|
152 |
+
el.next('select').select('option[value=' + values[count] + ']')[0].writeAttribute('selected', 'selected');
|
153 |
+
}
|
154 |
+
});
|
155 |
+
//]]>
|
156 |
+
</script>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>rapido_image_optimizer</name>
|
4 |
-
<version>15.
|
5 |
<stability>stable</stability>
|
6 |
<license>OSL v.3.0</license>
|
7 |
<channel>community</channel>
|
@@ -10,9 +10,9 @@
|
|
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-
|
14 |
-
<time>08:
|
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"/><file name="Version.php" hash="a67af2e1efaa03b8c42e915b3d2edb99"/></dir><dir name="Images"><dir name="List"><file name="Grid.php" hash="6387d5a9b72c907475a48f17a944bdf7"/><file name="Totals.php" hash="d6c3748a0f7a0c7706e57cf3895289f6"/></dir><file name="List.php" hash="
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.4.0</min><max>5.6.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>rapido_image_optimizer</name>
|
4 |
+
<version>15.212.1</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>OSL v.3.0</license>
|
7 |
<channel>community</channel>
|
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-08-07</date>
|
14 |
+
<time>08:09:32</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"/><file name="Version.php" hash="a67af2e1efaa03b8c42e915b3d2edb99"/></dir><dir name="Images"><dir name="List"><file name="Grid.php" hash="6387d5a9b72c907475a48f17a944bdf7"/><file name="Totals.php" hash="d6c3748a0f7a0c7706e57cf3895289f6"/></dir><file name="List.php" hash="706c54b2d84086820127814036062fcf"/></dir><dir name="System"><dir name="Config"><dir name="Form"><file name="Directories.php" hash="bf9fcfeac743cd0be3e668e9cf29fae5"/><dir name="Field"><dir name="Array"><file name="Abstract.php" hash="c27a26c08695d6e8007925190ee4767f"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="920fedcf289fd7822956f2cad5c085a8"/></dir><dir name="Model"><file name="Cron.php" hash="7ad58f715c924fa3bd136a22578d42f4"/><file name="Images.php" hash="cac2e6eba424d2fad5784766a04a37e4"/><file name="Observer.php" hash="928f67581b63689d6eae2c5fb017335d"/><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="fcab9d88496dba363a656350e78b917c"/><dir name="System"><dir name="Config"><dir name="Backend"><file name="Serialized.php" hash="16f3c904001363b25910aadfbcd0cc96"/></dir><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="cdc82bc9d42394ec255fc1e43e4a4e02"/></dir></dir></dir><dir name="data"><dir name="rapido_imageoptimizer_setup"><file name="data-upgrade-15.168.1-15.171.1.php" hash="d4dda33a8596964bafb9a8ffff4515e7"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="9243d31a493db1fd7667d47cb15e1929"/><file name="config.xml" hash="c44efb74b43a44364c1bc0113a9884b6"/><file name="system.xml" hash="1d8f15308d6c6941c4980e96c388e1a3"/><file name=".config.xml.swp" hash="2537aca2288682c52419864b22478d76"/></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"><dir name="system"><dir name="config"><dir name="form"><dir name="field"><file name="array.phtml" hash="6ffdd96d836167483a8bdb438fcee02a"/></dir></dir></dir></dir><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="d35ea48b3682bd58415d995bd6acbe75"/></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.4.0</min><max>5.6.0</max></php></required></dependencies>
|
18 |
</package>
|
shell/imageoptimizer.php
CHANGED
@@ -16,6 +16,10 @@ class Rapido_Shell_ImageOptimizer extends Mage_Shell_Abstract
|
|
16 |
* Run script
|
17 |
*
|
18 |
*/
|
|
|
|
|
|
|
|
|
19 |
public function run()
|
20 |
{
|
21 |
$helper = Mage::helper('rapido_imageoptimizer');
|
@@ -49,7 +53,9 @@ class Rapido_Shell_ImageOptimizer extends Mage_Shell_Abstract
|
|
49 |
}
|
50 |
|
51 |
foreach ($collection as $file) {
|
|
|
52 |
if ($helper->convertImage($file)) {
|
|
|
53 |
$converted++;
|
54 |
}
|
55 |
}
|
@@ -61,6 +67,7 @@ class Rapido_Shell_ImageOptimizer extends Mage_Shell_Abstract
|
|
61 |
|
62 |
foreach ($collection as $file) {
|
63 |
if ($helper->downloadImage($file)) {
|
|
|
64 |
$downloaded++;
|
65 |
}
|
66 |
}
|
@@ -74,11 +81,114 @@ class Rapido_Shell_ImageOptimizer extends Mage_Shell_Abstract
|
|
74 |
|
75 |
} elseif (isset($this->_args['test'])) {
|
76 |
var_dump($helper->checkApi());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
} else {
|
78 |
echo $this->usageHelp();
|
79 |
}
|
80 |
}
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
/**
|
83 |
* Retrieve Usage Help Message
|
84 |
*
|
16 |
* Run script
|
17 |
*
|
18 |
*/
|
19 |
+
|
20 |
+
protected $_excludedir = array();
|
21 |
+
const MAX_FILE_SIZE = 16000000;
|
22 |
+
|
23 |
public function run()
|
24 |
{
|
25 |
$helper = Mage::helper('rapido_imageoptimizer');
|
53 |
}
|
54 |
|
55 |
foreach ($collection as $file) {
|
56 |
+
$this->debugMsg('Uploading image: %s (ID: %s)', $file->getImageName(), $file->getId());
|
57 |
if ($helper->convertImage($file)) {
|
58 |
+
$this->debugMsg('Waiting for conversion: %s (ID: %s)', $file->getImageName(), $file->getId());
|
59 |
$converted++;
|
60 |
}
|
61 |
}
|
67 |
|
68 |
foreach ($collection as $file) {
|
69 |
if ($helper->downloadImage($file)) {
|
70 |
+
$this->debugMsg('Conversion completed: %s (ID: %s)', $file->getImageName(), $file->getId());
|
71 |
$downloaded++;
|
72 |
}
|
73 |
}
|
81 |
|
82 |
} elseif (isset($this->_args['test'])) {
|
83 |
var_dump($helper->checkApi());
|
84 |
+
} elseif (isset($this->_args['testcollect'])) {
|
85 |
+
$collection = Mage::getResourceModel('rapido_imageoptimizer/images_collection');
|
86 |
+
$hashData = array();
|
87 |
+
|
88 |
+
while ($images = $collection->fetchItem()) {
|
89 |
+
$hashData[$images->getFullPath()] = array(
|
90 |
+
'o' => $images->getOriginalChecksum(),
|
91 |
+
'c' => $images->getConvertedChecksum()
|
92 |
+
);
|
93 |
+
}
|
94 |
+
|
95 |
+
$ext = '{*.'.implode(',*.', explode(",", $this->getConfig('extensions'))).'}';
|
96 |
+
|
97 |
+
$dirs = unserialize($this->getConfig('directories'));
|
98 |
+
$basePaths = array();
|
99 |
+
foreach ($dirs as $dir) {
|
100 |
+
$path = trim($dir['path']);
|
101 |
+
$path = trim($path, '\\/');
|
102 |
+
switch ($dir['action']) {
|
103 |
+
case 0: // Disabled
|
104 |
+
break;
|
105 |
+
case 1: // Include path
|
106 |
+
$basePaths[] = array(
|
107 |
+
'path' =>rtrim(Mage::getBaseDir(), '\\/') . DS . $path,
|
108 |
+
'recur' => $dir['recur'],
|
109 |
+
);
|
110 |
+
break;
|
111 |
+
case 2: // Exclude path
|
112 |
+
$this->_excludedir[] = rtrim(Mage::getBaseDir(), '\\/') . DS . $path . DS;
|
113 |
+
}
|
114 |
+
}
|
115 |
+
$imgCount = 0;
|
116 |
+
$imgModel = Mage::getModel('rapido_imageoptimizer/images');
|
117 |
+
foreach ($basePaths as $basePath) {
|
118 |
+
if ($basePath['recur']) {
|
119 |
+
$dirs = $this->findAllDirs($basePath['path']);
|
120 |
+
} else {
|
121 |
+
$dirs[] = $basePath['path'];
|
122 |
+
}
|
123 |
+
foreach ($dirs as $dir) {
|
124 |
+
$match = glob($dir . $ext, GLOB_NOSORT|GLOB_BRACE);
|
125 |
+
if (!$match) {
|
126 |
+
continue;
|
127 |
+
}
|
128 |
+
foreach ($match as $image) {
|
129 |
+
$file = array();
|
130 |
+
$file['path'] = $dir;
|
131 |
+
$file['file'] = str_replace($dir, '', $image);
|
132 |
+
$file['crc'] = sha1_file($image);
|
133 |
+
$file['size'] = filesize($image);
|
134 |
+
|
135 |
+
if (isset($hashData[$file['path'] . $file['file']])) {
|
136 |
+
if ($hashData[$file['path'] . $file['file']]['o'] == $file['crc'] ||
|
137 |
+
$hashData[$file['path'] . $file['file']]['c'] == $file['crc']
|
138 |
+
) {
|
139 |
+
continue;
|
140 |
+
}
|
141 |
+
}
|
142 |
+
$img = $imgModel
|
143 |
+
->setCreatedate(now())
|
144 |
+
->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_NEW)
|
145 |
+
->setFullPath($file['path'] . $file['file'])
|
146 |
+
->setImageName($file['file'])
|
147 |
+
->setOriginalChecksum($file['crc'])
|
148 |
+
->setOriginalSize($file['size']);
|
149 |
+
|
150 |
+
if ($file['size'] > self::MAX_FILE_SIZE) {
|
151 |
+
$img->setStatus(Rapido_ImageOptimizer_Model_Status::STATUS_TOBIG);
|
152 |
+
}
|
153 |
+
|
154 |
+
try {
|
155 |
+
$img->save();
|
156 |
+
|
157 |
+
$hashData[$img->getFullPath()] = array(
|
158 |
+
'o' => $img->getOriginalChecksum(),
|
159 |
+
'c' => $img->getConvertedChecksum()
|
160 |
+
);
|
161 |
+
$imgCount++;
|
162 |
+
} catch (Exception $ex) {
|
163 |
+
Mage::log($ex->getMessage());
|
164 |
+
}
|
165 |
+
|
166 |
+
$img->unsetData();
|
167 |
+
}
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
echo Mage::helper('rapido_imageoptimizer')->__('%s new image files collected!', $imgCount) . "\n\n";
|
172 |
+
|
173 |
} else {
|
174 |
echo $this->usageHelp();
|
175 |
}
|
176 |
}
|
177 |
|
178 |
+
|
179 |
+
protected function debugMsg()
|
180 |
+
{
|
181 |
+
if (!isset($this->_args['debug'])) {
|
182 |
+
return;
|
183 |
+
}
|
184 |
+
|
185 |
+
echo call_user_func_array("sprintf", func_get_args());
|
186 |
+
echo "\n";
|
187 |
+
}
|
188 |
+
protected function getConfig($key)
|
189 |
+
{
|
190 |
+
return Mage::getStoreConfig('cms/rapido_imageoptimizer/' . $key);
|
191 |
+
}
|
192 |
/**
|
193 |
* Retrieve Usage Help Message
|
194 |
*
|