1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-22 06:57:53 +00:00
Files
matomo/plugins/CustomJsTracker/TrackingCode/PluginTrackerFiles.php
Michal Kleiner 9a3ef94df6 [Coding Style] Enable rule PSR12.Files.FileHeader + unify file headers (#22132)
* [Coding Style] Enable rule PSR12.Files.FileHeader

* Apply CS

* Replace Piwik with Matomo in file headers

* Unify file headers (position, no. of lines, https links)

* Rebuild dist files

* Apply CS

* Fix system test that relies on line numbers in a file that had the file header updated

---------

Co-authored-by: Stefan Giehl <stefan@matomo.org>
2024-04-20 20:50:47 +02:00

97 خطوط
2.6 KiB
PHP

<?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\Plugins\CustomJsTracker\TrackingCode;
use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Plugins\CustomJsTracker\File;
class PluginTrackerFiles
{
public const TRACKER_FILE = 'tracker.js';
public const MIN_TRACKER_FILE = 'tracker.min.js';
/**
* @var Plugin\Manager
*/
private $pluginManager;
/**
* @var bool
*/
protected $ignoreMinified = false;
public function __construct()
{
$this->pluginManager = Plugin\Manager::getInstance();
}
public function ignoreMinified()
{
$this->ignoreMinified = true;
}
protected function getDirectoriesToLook()
{
$dirs = array();
$manager = Plugin\Manager::getInstance();
foreach ($manager->getPluginsLoadedAndActivated() as $pluginName => $plugin) {
$dirs[$pluginName] = rtrim(Plugin\Manager::getPluginDirectory($pluginName), '/') . '/';
}
return $dirs;
}
/**
* @return File[]
*/
public function find()
{
$jsFiles = array();
foreach ($this->getDirectoriesToLook() as $pluginName => $pluginDir) {
if (!$this->ignoreMinified && file_exists($pluginDir . self::MIN_TRACKER_FILE)) {
$jsFiles[$pluginName] = new File($pluginDir . self::MIN_TRACKER_FILE);
} elseif (file_exists($pluginDir . self::TRACKER_FILE)) {
$jsFiles[$pluginName] = new File($pluginDir . self::TRACKER_FILE);
}
}
foreach ($jsFiles as $plugin => $file) {
if (!$this->shouldIncludeFile($plugin)) {
unset($jsFiles[$plugin]);
}
}
return $jsFiles;
}
protected function shouldIncludeFile($pluginName)
{
$shouldAddFile = true;
/**
* Detect if a custom tracker file should be added to the piwik.js tracker or not.
*
* This is useful for example if a plugin only wants to add its tracker file when the plugin is configured.
*
* @param bool &$shouldAddFile Decides whether the tracker file belonging to the given plugin should be added or not.
* @param string $pluginName The name of the plugin this file belongs to
*/
Piwik::postEvent('CustomJsTracker.shouldAddTrackerFile', array(&$shouldAddFile, $pluginName));
return $shouldAddFile;
}
protected function isPluginActivated($pluginName)
{
return $this->pluginManager->isPluginActivated($pluginName);
}
}