feature 2626: new design for the watermark configuration screen (tab in the "config > options")

TODO: the detection of derivatives that need to be updated is not working.


git-svn-id: http://piwigo.org/svn/trunk@14512 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
plegall 2012-04-29 07:34:44 +00:00
commit 5884b956f8
4 changed files with 370 additions and 2 deletions

View file

@ -173,6 +173,11 @@ if (isset($_POST['submit']))
}
break;
}
case 'watermark' :
{
include(PHPWG_ROOT_PATH.'admin/include/configuration_watermark_process.inc.php');
break;
}
case 'sizes' :
{
include(PHPWG_ROOT_PATH.'admin/include/configuration_sizes_process.inc.php');
@ -270,6 +275,7 @@ $tabsheet = new tabsheet();
// TabSheet initialization
$tabsheet->add('main', l10n('Main'), $conf_link.'main');
$tabsheet->add('sizes', l10n('Photo sizes'), $conf_link.'sizes');
$tabsheet->add('watermark', l10n('Watermark'), $conf_link.'watermark');
$tabsheet->add('display', l10n('Display'), $conf_link.'display');
$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
@ -495,6 +501,75 @@ switch ($page['section'])
break;
}
case 'watermark' :
{
$watermark_files = array();
foreach (glob(PHPWG_ROOT_PATH.'themes/default/watermarks/*.png') as $file)
{
$watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
}
foreach (glob(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'watermarks/*.png') as $file)
{
$watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
}
$watermark_filemap = array( '' => '---' );
foreach( $watermark_files as $file)
{
$display = basename($file);
$watermark_filemap[$file] = $display;
}
$template->assign('watermark_files', $watermark_filemap);
$wm = ImageStdParams::get_watermark();
$position = 'custom';
if ($wm->xpos == 0 and $wm->ypos == 0)
{
$position = 'topleft';
}
if ($wm->xpos == 100 and $wm->ypos == 0)
{
$position = 'topright';
}
if ($wm->xpos == 50 and $wm->ypos == 50)
{
$position = 'middle';
}
if ($wm->xpos == 0 and $wm->ypos == 100)
{
$position = 'bottomleft';
}
if ($wm->xpos == 100 and $wm->ypos == 100)
{
$position = 'bottomright';
}
if ($wm->xrepeat != 0)
{
$position = 'custom';
}
$template->assign(
'watermark',
array(
'file' => $wm->file,
'minw' => $wm->min_size[0],
'minh' => $wm->min_size[1],
'xpos' => $wm->xpos,
'ypos' => $wm->ypos,
'xrepeat' => $wm->xrepeat,
'opacity' => $wm->opacity,
'position' => $position,
)
);
$template->append(
'watermark',
array(),
true
);
break;
}
}
//----------------------------------------------------------- sending html code

View file

@ -0,0 +1,172 @@
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
if( !defined("PHPWG_ROOT_PATH") )
{
die ("Hacking attempt!");
}
$errors = array();
$pwatermark = $_POST['w'];
// step 1 - sanitize HTML input
switch ($pwatermark['position'])
{
case 'topleft':
{
$pwatermark['xpos'] = 0;
$pwatermark['ypos'] = 0;
break;
}
case 'topright':
{
$pwatermark['xpos'] = 100;
$pwatermark['ypos'] = 0;
break;
}
case 'middle':
{
$pwatermark['xpos'] = 50;
$pwatermark['ypos'] = 50;
break;
}
case 'bottomleft':
{
$pwatermark['xpos'] = 0;
$pwatermark['ypos'] = 100;
break;
}
case 'bottomright':
{
$pwatermark['xpos'] = 100;
$pwatermark['ypos'] = 100;
break;
}
}
// step 2 - check validity
$v = intval($pwatermark['xpos']);
if ($v < 0 or $v > 100)
{
$errors['watermark']['xpos'] = '[0..100]';
}
$v = intval($pwatermark['ypos']);
if ($v < 0 or $v > 100)
{
$errors['watermark']['ypos'] = '[0..100]';
}
$v = intval($pwatermark['opacity']);
if ($v <= 0 or $v > 100)
{
$errors['watermark']['opacity'] = '(0..100]';
}
// step 3 - save data
if (count($errors)==0)
{
$watermark = new WatermarkParams();
$watermark->file = $pwatermark['file'];
$watermark->xpos = intval($pwatermark['xpos']);
$watermark->ypos = intval($pwatermark['ypos']);
$watermark->xrepeat = intval($pwatermark['xrepeat']);
$watermark->opacity = intval($pwatermark['opacity']);
$watermark->min_size = array(intval($pwatermark['minw']),intval($pwatermark['minh']));
$old_watermark = ImageStdParams::get_watermark();
$watermark_changed =
$watermark->file != $old_watermark->file
|| $watermark->xpos != $old_watermark->xpos
|| $watermark->ypos != $old_watermark->ypos
|| $watermark->xrepeat != $old_watermark->xrepeat
|| $watermark->opacity != $old_watermark->opacity;
// do we have to regenerate the derivatives?
$old_enabled = ImageStdParams::get_defined_type_map();
// $disabled = @unserialize( @$conf['disabled_derivatives'] );
// if ($disabled===false)
// {
// $disabled = array();
// }
// save the new watermark configuration
ImageStdParams::set_watermark($watermark);
$new_enabled = ImageStdParams::get_defined_type_map();
$changed_types = array();
foreach(ImageStdParams::get_all_types() as $type)
{
if (isset($old_enabled[$type]))
{
$old_params = $old_enabled[$type];
// echo '<pre>old '.$type."\n"; print_r($old_params); echo '</pre>';
$new_params = $new_enabled[$type];
ImageStdParams::apply_global($new_params);
// echo '<pre>new '.$type."\n"; print_r($old_params); echo '</pre>';
$same = true;
if ($new_params->use_watermark != $old_params->use_watermark
or $new_params->use_watermark and $watermark_changed)
{
$same = false;
}
if (!$same)
{
$new_params->last_mod_time = time();
$changed_types[] = $type;
}
else
{
$new_params->last_mod_time = $old_params->last_mod_time;
}
$new_enabled[$type] = $new_params;
}
}
$enabled_by = array(); // keys ordered by all types
foreach(ImageStdParams::get_all_types() as $type)
{
if (isset($new_enabled[$type]))
{
$enabled_by[$type] = $new_enabled[$type];
}
}
ImageStdParams::set_and_save($enabled_by);
if (count($changed_types))
{
clear_derivative_cache($changed_types);
}
}
else
{
$template->assign('watermark', $pwatermark);
$template->assign('ferrors', $errors);
}
?>

View file

@ -450,6 +450,95 @@ input[type="text"].dError {border-color:#ff7070; background-color:#FFe5e5;}
</fieldset>
{/if}
{if isset($watermark)}
{footer_script}{literal}
jQuery(document).ready(function() {
if (jQuery("input[name='w[position]']:checked").val() == 'custom') {
jQuery("#positionCustomDetails").show();
}
jQuery("input[name='w[position]']").change(function(){
if (jQuery(this).val() == 'custom') {
jQuery("#positionCustomDetails").show();
}
else {
jQuery("#positionCustomDetails").hide();
}
});
});
{/literal}{/footer_script}
<fieldset id="watermarkConf">
<legend></legend>
<ul>
<li>
<label>{'Select a file'|@translate}</label>
<select name="w[file]" id="wSelect">
{html_options options=$watermark_files selected=$watermark.file}
</select>
<br>{'... or '|@translate}<a href="#" class="addWatermarkOpen" title="{'add a new watermark'|@translate}">{'add a new watermark'|@translate}</a>
</li>
{*
<p><img id="wImg"></img></p>
*}
<li>
<label>
{'Apply watermark if width is bigger than'|@translate}
<input size="4" maxlength="4" type="text" name="w[minw]" value="{$watermark.minw}"{if isset($ferrors.watermark.minw)}class="dError"{/if}>
</label>
{'pixels'|@translate}
</li>
<li>
<label>
{'Apply watermark if height is bigger than'|@translate}
<input size="4" maxlength="4" type="text" name="w[minh]" value="{$watermark.minh}"{if isset($ferrors.watermark.minh)}class="dError"{/if}>
</label>
{'pixels'|@translate}
</li>
<li>
<label>{'Position'|@translate}</label>
<br>
<div id="watermarkPositionBox">
<label class="right">{'top right corner'|@translate} <input name="w[position]" type="radio" value="topright"{if $watermark.position eq 'topright'} checked="checked"{/if}></label>
<label><input name="w[position]" type="radio" value="topleft"{if $watermark.position eq 'topleft'} checked="checked"{/if}> {'top left corner'|@translate}</label>
<label class="middle"><input name="w[position]" type="radio" value="middle"{if $watermark.position eq 'middle'} checked="checked"{/if}> {'middle'|@translate}</label>
<label class="right">{'bottom right corner'|@translate} <input name="w[position]" type="radio" value="bottomright"{if $watermark.position eq 'bottomright'} checked="checked"{/if}></label>
<label><input name="w[position]" type="radio" value="bottomleft"{if $watermark.position eq 'bottomleft'} checked="checked"{/if}> {'bottom left corner'|@translate}</label>
</div>
<label style="display:block;margin-top:10px;font-weight:normal;"><input name="w[position]" type="radio" value="custom"{if $watermark.position eq 'custom'} checked="checked"{/if}> {'custom'|@translate}</label>
<div id="positionCustomDetails">
<label>{'X Position'|@translate}
<input size="3" maxlength="3" type="text" name="w[xpos]" value="{$watermark.xpos}"{if isset($ferrors.watermark.xpos)}class="dError"{/if}>%
</label>
<br>
<label>{'Y Position'|@translate}
<input size="3" maxlength="3" type="text" name="w[ypos]" value="{$watermark.ypos}"{if isset($ferrors.watermark.ypos)}class="dError"{/if}>%
</label>
<br>
<label>{'X Repeat'|@translate}
<input size="3" maxlength="3" type="text" name="w[xrepeat]" value="{$watermark.xrepeat}"{if isset($ferrors.watermark.xrepeat)}class="dError"{/if}>
</label>
</div>
</li>
<li>
<label>{'Opacity'|@translate}</label>
<input size="3" maxlength="3" type="text" name="w[opacity]" value="{$watermark.opacity}"{if isset($ferrors.watermark.opacity)}class="dError"{/if}> %
</li>
</ul>
</fieldset>
{/if} {* end of watermark section *}
{if isset($display)}
<fieldset id="indexDisplayConf">
<legend>{'Main Page'|@translate}</legend>

View file

@ -471,7 +471,7 @@ FORM.properties SPAN.property {
padding: 0 0.5em 0 0;
}
#mainConf, #historyConf, #commentsConf {border:none}
#mainConf, #historyConf, #commentsConf, #watermarkConf {border:none}
#configContent label {
font-weight: bold;
@ -1075,4 +1075,36 @@ FORM#categoryOrdering .categoryLi:hover p.albumActions {visibility:visible;}
#autoOrder p.actionButtons, #createAlbum p.actionButtons {margin-bottom:0;}
#ftpPage p {text-align:left;margin:1em;}
#ftpPage fieldset p {margin:0;}
#ftpPage fieldset p {margin:0;}
/* watermark configuration screen */
#watermarkPositionBox {
border:2px solid #ccc;
width:500px;
padding:5px;
background-color:#e5e5e5;
}
#watermarkPositionBox label {
font-weight:normal;
display:block;
color:#444;
}
#watermarkPositionBox label.middle {
margin:50px;
text-align:center;
}
#watermarkPositionBox label.right {
float:right;
}
#positionCustomDetails {
margin-left:20px;
display:none;
}
#positionCustomDetails label {
font-weight:normal;
}