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 / MetadataLoader.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
MetadataLoader.php
121 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 Exception;
12 use Piwik\Piwik;
13 use Piwik\Url;
14 use Piwik\Version;
15 /**
16 * @see core/Version.php
17 */
18 require_once PIWIK_INCLUDE_PATH . '/core/Version.php';
19 /**
20 * Loads plugin metadata found in the following files:
21 * - piwik.json
22 */
23 class MetadataLoader
24 {
25 public const PLUGIN_JSON_FILENAME = 'plugin.json';
26 /**
27 * The name of the plugin whose metadata will be loaded.
28 *
29 * @var string
30 */
31 private $pluginName;
32 /**
33 * @param string $pluginName Name of the plugin to load metadata.
34 */
35 public function __construct($pluginName)
36 {
37 $this->pluginName = $pluginName;
38 }
39 /**
40 * Loads plugin metadata. @see Plugin::getInformation.
41 *
42 * @return array
43 */
44 public function load()
45 {
46 $defaults = $this->getDefaultPluginInformation();
47 $plugin = $this->loadPluginInfoJson();
48 // use translated plugin description if available
49 if ($defaults['description'] != Piwik::translate($defaults['description'])) {
50 unset($plugin['description']);
51 }
52 // look for a license file
53 $licenseFile = $this->getPathToLicenseFile();
54 if (!empty($licenseFile)) {
55 $plugin['license_file'] = $licenseFile;
56 }
57 return array_merge($defaults, $plugin);
58 }
59 public function hasPluginJson()
60 {
61 $hasJson = $this->loadPluginInfoJson();
62 return !empty($hasJson);
63 }
64 private function getDefaultPluginInformation()
65 {
66 $descriptionKey = $this->pluginName . '_PluginDescription';
67 return ['description' => $descriptionKey, 'homepage' => Url::addCampaignParametersToMatomoLink('https://matomo.org/'), 'authors' => [['name' => 'Matomo', 'homepage' => Url::addCampaignParametersToMatomoLink('https://matomo.org/')]], 'license' => 'GPL v3+', 'version' => Version::VERSION, 'theme' => \false, 'require' => []];
68 }
69 /**
70 * It is important that this method works without using anything from DI
71 * @return array|mixed
72 */
73 public function loadPluginInfoJson()
74 {
75 $path = $this->getPathToPluginJson();
76 return $this->loadJsonMetadata($path);
77 }
78 public function getPathToPluginJson()
79 {
80 $path = $this->getPathToPluginFolder() . '/' . self::PLUGIN_JSON_FILENAME;
81 return $path;
82 }
83 private function loadJsonMetadata($path)
84 {
85 if (!file_exists($path)) {
86 return array();
87 }
88 $json = file_get_contents($path);
89 if (!$json) {
90 return array();
91 }
92 $info = json_decode($json, $assoc = \true);
93 if (!is_array($info) || empty($info)) {
94 throw new Exception("Invalid JSON file: {$path}");
95 }
96 return $info;
97 }
98 /**
99 * @return string
100 */
101 private function getPathToPluginFolder()
102 {
103 return \Piwik\Plugin\Manager::getPluginDirectory($this->pluginName);
104 }
105 /**
106 * @return null|string
107 */
108 public function getPathToLicenseFile()
109 {
110 $prefixPath = $this->getPathToPluginFolder() . '/';
111 $licenseFiles = array('LICENSE', 'LICENSE.md', 'LICENSE.txt');
112 foreach ($licenseFiles as $licenseFile) {
113 $pathToLicense = $prefixPath . $licenseFile;
114 if (is_file($pathToLicense) && is_readable($pathToLicense)) {
115 return $pathToLicense;
116 }
117 }
118 return null;
119 }
120 }
121