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 1 - sanitize HTML input |
---|
33 | switch ($pwatermark['position']) |
---|
34 | { |
---|
35 | case 'topleft': |
---|
36 | { |
---|
37 | $pwatermark['xpos'] = 0; |
---|
38 | $pwatermark['ypos'] = 0; |
---|
39 | break; |
---|
40 | } |
---|
41 | case 'topright': |
---|
42 | { |
---|
43 | $pwatermark['xpos'] = 100; |
---|
44 | $pwatermark['ypos'] = 0; |
---|
45 | break; |
---|
46 | } |
---|
47 | case 'middle': |
---|
48 | { |
---|
49 | $pwatermark['xpos'] = 50; |
---|
50 | $pwatermark['ypos'] = 50; |
---|
51 | break; |
---|
52 | } |
---|
53 | case 'bottomleft': |
---|
54 | { |
---|
55 | $pwatermark['xpos'] = 0; |
---|
56 | $pwatermark['ypos'] = 100; |
---|
57 | break; |
---|
58 | } |
---|
59 | case 'bottomright': |
---|
60 | { |
---|
61 | $pwatermark['xpos'] = 100; |
---|
62 | $pwatermark['ypos'] = 100; |
---|
63 | break; |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | // step 2 - check validity |
---|
68 | $v = intval($pwatermark['xpos']); |
---|
69 | if ($v < 0 or $v > 100) |
---|
70 | { |
---|
71 | $errors['watermark']['xpos'] = '[0..100]'; |
---|
72 | } |
---|
73 | |
---|
74 | $v = intval($pwatermark['ypos']); |
---|
75 | if ($v < 0 or $v > 100) |
---|
76 | { |
---|
77 | $errors['watermark']['ypos'] = '[0..100]'; |
---|
78 | } |
---|
79 | |
---|
80 | $v = intval($pwatermark['opacity']); |
---|
81 | if ($v <= 0 or $v > 100) |
---|
82 | { |
---|
83 | $errors['watermark']['opacity'] = '(0..100]'; |
---|
84 | } |
---|
85 | |
---|
86 | // step 3 - save data |
---|
87 | if (count($errors) == 0) |
---|
88 | { |
---|
89 | $watermark = new WatermarkParams(); |
---|
90 | $watermark->file = $pwatermark['file']; |
---|
91 | $watermark->xpos = intval($pwatermark['xpos']); |
---|
92 | $watermark->ypos = intval($pwatermark['ypos']); |
---|
93 | $watermark->xrepeat = intval($pwatermark['xrepeat']); |
---|
94 | $watermark->opacity = intval($pwatermark['opacity']); |
---|
95 | $watermark->min_size = array(intval($pwatermark['minw']),intval($pwatermark['minh'])); |
---|
96 | |
---|
97 | $old_watermark = ImageStdParams::get_watermark(); |
---|
98 | $watermark_changed = |
---|
99 | $watermark->file != $old_watermark->file |
---|
100 | || $watermark->xpos != $old_watermark->xpos |
---|
101 | || $watermark->ypos != $old_watermark->ypos |
---|
102 | || $watermark->xrepeat != $old_watermark->xrepeat |
---|
103 | || $watermark->opacity != $old_watermark->opacity; |
---|
104 | |
---|
105 | // do we have to regenerate the derivatives? |
---|
106 | $old_enabled = ImageStdParams::get_defined_type_map(); |
---|
107 | // $disabled = @unserialize( @$conf['disabled_derivatives'] ); |
---|
108 | // if ($disabled===false) |
---|
109 | // { |
---|
110 | // $disabled = array(); |
---|
111 | // } |
---|
112 | |
---|
113 | // save the new watermark configuration |
---|
114 | ImageStdParams::set_watermark($watermark); |
---|
115 | |
---|
116 | $new_enabled = ImageStdParams::get_defined_type_map(); |
---|
117 | |
---|
118 | $changed_types = array(); |
---|
119 | |
---|
120 | foreach(ImageStdParams::get_all_types() as $type) |
---|
121 | { |
---|
122 | if (isset($old_enabled[$type])) |
---|
123 | { |
---|
124 | $old_params = $old_enabled[$type]; |
---|
125 | // echo '<pre>old '.$type."\n"; print_r($old_params); echo '</pre>'; |
---|
126 | |
---|
127 | $new_params = $new_enabled[$type]; |
---|
128 | ImageStdParams::apply_global($new_params); |
---|
129 | // echo '<pre>new '.$type."\n"; print_r($old_params); echo '</pre>'; |
---|
130 | |
---|
131 | $same = true; |
---|
132 | |
---|
133 | if ($new_params->use_watermark != $old_params->use_watermark |
---|
134 | or $new_params->use_watermark and $watermark_changed) |
---|
135 | { |
---|
136 | $same = false; |
---|
137 | } |
---|
138 | |
---|
139 | if (!$same) |
---|
140 | { |
---|
141 | $new_params->last_mod_time = time(); |
---|
142 | $changed_types[] = $type; |
---|
143 | } |
---|
144 | else |
---|
145 | { |
---|
146 | $new_params->last_mod_time = $old_params->last_mod_time; |
---|
147 | } |
---|
148 | $new_enabled[$type] = $new_params; |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | $enabled_by = array(); // keys ordered by all types |
---|
153 | foreach(ImageStdParams::get_all_types() as $type) |
---|
154 | { |
---|
155 | if (isset($new_enabled[$type])) |
---|
156 | { |
---|
157 | $enabled_by[$type] = $new_enabled[$type]; |
---|
158 | } |
---|
159 | } |
---|
160 | ImageStdParams::set_and_save($enabled_by); |
---|
161 | |
---|
162 | if (count($changed_types)) |
---|
163 | { |
---|
164 | clear_derivative_cache($changed_types); |
---|
165 | } |
---|
166 | } |
---|
167 | else |
---|
168 | { |
---|
169 | $template->assign('watermark', $pwatermark); |
---|
170 | $template->assign('ferrors', $errors); |
---|
171 | } |
---|
172 | ?> |
---|