/** * Return list of module directories which contain templates * * @return array */ protected function getSkinDirs() { $result = array(); foreach (\XLite\Core\Layout::getInstance()->getSkinsAll() as $interface => $tmp) { $result = array_merge($result, \XLite\Core\Layout::getInstance()->getSkinPaths($interface)); } foreach ($result as $key => &$data) { $path = \Includes\Utils\ModulesManager::getRelativeDir($this->module->getAuthor(), $this->module->getName()); $path = $data['fs'] . LC_DS . 'modules' . LC_DS . $path; if (\Includes\Utils\FileManager::isDirReadable($path)) { $data = $path; } else { unset($result[$key]); } } return array_values(array_unique($result)); }
/** * Helper to search module with the same name and author * * @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder to prepare * @param \XLite\Model\Module $module Module to get info from * * @return \Doctrine\ORM\QueryBuilder */ protected function prepareCndSingleModuleSearch(\Doctrine\ORM\QueryBuilder $queryBuilder, \XLite\Model\Module $module) { $queryBuilder->andWhere('m.name = :name')->andWhere('m.author = :author')->setParameter('name', $module->getName())->setParameter('author', $module->getAuthor())->setMaxResults(1); }
/** * {@inheritDoc} */ public function getAuthor() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getAuthor', array()); return parent::getAuthor(); }
/** * Returns skin preview image URL * * @param \XLite\Model\Module $module Skin module * @param string $color Color * @param string $type Layout type * * @return string */ public function getLayoutPreview($module, $color, $type) { $result = null; $path = $module && $module instanceof \XLite\Model\Module ? 'modules/' . $module->getAuthor() . '/' . $module->getName() . '/' : 'images/layout/'; $image = 'preview' . ($color ? '_' . $color : '') . ($type ? '_' . $type : '') . '.jpg'; $result = $this->getResourceWebPath($path . $image); if (null === $result) { $image = 'preview' . ($color ? '_' . $color : '') . '.jpg'; $result = $this->getResourceWebPath($path . $image); } if (null === $result) { $image = 'preview' . ($type ? '_' . $type : '') . '.jpg'; $result = $this->getResourceWebPath($path . $image); } if (null === $result) { $image = 'preview.jpg'; $result = $this->getResourceWebPath($path . $image); } return $result ?: $this->getResourceWebPath('images/layout/preview_placeholder.jpg'); }
/** * Uninstall module * * @param \XLite\Model\Module $module Module object * @param array &$messages Messages list * * @return boolean */ public function uninstallModule(\XLite\Model\Module $module, &$messages) { $result = false; // Get module pack $pack = new \XLite\Core\Pack\Module($module); $dirs = $pack->getDirs(); $nonWritableDirs = array(); // Check module directories permissions foreach ($dirs as $dir) { if (\Includes\Utils\FileManager::isExists($dir) && !\Includes\Utils\FileManager::isDirWriteable($dir)) { $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT); } } $params = array('name' => sprintf('%s v%s (%s)', $module->getModuleName(), $module->getVersion(), $module->getAuthorName())); if (empty($nonWritableDirs)) { $yamlData = array(); $yamlFiles = \Includes\Utils\ModulesManager::getModuleYAMLFiles($module->getAuthor(), $module->getName()); foreach ($yamlFiles as $yamlFile) { $yamlData[] = \Includes\Utils\FileManager::read($yamlFile); } if (!$module->checkModuleMainClass()) { $classFile = LC_DIR_CLASSES . \Includes\Utils\Converter::getClassFile($module->getMainClass()); if (\Includes\Utils\FileManager::isFileReadable($classFile)) { require_once $classFile; } } // Call uninstall event method $r = $module->callModuleMethod('callUninstallEvent', 111); if (111 == $r) { \XLite\Logger::getInstance()->log($module->getActualName() . ': Method callUninstallEvent() was not called'); } // Remove from FS foreach ($dirs as $dir) { \Includes\Utils\FileManager::unlinkRecursive($dir); } \Includes\Utils\ModulesManager::disableModule($module->getActualName()); \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName()); // Remove module from DB try { // Refresh module entity as it was changed by disableModule() method above $module = $this->find($module->getModuleID()); $this->delete($module); } catch (\Exception $e) { $messages[] = $e->getMessage(); } if ($module->getModuleID()) { $messages[] = \XLite\Core\Translation::getInstance()->translate('A DB error occured while uninstalling the module X', $params); } else { if (!empty($yamlData)) { foreach ($yamlData as $yaml) { \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml); } } $messages[] = \XLite\Core\Translation::getInstance()->translate('The module X has been uninstalled successfully', $params); $result = true; } } else { $messages[] = \XLite\Core\Translation::getInstance()->translate('Unable to delete module X files: some dirs have no writable permissions: Y', $params + array('dirs' => implode(', ', $nonWritableDirs))); } return $result; }
/** * Module page URL getter * * @param \XLite\Model\Module $module Module * * @return string */ protected function getModulePageURL(\XLite\Model\Module $module) { $params = array('clearCnd' => 1, 'clearSearch' => 1); $pageId = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->getInstalledPageId($module->getAuthor(), $module->getName(), \XLite\View\Pager\Admin\Module\Manage::getInstance()->getItemsPerPage()); if (0 < $pageId) { $params[\XLite\View\Pager\APager::PARAM_PAGE_ID] = $pageId; } return $this->buildURL('addons_list_installed', '', $params) . '#' . $module->getName(); }
/** * Check if the XC module notice must be displayed. * The notice is displayed when the module is a part of X-Cart 5 license * and current X-Cart 5 license type of core differs from X-Cart 5 license type of module. * * @param \XLite\Model\Module $module Module entity * * @return boolean */ protected function showXCNModuleNotice(\XLite\Model\Module $module) { $marketplaceModule = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->findOneBy(array('name' => $module->getName(), 'author' => $module->getAuthor(), 'fromMarketplace' => true)); return $marketplaceModule && (bool) \XLite::getXCNLicense() && $this->isXCN($marketplaceModule) && !$module->getEnabled() && 1 < $marketplaceModule->getEditionState(); }
/** * Returns skin preview image URL * * @param \XLite\Model\Module $module Skin module * @param string $color Color * @param string $type Layout type * * @return string */ public function getLayoutPreview($module, $color, $type) { $skinModule = $module && '' === $color && 'XC' === $module->getAuthor() && 'ColorSchemes' === $module->getName() ? null : $module; return parent::getLayoutPreview($skinModule, $color, $type); }
/** * Returns installed module url * * @param \XLite\Model\Module $module Module * * @return string */ protected function getInstalledModuleURL($module) { $pageId = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->getInstalledPageId($module->getAuthor(), $module->getName(), \XLite\View\Pager\Admin\Module\Manage::getInstance()->getItemsPerPage()); $params = array('clearCnd' => 1, \XLite\View\Pager\APager::PARAM_PAGE_ID => $pageId); return \XLite::getInstance()->getShopURL(sprintf('%s#%s', $this->buildURL('addons_list_installed', '', $params), $module->getName())); }