| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| 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'; |
|
|
| |
| |
| |
| private $pluginManager; |
|
|
| |
| |
| |
| 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; |
| } |
|
|
| |
| |
| |
| 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; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| Piwik::postEvent('CustomJsTracker.shouldAddTrackerFile', array(&$shouldAddFile, $pluginName)); |
|
|
| return $shouldAddFile; |
| } |
|
|
| protected function isPluginActivated($pluginName) |
| { |
| return $this->pluginManager->isPluginActivated($pluginName); |
| } |
| } |
|
|