PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Plugin / API.php
matomo / app / core / Plugin Last commit date
ConsoleCommand 1 month ago Dimension 1 month ago API.php 6 months ago AggregatedMetric.php 2 years ago ArchivedMetric.php 1 year ago Archiver.php 1 month ago Categories.php 2 years ago ComponentFactory.php 3 months ago ComputedMetric.php 1 year ago ConsoleCommand.php 1 month ago Controller.php 1 month ago ControllerAdmin.php 2 weeks ago Dependency.php 1 month ago LogTablesProvider.php 2 years ago Manager.php 1 month ago Menu.php 1 month ago MetadataLoader.php 1 month ago Metric.php 1 month ago PluginException.php 1 year ago ProcessedMetric.php 3 months ago ReleaseChannels.php 3 months ago Report.php 1 month ago ReportsProvider.php 2 years ago RequestProcessors.php 4 months ago Segment.php 3 months ago SettingsProvider.php 1 month ago Tasks.php 1 month ago ThemeStyles.php 2 weeks ago ViewDataTable.php 3 months ago Visualization.php 1 year ago WidgetsProvider.php 3 months ago
API.php
138 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\Plugin;
10
11 use Piwik\Container\StaticContainer;
12 use Piwik\Piwik;
13 use Piwik\Plugins\Login\PasswordVerifier;
14 use Piwik\Log\LoggerInterface;
15 use Exception;
16 /**
17 * The base class of all API singletons.
18 *
19 * Plugins that want to expose functionality through the Reporting API should create a class
20 * that extends this one. Every public method in that class that is not annotated with **@ignore**
21 * will be callable through Matomo's Web API.
22 *
23 * _Note: If your plugin calculates and stores reports, they should be made available through the API._
24 *
25 * ### Examples
26 *
27 * **Defining an API for a plugin**
28 *
29 * class API extends \Piwik\Plugin\API
30 * {
31 * public function myMethod($idSite, $period, $date, $segment = false)
32 * {
33 * $dataTable = // ... get some data ...
34 * return $dataTable;
35 * }
36 * }
37 *
38 * **Linking to an API method**
39 *
40 * <a href="?module=API&method=MyPlugin.myMethod&idSite=1&period=day&date=2013-10-23">Link</a>
41 *
42 * @api
43 */
44 abstract class API
45 {
46 private static $instances;
47 /** @var bool */
48 protected $autoSanitizeInputParams = \true;
49 /**
50 * Returns the singleton instance for the derived class. If the singleton instance
51 * has not been created, this method will create it.
52 *
53 * @return static
54 */
55 public static function getInstance()
56 {
57 $class = get_called_class();
58 if (!isset(self::$instances[$class])) {
59 $container = StaticContainer::getContainer();
60 $refl = new \ReflectionClass($class);
61 if (!$refl->getConstructor() || $refl->getConstructor()->isPublic()) {
62 self::$instances[$class] = $container->get($class);
63 } else {
64 /** @var LoggerInterface $logger */
65 $logger = $container->get(LoggerInterface::class);
66 // BC with API defining a protected constructor
67 $logger->notice('The API class {class} defines a protected constructor which is deprecated, make the constructor public instead', ['class' => $class]);
68 self::$instances[$class] = new $class();
69 }
70 }
71 return self::$instances[$class];
72 }
73 /**
74 * Used in tests only
75 * @ignore
76 * @internal
77 */
78 public static function unsetInstance()
79 {
80 $class = get_called_class();
81 unset(self::$instances[$class]);
82 }
83 /**
84 * Used in tests only
85 * @ignore
86 * @internal
87 */
88 public static function unsetAllInstances()
89 {
90 self::$instances = [];
91 }
92 /**
93 * Sets the singleton instance. For testing purposes.
94 * @ignore
95 * @internal
96 */
97 public static function setSingletonInstance($instance)
98 {
99 $class = get_called_class();
100 self::$instances[$class] = $instance;
101 }
102 /**
103 * Verifies if the given password matches the current users password
104 *
105 * @param $passwordConfirmation
106 * @throws Exception
107 */
108 protected function confirmCurrentUserPassword(
109 #[\SensitiveParameter]
110 $passwordConfirmation)
111 {
112 $loginCurrentUser = Piwik::getCurrentUserLogin();
113 if (!Piwik::doesUserRequirePasswordConfirmation($loginCurrentUser)) {
114 return;
115 // password confirmation disabled for user
116 }
117 if (empty($passwordConfirmation)) {
118 throw new Exception(Piwik::translate('UsersManager_ConfirmWithReAuthentication'));
119 }
120 try {
121 if (!StaticContainer::get(PasswordVerifier::class)->isPasswordCorrect($loginCurrentUser, $passwordConfirmation)) {
122 throw new Exception(Piwik::translate('UsersManager_CurrentPasswordNotCorrect'));
123 }
124 } catch (Exception $e) {
125 // in case of any error (e.g. the provided password is too weak)
126 throw new Exception(Piwik::translate('UsersManager_CurrentPasswordNotCorrect'));
127 }
128 }
129 /**
130 * @return bool
131 * @internal
132 */
133 public function usesAutoSanitizeInputParams()
134 {
135 return $this->autoSanitizeInputParams;
136 }
137 }
138