function desactivate_custom_modules() { $db = Db::getInstance(); $modulesDirOnDisk = Module::getModulesDirOnDisk(); $module_list_xml = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'modules_list.xml'; $nativeModules = simplexml_load_file($module_list_xml); $nativeModules = $nativeModules->modules; foreach ($nativeModules as $nativeModulesType) { if (in_array($nativeModulesType['type'], array('native', 'partner'))) { $arrNativeModules[] = '""'; foreach ($nativeModulesType->module as $module) { $arrNativeModules[] = '"' . pSQL($module['name']) . '"'; } } } $arrNonNative = $db->ExecuteS(' SELECT * FROM `' . _DB_PREFIX_ . 'module` m WHERE name NOT IN (' . implode(',', $arrNativeModules) . ') '); $uninstallMe = array("undefined-modules"); if (is_array($arrNonNative)) { foreach ($arrNonNative as $aModule) { $uninstallMe[] = $aModule['name']; } } if (!is_array($uninstallMe)) { $uninstallMe = array($uninstallMe); } foreach ($uninstallMe as $k => $v) { $uninstallMe[$k] = '"' . pSQL($v) . '"'; } return Db::getInstance()->Execute(' UPDATE `' . _DB_PREFIX_ . 'module` SET `active`= 0 WHERE `name` IN (' . implode(',', $uninstallMe) . ')'); }
public static function getFilesList($iso_from, $theme_from, $iso_to = false, $theme_to = false, $select = false, $check = false, $modules = false) { if (empty($iso_from)) { die(Tools::displayError()); } $copy = ($iso_to and $theme_to) ? true : false; $lPath_from = _PS_TRANSLATIONS_DIR_ . (string) $iso_from . '/'; $tPath_from = _PS_ROOT_DIR_ . '/themes/' . (string) $theme_from . '/'; $mPath_from = _PS_MAIL_DIR_ . (string) $iso_from . '/'; if ($copy) { $lPath_to = _PS_TRANSLATIONS_DIR_ . (string) $iso_to . '/'; $tPath_to = _PS_ROOT_DIR_ . '/themes/' . (string) $theme_to . '/'; $mPath_to = _PS_MAIL_DIR_ . (string) $iso_to . '/'; } $lFiles = array('admin' . '.php', 'errors' . '.php', 'fields' . '.php', 'pdf' . '.php'); $mFiles = array('account.html', 'account.txt', 'bankwire.html', 'bankwire.txt', 'cheque.html', 'cheque.txt', 'contact.html', 'contact.txt', 'contact_form.html', 'contact_form.txt', 'credit_slip.html', 'credit_slip.txt', 'download_product.html', 'download_product.txt', 'download-product.tpl', 'employee_password.html', 'employee_password.txt', 'forward_msg.html', 'forward_msg.txt', 'guest_to_customer.html', 'guest_to_customer.txt', 'in_transit.html', 'in_transit.txt', 'newsletter.html', 'newsletter.txt', 'order_canceled.html', 'order_canceled.txt', 'order_conf.html', 'order_conf.txt', 'order_customer_comment.html', 'order_customer_comment.txt', 'order_merchant_comment.html', 'order_merchant_comment.txt', 'order_return_state.html', 'order_return_state.txt', 'outofstock.html', 'outofstock.txt', 'password.html', 'password.txt', 'password_query.html', 'password_query.txt', 'payment.html', 'payment.txt', 'payment_error.html', 'payment_error.txt', 'preparation.html', 'preparation.txt', 'refund.html', 'refund.txt', 'reply_msg.html', 'reply_msg.txt', 'shipped.html', 'shipped.txt', 'test.html', 'test.txt', 'voucher.html', 'voucher.txt'); $number = -1; $files = array(); $files_tr = array(); $files_theme = array(); $files_mail = array(); $files_modules = array(); // When a copy is made from a theme in specific language // to an other theme for the same language, // it's avoid to copy Translations, Mails files // and modules files which are not override by theme. if (!$copy or $iso_from != $iso_to) { // Translations files if (!$check or $check and (string) $iso_from != 'en') { foreach ($lFiles as $file) { $files_tr[$lPath_from . $file] = $copy ? $lPath_to . $file : ++$number; } } if ($select == 'tr') { return $files_tr; } $files = array_merge($files, $files_tr); // Mail files if (!$check or $check and (string) $iso_from != 'en') { $files_mail[$mPath_from . 'lang.php'] = $copy ? $mPath_to . 'lang.php' : ++$number; } foreach ($mFiles as $file) { $files_mail[$mPath_from . $file] = $copy ? $mPath_to . $file : ++$number; } if ($select == 'mail') { return $files_mail; } $files = array_merge($files, $files_mail); // Modules if ($modules) { $modList = Module::getModulesDirOnDisk(); foreach ($modList as $k => $mod) { $modDir = _PS_MODULE_DIR_ . $mod; // Lang file if (file_exists($modDir . '/' . (string) $iso_from . '.php')) { $files_modules[$modDir . '/' . (string) $iso_from . '.php'] = $copy ? $modDir . '/' . (string) $iso_to . '.php' : ++$number; } // Mails files $modMailDirFrom = $modDir . '/mails/' . (string) $iso_from; $modMailDirTo = $modDir . '/mails/' . (string) $iso_to; if (file_exists($modMailDirFrom)) { $dirFiles = scandir($modMailDirFrom); foreach ($dirFiles as $file) { if (file_exists($modMailDirFrom . '/' . $file) and $file != '.' and $file != '..' and $file != '.svn') { $files_modules[$modMailDirFrom . '/' . $file] = $copy ? $modMailDirTo . '/' . $file : ++$number; } } } } if ($select == 'modules') { return $files_modules; } $files = array_merge($files, $files_modules); } } else { if ($select == 'mail' or $select == 'tr') { return $files; } } // Theme files if (!$check or $check and (string) $iso_from != 'en') { $files_theme[$tPath_from . 'lang/' . (string) $iso_from . '.php'] = $copy ? $tPath_to . 'lang/' . (string) $iso_to . '.php' : ++$number; $module_theme_files = file_exists($tPath_from . 'modules/') ? scandir($tPath_from . 'modules/') : array(); foreach ($module_theme_files as $module) { if ($module !== '.' and $module != '..' and $module !== '.svn' and file_exists($tPath_from . 'modules/' . $module . '/' . (string) $iso_from . '.php')) { $files_theme[$tPath_from . 'modules/' . $module . '/' . (string) $iso_from . '.php'] = $copy ? $tPath_to . 'modules/' . $module . '/' . (string) $iso_to . '.php' : ++$number; } } } if ($select == 'theme') { return $files_theme; } $files = array_merge($files, $files_theme); // Return return $files; }
public static function getFilesList($iso_from, $theme_from, $iso_to = false, $theme_to = false, $select = false, $check = false, $modules = false) { $copy = ($iso_to and $theme_to) ? true : false; $lPath_from = _PS_TRANSLATIONS_DIR_ . strval($iso_from) . '/'; $tPath_from = _PS_ROOT_DIR_ . '/themes/' . strval($theme_from) . '/lang/'; $mPath_from = _PS_MAIL_DIR_ . strval($iso_from) . '/'; if ($copy) { $lPath_to = _PS_TRANSLATIONS_DIR_ . strval($iso_to) . '/'; $tPath_to = _PS_ROOT_DIR_ . '/themes/' . strval($theme_to) . '/lang/'; $mPath_to = _PS_MAIL_DIR_ . strval($iso_to) . '/'; } $lFiles = array('admin' . '.php', 'errors' . '.php', 'fields' . '.php', 'pdf' . '.php'); $mFiles = array('account.html', 'account.txt', 'bankwire.html', 'bankwire.txt', 'cheque.html', 'cheque.txt', 'contact.html', 'contact.txt', 'credit_slip.html', 'credit_slip.txt', 'download_product.html', 'download_product.txt', 'download-product.tpl', 'employee_password.html', 'employee_password.txt', 'newsletter.html', 'newsletter.txt', 'order_canceled.html', 'order_canceled.txt', 'order_conf.html', 'order_conf.txt', 'order_customer_comment.html', 'order_customer_comment.txt', 'order_merchant_comment.html', 'order_merchant_comment.txt', 'order_return_state.html', 'order_return_state.txt', 'outofstock.html', 'outofstock.txt', 'password.html', 'password.txt', 'payment.html', 'payment.txt', 'payment_error.html', 'payment_error.txt', 'preparation.html', 'preparation.txt', 'refund.html', 'refund.txt', 'shipped.html', 'shipped.txt', 'in_transit.txt', 'in_transit.html', 'test.html', 'test.txt', 'voucher.html', 'voucher.txt'); $number = -1; $files = array(); $files_tr = array(); $files_theme = array(); $files_mail = array(); $files_modules = array(); // Translations files if (!$check or $check and strval($iso_from) != 'en') { foreach ($lFiles as $file) { $files_tr[$lPath_from . $file] = $copy ? $lPath_to . $file : ++$number; } } if ($select == 'tr') { return $files_tr; } $files = array_merge($files, $files_tr); // Theme files if (!$check or $check and strval($iso_from) != 'en') { $files_theme[$tPath_from . strval($iso_from) . '.php'] = $copy ? $tPath_to . strval($iso_to) . '.php' : ++$number; } if ($select == 'theme') { return $files_theme; } $files = array_merge($files, $files_theme); // Mail files if (!$check or $check and strval($iso_from) != 'en') { $files_mail[$mPath_from . 'lang.php'] = $copy ? $mPath_to . 'lang.php' : ++$number; } foreach ($mFiles as $file) { $files_mail[$mPath_from . $file] = $copy ? $mPath_to . $file : ++$number; } if ($select == 'mail') { return $files_mail; } $files = array_merge($files, $files_mail); // Modules if ($modules) { $modList = Module::getModulesDirOnDisk(); foreach ($modList as $k => $mod) { // Lang file $modDir = _PS_MODULE_DIR_ . $mod; if (file_exists($modDir . '/' . strval($iso_from) . '.php')) { $files_modules[$modDir . '/' . strval($iso_from) . '.php'] = $copy ? $modDir . '/' . strval($iso_to) . '.php' : ++$number; } // Mails files $modMailDirFrom = $modDir . '/mails/' . strval($iso_from); $modMailDirTo = $modDir . '/mails/' . strval($iso_to); if (file_exists($modMailDirFrom)) { $dirFiles = scandir($modMailDirFrom); foreach ($dirFiles as $file) { if (file_exists($modMailDirFrom . '/' . $file) and $file != '.' and $file != '..' and $file != '.svn') { $files_modules[$modMailDirFrom . '/' . $file] = $copy ? $modMailDirTo . '/' . $file : ++$number; } } } } if ($select == 'modules') { return $files_modules; } $files = array_merge($files, $files_modules); } // Return return $files; }
public function getModulesList() { $results = array(); $modules = Module::getModulesDirOnDisk(); foreach ($modules as $module) { $backward_directory = _PS_MODULE_DIR_ . $module . '/backward_compatibility/'; $module = Module::getInstanceByName($module); if (is_dir($backward_directory) && strcmp($module->name, 'backwardcompatibility') != 0) { $ini_file = $backward_directory . 'backward.ini'; $version = $this->getVersion($ini_file); if (($handle = @fopen($ini_file, 'a+')) && is_writable($backward_directory)) { @fclose($handle); $writable = true; } else { $writable = false; } $results[] = array('name' => $module->name, 'display_name' => $module->displayName, 'version' => $version, 'writable' => $writable); } } return $results; }
/** * Return available modules * * @param boolean $useConfig in order to use config.xml file in module dir * @return array Modules */ public static function getModulesOnDisk($useConfig = false, $loggedOnAddons = false, $id_employee = false) { global $_MODULES; // Init var $module_list = array(); $module_name_list = array(); $modulesNameToCursor = array(); $errors = array(); // Get modules directory list and memory limit $modules_dir = Module::getModulesDirOnDisk(); $memory_limit = Tools::getMemoryLimit(); $modules_installed = array(); $result = Db::getInstance()->executeS(' SELECT m.name, m.version, mp.interest FROM `' . _DB_PREFIX_ . 'module` m ' . Shop::addSqlAssociation('module', 'm') . ' 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; } foreach ($modules_dir as $module) { // Memory usage checking if (function_exists('memory_get_usage') && $memory_limit != '-1') { $current_memory = memory_get_usage(true); // memory_threshold in MB $memory_threshold = Tools::isX86_64arch() ? 3 : 1.5; if ($memory_limit - $current_memory <= $memory_threshold * 1024 * 1024) { $errors[] = Tools::displayError('All modules cannot be loaded due to memory limit restrictions, please increase your memory_limit value on your server configuration'); break; } } // Check if config.xml module file exists and if it's not outdated $configFile = _PS_MODULE_DIR_ . $module . '/config.xml'; $xml_exist = file_exists($configFile); if ($xml_exist) { $needNewConfigFile = filemtime($configFile) < filemtime(_PS_MODULE_DIR_ . $module . '/' . $module . '.php'); } else { $needNewConfigFile = true; } // If config.xml exists and that the use config flag is at true if ($useConfig && $xml_exist) { // Load config.xml libxml_use_internal_errors(true); $xml_module = simplexml_load_file($configFile); foreach (libxml_get_errors() as $error) { $errors[] = '[' . $module . '] ' . Tools::displayError('Error found in config file:') . ' ' . htmlentities($error->message); } libxml_clear_errors(); // If no errors in Xml, no need instand and no need new config.xml file, we load only translations if (!count($errors) && (int) $xml_module->need_instance == 0 && !$needNewConfigFile) { $file = _PS_MODULE_DIR_ . $module . '/' . Context::getContext()->language->iso_code . '.php'; if (Tools::file_exists_cache($file) && (include_once $file)) { if (isset($_MODULE) && is_array($_MODULE)) { $_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE; } } $item = new stdClass(); $item->id = 0; $item->warning = ''; foreach ($xml_module as $k => $v) { $item->{$k} = (string) $v; } $item->displayName = stripslashes(Translate::getModuleTranslation((string) $xml_module->name, Module::configXmlStringFormat($xml_module->displayName), (string) $xml_module->name)); $item->description = stripslashes(Translate::getModuleTranslation((string) $xml_module->name, Module::configXmlStringFormat($xml_module->description), (string) $xml_module->name)); $item->author = stripslashes(Translate::getModuleTranslation((string) $xml_module->name, Module::configXmlStringFormat($xml_module->author), (string) $xml_module->name)); if (isset($xml_module->confirmUninstall)) { $item->confirmUninstall = Translate::getModuleTranslation((string) $xml_module->name, Module::configXmlStringFormat($xml_module->confirmUninstall), (string) $xml_module->name); } $item->active = 0; $item->onclick_option = false; $module_list[] = $item; $module_name_list[] = '\'' . pSQL($item->name) . '\''; $modulesNameToCursor[strval($item->name)] = $item; } } // If use config flag is at false or config.xml does not exist OR need instance OR need a new config.xml file if (!$useConfig || !$xml_exist || isset($xml_module->need_instance) && (int) $xml_module->need_instance == 1 || $needNewConfigFile) { // If class does not exists, we include the file if (!class_exists($module, false)) { // Get content from php file $filepath = _PS_MODULE_DIR_ . $module . '/' . $module . '.php'; $file = trim(file_get_contents(_PS_MODULE_DIR_ . $module . '/' . $module . '.php')); if (substr($file, 0, 5) == '<?php') { $file = substr($file, 5); } if (substr($file, -2) == '?>') { $file = substr($file, 0, -2); } // If (false) is a trick to not load the class with "eval". // This way require_once will works correctly if (eval('if (false){ ' . $file . ' }') !== false) { require_once _PS_MODULE_DIR_ . $module . '/' . $module . '.php'; } else { $errors[] = sprintf(Tools::displayError('%1$s (parse error in %2$s)'), $module, substr($filepath, strlen(_PS_ROOT_DIR_))); } } // If class exists, we just instanciate it if (class_exists($module, false)) { $tmp_module = new $module(); $item = new stdClass(); $item->id = $tmp_module->id; $item->warning = $tmp_module->warning; $item->name = $tmp_module->name; $item->version = $tmp_module->version; $item->tab = $tmp_module->tab; $item->displayName = $tmp_module->displayName; $item->description = stripslashes($tmp_module->description); $item->author = $tmp_module->author; $item->limited_countries = $tmp_module->limited_countries; $item->parent_class = get_parent_class($module); $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->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) ? $tmp_module->confirmUninstall : null; $item->onclick_option = method_exists($module, 'onclickOption') ? true : false; if ($item->onclick_option) { $href = Context::getContext()->link->getAdminLink('Module', true) . '&module_name=' . $tmp_module->name . '&tab_module=' . $tmp_module->tab; $item->onclick_option_content = array(); $option_tab = array('desactive', 'reset', 'configure', 'delete'); foreach ($option_tab as $opt) { $item->onclick_option_content[$opt] = $tmp_module->onclickOption($opt, $href); } } $module_list[] = $item; if (!$xml_exist || $needNewConfigFile) { self::$_generate_config_xml_mode = true; $tmp_module->_generateConfigXml(); self::$_generate_config_xml_mode = false; } unset($tmp_module); } else { $errors[] = sprintf(Tools::displayError('%1$s (class missing in %2$s)'), $module, substr($filepath, strlen(_PS_ROOT_DIR_))); } } } // Get modules information from database if (!empty($module_name_list)) { $list = Shop::getContextListShopID(); $sql = 'SELECT m.id_module, m.name, ( SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'module_shop ms WHERE m.id_module = ms.id_module AND ms.id_shop IN (' . implode(',', $list) . ') ) as total FROM ' . _DB_PREFIX_ . 'module m WHERE m.name IN (' . implode(',', $module_name_list) . ')'; $results = Db::getInstance()->executeS($sql); foreach ($results as $result) { $moduleCursor = $modulesNameToCursor[$result['name']]; $moduleCursor->id = $result['id_module']; $moduleCursor->active = $result['total'] == count($list) ? 1 : 0; } } // Get Default Country Modules and customer module $files_list = array(array('type' => 'addonsNative', 'file' => _PS_ROOT_DIR_ . self::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 'loggedOnAddons' => 0), array('type' => 'addonsBought', 'file' => _PS_ROOT_DIR_ . self::CACHE_FILE_CUSTOMER_MODULES_LIST, 'loggedOnAddons' => 1), array('type' => 'addonsMustHave', 'file' => _PS_ROOT_DIR_ . self::CACHE_FILE_MUST_HAVE_MODULES_LIST, 'loggedOnAddons' => 0)); foreach ($files_list as $f) { if (file_exists($f['file']) && ($f['loggedOnAddons'] == 0 || $loggedOnAddons)) { $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 ($m->name == $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) . ' (Addons)'; $item->description = stripslashes(strip_tags((string) $modaddons->description)); $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; if (isset($modaddons->img)) { if (!file_exists(_PS_TMP_IMG_DIR_ . md5($modaddons->name) . '.jpg')) { if (!file_put_contents(_PS_TMP_IMG_DIR_ . md5($modaddons->name) . '.jpg', Tools::file_get_contents($modaddons->img))) { copy(_PS_IMG_DIR_ . '404.gif', _PS_TMP_IMG_DIR_ . md5($modaddons->name) . '.jpg'); } } if (file_exists(_PS_TMP_IMG_DIR_ . md5($modaddons->name) . '.jpg')) { $item->image = '../img/tmp/' . md5($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 = (double) $price; $item->id_currency = (int) $id_currency; if ($id_default_currency == $id_currency) { break; } } } } $module_list[] = $item; } } } } } foreach ($module_list as &$module) { if (isset($modules_installed[$module->name])) { $module->installed = true; $module->database_version = $modules_installed[$module->name]['version']; $module->interest = $modules_installed[$module->name]['interest']; } else { $module->installed = false; $module->database_version = 0; $module->interest = 0; } } usort($module_list, create_function('$a,$b', 'return strnatcasecmp($a->displayName, $b->displayName);')); if ($errors) { echo '<div class="alert error"><h3>' . Tools::displayError('The following module(s) could not be loaded') . ':</h3><ol>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ol></div>'; } return $module_list; }
/** * Generate XML files for trusted and untrusted modules * */ public static final function generateTrustedXml() { $modules_on_disk = Module::getModulesDirOnDisk(); $trusted = array(); $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); if (file_exists(_PS_ROOT_DIR_ . self::CACHE_FILE_CUSTOMER_MODULES_LIST)) { $trusted_modules_xml[] = _PS_ROOT_DIR_ . self::CACHE_FILE_CUSTOMER_MODULES_LIST; } // Create 2 arrays with trusted and untrusted modules foreach ($trusted_modules_xml as $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) { $trusted[] = Tools::strtolower((string) $modaddons->name); } } } foreach (glob(_PS_ROOT_DIR_ . '/config/xml/themes/*.xml') as $theme_xml) { if (file_exists($theme_xml)) { $content = Tools::file_get_contents($theme_xml); $xml = @simplexml_load_string($content, null, LIBXML_NOCDATA); foreach ($xml->modules->module as $modaddons) { if ((string) $modaddons['action'] == 'install') { $trusted[] = Tools::strtolower((string) $modaddons['name']); } } } } foreach ($modules_on_disk as $name) { if (!in_array($name, $trusted)) { if (Module::checkModuleFromAddonsApi($name)) { $trusted[] = Tools::strtolower($name); } else { $untrusted[] = Tools::strtolower($name); } } } $context = Context::getContext(); $theme = new Theme($context->shop->id_theme); // Save the 2 arrays into XML files $trusted_xml = new SimpleXMLElement('<modules_list/>'); $trusted_xml->addAttribute('theme', $theme->name); $modules = $trusted_xml->addChild('modules'); $modules->addAttribute('type', 'trusted'); foreach ($trusted as $key => $name) { $module = $modules->addChild('module'); $module->addAttribute('name', $name); } $success = file_put_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_TRUSTED_MODULES_LIST, $trusted_xml->asXML()); $untrusted_xml = new SimpleXMLElement('<modules_list/>'); $modules = $untrusted_xml->addChild('modules'); $modules->addAttribute('type', 'untrusted'); foreach ($untrusted as $key => $name) { $module = $modules->addChild('module'); $module->addAttribute('name', $name); } $success &= file_put_contents(_PS_ROOT_DIR_ . self::CACHE_FILE_UNTRUSTED_MODULES_LIST, $untrusted_xml->asXML()); if ($success) { return true; } else { Tools::displayError('Trusted and Untrusted XML have not been generated properly'); } }
/** * Return non native module * * @param int $position Take only positionnables modules * @return array Modules */ public static function getNonNativeModuleList() { $db = Db::getInstance(); $modulesDirOnDisk = Module::getModulesDirOnDisk(); $module_list_xml = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'modules_list.xml'; $nativeModules = simplexml_load_file($module_list_xml); $nativeModules = $nativeModules->modules; foreach ($nativeModules as $nativeModulesType) { if (in_array($nativeModulesType['type'], array('native', 'partner'))) { $arrNativeModules[] = '""'; foreach ($nativeModulesType->module as $module) { $arrNativeModules[] = '"' . pSQL($module['name']) . '"'; } } } return $db->ExecuteS(' SELECT * FROM `' . _DB_PREFIX_ . 'module` m WHERE name NOT IN (' . implode(',', $arrNativeModules) . ') '); }