From 5884b956f88bc8b602a7179d9e59f1c737ad99fc Mon Sep 17 00:00:00 2001 From: plegall Date: Sun, 29 Apr 2012 07:34:44 +0000 Subject: [PATCH] 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 --- admin/configuration.php | 75 ++++++++ .../configuration_watermark_process.inc.php | 172 ++++++++++++++++++ .../themes/default/template/configuration.tpl | 89 +++++++++ admin/themes/default/theme.css | 36 +++- 4 files changed, 370 insertions(+), 2 deletions(-) create mode 100644 admin/include/configuration_watermark_process.inc.php diff --git a/admin/configuration.php b/admin/configuration.php index 0de99e40f..0fbe113d6 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -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 diff --git a/admin/include/configuration_watermark_process.inc.php b/admin/include/configuration_watermark_process.inc.php new file mode 100644 index 000000000..d3dcc0f67 --- /dev/null +++ b/admin/include/configuration_watermark_process.inc.php @@ -0,0 +1,172 @@ + 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 '
old '.$type."\n"; print_r($old_params); echo '
'; + + $new_params = $new_enabled[$type]; + ImageStdParams::apply_global($new_params); + // echo '
new '.$type."\n"; print_r($old_params); echo '
'; + + $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); +} +?> \ No newline at end of file diff --git a/admin/themes/default/template/configuration.tpl b/admin/themes/default/template/configuration.tpl index 631423d3a..288e9f9ff 100644 --- a/admin/themes/default/template/configuration.tpl +++ b/admin/themes/default/template/configuration.tpl @@ -450,6 +450,95 @@ input[type="text"].dError {border-color:#ff7070; background-color:#FFe5e5;} {/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} + + +
+ + +
+ +{/if} {* end of watermark section *} + {if isset($display)}
{'Main Page'|@translate} diff --git a/admin/themes/default/theme.css b/admin/themes/default/theme.css index da92075c5..bf9013184 100644 --- a/admin/themes/default/theme.css +++ b/admin/themes/default/theme.css @@ -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;} \ No newline at end of file +#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; +} \ No newline at end of file