php Piwik-Plugin-Manager类(方法)实例源码

下面列出了php Piwik-Plugin-Manager 类(方法)源码代码实例,从而了解它的用法。

作者:aasso    项目:AnnahdaWebsiteCanva   
/**
  * 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);
 }

作者:diosmosi    项目:piwi   
/**
  * 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;
 }

作者:piwi    项目:piwi   
/**
  * @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;
 }

作者:piwi    项目:piwi   
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;
 }

作者:CaptainShar    项目:SSAD_Projec   
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);
     }
 }

作者:piwi    项目:piwi   
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);
 }

作者:bossrabbi    项目:piwi   
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));
     }
 }

作者:carriercom    项目:piwi   
static function update()
 {
     try {
         \Piwik\Plugin\Manager::getInstance()->activatePlugin('PrivacyManager');
     } catch (\Exception $e) {
     }
 }

作者:jos    项目:CGE-File-Sharin   
/**
  * 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;
 }

作者:piwi    项目:piwi   
/**
  * @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;
 }

作者:piwi    项目:piwi   
protected function isPluginActivated($pluginName)
 {
     if (in_array($pluginName, $this->activatedPluginNames)) {
         return true;
     }
     return $this->pluginManager->isPluginActivated($pluginName);
 }

作者:CaptainShar    项目:SSAD_Projec   
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');
     }
 }

作者:FluentDevelopmen    项目:piwi   
public function doUpdate(Updater $updater)
 {
     try {
         Manager::getInstance()->activatePlugin('Monolog');
     } catch (\Exception $e) {
     }
 }

作者:a4tunad    项目:piwi   
/**
  * 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;
 }

作者:bossrabbi    项目:piwi   
static function update()
 {
     try {
         Manager::getInstance()->activatePlugin('Monolog');
     } catch (\Exception $e) {
     }
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * 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;
 }

作者:FluentDevelopmen    项目:piwi   
public function doUpdate(Updater $updater)
 {
     try {
         \Piwik\Plugin\Manager::getInstance()->activatePlugin('ImageGraph');
     } catch (\Exception $e) {
     }
 }

作者:Joey300    项目:piwik-LoginEncrypte   
/**
  * 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");
     }
 }

作者:brienomatt    项目:elmsl   
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;
 }

作者:Abin    项目:piwi   
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);
 }


问题


面经


文章

微信
公众号

扫码关注公众号