PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.2.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.2.0
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 2 years ago Dimension 1 year ago API.php 1 year ago AggregatedMetric.php 2 years ago ArchivedMetric.php 1 year ago Archiver.php 1 year ago Categories.php 2 years ago ComponentFactory.php 2 years ago ComputedMetric.php 1 year ago ConsoleCommand.php 1 year ago Controller.php 1 year ago ControllerAdmin.php 1 year ago Dependency.php 1 year ago LogTablesProvider.php 2 years ago Manager.php 1 year ago Menu.php 1 year ago MetadataLoader.php 1 year ago Metric.php 1 year ago PluginException.php 1 year ago ProcessedMetric.php 1 year ago ReleaseChannels.php 2 years ago Report.php 1 year ago ReportsProvider.php 2 years ago RequestProcessors.php 2 years ago Segment.php 1 year ago SettingsProvider.php 2 years ago Tasks.php 1 year ago ThemeStyles.php 2 years ago ViewDataTable.php 1 year ago Visualization.php 1 year ago WidgetsProvider.php 2 years ago
API.php
135 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 protected $autoSanitizeInputParams = \true;
48 /**
49 * Returns the singleton instance for the derived class. If the singleton instance
50 * has not been created, this method will create it.
51 *
52 * @return static
53 */
54 public static function getInstance()
55 {
56 $class = get_called_class();
57 if (!isset(self::$instances[$class])) {
58 $container = StaticContainer::getContainer();
59 $refl = new \ReflectionClass($class);
60 if (!$refl->getConstructor() || $refl->getConstructor()->isPublic()) {
61 self::$instances[$class] = $container->get($class);
62 } else {
63 /** @var LoggerInterface $logger */
64 $logger = $container->get(LoggerInterface::class);
65 // BC with API defining a protected constructor
66 $logger->notice('The API class {class} defines a protected constructor which is deprecated, make the constructor public instead', ['class' => $class]);
67 self::$instances[$class] = new $class();
68 }
69 }
70 return self::$instances[$class];
71 }
72 /**
73 * Used in tests only
74 * @ignore
75 * @internal
76 */
77 public static function unsetInstance()
78 {
79 $class = get_called_class();
80 unset(self::$instances[$class]);
81 }
82 /**
83 * Used in tests only
84 * @ignore
85 * @internal
86 */
87 public static function unsetAllInstances()
88 {
89 self::$instances = [];
90 }
91 /**
92 * Sets the singleton instance. For testing purposes.
93 * @ignore
94 * @internal
95 */
96 public static function setSingletonInstance($instance)
97 {
98 $class = get_called_class();
99 self::$instances[$class] = $instance;
100 }
101 /**
102 * Verifies if the given password matches the current users password
103 *
104 * @param $passwordConfirmation
105 * @throws Exception
106 */
107 protected function confirmCurrentUserPassword($passwordConfirmation)
108 {
109 $loginCurrentUser = Piwik::getCurrentUserLogin();
110 if (!Piwik::doesUserRequirePasswordConfirmation($loginCurrentUser)) {
111 return;
112 // password confirmation disabled for user
113 }
114 if (empty($passwordConfirmation)) {
115 throw new Exception(Piwik::translate('UsersManager_ConfirmWithPassword'));
116 }
117 try {
118 if (!StaticContainer::get(PasswordVerifier::class)->isPasswordCorrect($loginCurrentUser, $passwordConfirmation)) {
119 throw new Exception(Piwik::translate('UsersManager_CurrentPasswordNotCorrect'));
120 }
121 } catch (Exception $e) {
122 // in case of any error (e.g. the provided password is too weak)
123 throw new Exception(Piwik::translate('UsersManager_CurrentPasswordNotCorrect'));
124 }
125 }
126 /**
127 * @return bool
128 * @internal
129 */
130 public function usesAutoSanitizeInputParams()
131 {
132 return $this->autoSanitizeInputParams;
133 }
134 }
135