feature 2626: ability to upload a new watermark

git-svn-id: http://piwigo.org/svn/trunk@14546 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
plegall 2012-04-29 23:58:44 +00:00
commit a129632a26
3 changed files with 39 additions and 6 deletions

View file

@ -29,6 +29,30 @@ if( !defined("PHPWG_ROOT_PATH") )
$errors = array();
$pwatermark = $_POST['w'];
// step 0 - manage upload if any
if (isset($_FILES['watermarkImage']) and !empty($_FILES['watermarkImage']['tmp_name']))
{
list($width, $height, $type) = getimagesize($_FILES['watermarkImage']['tmp_name']);
if (IMAGETYPE_PNG != $type)
{
$errors['watermarkImage'] = 'PNG';
}
else
{
$upload_dir = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'watermarks';
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
prepare_directory($upload_dir);
$new_name = get_filename_wo_extension($_FILES['watermarkImage']['name']).'.png';
$file_path = $upload_dir.'/'.$new_name;
move_uploaded_file($_FILES['watermarkImage']['tmp_name'], $file_path);
$pwatermark['file'] = substr($file_path, strlen(PHPWG_ROOT_PATH));
}
}
// step 1 - sanitize HTML input
switch ($pwatermark['position'])
{

View file

@ -33,7 +33,7 @@ jQuery(document).ready(function(){
<h2>{'Piwigo configuration'|@translate} {$TABSHEET_TITLE}</h2>
{if !isset($default)}
<form method="post" action="{$F_ACTION}" class="properties">
<form method="post" action="{$F_ACTION}" class="properties"{if isset($watermark)} enctype="multipart/form-data"{/if}>
{/if}
<div id="configContent">
{if isset($main)}
@ -479,20 +479,28 @@ jQuery(document).ready(function() {
jQuery("#positionCustomDetails").hide();
}
});
jQuery(".addWatermarkOpen").click(function(){
jQuery("#addWatermark, #selectWatermark").toggle();
});
});
{/literal}{/footer_script}
<fieldset id="watermarkConf">
<legend></legend>
<ul>
<li>
<label>{'Select a file'|@translate}</label>
<span id="selectWatermark"{if isset($ferrors.watermarkImage)} style="display:none"{/if}><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>
<br><img id="wImg"></img>
{'... or '|@translate}<a href="#" class="addWatermarkOpen">{'add a new watermark'|@translate}</a>
<br><img id="wImg"></img></span>{* #selectWatermark *}
<span id="addWatermark"{if isset($ferrors.watermarkImage)} style="display:inline"{/if}>
<a href="#" class="addWatermarkOpen">{'add a new watermark'|@translate}</a> (png)
<br><input type="file" size="60" id="watermarkImage" name="watermarkImage"{if isset($ferrors.watermarkImage)} class="dError"{/if}>
{if isset($ferrors.watermarkImage)}<span class="dErrorDesc" title="{$ferrors.watermarkImage}">!</span>{/if}
</span>{* #addWatermark *}
</li>
<li>

View file

@ -1112,4 +1112,5 @@ FORM#categoryOrdering .categoryLi:hover p.albumActions {visibility:visible;}
input[type="text"].dError {border-color:#ff7070; background-color:#FFe5e5;}
.dErrorDesc {background-color:red; color:white; padding:0 5px;border-radius:10px; font-weight:bold;cursor:help;}
#wImg {max-height:100px;border:2px solid #ccc;}
#wImg {max-height:100px;border:2px solid #ccc;margin-top:5px;}
#addWatermark {display:none;}