-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemSettings.php
More file actions
65 lines (54 loc) · 1.94 KB
/
SystemSettings.php
File metadata and controls
65 lines (54 loc) · 1.94 KB
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
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
declare(strict_types=1);
namespace Piwik\Plugins\McpServer;
use Piwik\Piwik;
use Piwik\Settings\FieldConfig;
use Piwik\Settings\Setting;
use Piwik\SettingsPiwik;
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
{
/** @var Setting */
public $enableMcp;
protected function init(): void
{
$this->enableMcp = $this->makeSetting(
'enable_mcp',
false,
FieldConfig::TYPE_BOOL,
function (FieldConfig $field) {
$field->title = Piwik::translate('McpServer_EnableMcpTitle');
$field->inlineHelp = implode('<br><br>', [
Piwik::translate('McpServer_EnableMcpHelpPurpose'),
Piwik::translate('McpServer_EnableMcpHelpDataScope'),
Piwik::translate('McpServer_EnableMcpHelpPolicy'),
Piwik::translate('McpServer_EnableMcpHelpUrl', ['<code>', $this->getMcpEndpointUrl(), '</code>']),
Piwik::translate(
'McpServer_EnableMcpHelpConnectGuide',
['<a href="' . $this->getConnectGuideUrl() . '">', '</a>']
),
]);
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
}
);
}
public function isMcpEnabled(): bool
{
return (bool) $this->enableMcp->getValue();
}
private function getMcpEndpointUrl(): string
{
$baseUrl = (string) SettingsPiwik::getPiwikUrl();
return rtrim($baseUrl, '/') . '/index.php?module=API&method=McpServer.mcp&format=mcp';
}
private function getConnectGuideUrl(): string
{
$baseUrl = (string) SettingsPiwik::getPiwikUrl();
return rtrim($baseUrl, '/') . '/index.php?module=McpServer&action=connect';
}
}