Changes for module upgrade and suggession

This commit is contained in:
shreesh arora
2021-12-15 12:24:42 +05:30
parent 1e913188b6
commit 248b2419da
13 changed files with 132 additions and 44 deletions

View File

@@ -54,11 +54,11 @@
{$module->displayName|escape:'html':'UTF-8'}
<small class="text-muted">v{$module->version} - {l s='by'} {$module->author}</small>
{if isset($module->type) && $module->type == 'addonsBought'}
- <span class="module-badge-bought help-tooltip text-warning" data-title="{l s="You bought this module on PrestaShop Addons. Thank You."}"><i class="icon-pushpin"></i> <small>{l s="Bought"}</small></span>
- <span class="module-badge-bought help-tooltip text-warning" data-title="{l s="You bought this module on QloApps Addons. Thank You."}"><i class="icon-pushpin"></i> <small>{l s="Bought"}</small></span>
{elseif isset($module->type) && $module->type == 'addonsMustHave'}
- <span class="module-badge-popular help-tooltip text-primary" data-title="{l s="This module is available on PrestaShop Addons"}"><i class="icon-group"></i> <small>{l s="Popular"}</small></span>
- <span class="module-badge-popular help-tooltip text-primary" data-title="{l s="This module is available on QloApps Addons"}"><i class="icon-group"></i> <small>{l s="Popular"}</small></span>
{elseif isset($module->type) && $module->type == 'addonsPartner'}
- <span class="module-badge-partner help-tooltip text-warning" data-title="{l s="Official, PrestaShop certified module. Free, secure and includes updates!"}"><i class="icon-pushpin"></i> <small>{l s="Official"}</small></span>
- <span class="module-badge-partner help-tooltip text-warning" data-title="{l s="Official, QloApps certified module. Free, secure and includes updates!"}"><i class="icon-pushpin"></i> <small>{l s="Official"}</small></span>
{elseif isset($module->id) && $module->id gt 0}
{if isset($module->version_addons) && $module->version_addons}
<span class="label label-warning">{l s='Need update'}</span>

View File

@@ -36,7 +36,7 @@
<div class="page-bar toolbarBox">
<div class="btn-toolbar">
<ul class="nav nav-pills pull-right">
{* {if isset($upgrade_available) && $upgrade_available|@count}
{if isset($upgrade_available) && $upgrade_available|@count}
{assign var='modules' value=''}
{foreach from=$upgrade_available item='module'}
{assign var='modules' value=$modules|cat:$module.name:'|'}
@@ -55,7 +55,7 @@
<div>{l s='Check for update'}</div>
</a>
</li>
{/if} *}
{/if}
{if $add_permission eq '1' && ($context_mode != Context::MODE_HOST)}
<li>
<a id="desc-module-new" class="toolbar_btn anchor" href="#" onclick="$('#module_install').slideToggle();" title="{l s='Add a new module'}">

View File

@@ -34,9 +34,9 @@
{$module->displayName}
<small class="text-muted">v{$module->version} - by {$module->author}</small>
{if isset($module->type) && $module->type == 'addonsBought'}
- <span class="module-badge-bought help-tooltip text-warning" data-title="{l s="You bought this module on PrestaShop Addons. Thank You."}"><i class="icon-pushpin"></i> <small>{l s="Bought"}</small></span>
- <span class="module-badge-bought help-tooltip text-warning" data-title="{l s="You bought this module on QloApps Addons. Thank You."}"><i class="icon-pushpin"></i> <small>{l s="Bought"}</small></span>
{elseif isset($module->type) && $module->type == 'addonsMustHave'}
- <span class="module-badge-popular help-tooltip text-primary" data-title="{l s="This module is available on PrestaShop Addons"}"><i class="icon-group"></i> <small>{l s="Popular"}</small></span>
- <span class="module-badge-popular help-tooltip text-primary" data-title="{l s="This module is available on QloApps Addons"}"><i class="icon-group"></i> <small>{l s="Popular"}</small></span>
{elseif isset($module->type) && $module->type == 'addonsPartner'}
- <span class="module-badge-partner help-tooltip text-warning" data-title="{l s="This module is available for free thanks to our partner."}"><i class="icon-pushpin"></i> <small>{l s="Official"}</small></span>
{elseif isset($module->id) && $module->id gt 0}

View File

@@ -67,5 +67,5 @@
</div>
{/if}
<div class="alert alert-addons row-margin-top">
<a href="http://addons.prestashop.com/?utm_source=back-office&amp;utm_medium=dispatch&amp;utm_campaign=back-office-{$lang_iso|upper}&amp;utm_content={if $host_mode}cloud{else}download{/if}" onclick="return !window.open(this.href);">{l s='More modules on addons.prestashop.com'}</a>
<a href="https://qloapps.com/addons" onclick="return !window.open(this.href);">{l s='More modules on qloapps.com/addons/'}</a>
</div>

View File

@@ -476,13 +476,6 @@ class HookCore extends ObjectModel
if ($disable_non_native_modules && !isset(Hook::$native_module)) {
Hook::$native_module = Module::getNativeModuleList();
if (Module::isInstalled('hotelreservationsystem')) {
include_once _PS_MODULE_DIR_.'hotelreservationsystem/classes/HotelHelper.php';
$qloNativeMods = array();
if ($qloNativeMods = HotelHelper::getQloNativeModules()) {
Hook::$native_module = array_merge(Hook::$native_module, $qloNativeMods);
}
}
}
$different_shop = false;

View File

@@ -46,7 +46,7 @@ class TabCore extends ObjectModel
/** @var int hide_host_mode */
public $hide_host_mode = false;
const TAB_MODULE_LIST_URL = _PS_TAB_MODULE_LIST_URL_;
const TAB_MODULE_LIST_URL = _QLO_TAB_MODULE_LIST_URL_;
/**
* @see ObjectModel::$definition
@@ -563,9 +563,6 @@ class TabCore extends ObjectModel
public static function getTabModulesList($id_tab)
{
$modules_list = array('default_list' => array(), 'slider_list' => array());
//@TODO in future we will show Qloapps recommended addons as per the tabs
// for not we will not show any recommended addons of prestashop
return $modules_list;
$xml_tab_modules_list = false;

View File

@@ -3318,7 +3318,7 @@ exit;
}
$post_data = http_build_query(array(
'version' => isset($params['version']) ? $params['version'] : _PS_VERSION_,
'version' => isset($params['version']) ? $params['version'] : _QLOAPPS_VERSION_,
'iso_lang' => Tools::strtolower(isset($params['iso_lang']) ? $params['iso_lang'] : Context::getContext()->language->iso_code),
'iso_code' => Tools::strtolower(isset($params['iso_country']) ? $params['iso_country'] : Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))),
'shop_url' => isset($params['shop_url']) ? $params['shop_url'] : Tools::getShopDomain(),
@@ -3326,7 +3326,7 @@ exit;
));
$protocols = array('https');
$end_point = 'api.addons.prestashop.com';
$end_point = 'api.qloapps.com';
switch ($request) {
case 'native':
@@ -3360,7 +3360,7 @@ exit;
$post_data .= '&method=check&module_name='.urlencode($params['module_name']).'&module_key='.urlencode($params['module_key']);
break;
case 'module':
$post_data .= '&method=module&id_module='.urlencode($params['id_module']);
$post_data .= '&method=module&module_name='.urlencode($params['module_name']);
if (isset($params['username_addons']) && isset($params['password_addons'])) {
$post_data .= '&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']);
} else {
@@ -3388,7 +3388,7 @@ exit;
'method' => 'POST',
'content' => $post_data,
'header' => 'Content-type: application/x-www-form-urlencoded',
'timeout' => 5,
'timeout' => 10,
)
));

View File

@@ -239,6 +239,9 @@ class AdminControllerCore extends Controller
/** @var HelperList */
protected $helper;
/** @var bool */
protected static $is_qloapps_up = true;
/**
* Actions to execute on multiple selections.
*
@@ -2126,7 +2129,7 @@ class AdminControllerCore extends Controller
@file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_MUST_HAVE_MODULES_LIST, Tools::addonsRequest('must-have'));
}
if (!$this->isFresh(Module::CACHE_FILE_TAB_MODULES_LIST, 604800)) {
$this->refresh(Module::CACHE_FILE_TAB_MODULES_LIST, _PS_TAB_MODULE_LIST_URL_);
$this->refresh(Module::CACHE_FILE_TAB_MODULES_LIST, _QLO_TAB_MODULE_LIST_URL_);
}
$this->tab_modules_list = Tab::getTabModulesList($this->id);
@@ -4042,9 +4045,6 @@ class AdminControllerCore extends Controller
return false;
}
/** @var bool */
protected static $is_prestashop_up = true;
/**
* @param string $file_to_refresh
* @param string $external_file
@@ -4052,10 +4052,10 @@ class AdminControllerCore extends Controller
*/
public function refresh($file_to_refresh, $external_file)
{
if (self::$is_prestashop_up && $content = Tools::file_get_contents($external_file)) {
if (self::$is_qloapps_up && $content = Tools::file_get_contents($external_file)) {
return (bool)file_put_contents(_PS_ROOT_DIR_.$file_to_refresh, $content);
}
self::$is_prestashop_up = false;
self::$is_qloapps_up = false;
return false;
}

View File

@@ -1473,7 +1473,100 @@ abstract class ModuleCore
}
}
}
//INFO:: addons module are removed from the module lists
$files_list = array(
array('type' => 'addonsNative', 'file' => _PS_ROOT_DIR_.self::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 'loggedOnAddons' => 0),
array('type' => 'addonsMustHave', 'file' => _PS_ROOT_DIR_.self::CACHE_FILE_MUST_HAVE_MODULES_LIST, 'loggedOnAddons' => 0),
array('type' => 'addonsBought', 'file' => _PS_ROOT_DIR_.self::CACHE_FILE_CUSTOMER_MODULES_LIST, 'loggedOnAddons' => 1),
);
foreach ($files_list as $f) {
if (file_exists($f['file']) && ($f['loggedOnAddons'] == 0 || $logged_on_addons)) {
if (Module::useTooMuchMemory()) {
$errors[] = Tools::displayError('All modules cannot be loaded due to memory limit restrictions, please increase your memory_limit value on your server configuration');
break;
}
$file = $f['file'];
$content = Tools::file_get_contents($file);
$xml = @simplexml_load_string($content, null, LIBXML_NOCDATA);
if ($xml && isset($xml->module)) {
foreach ($xml->module as $modaddons) {
$flag_found = 0;
foreach ($module_list as $k => &$m) {
if (Tools::strtolower($m->name) == Tools::strtolower($modaddons->name) && !isset($m->available_on_addons)) {
$flag_found = 1;
if ($m->version != $modaddons->version && version_compare($m->version, $modaddons->version) === -1) {
$module_list[$k]->version_addons = $modaddons->version;
}
}
}
if ($flag_found == 0) {
$item = new stdClass();
$item->id = 0;
$item->warning = '';
$item->type = strip_tags((string)$f['type']);
$item->name = strip_tags((string)$modaddons->name);
$item->version = strip_tags((string)$modaddons->version);
$item->tab = strip_tags((string)$modaddons->tab);
$item->displayName = strip_tags((string)$modaddons->displayName);
$item->description = stripslashes(strip_tags((string)$modaddons->description));
$item->description_full = stripslashes(strip_tags((string)$modaddons->description_full));
$item->author = strip_tags((string)$modaddons->author);
$item->limited_countries = array();
$item->parent_class = '';
$item->onclick_option = false;
$item->is_configurable = 0;
$item->need_instance = 0;
$item->not_on_disk = 1;
$item->available_on_addons = 1;
$item->trusted = Module::isModuleTrusted($item->name);
$item->active = 0;
$item->description_full = stripslashes($modaddons->description_full);
$item->additional_description = isset($modaddons->additional_description) ? stripslashes($modaddons->additional_description) : null;
$item->compatibility = isset($modaddons->compatibility) ? (array)$modaddons->compatibility : null;
$item->nb_rates = isset($modaddons->nb_rates) ? (array)$modaddons->nb_rates : null;
$item->avg_rate = isset($modaddons->avg_rate) ? (array)$modaddons->avg_rate : null;
$item->badges = isset($modaddons->badges) ? (array)$modaddons->badges : null;
$item->url = isset($modaddons->url) ? $modaddons->url : null;
if (isset($modaddons->img)) {
if (!file_exists(_PS_TMP_IMG_DIR_.md5((int)$modaddons->id.'-'.$modaddons->name).'.jpg')) {
if (!file_put_contents(_PS_TMP_IMG_DIR_.md5((int)$modaddons->id.'-'.$modaddons->name).'.jpg', Tools::file_get_contents($modaddons->img))) {
copy(_PS_IMG_DIR_.'404.gif', _PS_TMP_IMG_DIR_.md5((int)$modaddons->id.'-'.$modaddons->name).'.jpg');
}
}
if (file_exists(_PS_TMP_IMG_DIR_.md5((int)$modaddons->id.'-'.$modaddons->name).'.jpg')) {
$item->image = '../img/tmp/'.md5((int)$modaddons->id.'-'.$modaddons->name).'.jpg';
}
}
if ($item->type == 'addonsMustHave') {
$item->addons_buy_url = strip_tags((string)$modaddons->url);
$prices = (array)$modaddons->price;
$id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT');
foreach ($prices as $currency => $price) {
if ($id_currency = Currency::getIdByIsoCode($currency)) {
$item->price = (float)$price;
$item->id_currency = (int)$id_currency;
if ($id_default_currency == $id_currency) {
break;
}
}
}
}
$module_list[$modaddons->id.'-'.$item->name] = $item;
}
}
}
}
}
foreach ($module_list as $key => &$module) {
if (defined('_PS_HOST_MODE_') && in_array($module->name, self::$hosted_modules_blacklist)) {
unset($module_list[$key]);
@@ -1669,9 +1762,6 @@ abstract class ModuleCore
}
// The module seems to be trusted, but it does not seem to be dedicated to this country
return 2;
// Check if module is from webkul then it will be considered as trusted module
} elseif (isset($objModule->author) && (strtolower($objModule->author) == 'webkul')) {
return 1;
} elseif (stripos($untrusted_modules_list_content, $module_name) !== false) {
// If the module is already in the untrusted list, then return 0 (untrusted)
return 0;

View File

@@ -82,6 +82,8 @@ define('_MODULE_DIR_', __PS_BASE_URI__.'modules/');
/* Define API URLs if not defined before */
Tools::safeDefine('_PS_API_DOMAIN_', 'api.prestashop.com');
Tools::safeDefine('_PS_API_URL_', 'http://'._PS_API_DOMAIN_);
Tools::safeDefine('_PS_TAB_MODULE_LIST_URL_', _PS_API_URL_.'/xml/tab_modules_list.xml');
Tools::safeDefine('_PS_API_MODULES_LIST_16_', _PS_API_DOMAIN_.'/xml/modules_list_16.xml');
Tools::safeDefine('_PS_CURRENCY_FEED_URL_', _PS_API_URL_.'/xml/currencies.xml');
Tools::safeDefine('_QLO_API_DOMAIN_', 'api.qloapps.com');
Tools::safeDefine('_QLO_API_URL_', 'http://'._QLO_API_DOMAIN_);
Tools::safeDefine('_QLO_TAB_MODULE_LIST_URL_', _QLO_API_URL_.'/xml/tab_modules_list.xml');
Tools::safeDefine('_QLO_NATIVE_MODULES_LIST_',_QLO_API_DOMAIN_.'/xml/'.str_replace('.', '', _QLOAPPS_VERSION_).'.xml');

View File

@@ -169,7 +169,7 @@ class AdminInformationControllerCore extends AdminController
public function displayAjaxCheckFiles()
{
$this->file_list = array('missing' => array(), 'updated' => array());
$xml = @simplexml_load_file(_PS_API_URL_.'/xml/md5/'._PS_VERSION_.'.xml');
$xml = @simplexml_load_file(_QLO_API_URL_.'/xml/md5/'._QLOAPPS_VERSION_.'.xml');
if (!$xml || !isset($xml->ps_root_dir[0])) {
die(json_encode($this->file_list));
}

View File

@@ -60,7 +60,7 @@ class AdminModulesControllerCore extends AdminController
protected $iso_default_country;
protected $filter_configuration = array();
protected $xml_modules_list = _PS_API_MODULES_LIST_16_;
protected $xml_modules_list = _QLO_NATIVE_MODULES_LIST_;
/**
* Admin Modules Controller Constructor
@@ -768,8 +768,8 @@ class AdminModulesControllerCore extends AdminController
if (!file_exists(_PS_MODULE_DIR_.$name.'/'.$name.'.php') || $key == 'update' || $key == 'updateAll') {
$files_list = array(
array('type' => 'addonsNative', 'file' => Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 'loggedOnAddons' => 0),
array('type' => 'addonsBought', 'file' => Module::CACHE_FILE_CUSTOMER_MODULES_LIST, 'loggedOnAddons' => 1),
array('type' => 'addonsMustHave', 'file' => Module::CACHE_FILE_MUST_HAVE_MODULES_LIST, 'loggedOnAddons' => 1),
// array('type' => 'addonsBought', 'file' => Module::CACHE_FILE_CUSTOMER_MODULES_LIST, 'loggedOnAddons' => 1),
// array('type' => 'addonsMustHave', 'file' => Module::CACHE_FILE_MUST_HAVE_MODULES_LIST, 'loggedOnAddons' => 1),
);
foreach ($files_list as $f) {
@@ -779,7 +779,8 @@ class AdminModulesControllerCore extends AdminController
if ($xml = @simplexml_load_string($content, null, LIBXML_NOCDATA)) {
foreach ($xml->module as $modaddons) {
if (Tools::strtolower($name) == Tools::strtolower($modaddons->name)) {
$module_to_update[$name]['id'] = $modaddons->id;
// $module_to_update[$name]['id'] = $modaddons->id;
$module_to_update[$name]['name'] = $modaddons->name;
$module_to_update[$name]['displayName'] = $modaddons->displayName;
$module_to_update[$name]['need_loggedOnAddons'] = $f['loggedOnAddons'];
}
@@ -791,11 +792,11 @@ class AdminModulesControllerCore extends AdminController
foreach ($module_to_update as $name => $attr) {
if ((is_null($attr) && $this->logged_on_addons == 0) || ($attr['need_loggedOnAddons'] == 1 && $this->logged_on_addons == 0)) {
$this->errors[] = sprintf(Tools::displayError('You need to be logged in to your PrestaShop Addons account in order to update the %s module. %s'), '<strong>'.$name.'</strong>', '<a href="#" class="addons_connect" data-toggle="modal" data-target="#modal_addons_connect" title="Addons">'.$this->l('Click here to log in.').'</a>');
} elseif (!is_null($attr['id'])) {
} elseif (!is_null($attr['name'])) {
$download_ok = false;
if ($attr['need_loggedOnAddons'] == 0 && file_put_contents(_PS_MODULE_DIR_.$name.'.zip', Tools::addonsRequest('module', array('id_module' => pSQL($attr['id']))))) {
if ($attr['need_loggedOnAddons'] == 0 && file_put_contents(_PS_MODULE_DIR_.$name.'.zip', Tools::addonsRequest('module', array('module_name' => pSQL($attr['name']))))) {
$download_ok = true;
} elseif ($attr['need_loggedOnAddons'] == 1 && $this->logged_on_addons && file_put_contents(_PS_MODULE_DIR_.$name.'.zip', Tools::addonsRequest('module', array('id_module' => pSQL($attr['id']), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons)))))) {
} elseif ($attr['need_loggedOnAddons'] == 1 && $this->logged_on_addons && file_put_contents(_PS_MODULE_DIR_.$name.'.zip', Tools::addonsRequest('module', array('module_name' => pSQL($attr['name']), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons)))))) {
$download_ok = true;
}

View File

@@ -2039,7 +2039,12 @@ class AdminThemesControllerCore extends AdminController
*/
private function getNativeModule($type = 0)
{
$xml = @simplexml_load_string(Tools::file_get_contents(_PS_API_URL_.'/xml/modules_list_16.xml'));
$protocols = array('https://', 'http://');
foreach ($protocols as $protocol) {
if($xml = @simplexml_load_string(Tools::file_get_contents($protocol._QLO_NATIVE_MODULES_LIST_))) {
break;
}
}
if ($xml) {
$natives = array();