-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathController.php
79 lines (64 loc) · 2.26 KB
/
Controller.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
<?php
/**
* AOM - Piwik Advanced Online Marketing Plugin
*
* @author Daniel Stonies <[email protected]>
*/
namespace Piwik\Plugins\AOM;
use Piwik\Common;
use Piwik\Piwik;
class Controller extends \Piwik\Plugin\ControllerAdmin
{
/**
* @return string
*/
public function settings()
{
Piwik::checkUserHasSomeAdminAccess();
$settings = new SystemSettings();
$viewVariables = [
'accounts' => $settings->getAccounts(),
];
foreach (AOM::getPlatforms() as $platform) {
$viewVariables[lcfirst($platform) . 'IsActive'] =
$settings->{'platform' . $platform . 'IsActive'}->getValue();
}
return $this->renderTemplate('settings', $viewVariables);
}
/**
* This method routes method calls to the advertising platform's individual controllers.
*
* @throws \Exception
*/
public function platformAction()
{
Piwik::checkUserHasSomeAdminAccess();
// Platform supported?
$platform = Common::getRequestVar('platform', false);
if (!in_array($platform, AOM::getPlatforms())) {
throw new \Exception('Platform "' . $platform . '" is not supported.');
}
$className = 'Piwik\\Plugins\\AOM\\Platforms\\' . $platform . '\\Controller';
$controller = new $className($platform);
// Does method exist?
$method = Common::getRequestVar('method', false);
if (!method_exists($controller, $method)) {
throw new \Exception('Method "' . $method . '" does not exist in platform "' . $platform . '".');
}
// Params must be JSON
$params = $platform = Common::getRequestVar('params', false);
if (false != $params) {
$params = str_replace('"', '"', $params);
$params = @json_decode($params, true);
if (json_last_error() != JSON_ERROR_NONE || !is_array($params)) {
throw new \Exception('Invalid JSON passed to Controller->platformAction().');
}
}
// Call controller method
if (is_array($params)) {
return call_user_func_array([$controller, $method], $params);
} else {
return $controller->{$method}();
}
}
}