diff --git a/admin-dev/themes/default/template/controllers/modules/tab_modules_list.tpl b/admin-dev/themes/default/template/controllers/modules/tab_modules_list.tpl index 51560c295..f3ec4d4c1 100644 --- a/admin-dev/themes/default/template/controllers/modules/tab_modules_list.tpl +++ b/admin-dev/themes/default/template/controllers/modules/tab_modules_list.tpl @@ -30,7 +30,8 @@ $('.action_tab_module').each( function (){ $(this).click(function () { option = $('#'+$(this).data('option')+' :selected'); - if ($(option).data('onclick') != '') + + if (typeof($(option).data('onclick')) != 'undefined' || $(option).data('onclick') != '') { var f = eval("(function(){ "+$(option).data('onclick')+"})"); if (f.call()) diff --git a/classes/Tools.php b/classes/Tools.php index add6d0fda..e5a2d8636 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -2332,6 +2332,92 @@ exit; return $pattern; return preg_replace('/\\\[px]\{[a-z]\}{1,2}|(\/[a-z]*)u([a-z]*)$/i', "$1$2", $pattern); } + + public static function addonsRequest($request, $params = array()) + { + $addons_url = 'api.addons.prestashop.com'; + $postData = ''; + $postDataArray = array( + 'version' => _PS_VERSION_, + 'iso_lang' => strtolower(Context::getContext()->language->iso_code), + 'iso_code' => strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))), + 'shop_url' => urlencode(Tools::getShopDomain()), + 'mail' => urlencode(Configuration::get('PS_SHOP_EMAIL')) + ); + foreach ($postDataArray as $postDataKey => $postDataValue) + $postData .= '&'.$postDataKey.'='.$postDataValue; + $postData = ltrim($postData, '&'); + + // Config for each request + if ($request == 'native') + { + // Define protocol accepted and post data values for this request + $protocolsList = array('https://' => 443, 'http://' => 80); + $postData .= '&method=listing&action=native'; + } + if ($request == 'must-have') + { + // Define protocol accepted and post data values for this request + $protocolsList = array('https://' => 443, 'http://' => 80); + $postData .= '&method=listing&action=must-have'; + } + if ($request == 'customer') + { + // Define protocol accepted and post data values for this request + $protocolsList = array('https://' => 443); + $postData .= '&method=listing&action=customer&username='.urlencode(trim(Context::getContext()->cookie->username_addons)).'&password='.urlencode(trim(Context::getContext()->cookie->password_addons)); + } + if ($request == 'check_customer') + { + // Define protocol accepted and post data values for this request + $protocolsList = array('https://' => 443); + $postData .= '&method=check_customer&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']); + } + if ($request == 'module') + { + // Define protocol accepted and post data values for this request + if (isset($params['username_addons']) && isset($params['password_addons'])) + { + $protocolsList = array('https://' => 443); + $postData .= '&method=module&id_module='.urlencode($params['id_module']).'&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']); + } + else + { + $protocolsList = array('https://' => 443, 'http://' => 80); + $postData .= '&method=module&id_module='.urlencode($params['id_module']); + } + } + + if ($request == 'install_modules') + { + // Define protocol accepted and post data values for this request + $protocolsList = array('https://' => 443, 'http://' => 80); + $postData .= '&method=listing&action=install_modules'; + + } + + // Make the request + $opts = array( + 'http'=>array( + 'method'=> 'POST', + 'content' => $postData, + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'timeout' => 5, + ) + ); + $context = stream_context_create($opts); + foreach ($protocolsList as $protocol => $port) + { + $content = Tools::file_get_contents($protocol.$addons_url, false, $context); + + // If content returned, we cache it + if ($content) + return $content; + } + + // No content, return false + return false; + } } /** diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index f797cb5c8..c7d31a588 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -34,8 +34,6 @@ class AdminControllerCore extends Controller public $confirmations = array(); public $shopShareDatas = false; - protected $addons_url = 'api.addons.prestashop.com'; - public $_languages = array(); public $default_form_language; public $allow_employee_form_lang; @@ -2865,83 +2863,6 @@ class AdminControllerCore extends Controller return (bool)file_put_contents(_PS_ROOT_DIR_.$file_to_refresh, $content); return false; } - - public function addonsRequest($request, $params = array()) - { - $postData = ''; - $postDataArray = array( - 'version' => _PS_VERSION_, - 'iso_lang' => strtolower(Context::getContext()->language->iso_code), - 'iso_code' => strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))), - 'shop_url' => urlencode(Tools::getShopDomain()), - 'mail' => urlencode(Configuration::get('PS_SHOP_EMAIL')) - ); - foreach ($postDataArray as $postDataKey => $postDataValue) - $postData .= '&'.$postDataKey.'='.$postDataValue; - $postData = ltrim($postData, '&'); - - // Config for each request - if ($request == 'native') - { - // Define protocol accepted and post data values for this request - $protocolsList = array('https://' => 443, 'http://' => 80); - $postData .= '&method=listing&action=native'; - } - if ($request == 'must-have') - { - // Define protocol accepted and post data values for this request - $protocolsList = array('https://' => 443, 'http://' => 80); - $postData .= '&method=listing&action=must-have'; - } - if ($request == 'customer') - { - // Define protocol accepted and post data values for this request - $protocolsList = array('https://' => 443); - $postData .= '&method=listing&action=customer&username='.urlencode(trim($this->context->cookie->username_addons)).'&password='.urlencode(trim($this->context->cookie->password_addons)); - } - if ($request == 'check_customer') - { - // Define protocol accepted and post data values for this request - $protocolsList = array('https://' => 443); - $postData .= '&method=check_customer&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']); - } - if ($request == 'module') - { - // Define protocol accepted and post data values for this request - if (isset($params['username_addons']) && isset($params['password_addons'])) - { - $protocolsList = array('https://' => 443); - $postData .= '&method=module&id_module='.urlencode($params['id_module']).'&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']); - } - else - { - $protocolsList = array('https://' => 443, 'http://' => 80); - $postData .= '&method=module&id_module='.urlencode($params['id_module']); - } - } - - // Make the request - $opts = array( - 'http'=>array( - 'method'=> 'POST', - 'content' => $postData, - 'header' => 'Content-type: application/x-www-form-urlencoded', - 'timeout' => 5, - ) - ); - $context = stream_context_create($opts); - foreach ($protocolsList as $protocol => $port) - { - $content = Tools::file_get_contents($protocol.$this->addons_url, false, $context); - - // If content returned, we cache it - if ($content) - return $content; - } - - // No content, return false - return false; - } public function fillModuleData(&$module, $output_type = 'link', $back = null) { diff --git a/controllers/admin/AdminHomeController.php b/controllers/admin/AdminHomeController.php index 84ec1cde1..2e9059150 100644 --- a/controllers/admin/AdminHomeController.php +++ b/controllers/admin/AdminHomeController.php @@ -669,7 +669,7 @@ class AdminHomeControllerCore extends AdminController } if (!$this->isFresh(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 86400)) - file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, $this->addonsRequest('native')); + file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, Tools::addonsRequest('native')); $tpl_vars['upgrade'] = $upgrade; diff --git a/controllers/admin/AdminModulesController.php b/controllers/admin/AdminModulesController.php index dcb8e6cb3..934eff0ee 100644 --- a/controllers/admin/AdminModulesController.php +++ b/controllers/admin/AdminModulesController.php @@ -156,7 +156,7 @@ class AdminModulesControllerCore extends AdminController { if (!$this->isFresh(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 86400)) { - if (file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, $this->addonsRequest('native'))) + if (file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, Tools::addonsRequest('native'))) $this->status = 'refresh'; else $this->status = 'error'; @@ -166,7 +166,7 @@ class AdminModulesControllerCore extends AdminController if (!$this->isFresh(Module::CACHE_FILE_MUST_HAVE_MODULES_LIST, 86400)) { - if (file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_MUST_HAVE_MODULES_LIST, $this->addonsRequest('must-have'))) + if (file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_MUST_HAVE_MODULES_LIST, Tools::addonsRequest('must-have'))) $this->status = 'refresh'; else $this->status = 'error'; @@ -180,7 +180,7 @@ class AdminModulesControllerCore extends AdminController { if (!$this->isFresh(Module::CACHE_FILE_CUSTOMER_MODULES_LIST, 60)) { - if (file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_CUSTOMER_MODULES_LIST, $this->addonsRequest('customer'))) + if (file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_CUSTOMER_MODULES_LIST, Tools::addonsRequest('customer'))) $this->status = 'refresh'; else $this->status = 'error'; @@ -198,7 +198,7 @@ class AdminModulesControllerCore extends AdminController public function ajaxProcessLogOnAddonsWebservices() { - $content = $this->addonsRequest('check_customer', array('username_addons' => pSQL(trim(Tools::getValue('username_addons'))), 'password_addons' => pSQL(trim(Tools::getValue('password_addons'))))); + $content = Tools::addonsRequest('check_customer', array('username_addons' => pSQL(trim(Tools::getValue('username_addons'))), 'password_addons' => pSQL(trim(Tools::getValue('password_addons'))))); $xml = @simplexml_load_string($content, null, LIBXML_NOCDATA); if (!$xml) die('KO'); @@ -629,10 +629,10 @@ class AdminModulesControllerCore extends AdminController if ($name == $modaddons->name && isset($modaddons->id) && ($this->logged_on_addons || $f['loggedOnAddons'] == 0)) { if ($f['loggedOnAddons'] == 0) - if (file_put_contents('../modules/'.$modaddons->name.'.zip', $this->addonsRequest('module', array('id_module' => pSQL($modaddons->id))))) + if (file_put_contents('../modules/'.$modaddons->name.'.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id))))) $this->extractArchive('../modules/'.$modaddons->name.'.zip', false); if ($f['loggedOnAddons'] == 1 && $this->logged_on_addons) - if (file_put_contents('../modules/'.$modaddons->name.'.zip', $this->addonsRequest('module', array('id_module' => pSQL($modaddons->id), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons)))))) + if (file_put_contents('../modules/'.$modaddons->name.'.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons)))))) $this->extractArchive('../modules/'.$modaddons->name.'.zip', false); } } diff --git a/install-dev/models/install.php b/install-dev/models/install.php index efc4433a9..68da421a4 100644 --- a/install-dev/models/install.php +++ b/install-dev/models/install.php @@ -588,15 +588,36 @@ class InstallModelInstall extends InstallAbstractModel return $modules; } + + public function getAddonsModulesList() + { + $addons_modules = array(); + $content = Tools::addonsRequest('install_modules'); + $xml = @simplexml_load_string($content, null, LIBXML_NOCDATA); + foreach ($xml->module as $modaddons) + $addons_modules[] = array('id_module' => $modaddons->id, 'name' => $modaddons->name); + + return $addons_modules; + } + /** * PROCESS : installModules - * Install all modules in ~/modules/ directory + * Download module from addons and Install all modules in ~/modules/ directory */ public function installModules($module = null) { $modules = $module ? array($module) : $this->getModulesList(); + $addons_modules = $this->getAddonsModulesList(); + foreach($addons_modules as $addons_module) + if (file_put_contents(_PS_MODULE_DIR_.$addons_module['name'].'.zip', Tools::addonsRequest('module', array('id_module' => $addons_module['id_module'])))) + if (Tools::ZipExtract(_PS_MODULE_DIR_.$addons_module['name'].'.zip', _PS_MODULE_DIR_)) + { + $modules[] = (string)$addons_module['name'];//if the module has been unziped we add the name in the modules list to install + unlink(_PS_MODULE_DIR_.$addons_module['name'].'.zip'); + } + $errors = array(); foreach ($modules as $module_name) {