-
Notifications
You must be signed in to change notification settings - Fork 10
/
Controller.php
141 lines (110 loc) · 4.22 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
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
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package CustomOptOut
*/
namespace Piwik\Plugins\MatomoCustomOptOut;
use Piwik\Common;
use Piwik\Piwik;
use Piwik\Plugin\ControllerAdmin;
use Piwik\Plugins\LanguagesManager\LanguagesManager;
use Piwik\Plugins\SitesManager\API as APISiteManager;
use Piwik\Site;
use Piwik\UrlHelper;
use Piwik\View;
/**
*
* @package MatomoCustomOptOut
*/
class Controller extends ControllerAdmin
{
/**
* Main Plugin Index
*
* @return mixed
* @throws \Exception
*/
public function index()
{
Piwik::checkUserHasSomeAdminAccess();
if (isset($_SERVER['REQUEST_METHOD']) && 'POST' == $_SERVER['REQUEST_METHOD']) {
// Cannot use Common::getRequestVar, because the function remove whitespaces and newline breaks
$postedSiteData = isset($_POST['site']) ? $_POST['site'] : null;
if (is_array($postedSiteData) && count($postedSiteData) > 0) {
foreach ($postedSiteData as $id => $site) {
if (!isset($site['css'], $site['file']) && !isset($site['js'], $site['js_file'])) {
continue;
}
// Check URL for CSS file
if (empty($site['file']) || !UrlHelper::isLookLikeUrl($site['file'])) {
$site['file'] = null;
}
// Check URL for JS file
if (empty($site['js_file']) || !UrlHelper::isLookLikeUrl($site['js_file'])) {
$site['js_file'] = null;
}
if (empty($site['css'])) {
$site['css'] = null;
}
if (empty($site['js'])) {
$site['js'] = null;
}
API::getInstance()->saveSite($id, $site['css'], $site['file'], $site['js'], $site['js_file']);
}
// Redirect to, clear POST vars
$this->redirectToIndex('MatomoCustomOptOut', 'index');
return;
}
}
$view = new View('@MatomoCustomOptOut/index.twig');
Site::clearCache();
if (Piwik::hasUserSuperUserAccess()) {
$sitesRaw = APISiteManager::getInstance()->getAllSites();
} else {
$sitesRaw = APISiteManager::getInstance()->getSitesWithAdminAccess();
}
// Gets sites after Site.setSite hook was called
$sites = array_values(Site::getSites());
if (count($sites) != count($sitesRaw)) {
throw new \Exception("One or more website are missing or invalid.");
}
foreach ($sites as &$site) {
$site['alias_urls'] = APISiteManager::getInstance()->getSiteUrlsFromId($site['idsite']);
}
$settings = new SystemSettings();
$view->adminSites = $sites;
$view->adminSitesCount = count($sites);
$view->language = LanguagesManager::getLanguageCodeForCurrentUser();
$view->isEditorEnabled = API::getInstance()->isCssEditorEnabled();
$view->editorTheme = API::getInstance()->getEditorTheme();
$view->showOldLinks = false;
$view->enableJs = $settings->enableJavascriptInjection->getValue();
$this->setBasicVariablesView($view);
return $view->render();
}
/**
* Shows the "Track Visits" checkbox.
* @deprecated This action is introduced only to keep BC with older piwik versions <= 2.15.0
* The user will be redirected to CoreAdminHome:optOut
*/
public function optOut()
{
// See Issue #33
$siteId = Common::getRequestVar('idsite', 0, 'integer');
// Is still available for BC
if (!$siteId) {
$siteId = Common::getRequestVar('idSite', 0, 'integer');
}
// Redirect to default OptOut Method if OptOut Manager available
$params = $_GET;
unset($params['action']);
unset($params['module']);
unset($params['idSite']);
$this->redirectToIndex('CoreAdminHome', 'optOut', $siteId, null, null, $params);
}
}