[-] BO : moved some code from AdminModulesController to AdminController because is is used on AdminHomeController
This commit is contained in:
@@ -55,7 +55,6 @@ class AdminModulesControllerCore extends AdminController
|
||||
protected $filter_configuration = array();
|
||||
|
||||
protected $xml_modules_list = 'api.prestashop.com/xml/modules_list_15.xml';
|
||||
protected $addons_url = 'api.addons.prestashop.com';
|
||||
protected $logged_on_addons = false;
|
||||
|
||||
/**
|
||||
@@ -129,101 +128,6 @@ class AdminModulesControllerCore extends AdminController
|
||||
$this->logged_on_addons = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax Request Methods
|
||||
*
|
||||
* if modules_list.xml is outdated,
|
||||
* this function will re-upload it from prestashop.com
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
|
||||
public function isFresh($file, $timeout = 604800000)
|
||||
{
|
||||
if (file_exists(_PS_ROOT_DIR_.$file))
|
||||
{
|
||||
if (filesize(_PS_ROOT_DIR_.$file) < 1)
|
||||
return false;
|
||||
return ((time() - filemtime(_PS_ROOT_DIR_.$file)) < $timeout);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public function refresh($file_to_refresh, $external_file)
|
||||
{
|
||||
$content = Tools::file_get_contents($external_file);
|
||||
if ($content)
|
||||
return file_put_contents(_PS_ROOT_DIR_.$file_to_refresh, $content);
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addonsRequest($request, $params = array())
|
||||
{
|
||||
// Config for each request
|
||||
if ($request == 'native')
|
||||
{
|
||||
// Define protocol accepted and post data values for this request
|
||||
$protocolsList = array('https://' => 443, 'http://' => 80);
|
||||
$postData = 'version='._PS_VERSION_.'&method=listing&action=native&iso_code='.strtolower(Configuration::get('PS_LOCALE_COUNTRY')).'&iso_lang='.strtolower(Context::getContext()->language->iso_code);
|
||||
}
|
||||
if ($request == 'must-have')
|
||||
{
|
||||
// Define protocol accepted and post data values for this request
|
||||
$protocolsList = array('https://' => 443, 'http://' => 80);
|
||||
$postData = 'version='._PS_VERSION_.'&method=listing&action=must-have&iso_code='.strtolower(Configuration::get('PS_LOCALE_COUNTRY')).'&iso_lang='.strtolower(Context::getContext()->language->iso_code);
|
||||
}
|
||||
if ($request == 'customer')
|
||||
{
|
||||
// Define protocol accepted and post data values for this request
|
||||
$protocolsList = array('https://' => 443);
|
||||
$postData = 'version='._PS_VERSION_.'&method=listing&action=customer&username='.pSQL(trim($this->context->cookie->username_addons)).'&password='.pSQL(trim($this->context->cookie->password_addons)).'&iso_lang='.strtolower(Context::getContext()->language->iso_code);
|
||||
}
|
||||
if ($request == 'check_customer')
|
||||
{
|
||||
// Define protocol accepted and post data values for this request
|
||||
$protocolsList = array('https://' => 443);
|
||||
$postData = 'version='._PS_VERSION_.'&method=check_customer&username='.pSQL($params['username_addons']).'&password='.pSQL($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 = 'version='._PS_VERSION_.'&method=module&id_module='.pSQL($params['id_module']).'&username='.pSQL($params['username_addons']).'&password='.pSQL($params['password_addons']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$protocolsList = array('https://' => 443, 'http://' => 80);
|
||||
$postData = 'version='._PS_VERSION_.'&method=module&id_module='.pSQL($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 = @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 ajaxProcessRefreshModuleList()
|
||||
{
|
||||
// Refresh modules_list.xml every week
|
||||
@@ -231,7 +135,7 @@ class AdminModulesControllerCore extends AdminController
|
||||
{
|
||||
if ($this->refresh(Module::CACHE_FILE_MODULES_LIST, 'https://'.$this->xml_modules_list))
|
||||
$this->status = 'refresh';
|
||||
else if ($this->refresh(Module::CACHE_FILE_MODULES_LIST, 'http://'.$this->xml_modules_list))
|
||||
elseif ($this->refresh(Module::CACHE_FILE_MODULES_LIST, 'http://'.$this->xml_modules_list))
|
||||
$this->status = 'refresh';
|
||||
else
|
||||
$this->status = 'error';
|
||||
|
||||
Reference in New Issue
Block a user