Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <tsteur@users.noreply.github.com>2016-11-15 04:03:59 +0300
committerMatthieu Aubry <mattab@users.noreply.github.com>2016-11-15 04:03:59 +0300
commit587cc39e0362719332d410b7a4d5ddcc68788eeb (patch)
treec982c369cdda542c3a4de08be11c893e5364838c /plugins/Marketplace/Plugins
parent64314b26dbc6619d535002bdb79b9e55d1fc87db (diff)
Update Marketplace to work with new API (#10799)
* starting to port marketplace to piwik 3 * updating tests * fix translation key * fix various issues * use material select * fix plugin upload * deprecate license_homepage plugin metadata and link to a LICENSE[.md|.txt] file if found (#10756) * deprecate license_homepage plugin metadata, and link to a LICENSE[.md|.txt] file if found * Make license view HTML only without menu * fix tests and update * fix some links did not work * we need to show warnings even when plugin is installed, not only when activated. otherwise it is not clear why something is not downloadable * fix install was not working * improved responsiveness of marketplace * fix more tests * fix search was shown when only a few plugins are there * fix ui tests * fix some translations * fix tests and remove duplicated test
Diffstat (limited to 'plugins/Marketplace/Plugins')
-rw-r--r--plugins/Marketplace/Plugins/InvalidLicenses.php238
1 files changed, 238 insertions, 0 deletions
diff --git a/plugins/Marketplace/Plugins/InvalidLicenses.php b/plugins/Marketplace/Plugins/InvalidLicenses.php
new file mode 100644
index 0000000000..1a0a198f67
--- /dev/null
+++ b/plugins/Marketplace/Plugins/InvalidLicenses.php
@@ -0,0 +1,238 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\Plugins\Marketplace\Plugins;
+
+use Piwik\Cache;
+use Piwik\Piwik;
+use Piwik\Plugin;
+use Piwik\Plugins\Marketplace\Api\Client;
+use Piwik\Plugins\Marketplace\Plugins;
+use Piwik\Translation\Translator;
+use Piwik\Url;
+
+/**
+ *
+ */
+class InvalidLicenses
+{
+ /**
+ * @var Client
+ */
+ private $client;
+
+ /**
+ * @var Plugin\Manager
+ */
+ private $pluginManager;
+
+ /**
+ * @var Translator
+ */
+ private $translator;
+
+ /**
+ * @var Cache\Eager
+ */
+ private $cache;
+
+ /**
+ * @var array
+ */
+ private $activatedPluginNames = array();
+
+ private $plugins;
+
+ private $cacheKey = 'Marketplace_ExpiredPlugins';
+
+ public function __construct(Client $client, Cache\Eager $cache, Translator $translator, Plugins $plugins)
+ {
+ $this->client = $client;
+ $this->translator = $translator;
+ $this->pluginManager = Plugin\Manager::getInstance();
+ $this->cache = $cache;
+ $this->plugins = $plugins;
+ }
+
+ public function getPluginNamesOfInvalidLicenses()
+ {
+ // it is very important this is cached, otherwise performance may decrease a lot. Eager cache is currently
+ // cached for 12 hours. In case we lower ttl for eager cache it might be worth considering to change to another
+ // cache
+ if ($this->cache->contains($this->cacheKey)) {
+ $expiredPlugins = $this->cache->fetch($this->cacheKey);
+ } else {
+ $expiredPlugins = $this->getPluginNamesToExpireInCaseLicenseIsInvalid();
+ $this->cache->save($this->cacheKey, $expiredPlugins);
+ }
+
+ return $expiredPlugins;
+ }
+
+ public function clearCache()
+ {
+ $this->cache->delete($this->cacheKey);
+ }
+
+ public function getMessageExceededLicenses()
+ {
+ $plugins = $this->getPluginNamesOfInvalidLicenses();
+
+ if (empty($plugins['exceeded'])) {
+ return;
+ }
+
+ $plugins = '<strong>' . implode('</strong>, <strong>', $plugins['exceeded']) . '</strong>';
+ $loginUrl = $this->getLoginLink();
+ $loginUrlEnd = '';
+ if (!empty($loginUrl)) {
+ $loginUrlEnd = '</a>';
+ }
+
+ $message = $this->translator->translate('Marketplace_LicenseExceededDescription', array($plugins, '<br/>', "<strong>" . $loginUrl, $loginUrlEnd . "</strong>"));
+
+ if (Piwik::hasUserSuperUserAccess()) {
+ $message .= ' ' . $this->getSubscritionSummaryMessage();
+ }
+
+ return $message;
+ }
+
+ public function getMessageNoLicense()
+ {
+ $plugins = $this->getPluginNamesOfInvalidLicenses();
+
+ if (empty($plugins['noLicense'])) {
+ return;
+ }
+
+ $plugins = '<strong>' . implode('</strong>, <strong>', $plugins['noLicense']) . '</strong>';
+ $loginUrl = $this->getLoginLink();
+ $loginUrlEnd = '';
+ if (!empty($loginUrl)) {
+ $loginUrlEnd = '</a>';
+ }
+
+ $message = $this->translator->translate('Marketplace_LicenseMissingDescription', array($plugins, '<br/>', "<strong>" . $loginUrl, $loginUrlEnd. "</strong>"));
+
+ if (Piwik::hasUserSuperUserAccess()) {
+ $message .= ' ' . $this->getSubscritionSummaryMessage();
+ }
+
+ return $message;
+ }
+
+ public function getMessageExpiredLicenses()
+ {
+ $plugins = $this->getPluginNamesOfInvalidLicenses();
+
+ if (empty($plugins['expired'])) {
+ return;
+ }
+
+ $plugins = '<strong>' . implode('</strong>, <strong>', $plugins['expired']) . '</strong>';
+ $loginUrl = $this->getLoginLink();
+ $loginUrlEnd = '';
+ if (!empty($loginUrl)) {
+ $loginUrlEnd = '</a>';
+ }
+
+ $message = $this->translator->translate('Marketplace_LicenseExpiredDescription', array($plugins, '<br/>', "<strong>" . $loginUrl, $loginUrlEnd . "</strong>"));
+
+ if (Piwik::hasUserSuperUserAccess()) {
+ $message .= ' ' . $this->getSubscritionSummaryMessage();
+ }
+
+ return $message;
+ }
+
+ private function getLoginLink()
+ {
+ $info = $this->client->getInfo();
+
+ if (empty($info['loginUrl'])) {
+ return '';
+ }
+
+ return '<a href="' . $info['loginUrl'] . '" target="_blank" rel="noreferrer">';
+ }
+
+ private function getSubscritionSummaryMessage()
+ {
+ $url = Url::getCurrentQueryStringWithParametersModified(array(
+ 'module' => 'Marketplace', 'action' => 'subscriptionOverview'
+ ));
+
+ $link = '<a href="' . $url . '">';
+
+ return "<br/>" . $this->translator->translate('Marketplace_ViewSubscriptionsSummary', array($link, '</a>'));
+ }
+
+ private function getPluginNamesToExpireInCaseLicenseIsInvalid()
+ {
+ $pluginNames = array(
+ 'exceeded' => array(),
+ 'expired' => array(),
+ 'noLicense' => array()
+ );
+
+ try {
+ $paidPlugins = $this->plugins->getAllPaidPlugins();
+ } catch (\Exception $e) {
+ return $pluginNames;
+ }
+
+ if (!empty($paidPlugins)) {
+ foreach ($paidPlugins as $plugin) {
+ $pluginName = $plugin['name'];
+ if ($this->isPluginActivated($pluginName)) {
+ if (empty($plugin['consumer']['license'])) {
+ $pluginNames['noLicense'][] = $pluginName;
+ } elseif (!empty($plugin['consumer']['license']['isExceeded'])) {
+ $pluginNames['exceeded'][] = $pluginName;
+ } elseif (isset($plugin['consumer']['license']['isValid'])
+ && empty($plugin['consumer']['license']['isValid'])) {
+ $pluginNames['expired'][] = $pluginName;
+ }
+ }
+ }
+ }
+
+ return $pluginNames;
+ }
+
+ /**
+ * for tests only
+ * @param array $pluginNames
+ * @internal
+ * @ignore
+ */
+ public function setActivatedPluginNames($pluginNames)
+ {
+ $this->activatedPluginNames = $pluginNames;
+ }
+
+ protected function isPluginInstalled($pluginName)
+ {
+ if (in_array($pluginName, $this->activatedPluginNames)) {
+ return true;
+ }
+
+ return $this->pluginManager->isPluginInstalled($pluginName);
+ }
+
+ protected function isPluginActivated($pluginName)
+ {
+ if (in_array($pluginName, $this->activatedPluginNames)) {
+ return true;
+ }
+
+ return $this->pluginManager->isPluginActivated($pluginName);
+ }
+
+}