[-] BO : moved some code from AdminModulesController to AdminController because is is used on AdminHomeController
This commit is contained in:
@@ -34,6 +34,8 @@ class AdminControllerCore extends Controller
|
|||||||
public $informations = array();
|
public $informations = array();
|
||||||
public $confirmations = array();
|
public $confirmations = array();
|
||||||
public $shopShareDatas = false;
|
public $shopShareDatas = false;
|
||||||
|
|
||||||
|
protected $addons_url = 'api.addons.prestashop.com';
|
||||||
|
|
||||||
public $_languages = array();
|
public $_languages = array();
|
||||||
public $default_form_language;
|
public $default_form_language;
|
||||||
@@ -2665,5 +2667,91 @@ class AdminControllerCore extends Controller
|
|||||||
if ($this->status === '')
|
if ($this->status === '')
|
||||||
$this->status = 'error';
|
$this->status = 'error';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -658,6 +658,9 @@ class AdminHomeControllerCore extends AdminController
|
|||||||
if (Configuration::get('PS_LAST_VERSION_CHECK') < time() - (3600 * Upgrader::DEFAULT_CHECK_VERSION_DELAY_HOURS))
|
if (Configuration::get('PS_LAST_VERSION_CHECK') < time() - (3600 * Upgrader::DEFAULT_CHECK_VERSION_DELAY_HOURS))
|
||||||
$tpl_vars['refresh_check_version'] = 1;
|
$tpl_vars['refresh_check_version'] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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'));
|
||||||
|
|
||||||
$tpl_vars['upgrade'] = $upgrade;
|
$tpl_vars['upgrade'] = $upgrade;
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ class AdminModulesControllerCore extends AdminController
|
|||||||
protected $filter_configuration = array();
|
protected $filter_configuration = array();
|
||||||
|
|
||||||
protected $xml_modules_list = 'api.prestashop.com/xml/modules_list_15.xml';
|
protected $xml_modules_list = 'api.prestashop.com/xml/modules_list_15.xml';
|
||||||
protected $addons_url = 'api.addons.prestashop.com';
|
|
||||||
protected $logged_on_addons = false;
|
protected $logged_on_addons = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,101 +128,6 @@ class AdminModulesControllerCore extends AdminController
|
|||||||
$this->logged_on_addons = true;
|
$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()
|
public function ajaxProcessRefreshModuleList()
|
||||||
{
|
{
|
||||||
// Refresh modules_list.xml every week
|
// 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))
|
if ($this->refresh(Module::CACHE_FILE_MODULES_LIST, 'https://'.$this->xml_modules_list))
|
||||||
$this->status = 'refresh';
|
$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';
|
$this->status = 'refresh';
|
||||||
else
|
else
|
||||||
$this->status = 'error';
|
$this->status = 'error';
|
||||||
|
|||||||
Reference in New Issue
Block a user