PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.13.0 5.12.1 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 2 years ago API.php 2 years ago AggregatedMetric.php 2 years ago ArchivedMetric.php 2 years ago Archiver.php 2 years ago Categories.php 2 years ago ComponentFactory.php 2 years ago ComputedMetric.php 2 years ago ConsoleCommand.php 2 years ago Controller.php 2 years ago ControllerAdmin.php 2 years ago Dependency.php 2 years ago LogTablesProvider.php 2 years ago Manager.php 2 years ago Menu.php 2 years ago MetadataLoader.php 2 years ago Metric.php 2 years ago PluginException.php 2 years ago ProcessedMetric.php 2 years ago ReleaseChannels.php 2 years ago Report.php 2 years ago ReportsProvider.php 2 years ago RequestProcessors.php 2 years ago Segment.php 2 years ago SettingsProvider.php 2 years ago Tasks.php 2 years ago ThemeStyles.php 2 years ago ViewDataTable.php 2 years ago Visualization.php 2 years ago WidgetsProvider.php 2 years ago
MetadataLoader.php
124 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\Plugin;
11
12 use Exception;
13 use Piwik\Piwik;
14 use Piwik\Url;
15 use Piwik\Version;
16 /**
17 * @see core/Version.php
18 */
19 require_once PIWIK_INCLUDE_PATH . '/core/Version.php';
20 /**
21 * Loads plugin metadata found in the following files:
22 * - piwik.json
23 */
24 class MetadataLoader
25 {
26 const PLUGIN_JSON_FILENAME = 'plugin.json';
27 /**
28 * The name of the plugin whose metadata will be loaded.
29 *
30 * @var string
31 */
32 private $pluginName;
33 /**
34 * Constructor.
35 *
36 * @param string $pluginName Name of the plugin to load metadata.
37 */
38 public function __construct($pluginName)
39 {
40 $this->pluginName = $pluginName;
41 }
42 /**
43 * Loads plugin metadata. @see Plugin::getInformation.
44 *
45 * @return array
46 */
47 public function load()
48 {
49 $defaults = $this->getDefaultPluginInformation();
50 $plugin = $this->loadPluginInfoJson();
51 // use translated plugin description if available
52 if ($defaults['description'] != Piwik::translate($defaults['description'])) {
53 unset($plugin['description']);
54 }
55 // look for a license file
56 $licenseFile = $this->getPathToLicenseFile();
57 if (!empty($licenseFile)) {
58 $plugin['license_file'] = $licenseFile;
59 }
60 return array_merge($defaults, $plugin);
61 }
62 public function hasPluginJson()
63 {
64 $hasJson = $this->loadPluginInfoJson();
65 return !empty($hasJson);
66 }
67 private function getDefaultPluginInformation()
68 {
69 $descriptionKey = $this->pluginName . '_PluginDescription';
70 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' => []];
71 }
72 /**
73 * It is important that this method works without using anything from DI
74 * @return array|mixed
75 */
76 public function loadPluginInfoJson()
77 {
78 $path = $this->getPathToPluginJson();
79 return $this->loadJsonMetadata($path);
80 }
81 public function getPathToPluginJson()
82 {
83 $path = $this->getPathToPluginFolder() . '/' . self::PLUGIN_JSON_FILENAME;
84 return $path;
85 }
86 private function loadJsonMetadata($path)
87 {
88 if (!file_exists($path)) {
89 return array();
90 }
91 $json = file_get_contents($path);
92 if (!$json) {
93 return array();
94 }
95 $info = json_decode($json, $assoc = true);
96 if (!is_array($info) || empty($info)) {
97 throw new Exception("Invalid JSON file: {$path}");
98 }
99 return $info;
100 }
101 /**
102 * @return string
103 */
104 private function getPathToPluginFolder()
105 {
106 return \Piwik\Plugin\Manager::getPluginDirectory($this->pluginName);
107 }
108 /**
109 * @return null|string
110 */
111 public function getPathToLicenseFile()
112 {
113 $prefixPath = $this->getPathToPluginFolder() . '/';
114 $licenseFiles = array('LICENSE', 'LICENSE.md', 'LICENSE.txt');
115 foreach ($licenseFiles as $licenseFile) {
116 $pathToLicense = $prefixPath . $licenseFile;
117 if (is_file($pathToLicense) && is_readable($pathToLicense)) {
118 return $pathToLicense;
119 }
120 }
121 return null;
122 }
123 }
124