| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Application\Kernel; |
|
|
| use Piwik\Plugin\MetadataLoader; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class PluginList |
| { |
| |
| |
| |
| private $settings; |
|
|
| |
| |
| |
| |
| private $corePluginsDisabledByDefault = array( |
| 'ArchivingMetrics', |
| 'DBStats', |
| 'ExamplePlugin', |
| 'ExampleCommand', |
| 'ExampleSettingsPlugin', |
| 'ExampleUI', |
| 'ExampleVisualization', |
| 'ExamplePluginTemplate', |
| 'ExampleTracker', |
| 'ExampleLogTables', |
| 'ExampleReport', |
| 'ExampleAPI', |
| 'ExampleVue', |
| 'MobileAppMeasurable', |
| 'TagManager', |
| ); |
|
|
| |
| private $coreThemesDisabledByDefault = array( |
| 'ExampleTheme', |
| ); |
|
|
| public function __construct(GlobalSettingsProvider $settings) |
| { |
| $this->settings = $settings; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getActivatedPlugins() |
| { |
| $section = $this->settings->getSection('Plugins'); |
| $plugins = @$section['Plugins'] ?: array(); |
|
|
| return $plugins; |
| } |
|
|
| |
| |
| |
| |
| |
| public function getPluginsBundledWithPiwik() |
| { |
| $pathGlobal = $this->settings->getPathGlobal(); |
|
|
| $section = $this->settings->getIniFileChain()->getFrom($pathGlobal, 'Plugins'); |
| return $section['Plugins']; |
| } |
|
|
| |
| |
| |
| |
| |
| public function getCorePluginsDisabledByDefault() |
| { |
| return array_merge($this->corePluginsDisabledByDefault, $this->coreThemesDisabledByDefault); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function sortPlugins(array $plugins) |
| { |
| $global = $this->getPluginsBundledWithPiwik(); |
| if (empty($global)) { |
| return $plugins; |
| } |
|
|
| |
| $global = array_merge($global, $this->corePluginsDisabledByDefault); |
|
|
| $global = array_values($global); |
| $plugins = array_values($plugins); |
|
|
| $defaultPluginsLoadedFirst = array_intersect($global, $plugins); |
|
|
| $otherPluginsToLoadAfterDefaultPlugins = array_diff($plugins, $defaultPluginsLoadedFirst); |
|
|
| |
| natcasesort($otherPluginsToLoadAfterDefaultPlugins); |
|
|
| $sorted = array_merge($defaultPluginsLoadedFirst, $otherPluginsToLoadAfterDefaultPlugins); |
|
|
| return $sorted; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function sortPluginsAndRespectDependencies(array $plugins, $pluginJsonCache = array()) |
| { |
| $global = $this->getPluginsBundledWithPiwik(); |
|
|
| if (empty($global)) { |
| return $plugins; |
| } |
|
|
| |
| $global = array_merge($global, $this->corePluginsDisabledByDefault); |
|
|
| $global = array_values($global); |
| $plugins = array_values($plugins); |
|
|
| $defaultPluginsLoadedFirst = array_intersect($global, $plugins); |
|
|
| $otherPluginsToLoadAfterDefaultPlugins = array_diff($plugins, $defaultPluginsLoadedFirst); |
|
|
| |
| natcasesort($otherPluginsToLoadAfterDefaultPlugins); |
|
|
| $sorted = array(); |
| foreach ($otherPluginsToLoadAfterDefaultPlugins as $pluginName) { |
| $sorted = $this->sortRequiredPlugin($pluginName, $pluginJsonCache, $otherPluginsToLoadAfterDefaultPlugins, $sorted); |
| } |
|
|
| $sorted = array_merge($defaultPluginsLoadedFirst, $sorted); |
|
|
| return $sorted; |
| } |
|
|
| private function sortRequiredPlugin($pluginName, &$pluginJsonCache, $toBeSorted, $sorted) |
| { |
| if (!isset($pluginJsonCache[$pluginName])) { |
| $loader = new MetadataLoader($pluginName); |
| $pluginJsonCache[$pluginName] = $loader->loadPluginInfoJson(); |
| } |
|
|
| if (!empty($pluginJsonCache[$pluginName]['require'])) { |
| $dependencies = $pluginJsonCache[$pluginName]['require']; |
| foreach ($dependencies as $possiblePluginName => $key) { |
| if (in_array($possiblePluginName, $toBeSorted, true) && !in_array($possiblePluginName, $sorted, true)) { |
| $sorted = $this->sortRequiredPlugin($possiblePluginName, $pluginJsonCache, $toBeSorted, $sorted); |
| } |
| } |
| } |
|
|
| if (!in_array($pluginName, $sorted, true)) { |
| $sorted[] = $pluginName; |
| } |
|
|
| return $sorted; |
| } |
| } |
|
|