This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAPI.php
59 lines (53 loc) · 1.45 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
<?php
/**
* Part of Piwik Login Shibboleth Plug-in.
*/
namespace Piwik\Plugins\LoginShibboleth;
use Exception;
use Piwik\Piwik;
use RuntimeException;
/**
* API functionality for settings.
*
* API is used by the Setting to write or read settings from the configuration file.
* If this plug-in should have any other API related functions, they should be added here.
* The API is only available to the user with SuperUser access.
*
*/
class API extends \Piwik\Plugin\API
{
/**
* Constructor.
*/
public function __construct()
{
}
/**
* Saves the Login Shibboleth settings in the config file automatically.
*
* @param string $data JSON encoded config array.
*
* @return array
*
* @throws Exception if user does not have super access, if this is not a POST method or
* if JSON is not supplied.
*/
public function saveShibbolethConfig($data)
{
$this->checkHttpMethodIsPost();
Piwik::checkUserHasSuperUserAccess();
Config::savePluginOptions($data);
return array('result' => 'success', 'message' => Piwik::translate('General_YourChangesHaveBeenSaved'));
}
/**
* Check is the method sending the data is post.
*
* @throws \Exception
*/
private function checkHttpMethodIsPost()
{
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
throw new RuntimeException('Invalid HTTP method.');
}
}
}