Skip to content

Commit

Permalink
Changes for module upgrade and suggession
Browse files Browse the repository at this point in the history
  • Loading branch information
shreesh arora committed Dec 15, 2021
1 parent 1e91318 commit 248b241
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 44 deletions.
6 changes: 3 additions & 3 deletions admin/themes/default/template/controllers/modules/list.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:'|'}
Expand All @@ -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'}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
7 changes: 0 additions & 7 deletions classes/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,6 @@ public static function exec(

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;
Expand Down
5 changes: 1 addition & 4 deletions classes/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -563,9 +563,6 @@ public static function getClassNameById($id_tab)
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;

Expand Down
8 changes: 4 additions & 4 deletions classes/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -3318,15 +3318,15 @@ public static function addonsRequest($request, $params = array())
}

$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(),
'mail' => isset($params['email']) ? $params['email'] : Configuration::get('PS_SHOP_EMAIL')
));

$protocols = array('https');
$end_point = 'api.addons.prestashop.com';
$end_point = 'api.qloapps.com';

switch ($request) {
case 'native':
Expand Down Expand Up @@ -3360,7 +3360,7 @@ public static function addonsRequest($request, $params = array())
$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 {
Expand Down Expand Up @@ -3388,7 +3388,7 @@ public static function addonsRequest($request, $params = array())
'method' => 'POST',
'content' => $post_data,
'header' => 'Content-type: application/x-www-form-urlencoded',
'timeout' => 5,
'timeout' => 10,
)
));

Expand Down
12 changes: 6 additions & 6 deletions classes/controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -2126,7 +2129,7 @@ protected function initTabModuleList()
@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);
Expand Down Expand Up @@ -4042,20 +4045,17 @@ public function isFresh($file, $timeout = 604800)
return false;
}

/** @var bool */
protected static $is_prestashop_up = true;

/**
* @param string $file_to_refresh
* @param string $external_file
* @return bool
*/
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;
}

Expand Down
98 changes: 94 additions & 4 deletions classes/module/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,100 @@ public static function getModulesOnDisk($use_config = false, $logged_on_addons =
}
}
}
//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]);
Expand Down Expand Up @@ -1669,9 +1762,6 @@ final public static function isModuleTrusted($module_name)
}
// 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;
Expand Down
6 changes: 4 additions & 2 deletions config/defines_uri.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
/* 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');
2 changes: 1 addition & 1 deletion controllers/admin/AdminInformationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function getTestResult()
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));
}
Expand Down
Loading

0 comments on commit 248b241

Please sign in to comment.