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