Dotclear


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/blowupConfig/lib/class.blowup.config.php

    • Property exe set to *
    r270 r295  
    2222               'ss5' => 'Impact, Charcoal, sans-serif' 
    2323          ), 
    24            
     24 
    2525          'serif' => array( 
    2626               's1' => 'Times, "Times New Roman", serif', 
     
    2828               's3' => 'Baskerville, "Palatino Linotype", serif' 
    2929          ), 
    30            
     30 
    3131          'monospace' => array( 
    3232               'm1' => '"Andale Mono", "Courier New", monospace', 
     
    3434          ) 
    3535     ); 
    36       
     36 
    3737     protected static $fonts_combo = array(); 
    3838     protected static $fonts_list = array(); 
    39       
     39 
    4040     public static $top_images = array( 
    4141          'default' => 'Default', 
     
    5555          'typo' => 'Typo', 
    5656     ); 
    57       
     57 
    5858     public static function fontsList() 
    5959     { 
     
    7070               } 
    7171          } 
    72            
     72 
    7373          return self::$fonts_combo; 
    7474     } 
    75       
     75 
    7676     public static function fontDef($c) 
    7777     { 
     
    8585               } 
    8686          } 
    87            
     87 
    8888          return isset(self::$fonts_list[$c]) ? self::$fonts_list[$c] : null; 
    8989     } 
    90       
     90 
    9191     public static function adjustFontSize($s) 
    9292     { 
     
    9797               return $m[1].$m[2]; 
    9898          } 
    99            
     99 
    100100          return null; 
    101101     } 
    102       
     102 
    103103     public static function adjustPosition($p) 
    104104     { 
     
    106106               return null; 
    107107          } 
    108            
     108 
    109109          $p = explode(':',$p); 
    110            
     110 
    111111          return $p[0].(count($p) == 1 ? ':0' : ':'.$p[1]); 
    112112     } 
    113       
     113 
    114114     public static function adjustColor($c) 
    115115     { 
     
    117117               return ''; 
    118118          } 
    119            
     119 
    120120          $c = strtoupper($c); 
    121            
     121 
    122122          if (preg_match('/^[A-F0-9]{3,6}$/',$c)) { 
    123123               $c = '#'.$c; 
    124124          } 
    125            
     125 
    126126          if (preg_match('/^#[A-F0-9]{6}$/',$c)) { 
    127127               return $c; 
    128128          } 
    129            
     129 
    130130          if (preg_match('/^#[A-F0-9]{3,}$/',$c)) { 
    131131               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); 
    132132          } 
    133            
     133 
    134134          return ''; 
    135135     } 
    136       
     136 
     137     public static function cleanCSS($css) 
     138     { 
     139          // TODO ? 
     140          return $css; 
     141     } 
     142 
    137143     public static function imagesPath() 
    138144     { 
     
    140146          return path::real($core->blog->public_path).'/blowup-images'; 
    141147     } 
    142       
     148 
    143149     public static function imagesURL() 
    144150     { 
     
    146152          return $core->blog->settings->system->public_url.'/blowup-images'; 
    147153     } 
    148       
     154 
    149155     public static function canWriteImages($create=false) 
    150156     { 
    151157          global $core; 
    152            
     158 
    153159          $public = path::real($core->blog->public_path); 
    154160          $imgs = self::imagesPath(); 
    155            
     161 
    156162          if (!function_exists('imagecreatetruecolor') || !function_exists('imagepng') || !function_exists('imagecreatefrompng')) { 
    157163               $core->error->add(__('At least one of the following functions is not available: '. 
     
    159165               return false; 
    160166          } 
    161            
     167 
    162168          if (!is_dir($public)) { 
    163169               $core->error->add(__('The \'public\' directory does not exist.')); 
    164170               return false; 
    165171          } 
    166            
     172 
    167173          if (!is_dir($imgs)) { 
    168174               if (!is_writable($public)) { 
     
    175181               return true; 
    176182          } 
    177            
     183 
    178184          if (!is_writable($imgs)) { 
    179185               $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public/blowup-images')); 
    180186               return false; 
    181187          } 
    182            
     188 
    183189          return true; 
    184190     } 
    185       
     191 
    186192     public static function uploadImage($f) 
    187193     { 
     
    189195               throw new Exception(__('Unable to create images.')); 
    190196          } 
    191            
     197 
    192198          $name = $f['name']; 
    193199          $type = files::getMimeType($name); 
    194            
     200 
    195201          if ($type != 'image/jpeg' && $type != 'image/png') { 
    196202               throw new Exception(__('Invalid file type.')); 
    197203          } 
    198            
     204 
    199205          $dest = self::imagesPath().'/uploaded'.($type == 'image/png' ? '.png' : '.jpg'); 
    200            
     206 
    201207          if (@move_uploaded_file($f['tmp_name'],$dest) === false) { 
    202208               throw new Exception(__('An error occurred while writing the file.')); 
    203209          } 
    204            
     210 
    205211          $s = getimagesize($dest); 
    206212          if ($s[0] != 800) { 
    207213               throw new Exception(__('Uploaded image is not 800 pixels wide.')); 
    208214          } 
    209            
     215 
    210216          return $dest; 
    211217     } 
    212       
     218 
    213219     public static function createImages(&$config,$uploaded) 
    214220     { 
     
    219225          $comment_color_my = $config['post_commentmy_bg_c']; 
    220226          $top_image = $config['top_image']; 
    221            
     227 
    222228          $config['top_height'] = null; 
    223            
     229 
    224230          if ($top_image != 'custom' && !isset(self::$top_images[$top_image])) { 
    225231               $top_image = 'default'; 
     
    228234               $uploaded = null; 
    229235          } 
    230            
     236 
    231237          if (!self::canWriteImages(true)) { 
    232238               throw new Exception(__('Unable to create images.')); 
    233239          } 
    234            
     240 
    235241          $body_fill = array( 
    236242               'light' => dirname(__FILE__).'/../alpha-img/gradient-l.png', 
     
    238244               'dark' => dirname(__FILE__).'/../alpha-img/gradient-d.png' 
    239245          ); 
    240            
     246 
    241247          $body_g = isset($body_fill[$gradient]) ? $body_fill[$gradient] : false; 
    242            
     248 
    243249          if ($top_image == 'custom' && $uploaded) { 
    244250               $page_t = $uploaded; 
     
    246252               $page_t = dirname(__FILE__).'/../alpha-img/page-t/'.$top_image.'.png'; 
    247253          } 
    248            
     254 
    249255          $body_bg = dirname(__FILE__).'/../alpha-img/body-bg.png'; 
    250256          $page_t_mask = dirname(__FILE__).'/../alpha-img/page-t/image-mask.png'; 
     
    254260          $default_bg = '#e0e0e0'; 
    255261          $default_prelude = '#ededed'; 
    256            
     262 
    257263          self::dropImage(basename($body_bg)); 
    258264          self::dropImage('page-t.png'); 
     
    260266          self::dropImage(basename($comment_t)); 
    261267          self::dropImage(basename($comment_b)); 
    262            
     268 
    263269          $body_color = self::adjustColor($body_color); 
    264270          $prelude_color = self::adjustColor($prelude_color); 
    265271          $comment_color = self::adjustColor($comment_color); 
    266            
     272 
    267273          if ($top_image || $body_color || $gradient != 'light' || $prelude_color || $uploaded) 
    268274          { 
     
    271277               } 
    272278               $body_color = sscanf($body_color,'#%2X%2X%2X'); 
    273                 
     279 
    274280               # Create body gradient with color 
    275281               $d_body_bg = imagecreatetruecolor(50,180); 
    276282               $fill = imagecolorallocate($d_body_bg,$body_color[0],$body_color[1],$body_color[2]); 
    277283               imagefill($d_body_bg,0,0,$fill); 
    278                 
     284 
    279285               # User choosed a gradient 
    280286               if ($body_g) { 
     
    284290                    imagedestroy($s_body_bg); 
    285291               } 
    286                 
     292 
    287293               if (!$prelude_color) { 
    288294                    $prelude_color = $default_prelude; 
    289295               } 
    290296               $prelude_color = sscanf($prelude_color,'#%2X%2X%2X'); 
    291                 
     297 
    292298               $s_prelude = imagecreatetruecolor(50,30); 
    293299               $fill = imagecolorallocate($s_prelude,$prelude_color[0],$prelude_color[1],$prelude_color[2]); 
    294300               imagefill($s_prelude,0,0,$fill); 
    295301               imagecopy($d_body_bg,$s_prelude,0,0,0,0,50,30); 
    296                 
     302 
    297303               imagepng($d_body_bg,self::imagesPath().'/'.basename($body_bg)); 
    298304          } 
    299            
     305 
    300306          if ($top_image || $body_color || $gradient != 'light') 
    301307          { 
     
    304310               $size = $size[1]; 
    305311               $type = files::getMimeType($page_t); 
    306                 
     312 
    307313               $d_page_t = imagecreatetruecolor(800,$size); 
    308                 
     314 
    309315               if ($type == 'image/png') { 
    310316                    $s_page_t = @imagecreatefrompng($page_t); 
     
    312318                    $s_page_t = @imagecreatefromjpeg($page_t); 
    313319               } 
    314                 
     320 
    315321               if (!$s_page_t) { 
    316322                    throw new exception(__('Unable to open image.')); 
    317323               } 
    318                 
     324 
    319325               $fill = imagecolorallocate($d_page_t,$body_color[0],$body_color[1],$body_color[2]); 
    320326               imagefill($d_page_t,0,0,$fill); 
    321                 
     327 
    322328               if ($type == 'image/png') 
    323329               { 
     
    331337                    # JPEG, we add image and a frame with rounded corners 
    332338                    imagecopy($d_page_t,$s_page_t,0,0,0,0,800,$size); 
    333                      
     339 
    334340                    imagecopy($d_page_t,$d_body_bg,0,0,0,50,8,4); 
    335341                    imagecopy($d_page_t,$d_body_bg,0,4,0,54,4,4); 
    336342                    imagecopy($d_page_t,$d_body_bg,792,0,0,50,8,4); 
    337343                    imagecopy($d_page_t,$d_body_bg,796,4,0,54,4,4); 
    338                      
     344 
    339345                    $mask = imagecreatefrompng($page_t_mask); 
    340346                    imagealphablending($mask,true); 
    341347                    imagecopy($d_page_t,$mask,0,0,0,0,800,11); 
    342348                    imagedestroy($mask); 
    343                      
     349 
    344350                    $fill = imagecolorallocate($d_page_t,255,255,255); 
    345351                    imagefilledrectangle($d_page_t,0,11,3,$size-1,$fill); 
     
    347353                    imagefilledrectangle($d_page_t,0,$size-9,799,$size-1,$fill); 
    348354               } 
    349                 
     355 
    350356               $config['top_height'] = ($size).'px'; 
    351                 
     357 
    352358               imagepng($d_page_t,self::imagesPath().'/page-t.png'); 
    353                 
     359 
    354360               imagedestroy($d_body_bg); 
    355361               imagedestroy($d_page_t); 
    356362               imagedestroy($s_page_t); 
    357                 
     363 
    358364               # Create bottom image with color 
    359365               $d_page_b = imagecreatetruecolor(800,8); 
    360366               $fill = imagecolorallocate($d_page_b,$body_color[0],$body_color[1],$body_color[2]); 
    361367               imagefill($d_page_b,0,0,$fill); 
    362                 
     368 
    363369               $s_page_b = imagecreatefrompng($page_b); 
    364370               imagealphablending($s_page_b,true); 
    365371               imagecopy($d_page_b,$s_page_b,0,0,0,0,800,160); 
    366                 
     372 
    367373               imagepng($d_page_b,self::imagesPath().'/'.basename($page_b)); 
    368                 
     374 
    369375               imagedestroy($d_page_b); 
    370376               imagedestroy($s_page_b); 
    371377          } 
    372            
     378 
    373379          if ($comment_color) { 
    374380               self::commentImages($comment_color,$comment_t,$comment_b,basename($comment_t),basename($comment_b)); 
     
    378384          } 
    379385     } 
    380       
     386 
    381387     protected static function commentImages($comment_color,$comment_t,$comment_b,$dest_t,$dest_b) 
    382388     { 
    383389          $comment_color = sscanf($comment_color,'#%2X%2X%2X'); 
    384                 
     390 
    385391          $d_comment_t = imagecreatetruecolor(500,25); 
    386392          $fill = imagecolorallocate($d_comment_t,$comment_color[0],$comment_color[1],$comment_color[2]); 
    387393          imagefill($d_comment_t,0,0,$fill); 
    388            
     394 
    389395          $s_comment_t = imagecreatefrompng($comment_t); 
    390396          imagealphablending($s_comment_t,true); 
    391397          imagecopy($d_comment_t,$s_comment_t,0,0,0,0,500,25); 
    392            
     398 
    393399          imagepng($d_comment_t,self::imagesPath().'/'.$dest_t); 
    394400          imagedestroy($d_comment_t); 
    395401          imagedestroy($s_comment_t); 
    396            
     402 
    397403          $d_comment_b = imagecreatetruecolor(500,7); 
    398404          $fill = imagecolorallocate($d_comment_b,$comment_color[0],$comment_color[1],$comment_color[2]); 
    399405          imagefill($d_comment_b,0,0,$fill); 
    400            
     406 
    401407          $s_comment_b = imagecreatefrompng($comment_b); 
    402408          imagealphablending($s_comment_b,true); 
    403409          imagecopy($d_comment_b,$s_comment_b,0,0,0,0,500,7); 
    404            
     410 
    405411          imagepng($d_comment_b,self::imagesPath().'/'.$dest_b); 
    406412          imagedestroy($d_comment_b); 
    407413          imagedestroy($s_comment_b); 
    408414     } 
    409       
     415 
    410416     public static function dropImage($img) 
    411417     { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map