| 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 | |
|---|
| 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 | { |
|---|
| 38 | $errors['watermarkImage'] = sprintf( |
|---|
| 39 | l10n('Allowed file types: %s.'), |
|---|
| 40 | 'PNG' |
|---|
| 41 | ); |
|---|
| 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 | |
|---|
| 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 |
|---|
| 114 | if (count($errors) == 0) |
|---|
| 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 | // do we have to regenerate the derivatives? |
|---|
| 133 | $old_enabled = ImageStdParams::get_defined_type_map(); |
|---|
| 134 | // $disabled = @unserialize( @$conf['disabled_derivatives'] ); |
|---|
| 135 | // if ($disabled===false) |
|---|
| 136 | // { |
|---|
| 137 | // $disabled = array(); |
|---|
| 138 | // } |
|---|
| 139 | |
|---|
| 140 | // save the new watermark configuration |
|---|
| 141 | ImageStdParams::set_watermark($watermark); |
|---|
| 142 | |
|---|
| 143 | $new_enabled = ImageStdParams::get_defined_type_map(); |
|---|
| 144 | |
|---|
| 145 | $changed_types = array(); |
|---|
| 146 | |
|---|
| 147 | foreach(ImageStdParams::get_all_types() as $type) |
|---|
| 148 | { |
|---|
| 149 | if (isset($old_enabled[$type])) |
|---|
| 150 | { |
|---|
| 151 | $old_params = $old_enabled[$type]; |
|---|
| 152 | // echo '<pre>old '.$type."\n"; print_r($old_params); echo '</pre>'; |
|---|
| 153 | |
|---|
| 154 | $new_params = $new_enabled[$type]; |
|---|
| 155 | ImageStdParams::apply_global($new_params); |
|---|
| 156 | // echo '<pre>new '.$type."\n"; print_r($old_params); echo '</pre>'; |
|---|
| 157 | |
|---|
| 158 | $same = true; |
|---|
| 159 | |
|---|
| 160 | if ($new_params->use_watermark != $old_params->use_watermark |
|---|
| 161 | or $new_params->use_watermark and $watermark_changed) |
|---|
| 162 | { |
|---|
| 163 | $same = false; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | if (!$same) |
|---|
| 167 | { |
|---|
| 168 | $new_params->last_mod_time = time(); |
|---|
| 169 | $changed_types[] = $type; |
|---|
| 170 | } |
|---|
| 171 | else |
|---|
| 172 | { |
|---|
| 173 | $new_params->last_mod_time = $old_params->last_mod_time; |
|---|
| 174 | } |
|---|
| 175 | $new_enabled[$type] = $new_params; |
|---|
| 176 | } |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | $enabled_by = array(); // keys ordered by all types |
|---|
| 180 | foreach(ImageStdParams::get_all_types() as $type) |
|---|
| 181 | { |
|---|
| 182 | if (isset($new_enabled[$type])) |
|---|
| 183 | { |
|---|
| 184 | $enabled_by[$type] = $new_enabled[$type]; |
|---|
| 185 | } |
|---|
| 186 | } |
|---|
| 187 | ImageStdParams::set_and_save($enabled_by); |
|---|
| 188 | |
|---|
| 189 | if (count($changed_types)) |
|---|
| 190 | { |
|---|
| 191 | clear_derivative_cache($changed_types); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | array_push( |
|---|
| 195 | $page['infos'], |
|---|
| 196 | l10n('Your configuration settings are saved') |
|---|
| 197 | ); |
|---|
| 198 | } |
|---|
| 199 | else |
|---|
| 200 | { |
|---|
| 201 | $template->assign('watermark', $pwatermark); |
|---|
| 202 | $template->assign('ferrors', $errors); |
|---|
| 203 | } |
|---|
| 204 | ?> |
|---|