| Server IP : 167.99.224.18 / Your IP : 216.73.216.136 Web Server : Apache/2.4.41 (Ubuntu) System : Linux wordpress-ubuntu-s-1vcpu-1gb-nyc1-01 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.0.25 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/wp-content/plugins-old/matomo/app/core/Plugin/ |
Upload File : |
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugin;
use Exception;
use Piwik\Piwik;
use Piwik\Url;
use Piwik\Version;
/**
* @see core/Version.php
*/
require_once PIWIK_INCLUDE_PATH . '/core/Version.php';
/**
* Loads plugin metadata found in the following files:
* - piwik.json
*/
class MetadataLoader
{
public const PLUGIN_JSON_FILENAME = 'plugin.json';
/**
* The name of the plugin whose metadata will be loaded.
*
* @var string
*/
private $pluginName;
/**
* Constructor.
*
* @param string $pluginName Name of the plugin to load metadata.
*/
public function __construct($pluginName)
{
$this->pluginName = $pluginName;
}
/**
* Loads plugin metadata. @see Plugin::getInformation.
*
* @return array
*/
public function load()
{
$defaults = $this->getDefaultPluginInformation();
$plugin = $this->loadPluginInfoJson();
// use translated plugin description if available
if ($defaults['description'] != Piwik::translate($defaults['description'])) {
unset($plugin['description']);
}
// look for a license file
$licenseFile = $this->getPathToLicenseFile();
if (!empty($licenseFile)) {
$plugin['license_file'] = $licenseFile;
}
return array_merge($defaults, $plugin);
}
public function hasPluginJson()
{
$hasJson = $this->loadPluginInfoJson();
return !empty($hasJson);
}
private function getDefaultPluginInformation()
{
$descriptionKey = $this->pluginName . '_PluginDescription';
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' => []];
}
/**
* It is important that this method works without using anything from DI
* @return array|mixed
*/
public function loadPluginInfoJson()
{
$path = $this->getPathToPluginJson();
return $this->loadJsonMetadata($path);
}
public function getPathToPluginJson()
{
$path = $this->getPathToPluginFolder() . '/' . self::PLUGIN_JSON_FILENAME;
return $path;
}
private function loadJsonMetadata($path)
{
if (!file_exists($path)) {
return array();
}
$json = file_get_contents($path);
if (!$json) {
return array();
}
$info = json_decode($json, $assoc = \true);
if (!is_array($info) || empty($info)) {
throw new Exception("Invalid JSON file: {$path}");
}
return $info;
}
/**
* @return string
*/
private function getPathToPluginFolder()
{
return \Piwik\Plugin\Manager::getPluginDirectory($this->pluginName);
}
/**
* @return null|string
*/
public function getPathToLicenseFile()
{
$prefixPath = $this->getPathToPluginFolder() . '/';
$licenseFiles = array('LICENSE', 'LICENSE.md', 'LICENSE.txt');
foreach ($licenseFiles as $licenseFile) {
$pathToLicense = $prefixPath . $licenseFile;
if (is_file($pathToLicense) && is_readable($pathToLicense)) {
return $pathToLicense;
}
}
return null;
}
}