/** * Returns true if it is ok to show some Piwik PRO advertising in the Piwik UI. * @return bool */ public function arePiwikProAdsEnabled() { if ($this->pluginManager->isPluginActivated('EnterpriseAdmin') || $this->pluginManager->isPluginActivated('LoginAdmin') || $this->pluginManager->isPluginActivated('CloudAdmin') || $this->pluginManager->isPluginActivated('WhiteLabel')) { return false; } $showAds = $this->config->General['piwik_pro_ads_enabled']; return !empty($showAds); }
private function assertOnlyTrackerPluginsAreLoaded($expectedPluginNamesLoaded) { // should currently load between 10 and 25 plugins $this->assertLessThan(25, count($this->manager->getLoadedPlugins())); $this->assertGreaterThan(10, count($this->manager->getLoadedPlugins())); // we need to make sure it actually only loaded the correct ones $this->assertEquals($expectedPluginNamesLoaded, array_keys($this->manager->getLoadedPlugins())); }
/** * Get all log table instances defined by any activated and loaded plugin. The returned tables are not sorted in * any order. * @return LogTable[] */ public function getAllLogTables() { if (!isset($this->tablesCache)) { $tables = $this->pluginManager->findMultipleComponents('Tracker', 'Piwik\\Tracker\\LogTable'); $this->tablesCache = array(); foreach ($tables as $table) { $this->tablesCache[] = StaticContainer::get($table); } } return $this->tablesCache; }
/** * @return ReleaseChannel[] */ public function getAllReleaseChannels() { $classNames = $this->pluginManager->findMultipleComponents('ReleaseChannel', 'Piwik\\UpdateCheck\\ReleaseChannel'); $channels = array(); foreach ($classNames as $className) { $channels[] = StaticContainer::get($className); } usort($channels, function (ReleaseChannel $a, ReleaseChannel $b) { if ($a->getOrder() === $b->getOrder()) { return 0; } return $a->getOrder() < $b->getOrder() ? -1 : 1; }); return $channels; }
private function enrichPluginInformation($plugin) { if (empty($plugin)) { return $plugin; } $plugin['isInstalled'] = $this->isPluginInstalled($plugin['name']); $plugin['isActivated'] = $this->isPluginActivated($plugin['name']); $plugin['isInvalid'] = $this->pluginManager->isPluginThirdPartyAndBogus($plugin['name']); $plugin['canBeUpdated'] = $plugin['isInstalled'] && $this->hasPluginUpdate($plugin); $plugin['lastUpdated'] = $this->toShortDate($plugin['lastUpdated']); $plugin['hasExceededLicense'] = !empty($plugin['isInstalled']) && !empty($plugin['shop']) && empty($plugin['isFree']) && empty($plugin['isDownloadable']) && !empty($plugin['consumer']['license']['isValid']) && !empty($plugin['consumer']['license']['isExceeded']); $plugin['isMissingLicense'] = !empty($plugin['isInstalled']) && !empty($plugin['shop']) && empty($plugin['isFree']) && empty($plugin['isDownloadable']) && empty($plugin['consumer']['license']); if (!empty($plugin['owner']) && strtolower($plugin['owner']) === 'piwikpro' && !empty($plugin['homepage']) && strpos($plugin['homepage'], 'pk_campaign') === false) { $plugin['homepage'] = $this->advertising->addPromoCampaignParametersToUrl($plugin['homepage'], Advertising::CAMPAIGN_NAME_PROFESSIONAL_SERVICES, 'Marketplace', $plugin['name']); } if ($plugin['canBeUpdated']) { $pluginUpdate = $this->getPluginUpdateInformation($plugin); $plugin['repositoryChangelogUrl'] = $pluginUpdate['repositoryChangelogUrl']; $plugin['currentVersion'] = $pluginUpdate['currentVersion']; } if (!empty($plugin['activity']['lastCommitDate']) && false === strpos($plugin['activity']['lastCommitDate'], '0000') && false === strpos($plugin['activity']['lastCommitDate'], '1970')) { $plugin['activity']['lastCommitDate'] = $this->toLongDate($plugin['activity']['lastCommitDate']); } else { $plugin['activity']['lastCommitDate'] = null; } if (!empty($plugin['versions'])) { foreach ($plugin['versions'] as $index => $version) { $plugin['versions'][$index]['release'] = $this->toLongDate($version['release']); } } $plugin = $this->addMissingRequirements($plugin); return $plugin; }
public function configureTopMenu(MenuTop $menu) { $login = Piwik::getCurrentUserLogin(); $user = APIUsersManager::getInstance()->getUser($login); if (!empty($user['alias'])) { $login = $user['alias']; } if (Plugin\Manager::getInstance()->isPluginActivated('Feedback')) { $menu->addItem('General_Help', null, array('module' => 'Feedback', 'action' => 'index')); } if (Piwik::isUserIsAnonymous()) { if (Plugin\Manager::getInstance()->isPluginActivated('Feedback')) { $menu->addItem($login, null, array('module' => 'Feedback', 'action' => 'index'), 998); } else { $menu->addItem($login, null, array('module' => 'API', 'action' => 'listAllAPI'), 998); } } else { $menu->addItem($login, null, array('module' => 'UsersManager', 'action' => 'userSettings'), 998); } $module = $this->getLoginModule(); if (Piwik::isUserIsAnonymous()) { $menu->addItem('Login_LogIn', null, array('module' => $module, 'action' => false), 999); } else { $menu->addItem('General_Logout', null, array('module' => $module, 'action' => 'logout', 'idSite' => null), 999); } }
public function installOrUpdatePluginFromMarketplace($pluginName) { $this->checkMarketplaceIsEnabled(); $this->pluginName = $pluginName; try { $this->makeSureFoldersAreWritable(); $this->makeSurePluginNameIsValid(); $tmpPluginZip = $this->downloadPluginFromMarketplace(); $tmpPluginFolder = dirname($tmpPluginZip) . '/' . basename($tmpPluginZip, '.zip') . '/'; $this->extractPluginFiles($tmpPluginZip, $tmpPluginFolder); $this->makeSurePluginJsonExists($tmpPluginFolder); $metadata = $this->getPluginMetadataIfValid($tmpPluginFolder); $this->makeSureThereAreNoMissingRequirements($metadata); $this->copyPluginToDestination($tmpPluginFolder); Filesystem::deleteAllCacheOnUpdate($this->pluginName); $pluginManager = PluginManager::getInstance(); if ($pluginManager->isPluginLoaded($this->pluginName)) { $plugin = PluginManager::getInstance()->getLoadedPlugin($this->pluginName); if (!empty($plugin)) { $plugin->reloadPluginInformation(); } } } catch (\Exception $e) { if (!empty($tmpPluginZip)) { Filesystem::deleteFileIfExists($tmpPluginZip); } if (!empty($tmpPluginFolder)) { $this->removeFolderIfExists($tmpPluginFolder); } throw $e; } $this->removeFileIfExists($tmpPluginZip); $this->removeFolderIfExists($tmpPluginFolder); }
static function update() { $errors = array(); try { $checker = new DoNotTrackHeaderChecker(); // enable DoNotTrack check in PrivacyManager if DoNotTrack plugin was enabled if (\Piwik\Plugin\Manager::getInstance()->isPluginActivated('DoNotTrack')) { $checker->activate(); } // enable IP anonymization if AnonymizeIP plugin was enabled if (\Piwik\Plugin\Manager::getInstance()->isPluginActivated('AnonymizeIP')) { IPAnonymizer::activate(); } } catch (\Exception $ex) { // pass } // disable & delete old plugins $oldPlugins = array('DoNotTrack', 'AnonymizeIP'); foreach ($oldPlugins as $plugin) { try { \Piwik\Plugin\Manager::getInstance()->deactivatePlugin($plugin); } catch (\Exception $e) { } $dir = PIWIK_INCLUDE_PATH . "/plugins/{$plugin}"; if (file_exists($dir)) { Filesystem::unlinkRecursive($dir, true); } if (file_exists($dir)) { $errors[] = "Please delete this directory manually (eg. using your FTP software): {$dir} \n"; } } if (!empty($errors)) { throw new \Exception("Warnings during the update: <br>" . implode("<br>", $errors)); } }
static function update() { try { \Piwik\Plugin\Manager::getInstance()->activatePlugin('PrivacyManager'); } catch (\Exception $e) { } }
/** * Returns a list of available command classnames. * * @return string[] */ private function getAvailableCommands() { $commands = $this->getDefaultPiwikCommands(); $detected = PluginManager::getInstance()->findMultipleComponents('Commands', 'Piwik\\Plugin\\ConsoleCommand'); $commands = array_merge($commands, $detected); /** * Triggered to filter / restrict console commands. Plugins that want to restrict commands * should subscribe to this event and remove commands from the existing list. * * **Example** * * public function filterConsoleCommands(&$commands) * { * $key = array_search('Piwik\Plugins\MyPlugin\Commands\MyCommand', $commands); * if (false !== $key) { * unset($commands[$key]); * } * } * * @param array &$commands An array containing a list of command class names. */ Piwik::postEvent('Console.filterCommands', array(&$commands)); $commands = array_values(array_unique($commands)); return $commands; }
/** * @param InputInterface $input * @param OutputInterface $output * @return array * @throws \RuntimeException */ protected function getPluginName(InputInterface $input, OutputInterface $output) { $overwrite = $input->getOption('overwrite'); $self = $this; $validate = function ($pluginName) use($self, $overwrite) { if (empty($pluginName)) { throw new \RuntimeException('You have to enter a plugin name'); } if (strlen($pluginName) > 40) { throw new \RuntimeException('Your plugin name cannot be longer than 40 characters'); } if (!Plugin\Manager::getInstance()->isValidPluginName($pluginName)) { throw new \RuntimeException(sprintf('The plugin name %s is not valid. The name must start with a letter and is only allowed to contain numbers and letters.', $pluginName)); } $pluginPath = $self->getPluginPath($pluginName); if (file_exists($pluginPath) && !$overwrite) { throw new \RuntimeException('A plugin with this name already exists'); } return $pluginName; }; $pluginName = $input->getOption('name'); if (empty($pluginName)) { $dialog = $this->getHelperSet()->get('dialog'); $pluginName = $dialog->askAndValidate($output, 'Enter a plugin name: ', $validate); } else { $validate($pluginName); } $pluginName = ucfirst($pluginName); return $pluginName; }
protected function isPluginActivated($pluginName) { if (in_array($pluginName, $this->activatedPluginNames)) { return true; } return $this->pluginManager->isPluginActivated($pluginName); }
public function registerWidgets() { if (PluginManager::getInstance()->isPluginActivated('UserCountry')) { WidgetsList::add('General_Visitors', Piwik::translate('UserCountryMap_VisitorMap'), 'UserCountryMap', 'visitorMap'); WidgetsList::add('Live!', Piwik::translate('UserCountryMap_RealTimeMap'), 'UserCountryMap', 'realtimeMap'); } }
public function doUpdate(Updater $updater) { try { Manager::getInstance()->activatePlugin('Monolog'); } catch (\Exception $e) { } }
/** * Create a component instance that exists within a specific plugin. Uses the component's * unqualified class name and expected base type. * * This method will only create a class if it is located within the component type's * associated subdirectory. * * @param string $pluginName The name of the plugin the component is expected to belong to, * eg, `'UserSettings'`. * @param string $componentClassSimpleName The component's class name w/o namespace, eg, * `"GetKeywords"`. * @param string $componentTypeClass The fully qualified class name of the component type, eg, * `"Piwik\Plugin\Report"`. * @return mixed|null A new instance of the desired component or null if not found. If the * plugin is not loaded or activated or the component is not located in * in the sub-namespace specified by `$componentTypeClass::COMPONENT_SUBNAMESPACE`, * this method will return null. */ public static function factory($pluginName, $componentClassSimpleName, $componentTypeClass) { if (empty($pluginName) || empty($componentClassSimpleName)) { return null; } $pluginManager = PluginManager::getInstance(); try { if (!$pluginManager->isPluginActivated($pluginName)) { return null; } $plugin = $pluginManager->getLoadedPlugin($pluginName); } catch (Exception $e) { Log::debug($e); return null; } $subnamespace = $componentTypeClass::COMPONENT_SUBNAMESPACE; $desiredComponentClass = 'Piwik\\Plugins\\' . $pluginName . '\\' . $subnamespace . '\\' . $componentClassSimpleName; $components = $plugin->findMultipleComponents($subnamespace, $componentTypeClass); foreach ($components as $class) { if ($class == $desiredComponentClass) { return new $class(); } } return null; }
static function update() { try { Manager::getInstance()->activatePlugin('Monolog'); } catch (\Exception $e) { } }
/** * Cache buster based on * - Piwik version * - Loaded plugins * - Super user salt * - Latest * * @param string[] $pluginNames * @return string */ public function piwikVersionBasedCacheBuster($pluginNames = false) { $currentGitHash = @file_get_contents(PIWIK_INCLUDE_PATH . '/.git/refs/heads/master'); $pluginList = md5(implode(",", !$pluginNames ? Manager::getInstance()->getLoadedPluginsName() : $pluginNames)); $cacheBuster = md5(SettingsPiwik::getSalt() . $pluginList . PHP_VERSION . Version::VERSION . trim($currentGitHash)); return $cacheBuster; }
public function doUpdate(Updater $updater) { try { \Piwik\Plugin\Manager::getInstance()->activatePlugin('ImageGraph'); } catch (\Exception $e) { } }
public function doUpdate(Updater $updater) { try { \Piwik\Plugin\Manager::getInstance()->activatePlugin('CustomVariables'); } catch (\Exception $e) { } }
/** * Called on plugin deactivation. */ public function deactivate() { // activate default Login module, as one of them is needed to access Piwik if (Manager::getInstance()->isPluginActivated("Login") == false) { Manager::getInstance()->activatePlugin("Login"); } }
function getTopMenuTranslationKey() { // if MobileMessaging is not activated, display 'Email reports' if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated('MobileMessaging')) { return self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; } if (Piwik::isUserIsAnonymous()) { return self::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY; } try { $reports = API::getInstance()->getReports(); $reportCount = count($reports); // if there are no reports and the mobile account is // - not configured: display 'Email reports' // - configured: display 'Email & SMS reports' if ($reportCount == 0) { return APIMobileMessaging::getInstance()->areSMSAPICredentialProvided() ? self::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY : self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; } } catch (\Exception $e) { return self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; } $anyMobileReport = false; foreach ($reports as $report) { if ($report['type'] == MobileMessaging::MOBILE_TYPE) { $anyMobileReport = true; break; } } // if there is at least one sms report, display 'Email & SMS reports' if ($anyMobileReport) { return self::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY; } return self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; }
public function test_getAllDimensions_shouldReturnActionVisitAndConversionDimensions() { Manager::getInstance()->loadPlugins(array('Actions', 'Events', 'DevicesDetector', 'Goals')); $dimensions = Dimension::getAllDimensions(); $this->assertGreaterThan(20, count($dimensions)); $foundConversion = false; $foundVisit = false; $foundAction = false; foreach ($dimensions as $dimension) { if ($dimension instanceof \Piwik\Plugin\Dimension\ConversionDimension) { $foundConversion = true; } else { if ($dimension instanceof \Piwik\Plugin\Dimension\ActionDimension) { $foundAction = true; } else { if ($dimension instanceof \Piwik\Plugin\Dimension\VisitDimension) { $foundVisit = true; } else { $this->fail('Unexpected dimension class found'); } } } $this->assertRegExp('/Piwik.Plugins.(Actions|Events|DevicesDetector|Goals).Columns/', get_class($dimension)); } $this->assertTrue($foundConversion); $this->assertTrue($foundAction); $this->assertTrue($foundVisit); }
public function setUp() { parent::setUp(); Plugin\Manager::getInstance()->activatePlugin('MobileAppMeasurable'); // setup the access layer FakeAccess::$superUser = true; }
public static function update() { try { \Piwik\Plugin\Manager::getInstance()->activatePlugin('Morpheus'); } catch (\Exception $e) { } }
/** * Triggers an event, executing all callbacks associated with it. * * @param string $eventName The name of the event, ie, API.getReportMetadata. * @param array $params The parameters to pass to each callback when executing. * @param bool $pending Whether this event should be posted again for plugins * loaded after the event is fired. * @param array|null $plugins The plugins to post events to. If null, the event * is posted to all plugins. The elements of this array * can be either the Plugin objects themselves * or their string names. */ public function postEvent($eventName, $params, $pending = false, $plugins = null) { if ($pending) { $this->pendingEvents[] = array($eventName, $params); } if (empty($plugins)) { $plugins = \Piwik\Plugin\Manager::getInstance()->getPluginsLoadedAndActivated(); } $callbacks = array(); // collect all callbacks to execute foreach ($plugins as $plugin) { if (is_string($plugin)) { $plugin = \Piwik\Plugin\Manager::getInstance()->getLoadedPlugin($plugin); } $hooks = $plugin->getListHooksRegistered(); if (isset($hooks[$eventName])) { list($pluginFunction, $callbackGroup) = $this->getCallbackFunctionAndGroupNumber($hooks[$eventName]); $callbacks[$callbackGroup][] = is_string($pluginFunction) ? array($plugin, $pluginFunction) : $pluginFunction; } } if (isset($this->extraObservers[$eventName])) { foreach ($this->extraObservers[$eventName] as $callbackInfo) { list($callback, $callbackGroup) = $this->getCallbackFunctionAndGroupNumber($callbackInfo); $callbacks[$callbackGroup][] = $callback; } } // sort callbacks by their importance ksort($callbacks); // execute callbacks in order foreach ($callbacks as $callbackGroup) { foreach ($callbackGroup as $callback) { call_user_func_array($callback, $params); } } }
protected function completeKey($cacheKey) { $pluginManager = PluginManager::getInstance(); $pluginNames = $pluginManager->getLoadedPluginsName(); $cacheKey = $cacheKey . md5(implode('', $pluginNames)) . Translate::getLanguageLoaded(); return $cacheKey; }
public function configureTopMenu(MenuTop $menu) { $login = Piwik::getCurrentUserLogin(); $user = APIUsersManager::getInstance()->getUser($login); if (!empty($user['alias'])) { $login = $user['alias']; } if (Plugin\Manager::getInstance()->isPluginActivated('Feedback')) { $menu->registerMenuIcon('General_Help', 'icon-help'); $menu->addItem('General_Help', null, array('module' => 'Feedback', 'action' => 'index'), $order = 990, Piwik::translate('General_Help')); } $menu->registerMenuIcon($login, 'icon-user'); if (Piwik::isUserIsAnonymous()) { if (Plugin\Manager::getInstance()->isPluginActivated('ScheduledReports')) { $menu->addItem($login, null, array('module' => 'ScheduledReports', 'action' => 'index'), 970, Piwik::translate('ScheduledReports_PersonalEmailReports')); } else { $menu->addItem($login, null, array('module' => 'API', 'action' => 'listAllAPI'), 970, Piwik::translate('API_ReportingApiReference')); } } else { $tooltip = sprintf('%s: %s', Piwik::translate('UsersManager_PersonalSettings'), $login); $menu->addItem($login, null, array('module' => 'UsersManager', 'action' => 'userSettings'), 970, $tooltip); } $module = $this->getLoginModule(); if (Piwik::isUserIsAnonymous()) { $menu->registerMenuIcon('Login_LogIn', 'icon-sign-in'); $menu->addItem('Login_LogIn', null, array('module' => $module, 'action' => false), 1000, Piwik::translate('Login_LogIn')); } else { $menu->registerMenuIcon('General_Logout', 'icon-sign-out'); $menu->addItem('General_Logout', null, array('module' => $module, 'action' => 'logout', 'idSite' => null), 1000, Piwik::translate('General_Logout')); } }
static function update() { Updater::updateDatabase(__FILE__, self::getSql()); try { \Piwik\Plugin\Manager::getInstance()->activatePlugin('Events'); } catch (\Exception $e) { } }
public static function update() { $pluginManager = \Piwik\Plugin\Manager::getInstance(); try { $pluginManager->activatePlugin('Resolution'); } catch (\Exception $e) { } }
public function postLoad() { if (PluginManager::getInstance()->isPluginActivated('UserCountry')) { WidgetsList::add('General_Visitors', Piwik::translate('UserCountryMap_VisitorMap'), 'UserCountryMap', 'visitorMap'); WidgetsList::add('Live!', Piwik::translate('UserCountryMap_RealTimeMap'), 'UserCountryMap', 'realtimeMap'); } Piwik::addAction('Template.leftColumnUserCountry', array('Piwik\\Plugins\\UserCountryMap\\UserCountryMap', 'insertMapInLocationReport')); }