-
Notifications
You must be signed in to change notification settings - Fork 10
/
API.php
119 lines (94 loc) · 2.8 KB
/
API.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
<?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 MatomoCustomOptOut
*/
namespace Piwik\Plugins\MatomoCustomOptOut;
use Piwik\Common;
use Piwik\Db;
use Piwik\Piwik;
/**
* API for plugin CustomOptOut
*
* @package CustomOptOut
* @method static \Piwik\Plugins\CustomOptOut\API getInstance()
*/
class API extends \Piwik\Plugin\API
{
/**
* Save the custom css and custom css file
*
* @param $siteId
* @param null $customCss
* @param null $customFile
*/
public function saveSite($siteId, $customCss = null, $customFile = null, $customJs = null, $customJsFile = null)
{
Piwik::checkUserHasAdminAccess($siteId);
$params = array($customCss, $customFile);
$query = "UPDATE ".Common::prefixTable("site") . " SET custom_css = ?, custom_css_file = ?";
// If js is activate, update its too.
$settings = new SystemSettings();
if ($settings->enableJavascriptInjection->getValue()) {
$query .= ", custom_js = ?, custom_js_file = ?";
$params[] = $customJs;
$params[] = $customJsFile;
}
$query .= " WHERE idsite = ?";
$params[] = $siteId;
Db::query($query, $params);
}
/**
* Returns the website information : id, custom css, custom css file
*
* @throws Exception If the site ID doesn't exist or the user doesn't have access to it
* @param int $idSite
* @return array
*/
public function getSiteDataId($idSite)
{
$query = "SELECT idsite, custom_css, custom_css_file";
$settings = new SystemSettings();
if ($settings->enableJavascriptInjection->getValue()) {
$query .= ", custom_js, custom_js_file";
} else {
$query .= ", null as custom_js, null as custom_js_file";
}
$query .= " FROM ".Common::prefixTable("site") . " WHERE idsite = ?";
$site = Db::get()->fetchRow($query, array($idSite));
return $site;
}
/**
* Returns true if the css editor is enabled
*
* @return bool
*/
public function isCssEditorEnabled()
{
$settings = new SystemSettings('CustomOptOut');
$value = (bool)$settings->enableEditor->getValue();
if ($value === false) {
return false;
}
return true;
}
/**
* Return the current css editor theme
*
* @return string
*/
public function getEditorTheme()
{
$settings = new SystemSettings('CustomOptOut');
$value = $settings->editorTheme->getValue();
if ($value == 'default') {
return 'default';
}
return 'blackboard';
}
}