added catalog page, updated dashboard and added recomendation section

This commit is contained in:
Shreesh Arora
2022-07-20 12:25:06 +05:30
committed by Shreesh Arora
parent ef44ddd00a
commit 5e9a3990a2
89 changed files with 2612 additions and 533 deletions

View File

@@ -171,13 +171,15 @@ abstract class ModuleCore
const CACHE_FILE_TAB_MODULES_LIST = '/config/xml/tab_modules_list.xml';
const CACHE_FILE_ALL_COUNTRY_MODULES_LIST = '/config/xml/modules_native_addons.xml';
// const CACHE_FILE_ALL_COUNTRY_MODULES_LIST = '/config/xml/modules_native_addons.xml';
const CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST = '/config/xml/default_country_modules_list.xml';
const CACHE_FILE_CUSTOMER_MODULES_LIST = '/config/xml/customer_modules_list.xml';
const CACHE_FILE_MUST_HAVE_MODULES_LIST = '/config/xml/must_have_modules_list.xml';
const CACHE_FILE_ADDONS_MODULES_LIST = '/config/xml/addons_modules_list.xml';
const CACHE_FILE_TRUSTED_MODULES_LIST = '/config/xml/trusted_modules_list.xml';
const CACHE_FILE_UNTRUSTED_MODULES_LIST = '/config/xml/untrusted_modules_list.xml';
@@ -1259,6 +1261,16 @@ abstract class ModuleCore
return Translate::getModuleTranslation((string)$xml_module->name, Module::configXmlStringFormat($xml_module->displayName), (string)$xml_module->name);
}
public static function getModuleInstallVersion($module)
{
return Db::getInstance()->getRow('
SELECT m.`name`, m.`version`, mp.`interest`, module_shop.`enable_device`
FROM `'._DB_PREFIX_.'module` m
'.Shop::addSqlAssociation('module', 'm', false).'
LEFT JOIN `'._DB_PREFIX_.'module_preference` mp ON (mp.`module` = m.`name` AND mp.`id_employee` = '.(int)$id_employee.')
WHERE m.`name` = "'.pSQL($module).'"');
}
protected static function useTooMuchMemory()
{
$memory_limit = Tools::getMemoryLimit();
@@ -1297,7 +1309,7 @@ abstract class ModuleCore
$result = Db::getInstance()->executeS('
SELECT m.name, m.version, mp.interest, module_shop.enable_device
FROM `'._DB_PREFIX_.'module` m
'.Shop::addSqlAssociation('module', 'm').'
'.Shop::addSqlAssociation('module', 'm', false).'
LEFT JOIN `'._DB_PREFIX_.'module_preference` mp ON (mp.`module` = m.`name` AND mp.`id_employee` = '.(int)$id_employee.')');
foreach ($result as $row) {
$modules_installed[$row['name']] = $row;
@@ -1364,7 +1376,21 @@ abstract class ModuleCore
$item->active = 0;
$item->onclick_option = false;
$item->trusted = Module::isModuleTrusted($item->name);
$item->url = false;
$item->is_native = false;
if (defined('_PS_HOST_MODE_') && in_array($item->name, self::$hosted_modules_blacklist)) {
continue;
} elseif (isset($modules_installed[$item->name])) {
$item->installed = true;
$item->database_version = $modules_installed[$item->name]['version'];
$item->interest = $modules_installed[$item->name]['interest'];
$item->enable_device = $modules_installed[$item->name]['enable_device'];
} else {
$item->installed = false;
$item->database_version = 0;
$item->interest = 0;
}
$module_list[] = $item;
@@ -1417,7 +1443,6 @@ abstract class ModuleCore
$item->is_configurable = $tmp_module->is_configurable = method_exists($tmp_module, 'getContent') ? 1 : 0;
$item->need_instance = isset($tmp_module->need_instance) ? $tmp_module->need_instance : 0;
$item->active = $tmp_module->active;
$item->trusted = Module::isModuleTrusted($tmp_module->name);
$item->currencies = isset($tmp_module->currencies) ? $tmp_module->currencies : null;
$item->currencies_mode = isset($tmp_module->currencies_mode) ? $tmp_module->currencies_mode : null;
$item->confirmUninstall = isset($tmp_module->confirmUninstall) ? html_entity_decode($tmp_module->confirmUninstall) : null;
@@ -1429,6 +1454,7 @@ abstract class ModuleCore
$item->badges = isset($tmp_module->badges) ? (array)$tmp_module->badges : null;
$item->url = isset($tmp_module->url) ? $tmp_module->url : null;
$item->onclick_option = method_exists($module, 'onclickOption') ? true : false;
$item->is_native = false;
if ($item->onclick_option) {
$href = Context::getContext()->link->getAdminLink('Module', true).'&module_name='.$tmp_module->name.'&tab_module='.$tmp_module->tab;
@@ -1440,6 +1466,19 @@ abstract class ModuleCore
}
}
if (defined('_PS_HOST_MODE_') && in_array($item->name, self::$hosted_modules_blacklist)) {
continue;
} elseif (isset($modules_installed[$item->name])) {
$item->installed = true;
$item->database_version = $modules_installed[$item->name]['version'];
$item->interest = $modules_installed[$item->name]['interest'];
$item->enable_device = $modules_installed[$item->name]['enable_device'];
} else {
$item->installed = false;
$item->database_version = 0;
$item->interest = 0;
}
$module_list[] = $item;
if (!$xml_exist || $need_new_config_file) {
@@ -1475,9 +1514,8 @@ abstract class ModuleCore
}
$files_list = array(
array('type' => 'addonsModules', 'file' => _PS_ROOT_DIR_.self::CACHE_FILE_ADDONS_MODULES_LIST, 'loggedOnAddons' => 0),
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)) {
@@ -1497,90 +1535,20 @@ abstract class ModuleCore
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;
$module_list[$k]->version_addons = strip_tags((string)$modaddons->version);
}
$module_list[$k]->url = isset($modaddons->url) ? strip_tags((string)$modaddons->url) : null;
if ($f['type'] == 'addonsNative') {
$module_list[$k]->is_native = true;
}
}
}
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]);
} elseif (isset($modules_installed[$module->name])) {
$module->installed = true;
$module->database_version = $modules_installed[$module->name]['version'];
$module->interest = $modules_installed[$module->name]['interest'];
$module->enable_device = $modules_installed[$module->name]['enable_device'];
} else {
$module->installed = false;
$module->database_version = 0;
$module->interest = 0;
}
}
usort($module_list, function ($a, $b) { return strnatcasecmp($a->displayName, $b->displayName); });
if ($errors) {
if (!isset(Context::getContext()->controller) && !Context::getContext()->controller->controller_name) {
@@ -1622,6 +1590,91 @@ abstract class ModuleCore
return $module_list;
}
public static function getInstalledModulesOnDisk($use_config = false, $logged_on_addons = false, $id_employee = false)
{
$modules = self::getModulesOnDisk($use_config, $logged_on_addons, $id_employee);
return array_filter($modules, function($m) {
return $m->installed;
});
}
public static function getSuggestedModules()
{
$files_list = array(
array('type' => 'addonsMustHave', 'file' => _PS_ROOT_DIR_.Module::CACHE_FILE_MUST_HAVE_MODULES_LIST, 'loggedOnAddons' => 0),
array('type' => 'addonsNative', 'file' => _PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 'loggedOnAddons' => 0),
);
$module_list = array();
foreach ($files_list as $f) {
$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) {
$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->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;
$item->is_native = false;
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;
}
}
}
$module_list = array_values($module_list);
return $module_list;
}
/**
* Return non native module
@@ -1641,7 +1694,7 @@ abstract class ModuleCore
$arr_native_modules = array();
if (is_array($native_modules)) {
foreach ($native_modules as $native_modules_type) {
if (in_array($native_modules_type['type'], array('native', 'partner'))) {
if (in_array($native_modules_type['type'], array('native', 'disk', 'partner'))) {
$arr_native_modules[] = '""';
foreach ($native_modules_type->module as $module) {
$arr_native_modules[] = '"'.pSQL($module['name']).'"';
@@ -1710,7 +1763,7 @@ abstract class ModuleCore
* @param string $key The key provided by addons
* @return int
*/
final public static function isModuleTrusted($module_name)
final public static function isModuleTrusted($module_name, $check_api = true)
{
static $trusted_modules_list_content = null;
static $modules_list_content = null;
@@ -1724,7 +1777,7 @@ abstract class ModuleCore
// we use the file, otherwise we regenerate it
if (!(file_exists(_PS_ROOT_DIR_.self::CACHE_FILE_TRUSTED_MODULES_LIST)
&& filesize(_PS_ROOT_DIR_.self::CACHE_FILE_TRUSTED_MODULES_LIST) > 0
&& ((time() - filemtime(_PS_ROOT_DIR_.self::CACHE_FILE_TRUSTED_MODULES_LIST)) < 86400)
&& ((time() - filemtime(_PS_ROOT_DIR_.self::CACHE_FILE_TRUSTED_MODULES_LIST)) < _TIME_1_DAY_)
)) {
self::generateTrustedXml();
}
@@ -1748,8 +1801,6 @@ abstract class ModuleCore
$untrusted_modules_list_content = Tools::file_get_contents(_PS_ROOT_DIR_.self::CACHE_FILE_UNTRUSTED_MODULES_LIST);
}
$objModule = Module::getInstanceByName($module_name);
// If the module is trusted, which includes both partner modules and modules bought on Addons
if (stripos($trusted_modules_list_content, $module_name) !== false) {
@@ -1769,10 +1820,11 @@ abstract class ModuleCore
// If the module isn't in one of the xml files
// It might have been uploaded recenlty so we check
// Addons API and clear XML files to be regenerated next time
Tools::deleteFile(_PS_ROOT_DIR_.self::CACHE_FILE_TRUSTED_MODULES_LIST);
Tools::deleteFile(_PS_ROOT_DIR_.self::CACHE_FILE_UNTRUSTED_MODULES_LIST);
return (int)Module::checkModuleFromAddonsApi($module_name);
if ($check_api) {
Tools::deleteFile(_PS_ROOT_DIR_.self::CACHE_FILE_TRUSTED_MODULES_LIST);
Tools::deleteFile(_PS_ROOT_DIR_.self::CACHE_FILE_UNTRUSTED_MODULES_LIST);
return (int)Module::checkModuleFromAddonsApi($module_name);
}
}
}
@@ -1787,9 +1839,11 @@ abstract class ModuleCore
$untrusted = array();
$trusted_modules_xml = array(
_PS_ROOT_DIR_.self::CACHE_FILE_ALL_COUNTRY_MODULES_LIST,
_PS_ROOT_DIR_.self::CACHE_FILE_MUST_HAVE_MODULES_LIST,
);
// _PS_ROOT_DIR_.self::CACHE_FILE_ALL_COUNTRY_MODULES_LIST,
_PS_ROOT_DIR_.self::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST,
_PS_ROOT_DIR_.self::CACHE_FILE_MUST_HAVE_MODULES_LIST,
_PS_ROOT_DIR_.self::CACHE_FILE_ADDONS_MODULES_LIST,
);
if (file_exists(_PS_ROOT_DIR_.self::CACHE_FILE_CUSTOMER_MODULES_LIST)) {
$trusted_modules_xml[] = _PS_ROOT_DIR_.self::CACHE_FILE_CUSTOMER_MODULES_LIST;
@@ -1874,12 +1928,12 @@ abstract class ModuleCore
if (!is_object($obj)) {
return false;
} elseif ($obj->module_key === '') {
return false;
// } elseif ($obj->module_key === '') {
// return false;
} else {
$params = array(
'module_name' => $obj->name,
'module_key' => $obj->module_key,
// 'module_key' => $obj->module_key,
);
$xml = Tools::addonsRequest('check_module', $params);
return (bool)(strpos($xml, 'success') !== false);