-
Notifications
You must be signed in to change notification settings - Fork 2
/
Controller.php
62 lines (50 loc) · 2.02 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
<?php
/**
* InnoCraft - the company of the makers of Piwik Analytics, the free/libre analytics platform
*
* @link https://www.innocraft.com
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\JsTrackerCustom;
use Piwik\Common;
use Piwik\Nonce;
use Piwik\Notification;
use Piwik\Piwik;
use Piwik\Plugin\ControllerAdmin;
use Piwik\Plugins\CustomJsTracker\CustomJsTracker;
use Piwik\View;
/**
*
*/
class Controller extends ControllerAdmin
{
public function index()
{
Piwik::checkUserHasSuperUserAccess();
$customJsFile = __DIR__ . '/tracker.js';
if (is_writable(__DIR__) && !file_exists($customJsFile)) {
file_put_contents($customJsFile, '');
}
if (!is_writable(__DIR__) || !is_writable($customJsFile)) {
$notification = new Notification(Piwik::translate('JsTrackerCustom_DirectoryOrFileNotWritable', array(__DIR__, $customJsFile)));
$notification->context = Notification::CONTEXT_ERROR;
Notification\Manager::notify('JsTrackerCustom_FileNotWritable', $notification);
} elseif (
($nonce = Common::getRequestVar('customJsNonce', '', 'string')) &&
($customJs = Common::getRequestVar('customJs', '', 'string'))
) {
Nonce::checkNonce('JsTrackerCustom.save', $nonce);
file_put_contents($customJsFile, Common::unsanitizeInputValue($customJs));
$instance = new CustomJsTracker();
$instance->updateTracker();
$notification = new Notification(Piwik::translate('General_YourChangesHaveBeenSaved'));
$notification->context = Notification::CONTEXT_SUCCESS;
Notification\Manager::notify('JsTrackerCustom_Saved', $notification);
}
$view = new View('@JsTrackerCustom/index');
$this->setBasicVariablesView($view);
$view->customJs = file_get_contents($customJsFile);
$view->customJsNonce = Nonce::getNonce('JsTrackerCustom.save');
return $view->render();
}
}