[-] BO : AdminModules fix on Addons Connection
This commit is contained in:
@@ -73,10 +73,10 @@
|
||||
{if !isset($logged_on_addons)}
|
||||
<!--start addons login-->
|
||||
<div class="filter-module" id="addons_login_div">
|
||||
<p>{l s='You have already got an Add On customer account'}</p>
|
||||
<p>{l s='You have a PrestaShop Addons account ?'}</p>
|
||||
<form id="addons_login_form" method="post">
|
||||
<label>{l s='Login Addons'} :</label> <input type="text" value="" id="username_addons" autocomplete="off" class="ac_input">
|
||||
<label>{l s= 'Password Addons'} :</label> <input type="text" value="" id="password_addons" autocomplete="off" class="ac_input">
|
||||
<label>{l s= 'Password Addons'} :</label> <input type="password" value="" id="password_addons" autocomplete="off" class="ac_input">
|
||||
<input type="submit" class="button" id="addons_login_button" value="{l s='Log in'}">
|
||||
<span id="addons_loading" style="color:red"></span>
|
||||
</form>
|
||||
|
||||
@@ -37,6 +37,12 @@
|
||||
var by = '{l s='by'}';
|
||||
var errorLogin = '{l s='Could not login to Addons'}';
|
||||
|
||||
{if isset($smarty.get.anchor)}
|
||||
$('document').ready( function() {
|
||||
$.scrollTo('#{$smarty.get.anchor|htmlentities}', 1200, {literal}{offset: -100}{/literal});
|
||||
});
|
||||
{/if}
|
||||
|
||||
{literal}
|
||||
function getPrestaStore(){if(getE("prestastore").style.display!='block')return;$.post(dirNameCurrentIndex+"/ajax.php",{page:"prestastore"},function(a){getE("prestastore-content").innerHTML=a;})}
|
||||
function truncate_author(author){return ((author.length > 20) ? author.substring(0, 20)+"..." : author);}
|
||||
@@ -177,10 +183,11 @@
|
||||
success : function(data)
|
||||
{
|
||||
// res.status = cache or refresh
|
||||
if (data != 'KO')
|
||||
if (data == 'OK')
|
||||
{
|
||||
$('#addons_loading').html('');
|
||||
$('#addons_login_div').fadeOut();
|
||||
window.location.href = window.location.href;
|
||||
}
|
||||
else
|
||||
$('#addons_loading').html(errorLogin);
|
||||
|
||||
+43
-41
@@ -588,7 +588,7 @@ abstract class ModuleCore
|
||||
* @param boolean $useConfig in order to use config.xml file in module dir
|
||||
* @return array Modules
|
||||
*/
|
||||
public static function getModulesOnDisk($useConfig = false)
|
||||
public static function getModulesOnDisk($useConfig = false, $loggedOnAddons = false)
|
||||
{
|
||||
global $_MODULES;
|
||||
|
||||
@@ -737,52 +737,54 @@ abstract class ModuleCore
|
||||
|
||||
|
||||
// Get Default Country Modules and customer module
|
||||
$filesList = array(_PS_ROOT_DIR_.'/config/default_country_modules_list.xml', _PS_ROOT_DIR_.'/config/default_customer_modules_list.xml');
|
||||
foreach ($filesList as $file)
|
||||
if (file_exists($file))
|
||||
{
|
||||
$content = Tools::file_get_contents($file);
|
||||
$xml = @simplexml_load_string($content, NULL, LIBXML_NOCDATA);
|
||||
foreach ($xml->module as $modaddons)
|
||||
if ($loggedOnAddons)
|
||||
{
|
||||
$filesList = array(_PS_ROOT_DIR_.'/config/default_country_modules_list.xml', _PS_ROOT_DIR_.'/config/customer_modules_list.xml');
|
||||
foreach ($filesList as $file)
|
||||
if (file_exists($file))
|
||||
{
|
||||
$flagFound = 0;
|
||||
foreach ($moduleList as $k => $m)
|
||||
if ($m->name == $modaddons->name && !isset($m->available_on_addons))
|
||||
{
|
||||
$flagFound = 1;
|
||||
if ($m->version != $modaddons->version && version_compare($m->version, $modaddons->version) === -1)
|
||||
$moduleList[$k]->version_addons = $modaddons->version;
|
||||
}
|
||||
if ($flagFound == 0)
|
||||
$content = Tools::file_get_contents($file);
|
||||
$xml = @simplexml_load_string($content, NULL, LIBXML_NOCDATA);
|
||||
foreach ($xml->module as $modaddons)
|
||||
{
|
||||
$item = new stdClass();
|
||||
$item->id = 0;
|
||||
$item->warning = '';
|
||||
$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 = strip_tags((string)$modaddons->description);
|
||||
$item->author = strip_tags((string)$modaddons->author);
|
||||
$item->limited_countries = array();
|
||||
$item->is_configurable = 0;
|
||||
$item->need_instance = 0;
|
||||
$item->available_on_addons = 1;
|
||||
$item->active = 0;
|
||||
if (!isset($modaddons->img) && isset($modaddons->id))
|
||||
$modaddons->img = 'http://media.prestastore.com/img/pico/'.(int)$modaddons->id.'.jpg';
|
||||
if (isset($modaddons->img))
|
||||
$flagFound = 0;
|
||||
foreach ($moduleList as $k => $m)
|
||||
if ($m->name == $modaddons->name && !isset($m->available_on_addons))
|
||||
{
|
||||
$flagFound = 1;
|
||||
if ($m->version != $modaddons->version && version_compare($m->version, $modaddons->version) === -1)
|
||||
$moduleList[$k]->version_addons = $modaddons->version;
|
||||
}
|
||||
if ($flagFound == 0)
|
||||
{
|
||||
if (!file_exists('../img/tmp/'.md5($modaddons->name).'.jpg'))
|
||||
copy($modaddons->img, '../img/tmp/'.md5($modaddons->name).'.jpg');
|
||||
if (file_exists('../img/tmp/'.md5($modaddons->name).'.jpg'))
|
||||
$item->image = '../img/tmp/'.md5($modaddons->name).'.jpg';
|
||||
$item = new stdClass();
|
||||
$item->id = 0;
|
||||
$item->warning = '';
|
||||
$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 = strip_tags((string)$modaddons->description);
|
||||
$item->author = strip_tags((string)$modaddons->author);
|
||||
$item->limited_countries = array();
|
||||
$item->is_configurable = 0;
|
||||
$item->need_instance = 0;
|
||||
$item->available_on_addons = 1;
|
||||
$item->active = 0;
|
||||
if (!isset($modaddons->img) && isset($modaddons->id))
|
||||
$modaddons->img = 'http://media.prestastore.com/img/pico/'.(int)$modaddons->id.'.jpg';
|
||||
if (isset($modaddons->img))
|
||||
{
|
||||
if (!file_exists('../img/tmp/'.md5($modaddons->name).'.jpg'))
|
||||
copy($modaddons->img, '../img/tmp/'.md5($modaddons->name).'.jpg');
|
||||
if (file_exists('../img/tmp/'.md5($modaddons->name).'.jpg'))
|
||||
$item->image = '../img/tmp/'.md5($modaddons->name).'.jpg';
|
||||
}
|
||||
$moduleList[] = $item;
|
||||
}
|
||||
$moduleList[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//echo round($current_memory / 1024 / 1024, 2).'Mo<br />';
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class AdminModulesControllerCore extends AdminController
|
||||
private $addons_url = 'https://addons.prestashop.com/webservice/151/';
|
||||
private $logged_on_addons = false;
|
||||
private $cache_file_default_country_modules_list = '/config/default_country_modules_list.xml';
|
||||
private $cache_file_customer_modules_list = '/config/default_customer_modules_list.xml';
|
||||
private $cache_file_customer_modules_list = '/config/customer_modules_list.xml';
|
||||
|
||||
/*
|
||||
** Admin Modules Controller Constructor
|
||||
@@ -131,6 +131,11 @@ class AdminModulesControllerCore extends AdminController
|
||||
$this->logged_on_addons = true;
|
||||
}
|
||||
|
||||
public function setMedia()
|
||||
{
|
||||
parent::setMedia();
|
||||
$this->addJqueryPlugin('scrollTo');
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -189,7 +194,7 @@ class AdminModulesControllerCore extends AdminController
|
||||
// If logged to Addons Webservices, refresh customer modules list every day
|
||||
if ($this->logged_on_addons && $this->status != 'error')
|
||||
{
|
||||
if (!$this->isFresh($this->cache_file_customer_modules_list, 86400))
|
||||
if (!$this->isFresh($this->cache_file_customer_modules_list, 60))
|
||||
{
|
||||
if ($this->refresh($this->cache_file_customer_modules_list, $this->addons_url.'listing/customer/'.pSQL(trim($this->context->cookie->username_addons)).'/'.pSQL(trim($this->context->cookie->password_addons))))
|
||||
$this->status = 'refresh';
|
||||
@@ -209,13 +214,19 @@ class AdminModulesControllerCore extends AdminController
|
||||
|
||||
public function ajaxProcessLogOnAddonsWebservices()
|
||||
{
|
||||
$content = Tools::file_get_contents($this->addons_url.'listing/customer/'.pSQL(trim(Tools::getValue('username_addons'))).'/'.pSQL(trim(Tools::getValue('password_addons'))));
|
||||
$content = Tools::file_get_contents($this->addons_url.'check_customer/'.pSQL(trim(Tools::getValue('username_addons'))).'/'.pSQL(trim(Tools::getValue('password_addons'))));
|
||||
$xml = @simplexml_load_string($content, NULL, LIBXML_NOCDATA);
|
||||
if (!$xml)
|
||||
die('KO');
|
||||
$this->context->cookie->username_addons = pSQL(trim(Tools::getValue('username_addons')));
|
||||
$this->context->cookie->password_addons = pSQL(trim(Tools::getValue('password_addons')));
|
||||
die('OK');
|
||||
$result = strtoupper((string)$xml->msg);
|
||||
if (!in_array($result, array('OK', 'KO')))
|
||||
die ('KO');
|
||||
if ($result == 'OK')
|
||||
{
|
||||
$this->context->cookie->username_addons = pSQL(trim(Tools::getValue('username_addons')));
|
||||
$this->context->cookie->password_addons = pSQL(trim(Tools::getValue('password_addons')));
|
||||
}
|
||||
die($result);
|
||||
}
|
||||
|
||||
public function ajaxProcessReloadModulesList()
|
||||
@@ -383,7 +394,7 @@ class AdminModulesControllerCore extends AdminController
|
||||
{
|
||||
if ($module->uninstall())
|
||||
if ($module->install())
|
||||
Tools::redirectAdmin(self::$currentIndex.'&conf=21'.'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name);
|
||||
Tools::redirectAdmin(self::$currentIndex.'&conf=21'.'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name));
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('Cannot install module');
|
||||
else
|
||||
@@ -489,16 +500,17 @@ class AdminModulesControllerCore extends AdminController
|
||||
// If Addons module, download and unzip it before installing it
|
||||
if ($this->logged_on_addons && !is_dir('../modules/'.$name.'/'))
|
||||
{
|
||||
$file = _PS_ROOT_DIR_.'/config/default_customer_modules_list.xml';
|
||||
if (file_exists($file))
|
||||
{
|
||||
$content = Tools::file_get_contents($file);
|
||||
$xml = @simplexml_load_string($content, NULL, LIBXML_NOCDATA);
|
||||
foreach ($xml->module as $modaddons)
|
||||
if ($name == $modaddons->name && isset($modaddons->id))
|
||||
if (@copy($this->addons_url.'module/'.pSQL($modaddons->id).'/'.pSQL(trim($this->context->cookie->username_addons)).'/'.pSQL(trim($this->context->cookie->password_addons)), '../modules/'.$this->name.'.zip'))
|
||||
$this->extractArchive('../modules/'.$this->name.'.zip');
|
||||
}
|
||||
$filesList = array($this->cache_file_default_country_modules_list, $this->cache_file_customer_modules_list);
|
||||
foreach ($filesList as $file)
|
||||
if (file_exists(_PS_ROOT_DIR_.$file))
|
||||
{
|
||||
$content = Tools::file_get_contents(_PS_ROOT_DIR_.$file);
|
||||
$xml = @simplexml_load_string($content, NULL, LIBXML_NOCDATA);
|
||||
foreach ($xml->module as $modaddons)
|
||||
if ($name == $modaddons->name && isset($modaddons->id))
|
||||
if (@copy($this->addons_url.'module/'.pSQL($modaddons->id).'/'.pSQL(trim($this->context->cookie->username_addons)).'/'.pSQL(trim($this->context->cookie->password_addons)), '../modules/'.$modaddons->name.'.zip'))
|
||||
$this->extractArchive('../modules/'.$modaddons->name.'.zip');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -599,7 +611,7 @@ class AdminModulesControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
if ($return)
|
||||
Tools::redirectAdmin(self::$currentIndex.'&conf='.$return.'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name);
|
||||
Tools::redirectAdmin(self::$currentIndex.'&conf='.$return.'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name));
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
@@ -782,7 +794,7 @@ class AdminModulesControllerCore extends AdminController
|
||||
$this->list_modules_categories[$k]['nb'] = 0;
|
||||
|
||||
// Retrieve Modules List
|
||||
$modules = Module::getModulesOnDisk(true);
|
||||
$modules = Module::getModulesOnDisk(true, $this->logged_on_addons);
|
||||
$this->initModulesList($modules);
|
||||
$this->nb_modules_total = count($modules);
|
||||
|
||||
@@ -803,8 +815,8 @@ class AdminModulesControllerCore extends AdminController
|
||||
$modules[$km]->logo = 'logo.png';
|
||||
$modules[$km]->optionsHtml = $this->displayModuleOptions($module);
|
||||
$modules[$km]->categoryName = (isset($this->list_modules_categories[$module->tab]['name']) ? $this->list_modules_categories[$module->tab]['name'] : $this->list_modules_categories['others']['name']);
|
||||
$modules[$km]->options['install_url'] = self::$currentIndex.'&install='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'#anchor'.ucfirst($module->name);
|
||||
$modules[$km]->options['uninstall_url'] = self::$currentIndex.'&uninstall='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'#anchor'.ucfirst($module->name);
|
||||
$modules[$km]->options['install_url'] = self::$currentIndex.'&install='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
|
||||
$modules[$km]->options['uninstall_url'] = self::$currentIndex.'&uninstall='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
|
||||
$modules[$km]->options['uninstall_onclick'] = ((!method_exists($module, 'onclickOption')) ? ((empty($module->confirmUninstall)) ? '' : 'if(confirm(\''.addslashes($module->confirmUninstall).'\')) ').'document.location.href=\''.$modules[$km]->options['uninstall_url'].'\'' : $module->onclickOption('uninstall', $modules[$km]->options['uninstall_url']));
|
||||
if (Tools::getValue('module_name') == $module->name && (int)Tools::getValue('conf') > 0)
|
||||
$modules[$km]->message = $this->_conf[(int)Tools::getValue('conf')];
|
||||
|
||||
Reference in New Issue
Block a user