forked from SomeBdyElse/cwmobileredirect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.ext_update.php
279 lines (240 loc) · 10.2 KB
/
class.ext_update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
use TYPO3\CMS\Backend\Utility\IconUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/***************************************************************
* Copyright notice
*
* (c) 2011-2014 Carsten Windler ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
// $test = \CarstenWindler\Cwmobileredirect\Main::getInstance();
class ext_update
{
/**
* The extension key
* @var string
*/
protected $extKey = 'cwmobileredirect';
/**
* Major Typo3 Version
* @var integer
*/
protected $majorVersion;
/**
* Holds the current localconf
* @var array
*/
protected $extConf;
/**
* Holds the current ext_conf_template
* @var array
*/
protected $extConfTemplateArr;
/**
* The constructor
* @return ext_update
*/
public function __construct()
{
$typo3Version = explode('.', TYPO3_version);
$this->majorVersion = intval($typo3Version[0]);
$this->extConf = $this->getExtConf();
$this->extConfTemplateArr = $this->getExtConfTemplateArr();
}
/**
* Main function, returning the HTML content of the module
*
* @return string
*/
public function main()
{
if (!$this->checkConfigs()) {
$out = 'Either your local configuration or the ext_conf_template.txt of this extension is empty or broken!';
return $out;
}
$differences = $this->getExtConfDifferences();
if (count($differences) > 0) {
if (GeneralUtility::_GP('do_update')) {
if ($this->updateExtConf(GeneralUtility::_GP('func'))) {
$out = 'Your local configuration has been updated. Thanks for chosing cwmobileredirect!<br>';
$out .= '<button onclick="location.href=\''
. GeneralUtility::linkThisScript(array('do_update' => '', 'func' => ''))
. '\'" value="" name="do_update" type="submit"><img style="vertical-align:bottom;" '
. IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/refresh_n.gif', 'width="18" height="16"')
. '>Check for more updates</button><br><br><br>';
} else {
$out = 'Your local configuration has been NOT updated.' .
' This most likely means that your cwmobileredirect installation is screwed. ' .
'You should consider removing and installing it from scratch.';
}
} else {
$out = 'Your local configuration can be updated:<br><br>';
if (isset($differences['redirect_exceptions'])) {
$out .= $differences['redirect_exceptions'];
$out .= '<button onclick="location.href=\'' .
GeneralUtility::linkThisScript(array(
'do_update' => 'update',
'func' => 'redirect_exceptions'
))
. '\'" value="update" name="do_update" type="submit"><img style="vertical-align:bottom;" '
. IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/refresh_n.gif', 'width="18" height="16"')
. '>Update redirect_exceptions</button><br><br><br>';
}
if (isset($differences['regexp1'])) {
$out .= $differences['regexp1'];
$out .= 'This will OVERWRITE your existing mobile browser detection settings (First RegExp) ' .
'in your local ' .
'configuration with the current extension default settings.<br><br>';
$out .= '<button onclick="location.href=\''
. GeneralUtility::linkThisScript(array('do_update' => 'update', 'func' => 'regexp1'))
. '\'" value="update" name="do_update" type="submit"><img style="vertical-align:bottom;" '
. IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/refresh_n.gif', 'width="18" height="16"')
. '>Update regexp1</button><br><br><br>';
}
if (isset($differences['regexp2'])) {
$out .= $differences['regexp2'];
$out .= 'This will OVERWRITE your existing mobile browser detection settings (Second RegExp) ' .
'in your local ' .
'configuration with the current extension default settings.<br><br>';
$out .= '<button onclick="location.href=\''
. GeneralUtility::linkThisScript(array('do_update' => 'update', 'func' => 'regexp2'))
. '\'" value="update" name="do_update" type="submit"><img style="vertical-align:bottom;" '
. IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/refresh_n.gif', 'width="18" height="16"')
. '>Update regexp1</button><br><br><br>';
}
}
} else {
$out = 'Your localconf does not need to be updated!';
}
return $out;
}
/**
* Checks how many rows are found and returns true if there are any
* (this function is called from the extension manager)
*
* @param string $what: what should be updated
* @return boolean
*/
public function access($what = 'all')
{
return true;
}
/**
* Checks whether all configs are ok
*
* @return boolean
*/
protected function checkConfigs()
{
if (!is_array($this->extConf) || count($this->extConf) == 0) {
return false;
}
if (!is_array($this->extConfTemplateArr) || count($this->extConfTemplateArr) == 0) {
return false;
}
return true;
}
/**
* Returns the content of ext_conf_template.txt as handy array
* @return boolean|array
*/
protected function getExtConfTemplateArr()
{
$extConfTemplateArr = array();
// Fetch the current reg exps from the ext_conf_template.txt
if ($this->majorVersion >= 6) {
// Typo3 >= 6.0
$objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$configurationUtility = $objectManager->get(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class);
$extConfTemplateArr =
$configurationUtility->getParsedExtConfTemplate($this->extKey);
}
return $extConfTemplateArr;
}
/**
* Checks whether certain localconf whether
* @return string|boolean
*/
protected function getExtConfDifferences()
{
$retArray = array();
if ($this->extConf['regexp1'] != $this->extConfTemplateArr['regexp1']['value']) {
$retArray['regexp1'] =
'<p><strong>regexp1 field differs from default!</strong><br><strong>local:</strong> ' .
$this->extConf['regexp1'] .
'<br><strong>default:</strong> ' . $this->extConfTemplateArr['regexp1']['value'] . '</p>';
}
if ($this->extConf['regexp2'] != $this->extConfTemplateArr['regexp2']['value']) {
$retArray['regexp2'] =
'<p><strong>regexp2 field differs from default!</strong><br><strong>local:</strong> ' .
$this->extConf['regexp2'] .
'<br><strong>default:</strong> ' . $this->extConfTemplateArr['regexp2']['value'] . '</p>';
}
if (empty($this->extConf['redirect_exceptions'])) {
$retArray['redirect_exceptions'] =
'<p><strong>redirect_exceptions field is empty!</strong>' .
'<br><strong>default:</strong> ' .
$this->extConfTemplateArr['redirect_exceptions']['value'] . '</p>';
}
return $retArray;
}
/**
* Upate the extConf
*
* @return boolean
*/
protected function updateExtConf($func)
{
// Get the value from the ext_conf_template and store it in the local conf
$this->extConf[$func] = $this->extConfTemplateArr[$func]['value'];
// Rewrite local configuration according to Typo3 version
if ($this->majorVersion >= 6) {
// Typo3 >= 6.0
$configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager'
);
$configurationManager->setLocalConfigurationValueByPath(
'EXT/extConf/' . $this->extKey,
serialize($this->extConf)
);
ExtensionManagementUtility::removeCacheFiles();
}
return true;
}
/**
* Get the extension configuration
*
* @return array
*/
protected function getExtConf()
{
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$this->extKey]);
if (!$extConf) {
$extConf = array();
}
return $extConf;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cwmobileredirect/class.ext_update.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cwmobileredirect/class.ext_update.php']);
}