Dotclear

source: plugins/blowupConfig/lib/class.blowup.config.php @ 1436:c6aa788720c9

Revision 1436:c6aa788720c9, 20.1 KB checked in by Denis Jean-Christian <contact@…>, 12 years ago (diff)

Write blowUp CSS into a public file on update, like images, fixes #736

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

Sites map