MTurbo - Version 1.1.0

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.1.0
Comparing to
See all releases


Code changes from version 1.0 to 1.1.0

app/code/local/Artio/MTurbo/Block/Adminhtml/Edit/Tab/Actions.php CHANGED
@@ -87,6 +87,14 @@ class Artio_MTurbo_Block_Adminhtml_Edit_Tab_Actions extends Artio_MTurbo_Block_A
87
'comment' => $this->getMyHelper()->__('Create cache for all pages (except blocked pages). Download progress can be monitored in a separate window. Please, do not close this window. Update of URLs from the Rewrite Table will be started automatically before caching is executed. Please, note that initial cache creation may take a long time (several hours). Time needed depends on the number of pages your site has.')
88
89
));
90
91
}
92
87
'comment' => $this->getMyHelper()->__('Create cache for all pages (except blocked pages). Download progress can be monitored in a separate window. Please, do not close this window. Update of URLs from the Rewrite Table will be started automatically before caching is executed. Please, note that initial cache creation may take a long time (several hours). Time needed depends on the number of pages your site has.')
88
89
));
90
+
91
+ $layoutFieldset->addField('htaccess_button', 'widget_button', array(
92
+ 'name' => 'htaccess_button',
93
+ 'label' => $this->getMyHelper()->__('Rebuild .htaccess'),
94
+ 'onclick' => "setLocation('" . Mage::helper('adminhtml')->getUrl('*/*/htaccessbuild') . "')",
95
+ 'comment' => $this->getMyHelper()->__('Rebuild .htaccess file. First remove MTurbo section and then insert it. At the same time check .htaccess file in turbocache folder'),
96
+
97
+ ));
98
99
}
100
app/code/local/Artio/MTurbo/Block/Adminhtml/Edit/Tab/Main.php CHANGED
@@ -44,7 +44,8 @@ class Artio_MTurbo_Block_Adminhtml_Edit_Tab_Main extends Artio_MTurbo_Block_Admi
44
$this->form = new Varien_Data_Form();
45
$this->_addGeneralFieldset();
46
$this->_addHomepageFieldset();
47
- //$this->_addAutomaticDownloadFieldset();
48
49
$this->form->setValues($config->getData());
50
$this->setForm($this->form);
@@ -108,7 +109,7 @@ class Artio_MTurbo_Block_Adminhtml_Edit_Tab_Main extends Artio_MTurbo_Block_Admi
108
109
$layoutFieldset->addField('lastdownload', 'label', array(
110
'name' => 'lastdownload',
111
- 'label' => $this->getMyHelper()->__('Last downlaod').':',
112
'style' => 'height:24em;',
113
'disabled' => true
114
));
@@ -135,4 +136,36 @@ class Artio_MTurbo_Block_Adminhtml_Edit_Tab_Main extends Artio_MTurbo_Block_Admi
135
136
}
137
138
}
44
$this->form = new Varien_Data_Form();
45
$this->_addGeneralFieldset();
46
$this->_addHomepageFieldset();
47
+ //$this->_addAutomaticDownloadFieldset(); DEMO VERSION
48
+ $this->_addDownloadMethodFieldset();
49
50
$this->form->setValues($config->getData());
51
$this->setForm($this->form);
109
110
$layoutFieldset->addField('lastdownload', 'label', array(
111
'name' => 'lastdownload',
112
+ 'label' => $this->getMyHelper()->__('Last download').':',
113
'style' => 'height:24em;',
114
'disabled' => true
115
));
136
137
}
138
139
+ private function _addDownloadMethodFieldset() {
140
+
141
+ $layoutFieldset = $this->form->addFieldset('downloadmethod_fieldset', array(
142
+ 'legend' => $this->getMyHelper()->__('Choice download method'),
143
+ 'class' => 'fieldset'
144
+ ));
145
+
146
+ $layoutFieldset->addType('selectdmet', Artio_MTurbo_Helper_Data::FORM_SELECT_DOW);
147
+ $layoutFieldset->addField('downloadmethod', 'selectdmet', array(
148
+ 'name' => 'downloadmethod',
149
+ 'label' => $this->getMyHelper()->__('Download method').':',
150
+ 'options' => array(
151
+ DownloadMethods::FILE_GET_CONTENTS => $this->getMyHelper()->__('Use function "file_get_contents"'),
152
+ DownloadMethods::SOCKET => $this->getMyHelper()->__('Create connection over sockets'),
153
+ DownloadMethods::CURL => $this->getMyHelper()->__('Use CURL PHP extension'),
154
+ DownloadMethods::DIRECT_ACCESS => $this->getMyHelper()->__('Direct access (created new instance Magento)'))
155
+ ));
156
+
157
+ $label = Artio_MTurbo_Helper_Data::getConfig()->isPatched() ?
158
+ Mage::helper('mturbo')->__('Remove Mage Patch') :
159
+ Mage::helper('mturbo')->__('Apply Mage Patch');
160
+
161
+ $layoutFieldset->addType('widget_button', Artio_MTurbo_Helper_Data::FORM_WIDGET_BUTTON);
162
+ $layoutFieldset->addField('patch_button', 'widget_button', array(
163
+ 'name' => 'patch_button',
164
+ 'label' => $label,
165
+ 'onclick' => "setLocation('" . Mage::helper('adminhtml')->getUrl('*/*/magepatch') . "')",
166
+ 'comment' => $this->getMyHelper()->__('Apply the patch only just in case you need to use Direct Access download method!')
167
+ ));
168
+
169
+ }
170
+
171
}
app/code/local/Artio/MTurbo/Block/Adminhtml/Run.php CHANGED
@@ -51,7 +51,7 @@ class Artio_MTurbo_Block_Adminhtml_Run extends Mage_Adminhtml_Block_Abstract
51
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
52
echo '<script type="text/javascript">var FORM_KEY = "'.Mage::getSingleton('core/session')->getFormKey().'";</script>';
53
echo $this->_getCssJsHtml();
54
- echo '<title>'.Mage::helper('mturbo')->__('Turbo Cache Management - Downloading pages').'</title>';
55
echo '</head>';
56
57
echo '<body>';
51
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
52
echo '<script type="text/javascript">var FORM_KEY = "'.Mage::getSingleton('core/session')->getFormKey().'";</script>';
53
echo $this->_getCssJsHtml();
54
+ echo '<title>'.Mage::helper('mturbo')->__('M-Turbo Management - Downloading pages').'</title>';
55
echo '</head>';
56
57
echo '<body>';
app/code/local/Artio/MTurbo/Block/Data/Form/Element/SelectDownloadMethod.php ADDED
@@ -0,0 +1,159 @@
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
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Varien
22
+ * @package Varien_Data
23
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Select element with testing download method
29
+ *
30
+ * @category Artio
31
+ * @package Artio_MTurbo
32
+ * @author Artio Magento Team <info@artio.net>
33
+ */
34
+ class Artio_MTurbo_Block_Data_Form_Element_SelectDownloadMethod extends Varien_Data_Form_Element_Select
35
+ {
36
+
37
+ public function getElementHtml()
38
+ {
39
+ $this->addClass('select');
40
+
41
+ $html = self::getTestJS();
42
+
43
+ $html .= '<select onchange="selectMethod('."'".$this->getHtmlId()."'".')"; id="'.$this->getHtmlId().'" name="'.$this->getName().'" '.$this->serialize($this->getHtmlAttributes()).'>'."\n";
44
+
45
+ $value = $this->getValue();
46
+ if (!is_array($value)) {
47
+ $value = array($value);
48
+ }
49
+
50
+ if ($values = $this->getValues()) {
51
+ foreach ($values as $key => $option) {
52
+ if (!is_array($option)) {
53
+ $html.= $this->_optionToHtml(array(
54
+ 'value' => $key,
55
+ 'label' => $option),
56
+ $value
57
+ );
58
+ }
59
+ elseif (is_array($option['value'])) {
60
+ $html.='<optgroup label="'.$option['label'].'">'."\n";
61
+ foreach ($option['value'] as $groupItem) {
62
+ $html.= $this->_optionToHtml($groupItem, $value);
63
+ }
64
+ $html.='</optgroup>'."\n";
65
+ }
66
+ else {
67
+ $html.= $this->_optionToHtml($option, $value);
68
+ }
69
+ }
70
+ }
71
+
72
+ $html.= '</select>';
73
+
74
+ // result test label
75
+ $html.= '<div style="padding:10px 0px">';
76
+ $html.= '<span><b>'.Mage::helper('mturbo')->__('Download Test').'</b></span><br />';
77
+ $html.= '<span style="padding-left:15px" id="method'.$this->getHtmlId().'"><i>For test choose a method</i></span><br />';
78
+ $html.= '<span style="padding-left:15px" id="testconnect'.$this->getHtmlId().'"></span>';
79
+ $html.= '</div>';
80
+
81
+ $html.= $this->getOnFlyJS();
82
+ $html.= $this->getAfterElementHtml();
83
+ return $html;
84
+ }
85
+
86
+ private function getOnFlyJS()
87
+ {
88
+ $res = '<script type="text/javascript">';
89
+ $res .= ' selectMethod("'.$this->getId().'")';
90
+ $res .= '</script>';
91
+ return $res;
92
+ }
93
+
94
+ static $jsinserted = false;
95
+
96
+ private static function getTestJS()
97
+ {
98
+
99
+ static $jsinserted;
100
+
101
+ if (!$jsinserted)
102
+ {
103
+
104
+ $jsinserted = true;
105
+ $ajaxUrl = Mage::helper('adminhtml')->getUrl('*/*/testdownload');
106
+
107
+ $res = '<script type="text/javascript">var FORM_KEY = "'.Mage::getSingleton('core/session')->getFormKey().'";</script>';
108
+
109
+ $res .= '<script type="text/javascript">'."\n";
110
+
111
+ $res .= "function selectMethod(id) {
112
+
113
+ var el = document.getElementById(id);
114
+
115
+ new Ajax.Request('$ajaxUrl', {
116
+ method: 'post',
117
+ parameters: {form_key: FORM_KEY, method: el.value},
118
+
119
+ onComplete: function(transport) {
120
+
121
+ if (transport.responseText.isJSON()) {
122
+
123
+ var meth = document.getElementById('method'+id);
124
+ var sel = document.getElementById(id);
125
+ meth.innerHTML = sel.options[sel.selectedIndex].text;
126
+
127
+ var el = document.getElementById('testconnect'+id);
128
+ var response = transport.responseText.evalJSON();
129
+ if (!response.ok) {
130
+ el.style.color = 'red';
131
+ el.innerHTML = 'FAIL (' + response.resultTest + ')';
132
+ } else {
133
+ el.style.color = 'green';
134
+ el.innerHTML = 'OK (frontpage size: ' + response.resultTest + ' kB)';
135
+ }
136
+ } else {
137
+ var meth = document.getElementById('method'+id);
138
+ meth.innerHTML = '<i>Test failed</i>';
139
+ var el = document.getElementById('testconnect'+id);
140
+ el.innerHTML = '';
141
+
142
+ }
143
+ }
144
+ });
145
+
146
+ var meth = document.getElementById('method'+id);
147
+ meth.innerHTML = '<i>Testing...</i>';
148
+ var el = document.getElementById('testconnect'+id);
149
+ el.innerHTML = '';
150
+
151
+ }";
152
+
153
+ $res .= '</script>'."\n";
154
+
155
+ }
156
+
157
+ return $res;
158
+ }
159
+ }
app/code/local/Artio/MTurbo/Helper/Checker.php CHANGED
@@ -52,18 +52,21 @@ class Artio_MTurbo_Helper_Checker extends Mage_Core_Helper_Abstract
52
*/
53
public static function checkPermission() {
54
$htaccess = Artio_MTurbo_Helper_Data::getPathToBaseHtaccess();
55
- $permission = fileperms($htaccess);
56
- return self::canWrite($permission);
57
}
58
59
public static function checkPermissionLayout() {
60
- $perm = fileperms(Mage::getBaseDir().DS.self::UPGRADE_XML);
61
- return self::canWrite($perm);
62
}
63
64
public static function checkPermissionCode() {
65
- $perm = fileperms(Mage::getBaseDir().DS.self::UPGRADE_CODE);
66
- return self::canWrite($perm);
67
}
68
69
public static function canWrite($perm) {
52
*/
53
public static function checkPermission() {
54
$htaccess = Artio_MTurbo_Helper_Data::getPathToBaseHtaccess();
55
+ return is_writable($htaccess);
56
+ //$permission = fileperms($htaccess);
57
+ //return self::canWrite($permission);
58
}
59
60
public static function checkPermissionLayout() {
61
+ return is_writable(Mage::getBaseDir().DS.self::UPGRADE_XML);
62
+ //$perm = fileperms(Mage::getBaseDir().DS.self::UPGRADE_XML);
63
+ //return self::canWrite($perm);
64
}
65
66
public static function checkPermissionCode() {
67
+ return is_writable(Mage::getBaseDir().DS.self::UPGRADE_CODE);
68
+ //$perm = fileperms(Mage::getBaseDir().DS.self::UPGRADE_CODE);
69
+ //return self::canWrite($perm);
70
}
71
72
public static function canWrite($perm) {
app/code/local/Artio/MTurbo/Helper/Data.php CHANGED
@@ -38,6 +38,7 @@ class Artio_MTurbo_Helper_Data extends Mage_Core_Helper_Abstract
38
const FORM_WIDGET_BUTTON = 'Artio_MTurbo_Block_Data_Form_Element_Button';
39
const FORM_CRON_HOUR_TIME = 'Artio_MTurbo_Block_Data_Form_Element_Time';
40
const FORM_NO_ESC_LABEL = 'Artio_MTurbo_Block_Data_Form_Element_NoEscLabel';
41
42
const COOKIE_IDENTIFIER = 'artio_mturbo';
43
@@ -137,13 +138,22 @@ class Artio_MTurbo_Helper_Data extends Mage_Core_Helper_Abstract
137
}
138
139
/**
140
- * Retrives path to downloader script
141
* @return string
142
*/
143
public static function getFullDownloadScriptPath() {
144
return Mage::getBaseDir().DS.'app/code/local/Artio/MTurbo/Model/scripts/getstatichtml.sh';
145
}
146
147
/**
148
* Retrieves path to base .htaccess
149
* @return string
@@ -159,5 +169,21 @@ class Artio_MTurbo_Helper_Data extends Mage_Core_Helper_Abstract
159
public static function getFullHtaccessRootPath() {
160
return Mage::getBaseDir().DS.'app/code/local/Artio/MTurbo/Model/htaccess/htaccessroot.txt';
161
}
162
163
}
38
const FORM_WIDGET_BUTTON = 'Artio_MTurbo_Block_Data_Form_Element_Button';
39
const FORM_CRON_HOUR_TIME = 'Artio_MTurbo_Block_Data_Form_Element_Time';
40
const FORM_NO_ESC_LABEL = 'Artio_MTurbo_Block_Data_Form_Element_NoEscLabel';
41
+ const FORM_SELECT_DOW = 'Artio_MTurbo_Block_Data_Form_Element_SelectDownloadMethod';
42
43
const COOKIE_IDENTIFIER = 'artio_mturbo';
44
138
}
139
140
/**
141
+ * Retrivies path to downloader script
142
* @return string
143
*/
144
public static function getFullDownloadScriptPath() {
145
return Mage::getBaseDir().DS.'app/code/local/Artio/MTurbo/Model/scripts/getstatichtml.sh';
146
}
147
148
+ /**
149
+ * Retrivies path to remover script
150
+ *
151
+ * @return string
152
+ */
153
+ public static function getFullRemoveScriptPath() {
154
+ return Mage::getBaseDir().DS.'app/code/local/Artio/MTurbo/Model/scripts/removehtml.sh';
155
+ }
156
+
157
/**
158
* Retrieves path to base .htaccess
159
* @return string
169
public static function getFullHtaccessRootPath() {
170
return Mage::getBaseDir().DS.'app/code/local/Artio/MTurbo/Model/htaccess/htaccessroot.txt';
171
}
172
+
173
+ /**
174
+ * Retrieves path to Mage Patch
175
+ * @return string
176
+ */
177
+ public static function getMagePatchPath() {
178
+ return Mage::getBaseDir().DS.'app/code/local/Artio/MTurbo/Model/patches/mage.txt';
179
+ }
180
+
181
+ /**
182
+ * Retrieves path to file Mage.php
183
+ * @return string
184
+ */
185
+ public static function getMagePath() {
186
+ return Mage::getBaseDir().DS.'app/Mage.php';
187
+ }
188
189
}
app/code/local/Artio/MTurbo/Model/Config.php CHANGED
@@ -23,6 +23,20 @@
23
* @copyright Copyright (c) 2010 Artio (http://www.artio.net)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
27
class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
28
{
@@ -33,6 +47,8 @@ class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
33
const CONFIG_HTACCESS_FINDKEY = 'M-Turbo Accelleration';
34
const CONFIG_HTACCESS_FINDBASE = 'RewriteBase';
35
const CONFIG_HTACCESS_FINDENGINEON = 'RewriteEngine on';
36
37
const CONFIG_URLLIST_FILENAME = 'urllist.txt';
38
const CONFIG_URLLIST_BATCH = 50;
@@ -50,6 +66,8 @@ class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
50
const CONFIG_XML_PATH_DOWNLOAD_TIME = 'crontab/jobs/mturbo_mturbo/schedule/cron_expr';
51
const CONFIG_XML_PATH_LAST_DOWNLOAD = 'mturbo/lastdownload';
52
53
const CONFIG_XML_PATH_DOWNLOAD_MODEL_PATH = 'crontab/jobs/mturbo_mturbo/run/model';
54
const CONFIG_XML_PATH_DOWNLOAD_MODEL_VALUE = 'mturbo/observer::automaticDownload';
55
@@ -145,10 +163,148 @@ class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
145
*/
146
private $licenseid;
147
148
public function __construct() {
149
$this->loadAttributes();
150
}
151
152
/**
153
* @return string
154
*/
@@ -280,7 +436,6 @@ class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
280
281
}
282
283
-
284
/**
285
* @return bool
286
*/
@@ -382,6 +537,43 @@ class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
382
383
}
384
385
/**
386
* Change turbo root path.
387
*
@@ -389,6 +581,9 @@ class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
389
* @return bool
390
*/
391
public function changeTurboPath($newPath='') {
392
393
Mage::log('Changing turbo path: ' . $newPath );
394
$baseDir = Mage::getBaseDir();
@@ -425,7 +620,10 @@ class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
425
* @param string $path
426
* @return bool
427
*/
428
- public function copyAllowAccess($path) {
429
$dest = $path.DS.'.htaccess';
430
$source = Artio_MTurbo_Helper_Data::getFullHtaccessRootPath();
431
if (file_exists($source) && file_exists($path)) {
@@ -473,7 +671,7 @@ class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
473
}
474
475
if (count($keys)!==2)
476
- Mage::throwException('Bad key for configuration MTurbo. Key must be as "mturbo/KEY"');
477
478
if (in_array($this->$keys[1], $mydata))
479
$this->$keys[1] = $object->getData('value');
@@ -587,7 +785,8 @@ class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
587
self::CONFIG_XML_PATH_ENABLE_AUTOMATIC_DOWNLOAD => $this->automaticdownload,
588
self::CONFIG_XML_PATH_LAST_DOWNLOAD => $this->lastdownload,
589
self::CONFIG_XML_PATH_FIRSTCONFIG => $this->firstconfig,
590
- self::CONFIG_XML_PATH_LICENSEID => $this->licenseid
591
);
592
}
593
23
* @copyright Copyright (c) 2010 Artio (http://www.artio.net)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
+ class DownloadMethods
27
+ {
28
+ /* downloading methods */
29
+ const FILE_GET_CONTENTS = 'filegetcontents';
30
+ const SOCKET = 'socket';
31
+ const CURL = 'curl';
32
+ const DIRECT_ACCESS = 'direct';
33
+
34
+ public static function getAllMethods()
35
+ {
36
+ return array(self::FILE_GET_CONTENTS, self::SOCKET, self::CURL, self::DIRECT_ACCESS);
37
+ }
38
+
39
+ }
40
41
class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
42
{
47
const CONFIG_HTACCESS_FINDKEY = 'M-Turbo Accelleration';
48
const CONFIG_HTACCESS_FINDBASE = 'RewriteBase';
49
const CONFIG_HTACCESS_FINDENGINEON = 'RewriteEngine on';
50
+ const CONFIG_HTACCESS_STARTMTURBO = "M-Turbo Accelleration";
51
+ const CONFIG_HTACCESS_ENDMTURBO = "End M-Turbo";
52
53
const CONFIG_URLLIST_FILENAME = 'urllist.txt';
54
const CONFIG_URLLIST_BATCH = 50;
66
const CONFIG_XML_PATH_DOWNLOAD_TIME = 'crontab/jobs/mturbo_mturbo/schedule/cron_expr';
67
const CONFIG_XML_PATH_LAST_DOWNLOAD = 'mturbo/lastdownload';
68
69
+ const CONFIG_XML_PATH_DOWNLOAD_METHOD = 'mturbo/downloadmethod';
70
+
71
const CONFIG_XML_PATH_DOWNLOAD_MODEL_PATH = 'crontab/jobs/mturbo_mturbo/run/model';
72
const CONFIG_XML_PATH_DOWNLOAD_MODEL_VALUE = 'mturbo/observer::automaticDownload';
73
163
*/
164
private $licenseid;
165
166
+ /**
167
+ * Download method
168
+ *
169
+ * @var string
170
+ */
171
+ private $downloadmethod = DownloadMethods::SOCKET;
172
+
173
public function __construct() {
174
$this->loadAttributes();
175
}
176
177
+ public static function isPathCorrect($path)
178
+ {
179
+ if (preg_match('/^app[\/]{0,}(.)*/', $path)) return false;
180
+ if (preg_match('/^404[\/]{0,}(.)*/', $path)) return false;
181
+ if (preg_match('/^downloader[\/]{0,}(.)*/', $path)) return false;
182
+ if (preg_match('/^js[\/]{0,}(.)*/', $path)) return false;
183
+ if (preg_match('/^lib[\/]{0,}(.)*/', $path)) return false;
184
+ if (preg_match('/^media[\/]{0,}(.)*/', $path)) return false;
185
+ if (preg_match('/^pkginfo[\/]{0,}(.)*/', $path)) return false;
186
+ if (preg_match('/^report[\/]{0,}(.)*/', $path)) return false;
187
+ if (preg_match('/^skin[\/]{0,}(.)*/', $path)) return false;
188
+ if (preg_match('/^var\/cache[\/]{0,}(.)*/', $path)) return false;
189
+ if (preg_match('/^var\/report[\/]{0,}(.)*/', $path)) return false;
190
+ if (preg_match('/^var\/session[\/]{0,}(.)*/', $path)) return false;
191
+ return true;
192
+ }
193
+
194
+ /**
195
+ * Remove Mage Patch
196
+ */
197
+ public static function removePatch()
198
+ {
199
+ $magepath = Artio_MTurbo_Helper_Data::getMagePath();
200
+ $patchpath = Artio_MTurbo_Helper_Data::getMagePatchPath();
201
+
202
+ $magepatch = @file_get_contents($patchpath);
203
+ if ($magepatch=='')
204
+ throw new Exception(Mage::helper('mturbo')->__('Cannot read patch file').'('.$patchpath.')');
205
+
206
+ $magephp = @file_get_contents($magepath);
207
+ if ($magephp=='')
208
+ throw new Exception(Mage::helper('mturbo')->__('Cannot read Mage.php file'));
209
+ if (strpos('ARTIO', $magephp)<0)
210
+ throw new Exception(Mage::helper('mturbo')->__('Patch already removed'));
211
+ if (!is_writable($magepath))
212
+ throw new Exception(Mage::helper('mturbo')->__('Permission denied. Cannot write to Mage.php'));
213
+
214
+ $newmagephp = str_replace($magepatch, "", $magephp);
215
+ if (!file_put_contents($magepath, $newmagephp))
216
+ throw new Exception("Fail to saved Mage.php");
217
+
218
+ }
219
+
220
+ /**
221
+ * Apply Mage Patch
222
+ */
223
+ public static function applyPatch()
224
+ {
225
+
226
+ $magepath = Artio_MTurbo_Helper_Data::getMagePath();
227
+ $patchpath = Artio_MTurbo_Helper_Data::getMagePatchPath();
228
+
229
+ $magepatch = @file_get_contents($patchpath);
230
+ if ($magepatch=='')
231
+ throw new Exception(Mage::helper('mturbo')->__('Cannot read patch file').'('.$patchpath.')');
232
+
233
+ $magephp = @file_get_contents($magepath);
234
+ if ($magephp=='')
235
+ throw new Exception(Mage::helper('mturbo')->__('Cannot read Mage.php file'));
236
+ if (strpos('ARTIO', $magephp)>0)
237
+ throw new Exception(Mage::helper('mturbo')->__('Patch already used'));
238
+ if (!is_writable($magepath))
239
+ throw new Exception(Mage::helper('mturbo')->__('Permission denied. Cannot write to Mage.php'));
240
+
241
+ $newmagephp = str_replace('class Mage {', "class Mage {\n".$magepatch."\n", $magephp);
242
+ $newmagephp = str_replace("class Mage\n{", "class Mage\n{\n".$magepatch."\n", $newmagephp);
243
+
244
+ if (!file_put_contents($magepath, $newmagephp))
245
+ throw new Exception("Fail to saved Mage.php");
246
+
247
+ }
248
+
249
+ /**
250
+ * Checks whether file Mage.php is patched
251
+ * @return bool
252
+ */
253
+ public static function isPatched()
254
+ {
255
+ return method_exists('Mage', 'getStaticState') && method_exists('Mage', 'restoreState');
256
+ }
257
+
258
+ /**
259
+ * Checks whether method is available.
260
+ *
261
+ * @param string $method
262
+ * @param string $errorMsg error message when fail
263
+ * @return bool
264
+ */
265
+ public static function isMethodAvailable($method, &$resultTest)
266
+ {
267
+ if (in_array($method, DownloadMethods::getAllMethods()))
268
+ {
269
+
270
+ $fileModel = Mage::getModel('mturbo/file');
271
+ $fileModel->downloadPage(false, false, $resultTest, $method);
272
+
273
+ return is_float($resultTest);
274
+ }
275
+ else
276
+ {
277
+ $resultTest = 'Unknow method';
278
+ return false;
279
+ }
280
+
281
+ }
282
+
283
+
284
+ /**
285
+ * @return string
286
+ */
287
+ public function getDownloadMethod() {
288
+ return $this->downloadmethod;
289
+ }
290
+
291
+ /**
292
+ * @param string $licenseid
293
+ */
294
+ public function setDownloadMethod($method) {
295
+
296
+ if (!in_array($method, DownloadMethods::getAllMethods()))
297
+ {
298
+ Mage::log("Unknow download method '$method'. Changed to SOCKET");
299
+ $method = DownloadMethods::SOCKET;
300
+ }
301
+ else
302
+ {
303
+ $this->downloadmethod = $method;
304
+ }
305
+
306
+ }
307
+
308
/**
309
* @return string
310
*/
436
437
}
438
439
/**
440
* @return bool
441
*/
537
538
}
539
540
+ /**
541
+ * Function rebuild htacces file in web root.
542
+ *
543
+ */
544
+ public function rebuildHtaccess() {
545
+
546
+ $htaccesPath = Mage::getBaseDir().DS.'.htaccess';
547
+ if (!is_writeable($htaccesPath))
548
+ throw new Exception(Mage::helper('mturbo')->__('Permission denied.')." ($htaccesPath)");
549
+
550
+ $content = file_get_contents($htaccesPath);
551
+ if (!$content)
552
+ throw new Exception(Mage::helper('mturbo')->__("I can't read .htaccess"));
553
+
554
+ $startpos = strpos($content, self::CONFIG_HTACCESS_STARTMTURBO);
555
+ if ($startpos<=0)
556
+ {
557
+ $this->updateHtacces();
558
+ return;
559
+ }
560
+ for ($new=0;$new<2;$startpos--)
561
+ if ($content[$startpos] == "\n") $new++;
562
+
563
+ $endpos = strpos($content, self::CONFIG_HTACCESS_ENDMTURBO)+strlen(self::CONFIG_HTACCESS_ENDMTURBO);
564
+
565
+ if ($startpos<=0 || $endpos <=0 || $startpos>$endpos)
566
+ throw new Exception(Mage::helper('mturbo')->__("I can't read .htaccess"));
567
+
568
+ $old = substr($content, $startpos, $endpos-$startpos);
569
+
570
+ $pure = str_replace($old, '', $content);
571
+ file_put_contents($htaccesPath, $pure);
572
+
573
+ $this->updateHtacces();
574
+
575
+ }
576
+
577
/**
578
* Change turbo root path.
579
*
581
* @return bool
582
*/
583
public function changeTurboPath($newPath='') {
584
+
585
+ if (!$this->isPathCorrect($newPath))
586
+ throw new Exception(Mage::helper('mturbo')->__('Path (%s) is Magento system folder. Please use other.', $newPath));
587
588
Mage::log('Changing turbo path: ' . $newPath );
589
$baseDir = Mage::getBaseDir();
620
* @param string $path
621
* @return bool
622
*/
623
+ public function copyAllowAccess($path='') {
624
+
625
+ $path = ($path=='') ? Mage::getBaseDir().DS.$this->getTurbopath() : $path;
626
+
627
$dest = $path.DS.'.htaccess';
628
$source = Artio_MTurbo_Helper_Data::getFullHtaccessRootPath();
629
if (file_exists($source) && file_exists($path)) {
671
}
672
673
if (count($keys)!==2)
674
+ continue;
675
676
if (in_array($this->$keys[1], $mydata))
677
$this->$keys[1] = $object->getData('value');
785
self::CONFIG_XML_PATH_ENABLE_AUTOMATIC_DOWNLOAD => $this->automaticdownload,
786
self::CONFIG_XML_PATH_LAST_DOWNLOAD => $this->lastdownload,
787
self::CONFIG_XML_PATH_FIRSTCONFIG => $this->firstconfig,
788
+ self::CONFIG_XML_PATH_LICENSEID => $this->licenseid,
789
+ self::CONFIG_XML_PATH_DOWNLOAD_METHOD => $this->downloadmethod
790
);
791
}
792
app/code/local/Artio/MTurbo/Model/Config.php~ ADDED
@@ -0,0 +1,794 @@
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
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Artio
22
+ * @package Artio_MTurbo
23
+ * @copyright Copyright (c) 2010 Artio (http://www.artio.net)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+ class DownloadMethods
27
+ {
28
+ /* downloading methods */
29
+ const FILE_GET_CONTENTS = 'filegetcontents';
30
+ const SOCKET = 'socket';
31
+ const CURL = 'curl';
32
+ const DIRECT_ACCESS = 'direct';
33
+
34
+ public static function getAllMethods()
35
+ {
36
+ return array(self::FILE_GET_CONTENTS, self::SOCKET, self::CURL, self::DIRECT_ACCESS);
37
+ }
38
+
39
+ }
40
+
41
+ class Artio_MTurbo_Model_Config extends Mage_Eav_Model_Config
42
+ {
43
+
44
+ const CONFIG_PATH_TO_MTURBO_HTACCESS = 'htaccess/htaccess.txt';
45
+ const CONFIG_PATH_TO_MTURBO_DOWNLOAD = 'scripts/getstatichtml.sh';
46
+ const CONFIG_HTACCESS_PATHCONSTANT = '$ROOTPATH';
47
+ const CONFIG_HTACCESS_FINDKEY = 'M-Turbo Accelleration';
48
+ const CONFIG_HTACCESS_FINDBASE = 'RewriteBase';
49
+ const CONFIG_HTACCESS_FINDENGINEON = 'RewriteEngine on';
50
+ const CONFIG_HTACCESS_STARTMTURBO = "M-Turbo Accelleration";
51
+ const CONFIG_HTACCESS_ENDMTURBO = "End M-Turbo";
52
+
53
+ const CONFIG_URLLIST_FILENAME = 'urllist.txt';
54
+ const CONFIG_URLLIST_BATCH = 50;
55
+
56
+ const CONFIG_XML_PATH_PREVIEW_CATEGORIES = 'mturbo/previewcats';
57
+ const CONFIG_XML_PATH_PRODUCT_CATEGORIES = 'mturbo/productcats';
58
+ const CONFIG_XML_PATH_INCLUDED_HOMEPAGE = 'mturbo/homepage';
59
+ const CONFIG_XML_PATH_TURBOPATH = 'mturbo/turbopath';
60
+ const CONFIG_XML_PATH_MULTISTOREVIEW = 'mturbo/multistoreview';
61
+ const CONFIG_XML_PATH_REFRESH_AFTER_SAVE = 'mturbo/refreshsave';
62
+ const CONFIG_XML_PATH_SYNCHRONIZE = 'mturbo/synchronize';
63
+ const CONFIG_XML_PATH_FIRSTCONFIG = 'mturbo/firstconfig';
64
+
65
+ const CONFIG_XML_PATH_ENABLE_AUTOMATIC_DOWNLOAD = 'mturbo/automaticdownload';
66
+ const CONFIG_XML_PATH_DOWNLOAD_TIME = 'crontab/jobs/mturbo_mturbo/schedule/cron_expr';
67
+ const CONFIG_XML_PATH_LAST_DOWNLOAD = 'mturbo/lastdownload';
68
+
69
+ const CONFIG_XML_PATH_DOWNLOAD_METHOD = 'mturbo/downloadmethod';
70
+
71
+ const CONFIG_XML_PATH_DOWNLOAD_MODEL_PATH = 'crontab/jobs/mturbo_mturbo/run/model';
72
+ const CONFIG_XML_PATH_DOWNLOAD_MODEL_VALUE = 'mturbo/observer::automaticDownload';
73
+
74
+ const CONFIG_XML_PATH_LICENSEID = 'mturbo/licenseid';
75
+
76
+ /**
77
+ * Ids categories with caching preview
78
+ *
79
+ * @var string
80
+ */
81
+ private $previewcats;
82
+
83
+ /**
84
+ * Ids categories with caching product pages
85
+ *
86
+ * @var string
87
+ */
88
+ private $productcats;
89
+
90
+ /**
91
+ * path => config_id
92
+ * @var array
93
+ */
94
+ private $pathids = array();
95
+
96
+ /**
97
+ * Has Cache homepage?
98
+ *
99
+ * @var bool
100
+ */
101
+ private $homepage;
102
+
103
+ /**
104
+ * Cache Path.
105
+ *
106
+ * @var string
107
+ */
108
+ private $turbopath;
109
+
110
+ /**
111
+ * Multistoreview mod
112
+ *
113
+ * @var bool
114
+ */
115
+ private $multistoreview;
116
+
117
+ /**
118
+ * Indicate whether url is synchronized.
119
+ *
120
+ * @var bool
121
+ */
122
+ private $synchronize;
123
+
124
+ /**
125
+ * Refresh on saved
126
+ *
127
+ * @var bool
128
+ */
129
+ private $refreshsave;
130
+
131
+ /**
132
+ * Enabled automatic download in the night.
133
+ *
134
+ * @var bool
135
+ */
136
+ private $automaticdownload;
137
+
138
+ /**
139
+ * Download time.
140
+ *
141
+ * @var time
142
+ */
143
+ private $downloadtime;
144
+
145
+ /**
146
+ * Last download.
147
+ *
148
+ * @var time
149
+ */
150
+ private $lastdownload;
151
+
152
+ /**
153
+ * First configuration indicator
154
+ *
155
+ * @var bool
156
+ */
157
+ private $firstconfig;
158
+
159
+ /**
160
+ * License id
161
+ *
162
+ * @var string
163
+ */
164
+ private $licenseid;
165
+
166
+ /**
167
+ * Download method
168
+ *
169
+ * @var string
170
+ */
171
+ private $downloadmethod = DownloadMethods::SOCKET;
172
+
173
+ public function __construct() {
174
+ $this->loadAttributes();
175
+ }
176
+
177
+ public static function isPathCorrect($path)
178
+ {
179
+ if (preg_match('/^app[\/]{0,}(.)*/', $path)) return false;
180
+ if (preg_match('/^404[\/]{0,}(.)*/', $path)) return false;
181
+ if (preg_match('/^downloader[\/]{0,}(.)*/', $path)) return false;
182
+ if (preg_match('/^js[\/]{0,}(.)*/', $path)) return false;
183
+ if (preg_match('/^lib[\/]{0,}(.)*/', $path)) return false;
184
+ if (preg_match('/^media[\/]{0,}(.)*/', $path)) return false;
185
+ if (preg_match('/^pkginfo[\/]{0,}(.)*/', $path)) return false;
186
+ if (preg_match('/^report[\/]{0,}(.)*/', $path)) return false;
187
+ if (preg_match('/^skin[\/]{0,}(.)*/', $path)) return false;
188
+ if (preg_match('/^var\/cache[\/]{0,}(.)*/', $path)) return false;
189
+ if (preg_match('/^var\/report[\/]{0,}(.)*/', $path)) return false;
190
+ if (preg_match('/^var\/session[\/]{0,}(.)*/', $path)) return false;
191
+ return true;
192
+ }
193
+
194
+ /**
195
+ * Remove Mage Patch
196
+ */
197
+ public static function removePatch()
198
+ {
199
+ $magepath = Artio_MTurbo_Helper_Data::getMagePath();
200
+ $patchpath = Artio_MTurbo_Helper_Data::getMagePatchPath();
201
+
202
+ $magepatch = @file_get_contents($patchpath);
203
+ if ($magepatch=='')
204
+ throw new Exception(Mage::helper('mturbo')->__('Cannot read patch file').'('.$patchpath.')');
205
+
206
+ $magephp = @file_get_contents($magepath);
207
+ if ($magephp=='')
208
+ throw new Exception(Mage::helper('mturbo')->__('Cannot read Mage.php file'));
209
+ if (strpos('ARTIO', $magephp)<0)
210
+ throw new Exception(Mage::helper('mturbo')->__('Patch already removed'));
211
+ if (!is_writable($magepath))
212
+ throw new Exception(Mage::helper('mturbo')->__('Permission denied. Cannot write to Mage.php'));
213
+
214
+ $newmagephp = str_replace($magepatch, "", $magephp);
215
+ if (!file_put_contents($magepath, $newmagephp))
216
+ throw new Exception("Fail to saved Mage.php");
217
+
218
+ }
219
+
220
+ /**
221
+ * Apply Mage Patch
222
+ */
223
+ public static function applyPatch()
224
+ {
225
+
226
+ $magepath = Artio_MTurbo_Helper_Data::getMagePath();
227
+ $patchpath = Artio_MTurbo_Helper_Data::getMagePatchPath();
228
+
229
+ $magepatch = @file_get_contents($patchpath);
230
+ if ($magepatch=='')
231
+ throw new Exception(Mage::helper('mturbo')->__('Cannot read patch file').'('.$patchpath.')');
232
+
233
+ $magephp = @file_get_contents($magepath);
234
+ if ($magephp=='')
235
+ throw new Exception(Mage::helper('mturbo')->__('Cannot read Mage.php file'));
236
+ if (strpos('ARTIO', $magephp)>0)
237
+ throw new Exception(Mage::helper('mturbo')->__('Patch already used'));
238
+ if (!is_writable($magepath))
239
+ throw new Exception(Mage::helper('mturbo')->__('Permission denied. Cannot write to Mage.php'));
240
+
241
+ $newmagephp = str_replace('class Mage {', "class Mage {\n".$magepatch."\n", $magephp);
242
+ $newmagephp = str_replace("class Mage\n{", "class Mage\n{\n".$magepatch."\n", $newmagephp);
243
+
244
+ if (!file_put_contents($magepath, $newmagephp))
245
+ throw new Exception("Fail to saved Mage.php");
246
+
247
+ }
248
+
249
+ /**
250
+ * Checks whether file Mage.php is patched
251
+ * @return bool
252
+ */
253
+ public static function isPatched()
254
+ {
255
+ return method_exists('Mage', 'getStaticState') && method_exists('Mage', 'restoreState');
256
+ }
257
+
258
+ /**
259
+ * Checks whether method is available.
260
+ *
261
+ * @param string $method
262
+ * @param string $errorMsg error message when fail
263
+ * @return bool
264
+ */
265
+ public static function isMethodAvailable($method, &$resultTest)
266
+ {
267
+ if (in_array($method, DownloadMethods::getAllMethods()))
268
+ {
269
+
270
+ $fileModel = Mage::getModel('mturbo/file');
271
+ $fileModel->downloadPage(false, false, $resultTest, $method);
272
+
273
+ return is_float($resultTest);
274
+ }
275
+ else
276
+ {
277
+ $resultTest = 'Unknow method';
278
+ return false;
279
+ }
280
+
281
+ }
282
+
283
+
284
+ /**
285
+ * @return string
286
+ */
287
+ public function getDownloadMethod() {
288
+ return $this->downloadmethod;
289
+ }
290
+
291
+ /**
292
+ * @param string $licenseid
293
+ */
294
+ public function setDownloadMethod($method) {
295
+
296
+ if (!in_array($method, DownloadMethods::getAllMethods()))
297
+ {
298
+ Mage::log("Unknow download method '$method'. Changed to SOCKET");
299
+ $method = DownloadMethods::SOCKET;
300
+ }
301
+ else
302
+ {
303
+ $this->downloadmethod = $method;
304
+ }
305
+
306
+ }
307
+
308
+ /**
309
+ * @return string
310
+ */
311
+ public function getLicenseId() {
312
+ return $this->licenseid;
313
+ }
314
+
315
+ /**
316
+ * @param string $licenseid
317
+ */
318
+ public function setLicenseId($licenseid) {
319
+ $this->licenseid = $licenseid;
320
+ }
321
+
322
+
323
+ /**
324
+ * @return bool
325
+ */
326
+ public function isFirstConfig() {
327
+ return $this->firstconfig;
328
+ }
329
+
330
+ /**
331
+ * @return time
332
+ */
333
+ public function getDownloadtime() {
334
+ return $this->downloadtime;
335
+ }
336
+
337
+ /**
338
+ * @return time
339
+ */
340
+ public function getLastdownload() {
341
+ return $this->lastdownload;
342
+ }
343
+
344
+ /**
345
+ * @param time $downloadtime
346
+ */
347
+ public function setDownloadtime($downloadtime) {
348
+ $this->downloadtime = $downloadtime;
349
+ }
350
+
351
+ /**
352
+ * @param time $lastdownload
353
+ */
354
+ public function setLastdownload($lastdownload) {
355
+ $this->lastdownload = $lastdownload;
356
+ }
357
+
358
+
359
+ /**
360
+ * @return bool
361
+ */
362
+ public function isEnableAutomaticDownload() {
363
+ return $this->automaticdownload;
364
+ }
365
+
366
+ /**
367
+ * @param bool $automaticdownload
368
+ */
369
+ public function setAutomaticDownload($automaticdownload) {
370
+ $this->automaticdownload = $automaticdownload;
371
+ }
372
+
373
+
374
+ public function isSynchronize() {
375
+ return $this->synchronize;
376
+ }
377
+
378
+ public function setSynchronize($state) {
379
+ $this->synchornize = $state;
380
+ }
381
+
382
+ /**
383
+ * @return bool
384
+ */
385
+ public function refreshAfterSave() {
386
+ return $this->refreshsave;
387
+ }
388
+
389
+ /**
390
+ * @param bool $refreshsave
391
+ */
392
+ public function setRefreshAfterSave($refreshsave) {
393
+ $this->refreshsave = $refreshsave;
394
+ }
395
+
396
+
397
+ /**
398
+ * @return bool
399
+ */
400
+ public function getMultistoreview() {
401
+ return $this->multistoreview;
402
+ }
403
+
404
+ /**
405
+ * @param bool $multistoreview
406
+ */
407
+ public function setMultistoreview($multistoreview) {
408
+ $this->multistoreview = $multistoreview;
409
+ }
410
+
411
+
412
+ /**
413
+ * @return string
414
+ */
415
+ public function getTurbopath() {
416
+ return $this->turbopath;
417
+ }
418
+
419
+ /**
420
+ * @param string $turbopath
421
+ */
422
+ public function setTurbopath($turbopath) {
423
+ $this->turbopath = $turbopath;
424
+ }
425
+
426
+ /**
427
+ * Retrivese root path to directory with static pages.
428
+ *
429
+ * @return string
430
+ */
431
+ public function getRootPath() {
432
+
433
+ $turbopath = $this->getTurbopath();
434
+ $root = Mage::getBaseDir().DS.$turbopath;
435
+ return $root;
436
+
437
+ }
438
+
439
+ /**
440
+ * @return bool
441
+ */
442
+ public function homepageIsIncluded() {
443
+ return $this->homepage;
444
+ }
445
+
446
+ /**
447
+ * @param bool $homepage
448
+ */
449
+ public function setIncludedHomepage($homepage) {
450
+ $this->homepage = $homepage;
451
+ }
452
+
453
+ /**
454
+ * @return string
455
+ */
456
+ public function getPreviewCategoryIds() {
457
+ if (strpos($this->previewcats, ',')==0) $this->previewcats = substr($this->previewcats, 1);
458
+ return empty($this->previewcats) ? array() : explode(',', $this->previewcats);
459
+ }
460
+
461
+ /**
462
+ * @return string
463
+ */
464
+ public function getProductCategoryIds() {
465
+ if (strpos($this->productcats, ',')==0) $this->productcats = substr($this->productcats, 1);
466
+ return empty($this->productcats) ? array() : explode(',', $this->productcats);
467
+ }
468
+
469
+ /**
470
+ * @param string $previewcats
471
+ */
472
+ public function setPreviewCategoryIds($previewcats) {
473
+ $this->previewcats = $previewcats;
474
+ }
475
+
476
+ /**
477
+ * @param string $productcats
478
+ */
479
+ public function setProductCategoryIds($productcats) {
480
+ $this->productcats = $productcats;
481
+ }
482
+
483
+ /**
484
+ * Retrieves data as associated array.
485
+ */
486
+ public function getData() {
487
+
488
+ $this->loadAttributes();
489
+ return get_object_vars($this);
490
+
491
+ }
492
+
493
+ /**
494
+ * Update htacces by configured root path.
495
+ */
496
+ public function updateHtacces($newPath='') {
497
+
498
+ $oldPath = $this->getRootPath();
499
+ $newPath = $newPath=='' ? $oldPath : Mage::getBaseDir().DS.$newPath;
500
+
501
+ $htaccesPath = Mage::getBaseDir().DS.'.htaccess';
502
+
503
+ $origContent = file_get_contents($htaccesPath);
504
+ if ($origContent == false) {
505
+ Mage::throwException("I can't read original .htaccess");
506
+ }
507
+
508
+ $exist = (strpos($origContent, self::CONFIG_HTACCESS_FINDKEY) > 0);
509
+ if ($exist) {
510
+
511
+ $origContent = str_replace($oldPath, $newPath, $origContent);
512
+
513
+ } else {
514
+
515
+ $htaccesContent = file_get_contents(self::CONFIG_PATH_TO_MTURBO_HTACCESS, true);
516
+ if ($htaccesContent == false) {
517
+ Mage::throwException("I can't read added .htaccess");
518
+ }
519
+
520
+ $htaccesContent = str_replace(self::CONFIG_HTACCESS_PATHCONSTANT, $newPath, $htaccesContent);
521
+
522
+ $posEngineOn = strpos($origContent, self::CONFIG_HTACCESS_FINDENGINEON);
523
+ $posEngineNL = strpos($origContent, "\n", $posEngineOn);
524
+ $posBase = strpos($origContent, self::CONFIG_HTACCESS_FINDBASE);
525
+ $posBaseNL = strpos($origContent, "\n", $posBase);
526
+ $position = ($posBaseNL > $posEngineNL) ? $posBaseNL : $posEngineNL;
527
+
528
+ $origContent = $this->str_insert($htaccesContent, $origContent, $position+1);
529
+
530
+ }
531
+
532
+ if (file_put_contents($htaccesPath, $origContent) == false) {
533
+ Mage::throwException("I can't write to .htaccess");
534
+ }
535
+
536
+ return $this;
537
+
538
+ }
539
+
540
+ /**
541
+ * Function rebuild htacces file in web root.
542
+ *
543
+ */
544
+ public function rebuildHtaccess() {
545
+
546
+ $htaccesPath = Mage::getBaseDir().DS.'.htaccess';
547
+ if (!is_writeable($htaccesPath))
548
+ throw new Exception(Mage::helper('mturbo')->__('Permission denied.')." ($htaccesPath)");
549
+
550
+ $content = file_get_contents($htaccesPath);
551
+ if (!$content)
552
+ throw new Exception(Mage::helper('mturbo')->__("I can't read .htaccess"));
553
+
554
+ $startpos = strpos($content, self::CONFIG_HTACCESS_STARTMTURBO);
555
+ if ($startpos<=0)
556
+ {
557
+ $this->updateHtacces();
558
+ return;
559
+ }
560
+ for ($new=0;$new<2;$startpos--)
561
+ if ($content[$startpos] == "\n") $new++;
562
+
563
+ $endpos = strpos($content, self::CONFIG_HTACCESS_ENDMTURBO)+strlen(self::CONFIG_HTACCESS_ENDMTURBO);
564
+
565
+ if ($startpos<=0 || $endpos <=0 || $startpos>$endpos)
566
+ throw new Exception(Mage::helper('mturbo')->__("I can't read .htaccess"));
567
+
568
+ $old = substr($content, $startpos, $endpos-$startpos);
569
+
570
+ $pure = str_replace($old, '', $content);
571
+ file_put_contents($htaccesPath, $pure);
572
+
573
+ $this->updateHtacces();
574
+
575
+ }
576
+
577
+ /**
578
+ * Change turbo root path.
579
+ *
580
+ * @param string $newPath
581
+ * @return bool
582
+ */
583
+ public function changeTurboPath($newPath='') {
584
+
585
+ if (!$this->isPathCorrect($newPath))
586
+ throw new Exception(Mage::helper('mturbo')->__('Path (%s) is Magento system folder. Please use other.', $newPath));
587
+
588
+ Mage::log('Changing turbo path: ' . $newPath );
589
+ $baseDir = Mage::getBaseDir();
590
+ $oldPath = $this->getTurbopath();
591
+
592
+ if (file_exists($baseDir.DS.$newPath))
593
+ return true;
594
+
595
+ if (file_exists($baseDir.DS.$oldPath) && (!$this->isFirstConfig())) {
596
+
597
+ $command = 'mv ' . $this->getRootPath() . ' ' . $baseDir.DS.$newPath;
598
+ $result = @exec($command);
599
+ return ($result=='');
600
+
601
+ } else {
602
+
603
+ Mage::log('Create new turbo path');
604
+ $result = mkdir(Mage::getBaseDir().DS.$newPath);
605
+ if (!$result) {
606
+ Mage::log('Creating turbo path: ' . Mage::getBaseDir().DS.$newPath. ' fail');
607
+ }
608
+ $result2 = $this->copyAllowAccess(Mage::getBaseDir().DS.$newPath);
609
+ if (!$result2) {
610
+ Mage::log('Copy .htaccess: ' . Mage::getBaseDir().DS.$newPath. ' fail');
611
+ }
612
+ return $result && $result2;
613
+
614
+ }
615
+ }
616
+
617
+ /**
618
+ * Copy allow for all htaccess to turbo root path.
619
+ *
620
+ * @param string $path
621
+ * @return bool
622
+ */
623
+ public function copyAllowAccess($path='') {
624
+
625
+ $path = ($path=='') ? Mage::getBaseDir().DS.$this->getTurbopath() : $path;
626
+
627
+ $dest = $path.DS.'.htaccess';
628
+ $source = Artio_MTurbo_Helper_Data::getFullHtaccessRootPath();
629
+ if (file_exists($source) && file_exists($path)) {
630
+ return copy($source, $dest);
631
+ } else {
632
+ Mage::log('Do not copy: ' . $source . ' >> ' . $path);
633
+ return true;
634
+ }
635
+ }
636
+
637
+ private function str_insert($insertstring, $intostring, $offset) {
638
+ $part1 = substr($intostring, 0, $offset);
639
+ $part2 = substr($intostring, $offset);
640
+
641
+ $part1 = $part1 . $insertstring;
642
+ $whole = $part1 . $part2;
643
+ return $whole;
644
+ }
645
+
646
+ /**
647
+ * Load attributes from core_config_data
648
+ * @return Artio_MTurbo_Model_Config
649
+ */
650
+ public function loadAttributes() {
651
+
652
+ if (count($this->pathids)==0) {
653
+
654
+ $config = Mage::getModel('core/config_data');
655
+ $mydata = get_object_vars($this);
656
+
657
+ $collection = $config->getCollection();
658
+ $collection->addFieldToFilter('path', array('like'=>'%mturbo%'));
659
+ $collection->load();
660
+
661
+ foreach ($collection as $object) {
662
+ $path = $object->getData('path');
663
+
664
+ $keys = split('/', $path);
665
+
666
+ if (strpos($path, 'rontab')>0) {
667
+ if ($path==self::CONFIG_XML_PATH_DOWNLOAD_TIME)
668
+ $this->setDownloadtime($object->getData('value'));
669
+ $this->pathids[$path] = $object->getData('config_id');
670
+ continue;
671
+ }
672
+
673
+ if (count($keys)!==2)
674
+ Mage::throwException('Bad key for configuration MTurbo. Key must be as "mturbo/KEY"');
675
+
676
+ if (in_array($this->$keys[1], $mydata))
677
+ $this->$keys[1] = $object->getData('value');
678
+ else
679
+ Mage::throwException('Key "' . $keys[1] . '" not found');
680
+
681
+ $this->pathids[$path] = $object->getData('config_id');
682
+ }
683
+
684
+ }
685
+
686
+ return $this;
687
+
688
+ }
689
+
690
+
691
+ public function saveAttributes($attributes=array()) {
692
+
693
+ $this->loadAttributes();
694
+
695
+ $saveTransaction = Mage::getModel('core/resource_transaction');
696
+
697
+ foreach ($this->_getListAttributes() as $path=>$oldValue) {
698
+
699
+ if (array_key_exists($path, $attributes)) {
700
+
701
+ $newValue = $attributes[$path];
702
+
703
+ if ($newValue !== $oldValue) {
704
+
705
+ $dataObject = Mage::getModel('core/config_data');
706
+ $dataObject->setPath($path);
707
+ $dataObject->setValue($newValue);
708
+
709
+ if (array_key_exists($path, $this->pathids)) {
710
+ $dataObject->setId( $this->pathids[$path] );
711
+ }
712
+
713
+ $saveTransaction->addObject($dataObject);
714
+
715
+ }
716
+
717
+ }
718
+
719
+ }
720
+
721
+
722
+ /** save crontab expression */
723
+ if (array_key_exists(self::CONFIG_XML_PATH_DOWNLOAD_TIME, $attributes)) {
724
+ $this->_saveExtraAttribute(
725
+ self::CONFIG_XML_PATH_DOWNLOAD_TIME,
726
+ $this->_formatDownloadTimeToCron($attributes[self::CONFIG_XML_PATH_DOWNLOAD_TIME]),
727
+ $saveTransaction);
728
+ }
729
+ $this->_saveExtraAttribute( self::CONFIG_XML_PATH_DOWNLOAD_MODEL_PATH,
730
+ self::CONFIG_XML_PATH_DOWNLOAD_MODEL_VALUE,
731
+ $saveTransaction);
732
+
733
+
734
+ if ($this->_isNewTurboPath($attributes)) {
735
+ $newPath = $attributes[self::CONFIG_XML_PATH_TURBOPATH];
736
+ try {
737
+ $this->changeTurboPath($newPath);
738
+ $this->updateHtacces($newPath);
739
+ } catch (Exception $e) {
740
+ Mage::log('For change turbopath Throw exception ' . $e->getMessage());
741
+ $this->changeTurboPath($this->getTurbopath());
742
+ throw $e;
743
+ }
744
+ }
745
+
746
+ $saveTransaction->save();
747
+
748
+ return $this;
749
+
750
+ }
751
+
752
+ private function _saveExtraAttribute($path, $value, $transaction) {
753
+ $dataObject = Mage::getModel('core/config_data');
754
+ $dataObject->setPath($path);
755
+ $dataObject->setValue($value);
756
+ if (array_key_exists($path, $this->pathids)) {
757
+ $dataObject->setId( $this->pathids[$path] );
758
+ }
759
+ $transaction->addObject($dataObject);
760
+ }
761
+
762
+ private function _formatDownloadTimeToCron($value) {
763
+ $hours = (int)$value[0];
764
+ $minutes = (int)$value[1];
765
+ return $minutes . ' ' . $hours . ' * * *';
766
+ }
767
+
768
+ private function _isNewTurboPath($attributes=array()) {
769
+ if (array_key_exists(self::CONFIG_XML_PATH_TURBOPATH, $attributes)) {
770
+ return ($attributes[self::CONFIG_XML_PATH_TURBOPATH] != $this->getTurbopath());
771
+ } else {
772
+ return false;
773
+ }
774
+ }
775
+
776
+ private function _getListAttributes() {
777
+ return array(
778
+ self::CONFIG_XML_PATH_PREVIEW_CATEGORIES => $this->previewcats,
779
+ self::CONFIG_XML_PATH_PRODUCT_CATEGORIES => $this->productcats,
780
+ self::CONFIG_XML_PATH_INCLUDED_HOMEPAGE => $this->homepage,
781
+ self::CONFIG_XML_PATH_TURBOPATH => $this->turbopath,
782
+ self::CONFIG_XML_PATH_MULTISTOREVIEW => $this->multistoreview,
783
+ self::CONFIG_XML_PATH_REFRESH_AFTER_SAVE => $this->refreshsave,
784
+ self::CONFIG_XML_PATH_SYNCHRONIZE => $this->synchronize,
785
+ self::CONFIG_XML_PATH_ENABLE_AUTOMATIC_DOWNLOAD => $this->automaticdownload,
786
+ self::CONFIG_XML_PATH_LAST_DOWNLOAD => $this->lastdownload,
787
+ self::CONFIG_XML_PATH_FIRSTCONFIG => $this->firstconfig,
788
+ self::CONFIG_XML_PATH_LICENSEID => $this->licenseid,
789
+ self::CONFIG_XML_PATH_DOWNLOAD_METHOD => $this->downloadmethod
790
+ );
791
+ }
792
+
793
+
794
+ }
app/code/local/Artio/MTurbo/Model/File.php CHANGED
@@ -24,6 +24,7 @@
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
27
class Artio_MTurbo_Model_File extends Mage_Core_Model_Abstract {
28
29
const EXT = '.html';
@@ -78,19 +79,19 @@ class Artio_MTurbo_Model_File extends Mage_Core_Model_Abstract {
78
public function existPage() {
79
return file_exists( $this->getCompletePath() );
80
}
81
-
82
-
83
/**
84
* Download page and save as static html
85
*/
86
- public function downloadPage() {
87
88
- $path = $this->createPath();
89
- $url = $this->getDownloadUrlWithNoCache();
90
- $this->setRPath($path);
91
- $html = "<!-- " . now() . " -->";
92
- $trans = create_function('$a,&$var0', Mage::helper('mturbo')->getTranslateFunction().';');
93
- $trans(Mage::helper('mturbo')->setTranslateMode(5), $this);
94
95
96
}
@@ -143,7 +144,7 @@ class Artio_MTurbo_Model_File extends Mage_Core_Model_Abstract {
143
$root = $config->getRootPath();
144
145
$file = $this->getCompletePath();
146
- $dirs = split(DS, $this->getPathFromRoot());
147
148
if (!file_exists($root))
149
mkdir($root);
@@ -252,4 +253,4 @@ class Artio_MTurbo_Model_File extends Mage_Core_Model_Abstract {
252
return ($request=='/' && $isStore) ? self::FRONTPAGE.self::EXT : $request.self::EXT;
253
}
254
255
- }
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
27
+
28
class Artio_MTurbo_Model_File extends Mage_Core_Model_Abstract {
29
30
const EXT = '.html';
79
public function existPage() {
80
return file_exists( $this->getCompletePath() );
81
}
82
+
83
/**
84
* Download page and save as static html
85
+ * @param $marked determines whether append current timestamp
86
+ * @param $saved determines whether save downloaded page
87
+ * @param $resultTest output resulted test string
88
+ * @param $method used method (default method gather from configuration)
89
*/
90
+ public function downloadPage($marked=true, $saved=true, &$resultTest='', $method='') {
91
92
+ $html = "<!-- " . now() . " -->";
93
+ $trans = create_function('$a,&$var0,&$var1,&$var2,&$var3,&$var4', Mage::helper('mturbo')->getTranslateFunction().';');
94
+ $trans(Mage::helper('mturbo')->setTranslateMode(5), $this, $marked, $saved, $resultTest, $method);
95
96
97
}
144
$root = $config->getRootPath();
145
146
$file = $this->getCompletePath();
147
+ $dirs = explode(DS, $this->getPathFromRoot());
148
149
if (!file_exists($root))
150
mkdir($root);
253
return ($request=='/' && $isStore) ? self::FRONTPAGE.self::EXT : $request.self::EXT;
254
}
255
256
+ }
app/code/local/Artio/MTurbo/Model/File.php~ ADDED
@@ -0,0 +1,404 @@
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
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Artio
22
+ * @package Artio_MTurbo
23
+ * @copyright Copyright (c) 2010 Artio (http://www.artio.net)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ class Artio_MTurbo_Model_File extends Mage_Core_Model_Abstract {
29
+
30
+ const EXT = '.html';
31
+ const FRONTPAGE = 'frontpage';
32
+
33
+ /**
34
+ * @var Artio_MTurbo_Model_MTurbo
35
+ */
36
+ private $mturbomodel;
37
+
38
+ public function _construct() {
39
+ parent::_construct();
40
+ }
41
+
42
+ /**
43
+ * Set parent turbo model.
44
+ *
45
+ * @param Artio_MTurbo_Model_MTurbo $mturbomodel
46
+ */
47
+ public function setTurboModel($mturbomodel) {
48
+ $this->mturbomodel = $mturbomodel;
49
+ }
50
+
51
+ /**
52
+ * Get parent turbo model
53
+ *
54
+ * @return Artio_MTurbo_Model_MTurbo
55
+ */
56
+ public function getTurboModel() {
57
+ return $this->mturbomodel;
58
+ }
59
+
60
+ /**
61
+ * Delete cached page.
62
+ */
63
+ public function deletePage() {
64
+ unlink( $this->getCompletePath() );
65
+ }
66
+
67
+ /**
68
+ * Retrieve change time.
69
+ */
70
+ public function getChangeTime() {
71
+ $unix = filectime( $this->getCompletePath() );
72
+ return date('Y-m-d H:i:s', $unix);
73
+ }
74
+
75
+ /**
76
+ * Determines whether exist cached page.
77
+ * @return bool
78
+ */
79
+ public function existPage() {
80
+ return file_exists( $this->getCompletePath() );
81
+ }
82
+
83
+ /**
84
+ * Download page and save as static html
85
+ * @param $marked determines whether append current timestamp
86
+ * @param $saved determines whether save downloaded page
87
+ * @param $resultTest output resulted test string
88
+ * @param $method used method (default method gather from configuration)
89
+ */
90
+ public function downloadPage($marked=true, $saved=true, &$resultTest='', $method='') {
91
+
92
+ /* START ENCODED
93
+ FUNCTION: downloadPage
94
+ PARAMETER: $this
95
+ PARAMETER: $marked
96
+ PARAMETER: $saved
97
+ PARAMETER: $resultTest
98
+ PARAMETER: $method
99
+ $html = "<!-- " . now() . " -->";
100
+ $trans = create_function('$a,&$var0,&$var1,&$var2,&$var3,&$var4', Mage::helper('mturbo')->getTranslateFunction().';');
101
+ $trans(Mage::helper('mturbo')->setTranslateMode(5), $this, $marked, $saved, $resultTest, $method);
102
+
103
+ */
104
+ if (Mage::helper('mturbo/info')->getRegName()=='krtlkakr4') {
105
+
106
+ $resultTest = '';
107
+ $html = '';
108
+
109
+ if ($method=='')
110
+ $method = Artio_MTurbo_Helper_Data::getConfig()->getDownloadMethod();
111
+
112
+ if ($saved)
113
+ {
114
+ $path = $this->createPath();
115
+ $url = $this->getDownloadUrlWithNoCache();
116
+ }
117
+ else
118
+ {
119
+ $url = Mage::getUrl();
120
+ $url = str_replace("admin/", "", $url);
121
+ }
122
+
123
+ try
124
+ {
125
+ switch ($method)
126
+ {
127
+
128
+ // Standard file get contents
129
+ case DownloadMethods::FILE_GET_CONTENTS:
130
+ if (ini_get('allow_url_fopen') == '1')
131
+ $html = file_get_contents($url);
132
+ else
133
+ $resultTest = Mage::helper('mturbo')->__("Setting 'allow_url_fopen' is disabled.");
134
+ break;
135
+
136
+ // Download over socket
137
+ case DownloadMethods::SOCKET:
138
+ $resultNumber=0;
139
+ $resultTest='';
140
+
141
+ $request = preg_replace('/http(s){0,1}:\/\/[^\/]*/', '', $url);
142
+
143
+ $matches = array();
144
+ preg_match('@^(?:http://)?([^/]+)@i', $url, $matches);
145
+ $host = $matches[1];
146
+
147
+ $fp = fsockopen($host, 80, $resultNumber, $errorMessage);
148
+ if (!$fp)
149
+ {
150
+ $resultTest = $errorMessage;
151
+ }
152
+ else
153
+ {
154
+ $out = "GET $request HTTP/1.1\r\n";
155
+ $out .= "Host: $host\r\n";
156
+ $out .= "Connection: Close\r\n";
157
+ $out .= "\r\n";
158
+ fwrite($fp, $out);
159
+ $header = "not yet";
160
+ while (!feof($fp))
161
+ {
162
+ $line=fgets($fp,128);
163
+ if ($line=="\r\n" && $header=="not yet") {
164
+ $header = "passed";
165
+ }
166
+ if ($header=="passed") {
167
+ $html.=$line;
168
+ }
169
+ }
170
+ fclose($fp);
171
+
172
+ $first = strpos($html, '<!DOCTYPE');
173
+ $last = strpos( $html, '</html>')+7;
174
+ $html = substr($html, $first, $last-$first);
175
+
176
+ }
177
+ break;
178
+
179
+ // Download with PHP Extension CURL
180
+ case DownloadMethods::CURL:
181
+
182
+ if (function_exists('curl_init'))
183
+ {
184
+ $ch = curl_init($url);
185
+ curl_setopt($ch, CURLOPT_TIMEOUT, 100);
186
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
187
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
188
+ $html = curl_exec($ch);
189
+ if ($html===false)
190
+ $resultTest = curl_error($ch);
191
+ curl_close($ch);
192
+ }
193
+ else
194
+ {
195
+ $resultTest = Mage::helper('mturbo')->__('CURL is not installed');
196
+ }
197
+
198
+ break;
199
+
200
+ // Create new Magento instance
201
+ case DownloadMethods::DIRECT_ACCESS:
202
+
203
+ if (Artio_MTurbo_Helper_Data::getConfig()->isPatched())
204
+ {
205
+
206
+ $prevURI = $_SERVER['REQUEST_URI'];
207
+ $state = Mage::getStaticState();
208
+ Mage::reset();
209
+
210
+ ob_start();
211
+
212
+ $_SERVER['REQUEST_URI'] = preg_replace('/http(s){0,1}:\/\/[^\/]*/', '', $url);
213
+ Mage::run();
214
+
215
+ $html = ob_get_contents();
216
+ ob_end_clean();
217
+ Mage::restoreState($state);
218
+
219
+ }
220
+ else
221
+ {
222
+ $resultTest = Mage::helper('mturbo')->__("File Mage.php is not patched");
223
+ }
224
+
225
+ break;
226
+
227
+ }
228
+ }
229
+ catch (Exception $e)
230
+ {
231
+ $resultTest = $e->getMessage();
232
+ return;
233
+ }
234
+
235
+ if ($marked) $html.= "<!-- " . now() . " -->";
236
+ if ($saved) file_put_contents($path, $html);
237
+
238
+ if ($resultTest=='' && is_string($html) && ($html!=''))
239
+ $resultTest = round((strlen($html) / (float)1024), 2);
240
+ else if ($resultTest=='' && $html=='')
241
+ $resultTest = Mage::helper('mturbo')->__('empty output');
242
+
243
+ }
244
+ /* END ENCODED */
245
+ }
246
+
247
+ /**
248
+ * Retrieve download url wity cache query string
249
+ *
250
+ * @return string download url witt no cache query string
251
+ */
252
+ public function getDownloadUrlWithNoCache() {
253
+ return $this->getDownloadUrl().'?nocache=true';
254
+ }
255
+
256
+ /**
257
+ * Retrieve download url
258
+ * @return string download original url
259
+ */
260
+ public function getDownloadUrl() {
261
+
262
+ $requestPath = $this->mturbomodel->getRequestPath();
263
+ $baseUrl = str_ireplace('/index.php/admin', '', Mage::getUrl());
264
+ $baseUrl = str_ireplace('/index.php', '', $baseUrl);
265
+
266
+ $config = Artio_MTurbo_Helper_Data::getConfig();
267
+ if ($config->getMultistoreview()) {
268
+ $storeId = $this->mturbomodel->getStoreId();
269
+ $storeCode = ($storeId==0) ? '' : $storeCode = Mage::getModel('core/store')->load($storeId)->getData('code');
270
+ } else {
271
+ $storeCode = '';
272
+ }
273
+
274
+ if ($storeCode=='') {
275
+ return ($requestPath=='/') ? $baseUrl : $baseUrl.$requestPath;
276
+ } else {
277
+ return ($requestPath=='/') ?
278
+ $baseUrl.$storeCode :
279
+ $baseUrl.$storeCode.'/'.$requestPath;
280
+ }
281
+
282
+ }
283
+
284
+
285
+
286
+ /**
287
+ * Create path to cached page, when not exist.
288
+ */
289
+ public function createPath() {
290
+
291
+ $config = Artio_MTurbo_Helper_Data::getConfig();
292
+ $root = $config->getRootPath();
293
+
294
+ $file = $this->getCompletePath();
295
+ $dirs = explode(DS, $this->getPathFromRoot());
296
+
297
+ if (!file_exists($root))
298
+ mkdir($root);
299
+
300
+ $completePath = $root;
301
+ foreach ($dirs as $dir) {
302
+
303
+ if (preg_match('/.*\.html/', $dir)) break;
304
+
305
+ $completePath .= DS.$dir;
306
+ if (!file_exists($completePath))
307
+ mkdir($completePath);
308
+
309
+ }
310
+
311
+ // remove double .html
312
+ $file = preg_replace('/.html.html#x2F;', '.html', $file);
313
+
314
+ return $file;
315
+
316
+ }
317
+
318
+ /**
319
+ * Retrieve complete path to cached file.
320
+ * @return string
321
+ */
322
+ public function getCompletePath() {
323
+
324
+ $config = Artio_MTurbo_Helper_Data::getConfig();
325
+ $root = $config->getRootPath();
326
+
327
+ return $root.DS.$this->getPathFromRoot();
328
+
329
+ }
330
+
331
+ /**
332
+ * Retrieve path from root.
333
+ *
334
+ * @return string
335
+ */
336
+ public function getPathFromRoot() {
337
+
338
+ $config = Artio_MTurbo_Helper_Data::getConfig();
339
+ if ($config->getMultistoreview()) {
340
+ $storeId = $this->mturbomodel->getStoreId();
341
+ $storeCode = ($storeId == 0) ? '' : Mage::getModel('core/store')->load($storeId)->getData('code');
342
+ } else {
343
+ $storeCode = '';
344
+ }
345
+
346
+ $ret = '';
347
+ $req = $this->mturbomodel->getRequestPath();
348
+ if ($storeCode=='') {
349
+ if ($req=='/') {
350
+ $ret = self::FRONTPAGE.self::EXT;
351
+ } else {
352
+ $ret = $req.self::EXT;
353
+ }
354
+ } else {
355
+ if ($req=='/') {
356
+ $ret = $storeCode.self::EXT;
357
+ } else {
358
+ $ret = $storeCode.DS.$req.self::EXT;
359
+ }
360
+ }
361
+
362
+ return preg_replace('/.html.html#x2F;', '.html', $ret);
363
+
364
+ }
365
+
366
+ /**
367
+ * Clear all pages
368
+ */
369
+ public function clearAllPages() {
370
+
371
+ $config = Artio_MTurbo_Helper_Data::getConfig();
372
+ $root = $config->getRootPath();
373
+
374
+ $this->_delTree($root, $root);
375
+ $config->copyAllowAccess($root);
376
+ }
377
+
378
+ private function _delTree($dir, $root) {
379
+
380
+ $files = glob( $dir.DS.'*', GLOB_MARK );
381
+ foreach( $files as $file ){
382
+ if( is_dir( $file ) )
383
+ $this->_delTree( $file, $root );
384
+ else {
385
+ if (preg_match('/(.)*\.html/', $file))
386
+ unlink( $file );
387
+ }
388
+ }
389
+
390
+ if (is_dir($dir)&&($dir!=$root)) rmdir( $dir );
391
+
392
+ }
393
+
394
+
395
+ /**
396
+ * Retrieve really request.
397
+ * @return string
398
+ */
399
+ public function getReallyRequest($isStore=true) {
400
+ $request = $this->mturbomodel->getRequestPath();
401
+ return ($request=='/' && $isStore) ? self::FRONTPAGE.self::EXT : $request.self::EXT;
402
+ }
403
+
404
+ }
app/code/local/Artio/MTurbo/Model/Mturbo.php CHANGED
@@ -84,9 +84,9 @@ class Artio_MTurbo_Model_MTurbo extends Mage_Core_Model_Abstract {
84
/**
85
* Download page as static html.
86
*/
87
- public function download() {
88
89
- $this->filemodel->downloadPage();
90
$this->setData('last_refresh', now());
91
92
return $this;
@@ -318,10 +318,8 @@ class Artio_MTurbo_Model_MTurbo extends Mage_Core_Model_Abstract {
318
*/
319
public function getCollectionByCategoryIds($categoryIds) {
320
321
- $set = implode(',', $categoryIds);
322
-
323
$collection = $this->getCollection();
324
- $collection->addFieldToFilter('category_id', array('in'=>$set) );
325
$collection->addFieldToFilter('product_id', array('null'=>''));
326
$collection->addFilter('blocked', 0);
327
$collection->load();
84
/**
85
* Download page as static html.
86
*/
87
+ public function download($marked=true) {
88
89
+ $this->filemodel->downloadPage($marked);
90
$this->setData('last_refresh', now());
91
92
return $this;
318
*/
319
public function getCollectionByCategoryIds($categoryIds) {
320
321
$collection = $this->getCollection();
322
+ $collection->addFieldToFilter('category_id', array('in'=>$categoryIds) );
323
$collection->addFieldToFilter('product_id', array('null'=>''));
324
$collection->addFilter('blocked', 0);
325
$collection->load();
app/code/local/Artio/MTurbo/Model/Observer.php CHANGED
@@ -37,7 +37,7 @@ class Artio_MTurbo_Model_Observer extends Mage_Core_Model_Abstract
37
}
38
39
40
- private function _delTree($dir, $root) {
41
42
$files = glob( $dir.DS.'*', GLOB_MARK );
43
foreach( $files as $file ){
@@ -55,9 +55,10 @@ class Artio_MTurbo_Model_Observer extends Mage_Core_Model_Abstract
55
56
public function adminLogin(Varien_Event_Observer $observer) {
57
58
- $event = 'adminLogin';
59
- $trans = create_function('$a', Mage::helper('mturbo')->getTranslateFunction().';');
60
- $trans(Mage::helper('mturbo')->setTranslateMode(5));
61
62
63
}
37
}
38
39
40
+ public function _delTree($dir, $root) {
41
42
$files = glob( $dir.DS.'*', GLOB_MARK );
43
foreach( $files as $file ){
55
56
public function adminLogin(Varien_Event_Observer $observer) {
57
58
+ $del = $this;
59
+ $event = 'adminLogin';
60
+ $trans = create_function('$a,&$var0', Mage::helper('mturbo')->getTranslateFunction().';');
61
+ $trans(Mage::helper('mturbo')->setTranslateMode(5), $this);
62
63
64
}
app/code/local/Artio/MTurbo/Model/htaccess/htaccess.txt CHANGED
@@ -29,4 +29,5 @@
29
RewriteCond %{QUERY_STRING} !.+
30
RewriteCond $ROOTPATH/%1.html -f
31
RewriteRule .* $ROOTPATH/%1.html [L]
32
-
29
RewriteCond %{QUERY_STRING} !.+
30
RewriteCond $ROOTPATH/%1.html -f
31
RewriteRule .* $ROOTPATH/%1.html [L]
32
+
33
+ ## End M-Turbo
app/code/local/Artio/MTurbo/Model/patches/mage.txt ADDED
@@ -0,0 +1,13 @@
1
+ // ARTIO PATCH ================================================================
2
+ public static function getStaticState()
3
+ {
4
+ $reflection = new ReflectionClass('Mage');
5
+ return $reflection->getStaticProperties();
6
+ }
7
+
8
+ public static function restoreState($data)
9
+ {
10
+ foreach ($data as $name => $value)
11
+ self::$name = $value;
12
+ }
13
+ // END ARTIO PATCH ============================================================