Merge branch 'bootstrap' of https://github.com/PrestaShop/PrestaShop into bootstrap

This commit is contained in:
Kevin Granger
2013-11-07 21:49:11 +01:00
22 changed files with 391 additions and 283 deletions
+1
View File
@@ -562,6 +562,7 @@
var options = $.extend({}, this.options, data);
this._initFormSettings(options);
this._initDataSettings(options);
options.url = options.url+'&rand=' + new Date().getTime();
return options;
},
@@ -29,7 +29,7 @@ $(function() {
});
</script>
{if !$nb_results}
{if !isset($nb_results) || !$nb_results}
<h2>{l s='There are no results matching your query "%s".' sprintf=$query}</h2>
{else}
<h2>
+4 -2
View File
@@ -71,7 +71,9 @@
var token_admin_customer_threads = '{getAdminToken tab='AdminCustomerThreads'}';
var currentIndex = '{$currentIndex|@addcslashes:'\''}';
var choose_language_translate = '{l s='Choose language' js=1}';
var default_language = '{$default_language|addslashes}';
var default_language = '{$default_language|intval}';
var admin_modules_link = '{$link->getAdminLink("AdminModules")|addslashes}';
var tab_modules_list = '{if isset($tab_modules_list) && $tab_modules_list}{$tab_modules_list|addslashes}{/if}';
</script>
{/if}
{if isset($css_files)}
@@ -111,7 +113,7 @@
<i class="icon-reorder"></i>
</button>
<a id="header_shopname" href="{$link->getAdminLink('AdminDashboard')|escape:'htmlall':'UTF-8'}">
<a id="header_shopname" href="{$default_tab_link|escape:'htmlall':'UTF-8'}">
<img src="{$img_dir}prestashop-avatar.png" height="15" width="15" />
{$shop_name}
</a>
@@ -214,7 +214,7 @@
{$params.title}
{/if}
{if (!isset($params.orderby) || $params.orderby) && !$simple_header}
{if (!isset($params.orderby) || $params.orderby) && !$simple_header && $show_filters}
<a {if isset($order_by) && ($key == $order_by) && ($order_way == 'DESC')}class="active"{/if} href="{$currentIndex}&{$list_id}Orderby={$key|urlencode}&{$list_id}Orderway=desc&token={$token}{if isset($smarty.get.$identifier)}&{$identifier}={$smarty.get.$identifier|intval}{/if}">
<i class="icon-caret-down"></i>
</a>
@@ -43,6 +43,18 @@
{/if}
</div>
</div>
{if isset($max_files) && $files|count >= $max_files}
<div class="row">
<div class="alert alert-warning">{l s='You have reached the limit (%s) of files to upload, please remove files to continue uploading' sprintf=$max_files}</div>
</div>
<script type="text/javascript">
$( document ).ready(function() {
{if isset($files) && $files}
$('#{$id}-images-thumbnails').parent().show();
{/if}
});
</script>
{else}
<div class="form-group">
<div class="col-lg-12">
<input id="{$id}" type="file" name="{$name}[]"{if isset($url)} data-url="{$url}"{/if}{if isset($multiple) && $multiple} multiple="multiple"{/if} class="hide" />
@@ -55,167 +67,138 @@
</div>
</div>
<div class="row" style="display:none">
<div class="alert alert-info" id="{$id}-files-list">
<strong>{l s='Files:'}</strong>
<br />
</div>
<div class="alert alert-info" id="{$id}-files-list"></div>
</div>
<div class="row" style="display:none">
<div class="alert alert-success" id="{$id}-success"></div>
</div>
<div class="row" style="display:none">
<div class="alert alert-danger" id="{$id}-errors"></div>
</div>
<script type="text/javascript">
function humanizeSize(bytes)
{
if (typeof bytes !== 'number') {
return '';
}
if (bytes >= 1000000000) {
return (bytes / 1000000000).toFixed(2) + ' GB';
}
if (bytes >= 1000000) {
return (bytes / 1000000).toFixed(2) + ' MB';
}
return (bytes / 1000).toFixed(2) + ' KB';
}
$( document ).ready(function() {
{if isset($multiple) && isset($max_files)}
var {$id}_max_files = {$max_files};
var {$id}_max_files = {$max_files - $files|count};
{/if}
{if isset($files) && $files}
$('#{$id}-images-thumbnails').parent().show();
{/if}
var {$id}_total_files = 0;
var {$id}_upload_button = Ladda.create( document.querySelector('#{$id}-upload-button' ));
var {$id}_total_files = 0;
var data = $('#{$id}').fileupload({
$('#{$id}').fileupload({
dataType: 'json',
autoUpload: false,
singleFileUploads: false,
add: function(e, data) {
if (typeof {$id}_max_files !== 'undefined') {
if ({$id}_total_files >= {$id}_max_files || data.originalFiles.length > {$id}_max_files) {
e.preventDefault();
alert('{l s='You can upload a maximum of %s files'|sprintf:$max_files}');
return;
}
}
{$id}_total_files++;
$('#{$id}-upload-button').show().on('click', function () {
data.submit();
});
},
start: function () {
singleFileUploads: true,
maxFileSize: {$post_max_size},
start: function (e) {
{$id}_upload_button.start();
$('#{$id}-upload-button').unbind('click'); //Important as we bind it for every elements in add function
},
fail: function (e, data) {
$('#{$id}-errors').html(data.errorThrown.message).parent().show();
},
done: function (e, data) {
if (typeof data.result.{$name} !== 'undefined') {
for (var i=0; i<data.result.{$name}.length; i++) {
if (typeof data.result.{$name}[i].image !== 'undefined') {
var template = '<div class="img-thumbnail text-center">';
template += '<p>'+data.result.{$name}[i].image+'</p>';
if (typeof data.result.{$name}[i].delete_url !== 'undefined') {
template += '<p><a class="btn btn-default" href="'+data.result.{$name}[i].delete_url+'"><i class="icon-trash"></i> {l s='Delete'}</a></p>';
}
if (data.result) {
if (typeof data.result.{$name} !== 'undefined') {
for (var i=0; i<data.result.{$name}.length; i++) {
if (data.result.{$name}[i] !== null) {
if (typeof data.result.{$name}[i].image !== 'undefined') {
var template = '<div class="img-thumbnail text-center">';
template += '<p>'+data.result.{$name}[i].image+'</p>';
if (typeof data.result.{$name}[i].delete_url !== 'undefined') {
template += '<p><a class="btn btn-default" href="'+data.result.{$name}[i].delete_url+'"><i class="icon-trash"></i> {l s='Delete'}</a></p>';
}
template += '</div>';
$('#{$id}-images-thumbnails').html($('#{$id}-images-thumbnails').html()+template);
$('#{$id}-images-thumbnails').parent().show();
template += '</div>';
$('#{$id}-images-thumbnails').html($('#{$id}-images-thumbnails').html()+template);
$('#{$id}-images-thumbnails').parent().show();
}
}
}
}
$(data.context).find('button').remove();
$(data.context).appendTo($('#{$id}-success'));
$('#{$id}-success').parent().show();
}
},
always: function (e, data) {
{$id}_upload_button.stop();
}
});
}).on('fileuploadalways', function (e, data) {
{$id}_total_files--;
$('#{$id}-add-button').on('click', function() {
$('#{$id}').trigger('click');
});
});
/**/
/*
var total_files = 0;
var total_uploaded_files = 0;
{if isset($multiple) && isset($max_files)}
var {$id}_max_files = {$max_files};
{/if}
$('#{$id}').fileupload(
{
dataType: 'json',
autoUpload: false,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
maxFileSize: 5000000, // 5 MB
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
previewMaxWidth: 100,
previewMaxHeight: 100,
previewCrop: false,
done: function (e, data) {
$.each(data.result, function (index, file) {
if (file[0].error)
$('#{$id}-errors').append(file[0].error+'<br/>').parent().show();
else
total_uploaded_files ++;
});
if (total_uploaded_files == data.originalFiles.length)
$('#{$id}-upload-button').css('background-color', 'green').children('.icon-cloud-upload').removeClass('icon-cloud-upload').addClass('icon-check');
},
progressall: function (e, data) {
upload_button.setProgress(data.loaded / data.total);
},
add: function (e, data) {
console.log(data.originalFiles.length);
if (typeof {$id}_max_files !== 'undefined')
{
if (data.originalFiles.length > {$id}_max_files) {
if ({$id}_total_files == 0)
{
{$id}_upload_button.stop();
$('#{$id}-upload-button').unbind('click');
$('#{$id}-files-list').parent().hide();
}
}).on('fileuploadadd', function(e, data) {
if (typeof {$id}_max_files !== 'undefined') {
if ({$id}_total_files >= {$id}_max_files) {
e.preventDefault();
alert('{l s='You can upload a maximum of %s files'|sprintf:$max_files}');
return;
}
}
data.context = $('#{$id}-files-list');
data.context.parent().show();
data.context = $('<div/>').addClass('row').appendTo($('#{$id}-files-list'));
var file_name = $('<span/>').append('<strong>'+data.files[0].name+'</strong> ('+humanizeSize(data.files[0].size)+')').appendTo(data.context);
$.each(data.files, function (index, file) {
var node = '<div class="row"><span>'+file.name+'</span><button class="btn btn-default pull-right" type="button"><i class="icon-trash"></i> Remove from list</button></div>';
data.context.append(node);
});
var button = $('<button/>').addClass('btn btn-default pull-right').prop('type', 'button').html('<i class="icon-trash"></i> {l s='Remove file'}').appendTo(data.context).on('click', function() {
{$id}_total_files--;
data.files = null;
var total_elements = $(this).parent().siblings('div.row').length;
$(this).parent().remove();
$('#{$id}-upload-button').show().on('click', function () {
total_files = data.originalFiles.length;
data.submit();
});
},
fail: function (e, data) {
$('#{$id}-errors').html(data.errorThrown.message).parent().show();
},
always: function (e, data) {
total_files--;
if (total_elements == 0) {
$('#{$id}-files-list').html('').parent().hide();
}
});
if (total_files == 0)
upload_button.stop();
}
});*/
$('#{$id}-files-list').parent().show();
$('#{$id}-upload-button').show().bind('click', function () {
if (data.files != null)
data.submit();
});
</script>
{$id}_total_files++;
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index, file = data.files[index];
if (file.error) {
$('#{$id}-errors').append('<div class="row"><strong>'+file.name+'</strong> ('+humanizeSize(file.size)+') : '+file.error+'</div>').parent().show();
$(data.context).find('button').trigger('click');
}
});
$('#{$id}-add-button').on('click', function() {
$('#{$id}-success').html('').parent().hide();
$('#{$id}-errors').html('').parent().hide();
$('#{$id}-files-list').html('').parent().hide();
{$id}_total_files = 0;
$('#{$id}').trigger('click');
});
});
</script>
{/if}
@@ -50,6 +50,11 @@
</div>
</div>
{/if}
{if isset($max_files) && $files|count >= $max_files}
<div class="row">
<div class="alert alert-warning">{l s='You have reached the limit (%s) of files to upload, please remove files to continue uploading' sprintf=$max_files}</div>
</div>
{else}
<div class="form-group">
<div class="col-lg-12">
<input id="{$id}" type="file" name="{$name}"{if isset($multiple) && $multiple} multiple="multiple"{/if} class="hide" />
@@ -72,10 +77,9 @@
</div>
</div>
</div>
<script type="text/javascript">
{if isset($multiple) && isset($max_files)}
var {$id}_max_files = {$max_files};
var {$id}_max_files = {$max_files - $files|count};
{/if}
$(document).ready(function(){
@@ -116,4 +120,5 @@
});
}
});
</script>
</script>
{/if}
+7 -1
View File
@@ -205,7 +205,13 @@ class DispatcherCore
{
$this->front_controller = self::FC_ADMIN;
$this->controller_not_found = 'adminnotfound';
$this->default_controller = 'admindashboard';
if (isset(Context::getContext()->employee) && Validate::isLoadedObject(Context::getContext()->employee) && isset(Context::getContext()->employee->default_tab))
{
$tab = new Tab((int)Context::getContext()->employee->default_tab);
$this->default_controller = $tab->class_name;
}
else
$this->default_controller = 'admindashboard';
}
elseif (Tools::getValue('fc') == 'module')
{
+24 -21
View File
@@ -48,9 +48,6 @@ class UploaderCore
public function getAcceptTypes()
{
if (!isset($this->_accept_types))
$this->setAcceptTypes('/.+$/i');
return $this->_accept_types;
}
@@ -101,6 +98,21 @@ class UploaderCore
return $this;
}
public function getPostMaxSizeBytes() {
$post_max_size = ini_get('post_max_size');
$bytes = trim($post_max_size);
$last = strtolower($post_max_size[strlen($post_max_size) - 1]);
switch ($last)
{
case 'g': $bytes *= 1024;
case 'm': $bytes *= 1024;
case 'k': $bytes *= 1024;
}
return $bytes;
}
public function getSavePath()
{
if (!isset($this->_save_path))
@@ -134,8 +146,11 @@ class UploaderCore
$this->files[] = $this->upload($tmp[$index]);
}
}
else
elseif ($upload)
{
$this->files[] = $this->upload($upload);
}
return $this->files;
}
@@ -173,7 +188,7 @@ class UploaderCore
protected function validate($file)
{
$post_max_size = $this->_getPostMaxSizeBytes();
$post_max_size = $this->getPostMaxSizeBytes();
if ($post_max_size && ($this->_getServerVars('CONTENT_LENGTH') > $post_max_size))
{
@@ -181,7 +196,10 @@ class UploaderCore
return false;
}
if (!preg_match($this->getAcceptTypes(), $file['name']))
$types = $this->getAcceptTypes();
//TODO check mime type.
if (isset($types) && !in_array(pathinfo($file['name'], PATHINFO_EXTENSION), $types))
{
$file['error'] = Tools::displayError('Filetype not allowed');
return false;
@@ -203,21 +221,6 @@ class UploaderCore
return filesize($file_path);
}
protected function _getPostMaxSizeBytes() {
$post_max_size = ini_get('post_max_size');
$bytes = trim($post_max_size);
$last = strtolower($post_max_size[strlen($post_max_size) - 1]);
switch ($last)
{
case 'g': $bytes *= 1024;
case 'm': $bytes *= 1024;
case 'k': $bytes *= 1024;
}
return $bytes;
}
protected function _getServerVars($var)
{
return (isset($_SERVER[$var]) ? $_SERVER[$var] : '');
+6 -2
View File
@@ -1502,7 +1502,7 @@ class AdminControllerCore extends Controller
if (Validate::isLoadedObject($this->context->employee))
{
$accesses = Profile::getProfileAccesses($this->context->employee->id_profile, 'class_name');
$default_tab = new Tab((int)Context::getContext()->employee->default_tab);
/* Hooks are volontary out the initialize array (need those variables already assigned) */
$bo_color = empty($this->context->employee->bo_color) ? '#FFFFFF' : $this->context->employee->bo_color;
$this->context->smarty->assign(array(
@@ -1516,7 +1516,7 @@ class AdminControllerCore extends Controller
'show_new_customers' => Configuration::get('PS_SHOW_NEW_CUSTOMERS') && $accesses['AdminCustomers']['view'],
'show_new_messages' => Configuration::get('PS_SHOW_NEW_MESSAGES') && $accesses['AdminCustomerThreads']['view'],
'first_name' => Tools::substr($this->context->employee->firstname, 0, 1),
'last_name' => htmlentities($this->context->employee->lastname, ENT_COMPAT, 'UTF-8'),
'last_name' => Tools::safeOutput($this->context->employee->lastname),
'employee' => $this->context->employee,
'search_type' => Tools::getValue('bo_search_type'),
'bo_query' => Tools::safeOutput(Tools::stripslashes(Tools::getValue('bo_query'))),
@@ -1529,9 +1529,13 @@ class AdminControllerCore extends Controller
'tabs' => $tabs,
'is_multishop' => $is_multishop,
'multishop_context' => $this->multishop_context,
'default_tab_link' => $this->context->link->getAdminLink($default_tab->class_name),
'employee_avatar' => ImageManager::thumbnail($this->context->employee->getImage(), 'employee'.'_'.(int)$this->context->employee->id.'.'.$this->imageType, 150, $this->imageType, true, true)
));
}
else
$this->context->smarty->assign('default_tab_link', $this->context->link->getAdminLink('AdminDashboard'));
$this->context->smarty->assign(array(
'img_dir' => _PS_IMG_,
'iso' => $this->context->language->iso_code,
+1 -1
View File
@@ -118,6 +118,7 @@ class HelperFormCore extends Helper
$uploader->setUrl(isset($params['url'])?$params['url']:null);
$uploader->setMultiple(isset($params['multiple'])?$params['multiple']:false);
$uploader->setUseAjax(isset($params['ajax'])?$params['ajax']:false);
$uploader->setMaxFiles(isset($params['max_files'])?$params['max_files']:null);
if (isset($params['files']) && $params['files'])
$uploader->setFiles($params['files']);
@@ -139,7 +140,6 @@ class HelperFormCore extends Helper
'download_url' => isset($params['file'])?$params['file']:null
)));
$uploader->setThumb(isset($params['thumb'])?$params['thumb']:null);
$uploader->setTitle(isset($params['title'])?$params['title']:null);
+8 -15
View File
@@ -26,35 +26,25 @@
class HelperImageUploaderCore extends HelperUploader
{
private $_temporary_path;
public function getMaxSize()
{
return (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
}
public function setTemporaryPath($value)
public function getSavePath()
{
$this->_temporary_path = $value;
}
public function getTemporaryPath()
{
if (!isset($this->_temporary_path))
$this->_temporary_path = _PS_TMP_IMG_DIR_;
return $this->_normalizeDirectory($this->_temporary_path);
return $this->_normalizeDirectory(_PS_TMP_IMG_DIR_);
}
public function getFilePath($file_name = null)
{
//Force file path
return tempnam($this->getTemporaryPath(), $this->getUniqueFileName());
return tempnam($this->getSavePath(), $this->getUniqueFileName());
}
protected function validate($file)
{
$post_max_size = $this->_getPostMaxSizeBytes();
$post_max_size = $this->getPostMaxSizeBytes();
if ($post_max_size && ($this->_getServerVars('CONTENT_LENGTH') > $post_max_size))
{
@@ -62,7 +52,10 @@ class HelperImageUploaderCore extends HelperUploader
return false;
}
if (!preg_match($this->getAcceptTypes(), $file['name']))
$types = $this->getAcceptTypes();
//TODO check mime type.
if (isset($types) && !in_array(pathinfo($file['name'], PATHINFO_EXTENSION), $types))
{
$file['error'] = Tools::displayError('Filetype not allowed');
return false;
+1
View File
@@ -104,6 +104,7 @@ class HelperOptionsCore extends Helper
$uploader->setUrl(isset($field['url'])?$field['url']:null);
$uploader->setMultiple(isset($field['multiple'])?$field['multiple']:false);
$uploader->setUseAjax(isset($field['ajax'])?$field['ajax']:false);
$uploader->setMaxFiles(isset($field['max_files'])?$field['max_files']:null);
if (isset($field['files']) && $field['files'])
$uploader->setFiles($field['files']);
+13 -8
View File
@@ -243,22 +243,28 @@ class HelperUploaderCore extends Uploader
.'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js"></script>';
$html .= '<script type="text/javascript" src="'.__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js"></script>';
$html .= '<script type="text/javascript" src="'.__PS_BASE_URI__.$admin_webpath
$html .= '<script type="text/javascript" src="'.__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.fileupload.js"></script>';
$html .= '<script type="text/javascript" src="'.__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js"></script>';
$html .= '<script type="text/javascript" src="'.__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js"></script>';
$html .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'/js/vendor/spin.js"></script>';
$html .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'/js/vendor/ladda.js"></script>';
}
else
{
$html = '';
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js');
//$context->controller->addJs('http://blueimp.github.io/JavaScript-Load-Image/js/load-image.min.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.fileupload.js');
/*$context->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.fileupload-image.js');*/
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__.'/js/vendor/spin.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__.'/js/vendor/ladda.js');
}
@@ -270,8 +276,6 @@ class HelperUploaderCore extends Uploader
$this->getTemplateFile($this->getTemplate()), $this->getContext()->smarty
);
$max_files = $this->getMaxFiles();
$template->assign(array(
'id' => $this->getId(),
'name' => $this->getName(),
@@ -280,7 +284,8 @@ class HelperUploaderCore extends Uploader
'files' => $this->getFiles(),
'thumb' => $this->getThumb(),
'title' => $this->getTitle(),
'max_files' => (isset($max_files) && $max_files > 0) ? ($max_files-count($this->getFiles())) : $max_files
'max_files' => $this->getMaxFiles(),
'post_max_size' => $this->getPostMaxSizeBytes()
));
$html .= $template->fetch();
@@ -312,11 +312,6 @@ class AdminCategoriesControllerCore extends AdminController
}
}
public function ajaxProcessuploadThumbnailImages()
{
Hook::exec('actionBackOfficeCategory');
}
public function initProcess()
{
if (Tools::isSubmit('add'.$this->table.'root'))
@@ -616,9 +611,9 @@ class AdminCategoriesControllerCore extends AdminController
Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminCategories').'&conf=7');
}
Hook::exec('actionBackOfficeCategoryRemoveThumbnail');
return parent::postProcess();
}
public function processForceDeleteImage()
{
$category = $this->loadObject(true);
+4
View File
@@ -199,6 +199,10 @@ class CategoryControllerCore extends FrontController
// Pagination must be call after "getProducts"
$this->pagination($this->nbProducts);
Hook::exec('actionProductListModifier', array(
'nb_products' => &$this->nbProducts,
'cat_products' => &$this->cat_products,
));
foreach ($this->cat_products as &$product)
if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity']))
-6
View File
@@ -283,11 +283,5 @@
<hook id="displayBackOfficeCategory" live_edit="0">
<name>displayBackOfficeCategory</name><title>Display new elements in the Back Office, tab AdminCategories</title><description>This hook launches modules when the AdminCategories tab is displayed in the Back Office</description>
</hook>
<hook id="actionBackOfficeCategory" live_edit="0">
<name>actionBackOfficeCategory</name><title>Process new elements in the Back Office, tab AdminCategories</title><description>This hook process modules when the AdminCategories tab is displayed in the Back Office</description>
</hook>
<hook id="actionBackOfficeCategoryRemoveThumbnail" live_edit="0">
<name>actionBackOfficeCategoryRemoveThumbnail</name><title>Delete elements in the Back Office, tab AdminCategories</title><description>This hook process modules when the AdminCategories tab call delete thumbnail</description>
</hook>
</entities>
</entity_hook>
+23 -81
View File
@@ -45,7 +45,18 @@ class BlockCategories extends Module
public function install()
{
if (!parent::install() ||
// Prepare tab
$tab = new Tab();
$tab->active = 1;
$tab->class_name = "AdminBlockCategories";
$tab->name = array();
foreach (Language::getLanguages(true) as $lang)
$tab->name[$lang['id_lang']] = 'BlockCategories';
$tab->id_parent = -1;
$tab->module = $this->name;
if (!$tab->add() ||
!parent::install() ||
!$this->registerHook('leftColumn') ||
!$this->registerHook('footer') ||
!$this->registerHook('header') ||
@@ -56,8 +67,6 @@ class BlockCategories extends Module
!$this->registerHook('actionAdminMetaControllerUpdate_optionsBefore') ||
!$this->registerHook('actionAdminLanguagesControllerStatusBefore') ||
!$this->registerHook('displayBackOfficeCategory') ||
!$this->registerHook('actionBackOfficeCategory') ||
!$this->registerHook('actionBackOfficeCategoryRemoveThumbnail') ||
!Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 4) ||
!Configuration::updateValue('BLOCK_CATEG_DHTML', 1))
return false;
@@ -66,6 +75,14 @@ class BlockCategories extends Module
public function uninstall()
{
$id_tab = (int)Tab::getIdFromClassName('AdminBlockCategories');
if ($id_tab)
{
$tab = new Tab($id_tab);
$tab->delete();
}
if (!parent::uninstall() ||
!Configuration::deleteByName('BLOCK_CATEG_MAX_DEPTH') ||
!Configuration::deleteByName('BLOCK_CATEG_DHTML'))
@@ -136,93 +153,18 @@ class BlockCategories extends Module
{
$files[$i]['type'] = HelperImageUploader::TYPE_IMAGE;
$files[$i]['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.(int)$category->id.'-'.$i.'_thumb.jpg', $this->context->controller->table.'_'.(int)$category->id.'-'.$i.'_thumb.jpg', 100, 'jpg', true, true);
$files[$i]['delete_url'] = Context::getContext()->link->getAdminLink('AdminCategories').'&deleteThumb='.$i.'&id_category='.(int)$category->id;
$files[$i]['delete_url'] = Context::getContext()->link->getAdminLink('AdminBlockCategories').'&deleteThumb='.$i.'&id_category='.(int)$category->id;
}
}
$helper = new HelperImageUploader();
$helper->setMultiple(true)->setUseAjax(true)->setName('thumbnail')->setFiles($files)->setMaxFiles(3)->setUrl(
Context::getContext()->link->getAdminLink('AdminCategories').'&ajax=1&id_category='.$category->id.'&action=uploadThumbnailImages');
Context::getContext()->link->getAdminLink('AdminBlockCategories').'&ajax=1&id_category='.$category->id
.'&action=uploadThumbnailImages');
$this->smarty->assign('helper', $helper->render());
return $this->display(__FILE__, 'views/blockcategories_admin.tpl');
}
public function hookActionBackOfficeCategory($params)
{
$category = new Category((int)Tools::getValue('id_category'));
if (isset($_FILES['thumbnail']))
{
//Get total of image already present in directory
$files = scandir(_PS_CAT_IMG_DIR_);
$assigned_keys = array();
$allowed_keys = array(0, 1, 2);
foreach ($files as $file) {
$matches = array();
if (preg_match('/'.$category->id.'-([0-9])?_thumb.jpg/i', $file, $matches) === 1)
$assigned_keys[] = (int)$matches[1];
}
$available_keys = array_diff($allowed_keys, $assigned_keys);
$helper = new HelperImageUploader('files');
$files = $helper->setName('thumbnail')->process();
$total_errors = array();
if (count($available_keys) < count($files))
{
$total_errors[] = sprintf(Tools::displayError('You cannot upload more than %s files'), count($available_keys));
die();
}
foreach ($files as $key => &$file)
{
$id = array_shift($available_keys);
$errors = array();
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($file['save_path']))
$errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. ');
// Copy new image
if (empty($errors) && !ImageManager::resize($file['save_path'], _PS_CAT_IMG_DIR_
.(int)Tools::getValue('id_category').'-'.$id.'_thumb.jpg'))
$errors[] = Tools::displayError('An error occurred while uploading the image.');
if (count($errors))
$total_errors = array_merge($total_errors, $errors);
unlink($file['save_path']);
//Necesary to prevent hacking
unset($file['save_path']);
//Add image preview and delete url
$file['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.(int)$category->id.'-'.$id.'_thumb.jpg',
$this->context->controller->table.'_'.(int)$category->id.'-'.$id.'_thumb.jpg', 100, 'jpg', true, true);
$file['delete_url'] = Context::getContext()->link->getAdminLink('AdminCategories').'&deleteThumb='
.$id.'&id_category='.(int)$category->id;
$id++;
}
if (count($total_errors))
$this->context->controller->errors = array_merge($this->context->controller->errors, $total_errors);
die(Tools::jsonEncode(array('thumbnail' => $files)));
}
}
public function hookActionBackOfficeCategoryRemoveThumbnail()
{
if (($id_thumb = Tools::getValue('deleteThumb', false)) !== false)
{
if (file_exists(_PS_CAT_IMG_DIR_.(int)Tools::getValue('id_category').'-'.(int)$id_thumb.'_thumb.jpg')
&& !unlink(_PS_CAT_IMG_DIR_.(int)Tools::getValue('id_category').'-'.(int)$id_thumb.'_thumb.jpg'))
$this->context->controller->errors[] = Tools::displayError('Error while delete');
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminCategories').'&id_category='
.(int)Tools::getValue('id_category').'&updatecategory');
}
}
public function hookLeftColumn($params)
{
$category = false;
@@ -0,0 +1,108 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.6.0
*/
class AdminBlockCategoriesController extends ModuleAdminController
{
public function postProcess()
{
if (($id_thumb = Tools::getValue('deleteThumb', false)) !== false)
{
if (file_exists(_PS_CAT_IMG_DIR_.(int)Tools::getValue('id_category').'-'.(int)$id_thumb.'_thumb.jpg')
&& !unlink(_PS_CAT_IMG_DIR_.(int)Tools::getValue('id_category').'-'.(int)$id_thumb.'_thumb.jpg'))
$this->context->controller->errors[] = Tools::displayError('Error while delete');
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminCategories').'&id_category='
.(int)Tools::getValue('id_category').'&updatecategory');
}
parent::postProcess();
}
public function ajaxProcessuploadThumbnailImages()
{
$category = new Category((int)Tools::getValue('id_category'));
if (isset($_FILES['thumbnail']))
{
//Get total of image already present in directory
$files = scandir(_PS_CAT_IMG_DIR_);
$assigned_keys = array();
$allowed_keys = array(0, 1, 2);
foreach ($files as $file) {
$matches = array();
if (preg_match('/'.$category->id.'-([0-9])?_thumb.jpg/i', $file, $matches) === 1)
$assigned_keys[] = (int)$matches[1];
}
$available_keys = array_diff($allowed_keys, $assigned_keys);
$helper = new HelperImageUploader('thumbnail');
$files = $helper->process();
$total_errors = array();
if (count($available_keys) < count($files))
{
$total_errors[] = sprintf(Tools::displayError('You cannot upload more than %s files'), count($available_keys));
die();
}
foreach ($files as $key => &$file)
{
$id = array_shift($available_keys);
$errors = array();
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($file['save_path']))
$errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. ');
// Copy new image
if (empty($errors) && !ImageManager::resize($file['save_path'], _PS_CAT_IMG_DIR_
.(int)Tools::getValue('id_category').'-'.$id.'_thumb.jpg'))
$errors[] = Tools::displayError('An error occurred while uploading the image.');
if (count($errors))
$total_errors = array_merge($total_errors, $errors);
unlink($file['save_path']);
//Necesary to prevent hacking
unset($file['save_path']);
//Add image preview and delete url
$file['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.(int)$category->id.'-'.$id.'_thumb.jpg',
$this->context->controller->table.'_'.(int)$category->id.'-'.$id.'_thumb.jpg', 100, 'jpg', true, true);
$file['delete_url'] = Context::getContext()->link->getAdminLink('AdminBlockCategories').'&deleteThumb='
.$id.'&id_category='.(int)$category->id.'&updatecategory';
}
if (count($total_errors))
$this->context->controller->errors = array_merge($this->context->controller->errors, $total_errors);
die(Tools::jsonEncode(array('thumbnail' => $files)));
}
}
}
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;
@@ -5,6 +5,5 @@ if (!defined('_PS_VERSION_'))
function upgrade_module_2_1($object)
{
return ($object->registerHook('displayBackOfficeCategory') && $object->registerHook('actionBackOfficeCategory')
&& $object->registerHook('actionBackOfficeCategoryRemoveThumbnail'));
return $object->registerHook('displayBackOfficeCategory');
}
+1 -8
View File
@@ -22,13 +22,8 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<script type="text/javascript">
var isLoggedWishlist = {if $logged}true{else}false{/if};
</script>
{if isset($products)}
{*define numbers of product per line in other page for desktop*}
{if $page_name !='index' && $page_name !='product'}
{assign var='nbItemsPerLine' value=3}
{assign var='nbItemsPerLineTablet' value=2}
@@ -122,9 +117,7 @@
{/if}
</div>
<div class="functional-buttons clearfix">
<div class="wishlist">
<a href="#" id="wishlist_button" onclick="WishlistCart('wishlist_block_list', 'add', '{$product.id_product|intval}', false, 1); return false;" class="addToWishlist"><i class="icon-heart-empty"></i> Add to Wishlist</a>
</div>
{hook h='displayProductListFunctionalButtons' product=$product}
{if isset($comparator_max_item) && $comparator_max_item}
<div class="compare">
<label for="comparator_item_{$product.id_product}">