PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.6.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.6.0
5.12.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 / MetadataLoader.php
matomo / app / core / Plugin Last commit date
ConsoleCommand 2 years ago Dimension 1 year ago API.php 7 months ago AggregatedMetric.php 2 years ago ArchivedMetric.php 1 year ago Archiver.php 7 months ago Categories.php 2 years ago ComponentFactory.php 2 years ago ComputedMetric.php 1 year ago ConsoleCommand.php 1 year ago Controller.php 7 months ago ControllerAdmin.php 7 months ago Dependency.php 1 year ago LogTablesProvider.php 2 years ago Manager.php 7 months ago Menu.php 1 year ago MetadataLoader.php 1 year ago Metric.php 7 months ago PluginException.php 1 year ago ProcessedMetric.php 1 year ago ReleaseChannels.php 1 year ago Report.php 7 months ago ReportsProvider.php 2 years ago RequestProcessors.php 2 years ago Segment.php 1 year ago SettingsProvider.php 7 months ago Tasks.php 7 months ago ThemeStyles.php 7 months ago ViewDataTable.php 7 months ago Visualization.php 1 year ago WidgetsProvider.php 2 years ago
MetadataLoader.php
123 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 * Constructor.
34 *
35 * @param string $pluginName Name of the plugin to load metadata.
36 */
37 public function __construct($pluginName)
38 {
39 $this->pluginName = $pluginName;
40 }
41 /**
42 * Loads plugin metadata. @see Plugin::getInformation.
43 *
44 * @return array
45 */
46 public function load()
47 {
48 $defaults = $this->getDefaultPluginInformation();
49 $plugin = $this->loadPluginInfoJson();
50 // use translated plugin description if available
51 if ($defaults['description'] != Piwik::translate($defaults['description'])) {
52 unset($plugin['description']);
53 }
54 // look for a license file
55 $licenseFile = $this->getPathToLicenseFile();
56 if (!empty($licenseFile)) {
57 $plugin['license_file'] = $licenseFile;
58 }
59 return array_merge($defaults, $plugin);
60 }
61 public function hasPluginJson()
62 {
63 $hasJson = $this->loadPluginInfoJson();
64 return !empty($hasJson);
65 }
66 private function getDefaultPluginInformation()
67 {
68 $descriptionKey = $this->pluginName . '_PluginDescription';
69 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' => []];
70 }
71 /**
72 * It is important that this method works without using anything from DI
73 * @return array|mixed
74 */
75 public function loadPluginInfoJson()
76 {
77 $path = $this->getPathToPluginJson();
78 return $this->loadJsonMetadata($path);
79 }
80 public function getPathToPluginJson()
81 {
82 $path = $this->getPathToPluginFolder() . '/' . self::PLUGIN_JSON_FILENAME;
83 return $path;
84 }
85 private function loadJsonMetadata($path)
86 {
87 if (!file_exists($path)) {
88 return array();
89 }
90 $json = file_get_contents($path);
91 if (!$json) {
92 return array();
93 }
94 $info = json_decode($json, $assoc = \true);
95 if (!is_array($info) || empty($info)) {
96 throw new Exception("Invalid JSON file: {$path}");
97 }
98 return $info;
99 }
100 /**
101 * @return string
102 */
103 private function getPathToPluginFolder()
104 {
105 return \Piwik\Plugin\Manager::getPluginDirectory($this->pluginName);
106 }
107 /**
108 * @return null|string
109 */
110 public function getPathToLicenseFile()
111 {
112 $prefixPath = $this->getPathToPluginFolder() . '/';
113 $licenseFiles = array('LICENSE', 'LICENSE.md', 'LICENSE.txt');
114 foreach ($licenseFiles as $licenseFile) {
115 $pathToLicense = $prefixPath . $licenseFile;
116 if (is_file($pathToLicense) && is_readable($pathToLicense)) {
117 return $pathToLicense;
118 }
119 }
120 return null;
121 }
122 }
123