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