[14512] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based photo gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
| 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
| 23 | |
---|
| 24 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
| 25 | { |
---|
| 26 | die ("Hacking attempt!"); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | $errors = array(); |
---|
| 30 | $pwatermark = $_POST['w']; |
---|
| 31 | |
---|
[14546] | 32 | // step 0 - manage upload if any |
---|
| 33 | if (isset($_FILES['watermarkImage']) and !empty($_FILES['watermarkImage']['tmp_name'])) |
---|
| 34 | { |
---|
| 35 | list($width, $height, $type) = getimagesize($_FILES['watermarkImage']['tmp_name']); |
---|
| 36 | if (IMAGETYPE_PNG != $type) |
---|
| 37 | { |
---|
[14549] | 38 | $errors['watermarkImage'] = sprintf( |
---|
| 39 | l10n('Allowed file types: %s.'), |
---|
| 40 | 'PNG' |
---|
| 41 | ); |
---|
[14546] | 42 | } |
---|
| 43 | else |
---|
| 44 | { |
---|
| 45 | $upload_dir = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'watermarks'; |
---|
| 46 | |
---|
| 47 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); |
---|
| 48 | prepare_directory($upload_dir); |
---|
| 49 | |
---|
| 50 | $new_name = get_filename_wo_extension($_FILES['watermarkImage']['name']).'.png'; |
---|
| 51 | $file_path = $upload_dir.'/'.$new_name; |
---|
| 52 | |
---|
| 53 | move_uploaded_file($_FILES['watermarkImage']['tmp_name'], $file_path); |
---|
| 54 | |
---|
| 55 | $pwatermark['file'] = substr($file_path, strlen(PHPWG_ROOT_PATH)); |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
[14512] | 59 | // step 1 - sanitize HTML input |
---|
| 60 | switch ($pwatermark['position']) |
---|
| 61 | { |
---|
| 62 | case 'topleft': |
---|
| 63 | { |
---|
| 64 | $pwatermark['xpos'] = 0; |
---|
| 65 | $pwatermark['ypos'] = 0; |
---|
| 66 | break; |
---|
| 67 | } |
---|
| 68 | case 'topright': |
---|
| 69 | { |
---|
| 70 | $pwatermark['xpos'] = 100; |
---|
| 71 | $pwatermark['ypos'] = 0; |
---|
| 72 | break; |
---|
| 73 | } |
---|
| 74 | case 'middle': |
---|
| 75 | { |
---|
| 76 | $pwatermark['xpos'] = 50; |
---|
| 77 | $pwatermark['ypos'] = 50; |
---|
| 78 | break; |
---|
| 79 | } |
---|
| 80 | case 'bottomleft': |
---|
| 81 | { |
---|
| 82 | $pwatermark['xpos'] = 0; |
---|
| 83 | $pwatermark['ypos'] = 100; |
---|
| 84 | break; |
---|
| 85 | } |
---|
| 86 | case 'bottomright': |
---|
| 87 | { |
---|
| 88 | $pwatermark['xpos'] = 100; |
---|
| 89 | $pwatermark['ypos'] = 100; |
---|
| 90 | break; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | // step 2 - check validity |
---|
| 95 | $v = intval($pwatermark['xpos']); |
---|
| 96 | if ($v < 0 or $v > 100) |
---|
| 97 | { |
---|
| 98 | $errors['watermark']['xpos'] = '[0..100]'; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | $v = intval($pwatermark['ypos']); |
---|
| 102 | if ($v < 0 or $v > 100) |
---|
| 103 | { |
---|
| 104 | $errors['watermark']['ypos'] = '[0..100]'; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | $v = intval($pwatermark['opacity']); |
---|
| 108 | if ($v <= 0 or $v > 100) |
---|
| 109 | { |
---|
| 110 | $errors['watermark']['opacity'] = '(0..100]'; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | // step 3 - save data |
---|
[14513] | 114 | if (count($errors) == 0) |
---|
[14512] | 115 | { |
---|
| 116 | $watermark = new WatermarkParams(); |
---|
| 117 | $watermark->file = $pwatermark['file']; |
---|
| 118 | $watermark->xpos = intval($pwatermark['xpos']); |
---|
| 119 | $watermark->ypos = intval($pwatermark['ypos']); |
---|
| 120 | $watermark->xrepeat = intval($pwatermark['xrepeat']); |
---|
| 121 | $watermark->opacity = intval($pwatermark['opacity']); |
---|
| 122 | $watermark->min_size = array(intval($pwatermark['minw']),intval($pwatermark['minh'])); |
---|
| 123 | |
---|
| 124 | $old_watermark = ImageStdParams::get_watermark(); |
---|
| 125 | $watermark_changed = |
---|
| 126 | $watermark->file != $old_watermark->file |
---|
| 127 | || $watermark->xpos != $old_watermark->xpos |
---|
| 128 | || $watermark->ypos != $old_watermark->ypos |
---|
| 129 | || $watermark->xrepeat != $old_watermark->xrepeat |
---|
| 130 | || $watermark->opacity != $old_watermark->opacity; |
---|
| 131 | |
---|
| 132 | // save the new watermark configuration |
---|
| 133 | ImageStdParams::set_watermark($watermark); |
---|
| 134 | |
---|
[14580] | 135 | // do we have to regenerate the derivatives (and which types)? |
---|
| 136 | $changed_types = array(); |
---|
[14512] | 137 | |
---|
[14584] | 138 | foreach (ImageStdParams::get_defined_type_map() as $type => $params) |
---|
[14512] | 139 | { |
---|
[14580] | 140 | $old_use_watermark = $params->use_watermark; |
---|
| 141 | ImageStdParams::apply_global($params); |
---|
[14512] | 142 | |
---|
[14580] | 143 | if ($params->use_watermark != $old_use_watermark |
---|
| 144 | or $params->use_watermark and $watermark_changed) |
---|
[14512] | 145 | { |
---|
[14580] | 146 | $params->last_mod_time = time(); |
---|
| 147 | $changed_types[] = $type; |
---|
[14512] | 148 | } |
---|
| 149 | } |
---|
| 150 | |
---|
[14584] | 151 | ImageStdParams::save(); |
---|
[14580] | 152 | |
---|
[14512] | 153 | if (count($changed_types)) |
---|
| 154 | { |
---|
| 155 | clear_derivative_cache($changed_types); |
---|
| 156 | } |
---|
[14549] | 157 | |
---|
| 158 | array_push( |
---|
| 159 | $page['infos'], |
---|
| 160 | l10n('Your configuration settings are saved') |
---|
| 161 | ); |
---|
[14512] | 162 | } |
---|
| 163 | else |
---|
| 164 | { |
---|
| 165 | $template->assign('watermark', $pwatermark); |
---|
| 166 | $template->assign('ferrors', $errors); |
---|
| 167 | } |
---|
| 168 | ?> |
---|