Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'core/PluginsManager.php')
-rw-r--r--core/PluginsManager.php34
1 files changed, 23 insertions, 11 deletions
diff --git a/core/PluginsManager.php b/core/PluginsManager.php
index 0b8bcabe58..51a22ba8df 100644
--- a/core/PluginsManager.php
+++ b/core/PluginsManager.php
@@ -286,8 +286,9 @@ class PluginsManager
}
// Only one theme enabled at a time
- $themeAlreadyEnabled = $this->getThemeEnabled();
- if($themeAlreadyEnabled) {
+ $themeEnabled = $this->getThemeEnabled();
+ if($themeEnabled) {
+ $themeAlreadyEnabled = $themeEnabled->getPluginName();
$plugin = $this->loadPlugin($pluginName);
if($plugin->isTheme()) {
$plugins = $this->deactivatePlugin( $themeAlreadyEnabled, $plugins );
@@ -328,16 +329,16 @@ class PluginsManager
* Returns the name of the non default theme currently enabled.
* If Zeitgeist is enabled, returns false (nb: Zeitgeist cannot be disabled)
*
- * @return string
+ * @return Plugin
*/
- protected function getThemeEnabled()
+ public function getThemeEnabled()
{
$plugins = $this->getLoadedPlugins();
foreach($plugins as $plugin) {
/* @var $plugin Plugin */
if($plugin->isTheme()
&& $plugin->getPluginName() != self::DEFAULT_THEME) {
- return $plugin->getPluginName();
+ return $plugin;
}
}
return false;
@@ -405,13 +406,13 @@ class PluginsManager
}
/**
- * Returns an array containing the plugins class names (eg. 'Piwik_UserCountry' and NOT 'UserCountry')
+ * Returns an array containing the plugins class names (eg. 'UserCountry' and NOT 'UserCountry')
*
* @return array
*/
public function getLoadedPluginsName()
{
- return array_map('get_class', $this->getLoadedPlugins());
+ return array_keys($this->getLoadedPlugins());
}
/**
@@ -466,7 +467,7 @@ class PluginsManager
/**
* Loads the plugin filename and instantiates the plugin with the given name, eg. UserCountry
- * Do NOT give the class name ie. Piwik_UserCountry, but give the plugin name ie. UserCountry
+ * Do NOT give the class name ie. UserCountry, but give the plugin name ie. UserCountry
*
* @param string $pluginName
* @throws \Exception
@@ -494,7 +495,7 @@ class PluginsManager
protected function makePluginClass($pluginName)
{
$pluginFileName = sprintf("%s/%s.php", $pluginName, $pluginName);
- $pluginClassName = sprintf('Piwik_%s', $pluginName);
+ $pluginClassName = $pluginName;
if (!Common::isValidFilename($pluginName)) {
throw new \Exception(sprintf("The plugin filename '%s' is not a valid filename", $pluginFileName));
@@ -510,10 +511,11 @@ class PluginsManager
require_once $path;
- if (!class_exists($pluginClassName, false)) {
+ $namespacedClass = $this->getClassNamePlugin($pluginName);
+ if(!class_exists($namespacedClass, false)) {
throw new \Exception("The class $pluginClassName couldn't be found in the file '$path'");
}
- $newPlugin = new $pluginClassName();
+ $newPlugin = new $namespacedClass;
if (!($newPlugin instanceof Plugin)) {
throw new \Exception("The plugin $pluginClassName in the file $path must inherit from Plugin.");
@@ -521,6 +523,15 @@ class PluginsManager
return $newPlugin;
}
+ protected function getClassNamePlugin($pluginName)
+ {
+ $className = $pluginName;
+ if($pluginName == 'API') {
+ $className = 'Plugin';
+ }
+ return "\\Piwik\\Plugins\\$pluginName\\$className";
+ }
+
/**
* Unload plugin
*
@@ -669,6 +680,7 @@ class PluginsManager
// is the plugin already installed or is it the first time we activate it?
$pluginsInstalled = $this->getInstalledPluginsName();
+
if (!in_array($pluginName, $pluginsInstalled)) {
$this->installPlugin($plugin);
$pluginsInstalled[] = $pluginName;