MTurbo - Version 1.2.8

Version Notes

Visit product homepage at:
http://www.artio.net/magento-extensions/m-turbo-accelerator

Download this release

Release Info

Developer Magento Core Team
Extension MTurbo
Version 1.2.8
Comparing to
See all releases


Code changes from version 1.2.7.1 to 1.2.8

Files changed (39) hide show
  1. app/code/local/Artio/MTurbo/Block/Adminhtml/Edit/Tab/Dynamic.php +160 -73
  2. app/code/local/Artio/MTurbo/Block/Adminhtml/Edit/Tab/Url.php +11 -12
  3. app/code/local/Artio/MTurbo/Block/Adminhtml/Welcome/Form.php +6 -1
  4. app/code/local/Artio/MTurbo/Block/Ajax.php +34 -38
  5. app/code/local/Artio/MTurbo/Block/Checkout/Cart/Item/Renderer/Configurable.php +31 -0
  6. app/code/local/Artio/MTurbo/Block/Dynamic.php +79 -0
  7. app/code/local/Artio/MTurbo/Block/Esi.php +48 -0
  8. app/code/local/Artio/MTurbo/Helper/Data.php +2 -2
  9. app/code/local/Artio/MTurbo/Helper/Functions.php +152 -78
  10. app/code/local/Artio/MTurbo/Helper/Info.php +1 -1
  11. app/code/local/Artio/MTurbo/Model/Config.php +66 -1
  12. app/code/local/Artio/MTurbo/Model/Config/DynamicTransformer.php +127 -102
  13. app/code/local/Artio/MTurbo/Model/DownloadMethods/Curlmulti.php +2 -0
  14. app/code/local/Artio/MTurbo/Model/DownloadQueue.php +2 -2
  15. app/code/local/Artio/MTurbo/Model/Htaccess.php +17 -1
  16. app/code/local/Artio/MTurbo/Model/JsPatch.php +0 -129
  17. app/code/local/Artio/MTurbo/Model/Layout.php +317 -0
  18. app/code/local/Artio/MTurbo/Model/Mturbo.php +42 -18
  19. app/code/local/Artio/MTurbo/Model/Mturbo/Event.php +14 -2
  20. app/code/local/Artio/MTurbo/Model/Mturbo/File.php +4 -0
  21. app/code/local/Artio/MTurbo/Model/Observer.php +174 -156
  22. app/code/local/Artio/MTurbo/Model/htaccess/htaccessstoreboth.txt +46 -0
  23. app/code/local/Artio/MTurbo/Model/htaccess/htaccesswebsiteboth.txt +21 -0
  24. app/code/local/Artio/MTurbo/Model/scripts/wgetlib.so +1 -1
  25. app/code/local/Artio/MTurbo/controllers/Adminhtml/MturboController.php +52 -19
  26. app/code/local/Artio/MTurbo/controllers/AdminhtmlController.php +28 -7
  27. app/code/local/Artio/MTurbo/controllers/IndexController.php +177 -34
  28. app/code/local/Artio/MTurbo/etc/config.xml +5 -1
  29. app/code/local/Artio/MTurbo/sql/mturbo_setup/mysql4-upgrade-1.0.0-1.2.0.php +0 -96
  30. app/code/local/Artio/MTurbo/sql/mturbo_setup/mysql4-upgrade-1.2.1-1.2.7.php +8 -12
  31. app/code/local/Artio/MTurbo/sql/mturbo_setup/{mysql4-upgrade-1.2.0-1.2.1.php → mysql4-upgrade-1.2.7-1.2.8.php} +5 -18
  32. app/design/adminhtml/default/default/layout/mturbo.xml +2 -1
  33. app/design/adminhtml/default/default/template/mturbo/formkey_warn.phtml +61 -0
  34. app/design/adminhtml/default/default/template/mturbo/tabs/dynamic.phtml +82 -0
  35. app/design/frontend/base/default/layout/mturbo.xml +37 -0
  36. app/design/frontend/default/default/layout/mturbo.xml +1 -1
  37. package.xml +5 -5
  38. skin/frontend/base/default/js/mturbo.js +0 -55
  39. skin/frontend/default/default/js/mturbo.js +0 -55
app/code/local/Artio/MTurbo/Block/Adminhtml/Edit/Tab/Dynamic.php CHANGED
@@ -36,6 +36,22 @@ class Artio_MTurbo_Block_Adminhtml_Edit_Tab_Dynamic
36
extends Artio_MTurbo_Block_Adminhtml_Edit_Tab_Abstract
37
{
38
39
/**
40
* Constructor.
41
*/
@@ -66,58 +82,22 @@ class Artio_MTurbo_Block_Adminhtml_Edit_Tab_Dynamic
66
67
/* fieldset for automatic refresh */
68
$layoutFieldsetDefault = $form->addFieldset('dynamic_block_default', array(
69
- 'legend' => $this->getMyHelper()->__( 'Default dynamic loaded blocks' ),
70
'class' => 'fieldset'
71
));
72
73
- $layoutFieldsetDefault->addField('cartsidebar', 'select', array(
74
- 'name' => 'cartsidebar',
75
- 'label' => $this->getMyHelper()->__('Cart Block (sidebar)').':',
76
- 'options' => array(
77
- 0 => $this->getMyHelper()->__('No'),
78
- 1 => $this->getMyHelper()->__ ( 'Yes' ))
79
- ));
80
-
81
- $layoutFieldsetDefault->addField('pollsidebar', 'select', array(
82
- 'name' => 'pollsidebar',
83
- 'label' => $this->getMyHelper()->__('Poll Block (sidebar)').':',
84
- 'options' => array(
85
- 0 => $this->getMyHelper()->__('No'),
86
- 1 => $this->getMyHelper()->__ ( 'Yes' ))
87
- ));
88
-
89
- $layoutFieldsetDefault->addField('comparesidebar', 'select', array(
90
- 'name' => 'comparesidebar',
91
- 'label' => $this->getMyHelper()->__('Compare Block (sidebar)').':',
92
- 'options' => array(
93
- 0 => $this->getMyHelper()->__('No'),
94
- 1 => $this->getMyHelper()->__ ( 'Yes' ))
95
- ));
96
-
97
$layoutFieldsetDefault->addField('cartlink', 'text', array(
98
'name' => 'cartlink',
99
'label' => $this->getMyHelper()->__('CSS selector for cart link').':',
100
'after_element_html' => '<span><i>'.$this->getMyHelper()->__("Separate the values by comma ','.").'</i></span>'
101
));
102
-
103
-
104
- $layoutFieldsetUser = $form->addFieldset('dynamic_block_user', array(
105
- 'legend' => $this->getMyHelper()->__( 'User dynamic loaded blocks (only for advanced developers).' ),
106
- 'class' => 'fieldset'
107
- ));
108
-
109
- $layoutFieldsetUser->addField('userblocks', 'textarea', array(
110
- 'name' => 'userblocks',
111
- 'label' => $this->getMyHelper()->__('Layout names of dynamic loaded blocks').':',
112
- 'after_element_html' => '<span><i>'.$this->getMyHelper()->__("Separate the block identifiers by comma ','. Separate a layout handle from a layout name by '#x27;. (Ex.: block,catalog_category_default\$other_block)").'</i></span>'
113
- ));
114
-
115
- $this->_addJsFixFieldset($form);
116
-
117
}
118
119
/* bind data */
120
- $form->setValues(Mage::getSingleton('mturbo/config_dynamicTransformer')->configToForm($config));
121
$this->setForm($form);
122
123
return parent::_prepareForm();
@@ -162,41 +142,148 @@ class Artio_MTurbo_Block_Adminhtml_Edit_Tab_Dynamic
162
}
163
164
165
- }
166
167
/**
168
- * Method adds fieldset for copying js file into all theme package.
169
- * @param Varien_Data_Form $form
170
*/
171
- private function _addJsFixFieldset($form) {
172
-
173
- $layoutFieldset = $form->addFieldset('layout_fieldset_watcher', array(
174
- 'legend' => $this->getMyHelper()->__('JavaScript Watcher (this control watches existing javascript in all your theme packages)'),
175
- 'class' => 'fieldset'
176
- ));
177
-
178
- /* @var $js Artio_MTurbo_Model_JsPatch */
179
- $js = Mage::getSingleton('mturbo/jsPatch');
180
-
181
- /* @var $themePackage Artio_MTurbo_Model_JsPatch */
182
- $layoutFieldset->addType('html_element', Artio_MTurbo_Helper_Data::FORM_HTML);
183
- foreach ($js->getAvailableThemePackages() as $i=>$themePackage) {
184
-
185
- if (!$themePackage->existsJs() && !$themePackage->makeJs()) {
186
- $html = '<span style="color:red">'.$this->getMyHelper()->__("Copying js file failed! Dynamic blocks won't work for this theme. Copy 'mturbo.js' from default theme, please!").'</span>';
187
- } else {
188
- $html = '<span style="color:green">'.$this->getMyHelper()->__("OK").'</span>';
189
- }
190
-
191
- $layoutFieldset->addField ('jsstate'.$i, 'html_element',
192
- array (
193
- 'label' => str_replace(Mage::getBaseDir().DS.'skin'.DS.'frontend', '', $themePackage->getJsPath()),
194
- 'code' => $html)
195
- );
196
-
197
- }
198
-
199
-
200
}
201
202
}
36
extends Artio_MTurbo_Block_Adminhtml_Edit_Tab_Abstract
37
{
38
39
+ /**
40
+ * The form data values
41
+ *
42
+ * array(
43
+ * 'cartlinks' => single string
44
+ * 'userblocks' => array(
45
+ * array('name' => name1, 'type' => type1),
46
+ * array('name' => name2, 'type' => type2),
47
+ * ...
48
+ * )
49
+ * )
50
+ *
51
+ * @var array
52
+ */
53
+ protected $_formDataValues = array();
54
+
55
/**
56
* Constructor.
57
*/
82
83
/* fieldset for automatic refresh */
84
$layoutFieldsetDefault = $form->addFieldset('dynamic_block_default', array(
85
+ 'legend' => $this->getMyHelper()->__( 'Cart link' ),
86
'class' => 'fieldset'
87
));
88
89
$layoutFieldsetDefault->addField('cartlink', 'text', array(
90
'name' => 'cartlink',
91
'label' => $this->getMyHelper()->__('CSS selector for cart link').':',
92
'after_element_html' => '<span><i>'.$this->getMyHelper()->__("Separate the values by comma ','.").'</i></span>'
93
));
94
+
95
}
96
97
/* bind data */
98
+ $this->_formDataValues = Mage::getSingleton('mturbo/config_dynamicTransformer')->configToForm($config);
99
+
100
+ $form->setValues($this->_formDataValues);
101
$this->setForm($form);
102
103
return parent::_prepareForm();
142
}
143
144
145
+ }
146
147
/**
148
+ * Get HTML of "Add row" button.
149
+ *
150
+ * @param string $container
151
+ * @param srging $template
152
+ * @param string $title
153
+ * @return string
154
*/
155
+ public function getAddRowButtonHtml($container, $template, $title='Add')
156
+ {
157
+ return $this->getLayout()
158
+ ->createBlock('adminhtml/widget_button')
159
+ ->setType('button')
160
+ ->setClass('add')
161
+ ->setLabel($this->__($title))
162
+ ->setOnClick("addRow('".$container."', '".$template."')")
163
+ ->toHtml();
164
+ }
165
+
166
+
167
+ /**
168
+ * Get HTML of "Remove row" button.
169
+ */
170
+ public function getRemoveRowButtonHtml($selector='span')
171
+ {
172
+ return $this->getLayout()
173
+ ->createBlock('adminhtml/widget_button')
174
+ ->setType('button')
175
+ ->setClass('delete')
176
+ ->setLabel($this->__('Remove'))
177
+ ->setOnClick("removeRow(this, '".$selector."')")
178
+ ->toHtml();
179
+ }
180
+
181
+
182
+ /**
183
+ * Return block types as array (key => value)
184
+ *
185
+ * @return array
186
+ */
187
+ public function getBlockTypes()
188
+ {
189
+ return array(
190
+ Artio_MTurbo_Model_Config_DynamicTransformer::AJAX => $this->getMyHelper()->__('AJAX'),
191
+ // Artio_MTurbo_Model_Config_DynamicTransformer::ESI => $this->getMyHelper()->__('ESI'),
192
+ Artio_MTurbo_Model_Config_DynamicTransformer::DISABLED => $this->getMyHelper()->__('Disabled')
193
+ );
194
+ }
195
+
196
+ /**
197
+ * Get layout handles of all XML.
198
+ *
199
+ * @return array
200
+ */
201
+ public function getBlocks()
202
+ {
203
+ $layout = $this->_getLayoutModel();
204
+
205
+ $result = array();
206
+
207
+ $designs = $layout->getDesignsAsFlatStrings();
208
+
209
+ foreach ($designs as $design)
210
+ {
211
+ $layout->setDesign($design);
212
+
213
+ $blocks = $layout->getBlocks();
214
+
215
+ foreach ($blocks as $block)
216
+ {
217
+ $handle = isset($block['handle']) ? $block['handle'] : '';
218
+ $name = isset($block['name']) ? $block['name'] : '';
219
+ $type = isset($block['type']) ? $block['type'] : '';
220
+
221
+ if (!$handle || !$name)
222
+ continue;
223
+
224
+ $key = $handle.'#x27;.$name;
225
+ $val = $name.($type ? " ($type)" : "");
226
+
227
+ if (!isset($result[$handle]))
228
+ $result[$handle] = array();
229
+
230
+ if (!isset($result[$handle][$key]))
231
+ $result[$handle][$key] = $val;
232
+ }
233
+ }
234
+
235
+ // sort blocks in each handle
236
+ foreach ($result as $h => $b)
237
+ asort($result[$h]);
238
+
239
+ // sort handles
240
+ ksort($result);
241
+
242
+ // move default handle at begining of result
243
+ if (isset($result['default']))
244
+ {
245
+ $default = $result['default'];
246
+ unset($result['default']);
247
+ $result = array_merge(array('default'=>$default), $result);
248
+ }
249
+
250
+ return $result;
251
+ }
252
+
253
+
254
+ /**
255
+ * Get count of user blocks.
256
+ *
257
+ * @return number
258
+ */
259
+ public function getFormUserBlockCount()
260
+ {
261
+ return isset($this->_formDataValues['userblocks']) ? count($this->_formDataValues['userblocks']) : 0;
262
+ }
263
+
264
+
265
+ /**
266
+ * Get user block at index $i. If $i is out of bound
267
+ * method returns null.
268
+ *
269
+ * @param unknown_type $i
270
+ * @return NULL
271
+ */
272
+ public function getFormUserBlock($i)
273
+ {
274
+ return isset($this->_formDataValues['userblocks'][$i]) ? $this->_formDataValues['userblocks'][$i] : null;
275
+ }
276
+
277
+
278
+ /**
279
+ * Get layout model which provides access to
280
+ * the layout data (handles, block names etc.)
281
+ *
282
+ * @return Artio_MTurbo_Model_Layout
283
+ */
284
+ protected function _getLayoutModel()
285
+ {
286
+ return Mage::getModel('mturbo/layout');
287
}
288
289
}
app/code/local/Artio/MTurbo/Block/Adminhtml/Edit/Tab/Url.php CHANGED
@@ -182,7 +182,16 @@ class Artio_MTurbo_Block_Adminhtml_Edit_Tab_Url
182
$this->getMassactionBlock()->setTemplate('mturbo/massaction.phtml');
183
$this->getMassactionBlock()->setFormFieldName('mturbo');
184
185
-
186
$this->getMassactionBlock()->addItem('block', array(
187
'label' => Mage::helper('mturbo')->__('Block'),
188
'url' => $this->getUrl('*/*/massBlock')
@@ -193,16 +202,6 @@ class Artio_MTurbo_Block_Adminhtml_Edit_Tab_Url
193
'url' => $this->getUrl('*/*/massUnblock')
194
));
195
196
- /*$this->getMassactionBlock()->addItem('refresh', array(
197
- 'label' => Mage::helper('mturbo')->__('Cache'),
198
- 'url' => $this->getUrl('*//**//*massRefresh')
199
- ));*/
200
-
201
- $this->getMassactionBlock()->addItem('purge', array(
202
- 'label' => Mage::helper('mturbo')->__('Purge from disk'),
203
- 'url' => $this->getUrl('*/*/massPurge')
204
- ));
205
-
206
$this->getMassactionBlock()->addItem('delete', array(
207
'label' => Mage::helper('mturbo')->__('Delete'),
208
'url' => $this->getUrl('*/*/massDelete'),
@@ -250,7 +249,7 @@ class Artio_MTurbo_Block_Adminhtml_Edit_Tab_Url
250
}
251
$('massrefresh').value = url_section_massactionJsObject.checkedString;
252
this.form.target='_blank';
253
- this.form.action = '".Mage::helper('adminhtml')->getUrl('*/*/massRefresh')."';
254
this.form.submit();
255
setTimeout('location.reload(true);',10);
256
";
182
$this->getMassactionBlock()->setTemplate('mturbo/massaction.phtml');
183
$this->getMassactionBlock()->setFormFieldName('mturbo');
184
185
+ $this->getMassactionBlock()->addItem('refresh', array(
186
+ 'label' => Mage::helper('mturbo')->__('Cache'),
187
+ 'url' => $this->getUrl('*/*/massRefresh')
188
+ ));
189
+
190
+ $this->getMassactionBlock()->addItem('purge', array(
191
+ 'label' => Mage::helper('mturbo')->__('Purge'),
192
+ 'url' => $this->getUrl('*/*/massPurge')
193
+ ));
194
+
195
$this->getMassactionBlock()->addItem('block', array(
196
'label' => Mage::helper('mturbo')->__('Block'),
197
'url' => $this->getUrl('*/*/massBlock')
202
'url' => $this->getUrl('*/*/massUnblock')
203
));
204
205
$this->getMassactionBlock()->addItem('delete', array(
206
'label' => Mage::helper('mturbo')->__('Delete'),
207
'url' => $this->getUrl('*/*/massDelete'),
249
}
250
$('massrefresh').value = url_section_massactionJsObject.checkedString;
251
this.form.target='_blank';
252
+ this.form.action = '".Mage::helper('adminhtml')->getUrl('*/*/massRefreshButton')."';
253
this.form.submit();
254
setTimeout('location.reload(true);',10);
255
";
app/code/local/Artio/MTurbo/Block/Adminhtml/Welcome/Form.php CHANGED
@@ -131,7 +131,12 @@ class Artio_MTurbo_Block_Adminhtml_Welcome_Form extends Mage_Adminhtml_Block_Wid
131
}
132
133
private function _getOkText() {
134
- $text = Mage::helper('mturbo')->__('Welcome text demo');
135
return $this->_wrapInfoDiv($text);
136
}
137
131
}
132
133
private function _getOkText() {
134
+ $text = Mage::helper('mturbo')->__("<p>Welcome to M-Turbo Cache developed by Artio.
135
+ To complete installation, we need to have entered the path to your directory where you want to store cached pages.
136
+ This path is then entered into a .htaccess file, which is a function of the components necessary.</p><p>More, you can choose
137
+ which website you want to caches and which not. Each website you can also choose storeview.
138
+ In addition, please fill out the base directory of each website. In the default settings is set base dir for the administration,
139
+ which does must not correspond to the base dir for the frontend.</p><p style=\"color:red\">Note: In demo version you can enable only one website.</p>");
140
return $this->_wrapInfoDiv($text);
141
}
142
app/code/local/Artio/MTurbo/Block/Ajax.php CHANGED
@@ -26,46 +26,42 @@
26
* @package Artio_MTurbo
27
* @author Artio Magento Team (info@artio.net)
28
*/
29
- class Artio_MTurbo_Block_Ajax extends Mage_Core_Block_Template
30
{
31
32
- public function __construct($attributes=array())
33
- {
34
- parent::__construct($attributes);
35
- $this->setTemplate('mturbo/ajax');
36
- }
37
-
38
- public function __call($method, $args) {
39
- // do not, prevents call undefined methods
40
- }
41
-
42
- public static function __callStatic($name, $arguments) {
43
- // do not, prevents call undefined methods
44
- }
45
-
46
- protected function _toHtml() {
47
-
48
- $id = $this->getData('ajax_identifier');
49
- $clearId = str_replace(array('.', '#x27;), array('_','_'), $id);
50
-
51
- $html = "<div id=\"".$id."\"></div>
52
- <script type=\"text/javascript\">
53
- //<![CDATA[
54
- function fillBlock".$clearId."() {
55
- if (typeof(mturboloader)!='undefined') {
56
- mturboloader;
57
- if (mturboloader.complete) {
58
- $('".$id."').replace(mturboloader.getBlock('".$id."'));
59
- } else {
60
- setTimeout('fillBlock".$clearId."()', 100);
61
- }
62
- }
63
- }
64
- fillBlock".$clearId."();
65
//]]>
66
</script>";
67
-
68
- return $html;
69
- }
70
71
- }
26
* @package Artio_MTurbo
27
* @author Artio Magento Team (info@artio.net)
28
*/
29
+ class Artio_MTurbo_Block_Ajax extends Artio_MTurbo_Block_Dynamic
30
{
31
32
+
33
+ /**
34
+ * (non-PHPdoc)
35
+ * @see Mage_Core_Block_Abstract::_toHtml()
36
+ */
37
+ protected function _toHtml()
38
+ {
39
+ // block must output html here
40
+ // there must not be used a template, because original blocks could override it
41
+
42
+ $id = $this->_getMTurboId();
43
+ $clearId = $this->_getMTurboClearId();
44
+
45
+ return "
46
+ <div id=\"$id\"></div>
47
+ <script type=\"text/javascript\">
48
+ //<![CDATA[
49
+ function fillBlock$clearId() {
50
+
51
+ if (typeof(mturboloader)=='undefined')
52
+ return;
53
+
54
+ if (mturboloader.complete)
55
+ $('$id').replace(mturboloader.getBlock('$id'));
56
+ else
57
+ setTimeout('fillBlock$clearId()', 100);
58
+
59
+ }
60
+
61
+ fillBlock$clearId();
62
//]]>
63
</script>";
64
+ }
65
+
66
67
+ }
app/code/local/Artio/MTurbo/Block/Checkout/Cart/Item/Renderer/Configurable.php ADDED
@@ -0,0 +1,31 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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
+ *
16
+ * @category Artio
17
+ * @package Artio_MTurbo
18
+ * @copyright Copyright (c) 2011 Artio (http://www.artio.net)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+
22
+ /**
23
+ * Shopping cart item render block
24
+ *
25
+ * @category Artio
26
+ * @package Artio_MTurbo
27
+ * @author Artio Magento Team <info@artio.net>
28
+ */
29
+ class Artio_MTurbo_Block_Checkout_Cart_Item_Renderer_Configurable extends Artio_MTurbo_Block_Checkout_Cart_Item_Renderer
30
+ {
31
+ }
app/code/local/Artio/MTurbo/Block/Dynamic.php ADDED
@@ -0,0 +1,79 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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
+ *
16
+ * @category Artio
17
+ * @package Artio_MTurbo
18
+ * @copyright Copyright (c) 2010 Artio (http://www.artio.net)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+
22
+ /**
23
+ * Main container
24
+ *
25
+ * @category Artio
26
+ * @package Artio_MTurbo
27
+ * @author Artio Magento Team (info@artio.net)
28
+ */
29
+ abstract class Artio_MTurbo_Block_Dynamic extends Mage_Core_Block_Template
30
+ {
31
+
32
+
33
+ /**
34
+ * Get block identifier.
35
+ *
36
+ * @return string
37
+ */
38
+ protected function _getMTurboId()
39
+ {
40
+ return $this->getData('identifier');
41
+ }
42
+
43
+
44
+ /**
45
+ * Get cleared block identifer.
46
+ *
47
+ * Method returns identifier as Artio_MTurbo_Block_Ajax::getId(),
48
+ * where all occurences '.' or '#x27; are replaced by '_'.
49
+ *
50
+ * "Clear Id" is used as JavaScript identifier, therefore there must
51
+ * not contain with '.' or '#x27;.
52
+ *
53
+ * @return string
54
+ */
55
+ protected function _getMTurboClearId()
56
+ {
57
+ return str_replace(array('.', '#x27;), array('_','_'), $this->_getMTurboId());
58
+ }
59
+
60
+
61
+ /**
62
+ * (non-PHPdoc)
63
+ */
64
+ public function __call($method, $args) {
65
+ // do nothing, this prevents "undefined method" errors
66
+ // when a method of the original block is called
67
+ }
68
+
69
+
70
+ /**
71
+ * (non-PHPdoc)
72
+ */
73
+ public static function __callStatic($name, $arguments) {
74
+ // do nothing, this prevents "undefined method" errors
75
+ // when a method of the original block is called
76
+ }
77
+
78
+
79
+ }
app/code/local/Artio/MTurbo/Block/Esi.php ADDED
@@ -0,0 +1,48 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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
+ *
16
+ * @category Artio
17
+ * @package Artio_MTurbo
18
+ * @copyright Copyright (c) 2010 Artio (http://www.artio.net)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+
22
+ /**
23
+ * Main container
24
+ *
25
+ * @category Artio
26
+ * @package Artio_MTurbo
27
+ * @author Artio Magento Team (info@artio.net)
28
+ */
29
+ class Artio_MTurbo_Block_Esi extends Artio_MTurbo_Block_Dynamic
30
+ {
31
+
32
+
33
+ /**
34
+ * (non-PHPdoc)
35
+ * @see Mage_Core_Block_Abstract::_toHtml()
36
+ */
37
+ protected function _toHtml()
38
+ {
39
+ // block must output html here
40
+ // there must not be used a template, because original blocks could override it
41
+
42
+ $url = $this->getUrl('mturbofrontend/index/esi', array('identifier' => $this->_getMTurboId()));
43
+
44
+ return "<esi:include src=\"".$url."\" />";
45
+ }
46
+
47
+
48
+ }
app/code/local/Artio/MTurbo/Helper/Data.php CHANGED
@@ -31,9 +31,9 @@ class Artio_MTurbo_Helper_Data extends Mage_Core_Helper_Abstract
31
/* constant for version information */
32
const MAJOR_VERSION = 1;
33
const MINOR_VERSION = 2;
34
- const REVISION = 7;
35
const BUILD = 0;
36
- const DESCRIPTION = 'Demo version. Copyright &copy; 2010-2013 Artio';
37
const TYPE = 'demo';
38
39
/* constants for components of user interface */
31
/* constant for version information */
32
const MAJOR_VERSION = 1;
33
const MINOR_VERSION = 2;
34
+ const REVISION = 8;
35
const BUILD = 0;
36
+ const DESCRIPTION = 'Demo version. Copyright &copy; 2010-2015 Artio';
37
const TYPE = 'demo';
38
39
/* constants for components of user interface */
app/code/local/Artio/MTurbo/Helper/Functions.php CHANGED
@@ -29,6 +29,84 @@
29
class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
30
{
31
32
/**
33
* Function inserts string into another string to the chosen place.
34
*
@@ -42,11 +120,11 @@ class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
42
$part1 = substr($intostring, 0, $offset);
43
$part2 = substr($intostring, $offset);
44
45
- if ($part1 == false || $part2 == false)
46
return false;
47
else
48
return $part1 . $insertstring . $part2;
49
-
50
}
51
52
@@ -59,56 +137,81 @@ class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
59
* @return array
60
*/
61
public function str_to_array($str, $delimiter=',') {
62
-
63
if (!is_string($str) || $str==='')
64
- return array();
65
66
if (strpos($str, $delimiter)===0)
67
$str = substr($str, 1);
68
69
- return explode($delimiter, $str);
70
-
71
}
72
-
73
/**
74
* Function retrieves unique_array from array or string,
75
* where are values delimiteted by delimiter.
76
- *
77
* @param string|array $data
78
* @param string $delimiter
79
*/
80
public function make_unique_array($data, $delimiter=',') {
81
-
82
if (is_array($data))
83
return array_unique($data);
84
else if (is_string($data))
85
return array_unique(self::str_to_array($data, $delimiter));
86
else
87
return array();
88
-
89
}
90
-
91
-
92
- /**
93
* Function deletes directory recursive.
94
*
95
* @param $dir directory to delete
96
* @param $pattern
97
- */
98
function unlink_recursive($dir, $match='/.*\.html#x2F;', $includeDirs=false) {
99
100
- if (is_file($dir) && preg_match($match, $dir))
101
return @unlink($dir);
102
-
103
$result = true;
104
-
105
if (file_exists($dir)):
106
$dirPtr = @opendir($dir);
107
if ($dirPtr):
108
-
109
while ($file = @readdir($dirPtr)):
110
if ($file == '.' || $file == '..') continue;
111
-
112
if (is_dir($dir.'/'.$file)):
113
$result = $result & $this->unlink_recursive($dir.'/'.$file, $match, $includeDirs);
114
else:
@@ -117,16 +220,16 @@ class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
117
endif;
118
endif;
119
endwhile;
120
-
121
endif;
122
endif;
123
if ($includeDirs) return ($result & @rmdir($dir));
124
}
125
126
-
127
/**
128
* Create directories structure, when it necessary.
129
- *
130
* @param $dir directories from the root
131
* @param $root root, this directory will be not created
132
* @return bool TRUE when success, otherwise FALSE
@@ -137,10 +240,10 @@ class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
137
return false;
138
139
return true;
140
-
141
}
142
-
143
-
144
/**
145
* Function check file on existable, readable and writable.
146
* @param string $file path to file
@@ -152,7 +255,7 @@ class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
152
public function get_file_state($file, &$description, $mod='erw') {
153
154
$mod = strtolower($mod);
155
-
156
/* check existable */
157
if (strpos($mod, 'e')!==false) {
158
if (!file_exists($file)) {
@@ -160,7 +263,7 @@ class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
160
return false;
161
}
162
}
163
-
164
/* check readable */
165
if (strpos($mod, 'r')!==false) {
166
if (!is_readable($file)) {
@@ -168,7 +271,7 @@ class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
168
return false;
169
}
170
}
171
-
172
/* check writeable */
173
if (strpos($mod, 'w')!==false) {
174
if (!is_writeable($file)) {
@@ -176,13 +279,13 @@ class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
176
return false;
177
}
178
}
179
-
180
$description = 'Ready';
181
return true;
182
-
183
}
184
185
-
186
/**
187
* Function formats size of file.
188
* @param int $size size of file in bytes
@@ -193,53 +296,24 @@ class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
193
* @return string formatted size
194
*/
195
function format_file_size($size, $precision=2, $unit=true, $triple=',', $decimal='.') {
196
-
197
- $sizeText = '';
198
-
199
- // division value by size
200
- if (!$size) {
201
- $sizeText = '0'. ($unit ? '&nbsp;B' : '');
202
- } else {
203
-
204
- if ($size < 1024)
205
- $sizeText = $size . ($unit ? '&nbsp;B' : '');
206
- else if ($size < 1048576)
207
- $sizeText = round($size/(float)1024, $precision) . ($unit ? '&nbsp;kB' : '');
208
- else if ($size < 1073741824)
209
- $sizeText = round($size/(float)1048576, $precision) . ($unit ? '&nbsp;MB' : '');
210
- else
211
- $sizeText = round($size/(float)1073741824, $precision) . ($unit ? '&nbsp;GB' : '');
212
- }
213
-
214
- // for this settings don't process more
215
- if ($triple='' && $decimal='.')
216
- return (string)$sizeText;
217
-
218
- // processing decimal and tripple delimiters
219
- $res = '';
220
- $len = strlen((string)$sizeText);
221
- $trip = 0;
222
- $dec = false;
223
- for ($i=$len-1; $i>=0; $i--) {
224
- if (!$dec && $sizeText[$i]!='.') {
225
- $res = $sizeText[$i].$res;
226
- } else if (!$dec && $sizeText[$i]=='.') {
227
- $dec = true;
228
- $res = $decimal.$res;
229
- } else {
230
- $res = $sizeText[$i].$res;
231
- $trip++;
232
- if ($trip==3 && $i>0) {
233
- $res = $triple.$res;
234
- $trip = 0;
235
- }
236
- }
237
- }
238
-
239
- // return result
240
- return $res;
241
-
242
}
243
-
244
245
}
29
class Artio_MTurbo_Helper_Functions extends Mage_Core_Helper_Abstract
30
{
31
32
+ /**
33
+ * Method open the $directory and list all files which match the
34
+ * filter. If filter is empty method returns all files.
35
+ *
36
+ * Method retrieves relative path to $directory.
37
+ *
38
+ * Filter must be a regexp (Ex.: '/\.xml#x2F;', '/^mydocs_.*\.txt#x2F;' ... )
39
+ *
40
+ * You can specified $type of returned files. 'f' means only files.
41
+ * 'd' means only directories and 'a' means both. Other values will
42
+ * be transformed to 'a'.
43
+ *
44
+ * If $excludeDefault is set to true then default directories '.' and
45
+ * '..' will not be added to return array.
46
+ *
47
+ * If $directory is not specified
48
+ * or is not readable then method logs error and return false.
49
+ *
50
+ * @param string $directory
51
+ * @param string $type
52
+ * @param string $filter
53
+ * @param bool $recursively
54
+ * @param bool $excludeDefault
55
+ * @return array|bool
56
+ */
57
+ public function list_dir($directory, $type = 'a', $filter = '', $recursively = false, $excludeDefault = true)
58
+ {
59
+ if (!$directory || !is_dir($directory))
60
+ {
61
+ Mage::log(__METHOD__.": '$directory' is not a directory.");
62
+ return false;
63
+ }
64
+
65
+ if (!$type || !in_array($type, array('f', 'd', 'a')))
66
+ $type = 'a';
67
+
68
+
69
+ $handle = @opendir($directory);
70
+
71
+ if (!$handle)
72
+ {
73
+ Mage::log(__METHOD__.": opening '$directory' fails.");
74
+ return false;
75
+ }
76
+
77
+ $files = array();
78
+
79
+ while ($name = @readdir($handle))
80
+ {
81
+ if ($excludeDefault && ($name == '.' || $name == '..'))
82
+ continue;
83
+
84
+ $path = $directory.DS.$name;
85
+
86
+ if ($recursively && is_dir($path))
87
+ {
88
+ $subfiles = $this->list_dir($path, $type, $filter, $recursively, $excludeDefault);
89
+
90
+ foreach ($subfiles as $subfile)
91
+ $files[] = $name.DS.$subfile;
92
+ }
93
+
94
+ if ($type == 'f' && !is_file($path))
95
+ continue;
96
+ if ($type == 'd' && !is_dir($path))
97
+ continue;
98
+ if ($filter && !preg_match($filter, $name))
99
+ continue;
100
+
101
+ $files[] = $name;
102
+ }
103
+
104
+ @closedir($handle);
105
+
106
+ return $files;
107
+ }
108
+
109
+
110
/**
111
* Function inserts string into another string to the chosen place.
112
*
120
$part1 = substr($intostring, 0, $offset);
121
$part2 = substr($intostring, $offset);
122
123
+ if ($part1 == false || $part2 == false)
124
return false;
125
else
126
return $part1 . $insertstring . $part2;
127
+
128
}
129
130
137
* @return array
138
*/
139
public function str_to_array($str, $delimiter=',') {
140
+
141
if (!is_string($str) || $str==='')
142
+ return array();
143
144
if (strpos($str, $delimiter)===0)
145
$str = substr($str, 1);
146
147
+ return explode($delimiter, $str);
148
+
149
}
150
+
151
/**
152
* Function retrieves unique_array from array or string,
153
* where are values delimiteted by delimiter.
154
+ *
155
* @param string|array $data
156
* @param string $delimiter
157
*/
158
public function make_unique_array($data, $delimiter=',') {
159
+
160
if (is_array($data))
161
return array_unique($data);
162
else if (is_string($data))
163
return array_unique(self::str_to_array($data, $delimiter));
164
else
165
return array();
166
+
167
}
168
+
169
+
170
+ /**
171
+ * Copy array $array without value $value.
172
+ *
173
+ * $value is tested by '==='. If $arrray does not
174
+ * contain $value method returns copy of $array.
175
+ *
176
+ * @param array $array
177
+ * @param mixed $value
178
+ * @return array
179
+ */
180
+ public function array_remove($array, $value)
181
+ {
182
+ if (!is_array($array))
183
+ return $array;
184
+
185
+ $result = array();
186
+
187
+ foreach ($array as $k => $v)
188
+ if ($v !== $value)
189
+ $result[$k] = $v;
190
+
191
+ return $result;
192
+ }
193
+
194
+
195
+ /**
196
* Function deletes directory recursive.
197
*
198
* @param $dir directory to delete
199
* @param $pattern
200
+ */
201
function unlink_recursive($dir, $match='/.*\.html#x2F;', $includeDirs=false) {
202
203
+ if (is_file($dir) && preg_match($match, $dir))
204
return @unlink($dir);
205
+
206
$result = true;
207
+
208
if (file_exists($dir)):
209
$dirPtr = @opendir($dir);
210
if ($dirPtr):
211
+
212
while ($file = @readdir($dirPtr)):
213
if ($file == '.' || $file == '..') continue;
214
+
215
if (is_dir($dir.'/'.$file)):
216
$result = $result & $this->unlink_recursive($dir.'/'.$file, $match, $includeDirs);
217
else:
220
endif;
221
endif;
222
endwhile;
223
+
224
endif;
225
endif;
226
if ($includeDirs) return ($result & @rmdir($dir));
227
}
228
229
+
230
/**
231
* Create directories structure, when it necessary.
232
+ *
233
* @param $dir directories from the root
234
* @param $root root, this directory will be not created
235
* @return bool TRUE when success, otherwise FALSE
240
return false;
241
242
return true;
243
+
244
}
245
+
246
+
247
/**
248
* Function check file on existable, readable and writable.
249
* @param string $file path to file
255
public function get_file_state($file, &$description, $mod='erw') {
256
257
$mod = strtolower($mod);
258
+
259
/* check existable */
260
if (strpos($mod, 'e')!==false) {
261
if (!file_exists($file)) {
263
return false;
264
}
265
}
266
+
267
/* check readable */
268
if (strpos($mod, 'r')!==false) {
269
if (!is_readable($file)) {
271
return false;
272
}
273
}
274
+
275
/* check writeable */
276
if (strpos($mod, 'w')!==false) {
277
if (!is_writeable($file)) {
279
return false;
280
}
281
}
282
+
283
$description = 'Ready';
284
return true;
285
+
286
}
287
288
+
289
/**
290
* Function formats size of file.
291
* @param int $size size of file in bytes
296
* @return string formatted size
297
*/
298
function format_file_size($size, $precision=2, $unit=true, $triple=',', $decimal='.') {
299
+
300
+ $size = (int) $size;
301
+
302
+ $kilo = 1024;
303
+ $mega = 1024*1024;
304
+ $giga = 1024*1024*1024;
305
+
306
+ if ($size < $kilo)
307
+ $x = array(1, 'B');
308
+ else if ($size < $mega)
309
+ $x = array($kilo, 'KiB');
310
+ else if ($size < $giga)
311
+ $x = array($mega, 'MiB');
312
+ else
313
+ $x = array($giga, 'GiB');
314
+
315
+ return number_format($size/(float)$x[0], $precision, $decimal, $triple) . ($unit ? '&nbsp;'.$x[1] : '');
316
}
317
+
318
319
}
app/code/local/Artio/MTurbo/Helper/Info.php CHANGED
@@ -83,7 +83,7 @@ class Artio_MTurbo_Helper_Info extends Mage_Core_Helper_Abstract {
83
84
85
} else {
86
- $this->raiseNotice(100, $this->__('ERROR_REG_CHECK_FAIL'), $false);
87
}
88
89
83
84
85
} else {
86
+ $this->raiseNotice(100, $this->__('Check download id failed.<br />Contact <a href="mailto:support@artio.net">support@artio.net</a>.'), $false);
87
}
88
89
app/code/local/Artio/MTurbo/Model/Config.php CHANGED
@@ -108,6 +108,70 @@ class Artio_MTurbo_Model_Config extends Varien_Object
108
private $pathids = array();
109
110
111
/**
112
* Retrieves website configuration.
113
* @param string $websiteCode code of website
@@ -357,8 +421,9 @@ class Artio_MTurbo_Model_Config extends Varien_Object
357
358
}
359
360
- return $this;
361
362
}
363
364
108
private $pathids = array();
109
110
111
+ /**
112
+ * Method determines whether there is need to do synchronization.
113
+ *
114
+ * Usage:
115
+ * <pre>
116
+ * $config = Mage::getSingleton('mturbo/config');
117
+ * $config->load();
118
+ * $config->addData($someData);
119
+ * $config->save();
120
+ * $config->isNeedToSynchronize()
121
+ * </pre>
122
+ *
123
+ * @return bool
124
+ */
125
+ public function isNeedToSynchronize()
126
+ {
127
+ return $this->dataHasChangedFor('preview_categories')
128
+ || $this->dataHasChangedFor('product_categories')
129
+ || $this->dataHasChangedFor('cms_pages');
130
+ }
131
+
132
+
133
+ /**
134
+ * Method determines whether there is need to refresh a page.
135
+ *
136
+ * Usage:
137
+ * <pre>
138
+ * $config = Mage::getSingleton('mturbo/config');
139
+ * $config->load();
140
+ * $config->addData($someData);
141
+ * $config->save();
142
+ * $config->isNeedToRefresh()
143
+ * </pre>
144
+ *
145
+ * @return bool
146
+ */
147
+ public function isNeedToRefresh()
148
+ {
149
+ return $this->dataHasChangedFor('dynamic_blocks')
150
+ || $this->dataHasChangedFor('dynamic_checkout_cart_link');
151
+ }
152
+
153
+
154
+ /**
155
+ * Method determines whether there is need to refresh cache.
156
+ *
157
+ * Usage:
158
+ * <pre>
159
+ * $config = Mage::getSingleton('mturbo/config');
160
+ * $config->load();
161
+ * $config->addData($someData);
162
+ * $config->save();
163
+ * $config->isNeedToRefresh()
164
+ * </pre>
165
+ *
166
+ * @return bool
167
+ */
168
+ public function isNeedToRefreshCache()
169
+ {
170
+ return $this->dataHasChangedFor('automatic_download')
171
+ || $this->dataHasChangedFor('automatic_download_time');
172
+ }
173
+
174
+
175
/**
176
* Retrieves website configuration.
177
* @param string $websiteCode code of website
421
422
}
423
424
+ $config->setOrigData();
425
426
+ return $this;
427
}
428
429
app/code/local/Artio/MTurbo/Model/Config/DynamicTransformer.php CHANGED
@@ -24,176 +24,201 @@
24
* @category Artio
25
* @package Artio_MTurbo
26
* @author Artio Magento Team (jiri.chmiel@artio.cz)
27
*/
28
class Artio_MTurbo_Model_Config_DynamicTransformer extends Varien_Object
29
{
30
31
- // associative array 'name' => 'type'
32
- private $defaultBlocks = array(
33
34
- 'comparesidebar' => 'catalog/product_compare_sidebar',
35
- 'cartsidebar' => 'checkout/cart_sidebar',
36
- 'pollsidebar' => 'poll/activePoll',
37
38
- );
39
40
- private $classBlocks13 = array (
41
42
- 'comparesidebar' => 'Mage_Reports_Block_Product_Compared',
43
- 'cartsidebar' => 'Mage_Checkout_Block_Cart_Sidebar',
44
- 'pollsidebar' => 'Mage_Poll_Block_ActivePoll',
45
46
- );
47
-
48
- private $classBlocks14 = array (
49
-
50
- 'comparesidebar' => 'Mage_Catalog_Block_Product_Compare_Sidebar',
51
- 'cartsidebar' => 'Mage_Checkout_Block_Cart_Sidebar',
52
- 'pollsidebar' => 'Mage_Poll_Block_ActivePoll',
53
-
54
- );
55
56
- private $keysDefaultBlocks = null;
57
- private $classBlocks = null;
58
-
59
60
/**
61
- * Method dermines whether block is default.
62
- * If block is user defined then method returns false.
63
*
64
- * @param string $identifier
65
- * @return bool
66
*/
67
- public function isDefaultBlock($identifier) {
68
-
69
- if (!isset($this->keysDefaultBlocks))
70
- $this->keysDefaultBlocks = array_keys($this->defaultBlocks);
71
-
72
- return in_array($identifier, $this->keysDefaultBlocks);
73
74
}
75
76
77
/**
78
- * Method retrieves type block by identifier.
79
- * Returns false, when identifier is unknowed.
80
- * @param string $identifier
81
- * @return bool
82
*/
83
- public function getType($identifier) {
84
-
85
- if (isset($this->defaultBlocks[$identifier]))
86
- return $this->defaultBlocks[$identifier];
87
- else
88
return false;
89
90
- }
91
-
92
- private function _getClassBlocks() {
93
-
94
- if (!isset($this->classBlocks)) {
95
-
96
- $this->classBlocks = $this->classBlocks14;
97
- try {
98
-
99
- $version = explode(".", Mage::getVersion());
100
- $this->classBlocks = (isset($version[1]) && ($version[1]=='3')) ? $this->classBlocks13 : $this->classBlocks14;
101
102
- } catch (Exception $e) { }
103
-
104
- }
105
-
106
- return $this->classBlocks;
107
108
}
109
-
110
111
/**
112
* Get the dynamic name of $block. If $block is configured
113
- * as dynamic (by type or by layout name) then method returns
114
- * block's name in layout else method returns false.
115
*
116
- * If $block is not specified method returns false;
117
*
118
* @param Mage_Core_Block_Abstract $block
119
- * @return bool
120
*/
121
- public function getDynamicName($block) {
122
123
if (!$block)
124
- return false;
125
126
- $blockTypes = $this->_getClassBlocks();
127
$configBlocks = Mage::getSingleton('mturbo/config')->getDynamicBlocksAsArray();
128
129
- $candidate = false;
130
-
131
foreach ($configBlocks as $configBlock)
132
{
133
- $configBlockWithoutLayout = preg_replace('/^[^\$]*\#x2F;', '', $configBlock);
134
-
135
- if ($configBlockWithoutLayout == $block->getNameInLayout())
136
- return $configBlock;
137
138
- if (@is_a($block, $blockTypes[$configBlockWithoutLayout]))
139
- $candidate = $block->getNameInLayout();
140
}
141
142
- return $candidate;
143
}
144
145
146
/**
147
* Method transform form data to config and fill it.
148
* @param Artio_MTurbo_Model_Config $config
149
* @param array $formData data from form
150
*/
151
- public function extractData($config, $formData=array()) {
152
153
- $blocks = array();
154
155
- /* foreach data */
156
- foreach ($formData as $key=>$value) {
157
- if ($this->isDefaultBlock($key))
158
- if ($value=='1')
159
- $blocks[] = $key;
160
- }
161
162
- if (isset($formData['userblocks']))
163
- $blocks = array_merge($blocks, explode(",", $formData['userblocks']));
164
165
- $config->setDynamicBlocks(implode(",", array_unique($blocks)));
166
167
- if (isset($formData['cartlink']))
168
$config->setDynamicCheckoutCartLink($formData['cartlink']);
169
}
170
171
172
/**
173
* Method transform data for administration form and retrieves as array.
174
* @param Artio_MTurbo_Model_Config $config
175
* @return array transformed data
176
*/
177
- public function configToForm($config) {
178
179
- /* result is empty */
180
- $result = array();
181
182
- $dynamicBlocks = $config->getDynamicBlocksAsArray();
183
- foreach ($dynamicBlocks as $dynamic) {
184
- if ($this->isDefaultBlock($dynamic)) {
185
- $result[$dynamic] = '1';
186
- }
187
}
188
189
- $diff = array_diff($dynamicBlocks, $this->keysDefaultBlocks);
190
- $string = implode(",", $diff);
191
- $result['userblocks'] = $string;
192
- $result['cartlink'] = $config->getDynamicCheckoutCartLink();
193
-
194
- /* return result */
195
- return $result;
196
-
197
}
198
199
}
24
* @category Artio
25
* @package Artio_MTurbo
26
* @author Artio Magento Team (jiri.chmiel@artio.cz)
27
+ * @TODO: radeji udelat jako helper
28
*/
29
class Artio_MTurbo_Model_Config_DynamicTransformer extends Varien_Object
30
{
31
32
+ /**
33
+ * Internal identifier of AJAX dynamic blocks.
34
+ *
35
+ * @var string
36
+ */
37
+ const AJAX = 'ajax';
38
39
+ /**
40
+ * Internal identifiers of ESI dynamic blocks.
41
+ *
42
+ * @var string
43
+ */
44
+ const ESI = 'esi';
45
46
47
+ /**
48
+ * Internal identifiers of disabled dynamic blocks.
49
+ *
50
+ * @var string
51
+ */
52
+ const DISABLED = 'disabled';
53
54
55
+ /**
56
+ * Method determines whether block is dynamic or not.
57
+ * If $block is dynamic method returns true otherwise returns false.
58
+ *
59
+ * If $block is null method returns false.
60
+ *
61
+ * @param Mage_Core_Block_Abstract $block
62
+ * @return bool
63
+ */
64
+ public function isBlockDynamic($block)
65
+ {
66
+ return ($block && ($block instanceof Artio_MTurbo_Block_Dynamic));
67
+ }
68
69
70
/**
71
+ * Method determines whether block can be used as dynamic or not.
72
+ * If $block is set as dynamic method returns true
73
+ * else method returns false.
74
*
75
+ * If $block is not specified method returns false.
76
+ *
77
+ * @param Mage_Core_Block_Abstract $block
78
+ * @return bool
79
*/
80
+ public function canBeUsedAsDynamic($block)
81
+ {
82
+ list($handle, $name, $type) = $this->getDynamicInfo($block);
83
84
+ return ($handle && $name && $type && $type != self::DISABLED);
85
}
86
87
88
/**
89
+ * Method replace block in the layout. The origin block will
90
+ * be removed and there will be created new dynamic block.
91
+ *
92
+ * @param Mage_Core_Block_Abstract $block
93
+ * @param Mage_Core_Model_Layout $layout
94
+ * @return Artio_MTurbo_Model_Config_DynamicTransformer
95
*/
96
+ public function replaceBlockInLayout($block, $layout)
97
+ {
98
+ if (!$block || !$layout || !$this->canBeUsedAsDynamic($block))
99
return false;
100
101
+ list($handle, $name, $type) = $this->getDynamicInfo($block);
102
103
104
+ if ($type == self::ESI)
105
+ $blockType = 'mturbo/esi';
106
+ else if ($type == self::AJAX)
107
+ $blockType = 'mturbo/ajax';
108
+ else
109
+ return false; // unknow block type
110
+
111
+ $id = $handle.'#x27;.$name;
112
+
113
+ $layout->unsetBlock($name);
114
+ $layout->createBlock($blockType, $name, array('identifier' => $id));
115
+
116
+ return $id;
117
}
118
+
119
120
/**
121
* Get the dynamic name of $block. If $block is configured
122
+ * as dynamic and it is not disabled then method returns
123
+ * dynamic blocks info, which is:
124
+ *
125
+ * array(layout handle, layout name, type)
126
+ *
127
+ * If $block is not dynamic or $block is not specified method
128
+ * returns
129
*
130
+ * array("", "", "")
131
*
132
* @param Mage_Core_Block_Abstract $block
133
+ * @return array
134
*/
135
+ public function getDynamicInfo($block) {
136
137
if (!$block)
138
+ return array("", "", "");
139
140
$configBlocks = Mage::getSingleton('mturbo/config')->getDynamicBlocksAsArray();
141
142
foreach ($configBlocks as $configBlock)
143
{
144
+ $matches = array();
145
146
+ preg_match('/^([^\$#]*)\$([^\$#]*)#([^\$#]*)#x2F;', $configBlock, $matches);
147
+
148
+ $layoutHandle = isset($matches[1]) ? $matches[1] : "";
149
+ $layoutName = isset($matches[2]) ? $matches[2] : "";
150
+ $type = isset($matches[3]) ? $matches[3] : "";
151
+
152
+ if ($layoutName == $block->getNameInLayout())
153
+ return array($layoutHandle, $layoutName, $type);
154
}
155
156
+ return array("", "", "");
157
}
158
159
160
/**
161
* Method transform form data to config and fill it.
162
+ *
163
* @param Artio_MTurbo_Model_Config $config
164
* @param array $formData data from form
165
*/
166
+ public function extractData($config, $formData = array())
167
+ {
168
+ $helper = Mage::helper('mturbo');
169
170
+ $blocks = isset($formData['blocks']) ? $formData['blocks'] : array();
171
172
+ $names = $blocks['name'];
173
+ $types = $blocks['type'];
174
175
+ $blocksToSave = array();
176
177
+ for ($i=0; $i<count($names); $i++)
178
+ {
179
+ $name = $names[$i];
180
+ $type = $types[$i];
181
+
182
+ if (array_key_exists($name, $blocksToSave))
183
+ Mage::throwException($helper->__('You cannot choose two blocks with the same type.'));
184
+
185
+ $blocksToSave[$name] = $name.'#'.$type;
186
+ }
187
+
188
+ $config->setDynamicBlocks(implode(",", $blocksToSave));
189
190
+ if (isset($formData['cartlink']))
191
$config->setDynamicCheckoutCartLink($formData['cartlink']);
192
}
193
194
195
/**
196
* Method transform data for administration form and retrieves as array.
197
+ *
198
* @param Artio_MTurbo_Model_Config $config
199
* @return array transformed data
200
*/
201
+ public function configToForm($config)
202
+ {
203
+ $userblocks = $config->getDynamicBlocks();
204
+ $userblocks = explode(',', $userblocks);
205
206
+ $blocks = array();
207
208
+ foreach ($userblocks as $block)
209
+ {
210
+ $parts = explode('#', $block);
211
+
212
+ $name = $parts[0];
213
+ $type = isset($parts[1]) ? $parts[1] : '';
214
+
215
+ $blocks[] = array('name' => $name, 'type' => $type);
216
}
217
218
+ return array(
219
+ 'userblocks' => $blocks,
220
+ 'cartlink' => $config->getDynamicCheckoutCartLink()
221
+ );
222
}
223
224
}
app/code/local/Artio/MTurbo/Model/DownloadMethods/Curlmulti.php CHANGED
@@ -106,6 +106,8 @@ class Artio_MTurbo_Model_DownloadMethods_Curlmulti extends Artio_MTurbo_Model_Do
106
$options = array(
107
CURLOPT_HEADER => 0,
108
CURLOPT_RETURNTRANSFER => 1,
109
);
110
111
$handles = array();
106
$options = array(
107
CURLOPT_HEADER => 0,
108
CURLOPT_RETURNTRANSFER => 1,
109
+ CURLOPT_TIMEOUT => 100,
110
+ CURLOPT_FOLLOWLOCATION => 1
111
);
112
113
$handles = array();
app/code/local/Artio/MTurbo/Model/DownloadQueue.php CHANGED
@@ -258,7 +258,7 @@ class Artio_MTurbo_Model_DownloadQueue
258
protected function _checkHtml($html, $url, $minsize, $storeId) {
259
260
if (!is_string($html))
261
- return Mage::helper('mturbo')->__('Page is not a string file | url: <b>%s</b>', $url);
262
263
if (strlen($html) < $minsize)
264
return Mage::helper('mturbo')->__('Page is too small | url: <b>%s</b>', $url);
@@ -266,7 +266,7 @@ class Artio_MTurbo_Model_DownloadQueue
266
$title = (string) Mage::helper('mturbo')->getNoRouteTitle($storeId);
267
268
if (strlen($title)>1 && strpos($html, "<title>$title") !== false)
269
- return Mage::helper('mturbo')->__('HTTP 404 | url: <b>%s</b>', $url);
270
271
// empty string means correct
272
return "";
258
protected function _checkHtml($html, $url, $minsize, $storeId) {
259
260
if (!is_string($html))
261
+ return Mage::helper('mturbo')->__('Bad page | url: <b>%s</b>', $url);
262
263
if (strlen($html) < $minsize)
264
return Mage::helper('mturbo')->__('Page is too small | url: <b>%s</b>', $url);
266
$title = (string) Mage::helper('mturbo')->getNoRouteTitle($storeId);
267
268
if (strlen($title)>1 && strpos($html, "<title>$title") !== false)
269
+ return Mage::helper('mturbo')->__('Bad page | url: <b>%s</b>', $url);
270
271
// empty string means correct
272
return "";
app/code/local/Artio/MTurbo/Model/Htaccess.php CHANGED
@@ -106,6 +106,15 @@ class Artio_MTurbo_Model_Htaccess
106
}
107
108
109
/**
110
* Retrieves full path to template of sides htaccess file.
111
* @return string full path to template of sides htaccess file
@@ -454,9 +463,16 @@ class Artio_MTurbo_Model_Htaccess
454
455
/* make back only if is enabled in configuration */
456
if ($config->getEnabledHtaccessBackup()) {
457
458
$backupNum = $config->getNumberOfHtaccessBackups();
459
- $backupPath = $this->websiteconfig->getBaseDir().DS.'.htaccess.bak';
460
461
/* search free backup slot */
462
for ($i=0; $i<$backupNum; $i++)
106
}
107
108
109
+ /**
110
+ * Get directory with htaccess backups.
111
+ * @return string
112
+ */
113
+ public function getHtaccessBackupsDirectory() {
114
+ return $this->websiteconfig->getBaseDir().DS.'var'.DS.'htaccess_backups';
115
+ }
116
+
117
+
118
/**
119
* Retrieves full path to template of sides htaccess file.
120
* @return string full path to template of sides htaccess file
463
464
/* make back only if is enabled in configuration */
465
if ($config->getEnabledHtaccessBackup()) {
466
+
467
+ $backupDir = $this->getHtaccessBackupsDirectory();
468
+
469
+ if (!is_dir($backupDir) && !mkdir($backupDir, 0755, $recursive = true)) {
470
+ Mage::log("M-Turbo: M-Turbo can not create .htaccess backup directory.", Zend_Log::NOTICE);
471
+ return;
472
+ }
473
474
$backupNum = $config->getNumberOfHtaccessBackups();
475
+ $backupPath = $backupDir.DS.'htaccess.bak';
476
477
/* search free backup slot */
478
for ($i=0; $i<$backupNum; $i++)
app/code/local/Artio/MTurbo/Model/JsPatch.php DELETED
@@ -1,129 +0,0 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/osl-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
- *
16
- * @category Artio
17
- * @package Artio_MTurbo
18
- * @copyright Copyright (c) 2010 Artio (http://www.artio.net)
19
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
- */
21
-
22
- /**
23
- * This model maintains javasript file for dynamic loaded blocks.
24
- * It watches adding new theme packages. If any theme package is added then copy
25
- * javascript. It alos retrieves information about this copying.
26
- *
27
- * @category Artio
28
- * @package Artio_MTurbo
29
- * @author Artio Magento Team (jiri.chmiel@artio.cz)
30
- */
31
- class Artio_MTurbo_Model_JsPatch {
32
-
33
- /**
34
- * Path to js file.
35
- * @var string
36
- */
37
- private $_jsPath = '';
38
-
39
- /**
40
- * Path to default js file
41
- * @var string
42
- */
43
- private $_defaultJsPath = '';
44
-
45
- /**
46
- * Method determines whether js does exists in theme package.
47
- * @return bool
48
- */
49
- public function existsJs() {
50
- return file_exists($this->_jsPath);
51
- }
52
-
53
- /**
54
- * Method make js by copying from default theme.
55
- * @return bool TRUE when success, FALSE when fail
56
- */
57
- public function makeJs() {
58
-
59
- if ($this->existsJs())
60
- return true;
61
-
62
- $dirname = dirname($this->_jsPath);
63
-
64
- if (!is_dir($dirname) && !mkdir($dirname, 0777, true))
65
- return false;
66
- else
67
- return copy($this->_defaultJsPath, $this->_jsPath);
68
-
69
- }
70
-
71
-
72
- /**
73
- * Method retrieves absolute path to default js path.
74
- * @return string
75
- */
76
- public function getDefaultJsPath() {
77
- return $this->_defaultJsPath;
78
- }
79
-
80
-
81
- /**
82
- * Method retrieves absolute path to js in this theme.
83
- * @return string
84
- */
85
- public function getJsPath() {
86
- return $this->_jsPath;
87
- }
88
-
89
-
90
- /*
91
- * STATIC METHODS
92
- */
93
-
94
- /**
95
- * Method searches available theme package and retrieves them as array.
96
- * @return array
97
- */
98
- public static function getAvailableThemePackages() {
99
-
100
- $res = array();
101
- $dir = Mage::getBaseDir().DS.'skin'.DS.'frontend';
102
-
103
- if ($handle = opendir($dir)) {
104
- while (false !== ($file = readdir($handle))) {
105
-
106
- if (!in_array($file, array('.','..'))) {
107
-
108
- $base = $dir.DS.$file;
109
- if (is_dir($base)) {
110
-
111
- $js = Mage::getModel('mturbo/jsPatch');
112
- $js->_defaultJsPath = $dir.DS.'default'.DS.'default'.DS.'js'.DS.'mturbo.js';
113
- $js->_jsPath = $base.DS.'default'.DS.'js'.DS.'mturbo.js';
114
-
115
- $res[] = $js;
116
-
117
- }
118
- }
119
-
120
- }
121
- closedir($handle);
122
- }
123
-
124
- return $res;
125
-
126
- }
127
-
128
-
129
- }
app/code/local/Artio/MTurbo/Model/Layout.php ADDED
@@ -0,0 +1,317 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-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
+ *
16
+ * @category Artio
17
+ * @package Artio_MTurbo
18
+ * @copyright Copyright (c) 2013 Artio (http://www.artio.net)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+
22
+ /**
23
+ * The model
24
+ *
25
+ *
26
+ * @category Artio
27
+ * @package Artio_MTurbo
28
+ * @author Artio Magento Team (jiri.chmiel@artio.cz)
29
+ */
30
+ class Artio_MTurbo_Model_Layout
31
+ {
32
+
33
+ /**
34
+ * Package theme.
35
+ *
36
+ * @var string
37
+ */
38
+ protected $_package = null;
39
+
40
+
41
+ /**
42
+ * Skin theme.
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_skin = null;
47
+
48
+
49
+ /**
50
+ * List of used files.
51
+ *
52
+ * @var array
53
+ */
54
+ protected $_files = null;
55
+
56
+
57
+ /**
58
+ * Set used design.
59
+ *
60
+ * Argument $design must be something like
61
+ * 'base/default', 'default/myskin1' etc.
62
+ *
63
+ * If $design is not specified or is bad method
64
+ * does nothing.
65
+ *
66
+ * @param string $design
67
+ * @return Artio_MTurbo_Model_Layout
68
+ */
69
+ public function setDesign($design)
70
+ {
71
+ $parts = explode('/', $design);
72
+
73
+ // invalid $designTheme
74
+ if (count($parts) != 2)
75
+ return $this;
76
+
77
+ $package = $parts[0];
78
+ $skin = $parts[1];
79
+
80
+ // invalid $designTheme
81
+ if (!$package || !$skin)
82
+ return $this;
83
+
84
+ $this->_package = $package;
85
+ $this->_skin = $skin;
86
+
87
+ $this->_loadLayoutFiles();
88
+
89
+ return $this;
90
+ }
91
+
92
+
93
+ /**
94
+ * Get all blocks of a $filterHandle.
95
+ *
96
+ * The result has follow formats
97
+ * array(
98
+ * 0 => array('type' => type of block, 'name' => name in layout, 'as' => alias if anoy, 'template' => template if any ... and next attributes if any)
99
+ * ...
100
+ * )
101
+ *
102
+ * If xml files is not loaded or $filterHandle is not specified
103
+ * method returns empty array.
104
+ *
105
+ * Note method always all blocks. Filtering by $filterHandle is done ex post.
106
+ *
107
+ * @param string $handle
108
+ * @return array
109
+ */
110
+ public function getBlocks($filterHandle = null)
111
+ {
112
+ if (!$this->_files)
113
+ return array();
114
+
115
+ $blocks = array();
116
+
117
+ foreach ($this->_files as $file)
118
+ {
119
+ $xml = @simplexml_load_file($file);
120
+
121
+ if ($xml === false)
122
+ continue;
123
+
124
+ $nodes = $xml->xpath("//block");
125
+
126
+ if ($nodes) foreach ($nodes as $node)
127
+ {
128
+ $handle = $this->_getHandle($node);
129
+
130
+ if (!$filterHandle || $handle == $filterHandle)
131
+ {
132
+ $info = array('handle' => $handle);
133
+
134
+ foreach ($node->attributes() as $n => $v)
135
+ {
136
+ $info[$n] = $v->__toString();
137
+ }
138
+
139
+ $blocks[] = $info;
140
+ }
141
+ }
142
+ }
143
+
144
+ return $blocks;
145
+ }
146
+
147
+
148
+ /**
149
+ * Get handle name of $node.
150
+ *
151
+ * If $node is not specified or layout hadnle not found
152
+ * method return false.
153
+ *
154
+ * @param SimpleXmlElement $node
155
+ * @return string
156
+ */
157
+ protected function _getHandle($node)
158
+ {
159
+ $prev = null;
160
+
161
+ while ($node && $node->getName() != 'layout')
162
+ {
163
+ $prev = $node;
164
+
165
+ $parn = $node->xpath('..');
166
+ $node = isset($parn[0]) ? $parn[0] : false;
167
+ }
168
+
169
+ return $prev ? $prev->getName() : false;
170
+ }
171
+
172
+
173
+ /**
174
+ * Get all of used the layout files.
175
+ *
176
+ * @param string $designTheme
177
+ * @return Artio_MTurbo_Model_Layout
178
+ */
179
+ protected function _loadLayoutFiles()
180
+ {
181
+ if (!$this->_package || !$this->_skin)
182
+ return $this;
183
+
184
+ $package = $this->_package;
185
+ $skin = $this->_skin;
186
+
187
+ $designRoot = $this->getBaseDesignRoot();
188
+ $helper = $this->_funcHelper();
189
+
190
+ $baseDefaultDir = $designRoot.DS.'base'.DS.'default'.DS.'layout';
191
+ $packageDefaultDir = $designRoot.DS.$package.DS.'default'.DS.'layout';
192
+ $packageSkinDir = $designRoot.DS.$package.DS.$skin.DS.'layout';
193
+
194
+ $baseDefault = array();
195
+ $packageDefault = array();
196
+ $packageSkin = array();
197
+
198
+ if (is_dir($baseDefaultDir))
199
+ $baseDefault = $helper->list_dir($baseDefaultDir, 'f', '/\.xml#x2F;', $rec = true);
200
+
201
+ if ($package != 'base' && is_dir($packageDefaultDir))
202
+ $packageDefault = $helper->list_dir($packageDefaultDir, 'f', '/\.xml#x2F;', $rec = true);
203
+
204
+ if ($skin != 'default' && is_dir($packageSkinDir))
205
+ $packageSkin = $helper->list_dir($packageSkinDir, 'f', '/\.xml#x2F;', $rec = true);
206
+
207
+ if ($baseDefault === false || $packageDefault === false || $packageSkin === false)
208
+ return false;
209
+
210
+ $files = array();
211
+
212
+ foreach ($packageSkin as $file)
213
+ $files[] = $baseDefaultDir.DS.$file;
214
+
215
+ foreach ($packageDefault as $file)
216
+ if (!in_array($file, $files))
217
+ $files[] = $packageDefaultDir.DS.$file;
218
+
219
+ foreach ($baseDefault as $file)
220
+ if (!in_array($file, $files))
221
+ $files[] = $packageSkinDir.DS.$file;
222
+
223
+ $this->_files = $files;
224
+
225
+ return $this;
226
+ }
227
+
228
+
229
+ /**
230
+ * Get 'functions' helper.
231
+ *
232
+ * @return Artio_MTurbo_Helper_Functions
233
+ */
234
+ protected function _funcHelper()
235
+ {
236
+ return Mage::helper('mturbo/functions');
237
+ }
238
+
239
+
240
+ /**
241
+ * Method get the list of used the frontend
242
+ * design theme.
243
+ *
244
+ * Ex.:
245
+ *
246
+ * array(
247
+ * 'base/default',
248
+ * 'default/default',
249
+ * 'default/iphone',
250
+ * 'default/myskin1',
251
+ * 'default/myskin2'
252
+ * )
253
+ *
254
+ * @return array
255
+ */
256
+ public function getDesignsAsFlatStrings()
257
+ {
258
+ $designs = $this->getDesigns();
259
+
260
+ $result = array();
261
+
262
+ foreach ($designs as $theme => $skins)
263
+ foreach ($skins as $skin)
264
+ $result[] = $theme.'/'.$skin;
265
+
266
+ return $result;
267
+ }
268
+
269
+
270
+ /**
271
+ * Method get the list of used the frontend
272
+ * design theme.
273
+ *
274
+ * Ex.:
275
+ *
276
+ * array(
277
+ * 'base' => array('default')
278
+ * 'default' => array('default', 'iphone', 'myskin1', 'myskin2')
279
+ * )
280
+ *
281
+ * @return array
282
+ */
283
+ public function getDesigns()
284
+ {
285
+ $designDir = $this->getBaseDesignRoot();
286
+
287
+ $packages = array();
288
+
289
+ $themes = $this->_funcHelper()->list_dir($designDir, 'd');
290
+
291
+ if ($themes === false)
292
+ return false;
293
+
294
+ foreach ($themes as $theme)
295
+ {
296
+ $skins = $this->_funcHelper()->list_dir($designDir.DS.$theme, 'd');
297
+
298
+ if ($skins !== false)
299
+ $packages[$theme] = $skins;
300
+ }
301
+
302
+ return $packages;
303
+ }
304
+
305
+
306
+ /**
307
+ * Get base design root.
308
+ *
309
+ * @return string
310
+ */
311
+ public function getBaseDesignRoot()
312
+ {
313
+ return Mage::getBaseDir('app').DS.'design'.DS.'frontend';
314
+ }
315
+
316
+
317
+ }
app/code/local/Artio/MTurbo/Model/Mturbo.php CHANGED
@@ -271,8 +271,8 @@ class Artio_MTurbo_Model_MTurbo extends Mage_Core_Model_Abstract {
271
/* not-selected short product ulr */
272
$queryDeleteProductsShort = "
273
DELETE FROM `".$prefix."mturbo`
274
- WHERE (`category_id` IS NULL AND `product_id` IN
275
- (SELECT `product_id` FROM `".$prefix."core_url_rewrite` WHERE `category_id` NOT IN (".$products.")));";
276
277
/* url with redirect */
278
$queryDeleteRedirect = "
@@ -314,20 +314,37 @@ class Artio_MTurbo_Model_MTurbo extends Mage_Core_Model_Abstract {
314
315
$catStatId = $categoryEntity->getAttribute('is_active')->getId();
316
317
- /* inactive and not-visible products */
318
- $queryDeleteInactiveProducts = "
319
- DELETE FROM `".$prefix."mturbo`
320
- WHERE `product_id` IN (
321
- SELECT entity_id FROM `".$prefix."catalog_product_entity_int`
322
- WHERE
323
- ((attribute_id=".$statId." AND value = 2) OR
324
- (attribute_id=".$visId." AND value <= 1)));";
325
-
326
- /* inactive categories */
327
- $queryDeleteInactiveCategories = "
328
- DELETE FROM `".$prefix."mturbo` WHERE `category_id` IN (
329
- SELECT entity_id FROM `".$prefix."catalog_category_entity_int`
330
- WHERE (attribute_id=".$catStatId." AND value = 0)); ";
331
332
/* inactive cms */
333
$queryDeleteInactiveCms = "
@@ -368,8 +385,15 @@ class Artio_MTurbo_Model_MTurbo extends Mage_Core_Model_Abstract {
368
$connection->query($queryDeleteCMS);
369
370
// delete inactive and not-visible entities
371
- $connection->query($queryDeleteInactiveProducts);
372
- $connection->query($queryDeleteInactiveCategories);
373
$connection->query($queryDeleteInactiveCms);
374
375
// delete long url when "use category in product's url" is disabled
271
/* not-selected short product ulr */
272
$queryDeleteProductsShort = "
273
DELETE FROM `".$prefix."mturbo`
274
+ WHERE (`category_id` IS NULL AND `product_id` IS NOT NULL AND `product_id` NOT IN
275
+ (SELECT `product_id` FROM `".$prefix."core_url_rewrite` WHERE `category_id` IN (".$products.")));";
276
277
/* url with redirect */
278
$queryDeleteRedirect = "
314
315
$catStatId = $categoryEntity->getAttribute('is_active')->getId();
316
317
+ /* inactive categories/products, not visible products */
318
+ $queryDeleteInactiveProducts = array();
319
+ $queryDeleteNonvisibleProducts = array();
320
+ $queryDeleteInactiveCategories = array();
321
+
322
+ foreach ($activeStoresIdArray as $storeId)
323
+ {
324
+ $queryDeleteInactiveProducts[] = "
325
+ DELETE FROM `".$prefix."mturbo` WHERE `store_id` = $storeId AND `product_id` IN (
326
+ SELECT `e`.`entity_id`
327
+ FROM `".$prefix."catalog_product_entity` e
328
+ LEFT JOIN `".$prefix."catalog_product_entity_int` d ON (`e`.`entity_id` = `d`.`entity_id` AND `d`.`attribute_id` = $statId AND `d`.`store_id` = 0)
329
+ LEFT JOIN `".$prefix."catalog_product_entity_int` s ON (`e`.`entity_id` = `s`.`entity_id` AND `s`.`attribute_id` = $statId AND `s`.`store_id` = $storeId)
330
+ WHERE `s`.`value` = 2 OR (`d`.`value` = 2 AND `s`.`value` IS NULL))";
331
+
332
+ $queryDeleteNonvisibleProducts[] = "
333
+ DELETE FROM `".$prefix."mturbo` WHERE `store_id` = $storeId AND `product_id` IN (
334
+ SELECT `e`.`entity_id`
335
+ FROM `".$prefix."catalog_product_entity` e
336
+ LEFT JOIN `".$prefix."catalog_product_entity_int` d ON (`e`.`entity_id` = `d`.`entity_id` AND `d`.`attribute_id` = $visId AND `d`.`store_id` = 0)
337
+ LEFT JOIN `".$prefix."catalog_product_entity_int` s ON (`e`.`entity_id` = `s`.`entity_id` AND `s`.`attribute_id` = $visId AND `s`.`store_id` = $storeId)
338
+ WHERE `s`.`value` <= 1 OR (`d`.`value` <= 1 AND `s`.`value` IS NULL))";
339
+
340
+ $queryDeleteInactiveCategories[] = "
341
+ DELETE FROM `".$prefix."mturbo` WHERE `store_id` = $storeId AND `category_id` IN (
342
+ SELECT `e`.`entity_id`
343
+ FROM `".$prefix."catalog_category_entity` e
344
+ LEFT JOIN `".$prefix."catalog_category_entity_int` d ON (`e`.`entity_id` = `d`.`entity_id` AND `d`.`attribute_id` = $catStatId AND `d`.`store_id` = 0)
345
+ LEFT JOIN `".$prefix."catalog_category_entity_int` s ON (`e`.`entity_id` = `s`.`entity_id` AND `s`.`attribute_id` = $catStatId AND `s`.`store_id` = $storeId)
346
+ WHERE `s`.`value` = 0 OR (`d`.`value` = 0 AND `s`.`value` IS NULL))";
347
+ }
348
349
/* inactive cms */
350
$queryDeleteInactiveCms = "
385
$connection->query($queryDeleteCMS);
386
387
// delete inactive and not-visible entities
388
+ foreach ($queryDeleteInactiveProducts as $q)
389
+ $connection->query($q);
390
+
391
+ foreach ($queryDeleteNonvisibleProducts as $q)
392
+ $connection->query($q);
393
+
394
+ foreach ($queryDeleteInactiveCategories as $q)
395
+ $connection->query($q);
396
+
397
$connection->query($queryDeleteInactiveCms);
398
399
// delete long url when "use category in product's url" is disabled
app/code/local/Artio/MTurbo/Model/Mturbo/Event.php CHANGED
@@ -61,6 +61,14 @@ class Artio_MTurbo_Model_MTurbo_Event extends Mage_Core_Model_Abstract {
61
protected static $synchronize = false;
62
63
64
/**
65
* Add item into queue.
66
*
@@ -110,17 +118,19 @@ class Artio_MTurbo_Model_MTurbo_Event extends Mage_Core_Model_Abstract {
110
* Flush current queue.
111
*
112
* @see Artio_MTurbo_Model_MTurbo_Event::addItem
113
- * @return Artio_MTurbo_Model_MTurbo_Event
114
*/
115
public function flush() {
116
117
if (self::$synchronize)
118
$this->_getMTurboModel()->synchronize();
119
120
foreach (self::$queue as $action)
121
$this->flushAction($action);
122
123
- return $this;
124
}
125
126
@@ -177,6 +187,8 @@ class Artio_MTurbo_Model_MTurbo_Event extends Mage_Core_Model_Abstract {
177
$downloadQueue->addMTurboModel($item);
178
179
$downloadQueue->flush();
180
}
181
182
return $this;
61
protected static $synchronize = false;
62
63
64
+ /**
65
+ * The results of downloading.
66
+ *
67
+ * @var array (url1 => message1, url2 => message2, ...)
68
+ */
69
+ protected static $result = array();
70
+
71
+
72
/**
73
* Add item into queue.
74
*
118
* Flush current queue.
119
*
120
* @see Artio_MTurbo_Model_MTurbo_Event::addItem
121
+ * @return array
122
*/
123
public function flush() {
124
125
+ self::$result = array();
126
+
127
if (self::$synchronize)
128
$this->_getMTurboModel()->synchronize();
129
130
foreach (self::$queue as $action)
131
$this->flushAction($action);
132
133
+ return self::$result;
134
}
135
136
187
$downloadQueue->addMTurboModel($item);
188
189
$downloadQueue->flush();
190
+
191
+ self::$result = array_merge(self::$result, $downloadQueue->getResult());
192
}
193
194
return $this;
app/code/local/Artio/MTurbo/Model/Mturbo/File.php CHANGED
@@ -196,6 +196,8 @@ class Artio_MTurbo_Model_MTurbo_File extends Mage_Core_Model_Abstract {
196
* Url makes by unsecure base url, store code and request.
197
* Store code is used even when set not to use the store code in the url.
198
*
199
*/
200
201
/* path is empty */
@@ -238,6 +240,8 @@ class Artio_MTurbo_Model_MTurbo_File extends Mage_Core_Model_Abstract {
238
$path = mb_substr($path, 0, mb_strlen($path)-1);
239
}
240
241
/* add extension */
242
$path .= self::EXT;
243
return $path;
196
* Url makes by unsecure base url, store code and request.
197
* Store code is used even when set not to use the store code in the url.
198
*
199
+ * Path is processed by "urldecode" for support non-standard chars.
200
+ *
201
*/
202
203
/* path is empty */
240
$path = mb_substr($path, 0, mb_strlen($path)-1);
241
}
242
243
+ $path = urldecode($path);
244
+
245
/* add extension */
246
$path .= self::EXT;
247
return $path;
app/code/local/Artio/MTurbo/Model/Observer.php CHANGED
@@ -20,7 +20,7 @@
20
21
/**
22
* MTurbo observer.
23
- *
24