Start redraw skinstatic module

This commit is contained in:
Michael RICOIS 2018-02-20 12:02:19 +01:00
parent b5053e443a
commit 20af00f1ec
2 changed files with 49 additions and 410 deletions

View File

@ -1,235 +1,46 @@
<?php
if(!defined('_PS_VERSION_')) {
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminSkinStatic extends AdminTab {
require_once PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php';
class AdminSkinStatic extends AdminTab
{
public $_html = '';
public function postProcess()
{
global $cookie;
$languages = Language::getLanguages(FALSE);
if (Tools::isSubmit('btnSubmit')) {
if (Tools::getValue('version')) {
Configuration::updateValue('SKINSTATIC_VERSION', (int) Configuration::get('SKINSTATIC_VERSION') + 1);
$id_lang = (int) Tools::getValue('version');
for($i=0; $i < 2; $i++) {
$reset = Tools::getValue('reset_'.(int) $i);
if ($reset) {
file_put_contents(
_PS_ROOT_DIR_.'/themes/site/skinstatic_cache/columns_'.(int) $i.'_'.(int) $id_lang.'.html',
str_replace(
array('{left_link}', '{right_link}', '{version}'),
array(
Tools::getValue('left_link_'.(int) $i),
Tools::getValue('right_link_'.(int) $i),
Configuration::get('SKINSTATIC_VERSION'),
),
'<a'.((int) Tools::getValue('new_window_'.(int) $i)? ' onclick="window.open(this.href); return false;"': '').' id="skin-left" href="{left_link}"></a><a'.((int) Tools::getValue('new_window_'.(int) $i)? ' onclick="window.open(this.href); return false;"': '').' id="skin-right" href="{right_link}"></a>'.(Tools::getValue('fixed_'.(int) $i)? '
<script type="text/javascript">
<!--
$(document).ready(function() { var scrolling = $("#skin-left, #skin-right"); var pos = scrolling.position(); var size = scrolling.height() + 80; var max_size = $(document).height() - $("#footer").height() - 45; $(window).scroll(function(event) { offset = parseFloat(scrolling.css("marginTop").replace("px", "")); scrolling.css({ "marginTop": Math.min($(document).scrollTop(), max_size) + "px" }); }); '.($i == 0 && substr(Tools::getValue('left_link_'.(int) $i), 0, 28) == 'http://www.privatesportshop.'? '$("#skin-left, #skin-right").unbind("click").removeAttr("href").removeAttr("onclick").click(function(event) { event.stopPropagation(); event.preventDefault(); $("#privatesales_block li > a").first().trigger("click"); });': '').'
});
-->
</script>': '').'
'));
}
if(isset($_FILES['img_'.(int) $i]) && $_FILES['img_'.(int) $i]['name'] != '')
{
if(!copy($_FILES['img_'.(int) $i]['tmp_name'], _PS_ROOT_DIR_.'/themes/site/skinstatic_cache/skin_'.(int) $i.'_'.(int) $id_lang.'.jpg')) {
echo '<p class"error">'.$this->l('An error occured during the image upload.').'</p>';
continue;
}
// version logged
if ($i == 1) {
file_put_contents(
_PS_ROOT_DIR_.'/themes/site/skinstatic_cache/columns_'.(int) $i.'_'.(int) $id_lang.'.html',
str_replace(
array('{left_link}', '{right_link}', '{version}'),
array(
Tools::getValue('left_link_'.(int) $i),
Tools::getValue('right_link_'.(int) $i),
Configuration::get('SKINSTATIC_VERSION'),
),
'<style type="text/css">body#index #columns { background: url("//www.bebeboutik.com/themes/site/skinstatic_cache/skin_'.(int) $i.'_'.(int) $id_lang.'.jpg?v={version}") no-repeat '.(Tools::getValue('fixed_'.(int) $i)? 'fixed center 0px': 'scroll center 0px').' #FFFFFF}</style><a'.((int) Tools::getValue('new_window_'.(int) $i)? ' onclick="window.open(this.href); return false;"': '').' id="skin-left" href="{left_link}"></a><a'.((int) Tools::getValue('new_window_'.(int) $i)? ' onclick="window.open(this.href); return false;"': '').' id="skin-right" href="{right_link}"></a>'.(Tools::getValue('fixed_'.(int) $i)? '
<script type="text/javascript">
<!--
$(document).ready(function() { var scrolling = $("#skin-left, #skin-right"); var pos = scrolling.position(); var size = scrolling.height() + 80; var max_size = $(document).height() - $("#footer").height() - 45; $(window).scroll(function(event) { offset = parseFloat(scrolling.css("marginTop").replace("px", "")); margin = 170; height = 750; if($(document).scrollTop()==0){margin = 30;} if($(document).scrollTop()>130){height = $(window).height();}; scrolling.css({ "marginTop": Math.min($(document).scrollTop(), max_size)-margin + "px", "height" : height+"px" }); }); '.($i == 0 && substr(Tools::getValue('left_link_'.(int) $i), 0, 28) == 'http://www.privatesportshop.'? '$("#skin-left, #skin-right").unbind("click").removeAttr("href").removeAttr("onclick").click(function(event) { event.stopPropagation(); event.preventDefault(); $("#privatesales_block li > a").first().trigger("click"); });': '').'
});
-->
</script>': '').'
'));
} else {
//echo "<pre>";var_dump(Tools::getValue('right_link_'.(int) $i),Tools::getValue('left_link_'.(int) $i));echo "</pre>";die();
file_put_contents(
_PS_ROOT_DIR_.'/themes/site/skinstatic_cache/columns_'.(int) $i.'_'.(int) $id_lang.'.html',
str_replace(
array('{left_link}', '{right_link}', '{version}'),
array(
Tools::getValue('left_link_'.(int) $i),
Tools::getValue('right_link_'.(int) $i),
Configuration::get('SKINSTATIC_VERSION'),
),
'<style type="text/css">body#index #columns { background: url("//www.bebeboutik.com/themes/site/skinstatic_cache/skin_'.(int) $i.'_'.(int) $id_lang.'.jpg?v={version}") no-repeat '.(Tools::getValue('fixed_'.(int) $i)? 'fixed center 0px': 'scroll center 0px').' #FFFFFF}</style><a'.((int) Tools::getValue('new_window_'.(int) $i)? ' onclick="window.open(this.href); return false;"': '').' id="skin-left" href="{left_link}"></a><a'.((int) Tools::getValue('new_window_'.(int) $i)? ' onclick="window.open(this.href); return false;"': '').' id="skin-right" href="{right_link}"></a>'.(Tools::getValue('fixed_'.(int) $i)? '
<script type="text/javascript">
<!--
$(document).ready(function() { var scrolling = $("#skin-left, #skin-right"); var pos = scrolling.position(); var size = scrolling.height() + 80; var max_size = $(document).height() - $("#footer").height() - 45; $(window).scroll(function(event) { offset = parseFloat(scrolling.css("marginTop").replace("px", "")); scrolling.css({ "marginTop": Math.min($(document).scrollTop(), max_size) + "px" }); }); '.($i == 0 && substr(Tools::getValue('left_link_'.(int) $i), 0, 28) == 'http://www.privatesportshop.'? '$("#skin-left, #skin-right").unbind("click").removeAttr("href").removeAttr("onclick").click(function(event) { event.stopPropagation(); event.preventDefault(); $("#privatesales_block li > a").first().trigger("click"); });': '').'
});
-->
</script>': '').'
'));
}
}
}
$this->_html .= '<p class="conf">'.$this->l('Skin updated successfully.').'</p><br /><br />';
} else {
$this->_html .= '<p class="error">'.$this->l('You have to choose a site version.').'</p><br /><br />';
}
}
}
public function display()
{
global $cookie;
$languages = Language::getLanguages(FALSE);
// $divLangName = 'left_link_0¤right_link_0¤new_window_0¤fixed_0¤img_0¤left_link_1¤right_link_1¤new_window_1¤fixed_1¤img_1¤left_link_2¤right_link_2¤new_window_2¤fixed_2¤img_2';
$divLangName = 'left_link_1¤right_link_1¤new_window_1¤fixed_1¤img_1';
$divLangName .= '¤left_link_0¤right_link_0¤new_window_0¤fixed_0¤img_0';
$defaultFormLanguage = (int) Configuration::get('PS_LANG_DEFAULT');
$this->_html .=
'
<h2>Habillage graphique du site</h2>
<script type="text/javascript">
var id_language = '.(int) $defaultFormLanguage.';
</script>
<form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">
<fieldset>
<legend style="display: inline-block;"><img src="../img/admin/prefs.gif" />'.$this->l('Skin version').'</legend>
<br />
<div class="text">
<label>'.$this->l('Site version').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<input type="radio" value="'.(int) $language['id_lang'].'" name="version" /> '.$language['iso_code'].' ';
}
$this->_html .= '
<div class="clear"></div>
<p>'.$this->l('Choose the site version to update').'</p></div>
</div>
<legend style="display: inline-block;"><img src="../img/admin/prefs.gif" />'.$this->l('Links (logged in)').'</legend>
<br />
<div class="text">
<label>'.$this->l('Remove actual skin').'</label>
<div class="margin-form">
<input type="checkbox" value="1" name="reset_1" />
<div class="clear"></div>
</div>
<div class="text">
<label>'.$this->l('Left link:').'</label>
<div class="margin-form">
<input type="text" style="width: 350px;" value="" name="left_link_1" />
</div>
<div class="clear"></div>
</div>
<div class="text">
<label>'.$this->l('Right link:').'</label>
<div class="margin-form">
<input type="text" style="width: 350px;" value="" name="right_link_1" />
</div>
<div class="clear"></div>
</div>
<div class="text">
<label>'.$this->l('Open link in new window').'</label>
<div class="margin-form">
<input type="checkbox" value="1" name="new_window_1" />
</div>
<div class="clear"></div>
</div>
<div class="text">
<label>'.$this->l('Fixed background').'</label>
<div class="margin-form">
<input type="checkbox" value="1" name="fixed_1" />
</div>
<div class="clear"></div>
</div>
<div class="text">
<label>'.$this->l('Image').'</label>
<div class="margin-form">
<input type="file" name="img_1" />
</div>
<div class="clear"></div>
</div>
<br />
<legend style="display: inline-block;"><img src="../img/admin/prefs.gif" />'.$this->l('Links (logged out)').'</legend>
<br />
<div class="text">
<label>'.$this->l('Remove actual skin').'</label>
<div class="margin-form">
<input type="checkbox" value="1" name="reset_0" />
<div class="clear"></div>
</div>
<div class="text">
<label>'.$this->l('Left link:').'</label>
<div class="margin-form">
<input type="text" style="width: 350px;" value="" name="left_link_0" />
</div>
<div class="clear"></div>
</div>
<div class="text">
<label>'.$this->l('Right link:').'</label>
<div class="margin-form">
<input type="text" style="width: 350px;" value="" name="right_link_0" />
</div>
<div class="clear"></div>
</div>
<div class="text">
<label>'.$this->l('Open link in new window').'</label>
<div class="margin-form">
<input type="checkbox" value="1" name="new_window_0" />
</div>
<div class="clear"></div>
</div>
<div class="text">
<label>'.$this->l('Fixed background').'</label>
<div class="margin-form">
<input type="checkbox" value="1" name="fixed_0" />
</div>
<div class="clear"></div>
</div>
<div class="text">
<label>'.$this->l('Image').'</label>
<div class="margin-form">
<input type="file" name="img_0" />
</div>
<div class="clear"></div>
</div>
<br />
<p class="margin-form submit">
<br />
<input class="button" name="btnSubmit" value="'.$this->l('Update settings').'" type="submit" />
</p>
</fieldset>
</form>';
echo $this->_html;
echo "Display";
}
// List
public function displayList()
{
echo "DisplayList";
}
// Form
public function displayForm()
{
echo "DisplayForm";
}
// Fallback
private function displayFallback()
{
echo "DisplayFallback";
}
// Form fallback
private function displayFallbackForm()
{
echo "DisplayFallbackForm";
}
}

View File

@ -1,9 +1,15 @@
<?php
if (!defined('_PS_VERSION_'))
if (!defined('_PS_VERSION_')) {
exit;
}
class SkinStatic extends Module {
public function __construct() {
class SkinStatic extends Module
{
/**
*
*/
public function __construct()
{
$this->name = 'skinstatic';
$this->tab = 'front_office_features';
$this->version = '1.0';
@ -15,192 +21,14 @@ class SkinStatic extends Module {
$this->description = $this->l('Allows to display static parts as a skin on the website.');
}
public function getContent() {
$this->_html = '<h2>'.$this->displayName.'</h2>';
$languages = Language::getLanguages(FALSE);
$divLangName = 'left_link_0¤right_link_0¤new_window_0¤fixed_0¤img_0¤left_link_1¤right_link_1¤new_window_1¤fixed_1¤img_1¤left_link_2¤right_link_2¤new_window_2¤fixed_2¤img_2';
$defaultFormLanguage = (int) Configuration::get('PS_LANG_DEFAULT');
if (Tools::isSubmit('btnSubmit')) {
Configuration::updateValue('SKINSTATIC_VERSION', (int) Configuration::get('SKINSTATIC_VERSION') + 1);
foreach($languages as $language) {
for($i=0; $i < 3; $i++) {
if(isset($_FILES['img_'.(int) $i.'_'.(int) $language['id_lang']]) && $_FILES['img_'.(int) $i.'_'.(int) $language['id_lang']]['name'] != '') {
if(!copy($_FILES['img_'.(int) $i.'_'.(int) $language['id_lang']]['tmp_name'], _PS_ROOT_DIR_.'/themes/site/skinstatic_cache/skin_'.(int) $i.'_'.(int) $language['id_lang'].'.jpg')) {
echo '<p class"error">'.$this->l('An error occured during the image upload.').'</p>';
continue;
}
file_put_contents(
_PS_ROOT_DIR_.'/themes/site/skinstatic_cache/columns_'.(int) $i.'_'.(int) $language['id_lang'].'.html',
str_replace(
array('{left_link}', '{right_link}', '{version}'),
array(
Tools::getValue('left_link_'.(int) $i.'_'.(int) $language['id_lang']),
Tools::getValue('right_link_'.(int) $i.'_'.(int) $language['id_lang']),
Configuration::get('SKINSTATIC_VERSION'),
),
'<style type="text/css">body#index #columns { background: url("http://dev.bebeboutik.com/themes/site/skinstatic_cache/skin_'.(int) $i.'_'.(int) $language['id_lang'].'.jpg?v={version}") no-repeat '.(Tools::getValue('fixed_'.(int) $i.'_'.(int) $language['id_lang'])? 'fixed center 0px': 'scroll center 0px').' #FFFFFF}</style><a'.((int) Tools::getValue('new_window_'.(int) $i.'_'.(int) $language['id_lang'])? ' onclick="window.open(this.href); return false;"': '').' id="skin-left" href="{left_link}"></a><a'.((int) Tools::getValue('new_window_'.(int) $i.'_'.(int) $language['id_lang'])? ' onclick="window.open(this.href); return false;"': '').' id="skin-right" href="{right_link}"></a>'.(Tools::getValue('fixed_'.(int) $i.'_'.(int) $language['id_lang'])? '
<script type="text/javascript">
<!--
$(document).ready(function() { var scrolling = $("#skin-left, #skin-right"); var pos = scrolling.position(); var size = scrolling.height() + 80; var max_size = $(document).height() - $("#footer").height() - 45; $(window).scroll(function(event) { offset = parseFloat(scrolling.css("marginTop").replace("px", "")); scrolling.css({ "marginTop": Math.min($(document).scrollTop(), max_size) + "px" }); }); '.($i == 0 && substr(Tools::getValue('left_link_'.(int) $i.'_'.(int) $language['id_lang']), 0, 28) == 'http://www.privatesportshop.'? '$("#skin-left, #skin-right").unbind("click").removeAttr("href").removeAttr("onclick").click(function(event) { event.stopPropagation(); event.preventDefault(); $("#privatesales_block li > a").first().trigger("click"); });': '').'
});
-->
</script>': '').'
'));
}
}
}
$this->_html .= '<p class="conf">'.$this->l('Links updated successfully.').'</p><br /><br />';
}
$this->_html .=
'
<script type="text/javascript">
var id_language = '.(int) $defaultFormLanguage.';
</script>
<form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">
<fieldset>
<legend><img src="../img/admin/prefs.gif" />'.$this->l('Links (logged out)').'</legend>
<div class="text clear">
<label>'.$this->l('Left link:').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<div id="left_link_0_'.(int) $language['id_lang'].'" style="display: '.((int) $language['id_lang'] == $defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="text" style="width: 350px;" value="" name="left_link_0_'.(int) $language['id_lang'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultFormLanguage, $divLangName, 'left_link_0', TRUE);
$this->_html .= '<div class="clear"></div>
</div>
</div>
<div class="text">
<label>'.$this->l('Right link:').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<div id="right_link_0_'.(int) $language['id_lang'].'" style="display: '.((int) $language['id_lang'] == $defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="text" style="width: 350px;" value="" name="right_link_0_'.(int) $language['id_lang'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultFormLanguage, $divLangName, 'right_link_0', TRUE);
$this->_html .= '<div class="clear"></div>
</div>
</div>
<div class="text">
<label>'.$this->l('Open link in new window').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<div id="new_window_0_'.(int) $language['id_lang'].'" style="display: '.((int) $language['id_lang'] == $defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="checkbox" value="1" name="new_window_0_'.(int) $language['id_lang'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultFormLanguage, $divLangName, 'new_window_0', TRUE);
$this->_html .= '<div class="clear"></div>
</div>
</div>
<div class="text">
<label>'.$this->l('Fixed background').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<div id="fixed_0_'.(int) $language['id_lang'].'" style="display: '.((int) $language['id_lang'] == $defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="checkbox" value="1" name="fixed_0_'.(int) $language['id_lang'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultFormLanguage, $divLangName, 'fixed_0', TRUE);
$this->_html .= '<div class="clear"></div>
</div>
</div>
<div class="text">
<label>'.$this->l('Image').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<div id="img_0_'.(int) $language['id_lang'].'" style="display: '.((int) $language['id_lang'] == $defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="file" name="img_0_'.(int) $language['id_lang'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultFormLanguage, $divLangName, 'img_0', TRUE);
$this->_html .= '<div class="clear"></div>
</div>
</div>
<br />
<legend style="display: inline-block;"><img src="../img/admin/prefs.gif" />'.$this->l('Links (logged in)').'</legend>
<br />
<br />
<div class="text">
<label>'.$this->l('Left link:').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<div id="left_link_1_'.(int) $language['id_lang'].'" style="display: '.((int) $language['id_lang'] == $defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="text" style="width: 350px;" value="" name="left_link_1_'.(int) $language['id_lang'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultFormLanguage, $divLangName, 'left_link_1', TRUE);
$this->_html .= '<div class="clear"></div>
</div>
</div>
<div class="text">
<label>'.$this->l('Right link:').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<div id="right_link_1_'.(int) $language['id_lang'].'" style="display: '.((int) $language['id_lang'] == $defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="text" style="width: 350px;" value="" name="right_link_1_'.(int) $language['id_lang'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultFormLanguage, $divLangName, 'right_link_1', TRUE);
$this->_html .= '<div class="clear"></div>
</div>
</div>
<div class="text">
<label>'.$this->l('Open link in new window').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<div id="new_window_1_'.(int) $language['id_lang'].'" style="display: '.((int) $language['id_lang'] == $defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="checkbox" value="1" name="new_window_1_'.(int) $language['id_lang'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultFormLanguage, $divLangName, 'new_window_1', TRUE);
$this->_html .= '<div class="clear"></div>
</div>
</div>
<div class="text">
<label>'.$this->l('Fixed background').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<div id="fixed_1_'.(int) $language['id_lang'].'" style="display: '.((int) $language['id_lang'] == $defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="checkbox" value="1" name="fixed_1_'.(int) $language['id_lang'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultFormLanguage, $divLangName, 'fixed_1', TRUE);
$this->_html .= '<div class="clear"></div>
</div>
</div>
<div class="text">
<label>'.$this->l('Image').'</label>
<div class="margin-form">';
foreach($languages as $language) {
$this->_html .= '<div id="img_1_'.(int) $language['id_lang'].'" style="display: '.((int) $language['id_lang'] == $defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="file" name="img_1_'.(int) $language['id_lang'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultFormLanguage, $divLangName, 'img_1', TRUE);
$this->_html .= '<div class="clear"></div>
</div>
</div>
<br />
<p class="margin-form submit">
<br />
<input class="button" name="btnSubmit" value="'.$this->l('Update settings').'" type="submit" />
</p>
</fieldset>
</form>';
public function getContent()
{
$this->_html = 'No config. See Admin.';
return $this->_html;
}
public function install()
{
// See SQL file for installation
}
}