protected function write(array $record) { switch ($record['level']) { case Logger::EMERGENCY: case Logger::ALERT: case Logger::CRITICAL: case Logger::ERROR: $context = Notification::CONTEXT_ERROR; break; case Logger::WARNING: $context = Notification::CONTEXT_WARNING; break; default: $context = Notification::CONTEXT_INFO; break; } $message = $record['level_name'] . ': ' . htmlentities($record['message']); $notification = new Notification($message); $notification->context = $context; $notification->flags = 0; try { Manager::notify(Common::getRandomString(), $notification); } catch (Zend_Session_Exception $e) { // Can happen if this handler is enabled in CLI // Silently ignore the error. } }
public function saveSettings() { Piwik::checkUserIsSuperUser(); if ($_SERVER["REQUEST_METHOD"] == "POST") { $this->checkTokenInUrl(); switch (Common::getRequestVar('form')) { case "formMaskLength": $this->handlePluginState(Common::getRequestVar("anonymizeIPEnable", 0)); $trackerConfig = Config::getInstance()->Tracker; $trackerConfig['ip_address_mask_length'] = Common::getRequestVar("maskLength", 1); $trackerConfig['use_anonymized_ip_for_visit_enrichment'] = Common::getRequestVar("useAnonymizedIpForVisitEnrichment", 1); Config::getInstance()->Tracker = $trackerConfig; Config::getInstance()->forceSave(); break; case "formDeleteSettings": $this->checkDataPurgeAdminSettingsIsEnabled(); $settings = $this->getPurgeSettingsFromRequest(); PrivacyManager::savePurgeDataSettings($settings); break; default: //do nothing break; } } $notification = new Notification(Piwik::translate('General_YourChangesHaveBeenSaved')); $notification->context = Notification::CONTEXT_SUCCESS; Notification\Manager::notify('PrivacyManager_ChangesHaveBeenSaved', $notification); $this->redirectToIndex('PrivacyManager', 'privacySettings', null, null, null, array('updated' => 1)); }
public function sendSMS($apiKey, $smsText, $phoneNumber, $from) { $message = sprintf('An SMS was sent:<br />From: %s<br />To: %s<br />Message: %s', $from, $phoneNumber, $smsText); $notification = new Notification($message); $notification->raw = true; $notification->context = Notification::CONTEXT_INFO; Notification\Manager::notify('StubbedSMSProvider' . preg_replace('/[^a-z0-9]/', '', $phoneNumber), $notification); }
public function index() { Piwik::checkUserHasSuperUserAccess(); $view = new View('@IP2Location/index'); $view->language = LanguagesManager::getLanguageCodeForCurrentUser(); $this->setBasicVariablesView($view); $view->adminMenu = MenuAdmin::getInstance()->getMenu(); $view->topMenu = MenuTop::getInstance()->getMenu(); $view->notifications = NotificationManager::getAllNotificationsToDisplay(); $view->userMenu = MenuUser::getInstance()->getMenu(); $view->phpVersion = phpversion(); $view->phpIsNewEnough = version_compare($view->phpVersion, '5.3.0', '>='); $view->assign('userMenu', 'IP2Location'); $view->assign('dbNotFound', false); $view->assign('dbOutDated', false); $view->assign('showResults', false); $view->assign('fileName', '-'); $view->assign('date', '-'); $view->assign('country', ''); $view->assign('regionName', ''); $view->assign('cityName', ''); $view->assign('position', ''); $ipAddress = trim(Common::getRequestVar('ipAddress', $_SERVER['REMOTE_ADDR'])); $view->assign('ipAddress', $ipAddress); $dbPath = PIWIK_INCLUDE_PATH . '/plugins/IP2Location/data/'; $dbFile = ''; if ($handle = opendir($dbPath)) { while (false !== ($file = readdir($handle))) { if (strtoupper(substr($file, -4)) == '.BIN') { $dbFile = $dbPath . $file; break; } } closedir($handle); } if (!$dbFile) { $view->assign('dbNotFound', true); } if ($dbFile) { $view->assign('fileName', $file); if (filemtime($dbFile) < strtotime('-2 months')) { $view->assign('dbOutDated', true); } else { $view->assign('date', date('d M, Y', filemtime($dbFile))); } if (!empty($_POST)) { $view->assign('showResults', true); $result = IP2LocationAPI::lookup($ipAddress, $dbFile); $view->assign('country', $result['countryCode'] != '-' ? $result['countryName'] . ' (' . $result['countryCode'] . ')' : '-'); $view->assign('regionName', !preg_match('/not supported/', $result['regionName']) ? $result['regionName'] : '-'); $view->assign('cityName', !preg_match('/not supported/', $result['cityName']) ? $result['cityName'] : '-'); $view->assign('position', !preg_match('/not supported/', $result['latitude']) && $result['latitude'] != '-' ? $result['latitude'] . ', ' . $result['longitude'] : '-'); } } echo $view->render(); }
private function copyDataFile() { if (!file_exists($this->getDataFilePath()) && file_exists($this->getDataExampleFilePath())) { copy($this->getDataExampleFilePath(), $this->getDataFilePath()); } $notification = new Notification('Please edit the file ' . $this->getDataFilePath() . ' and fill in your data'); $notification->raw = true; $notification->context = Notification::CONTEXT_INFO; Notification\Manager::notify('IntranetGeoIp_DATA_ERROR', $notification); return; }
public function notifyWhenPiwikNotConfiguredCorrectly() { $fingerprintingEnabled = (bool) Config::getInstance()->Tracker['enable_fingerprinting_across_websites']; if ($fingerprintingEnabled) { return; } $message = "<b>Warning: InterSites Plugin requires a change in your Piwik configuration:</b><br/>" . " To collect data for InterSites plugin, you must configure Piwik to allow the tracking of your visitors across websites. </br>" . " (By default Piwik does not know if a given user has visited several of your websites.) </br>" . " To continue using InterSites you must edit your file config/config.ini.php and add the following setting: </br>" . "<code>[Tracker]</br>enable_fingerprinting_across_websites=1</code><br/>" . " After you make this change, give Piwik time to collect new data. You can then view the '%s' in the <b>All Websites</b> dashboard</a>."; $message = sprintf($message, Piwik::translate('InterSites_CommonVisitorsTool_LaunchLinkText')); $notification = new Notification($message); $notification->raw = true; $notification->context = Notification::CONTEXT_WARNING; Notification\Manager::notify('InterSites_MustBeConfigured', $notification); }
public function notifications() { $notification = new Notification('Lorem ipsum dolor sit amet, consectetur adipiscing elit.'); Notification\Manager::notify('ExampleUI_InfoSimple', $notification); $notification = new Notification('Neque porro quisquam est qui dolorem ipsum quia dolor sit amet.'); $notification->title = 'Warning:'; $notification->context = Notification::CONTEXT_WARNING; $notification->flags = null; Notification\Manager::notify('ExampleUI_warningWithClose', $notification); $notification = new Notification('Phasellus tincidunt arcu at justo faucibus, et lacinia est accumsan. '); $notification->title = 'Well done'; $notification->context = Notification::CONTEXT_SUCCESS; $notification->type = Notification::TYPE_TOAST; Notification\Manager::notify('ExampleUI_successToast', $notification); $notification = new Notification('Phasellus tincidunt arcu at justo <a href="#">faucibus</a>, et lacinia est accumsan. '); $notification->raw = true; $notification->context = Notification::CONTEXT_ERROR; Notification\Manager::notify('ExampleUI_error', $notification); $view = new View('@ExampleUI/notifications'); $this->setGeneralVariablesView($view); return $view->render(); }
public function saveSettings() { Piwik::checkUserHasSuperUserAccess(); if ($_SERVER["REQUEST_METHOD"] == "POST") { $this->checkTokenInUrl(); switch (Common::getRequestVar('form')) { case "formMaskLength": $enable = Common::getRequestVar("anonymizeIPEnable", 0); if ($enable == 1) { IPAnonymizer::activate(); } else { if ($enable == 0) { IPAnonymizer::deactivate(); } else { // pass } } $privacyConfig = new Config(); $privacyConfig->ipAddressMaskLength = Common::getRequestVar("maskLength", 1); $privacyConfig->useAnonymizedIpForVisitEnrichment = Common::getRequestVar("useAnonymizedIpForVisitEnrichment", 1); break; case "formDeleteSettings": $this->checkDataPurgeAdminSettingsIsEnabled(); $settings = $this->getPurgeSettingsFromRequest(); PrivacyManager::savePurgeDataSettings($settings); break; default: //do nothing break; } } $notification = new Notification(Piwik::translate('General_YourChangesHaveBeenSaved')); $notification->context = Notification::CONTEXT_SUCCESS; Notification\Manager::notify('PrivacyManager_ChangesHaveBeenSaved', $notification); $this->redirectToIndex('PrivacyManager', 'privacySettings', null, null, null, array('updated' => 1)); }
/** * @return string */ public function admin() { Piwik::checkUserHasSuperUserAccess(); $view = new View('@LoginLdap/index'); ControllerAdmin::setBasicVariablesAdminView($view); if (!function_exists('ldap_connect')) { $notification = new Notification(Piwik::translate('LoginLdap_LdapFunctionsMissing')); $notification->context = Notification::CONTEXT_ERROR; $notification->type = Notification::TYPE_PERSISTENT; Notification\Manager::notify('LoginLdap_LdapFunctionsMissing', $notification); } $this->setBasicVariablesView($view); $serverNames = Config::getServerNameList() ?: array(); $view->servers = array(); if (empty($serverNames)) { try { $serverInfo = ServerInfo::makeFromOldConfig()->getProperties(); $serverInfo['name'] = 'server'; $view->servers[] = $serverInfo; } catch (Exception $ex) { // ignore } } else { foreach ($serverNames as $server) { $serverConfig = Config::getServerConfig($server); if (!empty($serverConfig)) { $serverConfig['name'] = $server; $view->servers[] = $serverConfig; } } } $view->ldapConfig = Config::getPluginOptionValuesWithDefaults(); $view->isLoginControllerActivated = PluginManager::getInstance()->isPluginActivated('Login'); $view->updatedFromPre30 = Option::get('LoginLdap_updatedFromPre3_0'); return $view->render(); }
/** * Assigns view properties that would be useful to views that render admin pages. * * Assigns the following variables: * * - **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 */ public static function setBasicVariablesAdminView(View $view) { self::notifyWhenTrackingStatisticsDisabled(); self::notifyIfEAcceleratorIsUsed(); $view->topMenu = MenuTop::getInstance()->getMenu(); $view->userMenu = MenuUser::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'); } $view->isSuperUser = Piwik::hasUserSuperUserAccess(); self::notifyAnyInvalidPlugin(); self::checkPhpVersion($view); if (Piwik::hasUserSuperUserAccess() && self::isPhpVersion53()) { $notification = new Notification(Piwik::translate('General_WarningPhpVersionXIsTooOld', '5.3')); $notification->title = Piwik::translate('General_Warning'); $notification->priority = Notification::PRIORITY_LOW; $notification->context = Notification::CONTEXT_WARNING; $notification->type = Notification::TYPE_TRANSIENT; $notification->flags = Notification::FLAG_NO_CLEAR; NotificationManager::notify('PHP53VersionCheck', $notification); } $adminMenu = MenuAdmin::getInstance()->getMenu(); $view->adminMenu = $adminMenu; $notifications = $view->notifications; if (empty($notifications)) { $view->notifications = NotificationManager::getAllNotificationsToDisplay(); NotificationManager::cancelAllNonPersistent(); } }
/** * Assigns view properties that would be useful to views that render admin pages. * * Assigns the following variables: * * - **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 */ public static function setBasicVariablesAdminView(View $view) { self::notifyWhenTrackingStatisticsDisabled(); $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'); } $view->isSuperUser = Piwik::isUserIsSuperUser(); self::notifyAnyInvalidPlugin(); self::checkPhpVersion($view); $adminMenu = MenuAdmin::getInstance()->getMenu(); $view->adminMenu = $adminMenu; $view->notifications = NotificationManager::getAllNotificationsToDisplay(); NotificationManager::cancelAllNonPersistent(); }
/** * Assigns view properties that would be useful to views that render admin pages. * * Assigns the following variables: * * - **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()`. * - **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 */ public static function setBasicVariablesAdminView(View $view) { self::notifyWhenTrackingStatisticsDisabled(); self::notifyIfEAcceleratorIsUsed(); $view->topMenu = MenuTop::getInstance()->getMenu(); $view->userMenu = MenuUser::getInstance()->getMenu(); $view->isDataPurgeSettingsEnabled = self::isDataPurgeSettingsEnabled(); $enableFrames = PiwikConfig::getInstance()->General['enable_framed_settings']; $view->enableFrames = $enableFrames; if (!$enableFrames) { $view->setXFrameOptions('sameorigin'); } $view->isSuperUser = Piwik::hasUserSuperUserAccess(); self::notifyAnyInvalidPlugin(); self::checkPhpVersion($view); self::notifyWhenPhpVersionIsEOL(); self::notifyWhenDebugOnDemandIsEnabled('debug'); self::notifyWhenDebugOnDemandIsEnabled('debug_on_demand'); $adminMenu = MenuAdmin::getInstance()->getMenu(); $view->adminMenu = $adminMenu; $notifications = $view->notifications; if (empty($notifications)) { $view->notifications = NotificationManager::getAllNotificationsToDisplay(); NotificationManager::cancelAllNonPersistent(); } }
public function markNotificationAsRead() { $notificationId = Common::getRequestVar('notificationId'); NotificationManager::cancel($notificationId); }
/** * Assigns variables to {@link Piwik\View} instances that display an entire page. * * The following variables assigned: * * **date** - The value of the **date** query parameter. * **idSite** - The value of the **idSite** query parameter. * **rawDate** - The value of the **date** query parameter. * **prettyDate** - A pretty string description of the current period. * **siteName** - The current site's name. * **siteMainUrl** - The URL of the current site. * **startDate** - The start date of the current period. A {@link Piwik\Date} instance. * **endDate** - The end date of the current period. A {@link Piwik\Date} instance. * **language** - The current language's language code. * **config_action_url_category_delimiter** - The value of the `[General] action_url_category_delimiter` * INI config option. * **topMenu** - The result of `MenuTop::getInstance()->getMenu()`. * * As well as the variables set by {@link setPeriodVariablesView()}. * * Will exit on error. * * @param View $view * @return void * @api */ protected function setGeneralVariablesView($view) { $view->date = $this->strDate; try { $view->idSite = $this->idSite; if (empty($this->site) || empty($this->idSite)) { throw new Exception("The requested website idSite is not found in the request, or is invalid.\n\t\t\t\tPlease check that you are logged in Piwik and have permission to access the specified website."); } $this->setPeriodVariablesView($view); $rawDate = Common::getRequestVar('date'); $periodStr = Common::getRequestVar('period'); if ($periodStr != 'range') { $date = Date::factory($this->strDate); $period = Period\Factory::build($periodStr, $date); } else { $period = new Range($periodStr, $rawDate, $this->site->getTimezone()); } $view->rawDate = $rawDate; $view->prettyDate = self::getCalendarPrettyDate($period); $view->siteName = $this->site->getName(); $view->siteMainUrl = $this->site->getMainUrl(); $datetimeMinDate = $this->site->getCreationDate()->getDatetime(); $minDate = Date::factory($datetimeMinDate, $this->site->getTimezone()); $this->setMinDateView($minDate, $view); $maxDate = Date::factory('now', $this->site->getTimezone()); $this->setMaxDateView($maxDate, $view); // Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected $dateStart = $period->getDateStart(); if ($dateStart->isEarlier($minDate)) { $dateStart = $minDate; } $dateEnd = $period->getDateEnd(); if ($dateEnd->isLater($maxDate)) { $dateEnd = $maxDate; } $view->startDate = $dateStart; $view->endDate = $dateEnd; $language = LanguagesManager::getLanguageForSession(); $view->language = !empty($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser(); $this->setBasicVariablesView($view); $view->topMenu = MenuTop::getInstance()->getMenu(); $view->userMenu = MenuUser::getInstance()->getMenu(); $notifications = $view->notifications; if (empty($notifications)) { $view->notifications = NotificationManager::getAllNotificationsToDisplay(); NotificationManager::cancelAllNonPersistent(); } } catch (Exception $e) { Piwik_ExitWithMessage($e->getMessage(), $e->getTraceAsString()); } }
public function activate($redirectAfter = true) { $pluginName = $this->initPluginModification(static::ACTIVATE_NONCE); $this->dieIfPluginsAdminIsDisabled(); $this->pluginManager->activatePlugin($pluginName); if ($redirectAfter) { $message = $this->translator->translate('CorePluginsAdmin_SuccessfullyActicated', array($pluginName)); if ($this->settingsProvider->getSystemSettings($pluginName)) { $target = sprintf('<a href="index.php%s#%s">', Url::getCurrentQueryStringWithParametersModified(array('module' => 'CoreAdminHome', 'action' => 'generalSettings')), $pluginName); $message .= ' ' . $this->translator->translate('CorePluginsAdmin_ChangeSettingsPossible', array($target, '</a>')); } $notification = new Notification($message); $notification->raw = true; $notification->title = $this->translator->translate('General_WellDone'); $notification->context = Notification::CONTEXT_SUCCESS; Notification\Manager::notify('CorePluginsAdmin_PluginActivated', $notification); $redirectTo = Common::getRequestVar('redirectTo', '', 'string'); if (!empty($redirectTo) && $redirectTo === 'marketplace') { $this->redirectToIndex('Marketplace', 'overview'); } elseif (!empty($redirectTo) && $redirectTo === 'referrer') { $this->redirectAfterModification($redirectAfter); } else { $plugin = $this->pluginManager->loadPlugin($pluginName); $actionToRedirect = 'plugins'; if ($plugin->isTheme()) { $actionToRedirect = 'themes'; } $this->redirectToIndex('CorePluginsAdmin', $actionToRedirect); } } }
/** * Assigns variables to {@link Piwik\View} instances that display an entire page. * * The following variables assigned: * * **date** - The value of the **date** query parameter. * **idSite** - The value of the **idSite** query parameter. * **rawDate** - The value of the **date** query parameter. * **prettyDate** - A pretty string description of the current period. * **siteName** - The current site's name. * **siteMainUrl** - The URL of the current site. * **startDate** - The start date of the current period. A {@link Piwik\Date} instance. * **endDate** - The end date of the current period. A {@link Piwik\Date} instance. * **language** - The current language's language code. * **config_action_url_category_delimiter** - The value of the `[General] action_url_category_delimiter` * INI config option. * **topMenu** - The result of `MenuTop::getInstance()->getMenu()`. * * As well as the variables set by {@link setPeriodVariablesView()}. * * Will exit on error. * * @param View $view * @return void * @api */ protected function setGeneralVariablesView($view) { $view->idSite = $this->idSite; $this->checkSitePermission(); $this->setPeriodVariablesView($view); $view->siteName = $this->site->getName(); $view->siteMainUrl = $this->site->getMainUrl(); $siteTimezone = $this->site->getTimezone(); $datetimeMinDate = $this->site->getCreationDate()->getDatetime(); $minDate = Date::factory($datetimeMinDate, $siteTimezone); $this->setMinDateView($minDate, $view); $maxDate = Date::factory('now', $siteTimezone); $this->setMaxDateView($maxDate, $view); $rawDate = Common::getRequestVar('date'); Period::checkDateFormat($rawDate); $periodStr = Common::getRequestVar('period'); if ($periodStr != 'range') { $date = Date::factory($this->strDate); $validDate = $this->getValidDate($date, $minDate, $maxDate); $period = Period\Factory::build($periodStr, $validDate); if ($date->toString() !== $validDate->toString()) { // we to not always change date since it could convert a strDate "today" to "YYYY-MM-DD" // only change $this->strDate if it was not valid before $this->setDate($validDate); } } else { $period = new Range($periodStr, $rawDate, $siteTimezone); } // Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected $dateStart = $period->getDateStart(); $dateStart = $this->getValidDate($dateStart, $minDate, $maxDate); $dateEnd = $period->getDateEnd(); $dateEnd = $this->getValidDate($dateEnd, $minDate, $maxDate); if ($periodStr == 'range') { // make sure we actually display the correct calendar pretty date $newRawDate = $dateStart->toString() . ',' . $dateEnd->toString(); $period = new Range($periodStr, $newRawDate, $siteTimezone); } $view->date = $this->strDate; $view->prettyDate = self::getCalendarPrettyDate($period); $view->prettyDateLong = $period->getLocalizedLongString(); $view->rawDate = $rawDate; $view->startDate = $dateStart; $view->endDate = $dateEnd; $language = LanguagesManager::getLanguageForSession(); $view->language = !empty($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser(); $this->setBasicVariablesView($view); $view->topMenu = MenuTop::getInstance()->getMenu(); $view->adminMenu = MenuAdmin::getInstance()->getMenu(); $notifications = $view->notifications; if (empty($notifications)) { $view->notifications = NotificationManager::getAllNotificationsToDisplay(); NotificationManager::cancelAllNonPersistent(); } }
/** * Deactivate default Login module, as both cannot be activated together * * TODO: shouldn't disable Login plugin but have to wait until Dependency Injection is added to core */ public function activate() { if (Manager::getInstance()->isPluginActivated("Login") == true) { Manager::getInstance()->deactivatePlugin("Login"); $notification = new Notification(Piwik::translate('GoogleAuthenticator_LoginPluginDisabled')); $notification->context = Notification::CONTEXT_INFO; Notification\Manager::notify('GoogleAuthenticator_LoginPluginDisabled', $notification); } }
/** * Load the plugins classes installed. * Register the observers for every plugin. */ private function reloadActivatedPlugins() { $pluginsToPostPendingEventsTo = array(); foreach ($this->pluginsToLoad as $pluginName) { if (!$this->isPluginLoaded($pluginName) && !$this->isPluginThirdPartyAndBogus($pluginName)) { $newPlugin = $this->loadPlugin($pluginName); if ($newPlugin === null) { continue; } if ($newPlugin->hasMissingDependencies()) { $this->deactivatePlugin($pluginName); // at this state we do not know yet whether current user has super user access. We do not even know // if someone is actually logged in. $message = Piwik::translate('CorePluginsAdmin_WeDeactivatedThePluginAsItHasMissingDependencies', array($pluginName, $newPlugin->getMissingDependenciesAsString())); $message .= ' '; $message .= Piwik::translate('General_PleaseContactYourPiwikAdministrator'); $notification = new Notification($message); $notification->context = Notification::CONTEXT_ERROR; Notification\Manager::notify('PluginManager_PluginDeactivated', $notification); continue; } $pluginsToPostPendingEventsTo[] = $newPlugin; } } // post pending events after all plugins are successfully loaded foreach ($pluginsToPostPendingEventsTo as $plugin) { EventDispatcher::getInstance()->postPendingEventsTo($plugin); } }
/** * Load the plugins classes installed. * Register the observers for every plugin. */ private function reloadActivatedPlugins() { $pluginsToPostPendingEventsTo = array(); foreach ($this->pluginsToLoad as $pluginName) { if (!$this->isPluginLoaded($pluginName) && !$this->isPluginThirdPartyAndBogus($pluginName)) { $newPlugin = $this->loadPlugin($pluginName); if ($newPlugin === null) { continue; } if ($newPlugin->hasMissingDependencies()) { $this->deactivatePlugin($pluginName); // add this state we do not know yet whether current user has super user access. We do not even know // if someone is actually logged in. $message = sprintf('We disabled the plugin %s as it has missing dependencies.', $pluginName); $message .= ' Please contact your Piwik administrator.'; $notification = new Notification($message); $notification->context = Notification::CONTEXT_ERROR; Notification\Manager::notify('PluginManager_PluginDeactivated', $notification); continue; } $pluginsToPostPendingEventsTo[] = $newPlugin; } } // post pending events after all plugins are successfully loaded foreach ($pluginsToPostPendingEventsTo as $plugin) { EventDispatcher::getInstance()->postPendingEventsTo($plugin); } }
public function activate($redirectAfter = true) { $pluginName = $this->initPluginModification(static::ACTIVATE_NONCE); $this->dieIfPluginsAdminIsDisabled(); \Piwik\Plugin\Manager::getInstance()->activatePlugin($pluginName); if ($redirectAfter) { $plugin = \Piwik\Plugin\Manager::getInstance()->loadPlugin($pluginName); $actionToRedirect = 'plugins'; if ($plugin->isTheme()) { $actionToRedirect = 'themes'; } $message = $this->translator->translate('CorePluginsAdmin_SuccessfullyActicated', array($pluginName)); if (SettingsManager::hasSystemPluginSettingsForCurrentUser($pluginName)) { $target = sprintf('<a href="index.php%s#%s">', Url::getCurrentQueryStringWithParametersModified(array('module' => 'CoreAdminHome', 'action' => 'adminPluginSettings')), $pluginName); $message .= ' ' . $this->translator->translate('CorePluginsAdmin_ChangeSettingsPossible', array($target, '</a>')); } $notification = new Notification($message); $notification->raw = true; $notification->title = $this->translator->translate('General_WellDone'); $notification->context = Notification::CONTEXT_SUCCESS; Notification\Manager::notify('CorePluginsAdmin_PluginActivated', $notification); $this->redirectToIndex('CorePluginsAdmin', $actionToRedirect); } }
private function createUpdateOrInstallView($template, $nonceName) { Piwik::checkUserHasSuperUserAccess(); $this->dieIfPluginsAdminIsDisabled(); $this->displayWarningIfConfigFileNotWritable(); $pluginName = $this->getPluginNameIfNonceValid($nonceName); $view = new View('@Marketplace/' . $template); $this->setBasicVariablesView($view); $view->errorMessage = ''; $view->plugin = array('name' => $pluginName); try { $this->pluginInstaller->installOrUpdatePluginFromMarketplace($pluginName); } catch (\Exception $e) { $notification = new Notification($e->getMessage()); $notification->context = Notification::CONTEXT_ERROR; $notification->type = Notification::TYPE_PERSISTENT; $notification->flags = Notification::FLAG_CLEAR; Notification\Manager::notify('CorePluginsAdmin_InstallPlugin', $notification); Url::redirectToReferrer(); return; } $view->plugin = $this->plugins->getPluginInfo($pluginName); return $view; }