Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 * Enabling one theme a time: automatically deactivates another theme if it was enabled (except Zeitgeist which is always on)
  • Loading branch information
mattab committed Jul 16, 2013
1 parent 7198b79 commit 53654d5
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions core/PluginsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,13 @@ protected function getPluginsDirectory()
* Deactivate plugin
*
* @param string $pluginName Name of plugin
* @param array $plugins Array of plugin names
*/
public function deactivatePlugin($pluginName)
public function deactivatePlugin($pluginName, $plugins = false)
{
$plugins = $this->pluginsToLoad;
if(empty($plugins)) {
$plugins = $this->pluginsToLoad;
}
$key = array_search($pluginName, $plugins);

$plugin = $this->loadPlugin($pluginName);
Expand All @@ -219,6 +222,8 @@ public function deactivatePlugin($pluginName)

Piwik_Config::getInstance()->forceSave();
Piwik::deleteAllCacheOnUpdate();

return $plugins;
}

/**
Expand Down Expand Up @@ -267,9 +272,14 @@ public function activatePlugin($pluginName)
// we add the plugin to the list of activated plugins
if (!in_array($pluginName, $plugins)) {
$plugins[] = $pluginName;
} else {
// clean up if we find a dupe
$plugins = array_unique($plugins);
}
$plugins = array_unique($plugins);

// Only one theme enabled at a time
$themeAlreadyEnabled = $this->getThemeEnabled();
if($plugin->isTheme()
&& $themeAlreadyEnabled) {
$plugins = $this->deactivatePlugin( $themeAlreadyEnabled, $plugins );
}

// the config file will automatically be saved with the new plugin
Expand All @@ -279,6 +289,25 @@ public function activatePlugin($pluginName)
Piwik::deleteAllCacheOnUpdate();
}

/**
* Returns the name of the non default theme currently enabled.
* If Zeitgeist is enabled, returns false (nb: Zeitgeist cannot be disabled)
*
* @return string
*/
protected function getThemeEnabled()
{
$plugins = $this->getLoadedPlugins();
foreach($plugins as $plugin) {
/* @var $plugin Piwik_Plugin */
if($plugin->isTheme()
&& $plugin->getPluginName() != Piwik_Twig::DEFAULT_THEME) {
return $plugin->getPluginName();
}
}
return false;
}

/**
* Load the specified plugins
*
Expand Down Expand Up @@ -356,7 +385,7 @@ public function getLoadedPluginsName()
* 'UserSettings' => Piwik_Plugin $pluginObject,
* );
*
* @return array
* @return array,Piwik_Plugin
*/
public function getLoadedPlugins()
{
Expand Down

0 comments on commit 53654d5

Please sign in to comment.