Inheritance: extends Piwik\Plugin
Example #1
0
 public function home()
 {
     $isMarketplaceEnabled = Marketplace::isMarketplaceEnabled();
     $isFeedbackEnabled = Plugin\Manager::getInstance()->isPluginLoaded('Feedback');
     $widgetsList = WidgetsList::get();
     $hasDonateForm = $widgetsList->isDefined('CoreHome', 'getDonateForm');
     $hasPiwikBlog = $widgetsList->isDefined('RssWidget', 'rssPiwik');
     return $this->renderTemplate('home', array('isMarketplaceEnabled' => $isMarketplaceEnabled, 'isFeedbackEnabled' => $isFeedbackEnabled, 'hasDonateForm' => $hasDonateForm, 'hasPiwikBlog' => $hasPiwikBlog));
 }
Example #2
0
 /**
  * PluginInstaller constructor.
  * @param Client|null $client
  */
 public function __construct($client = null)
 {
     if (!empty($client)) {
         $this->marketplaceClient = $client;
     } elseif (Marketplace::isMarketplaceEnabled()) {
         // we load it manually as marketplace might not be loaded
         $this->marketplaceClient = StaticContainer::get('Piwik\\Plugins\\Marketplace\\Api\\Client');
     }
 }
Example #3
0
File: Menu.php Project: piwik/piwik
 public function configureAdminMenu(MenuAdmin $menu)
 {
     $hasSuperUserAcess = Piwik::hasUserSuperUserAccess();
     $isAnonymous = Piwik::isUserIsAnonymous();
     $isMarketplaceEnabled = Marketplace::isMarketplaceEnabled();
     $pluginsUpdateMessage = '';
     if ($hasSuperUserAcess && $isMarketplaceEnabled && $this->marketplacePlugins) {
         $pluginsHavingUpdate = $this->marketplacePlugins->getPluginsHavingUpdate();
         if (!empty($pluginsHavingUpdate)) {
             $pluginsUpdateMessage = sprintf(' (%d)', count($pluginsHavingUpdate));
         }
     }
     if (!$isAnonymous) {
         $menu->addPlatformItem(null, "", $order = 7);
     }
     if ($hasSuperUserAcess) {
         $menu->addSystemItem(Piwik::translate('General_Plugins') . $pluginsUpdateMessage, $this->urlForAction('plugins', array('activated' => '')), $order = 20);
     }
 }
Example #4
0
 private static function notifyAnyInvalidLicense()
 {
     if (!Marketplace::isMarketplaceEnabled()) {
         return;
     }
     if (Piwik::isUserIsAnonymous()) {
         return;
     }
     if (!Piwik::isUserHasSomeAdminAccess()) {
         return;
     }
     $expired = StaticContainer::get('Piwik\\Plugins\\Marketplace\\Plugins\\InvalidLicenses');
     $messageLicenseMissing = $expired->getMessageNoLicense();
     if (!empty($messageLicenseMissing)) {
         $notification = new Notification($messageLicenseMissing);
         $notification->raw = true;
         $notification->context = Notification::CONTEXT_ERROR;
         $notification->title = Piwik::translate('Marketplace_LicenseMissing');
         Notification\Manager::notify('ControllerAdmin_LicenseMissingWarning', $notification);
     }
     $messageExceeded = $expired->getMessageExceededLicenses();
     if (!empty($messageExceeded)) {
         $notification = new Notification($messageExceeded);
         $notification->raw = true;
         $notification->context = Notification::CONTEXT_WARNING;
         $notification->title = Piwik::translate('Marketplace_LicenseExceeded');
         Notification\Manager::notify('ControllerAdmin_LicenseExceededWarning', $notification);
     }
     $messageExpired = $expired->getMessageExpiredLicenses();
     if (!empty($messageExpired)) {
         $notification = new Notification($messageExpired);
         $notification->raw = true;
         $notification->context = Notification::CONTEXT_WARNING;
         $notification->title = Piwik::translate('Marketplace_LicenseExpired');
         Notification\Manager::notify('ControllerAdmin_LicenseExpiredWarning', $notification);
     }
 }
Example #5
0
 private function createPluginsOrThemesView($template, $themesOnly)
 {
     Piwik::checkUserHasSuperUserAccess();
     $view = $this->configureView('@CorePluginsAdmin/' . $template);
     $view->updateNonce = Nonce::getNonce(MarketplaceController::UPDATE_NONCE);
     $view->activateNonce = Nonce::getNonce(static::ACTIVATE_NONCE);
     $view->uninstallNonce = Nonce::getNonce(static::UNINSTALL_NONCE);
     $view->deactivateNonce = Nonce::getNonce(static::DEACTIVATE_NONCE);
     $view->pluginsInfo = $this->getPluginsInfo($themesOnly);
     $users = Request::processRequest('UsersManager.getUsers');
     $view->otherUsersCount = count($users) - 1;
     $view->themeEnabled = $this->pluginManager->getThemeEnabled()->getPluginName();
     $view->pluginNamesHavingSettings = array_keys($this->settingsProvider->getAllSystemSettings());
     $view->isMarketplaceEnabled = Marketplace::isMarketplaceEnabled();
     $view->isPluginsAdminEnabled = CorePluginsAdmin::isPluginsAdminEnabled();
     $view->pluginsHavingUpdate = array();
     $view->marketplacePluginNames = array();
     if (Marketplace::isMarketplaceEnabled() && $this->marketplacePlugins) {
         try {
             $view->marketplacePluginNames = $this->marketplacePlugins->getAvailablePluginNames($themesOnly);
             $view->pluginsHavingUpdate = $this->marketplacePlugins->getPluginsHavingUpdate();
         } catch (Exception $e) {
             // curl exec connection error (ie. server not connected to internet)
         }
     }
     return $view;
 }
Example #6
0
 /**
  * Checks whether a plugin update notification can be enabled or not. It cannot be enabled if for instance the
  * Marketplace is disabled or if update notifications are disabled in general.
  *
  * @return bool
  */
 public static function canBeEnabled()
 {
     $isEnabled = Config::getInstance()->General['enable_update_communication'];
     return Marketplace::isMarketplaceEnabled() && !empty($isEnabled);
 }
Example #7
0
 /**
  * Update Piwik codebase by downloading and installing the latest version.
  *
  * @param bool $https Whether to use HTTPS if supported of not. If false, will use HTTP.
  * @return string[] Return an array of messages for the user.
  * @throws ArchiveDownloadException
  * @throws UpdaterException
  * @throws Exception
  */
 public function updatePiwik($https = true)
 {
     if (!$this->isNewVersionAvailable()) {
         throw new Exception($this->translator->translate('CoreUpdater_ExceptionAlreadyLatestVersion', Version::VERSION));
     }
     SettingsServer::setMaxExecutionTime(0);
     $newVersion = $this->getLatestVersion();
     $url = $this->getArchiveUrl($newVersion, $https);
     $messages = array();
     try {
         $archiveFile = $this->downloadArchive($newVersion, $url);
         $messages[] = $this->translator->translate('CoreUpdater_DownloadingUpdateFromX', $url);
         $extractedArchiveDirectory = $this->decompressArchive($archiveFile);
         $messages[] = $this->translator->translate('CoreUpdater_UnpackingTheUpdate');
         $this->verifyDecompressedArchive($extractedArchiveDirectory);
         $messages[] = $this->translator->translate('CoreUpdater_VerifyingUnpackedFiles');
         if (Marketplace::isMarketplaceEnabled()) {
             // we need to load the marketplace already here, otherwise it will use the new, updated file in Piwik 3
             // we also need to make sure to create a new instance here as otherwise we would change the "global"
             // environment, but we only want to change piwik version temporarily for this task here
             $environment = StaticContainer::getContainer()->make('Piwik\\Plugins\\Marketplace\\Environment');
             $environment->setPiwikVersion($newVersion);
             /** @var \Piwik\Plugins\Marketplace\Api\Client $marketplaceClient */
             $marketplaceClient = StaticContainer::getContainer()->make('Piwik\\Plugins\\Marketplace\\Api\\Client', array('environment' => $environment));
             require_once PIWIK_DOCUMENT_ROOT . '/plugins/CorePluginsAdmin/PluginInstaller.php';
             require_once PIWIK_DOCUMENT_ROOT . '/plugins/Marketplace/Api/Exception.php';
         }
         $this->installNewFiles($extractedArchiveDirectory);
         $messages[] = $this->translator->translate('CoreUpdater_InstallingTheLatestVersion');
     } catch (ArchiveDownloadException $e) {
         throw $e;
     } catch (Exception $e) {
         throw new UpdaterException($e, $messages);
     }
     try {
         if (Marketplace::isMarketplaceEnabled() && !empty($marketplaceClient)) {
             $messages[] = $this->translator->translate('CoreUpdater_CheckingForPluginUpdates');
             $pluginManager = PluginManager::getInstance();
             $pluginManager->loadAllPluginsAndGetTheirInfo();
             $loadedPlugins = $pluginManager->getLoadedPlugins();
             $marketplaceClient->clearAllCacheEntries();
             $pluginsWithUpdate = $marketplaceClient->checkUpdates($loadedPlugins);
             foreach ($pluginsWithUpdate as $pluginWithUpdate) {
                 $pluginName = $pluginWithUpdate['name'];
                 $messages[] = $this->translator->translate('CoreUpdater_UpdatingPluginXToVersionY', array($pluginName, $pluginWithUpdate['version']));
                 $pluginInstaller = new PluginInstaller($marketplaceClient);
                 $pluginInstaller->installOrUpdatePluginFromMarketplace($pluginName);
             }
         }
     } catch (MarketplaceApi\Exception $e) {
         // there is a problem with the connection to the server, ignore for now
     } catch (Exception $e) {
         throw new UpdaterException($e, $messages);
     }
     try {
         $disabledPluginNames = $this->disableIncompatiblePlugins($newVersion);
         if (!empty($disabledPluginNames)) {
             $messages[] = $this->translator->translate('CoreUpdater_DisablingIncompatiblePlugins', implode(', ', $disabledPluginNames));
         }
     } catch (Exception $e) {
         throw new UpdaterException($e, $messages);
     }
     return $messages;
 }