1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | class blowupConfig |
---|
15 | { |
---|
16 | protected static $fonts = array( |
---|
17 | 'sans-serif' => array( |
---|
18 | 'ss1' => 'Arial, Helvetica, sans-serif', |
---|
19 | 'ss2' => 'Verdana,Geneva, Arial, Helvetica, sans-serif', |
---|
20 | 'ss3' => '"Lucida Grande", "Lucida Sans Unicode", sans-serif', |
---|
21 | 'ss4' => '"Trebuchet MS", Helvetica, sans-serif', |
---|
22 | 'ss5' => 'Impact, Charcoal, sans-serif' |
---|
23 | ), |
---|
24 | |
---|
25 | 'serif' => array( |
---|
26 | 's1' => 'Times, "Times New Roman", serif', |
---|
27 | 's2' => 'Georgia, serif', |
---|
28 | 's3' => 'Baskerville, "Palatino Linotype", serif' |
---|
29 | ), |
---|
30 | |
---|
31 | 'monospace' => array( |
---|
32 | 'm1' => '"Andale Mono", "Courier New", monospace', |
---|
33 | 'm2' => '"Courier New", Courier, mono, monospace' |
---|
34 | ) |
---|
35 | ); |
---|
36 | |
---|
37 | protected static $fonts_combo = array(); |
---|
38 | protected static $fonts_list = array(); |
---|
39 | |
---|
40 | public static $top_images = array( |
---|
41 | 'default' => 'Default', |
---|
42 | 'blank' => 'Blank', |
---|
43 | 'light-trails-1' => 'Light Trails 1', |
---|
44 | 'light-trails-2' => 'Light Trails 2', |
---|
45 | 'light-trails-3' => 'Light Trails 3', |
---|
46 | 'light-trails-4' => 'Light Trails 4', |
---|
47 | 'butterflies' => 'Butterflies', |
---|
48 | 'flourish-1' => 'Flourished 1', |
---|
49 | 'flourish-2' => 'Flourished 2', |
---|
50 | 'animals' => 'Animals', |
---|
51 | 'plumetis' => 'Plumetis', |
---|
52 | 'flamingo' => 'Flamingo', |
---|
53 | 'rabbit' => 'Rabbit', |
---|
54 | 'roadrunner-1' => 'Road Runner 1', |
---|
55 | 'roadrunner-2' => 'Road Runner 2', |
---|
56 | 'typo' => 'Typo' |
---|
57 | ); |
---|
58 | |
---|
59 | public static function fontsList() |
---|
60 | { |
---|
61 | if (empty(self::$fonts_combo)) |
---|
62 | { |
---|
63 | self::$fonts_combo[__('default')] = ''; |
---|
64 | foreach (self::$fonts as $family => $g) |
---|
65 | { |
---|
66 | $fonts = array(); |
---|
67 | foreach ($g as $code => $font) { |
---|
68 | $fonts[str_replace('"','',$font)] = $code; |
---|
69 | } |
---|
70 | self::$fonts_combo[$family] = $fonts; |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | return self::$fonts_combo; |
---|
75 | } |
---|
76 | |
---|
77 | public static function fontDef($c) |
---|
78 | { |
---|
79 | if (empty(self::$fonts_list)) |
---|
80 | { |
---|
81 | foreach (self::$fonts as $family => $g) |
---|
82 | { |
---|
83 | foreach ($g as $code => $font) { |
---|
84 | self::$fonts_list[$code] = $font; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | return isset(self::$fonts_list[$c]) ? self::$fonts_list[$c] : null; |
---|
90 | } |
---|
91 | |
---|
92 | public static function adjustFontSize($s) |
---|
93 | { |
---|
94 | if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex)?$/',$s,$m)) { |
---|
95 | if (empty($m[2])) { |
---|
96 | $m[2] = 'px'; |
---|
97 | } |
---|
98 | return $m[1].$m[2]; |
---|
99 | } |
---|
100 | |
---|
101 | return null; |
---|
102 | } |
---|
103 | |
---|
104 | public static function adjustPosition($p) |
---|
105 | { |
---|
106 | if (!preg_match('/^[0-9]+(:[0-9]+)?$/',$p)) { |
---|
107 | return null; |
---|
108 | } |
---|
109 | |
---|
110 | $p = explode(':',$p); |
---|
111 | |
---|
112 | return $p[0].(count($p) == 1 ? ':0' : ':'.$p[1]); |
---|
113 | } |
---|
114 | |
---|
115 | public static function adjustColor($c) |
---|
116 | { |
---|
117 | if ($c === '') { |
---|
118 | return ''; |
---|
119 | } |
---|
120 | |
---|
121 | $c = strtoupper($c); |
---|
122 | |
---|
123 | if (preg_match('/^[A-F0-9]{3,6}$/',$c)) { |
---|
124 | $c = '#'.$c; |
---|
125 | } |
---|
126 | |
---|
127 | if (preg_match('/^#[A-F0-9]{6}$/',$c)) { |
---|
128 | return $c; |
---|
129 | } |
---|
130 | |
---|
131 | if (preg_match('/^#[A-F0-9]{3,}$/',$c)) { |
---|
132 | return '#'.substr($c,1,1).substr($c,1,1).substr($c,2,1).substr($c,2,1).substr($c,3,1).substr($c,3,1); |
---|
133 | } |
---|
134 | |
---|
135 | return ''; |
---|
136 | } |
---|
137 | |
---|
138 | public static function cleanCSS($css) |
---|
139 | { |
---|
140 | // TODO ? |
---|
141 | return $css; |
---|
142 | } |
---|
143 | |
---|
144 | public static function cssPath() |
---|
145 | { |
---|
146 | global $core; |
---|
147 | return path::real($core->blog->public_path).'/blowup-css'; |
---|
148 | } |
---|
149 | |
---|
150 | public static function cssURL() |
---|
151 | { |
---|
152 | global $core; |
---|
153 | return $core->blog->settings->system->public_url.'/blowup-css'; |
---|
154 | } |
---|
155 | |
---|
156 | public static function canWriteCss($create=false) |
---|
157 | { |
---|
158 | global $core; |
---|
159 | |
---|
160 | $public = path::real($core->blog->public_path); |
---|
161 | $css = self::cssPath(); |
---|
162 | |
---|
163 | if (!is_dir($public)) { |
---|
164 | $core->error->add(__('The \'public\' directory does not exist.')); |
---|
165 | return false; |
---|
166 | } |
---|
167 | |
---|
168 | if (!is_dir($css)) { |
---|
169 | if (!is_writable($public)) { |
---|
170 | $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public')); |
---|
171 | return false; |
---|
172 | } |
---|
173 | if ($create) { |
---|
174 | files::makeDir($css); |
---|
175 | } |
---|
176 | return true; |
---|
177 | } |
---|
178 | |
---|
179 | if (!is_writable($css)) { |
---|
180 | $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public/blowup-css')); |
---|
181 | return false; |
---|
182 | } |
---|
183 | |
---|
184 | return true; |
---|
185 | } |
---|
186 | |
---|
187 | public static function createCss($s) |
---|
188 | { |
---|
189 | global $core; |
---|
190 | |
---|
191 | if ($s === null) { |
---|
192 | return; |
---|
193 | } |
---|
194 | |
---|
195 | $css = array(); |
---|
196 | |
---|
197 | /* Sidebar position |
---|
198 | ---------------------------------------------- */ |
---|
199 | if ($s['sidebar_position'] == 'left') { |
---|
200 | $css['#wrapper']['background-position'] = '-300px 0'; |
---|
201 | $css['#main']['float'] = 'right'; |
---|
202 | $css['#sidebar']['float'] = 'left'; |
---|
203 | } |
---|
204 | |
---|
205 | /* Properties |
---|
206 | ---------------------------------------------- */ |
---|
207 | self::prop($css,'body','background-color',$s['body_bg_c']); |
---|
208 | |
---|
209 | self::prop($css,'body','color',$s['body_txt_c']); |
---|
210 | self::prop($css,'.post-tags li a:link, .post-tags li a:visited, .post-info-co a:link, .post-info-co a:visited','color',$s['body_txt_c']); |
---|
211 | self::prop($css,'#page','font-size',$s['body_txt_s']); |
---|
212 | self::prop($css,'body','font-family',self::fontDef($s['body_txt_f'])); |
---|
213 | |
---|
214 | self::prop($css,'.post-content, .post-excerpt, #comments dd, #pings dd, dd.comment-preview','line-height',$s['body_line_height']); |
---|
215 | |
---|
216 | if (!$s['blog_title_hide']) |
---|
217 | { |
---|
218 | self::prop($css,'#top h1 a','color',$s['blog_title_c']); |
---|
219 | self::prop($css,'#top h1','font-size',$s['blog_title_s']); |
---|
220 | self::prop($css,'#top h1','font-family',self::fontDef($s['blog_title_f'])); |
---|
221 | |
---|
222 | if ($s['blog_title_a'] == 'right' || $s['blog_title_a'] == 'left') { |
---|
223 | $css['#top h1'][$s['blog_title_a']] = '0px'; |
---|
224 | $css['#top h1']['width'] = 'auto'; |
---|
225 | } |
---|
226 | |
---|
227 | if ($s['blog_title_p']) |
---|
228 | { |
---|
229 | $_p = explode(':',$s['blog_title_p']); |
---|
230 | $css['#top h1']['top'] = $_p[1].'px'; |
---|
231 | if ($s['blog_title_a'] != 'center') { |
---|
232 | $_a = $s['blog_title_a'] == 'right' ? 'right' : 'left'; |
---|
233 | $css['#top h1'][$_a] = $_p[0].'px'; |
---|
234 | } |
---|
235 | } |
---|
236 | } |
---|
237 | else |
---|
238 | { |
---|
239 | self::prop($css,'#top h1 span','text-indent','-5000px'); |
---|
240 | self::prop($css,'#top h1','top','0px'); |
---|
241 | $css['#top h1 a'] = array( |
---|
242 | 'display' => 'block', |
---|
243 | 'height' => $s['top_height'] ? ($s['top_height']-10).'px' : '120px', |
---|
244 | 'width' => '800px' |
---|
245 | ); |
---|
246 | } |
---|
247 | self::prop($css,'#top','height',$s['top_height']); |
---|
248 | |
---|
249 | self::prop($css,'.day-date','color',$s['date_title_c']); |
---|
250 | self::prop($css,'.day-date','font-family',self::fontDef($s['date_title_f'])); |
---|
251 | self::prop($css,'.day-date','font-size',$s['date_title_s']); |
---|
252 | |
---|
253 | self::prop($css,'a','color',$s['body_link_c']); |
---|
254 | self::prop($css,'a:visited','color',$s['body_link_v_c']); |
---|
255 | self::prop($css,'a:hover, a:focus, a:active','color',$s['body_link_f_c']); |
---|
256 | |
---|
257 | self::prop($css,'#comment-form input, #comment-form textarea','color',$s['body_link_c']); |
---|
258 | self::prop($css,'#comment-form input.preview','color',$s['body_link_c']); |
---|
259 | self::prop($css,'#comment-form input.preview:hover','background',$s['body_link_f_c']); |
---|
260 | self::prop($css,'#comment-form input.preview:hover','border-color',$s['body_link_f_c']); |
---|
261 | self::prop($css,'#comment-form input.submit','color',$s['body_link_c']); |
---|
262 | self::prop($css,'#comment-form input.submit:hover','background',$s['body_link_f_c']); |
---|
263 | self::prop($css,'#comment-form input.submit:hover','border-color',$s['body_link_f_c']); |
---|
264 | |
---|
265 | self::prop($css,'#sidebar','font-family',self::fontDef($s['sidebar_text_f'])); |
---|
266 | self::prop($css,'#sidebar','font-size',$s['sidebar_text_s']); |
---|
267 | self::prop($css,'#sidebar','color',$s['sidebar_text_c']); |
---|
268 | |
---|
269 | self::prop($css,'#sidebar h2','font-family',self::fontDef($s['sidebar_title_f'])); |
---|
270 | self::prop($css,'#sidebar h2','font-size',$s['sidebar_title_s']); |
---|
271 | self::prop($css,'#sidebar h2','color',$s['sidebar_title_c']); |
---|
272 | |
---|
273 | self::prop($css,'#sidebar h3','font-family',self::fontDef($s['sidebar_title2_f'])); |
---|
274 | self::prop($css,'#sidebar h3','font-size',$s['sidebar_title2_s']); |
---|
275 | self::prop($css,'#sidebar h3','color',$s['sidebar_title2_c']); |
---|
276 | |
---|
277 | self::prop($css,'#sidebar ul','border-top-color',$s['sidebar_line_c']); |
---|
278 | self::prop($css,'#sidebar li','border-bottom-color',$s['sidebar_line_c']); |
---|
279 | self::prop($css,'#topnav ul','border-bottom-color',$s['sidebar_line_c']); |
---|
280 | |
---|
281 | self::prop($css,'#sidebar li a','color',$s['sidebar_link_c']); |
---|
282 | self::prop($css,'#sidebar li a:visited','color',$s['sidebar_link_v_c']); |
---|
283 | self::prop($css,'#sidebar li a:hover, #sidebar li a:focus, #sidebar li a:active','color',$s['sidebar_link_f_c']); |
---|
284 | self::prop($css,'#search input','color',$s['sidebar_link_c']); |
---|
285 | self::prop($css,'#search .submit','color',$s['sidebar_link_c']); |
---|
286 | self::prop($css,'#search .submit:hover','background',$s['sidebar_link_f_c']); |
---|
287 | self::prop($css,'#search .submit:hover','border-color',$s['sidebar_link_f_c']); |
---|
288 | |
---|
289 | self::prop($css,'.post-title','color',$s['post_title_c']); |
---|
290 | self::prop($css,'.post-title a, .post-title a:visited','color',$s['post_title_c']); |
---|
291 | self::prop($css,'.post-title','font-family',self::fontDef($s['post_title_f'])); |
---|
292 | self::prop($css,'.post-title','font-size',$s['post_title_s']); |
---|
293 | |
---|
294 | self::prop($css,'#comments dd','background-color',$s['post_comment_bg_c']); |
---|
295 | self::prop($css,'#comments dd','color',$s['post_comment_c']); |
---|
296 | self::prop($css,'#comments dd.me','background-color',$s['post_commentmy_bg_c']); |
---|
297 | self::prop($css,'#comments dd.me','color',$s['post_commentmy_c']); |
---|
298 | |
---|
299 | self::prop($css,'#prelude, #prelude a','color',$s['prelude_c']); |
---|
300 | |
---|
301 | self::prop($css,'#footer p','background-color',$s['footer_bg_c']); |
---|
302 | self::prop($css,'#footer p','color',$s['footer_c']); |
---|
303 | self::prop($css,'#footer p','font-size',$s['footer_s']); |
---|
304 | self::prop($css,'#footer p','font-family',self::fontDef($s['footer_f'])); |
---|
305 | self::prop($css,'#footer p a','color',$s['footer_l_c']); |
---|
306 | |
---|
307 | /* Images |
---|
308 | ------------------------------------------------------ */ |
---|
309 | self::backgroundImg($css,'body',$s['body_bg_c'],'body-bg.png'); |
---|
310 | self::backgroundImg($css,'body',$s['body_bg_g'] != 'light','body-bg.png'); |
---|
311 | self::backgroundImg($css,'body',$s['prelude_c'],'body-bg.png'); |
---|
312 | self::backgroundImg($css,'#top',$s['body_bg_c'],'page-t.png'); |
---|
313 | self::backgroundImg($css,'#top',$s['body_bg_g'] != 'light','page-t.png'); |
---|
314 | self::backgroundImg($css,'#top',$s['uploaded'] || $s['top_image'],'page-t.png'); |
---|
315 | self::backgroundImg($css,'#footer',$s['body_bg_c'],'page-b.png'); |
---|
316 | self::backgroundImg($css,'#comments dt',$s['post_comment_bg_c'],'comment-t.png'); |
---|
317 | self::backgroundImg($css,'#comments dd',$s['post_comment_bg_c'],'comment-b.png'); |
---|
318 | self::backgroundImg($css,'#comments dt.me',$s['post_commentmy_bg_c'],'commentmy-t.png'); |
---|
319 | self::backgroundImg($css,'#comments dd.me',$s['post_commentmy_bg_c'],'commentmy-b.png'); |
---|
320 | |
---|
321 | $res = ''; |
---|
322 | foreach ($css as $selector => $values) { |
---|
323 | $res .= $selector." {\n"; |
---|
324 | foreach ($values as $k => $v) { |
---|
325 | $res .= $k.':'.$v.";\n"; |
---|
326 | } |
---|
327 | $res .= "}\n"; |
---|
328 | } |
---|
329 | |
---|
330 | $res .= $s['extra_css']; |
---|
331 | |
---|
332 | if (!self::canWriteCss(true)) { |
---|
333 | throw new Exception(__('Unable to create css file.')); |
---|
334 | } |
---|
335 | |
---|
336 | # erase old css file |
---|
337 | self::dropCss($core->blog->settings->system->theme); |
---|
338 | |
---|
339 | # create new css file into public blowup-css subdirectory |
---|
340 | self::writeCss($core->blog->settings->system->theme, $res); |
---|
341 | |
---|
342 | return $res; |
---|
343 | } |
---|
344 | |
---|
345 | protected static function prop(&$css,$selector,$prop,$value) |
---|
346 | { |
---|
347 | if ($value) { |
---|
348 | $css[$selector][$prop] = $value; |
---|
349 | } |
---|
350 | } |
---|
351 | |
---|
352 | protected static function backgroundImg(&$css,$selector,$value,$image) |
---|
353 | { |
---|
354 | $file = self::imagesPath().'/'.$image; |
---|
355 | if ($value && file_exists($file)){ |
---|
356 | $css[$selector]['background-image'] = 'url('.self::imagesURL().'/'.$image.')'; |
---|
357 | } |
---|
358 | } |
---|
359 | |
---|
360 | private static function writeCss($theme,$css) |
---|
361 | { |
---|
362 | file_put_contents(self::cssPath().'/'.$theme.'.css', $css); |
---|
363 | } |
---|
364 | |
---|
365 | public static function dropCss($theme) |
---|
366 | { |
---|
367 | $file = path::real(self::cssPath().'/'.$theme.'.css'); |
---|
368 | if (is_writable(dirname($file))) { |
---|
369 | @unlink($file); |
---|
370 | } |
---|
371 | } |
---|
372 | |
---|
373 | public static function publicCssUrlHelper() |
---|
374 | { |
---|
375 | $theme = $GLOBALS['core']->blog->settings->system->theme; |
---|
376 | $url = blowupConfig::cssURL(); |
---|
377 | $path = blowupConfig::cssPath(); |
---|
378 | |
---|
379 | if (file_exists($path.'/'.$theme.'.css')) { |
---|
380 | return $url.'/'.$theme.'.css'; |
---|
381 | } |
---|
382 | |
---|
383 | return null; |
---|
384 | } |
---|
385 | |
---|
386 | public static function imagesPath() |
---|
387 | { |
---|
388 | global $core; |
---|
389 | return path::real($core->blog->public_path).'/blowup-images'; |
---|
390 | } |
---|
391 | |
---|
392 | public static function imagesURL() |
---|
393 | { |
---|
394 | global $core; |
---|
395 | return $core->blog->settings->system->public_url.'/blowup-images'; |
---|
396 | } |
---|
397 | |
---|
398 | public static function canWriteImages($create=false) |
---|
399 | { |
---|
400 | global $core; |
---|
401 | |
---|
402 | $public = path::real($core->blog->public_path); |
---|
403 | $imgs = self::imagesPath(); |
---|
404 | |
---|
405 | if (!function_exists('imagecreatetruecolor') || !function_exists('imagepng') || !function_exists('imagecreatefrompng')) { |
---|
406 | $core->error->add(__('At least one of the following functions is not available: '. |
---|
407 | 'imagecreatetruecolor, imagepng & imagecreatefrompng.')); |
---|
408 | return false; |
---|
409 | } |
---|
410 | |
---|
411 | if (!is_dir($public)) { |
---|
412 | $core->error->add(__('The \'public\' directory does not exist.')); |
---|
413 | return false; |
---|
414 | } |
---|
415 | |
---|
416 | if (!is_dir($imgs)) { |
---|
417 | if (!is_writable($public)) { |
---|
418 | $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public')); |
---|
419 | return false; |
---|
420 | } |
---|
421 | if ($create) { |
---|
422 | files::makeDir($imgs); |
---|
423 | } |
---|
424 | return true; |
---|
425 | } |
---|
426 | |
---|
427 | if (!is_writable($imgs)) { |
---|
428 | $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public/blowup-images')); |
---|
429 | return false; |
---|
430 | } |
---|
431 | |
---|
432 | return true; |
---|
433 | } |
---|
434 | |
---|
435 | public static function uploadImage($f) |
---|
436 | { |
---|
437 | if (!self::canWriteImages(true)) { |
---|
438 | throw new Exception(__('Unable to create images.')); |
---|
439 | } |
---|
440 | |
---|
441 | $name = $f['name']; |
---|
442 | $type = files::getMimeType($name); |
---|
443 | |
---|
444 | if ($type != 'image/jpeg' && $type != 'image/png') { |
---|
445 | throw new Exception(__('Invalid file type.')); |
---|
446 | } |
---|
447 | |
---|
448 | $dest = self::imagesPath().'/uploaded'.($type == 'image/png' ? '.png' : '.jpg'); |
---|
449 | |
---|
450 | if (@move_uploaded_file($f['tmp_name'],$dest) === false) { |
---|
451 | throw new Exception(__('An error occurred while writing the file.')); |
---|
452 | } |
---|
453 | |
---|
454 | $s = getimagesize($dest); |
---|
455 | if ($s[0] != 800) { |
---|
456 | throw new Exception(__('Uploaded image is not 800 pixels wide.')); |
---|
457 | } |
---|
458 | |
---|
459 | return $dest; |
---|
460 | } |
---|
461 | |
---|
462 | public static function createImages(&$config,$uploaded) |
---|
463 | { |
---|
464 | $body_color = $config['body_bg_c']; |
---|
465 | $prelude_color = $config['prelude_c']; |
---|
466 | $gradient = $config['body_bg_g']; |
---|
467 | $comment_color = $config['post_comment_bg_c']; |
---|
468 | $comment_color_my = $config['post_commentmy_bg_c']; |
---|
469 | $top_image = $config['top_image']; |
---|
470 | |
---|
471 | $config['top_height'] = null; |
---|
472 | |
---|
473 | if ($top_image != 'custom' && !isset(self::$top_images[$top_image])) { |
---|
474 | $top_image = 'default'; |
---|
475 | } |
---|
476 | if ($uploaded && !is_file($uploaded)) { |
---|
477 | $uploaded = null; |
---|
478 | } |
---|
479 | |
---|
480 | if (!self::canWriteImages(true)) { |
---|
481 | throw new Exception(__('Unable to create images.')); |
---|
482 | } |
---|
483 | |
---|
484 | $body_fill = array( |
---|
485 | 'light' => dirname(__FILE__).'/../alpha-img/gradient-l.png', |
---|
486 | 'medium' => dirname(__FILE__).'/../alpha-img/gradient-m.png', |
---|
487 | 'dark' => dirname(__FILE__).'/../alpha-img/gradient-d.png' |
---|
488 | ); |
---|
489 | |
---|
490 | $body_g = isset($body_fill[$gradient]) ? $body_fill[$gradient] : false; |
---|
491 | |
---|
492 | if ($top_image == 'custom' && $uploaded) { |
---|
493 | $page_t = $uploaded; |
---|
494 | } else { |
---|
495 | $page_t = dirname(__FILE__).'/../alpha-img/page-t/'.$top_image.'.png'; |
---|
496 | } |
---|
497 | |
---|
498 | $body_bg = dirname(__FILE__).'/../alpha-img/body-bg.png'; |
---|
499 | $page_t_mask = dirname(__FILE__).'/../alpha-img/page-t/image-mask.png'; |
---|
500 | $page_b = dirname(__FILE__).'/../alpha-img/page-b.png'; |
---|
501 | $comment_t = dirname(__FILE__).'/../alpha-img/comment-t.png'; |
---|
502 | $comment_b = dirname(__FILE__).'/../alpha-img/comment-b.png'; |
---|
503 | $default_bg = '#e0e0e0'; |
---|
504 | $default_prelude = '#ededed'; |
---|
505 | |
---|
506 | self::dropImage(basename($body_bg)); |
---|
507 | self::dropImage('page-t.png'); |
---|
508 | self::dropImage(basename($page_b)); |
---|
509 | self::dropImage(basename($comment_t)); |
---|
510 | self::dropImage(basename($comment_b)); |
---|
511 | |
---|
512 | $body_color = self::adjustColor($body_color); |
---|
513 | $prelude_color = self::adjustColor($prelude_color); |
---|
514 | $comment_color = self::adjustColor($comment_color); |
---|
515 | |
---|
516 | if ($top_image || $body_color || $gradient != 'light' || $prelude_color || $uploaded) |
---|
517 | { |
---|
518 | if (!$body_color) { |
---|
519 | $body_color = $default_bg; |
---|
520 | } |
---|
521 | $body_color = sscanf($body_color,'#%2X%2X%2X'); |
---|
522 | |
---|
523 | # Create body gradient with color |
---|
524 | $d_body_bg = imagecreatetruecolor(50,180); |
---|
525 | $fill = imagecolorallocate($d_body_bg,$body_color[0],$body_color[1],$body_color[2]); |
---|
526 | imagefill($d_body_bg,0,0,$fill); |
---|
527 | |
---|
528 | # User choosed a gradient |
---|
529 | if ($body_g) { |
---|
530 | $s_body_bg = imagecreatefrompng($body_g); |
---|
531 | imagealphablending($s_body_bg,true); |
---|
532 | imagecopy($d_body_bg,$s_body_bg,0,0,0,0,50,180); |
---|
533 | imagedestroy($s_body_bg); |
---|
534 | } |
---|
535 | |
---|
536 | if (!$prelude_color) { |
---|
537 | $prelude_color = $default_prelude; |
---|
538 | } |
---|
539 | $prelude_color = sscanf($prelude_color,'#%2X%2X%2X'); |
---|
540 | |
---|
541 | $s_prelude = imagecreatetruecolor(50,30); |
---|
542 | $fill = imagecolorallocate($s_prelude,$prelude_color[0],$prelude_color[1],$prelude_color[2]); |
---|
543 | imagefill($s_prelude,0,0,$fill); |
---|
544 | imagecopy($d_body_bg,$s_prelude,0,0,0,0,50,30); |
---|
545 | |
---|
546 | imagepng($d_body_bg,self::imagesPath().'/'.basename($body_bg)); |
---|
547 | } |
---|
548 | |
---|
549 | if ($top_image || $body_color || $gradient != 'light') |
---|
550 | { |
---|
551 | # Create top image from uploaded image |
---|
552 | $size = getimagesize($page_t); |
---|
553 | $size = $size[1]; |
---|
554 | $type = files::getMimeType($page_t); |
---|
555 | |
---|
556 | $d_page_t = imagecreatetruecolor(800,$size); |
---|
557 | |
---|
558 | if ($type == 'image/png') { |
---|
559 | $s_page_t = @imagecreatefrompng($page_t); |
---|
560 | } else { |
---|
561 | $s_page_t = @imagecreatefromjpeg($page_t); |
---|
562 | } |
---|
563 | |
---|
564 | if (!$s_page_t) { |
---|
565 | throw new exception(__('Unable to open image.')); |
---|
566 | } |
---|
567 | |
---|
568 | $fill = imagecolorallocate($d_page_t,$body_color[0],$body_color[1],$body_color[2]); |
---|
569 | imagefill($d_page_t,0,0,$fill); |
---|
570 | |
---|
571 | if ($type == 'image/png') |
---|
572 | { |
---|
573 | # PNG, we only add body gradient and image |
---|
574 | imagealphablending($s_page_t,true); |
---|
575 | imagecopyresized($d_page_t,$d_body_bg,0,0,0,50,800,130,50,130); |
---|
576 | imagecopy($d_page_t,$s_page_t,0,0,0,0,800,$size); |
---|
577 | } |
---|
578 | else |
---|
579 | { |
---|
580 | # JPEG, we add image and a frame with rounded corners |
---|
581 | imagecopy($d_page_t,$s_page_t,0,0,0,0,800,$size); |
---|
582 | |
---|
583 | imagecopy($d_page_t,$d_body_bg,0,0,0,50,8,4); |
---|
584 | imagecopy($d_page_t,$d_body_bg,0,4,0,54,4,4); |
---|
585 | imagecopy($d_page_t,$d_body_bg,792,0,0,50,8,4); |
---|
586 | imagecopy($d_page_t,$d_body_bg,796,4,0,54,4,4); |
---|
587 | |
---|
588 | $mask = imagecreatefrompng($page_t_mask); |
---|
589 | imagealphablending($mask,true); |
---|
590 | imagecopy($d_page_t,$mask,0,0,0,0,800,11); |
---|
591 | imagedestroy($mask); |
---|
592 | |
---|
593 | $fill = imagecolorallocate($d_page_t,255,255,255); |
---|
594 | imagefilledrectangle($d_page_t,0,11,3,$size-1,$fill); |
---|
595 | imagefilledrectangle($d_page_t,796,11,799,$size-1,$fill); |
---|
596 | imagefilledrectangle($d_page_t,0,$size-9,799,$size-1,$fill); |
---|
597 | } |
---|
598 | |
---|
599 | $config['top_height'] = ($size).'px'; |
---|
600 | |
---|
601 | imagepng($d_page_t,self::imagesPath().'/page-t.png'); |
---|
602 | |
---|
603 | imagedestroy($d_body_bg); |
---|
604 | imagedestroy($d_page_t); |
---|
605 | imagedestroy($s_page_t); |
---|
606 | |
---|
607 | # Create bottom image with color |
---|
608 | $d_page_b = imagecreatetruecolor(800,8); |
---|
609 | $fill = imagecolorallocate($d_page_b,$body_color[0],$body_color[1],$body_color[2]); |
---|
610 | imagefill($d_page_b,0,0,$fill); |
---|
611 | |
---|
612 | $s_page_b = imagecreatefrompng($page_b); |
---|
613 | imagealphablending($s_page_b,true); |
---|
614 | imagecopy($d_page_b,$s_page_b,0,0,0,0,800,160); |
---|
615 | |
---|
616 | imagepng($d_page_b,self::imagesPath().'/'.basename($page_b)); |
---|
617 | |
---|
618 | imagedestroy($d_page_b); |
---|
619 | imagedestroy($s_page_b); |
---|
620 | } |
---|
621 | |
---|
622 | if ($comment_color) { |
---|
623 | self::commentImages($comment_color,$comment_t,$comment_b,basename($comment_t),basename($comment_b)); |
---|
624 | } |
---|
625 | if ($comment_color_my) { |
---|
626 | self::commentImages($comment_color_my,$comment_t,$comment_b,'commentmy-t.png','commentmy-b.png'); |
---|
627 | } |
---|
628 | } |
---|
629 | |
---|
630 | protected static function commentImages($comment_color,$comment_t,$comment_b,$dest_t,$dest_b) |
---|
631 | { |
---|
632 | $comment_color = sscanf($comment_color,'#%2X%2X%2X'); |
---|
633 | |
---|
634 | $d_comment_t = imagecreatetruecolor(500,25); |
---|
635 | $fill = imagecolorallocate($d_comment_t,$comment_color[0],$comment_color[1],$comment_color[2]); |
---|
636 | imagefill($d_comment_t,0,0,$fill); |
---|
637 | |
---|
638 | $s_comment_t = imagecreatefrompng($comment_t); |
---|
639 | imagealphablending($s_comment_t,true); |
---|
640 | imagecopy($d_comment_t,$s_comment_t,0,0,0,0,500,25); |
---|
641 | |
---|
642 | imagepng($d_comment_t,self::imagesPath().'/'.$dest_t); |
---|
643 | imagedestroy($d_comment_t); |
---|
644 | imagedestroy($s_comment_t); |
---|
645 | |
---|
646 | $d_comment_b = imagecreatetruecolor(500,7); |
---|
647 | $fill = imagecolorallocate($d_comment_b,$comment_color[0],$comment_color[1],$comment_color[2]); |
---|
648 | imagefill($d_comment_b,0,0,$fill); |
---|
649 | |
---|
650 | $s_comment_b = imagecreatefrompng($comment_b); |
---|
651 | imagealphablending($s_comment_b,true); |
---|
652 | imagecopy($d_comment_b,$s_comment_b,0,0,0,0,500,7); |
---|
653 | |
---|
654 | imagepng($d_comment_b,self::imagesPath().'/'.$dest_b); |
---|
655 | imagedestroy($d_comment_b); |
---|
656 | imagedestroy($s_comment_b); |
---|
657 | } |
---|
658 | |
---|
659 | public static function dropImage($img) |
---|
660 | { |
---|
661 | $img = path::real(self::imagesPath().'/'.$img); |
---|
662 | if (is_writable(dirname($img))) { |
---|
663 | @unlink($img); |
---|
664 | @unlink(dirname($img).'/.'.basename($img,'.png').'_sq.jpg'); |
---|
665 | @unlink(dirname($img).'/.'.basename($img,'.png').'_m.jpg'); |
---|
666 | @unlink(dirname($img).'/.'.basename($img,'.png').'_s.jpg'); |
---|
667 | @unlink(dirname($img).'/.'.basename($img,'.png').'_sq.jpg'); |
---|
668 | @unlink(dirname($img).'/.'.basename($img,'.png').'_t.jpg'); |
---|
669 | } |
---|
670 | } |
---|
671 | } |
---|
672 | ?> |
---|