1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Piwik - free/libre analytics platform |
4
|
|
|
* |
5
|
|
|
* @link http://piwik.org |
6
|
|
|
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
namespace Piwik\Plugins\CorePluginsAdmin; |
10
|
|
|
|
11
|
|
|
use Exception; |
12
|
|
|
use Piwik\API\Request; |
13
|
|
|
use Piwik\Common; |
14
|
|
|
use Piwik\Config; |
15
|
|
|
use Piwik\Container\StaticContainer; |
16
|
|
|
use Piwik\Exception\MissingFilePermissionException; |
17
|
|
|
use Piwik\Filechecks; |
18
|
|
|
use Piwik\Filesystem; |
19
|
|
|
use Piwik\Nonce; |
20
|
|
|
use Piwik\Notification; |
21
|
|
|
use Piwik\Piwik; |
22
|
|
|
use Piwik\Plugin; |
23
|
|
|
use Piwik\Plugins\Marketplace\Marketplace; |
24
|
|
|
use Piwik\Plugins\Marketplace\Controller as MarketplaceController; |
25
|
|
|
use Piwik\Plugins\Marketplace\Plugins; |
26
|
|
|
use Piwik\SettingsPiwik; |
27
|
|
|
use Piwik\Translation\Translator; |
28
|
|
|
use Piwik\Url; |
29
|
|
|
use Piwik\Version; |
30
|
|
|
use Piwik\View; |
31
|
|
|
|
32
|
|
|
class Controller extends Plugin\ControllerAdmin |
33
|
|
|
{ |
34
|
|
|
const ACTIVATE_NONCE = 'CorePluginsAdmin.activatePlugin'; |
35
|
|
|
const DEACTIVATE_NONCE = 'CorePluginsAdmin.deactivatePlugin'; |
36
|
|
|
const UNINSTALL_NONCE = 'CorePluginsAdmin.uninstallPlugin'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var Translator |
40
|
|
|
*/ |
41
|
|
|
private $translator; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var Plugin\SettingsProvider |
45
|
|
|
*/ |
46
|
|
|
private $settingsProvider; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var PluginInstaller |
50
|
|
|
*/ |
51
|
|
|
private $pluginInstaller; |
52
|
|
|
/** |
53
|
|
|
* @var Plugin\Manager |
54
|
|
|
*/ |
55
|
|
|
private $pluginManager; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var Plugins |
59
|
|
|
*/ |
60
|
|
|
private $marketplacePlugins; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Controller constructor. |
64
|
|
|
* @param Translator $translator |
65
|
|
|
* @param Plugin\SettingsProvider $settingsProvider |
66
|
|
|
* @param PluginInstaller $pluginInstaller |
67
|
|
|
* @param Plugins $marketplacePlugins |
68
|
|
|
*/ |
69
|
|
|
public function __construct(Translator $translator, Plugin\SettingsProvider $settingsProvider, PluginInstaller $pluginInstaller, $marketplacePlugins = null) |
70
|
|
|
{ |
71
|
|
|
$this->translator = $translator; |
72
|
|
|
$this->settingsProvider = $settingsProvider; |
73
|
|
|
$this->pluginInstaller = $pluginInstaller; |
74
|
|
|
$this->pluginManager = Plugin\Manager::getInstance(); |
75
|
|
|
|
76
|
|
|
if (!empty($marketplacePlugins)) { |
77
|
|
|
$this->marketplacePlugins = $marketplacePlugins; |
78
|
|
|
} elseif (Marketplace::isMarketplaceEnabled()) { |
79
|
|
|
// we load it manually as marketplace might not be loaded |
80
|
|
|
$this->marketplacePlugins = StaticContainer::get('Piwik\Plugins\Marketplace\Plugins'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
parent::__construct(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function uploadPlugin() |
87
|
|
|
{ |
88
|
|
|
static::dieIfPluginsAdminIsDisabled(); |
|
|
|
|
89
|
|
|
Piwik::checkUserHasSuperUserAccess(); |
90
|
|
|
|
91
|
|
|
$nonce = Common::getRequestVar('nonce', null, 'string'); |
92
|
|
|
|
93
|
|
|
if (!Nonce::verifyNonce(MarketplaceController::INSTALL_NONCE, $nonce)) { |
94
|
|
|
throw new \Exception($this->translator->translate('General_ExceptionNonceMismatch')); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
Nonce::discardNonce(MarketplaceController::INSTALL_NONCE); |
98
|
|
|
|
99
|
|
|
if (empty($_FILES['pluginZip'])) { |
100
|
|
|
throw new \Exception('You did not specify a ZIP file.'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if (!empty($_FILES['pluginZip']['error'])) { |
104
|
|
|
throw new \Exception('Something went wrong during the plugin file upload. Please try again.'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$file = $_FILES['pluginZip']['tmp_name']; |
108
|
|
|
if (!file_exists($file)) { |
109
|
|
|
throw new \Exception('Something went wrong during the plugin file upload. Please try again.'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$view = $this->configureView('@CorePluginsAdmin/uploadPlugin'); |
113
|
|
|
|
114
|
|
|
$pluginMetadata = $this->pluginInstaller->installOrUpdatePluginFromFile($file); |
115
|
|
|
|
116
|
|
|
$view->nonce = Nonce::getNonce(static::ACTIVATE_NONCE); |
|
|
|
|
117
|
|
|
$view->plugin = array( |
|
|
|
|
118
|
|
|
'name' => $pluginMetadata->name, |
119
|
|
|
'version' => $pluginMetadata->version, |
120
|
|
|
'isTheme' => !empty($pluginMetadata->theme), |
121
|
|
|
'isActivated' => $this->pluginManager->isPluginActivated($pluginMetadata->name) |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
return $view->render(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @deprecated |
129
|
|
|
*/ |
130
|
|
|
public function browsePlugins() |
131
|
|
|
{ |
132
|
|
|
$this->redirectToIndex('Marketplace', 'overview'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @deprecated |
137
|
|
|
*/ |
138
|
|
|
public function browseThemes() |
139
|
|
|
{ |
140
|
|
|
$this->redirectToIndex('Marketplace', 'overview', null, null, null, array('show' => 'themes')); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
private function dieIfPluginsAdminIsDisabled() |
144
|
|
|
{ |
145
|
|
|
if (!CorePluginsAdmin::isPluginsAdminEnabled()) { |
146
|
|
|
throw new \Exception('Enabling, disabling and uninstalling plugins has been disabled by Piwik admins. |
147
|
|
|
Please contact your Piwik admins with your request so they can assist you.'); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
private function createPluginsOrThemesView($template, $themesOnly) |
152
|
|
|
{ |
153
|
|
|
Piwik::checkUserHasSuperUserAccess(); |
154
|
|
|
|
155
|
|
|
$view = $this->configureView('@CorePluginsAdmin/' . $template); |
156
|
|
|
|
157
|
|
|
$view->updateNonce = Nonce::getNonce(MarketplaceController::UPDATE_NONCE); |
|
|
|
|
158
|
|
|
$view->activateNonce = Nonce::getNonce(static::ACTIVATE_NONCE); |
|
|
|
|
159
|
|
|
$view->uninstallNonce = Nonce::getNonce(static::UNINSTALL_NONCE); |
|
|
|
|
160
|
|
|
$view->deactivateNonce = Nonce::getNonce(static::DEACTIVATE_NONCE); |
|
|
|
|
161
|
|
|
$view->pluginsInfo = $this->getPluginsInfo($themesOnly); |
|
|
|
|
162
|
|
|
|
163
|
|
|
$users = Request::processRequest('UsersManager.getUsers'); |
164
|
|
|
$view->otherUsersCount = count($users) - 1; |
|
|
|
|
165
|
|
|
$view->themeEnabled = $this->pluginManager->getThemeEnabled()->getPluginName(); |
|
|
|
|
166
|
|
|
|
167
|
|
|
$view->pluginNamesHavingSettings = array_keys($this->settingsProvider->getAllSystemSettings()); |
|
|
|
|
168
|
|
|
$view->isMarketplaceEnabled = Marketplace::isMarketplaceEnabled(); |
|
|
|
|
169
|
|
|
$view->isPluginsAdminEnabled = CorePluginsAdmin::isPluginsAdminEnabled(); |
|
|
|
|
170
|
|
|
|
171
|
|
|
$view->pluginsHavingUpdate = array(); |
|
|
|
|
172
|
|
|
$view->marketplacePluginNames = array(); |
|
|
|
|
173
|
|
|
|
174
|
|
|
if (Marketplace::isMarketplaceEnabled() && $this->marketplacePlugins) { |
175
|
|
|
try { |
176
|
|
|
$view->marketplacePluginNames = $this->marketplacePlugins->getAvailablePluginNames($themesOnly); |
|
|
|
|
177
|
|
|
$view->pluginsHavingUpdate = $this->marketplacePlugins->getPluginsHavingUpdate(); |
|
|
|
|
178
|
|
|
} catch(Exception $e) { |
179
|
|
|
// curl exec connection error (ie. server not connected to internet) |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
return $view; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function plugins() |
187
|
|
|
{ |
188
|
|
|
$view = $this->createPluginsOrThemesView('plugins', $themesOnly = false); |
189
|
|
|
return $view->render(); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function themes() |
193
|
|
|
{ |
194
|
|
|
$view = $this->createPluginsOrThemesView('themes', $themesOnly = true); |
195
|
|
|
return $view->render(); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
View Code Duplication |
protected function configureView($template) |
|
|
|
|
199
|
|
|
{ |
200
|
|
|
Piwik::checkUserIsNotAnonymous(); |
201
|
|
|
|
202
|
|
|
$view = new View($template); |
203
|
|
|
$this->setBasicVariablesView($view); |
204
|
|
|
|
205
|
|
|
// If user can manage plugins+themes, display a warning if config not writable |
206
|
|
|
if (CorePluginsAdmin::isPluginsAdminEnabled()) { |
207
|
|
|
$this->displayWarningIfConfigFileNotWritable(); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
$view->errorMessage = ''; |
|
|
|
|
211
|
|
|
|
212
|
|
|
return $view; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
protected function getPluginsInfo($themesOnly = false) |
216
|
|
|
{ |
217
|
|
|
$plugins = $this->pluginManager->loadAllPluginsAndGetTheirInfo(); |
218
|
|
|
|
219
|
|
|
foreach ($plugins as $pluginName => &$plugin) { |
220
|
|
|
|
221
|
|
|
$plugin['isCorePlugin'] = $this->pluginManager->isPluginBundledWithCore($pluginName); |
222
|
|
|
|
223
|
|
|
if (!empty($plugin['info']['description'])) { |
224
|
|
|
$plugin['info']['description'] = $this->translator->translate($plugin['info']['description']); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
if (!isset($plugin['info'])) { |
228
|
|
|
|
229
|
|
|
$suffix = $this->translator->translate('CorePluginsAdmin_PluginNotWorkingAlternative'); |
230
|
|
|
// If the plugin has been renamed, we do not show message to ask user to update plugin |
231
|
|
|
list($pluginNameRenamed, $methodName) = Request::getRenamedModuleAndAction($pluginName, 'index'); |
|
|
|
|
232
|
|
|
if ($pluginName != $pluginNameRenamed) { |
233
|
|
|
$suffix = "You may uninstall the plugin or manually delete the files in piwik/plugins/$pluginName/"; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
$description = '<strong>' |
237
|
|
|
. $this->translator->translate('CorePluginsAdmin_PluginNotCompatibleWith', array($pluginName, self::getPiwikVersion())) |
238
|
|
|
. '</strong><br/>' |
239
|
|
|
. $suffix; |
240
|
|
|
$plugin['info'] = array( |
241
|
|
|
'description' => $description, |
242
|
|
|
'version' => $this->translator->translate('General_Unknown'), |
243
|
|
|
'theme' => false, |
244
|
|
|
); |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
$pluginsFiltered = $this->keepPluginsOrThemes($themesOnly, $plugins); |
249
|
|
|
return $pluginsFiltered; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
protected function keepPluginsOrThemes($themesOnly, $plugins) |
253
|
|
|
{ |
254
|
|
|
$pluginsFiltered = array(); |
255
|
|
|
foreach ($plugins as $name => $thisPlugin) { |
256
|
|
|
|
257
|
|
|
$isTheme = false; |
258
|
|
|
if (!empty($thisPlugin['info']['theme'])) { |
259
|
|
|
$isTheme = (bool)$thisPlugin['info']['theme']; |
260
|
|
|
} |
261
|
|
|
if (($themesOnly && $isTheme) |
262
|
|
|
|| (!$themesOnly && !$isTheme) |
263
|
|
|
) { |
264
|
|
|
$pluginsFiltered[$name] = $thisPlugin; |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
return $pluginsFiltered; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public function safemode($lastError = array()) |
271
|
|
|
{ |
272
|
|
|
ob_clean(); |
273
|
|
|
|
274
|
|
|
$this->tryToRepairPiwik(); |
275
|
|
|
|
276
|
|
|
if (empty($lastError)) { |
277
|
|
|
$lastError = array( |
278
|
|
|
'message' => Common::getRequestVar('error_message', null, 'string'), |
279
|
|
|
'file' => Common::getRequestVar('error_file', null, 'string'), |
280
|
|
|
'line' => Common::getRequestVar('error_line', null, 'integer') |
281
|
|
|
); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
$outputFormat = Common::getRequestVar('format', 'html', 'string'); |
285
|
|
|
$outputFormat = strtolower($outputFormat); |
286
|
|
|
|
287
|
|
|
if (!empty($outputFormat) && 'html' !== $outputFormat) { |
288
|
|
|
|
289
|
|
|
$errorMessage = $lastError['message']; |
290
|
|
|
|
291
|
|
|
if (Piwik::isUserIsAnonymous()) { |
292
|
|
|
$errorMessage = 'A fatal error occurred.'; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
$response = new \Piwik\API\ResponseBuilder($outputFormat); |
296
|
|
|
$message = $response->getResponseException(new Exception($errorMessage)); |
297
|
|
|
|
298
|
|
|
return $message; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
if (Common::isPhpCliMode()) { |
302
|
|
|
throw new Exception("Error: " . var_export($lastError, true)); |
303
|
|
|
} |
304
|
|
|
$view = new View('@CorePluginsAdmin/safemode'); |
305
|
|
|
$view->lastError = $lastError; |
|
|
|
|
306
|
|
|
$view->isAllowedToTroubleshootAsSuperUser = $this->isAllowedToTroubleshootAsSuperUser(); |
|
|
|
|
307
|
|
|
$view->isSuperUser = Piwik::hasUserSuperUserAccess(); |
|
|
|
|
308
|
|
|
$view->isAnonymousUser = Piwik::isUserIsAnonymous(); |
|
|
|
|
309
|
|
|
$view->plugins = $this->pluginManager->loadAllPluginsAndGetTheirInfo(); |
|
|
|
|
310
|
|
|
$view->deactivateNonce = Nonce::getNonce(static::DEACTIVATE_NONCE); |
|
|
|
|
311
|
|
|
$view->deactivateIAmSuperUserSalt = Common::getRequestVar('i_am_super_user', '', 'string'); |
|
|
|
|
312
|
|
|
$view->uninstallNonce = Nonce::getNonce(static::UNINSTALL_NONCE); |
|
|
|
|
313
|
|
|
$view->emailSuperUser = implode(',', Piwik::getAllSuperUserAccessEmailAddresses()); |
|
|
|
|
314
|
|
|
$view->piwikVersion = Version::VERSION; |
|
|
|
|
315
|
|
|
$view->showVersion = !Common::getRequestVar('tests_hide_piwik_version', 0); |
|
|
|
|
316
|
|
|
$view->pluginCausesIssue = ''; |
|
|
|
|
317
|
|
|
|
318
|
|
|
// When the CSS merger in StylesheetUIAssetMerger throws an exception, safe mode is displayed. |
319
|
|
|
// This flag prevents an infinite loop where safemode would try to re-generate the cache buster which requires CSS merger.. |
320
|
|
|
$view->disableCacheBuster(); |
321
|
|
|
|
322
|
|
|
if (!empty($lastError['file'])) { |
323
|
|
|
preg_match('/piwik\/plugins\/(.*)\//', $lastError['file'], $matches); |
324
|
|
|
|
325
|
|
|
if (!empty($matches[1])) { |
326
|
|
|
$view->pluginCausesIssue = $matches[1]; |
|
|
|
|
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
return $view->render(); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
public function activate($redirectAfter = true) |
334
|
|
|
{ |
335
|
|
|
$pluginName = $this->initPluginModification(static::ACTIVATE_NONCE); |
336
|
|
|
$this->dieIfPluginsAdminIsDisabled(); |
337
|
|
|
|
338
|
|
|
$this->pluginManager->activatePlugin($pluginName); |
339
|
|
|
|
340
|
|
|
if ($redirectAfter) { |
341
|
|
|
$message = $this->translator->translate('CorePluginsAdmin_SuccessfullyActicated', array($pluginName)); |
342
|
|
|
|
343
|
|
|
if ($this->settingsProvider->getSystemSettings($pluginName)) { |
344
|
|
|
$target = sprintf('<a href="index.php%s#%s">', |
345
|
|
|
Url::getCurrentQueryStringWithParametersModified(array('module' => 'CoreAdminHome', 'action' => 'generalSettings')), |
346
|
|
|
$pluginName); |
347
|
|
|
$message .= ' ' . $this->translator->translate('CorePluginsAdmin_ChangeSettingsPossible', array($target, '</a>')); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
$notification = new Notification($message); |
351
|
|
|
$notification->raw = true; |
352
|
|
|
$notification->title = $this->translator->translate('General_WellDone'); |
353
|
|
|
$notification->context = Notification::CONTEXT_SUCCESS; |
354
|
|
|
Notification\Manager::notify('CorePluginsAdmin_PluginActivated', $notification); |
355
|
|
|
|
356
|
|
|
$redirectTo = Common::getRequestVar('redirectTo', '', 'string'); |
357
|
|
|
if (!empty($redirectTo) && $redirectTo === 'marketplace') { |
358
|
|
|
$this->redirectToIndex('Marketplace', 'overview'); |
359
|
|
|
} elseif (!empty($redirectTo) && $redirectTo === 'referrer') { |
360
|
|
|
$this->redirectAfterModification($redirectAfter); |
361
|
|
|
} else { |
362
|
|
|
$plugin = $this->pluginManager->loadPlugin($pluginName); |
363
|
|
|
|
364
|
|
|
$actionToRedirect = 'plugins'; |
365
|
|
|
if ($plugin->isTheme()) { |
366
|
|
|
$actionToRedirect = 'themes'; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
$this->redirectToIndex('CorePluginsAdmin', $actionToRedirect); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
} |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
public function deactivate($redirectAfter = true) |
376
|
|
|
{ |
377
|
|
|
if($this->isAllowedToTroubleshootAsSuperUser()) { |
378
|
|
|
Piwik::doAsSuperUser(function() use ($redirectAfter) { |
379
|
|
|
$this->doDeactivatePlugin($redirectAfter); |
380
|
|
|
}); |
381
|
|
|
} else { |
382
|
|
|
$this->doDeactivatePlugin($redirectAfter); |
383
|
|
|
} |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
public function uninstall($redirectAfter = true) |
387
|
|
|
{ |
388
|
|
|
$pluginName = $this->initPluginModification(static::UNINSTALL_NONCE); |
389
|
|
|
$this->dieIfPluginsAdminIsDisabled(); |
390
|
|
|
|
391
|
|
|
$uninstalled = $this->pluginManager->uninstallPlugin($pluginName); |
392
|
|
|
|
393
|
|
|
if (!$uninstalled) { |
394
|
|
|
$path = Filesystem::getPathToPiwikRoot() . '/plugins/' . $pluginName . '/'; |
395
|
|
|
$messagePermissions = Filechecks::getErrorMessageMissingPermissions($path); |
396
|
|
|
|
397
|
|
|
$messageIntro = $this->translator->translate("Warning: \"%s\" could not be uninstalled. Piwik did not have enough permission to delete the files in $path. ", |
398
|
|
|
$pluginName); |
399
|
|
|
$exitMessage = $messageIntro . "<br/><br/>" . $messagePermissions; |
400
|
|
|
$exitMessage .= "<br> Or manually delete this directory (using FTP or SSH access)"; |
401
|
|
|
|
402
|
|
|
$ex = new MissingFilePermissionException($exitMessage); |
403
|
|
|
$ex->setIsHtmlMessage(); |
404
|
|
|
|
405
|
|
|
throw $ex; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
$this->redirectAfterModification($redirectAfter); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
public function showLicense() |
412
|
|
|
{ |
413
|
|
|
$pluginName = Common::getRequestVar('pluginName', null, 'string'); |
414
|
|
|
|
415
|
|
|
$metadata = new Plugin\MetadataLoader($pluginName); |
416
|
|
|
$license_file = $metadata->getPathToLicenseFile(); |
417
|
|
|
|
418
|
|
|
$license = 'No license file found for this plugin.'; |
419
|
|
|
if(!empty($license_file)) { |
420
|
|
|
$license = file_get_contents($license_file); |
421
|
|
|
$license = nl2br($license); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
$view = $this->configureView('@CorePluginsAdmin/license'); |
425
|
|
|
$view->pluginName = $pluginName; |
|
|
|
|
426
|
|
|
$view->license = $license; |
|
|
|
|
427
|
|
|
return $view->render(); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
View Code Duplication |
protected function initPluginModification($nonceName) |
|
|
|
|
431
|
|
|
{ |
432
|
|
|
Piwik::checkUserHasSuperUserAccess(); |
433
|
|
|
|
434
|
|
|
$nonce = Common::getRequestVar('nonce', null, 'string'); |
435
|
|
|
|
436
|
|
|
if (!Nonce::verifyNonce($nonceName, $nonce)) { |
437
|
|
|
throw new \Exception($this->translator->translate('General_ExceptionNonceMismatch')); |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
Nonce::discardNonce($nonceName); |
441
|
|
|
|
442
|
|
|
$pluginName = Common::getRequestVar('pluginName', null, 'string'); |
443
|
|
|
|
444
|
|
|
if (!$this->pluginManager->isValidPluginName($pluginName)) { |
445
|
|
|
throw new Exception('Invalid plugin name'); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
return $pluginName; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
protected function redirectAfterModification($redirectAfter) |
452
|
|
|
{ |
453
|
|
|
if ($redirectAfter) { |
454
|
|
|
Url::redirectToReferrer(); |
455
|
|
|
} |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
private function tryToRepairPiwik() |
459
|
|
|
{ |
460
|
|
|
// in case any opcaches etc were not cleared after an update for instance. Might prevent from getting the |
461
|
|
|
// error again |
462
|
|
|
try { |
463
|
|
|
Filesystem::deleteAllCacheOnUpdate(); |
464
|
|
|
} catch (Exception $e) {} |
|
|
|
|
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* Let Super User troubleshoot in safe mode, even when Login is broken, with this special trick |
469
|
|
|
* |
470
|
|
|
* @return bool |
471
|
|
|
* @throws Exception |
472
|
|
|
*/ |
473
|
|
|
protected function isAllowedToTroubleshootAsSuperUser() |
474
|
|
|
{ |
475
|
|
|
$isAllowedToTroubleshootAsSuperUser = false; |
476
|
|
|
$salt = SettingsPiwik::getSalt(); |
477
|
|
View Code Duplication |
if (!empty($salt)) { |
478
|
|
|
$saltFromRequest = Common::getRequestVar('i_am_super_user', '', 'string'); |
479
|
|
|
$isAllowedToTroubleshootAsSuperUser = ($salt == $saltFromRequest); |
480
|
|
|
} |
481
|
|
|
return $isAllowedToTroubleshootAsSuperUser; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* @param $redirectAfter |
486
|
|
|
* @throws Exception |
487
|
|
|
*/ |
488
|
|
|
protected function doDeactivatePlugin($redirectAfter) |
489
|
|
|
{ |
490
|
|
|
$pluginName = $this->initPluginModification(static::DEACTIVATE_NONCE); |
491
|
|
|
$this->dieIfPluginsAdminIsDisabled(); |
492
|
|
|
|
493
|
|
|
$this->pluginManager->deactivatePlugin($pluginName); |
494
|
|
|
$this->redirectAfterModification($redirectAfter); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
} |
498
|
|
|
|
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: