/** * Action of license key registration * * @return void */ protected function doActionRegisterKey() { $key = \XLite\Core\Request::getInstance()->key; $addonsInfo = \XLite\Core\Marketplace::getInstance()->checkAddonKey($key); if ($addonsInfo && $addonsInfo[$key]) { $addonsInfo = $addonsInfo[$key]; $repo = \XLite\Core\Database::getRepo('\\XLite\\Model\\ModuleKey'); foreach ($addonsInfo as $info) { $module = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->findOneBy(array('author' => $info['author'], 'name' => $info['name'])); if ($module) { $entity = $repo->findKey($info['author'], $info['name']); if ($entity) { $entity->setKeyValue($key); $repo->update($entity); } else { $entity = $repo->insert($info + array('keyValue' => $key)); } \XLite\Core\Database::getEM()->flush(); // Clear cache for proper installation \XLite\Core\Marketplace::getInstance()->clearActionCache(\XLite\Core\Marketplace::ACTION_GET_ADDONS_LIST); $this->showInfo(__FUNCTION__, 'License key has been successfully verified for "{{name}}" module by "{{author}}" author', array('name' => $module->getModuleName(), 'author' => $module->getAuthorName())); } else { $this->showError(__FUNCTION__, 'Key is validated, but the module [' . implode(',', $info) . '] was not found'); } } } else { $error = \XLite\Core\Marketplace::getInstance()->getError(); if ($error) { $this->showError(__FUNCTION__, 'Response from marketplace: ' . $error); } else { $this->showError(__FUNCTION__, 'Response from marketplace is not received'); } } $this->setReturnURL($this->buildURL('addons_list_marketplace')); }
/** * Get list of upgrade waves * * @return array */ protected function getWaves() { if (!isset(static::$waves)) { static::$waves = \XLite\Core\Marketplace::getInstance()->getWaves(); } return static::$waves; }
/** * Initialize controller * * @return void */ public function init() { parent::init(); // Download data from marketplace \XLite\Core\Marketplace::getInstance()->saveAddonsList(); // Download data from marketplace \XLite\Core\Marketplace::getInstance()->checkAddonsKeys(); }
/** * Check if marketplace is accessible * * The admin is able to access the marketplate if: * 1) PHAR is installed on the server (the module packages can be installed to the shop) * * and * * 2) The marketplace is online and the cache is up-to-dated * * @return boolean */ public function isMarketplaceAccessible() { // Check Phar availability and marketplace accessibility $result = extension_loaded('phar') && \XLite\Core\Marketplace::getInstance()->doTestMarketplace(); if ($result) { // Check modules from marketplace is presented in the database $cnd = new \XLite\Core\CommonCell(); $cnd->{\XLite\Model\Repo\Module::P_FROM_MARKETPLACE} = true; $countModules = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->search($cnd, true); $result = 0 < $countModules; } return $result; }
/** * Return LICENSE text for the module * * @return string */ public function getLicense() { $result = null; $info = \XLite\Core\Marketplace::getInstance()->getAddonInfo($this->getModule()->getMarketplaceID()); if ($info) { $result = $info[\XLite\Core\Marketplace::FIELD_LICENSE]; } else { $this->showError(__FUNCTION__, 'License is not received'); } // Since this action is performed in popup if (!isset($result)) { $this->redirect(); } return $result; }
/** * Fetch messages * * @return array */ protected function fetchMessages() { $result = array(); $messages = \XLite\Core\Marketplace::getInstance()->getXC5Notifications(); if ($messages) { foreach ($messages as $message) { if ($message['type'] == 'warning') { $result[] = $message; } } } return $result; }
/** * Check if there are updates (new core revision and/or module revisions) * * @return boolean */ protected function areUpdatesAvailable() { if (!isset($this->updateFlags)) { $this->updateFlags = \XLite\Core\Marketplace::getInstance()->checkForUpdates(); if (!is_array($this->updateFlags)) { $this->updateFlags = array(); } } return !empty($this->updateFlags[\XLite\Core\Marketplace::FIELD_ARE_UPDATES_AVAILABLE]); }
/** * Define body classes * * @param array $classes Classes * * @return array */ public function defineBodyClasses(array $classes) { $classes = parent::defineBodyClasses($classes); $auth = \XLite\Core\Auth::getInstance(); if ($auth->isLogged() && $auth->getProfile()->isAdmin() == \XLite::isAdminZone()) { $flags = \XLite\Core\Marketplace::getInstance()->checkForUpdates(); if (is_array($flags) && (!empty($flags[\XLite\Core\Marketplace::FIELD_ARE_UPDATES_AVAILABLE]) || !empty($flags[\XLite\Core\Marketplace::FIELD_IS_UPGRADE_AVAILABLE]))) { $classes[] = 'upgrade-box-visible'; } if (!empty($_COOKIE['XCAdminLeftMenuCompressed'])) { $classes[] = 'left-menu-compressed'; } } if ($auth->isAdmin()) { $classes[] = 'login-page'; } if ($this->isForceChangePassword()) { $classes[] = 'force-change-password-section'; } return $classes; }
/** * Uninstall module * * @return void */ protected function doActionUninstall() { $module = $this->getModule(); if ($module) { $pack = new \XLite\Core\Pack\Module($module); $dirs = $pack->getDirs(); $nonWritableDirs = array(); // Check permissions foreach ($dirs as $dir) { if (!\Includes\Utils\FileManager::isDirWriteable($dir)) { $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT); } } $params = array('name' => $module->getActualName()); if (empty($nonWritableDirs)) { $yaml = \Includes\Utils\FileManager::read(\Includes\Utils\ModulesManager::getModuleYAMLFile($module->getAuthor(), $module->getName())); // Remove from FS foreach ($dirs as $dir) { \Includes\Utils\FileManager::unlinkRecursive($dir); } // Disable this and depended modules \Includes\Utils\ModulesManager::disableModule($module->getActualName()); \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName()); // Remove from DB \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->delete($module); if ($module->getModuleID()) { $message = 'A DB error occured while uninstalling the module "{{name}}"'; $this->showError(__FUNCTION__, $message, $params); } else { if (!empty($yaml)) { \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml); } $message = 'The module "{{name}}" has been uninstalled successfully'; $this->showInfo(__FUNCTION__, $message, $params); } // To restore previous state \XLite\Core\Marketplace::getInstance()->saveAddonsList(0); // Flag to rebuild cache \XLite::setCleanUpCacheFlag(true); } else { $message = 'Unable to delete module "{{name}}" files: some dirs have no writable permissions: {{dirs}}'; $this->showError(__FUNCTION__, $message, $params + array('dirs' => implode(', ', $nonWritableDirs))); } } }
/** * Protected constructor * * @return void */ protected function __construct() { parent::__construct(); // Upload addons info into the database \XLite\Core\Marketplace::getInstance()->saveAddonsList($this->getCacheTTL()); list($entries, $incompatibleModules, $isUpgraded) = \XLite\Core\TmpVars::getInstance()->{self::CELL_NAME}; if (is_array($entries)) { $this->entries = array_merge($this->entries, $entries); $this->incompatibleModules = $this->incompatibleModules + (array) $incompatibleModules; $this->setUpgraded(!empty($isUpgraded)); } else { $this->collectEntries(); } }
/** * Check if the core has update (but not upgrade) available * * @return boolean */ protected function hasCoreUpdate() { $update = \XLite\Core\Marketplace::getInstance()->checkForUpdates(); return !empty($update) && ($update[\XLite\Core\Marketplace::FIELD_ARE_UPDATES_AVAILABLE] && !$update[\XLite\Core\Marketplace::FIELD_IS_UPGRADE_AVAILABLE]); }
/** * Marketplace modules list (nonFree and Business) * * @param boolean $enabledFlag Edition OPTIONAL * * @return array */ public function getBusinessEditionModulesList() { $result = array(); $cnd = new \XLite\Core\CommonCell(); $cnd->{static::P_FROM_MARKETPLACE} = true; $modules = $this->search($cnd); $freeEdition = \XLite\Core\Marketplace::getInstance()->getFreeLicenseEdition(); foreach ($modules as $key => $module) { $editions = $module->getEditionNames(); if (!empty($editions) && !in_array($freeEdition, $editions)) { $installedModule = $this->findOneBy(array('name' => $module->getName(), 'author' => $module->getAuthor(), 'fromMarketplace' => 0, 'installed' => 1)); \XLite\Core\Database::getEM()->detach($module); if ($installedModule) { $module->setInstalled(true); $module->setEnabled($installedModule->getEnabled()); } elseif (!in_array('Business', $editions) || preg_match('/\\[DEPRECATED\\]$/', $module->getModuleName())) { continue; } $result[$key] = $module; } } return $result; }
/** * Defines the tags data structure * * @return array */ protected function getTagsData() { $result = array(); foreach (\XLite\Core\Marketplace::getInstance()->getAllTags() as $tag) { $result[$tag] = $this->buildURL('addons_list_marketplace', '', array('tag' => $tag, 'clearPager' => '1', 'clearSearch' => 1)); } return $result; }
/** * Clear marketplace cache * * @return void */ protected function doActionClearCache() { \XLite\Core\Marketplace::getInstance()->clearActionCache(); $params = \XLite\Core\Request::getInstance()->landing ? array('landing' => 1) : array(); $this->setReturnURL($this->buildURL('addons_list_marketplace', '', $params)); }
/** * Initialize handler * * @return void */ public function init() { \XLite\Core\Marketplace::getInstance()->getXC5Notifications(); }
/** * Return list of core versions for update * * @return array */ protected function getCoreVersions() { if (!isset($this->coreVersions)) { $this->coreVersions = (array) \XLite\Core\Marketplace::getInstance()->getCores(); } return $this->coreVersions; }
/** * Module has license restriction if the core has free license but the module does not have free edition * The empty editions field means the module has no license restriction * * @return boolean */ public function hasLicenseRestriction() { $result = false; $coreKey = \XLite::getXCNLicenseKey(); // The store without any license (trial license active) has no license-restricted module if ($coreKey !== '') { $editions = $this->getEditionNames(); // The module with the empty editions structure has no restrictions if (!empty($editions)) { $freeEdition = \XLite\Core\Marketplace::getInstance()->getFreeLicenseEdition(); // Module has restricted if there is no freeEdition in the editions structure $result = !in_array($freeEdition, $editions); } } return $result; }
/** * Get container tag attributes * * @return array */ protected function getContainerTagAttributes() { $state = 'post-opened'; $tmpVarHash = \XLite\Core\TmpVars::getInstance()->{static::READ_MARK_KEY}; $realHash = \XLite\Core\Marketplace::getInstance()->unseenUpdatesHash(); if ($realHash !== $tmpVarHash) { \XLite\Core\TmpVars::getInstance()->{static::READ_MARK_KEY} = null; } elseif (!empty($tmpVarHash)) { $state = 'post-closed'; } return array('class' => array('upgrade-box', $state)); }
/** * Download package * * @return boolean */ public function download() { $result = false; $majorVersion = $this->getMajorVersionNew(); $minorVersion = $this->getMinorVersionNew(); $path = \XLite\Core\Marketplace::getInstance()->getCorePack($majorVersion, $minorVersion); $params = array('major' => $majorVersion, 'minor' => $minorVersion); if (isset($path)) { $this->addFileInfoMessage('Core pack (v.{{major}}.{{minor}}) is received', $path, true, $params); $this->setRepositoryPath($path); $this->saveHashesForInstalledFiles(); $result = parent::download(); } else { $this->addFileErrorMessage('Core pack (v.{{major}}.{{minor}}) is not received', \XLite\Core\Marketplace::getInstance()->getError(), true, $params); } return $result; }
/** * Download package * * @return boolean */ public function download() { $result = false; $licenseKey = $this->getModuleForUpgrade()->getLicenseKey(); $path = \XLite\Core\Marketplace::getInstance()->getAddonPack($this->getMarketplaceID(), $licenseKey ? $licenseKey->getKeyValue() : null); $params = array('name' => $this->getActualName()); if (isset($path)) { $this->addFileInfoMessage('Module pack ("{{name}}") is received', $path, true, $params); $this->setRepositoryPath($path); $this->saveHashesForInstalledFiles(); $result = parent::download(); } else { $error = \XLite\Core\Marketplace::getInstance()->getError(); if (static::LICENSE_ERROR === $error) { $this->addToPremiumLicenseModules(); } else { $this->addFileErrorMessage('Module pack ("{{name}}") is not received', $error, true, $params); } } return $result; }
/** * Defines the tag promo banner * * @return boolean|array */ protected function getPromoBanner() { if (is_null($this->bannerInfo)) { $this->bannerInfo = false; $tag = $this->getTagValue(); if ($tag && !$this->isLandingPage()) { $tags = \XLite\Core\Marketplace::getInstance()->getAllTagsInfo(); if (isset($tags[$tag])) { $tagInfo = $tags[$tag]; // We show promo banner if // banner image is defined // and // module for banner is defined // and // banner is not expired (or expiration date is 0, nonexpiry-type banner) if ($tagInfo[\XLite\Core\Marketplace::FIELD_TAG_BANNER_IMG] && (!empty($tagInfo[\XLite\Core\Marketplace::FIELD_TAG_MODULE_BANNER]) || !empty($tagInfo[\XLite\Core\Marketplace::FIELD_TAG_BANNER_URL])) && $this->isPromoBannerActive($tagInfo[\XLite\Core\Marketplace::FIELD_TAG_BANNER_EXPIRATION_DATE])) { $this->bannerInfo = array('banner_url' => $tagInfo[\XLite\Core\Marketplace::FIELD_TAG_BANNER_IMG], 'module_banner_url' => !empty($tagInfo[\XLite\Core\Marketplace::FIELD_TAG_BANNER_URL]) ? $tagInfo[\XLite\Core\Marketplace::FIELD_TAG_BANNER_URL] : $this->getBannerURL($tagInfo[\XLite\Core\Marketplace::FIELD_TAG_MODULE_BANNER]), 'is_external_link' => !empty($tagInfo[\XLite\Core\Marketplace::FIELD_TAG_BANNER_URL])); } } } } return $this->bannerInfo; }
/** * The certain request handler * * @param integer $ttl Data TTL OPTIONAL * * @return boolean */ public function checkAddonsKeys($ttl = self::TTL_LONG) { $repoModuleKey = \XLite\Core\Database::getRepo('\\XLite\\Model\\ModuleKey'); $keys = array_unique(\Includes\Utils\ArrayManager::getObjectsArrayFieldValues($repoModuleKey->findAll(), 'getKeyValue', true)); $result = $this->performActionWithTTL($ttl, static::ACTION_CHECK_ADDON_KEY, array(static::FIELD_KEY => $keys), false); if (static::TTL_NOT_EXPIRED !== $result) { $repoModule = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module'); foreach ((array) $result as $key => $addonsInfo) { $repoModuleKey->deleteInBatch($repoModuleKey->findBy(array('keyValue' => $key))); foreach ($addonsInfo as $info) { $module = $repoModule->findOneBy(array('author' => $info['author'], 'name' => $info['name'])); if ($module) { $repoModuleKey->insert($info + array('keyValue' => $key)); // Clear cache for proper installation \XLite\Core\Marketplace::getInstance()->clearActionCache(\XLite\Core\Marketplace::ACTION_GET_ADDONS_LIST); } else { // No module has been found } } } } return (bool) $result; }
/** * Preprocess option Environment - update_wave * * @param \XLite\Model\Config $option Option entity * * @return boolean */ protected function preprocessUpgradeWaveOption($option) { $result = false; $value = $option->getNewValue(); $waves = \XLite\Core\Marketplace::getInstance()->getWaves(); if ($waves && isset($waves[$value])) { if (\XLite\Core\Marketplace::getInstance()->changeKeysWave($value)) { \XLite\Core\TopMessage::addInfo('Upgrade access level has been successfully assigned to your license keys'); $result = true; } else { \XLite\Core\TopMessage::addError('Could not assign upgrade access level to your license keys'); } } return $result; }
/** * testIsCustom * * @return void * @see ____func_see____ * @since 1.0.0 */ public function testIsCustom() { $module = $this->getTestModule1(); if (\XLite\Core\Marketplace::getInstance()->saveAddonsList()) { $this->markTestSkipped('LC can not update module data from marketplace'); } $this->assertFalse($module->isCustom(), 'check if module ' . self::TEST_MODULE_1 . ' is custom [1]'); }
/** * Run controller * * @return void */ protected function run() { \XLite\Core\Marketplace::getInstance()->updateShippingMethods(); parent::run(); }
/** * Get purchase page URL * * :FIXME: is it really needed? * * @return string */ protected function getPurchaseURL() { $apiURL = trim(\Includes\Utils\Converter::trimTrailingChars(\XLite\Core\Marketplace::getInstance()->getMarketplaceURL(), '/')); // Remove 'api' directory $apiURL = preg_replace('/\\?q=.+/Ss', '', $apiURL); $apiURL = preg_replace('/\\/api$/Ss', '/', $apiURL); return $apiURL; }
/** * Request marketplace to resend license key info on the specified email * * @return void */ protected function doActionResendKey() { $result = \XLite\Core\Marketplace::getInstance()->doResendLicenseKey(\XLite\Core\Request::getInstance()->email); if ($result) { \XLite\Core\TopMessage::addInfo('Information about free license key has been sent', array('email' => \XLite\Core\Request::getInstance()->email)); } else { \XLite\Core\TopMessage::addError(\XLite\Core\Marketplace::getInstance()->getError()); } $this->setReturnURL($this->buildURL('activate_free_license')); }
/** * Protected constructor * * @return void */ protected function __construct() { parent::__construct(); // Upload addons info into the database \XLite\Core\Marketplace::getInstance()->saveAddonsList($this->getCacheTTL()); $coreVersionBeforeUpgrade = \XLite\Core\Config::getInstance()->Internal->coreVersionBeforeUpgrade; // WARNING! Do not change the order of the structure data. // The NEW information must be added to the TAIL of the structure strictly! list($entries, $isUpgraded, $disabledModulesHooks, $incompatibleModules, $preUpgradeWarningModules) = \XLite\Core\TmpVars::getInstance()->{self::CELL_NAME}; // Hack for the 5.1.2 and previous versions. // @see #BUG-537 for more details if ($coreVersionBeforeUpgrade && version_compare($coreVersionBeforeUpgrade, '5.1.2', '<=')) { list($entries, $incompatibleModules, $isUpgraded, $disabledModulesHooks, $preUpgradeWarningModules) = \XLite\Core\TmpVars::getInstance()->{self::CELL_NAME}; } if (is_array($entries)) { $this->entries = array_merge($this->entries, $entries); $this->incompatibleModules = $this->incompatibleModules + (array) $incompatibleModules; $this->disabledModulesHooks = $this->disabledModulesHooks + (array) $disabledModulesHooks; $this->preUpgradeWarningModules = $this->preUpgradeWarningModules + (array) $preUpgradeWarningModules; $this->setUpgraded(!empty($isUpgraded)); } else { $this->collectEntries(); } }
/** * Action 'Re-validate license keys' * * @return void */ protected function doActionValidateKeys() { $result = \XLite\Core\Marketplace::getInstance()->checkAddonsKeys(10); $this->setReturnURL($this->buildURL('upgrade')); }
/** * Return upgrade flags * * @return array */ protected function getUpdateFlags() { if (!isset($this->updateFlags)) { $this->updateFlags = \XLite\Core\Marketplace::getInstance()->checkForUpdates(); } return is_array($this->updateFlags) ? $this->updateFlags : array(); }