1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2010 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 | /* TODO: Revoir le lien du menu de l'admin */ |
---|
25 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
26 | if (!defined('IN_ADMIN') or !IN_ADMIN) die('Hacking attempt!'); |
---|
27 | define('STC_PATH', PHPWG_PLUGINS_PATH.'SwiftThemeCreator/'); |
---|
28 | define('STC_INTERNAL_VERSION', '1.40'); |
---|
29 | load_language('plugin.lang', STC_PATH); |
---|
30 | |
---|
31 | /* |
---|
32 | * stc_hex2rgb convert any string to array of RGB values |
---|
33 | */ |
---|
34 | function stc_hex2rgb($color) |
---|
35 | { |
---|
36 | if ($color[0] == '#') $color = substr($color, 1); |
---|
37 | if (strlen($color) == 6) |
---|
38 | list($r, $g, $b) = array($color[0].$color[1], |
---|
39 | $color[2].$color[3], |
---|
40 | $color[4].$color[5]); |
---|
41 | else { |
---|
42 | $color .= $color . $color . '000'; |
---|
43 | list($r, $g, $b) = array($color[0].$color[0], |
---|
44 | $color[1].$color[1], |
---|
45 | $color[2].$color[2]); |
---|
46 | } |
---|
47 | return array(hexdec($r), hexdec($g), hexdec($b)); |
---|
48 | } |
---|
49 | /* |
---|
50 | * lighten returns array of x% of lighter RGB values |
---|
51 | */ |
---|
52 | function lighten( $r, $g, $b, $percent) |
---|
53 | { |
---|
54 | $r = min(round($r+(($percent*(255-$r))/100)),255); |
---|
55 | $g = min(round($g+(($percent*(255-$g))/100)),255); |
---|
56 | $b = min(round($b+(($percent*(255-$b))/100)),255); |
---|
57 | return sprintf('#%02X%02X%02X', $r, $g, $b); |
---|
58 | } |
---|
59 | /* |
---|
60 | * darken returns array of x% of darker RGB values |
---|
61 | */ |
---|
62 | function darken( $r, $g, $b, $percent) |
---|
63 | { |
---|
64 | $r = max(round($r-(($percent*$r)/100)),0); |
---|
65 | $g = max(round($g-(($percent*$g)/100)),0); |
---|
66 | $b = max(round($b-(($percent*$b)/100)),0); |
---|
67 | return sprintf('#%02X%02X%02X', $r, $g, $b); |
---|
68 | } |
---|
69 | /* |
---|
70 | * stc_newfile create a new file |
---|
71 | */ |
---|
72 | function stc_newfile( $filename, $data ) |
---|
73 | { |
---|
74 | $fp = @fopen($filename, 'w'); |
---|
75 | if ($fp) { |
---|
76 | $ret = fwrite($fp, $data); |
---|
77 | @fclose($fp); |
---|
78 | return $ret; |
---|
79 | } |
---|
80 | return false; |
---|
81 | } |
---|
82 | /* |
---|
83 | * Default values |
---|
84 | */ |
---|
85 | function init_main(&$main) |
---|
86 | { |
---|
87 | global $available_templates; |
---|
88 | $main = array( |
---|
89 | STC_INTERNAL_VERSION => true, /* $main version */ |
---|
90 | 'template_sel' => 0, |
---|
91 | 'newtpl' => 'yoga', |
---|
92 | 'newtheme' => '', |
---|
93 | 'simulate' => true, |
---|
94 | 'colorize' => false, |
---|
95 | 'brightness' => false, |
---|
96 | 'contrast' => false, |
---|
97 | 'new_theme' => '', |
---|
98 | 'color1' => '#111111', |
---|
99 | 'color' => array('#111111', '#EEEEEE', '#FF7700', '#FF3333', '#FF3363', ), |
---|
100 | 'templatedir' => PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul', |
---|
101 | 'color1' => '#111111', |
---|
102 | 'color2' => '#EEEEEE', |
---|
103 | 'color3' => '#FF7700', |
---|
104 | 'color4' => '#FF3333', |
---|
105 | 'color5' => '#FF3363', |
---|
106 | 'background' => 'fixed', |
---|
107 | 'picture_url' => PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/sample.jpg', |
---|
108 | 'picture_width' => 2048, |
---|
109 | 'picture_height' => 100, |
---|
110 | 'background_mode' => 'as', |
---|
111 | 'src_category' => 0, |
---|
112 | 'category' => 'header', |
---|
113 | 'phase' => 'Kernel init', |
---|
114 | 'subphase' => 'New version', |
---|
115 | ); |
---|
116 | } |
---|
117 | |
---|
118 | $errors = array(); |
---|
119 | $infos = array(); |
---|
120 | |
---|
121 | // +-----------------------------------------------------------------------+ |
---|
122 | // | Kernel init | |
---|
123 | // +-----------------------------------------------------------------------+ |
---|
124 | if (!isset($swift_theme_creator)) $swift_theme_creator = new ThemeCreator(); |
---|
125 | $swift_theme_creator->reload(); |
---|
126 | $main = $swift_theme_creator->theme_config; |
---|
127 | |
---|
128 | /* |
---|
129 | * Find templates |
---|
130 | */ |
---|
131 | $available_templates = array(); |
---|
132 | $template_dir = PHPWG_ROOT_PATH.'template'; |
---|
133 | foreach (get_dirs($template_dir) as $dir) |
---|
134 | { array_push($available_templates, $dir); |
---|
135 | } |
---|
136 | /* |
---|
137 | * $main is reloaded but does template still exist? |
---|
138 | * Does the fixed background still exist? Category? ... |
---|
139 | */ |
---|
140 | if (!isset($main[STC_INTERNAL_VERSION])) init_main($main); |
---|
141 | $flip = array_flip($available_templates); |
---|
142 | $main['template_sel'] = (isset($flip[$main['newtpl']])) ? |
---|
143 | $flip[$main['newtpl']] : 0; /* Deleted ? First available */ |
---|
144 | $main['subphase'] = 'Find category'; |
---|
145 | $query = 'SELECT id,name,uppercats,global_rank |
---|
146 | FROM ' . CATEGORIES_TABLE . ';'; |
---|
147 | display_select_cat_wrapper($query,array(),'src_category'); |
---|
148 | $available_cat = $template->get_template_vars('src_category'); |
---|
149 | $flip = array_flip($available_cat); |
---|
150 | $main['src_category'] = (isset($flip[$main['category']])) ? |
---|
151 | $flip[$main['category']] : max($flip); /* Deleted ? Most recent */ |
---|
152 | |
---|
153 | |
---|
154 | // +-----------------------------------------------------------------------+ |
---|
155 | // | $_POST controls | |
---|
156 | // +-----------------------------------------------------------------------+ |
---|
157 | $main['phase'] = 'POST controls'; |
---|
158 | if (!isset($_POST['reset'])) |
---|
159 | { |
---|
160 | $main['simulate'] = isset($_POST['simulate']); |
---|
161 | if (!isset($_POST['submit'])) $main['simulate'] = true; |
---|
162 | /* |
---|
163 | * Template controls |
---|
164 | */ |
---|
165 | $main['subphase'] = 'template controls'; |
---|
166 | if (isset($_POST['template'])) $main['template_sel'] = $_POST['template']; |
---|
167 | $main['newtpl'] = $available_templates[$main['template_sel']]; |
---|
168 | if ($main['newtpl'] != 'yoga') |
---|
169 | array_push($infos, l10n('Unpredictable results could be observed with ' |
---|
170 | . 'this template. Preview is based on yoga template only.')); |
---|
171 | |
---|
172 | /* |
---|
173 | * Theme controls |
---|
174 | */ |
---|
175 | $main['subphase'] = 'theme controls'; |
---|
176 | if (isset($_POST['new_theme'])) $main['newtheme'] = strip_tags($_POST['new_theme']); |
---|
177 | if ($main['newtheme'] == '') $main['simulate'] = true; /* Empty = Simulate */ |
---|
178 | $cleaning = true; /* Delete files on failure */ |
---|
179 | if ( !$main['simulate'] and !preg_match('/^[a-z0-9-_]{1,8}$/', $main['newtheme']) ) |
---|
180 | array_push($errors, l10n('Invalid theme name: 1 to 8 lowercase' |
---|
181 | . ' alphanumeric characters including "-" and "_".')); |
---|
182 | if ($main['simulate']) { /* $main['templatedir'] != $template_dir (Smarty) */ |
---|
183 | $main['templatedir'] = PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul'; |
---|
184 | $themedir = $main['templatedir']; |
---|
185 | $cleaning = false; /* No delete with simulate */ |
---|
186 | } else { |
---|
187 | $main['templatedir'] = PHPWG_ROOT_PATH . 'template/' . $main['newtpl']; |
---|
188 | $themedir = $main['templatedir'] . '/theme/' . $main['newtheme']; |
---|
189 | } |
---|
190 | |
---|
191 | /* |
---|
192 | * Directories controls |
---|
193 | */ |
---|
194 | $main['subphase'] = 'directories controls'; |
---|
195 | if (is_dir( $themedir ) and !$main['simulate']) { |
---|
196 | array_push($errors, '['.$themedir.'] : '.l10n('Invalid theme: This' |
---|
197 | . ' theme exists already (no override available).')); |
---|
198 | $cleaning = false; /* No delete on existing theme */ |
---|
199 | } elseif ( !is_writable($main['templatedir']) ) |
---|
200 | array_push($errors, '['.$main['templatedir'].'] : '.l10n('no_write_access')); |
---|
201 | |
---|
202 | /* |
---|
203 | * Colors controls |
---|
204 | */ |
---|
205 | $main['subphase'] = 'colors controls'; |
---|
206 | if (isset($_POST['color1'])) |
---|
207 | $main['color'] = array( |
---|
208 | $_POST['color1'], $_POST['color2'], $_POST['color3'], $_POST['color4'], |
---|
209 | $_POST['color5']); |
---|
210 | $main['color1'] = $main['color'][0]; |
---|
211 | $main['color2'] = $main['color'][1]; |
---|
212 | $main['color3'] = $main['color'][2]; |
---|
213 | $main['color4'] = $main['color'][3]; |
---|
214 | $main['color5'] = $main['color'][4]; |
---|
215 | $colors = $main['color1'] . $main['color2'] |
---|
216 | . $main['color3'] . $main['color4'] . $main['color5']; |
---|
217 | if ( !preg_match('/^(#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})){5}$/', $colors) ) |
---|
218 | array_push($errors, l10n('Invalid color code: 3 or 6 hexadecimal characters,' |
---|
219 | . ' preceded or not by "#"')); |
---|
220 | |
---|
221 | /* |
---|
222 | * Background and text difference control |
---|
223 | */ |
---|
224 | $main['subphase'] = 'text difference controls'; |
---|
225 | list($r,$g,$b) = stc_hex2rgb($main['color'][0]); |
---|
226 | list($r2,$g2,$b2) = stc_hex2rgb($main['color'][1]); |
---|
227 | $dif = abs( ( (($r*299)+($g*587)+($b*114)) / 1000 ) |
---|
228 | - ( (( $r2*299)+($g2*587)+($b2*114)) / 1000 ) ); |
---|
229 | if ( $dif < 65 ) |
---|
230 | array_push($errors, l10n('Insufficient brightness difference between ' |
---|
231 | . 'text and background. dif=') . $dif); |
---|
232 | $dif = (max($r, $r2) - min($r, $r2)) |
---|
233 | + (max($g, $g2) - min($g, $g2)) + (max($b, $b2) - min($b, $b2)); |
---|
234 | if ( $dif < 200 ) |
---|
235 | array_push($errors, l10n('Insufficient colour difference between ' |
---|
236 | . 'text and background. dif=') . $dif); |
---|
237 | |
---|
238 | /* |
---|
239 | * Background and Internal links difference control |
---|
240 | */ |
---|
241 | $main['subphase'] = 'links difference controls'; |
---|
242 | if (false) |
---|
243 | { |
---|
244 | list($r,$g,$b) = stc_hex2rgb($main['color'][0]); |
---|
245 | list($r2,$g2,$b2) = stc_hex2rgb($main['color'][2]); |
---|
246 | $dif = abs( ( (($r*299)+($g*587)+($b*114)) / 1000 ) |
---|
247 | - ( (($r2*299)+($g2*587)+($b2*114)) / 1000 )); |
---|
248 | if ( $dif < 65 ) |
---|
249 | array_push($errors, l10n('Insufficient brightness difference between ' |
---|
250 | . 'Internal links and background. dif=') . $dif); |
---|
251 | $dif = (max($r, $r2) - min($r, $r2)) |
---|
252 | + (max($g, $g2) - min($g, $g2)) + (max($b, $b2) - min($b, $b2)); |
---|
253 | if ( $dif < 200 ) |
---|
254 | array_push($errors, l10n('Insufficient colour difference between ' |
---|
255 | . 'Internal links and background. dif=') . $dif); |
---|
256 | } |
---|
257 | |
---|
258 | /* |
---|
259 | * Header background controls |
---|
260 | */ |
---|
261 | $main['subphase'] = 'fixed background controls'; |
---|
262 | if (isset($_POST['picture_url'])) $main['picture_url'] = $_POST['picture_url']; |
---|
263 | if (isset($_POST['background_mode'])) |
---|
264 | $main['background_mode'] = $_POST['background_mode']; |
---|
265 | if (isset($_POST['background'])) $main['background'] = $_POST['background']; |
---|
266 | // Fixed |
---|
267 | if ( $main['background'] == 'fixed') { |
---|
268 | if ( is_dir($main['picture_url']) |
---|
269 | or !is_file($main['picture_url']) ) |
---|
270 | array_push($errors, l10n('Header picture is not found, check its path and name.')); |
---|
271 | $extension = substr($main['picture_url'],strrpos($main['picture_url'],'.')+1); |
---|
272 | if (!in_array($extension, array('jpg','jpeg','png'))) |
---|
273 | array_push($errors, l10n('Compliant extensions are .jpg, .jpeg or .png.')); |
---|
274 | } |
---|
275 | $main['subphase'] = 'random background controls'; |
---|
276 | if (isset($_POST['src_category'])) |
---|
277 | $main['src_category'] = (int) $_POST['src_category']; |
---|
278 | $main['category'] = $available_cat[$main['src_category']]; |
---|
279 | |
---|
280 | /* |
---|
281 | * Width and Height limits control |
---|
282 | */ |
---|
283 | $main['subphase'] = 'width and height controls'; |
---|
284 | if ($main['background'] != 'off' |
---|
285 | and isset($_POST['picture_width']) |
---|
286 | and isset($_POST['picture_height'])) |
---|
287 | { |
---|
288 | if( !(ctype_digit($_POST['picture_width']) |
---|
289 | and $_POST['picture_width'] > 11 |
---|
290 | and $_POST['picture_width'] < 4097 ) ) |
---|
291 | array_push($errors, '['.$_POST['picture_width'].'] : ' |
---|
292 | . l10n('incorrect width value [12-4096].')); |
---|
293 | else $main['picture_width'] = $_POST['picture_width']; |
---|
294 | if ( !(ctype_digit($_POST['picture_height']) |
---|
295 | and $_POST['picture_height'] > 11 |
---|
296 | and $_POST['picture_height'] < 201 ) ) |
---|
297 | array_push($errors, '['.$_POST['picture_height'].'] : ' |
---|
298 | . l10n('incorrect width value [12-200].')); |
---|
299 | else $main['picture_height'] = $_POST['picture_height']; |
---|
300 | } |
---|
301 | |
---|
302 | /* |
---|
303 | * Generate missing colors values |
---|
304 | */ |
---|
305 | $main['subphase'] = 'complementary colors'; |
---|
306 | list($r,$g,$b) = stc_hex2rgb($main['color'][0]); |
---|
307 | if ((( (($r+1)/256)*(($g+1)/256)*(($b+1)/256) ) * 1000 ) < 125 ) |
---|
308 | $main['color6'] = lighten( $r, $g, $b, 10); |
---|
309 | else $main['color6'] = darken( $r, $g, $b, 10); |
---|
310 | list($r,$g,$b) = stc_hex2rgb($main['color'][4]); |
---|
311 | if ((( (($r+1)/256)*(($g+1)/256)*(($b+1)/256) ) * 1000 ) < 125 ) |
---|
312 | $main['color7'] = lighten( $r, $g, $b, 10); |
---|
313 | else $main['color7'] = darken( $r, $g, $b, 10); |
---|
314 | $main['colorize'] = isset($_POST['colorize']) ? true : false; |
---|
315 | $main['brightness'] = isset($_POST['brightness']) ? true : false; |
---|
316 | $main['contrast'] = isset($_POST['contrast']) ? true : false; |
---|
317 | } |
---|
318 | |
---|
319 | // +-----------------------------------------------------------------------+ |
---|
320 | // | Build files | |
---|
321 | // +-----------------------------------------------------------------------+ |
---|
322 | $main['phase'] = 'Files building'; |
---|
323 | if (!function_exists('imagecreatetruecolor') or !function_exists('imagefilter')) { |
---|
324 | array_push($errors, l10n('Some Php Graphic resources are missing.' |
---|
325 | . ' Sorry for the inconvenience, but Swift Theme Creator couldn\'t work in such case.')); |
---|
326 | array_push($infos, l10n('This plugin requires PHP 5.2.5 or later' |
---|
327 | . ' and compiled against graphic library GD 2.0.1 or later.')); |
---|
328 | array_push($infos, l10n('On this server, PHP is:'). phpversion()); |
---|
329 | if (function_exists('gd_info')) { |
---|
330 | $GD = gd_info(); |
---|
331 | array_push($infos, l10n('and graphic library is:').$GD['GD Version']); |
---|
332 | } |
---|
333 | else array_push($infos, l10n('graphic library version is not available.')); |
---|
334 | $main['background'] = 'off'; |
---|
335 | } |
---|
336 | if ((isset($_POST['submit']) or $main['simulate'] ) and (!is_adviser())) |
---|
337 | { |
---|
338 | /* |
---|
339 | * Go ahead |
---|
340 | */ |
---|
341 | $main['subphase'] = 'Mkdir control'; |
---|
342 | if (count($errors) == 0) { |
---|
343 | umask(0000); |
---|
344 | @mkdir($themedir, 0705); |
---|
345 | if (!is_dir( $themedir )) |
---|
346 | array_push($errors, |
---|
347 | l10n('Theme directory creation failure: ' |
---|
348 | . 'it can\'t be created (for now en attendant la suite 8-) ).')); |
---|
349 | else { |
---|
350 | $main['ldelim'] = '{ldelim}'; |
---|
351 | /* |
---|
352 | * Build themeconf.inc.php |
---|
353 | **/ |
---|
354 | $main['subphase'] = 'Build themeconf'; |
---|
355 | $plugin_tpl = new Template(); |
---|
356 | $plugin_tpl->set_filenames(array('themeconf'=> |
---|
357 | STC_PATH . 'themeconf.inc.tpl')); |
---|
358 | $plugin_tpl->assign('main',$main); |
---|
359 | $main['themeconf_inc_php'] = $plugin_tpl->parse('themeconf', true); |
---|
360 | $rfs = stc_newfile( $themedir . '/themeconf.inc.php', |
---|
361 | $main['themeconf_inc_php'] ); |
---|
362 | /* |
---|
363 | * Build mail-css.tpl |
---|
364 | **/ |
---|
365 | $main['subphase'] = 'Build mail-css'; |
---|
366 | $plugin_tpl->set_filenames(array('mailcss'=> |
---|
367 | STC_PATH . 'mail-css.tpl2')); |
---|
368 | $plugin_tpl->assign('main',$main); |
---|
369 | $main['mail-css.tpl'] = $plugin_tpl->parse('mailcss', true); |
---|
370 | $rfs = $rfs && stc_newfile( $themedir . '/mail-css.tpl', |
---|
371 | $main['mail-css.tpl'] ); |
---|
372 | /* |
---|
373 | * Build theme.css |
---|
374 | **/ |
---|
375 | $main['subphase'] = 'Build theme'; |
---|
376 | $plugin_tpl->set_filenames(array('theme'=> STC_PATH . 'theme.tpl')); |
---|
377 | $plugin_tpl->assign('main',$main); |
---|
378 | $main['theme.css'] = $plugin_tpl->parse('theme', true); |
---|
379 | $rfs = $rfs && stc_newfile( $themedir . '/theme.css', $main['theme.css'] ); |
---|
380 | $internal = stc_hex2rgb($main['color'][2]); |
---|
381 | list($r,$g,$b) = $internal; |
---|
382 | $background = stc_hex2rgb($main['color'][0]); |
---|
383 | list($r2,$g2,$b2) = $background; |
---|
384 | $delta = floor(((array_sum($internal)/3) - (array_sum($background)/3))/5.1); |
---|
385 | /* Brightness is half of difference between colors of internal lnks and bkground */ |
---|
386 | /* but if color range is 0-255, resulting brightness range is between -50 and 50 */ |
---|
387 | if ($delta > 0) { /* Colorize need a darker color on a dark background */ |
---|
388 | $r = floor($r / 5); |
---|
389 | $g = floor($g / 5); |
---|
390 | $b = floor($b / 5); |
---|
391 | } |
---|
392 | if (isset($_POST['background']) and $_POST['background'] == 'random') |
---|
393 | { |
---|
394 | $main['subphase'] = 'Pick random for a pic'; |
---|
395 | $main['random'] = mt_rand(12, 4096); |
---|
396 | $result = pwg_query(' |
---|
397 | SELECT i.path |
---|
398 | FROM '.CATEGORIES_TABLE.' c, |
---|
399 | '.IMAGES_TABLE.' i, |
---|
400 | '.IMAGE_CATEGORY_TABLE.' ic |
---|
401 | WHERE c.status=\'public\' |
---|
402 | AND c.id = ic.category_id |
---|
403 | AND c.id = ' . $main['src_category'] . ' |
---|
404 | AND ic.category_id = ' . $main['src_category'] . ' |
---|
405 | AND ic.image_id = i.id |
---|
406 | ORDER BY RAND(' . $main['random'] . ') |
---|
407 | LIMIT 0,1'); |
---|
408 | if($result) list($main['pic_path']) = mysql_fetch_array($result); |
---|
409 | else $main['pic_path'] = |
---|
410 | PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/header.jpg'; |
---|
411 | $main['pic_ext'] = substr($main['pic_path'],strrpos($main['pic_path'],'.')+1); |
---|
412 | if ($main['pic_ext']=='png') |
---|
413 | $img = imagecreatefrompng($main['pic_path']); |
---|
414 | elseif (in_array($main['pic_ext'],array('jpg','jpeg'))) |
---|
415 | $img = imagecreatefromjpeg($main['pic_path']); |
---|
416 | else $img = imagecreatefromjpeg(PHPWG_ROOT_PATH |
---|
417 | . 'plugins/SwiftThemeCreator/simul/header.jpg'); |
---|
418 | imagejpeg( $img, $themedir . '/header.jpg', 90 ); |
---|
419 | imagedestroy ($img); |
---|
420 | } |
---|
421 | if (isset($_POST['background']) and $_POST['background'] == 'fixed') |
---|
422 | { |
---|
423 | $main['subphase'] = 'Fixed background'; |
---|
424 | $hdr = imagecreatetruecolor ($main['picture_width'], $main['picture_height']); |
---|
425 | imagecolorset ( $hdr, 0, $r2, $g2, $b2 ); |
---|
426 | if ($extension == 'png') $img = imagecreatefrompng($main['picture_url']); |
---|
427 | else $img = imagecreatefromjpeg($main['picture_url']); |
---|
428 | imagecopymerge ( $hdr, $img, 0, 0, 0, 0, $main['picture_width'], $main['picture_height'], 60 ); |
---|
429 | imagedestroy ($img); |
---|
430 | if ($main['colorize']) imagefilter($hdr, IMG_FILTER_COLORIZE, $r, $g, $b); |
---|
431 | if ($main['brightness']) imagefilter($hdr, IMG_FILTER_BRIGHTNESS, $delta); |
---|
432 | if ($main['contrast']) imagefilter($hdr, IMG_FILTER_CONTRAST, 20); |
---|
433 | imagejpeg( $hdr, $themedir . '/header.jpg', 90 ); |
---|
434 | imagedestroy ($hdr); |
---|
435 | } |
---|
436 | /* |
---|
437 | * Build background image for titrePage or definition list (in #menubar) |
---|
438 | **/ |
---|
439 | $main['subphase'] = 'Headbars background'; |
---|
440 | $hdr = imagecreatetruecolor (1, 38); |
---|
441 | imagecolorset ( $hdr, 0, $r2, $g2, $b2 ); |
---|
442 | $img = imagecreatefrompng(STC_PATH . '/titrePage-bg.png'); |
---|
443 | imagecopymerge ( $hdr, $img, 0, 0, 0, 0, 1, 38, 60 ); |
---|
444 | imagedestroy ($img); |
---|
445 | if ($main['colorize']) imagefilter($hdr, IMG_FILTER_COLORIZE, $r, $g, $b); |
---|
446 | if ($main['brightness']) imagefilter($hdr, IMG_FILTER_BRIGHTNESS, $delta); |
---|
447 | if ($main['contrast']) imagefilter($hdr, IMG_FILTER_CONTRAST, 20); |
---|
448 | imagepng( $hdr, $themedir . '/stc.png', 9 ); |
---|
449 | imagedestroy ($hdr); |
---|
450 | |
---|
451 | /* |
---|
452 | * Errors and cleaning or Congratulations |
---|
453 | **/ |
---|
454 | $main['phase'] = 'Congratulation'; |
---|
455 | $main['subphase'] = 'cleaning'; |
---|
456 | if ($rfs == false) { |
---|
457 | array_push($errors, |
---|
458 | l10n('Theme files creation failure: theme should be deleted.')); |
---|
459 | if ($cleaning) { |
---|
460 | @unlink( $themedir . '/header.jpg' ); |
---|
461 | @unlink( $themedir . '/stc.png' ); |
---|
462 | @unlink( $themedir . '/themeconf.inc.php' ); |
---|
463 | @unlink( $themedir . '/mail-css.tpl' ); |
---|
464 | @unlink( $themedir . '/theme.css' ); |
---|
465 | @rmdir( $themedir ); |
---|
466 | } |
---|
467 | } |
---|
468 | elseif (!$main['simulate']) { |
---|
469 | array_push($infos, |
---|
470 | '['.$main['newtpl'] . '/' . $main['newtheme'].'] : ' |
---|
471 | .l10n('Congratulation! You have got(/ten) a new available theme.')); |
---|
472 | @copy( $themedir . '/header.jpg', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/header.jpg'); |
---|
473 | @copy( $themedir . '/stc.png', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/stc.png'); |
---|
474 | @copy( $themedir . '/themeconf.inc.php', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/themeconf.inc.php'); |
---|
475 | @copy( $themedir . '/mail-css.tpl', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/mail-css.tpl'); |
---|
476 | @copy( $themedir . '/theme.css', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/theme.css'); |
---|
477 | } |
---|
478 | } |
---|
479 | } |
---|
480 | |
---|
481 | // TODO ******** theSwiftHeader itself ********* |
---|
482 | |
---|
483 | $swift_theme_creator->save_theme_config(); |
---|
484 | } |
---|
485 | |
---|
486 | // +-----------------------------------------------------------------------+ |
---|
487 | // | reset values |
---|
488 | // +-----------------------------------------------------------------------+ |
---|
489 | if (isset($_POST['reset']) and (!is_adviser())) { |
---|
490 | $main = array(); |
---|
491 | init_main($main); |
---|
492 | $swift_theme_creator->theme_config = $main; |
---|
493 | $swift_theme_creator->save_theme_config(); |
---|
494 | redirect( get_admin_plugin_menu_link(dirname(__FILE__).'/theme_creator.php')); |
---|
495 | } |
---|
496 | |
---|
497 | // Don't forget to re-read because some statements are superfluous |
---|
498 | |
---|
499 | // +-----------------------------------------------------------------------+ |
---|
500 | // | template initialization |
---|
501 | // +-----------------------------------------------------------------------+ |
---|
502 | $template->set_filenames(array( |
---|
503 | 'plugin_admin_content' => dirname(__FILE__) . '/theme_creator.tpl')); |
---|
504 | $template->append('head_elements', |
---|
505 | '<script type="text/javascript" |
---|
506 | src="./plugins/SwiftThemeCreator/farbtastic/farbtastic.js"></script> |
---|
507 | <link rel="stylesheet" type="text/css" |
---|
508 | href="./plugins/SwiftThemeCreator/farbtastic/farbtastic.css" /> |
---|
509 | <style type="text/css" media="screen"> |
---|
510 | .colorwell { border: 3px double #F30; width: 6em; |
---|
511 | text-align: center; cursor: pointer; } |
---|
512 | body .colorwell-selected { border: 3px double #F36; font-weight: bold; } |
---|
513 | .radio { margin: 0 10px 0 50px; } |
---|
514 | </style>' |
---|
515 | ); |
---|
516 | $template->assign('radio_options', |
---|
517 | array( |
---|
518 | 'true' => l10n('Yes'), |
---|
519 | 'false' => l10n('No'))); |
---|
520 | $template->assign('template_options', $available_templates); |
---|
521 | $template->assign('background_options', |
---|
522 | array( |
---|
523 | 'off' => l10n('No'), |
---|
524 | 'random' => l10n('24H Random'), |
---|
525 | 'fixed' => l10n('Fixed URL'), |
---|
526 | )); |
---|
527 | $template->assign('background_mode_options', |
---|
528 | array( |
---|
529 | 'as' => l10n('As is'), |
---|
530 | 'crop' => l10n('Truncated'), |
---|
531 | 'sized' => l10n('Resized'), |
---|
532 | )); |
---|
533 | if (count($errors) != 0) $template->assign('errors', $errors); |
---|
534 | if (count($infos) != 0) $template->assign('infos', $infos); |
---|
535 | /* Restore Main values */ |
---|
536 | $template->assign('main', $main); |
---|
537 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
538 | $swift_theme_creator->theme_config = $main; |
---|
539 | $swift_theme_creator->save_theme_config(); |
---|
540 | ?> |
---|