Newer
Older
<?php
/**
* Piwik - Open source web analytics
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
use Piwik\Config as PiwikConfig;
use Piwik\Menu\MenuAdmin;
use Piwik\Menu\MenuTop;
use Piwik\Notification;
Thomas Steur
a validé
use Piwik\Notification\Manager as NotificationManager;
use Piwik\Url;
use Piwik\Version;
use Piwik\View;
* Base class of plugin controllers that provide administrative functionality.
*
* See {@link Controller} to learn more about Piwik controllers.
abstract class ControllerAdmin extends Controller
Thomas Steur
a validé
private static $isEacceleratorUsed = false;
private static function notifyWhenTrackingStatisticsDisabled()
{
$statsEnabled = PiwikConfig::getInstance()->Tracker['record_statistics'];
if ($statsEnabled == "0") {
$notification = new Notification(Piwik::translate('General_StatisticsAreNotRecorded'));
$notification->context = Notification::CONTEXT_INFO;
Notification\Manager::notify('ControllerAdmin_StatsAreNotRecorded', $notification);
}
}
private static function notifyAnyInvalidPlugin()
{
$missingPlugins = \Piwik\Plugin\Manager::getInstance()->getMissingPlugins();
if (empty($missingPlugins)) {
return;
}
Thomas Steur
a validé
if (!Piwik::hasUserSuperUserAccess()) {
return;
}
$pluginsLink = Url::getCurrentQueryStringWithParametersModified(array(
'module' => 'CorePluginsAdmin', 'action' => 'plugins'
));
$invalidPluginsWarning = Piwik::translate('CoreAdminHome_InvalidPluginsWarning', array(
self::getPiwikVersion(),
'<strong>' . implode('</strong>, <strong>', $missingPlugins) . '</strong>'))
. Piwik::translate('CoreAdminHome_InvalidPluginsYouCanUninstall', array(
'<a href="' . $pluginsLink . '"/>',
'</a>'
));
$notification = new Notification($invalidPluginsWarning);
$notification->raw = true;
$notification->context = Notification::CONTEXT_WARNING;
$notification->title = Piwik::translate('General_Warning') . ':';
Notification\Manager::notify('ControllerAdmin_InvalidPluginsWarning', $notification);
}
* Calls {@link setBasicVariablesView()} and {@link setBasicVariablesAdminView()}
* @param View $view
*/
protected function setBasicVariablesView($view)
{
parent::setBasicVariablesView($view);
self::setBasicVariablesAdminView($view);
}
static public function displayWarningIfConfigFileNotWritable()
$isConfigFileWritable = PiwikConfig::getInstance()->isFileWritable();
if (!$isConfigFileWritable) {
$exception = PiwikConfig::getInstance()->getConfigNotWritableException();
$message = $exception->getMessage();
$notification = new Notification($message);
$notification->raw = true;
$notification->context = Notification::CONTEXT_WARNING;
Notification\Manager::notify('ControllerAdmin_ConfigNotWriteable', $notification);
}
Thomas Steur
a validé
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* See http://dev.piwik.org/trac/ticket/4439#comment:8 and https://github.com/eaccelerator/eaccelerator/issues/12
*
* Eaccelerator does not support closures and is known to be not comptabile with Piwik. Therefore we are disabling
* it automatically. At this point it looks like Eaccelerator is no longer under development and the bug has not
* been fixed within a year.
*/
public static function disableEacceleratorIfEnabled()
{
$isEacceleratorUsed = ini_get('eaccelerator.enable');
if (!empty($isEacceleratorUsed)) {
self::$isEacceleratorUsed = true;
@ini_set('eaccelerator.enable', 0);
}
}
private static function notifyIfEAcceleratorIsUsed()
{
if (self::$isEacceleratorUsed) {
$params = array('<a href="http://dev.piwik.org/trac/ticket/4439">', '</a>');
$message = Piwik::translate('CoreAdminHome_EacceleratorNotCompatible', $params);
$notification = new Notification($message);
$notification->context = Notification::CONTEXT_WARNING;
$notification->raw = true;
Notification\Manager::notify('ControllerAdmin_EacceleratorIsUsed', $notification);
}
}
* Assigns view properties that would be useful to views that render admin pages.
* - **statisticsNotRecorded** - Set to true if the `[Tracker] record_statistics` INI
* config is `0`. If not `0`, this variable will not be defined.
* - **topMenu** - The result of `MenuTop::getInstance()->getMenu()`.
* - **currentAdminMenuName** - The currently selected admin menu name.
* - **enableFrames** - The value of the `[General] enable_framed_pages` INI config option. If
* true, {@link Piwik\View::setXFrameOptions()} is called on the view.
* - **isSuperUser** - Whether the current user is a superuser or not.
* - **usingOldGeoIPPlugin** - Whether this Piwik install is currently using the old GeoIP
* plugin or not.
* - **invalidPluginsWarning** - Set if some of the plugins to load (determined by INI configuration)
* are invalid or missing.
* - **phpVersion** - The current PHP version.
* - **phpIsNewEnough** - Whether the current PHP version is new enough to run Piwik.
* - **adminMenu** - The result of `MenuAdmin::getInstance()->getMenu()`.
* @param View $view
* @api
*/
static public function setBasicVariablesAdminView(View $view)
self::notifyWhenTrackingStatisticsDisabled();
Thomas Steur
a validé
self::notifyIfEAcceleratorIsUsed();
$view->topMenu = MenuTop::getInstance()->getMenu();
$view->currentAdminMenuName = MenuAdmin::getInstance()->getCurrentAdminMenuName();
$view->isDataPurgeSettingsEnabled = self::isDataPurgeSettingsEnabled();
$view->enableFrames = PiwikConfig::getInstance()->General['enable_framed_settings'];
if (!$view->enableFrames) {
$view->setXFrameOptions('sameorigin');
}
Thomas Steur
a validé
$view->isSuperUser = Piwik::hasUserSuperUserAccess();
self::notifyAnyInvalidPlugin();
diosmosis
a validé
self::checkPhpVersion($view);
$adminMenu = MenuAdmin::getInstance()->getMenu();
$view->adminMenu = $adminMenu;
$view->notifications = NotificationManager::getAllNotificationsToDisplay();
NotificationManager::cancelAllNonPersistent();
diosmosis
a validé
}
Thomas Steur
a validé
static public function isDataPurgeSettingsEnabled()
{
return (bool) Config::getInstance()->General['enable_delete_old_data_settings_admin'];
}
static protected function getPiwikVersion()
{
return "Piwik " . Version::VERSION;
}
diosmosis
a validé
/**
* Check if the current PHP version is >= 5.3. If not, a warning is displayed
* to the user.
*/
private static function checkPhpVersion($view)
{
$view->phpVersion = PHP_VERSION;
$view->phpIsNewEnough = version_compare($view->phpVersion, '5.3.0', '>=');
protected function getDefaultWebsiteId()
{
$sitesId = \Piwik\Plugins\SitesManager\API::getInstance()->getSitesIdWithAdminAccess();
if (!empty($sitesId)) {
return $sitesId[0];
}
return parent::getDefaultWebsiteId();
}