- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/blowupConfig/lib/class.blowup.config.php
- Property exe set to *
r270 r295 22 22 'ss5' => 'Impact, Charcoal, sans-serif' 23 23 ), 24 24 25 25 'serif' => array( 26 26 's1' => 'Times, "Times New Roman", serif', … … 28 28 's3' => 'Baskerville, "Palatino Linotype", serif' 29 29 ), 30 30 31 31 'monospace' => array( 32 32 'm1' => '"Andale Mono", "Courier New", monospace', … … 34 34 ) 35 35 ); 36 36 37 37 protected static $fonts_combo = array(); 38 38 protected static $fonts_list = array(); 39 39 40 40 public static $top_images = array( 41 41 'default' => 'Default', … … 55 55 'typo' => 'Typo', 56 56 ); 57 57 58 58 public static function fontsList() 59 59 { … … 70 70 } 71 71 } 72 72 73 73 return self::$fonts_combo; 74 74 } 75 75 76 76 public static function fontDef($c) 77 77 { … … 85 85 } 86 86 } 87 87 88 88 return isset(self::$fonts_list[$c]) ? self::$fonts_list[$c] : null; 89 89 } 90 90 91 91 public static function adjustFontSize($s) 92 92 { … … 97 97 return $m[1].$m[2]; 98 98 } 99 99 100 100 return null; 101 101 } 102 102 103 103 public static function adjustPosition($p) 104 104 { … … 106 106 return null; 107 107 } 108 108 109 109 $p = explode(':',$p); 110 110 111 111 return $p[0].(count($p) == 1 ? ':0' : ':'.$p[1]); 112 112 } 113 113 114 114 public static function adjustColor($c) 115 115 { … … 117 117 return ''; 118 118 } 119 119 120 120 $c = strtoupper($c); 121 121 122 122 if (preg_match('/^[A-F0-9]{3,6}$/',$c)) { 123 123 $c = '#'.$c; 124 124 } 125 125 126 126 if (preg_match('/^#[A-F0-9]{6}$/',$c)) { 127 127 return $c; 128 128 } 129 129 130 130 if (preg_match('/^#[A-F0-9]{3,}$/',$c)) { 131 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 132 } 133 133 134 134 return ''; 135 135 } 136 136 137 public static function cleanCSS($css) 138 { 139 // TODO ? 140 return $css; 141 } 142 137 143 public static function imagesPath() 138 144 { … … 140 146 return path::real($core->blog->public_path).'/blowup-images'; 141 147 } 142 148 143 149 public static function imagesURL() 144 150 { … … 146 152 return $core->blog->settings->system->public_url.'/blowup-images'; 147 153 } 148 154 149 155 public static function canWriteImages($create=false) 150 156 { 151 157 global $core; 152 158 153 159 $public = path::real($core->blog->public_path); 154 160 $imgs = self::imagesPath(); 155 161 156 162 if (!function_exists('imagecreatetruecolor') || !function_exists('imagepng') || !function_exists('imagecreatefrompng')) { 157 163 $core->error->add(__('At least one of the following functions is not available: '. … … 159 165 return false; 160 166 } 161 167 162 168 if (!is_dir($public)) { 163 169 $core->error->add(__('The \'public\' directory does not exist.')); 164 170 return false; 165 171 } 166 172 167 173 if (!is_dir($imgs)) { 168 174 if (!is_writable($public)) { … … 175 181 return true; 176 182 } 177 183 178 184 if (!is_writable($imgs)) { 179 185 $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public/blowup-images')); 180 186 return false; 181 187 } 182 188 183 189 return true; 184 190 } 185 191 186 192 public static function uploadImage($f) 187 193 { … … 189 195 throw new Exception(__('Unable to create images.')); 190 196 } 191 197 192 198 $name = $f['name']; 193 199 $type = files::getMimeType($name); 194 200 195 201 if ($type != 'image/jpeg' && $type != 'image/png') { 196 202 throw new Exception(__('Invalid file type.')); 197 203 } 198 204 199 205 $dest = self::imagesPath().'/uploaded'.($type == 'image/png' ? '.png' : '.jpg'); 200 206 201 207 if (@move_uploaded_file($f['tmp_name'],$dest) === false) { 202 208 throw new Exception(__('An error occurred while writing the file.')); 203 209 } 204 210 205 211 $s = getimagesize($dest); 206 212 if ($s[0] != 800) { 207 213 throw new Exception(__('Uploaded image is not 800 pixels wide.')); 208 214 } 209 215 210 216 return $dest; 211 217 } 212 218 213 219 public static function createImages(&$config,$uploaded) 214 220 { … … 219 225 $comment_color_my = $config['post_commentmy_bg_c']; 220 226 $top_image = $config['top_image']; 221 227 222 228 $config['top_height'] = null; 223 229 224 230 if ($top_image != 'custom' && !isset(self::$top_images[$top_image])) { 225 231 $top_image = 'default'; … … 228 234 $uploaded = null; 229 235 } 230 236 231 237 if (!self::canWriteImages(true)) { 232 238 throw new Exception(__('Unable to create images.')); 233 239 } 234 240 235 241 $body_fill = array( 236 242 'light' => dirname(__FILE__).'/../alpha-img/gradient-l.png', … … 238 244 'dark' => dirname(__FILE__).'/../alpha-img/gradient-d.png' 239 245 ); 240 246 241 247 $body_g = isset($body_fill[$gradient]) ? $body_fill[$gradient] : false; 242 248 243 249 if ($top_image == 'custom' && $uploaded) { 244 250 $page_t = $uploaded; … … 246 252 $page_t = dirname(__FILE__).'/../alpha-img/page-t/'.$top_image.'.png'; 247 253 } 248 254 249 255 $body_bg = dirname(__FILE__).'/../alpha-img/body-bg.png'; 250 256 $page_t_mask = dirname(__FILE__).'/../alpha-img/page-t/image-mask.png'; … … 254 260 $default_bg = '#e0e0e0'; 255 261 $default_prelude = '#ededed'; 256 262 257 263 self::dropImage(basename($body_bg)); 258 264 self::dropImage('page-t.png'); … … 260 266 self::dropImage(basename($comment_t)); 261 267 self::dropImage(basename($comment_b)); 262 268 263 269 $body_color = self::adjustColor($body_color); 264 270 $prelude_color = self::adjustColor($prelude_color); 265 271 $comment_color = self::adjustColor($comment_color); 266 272 267 273 if ($top_image || $body_color || $gradient != 'light' || $prelude_color || $uploaded) 268 274 { … … 271 277 } 272 278 $body_color = sscanf($body_color,'#%2X%2X%2X'); 273 279 274 280 # Create body gradient with color 275 281 $d_body_bg = imagecreatetruecolor(50,180); 276 282 $fill = imagecolorallocate($d_body_bg,$body_color[0],$body_color[1],$body_color[2]); 277 283 imagefill($d_body_bg,0,0,$fill); 278 284 279 285 # User choosed a gradient 280 286 if ($body_g) { … … 284 290 imagedestroy($s_body_bg); 285 291 } 286 292 287 293 if (!$prelude_color) { 288 294 $prelude_color = $default_prelude; 289 295 } 290 296 $prelude_color = sscanf($prelude_color,'#%2X%2X%2X'); 291 297 292 298 $s_prelude = imagecreatetruecolor(50,30); 293 299 $fill = imagecolorallocate($s_prelude,$prelude_color[0],$prelude_color[1],$prelude_color[2]); 294 300 imagefill($s_prelude,0,0,$fill); 295 301 imagecopy($d_body_bg,$s_prelude,0,0,0,0,50,30); 296 302 297 303 imagepng($d_body_bg,self::imagesPath().'/'.basename($body_bg)); 298 304 } 299 305 300 306 if ($top_image || $body_color || $gradient != 'light') 301 307 { … … 304 310 $size = $size[1]; 305 311 $type = files::getMimeType($page_t); 306 312 307 313 $d_page_t = imagecreatetruecolor(800,$size); 308 314 309 315 if ($type == 'image/png') { 310 316 $s_page_t = @imagecreatefrompng($page_t); … … 312 318 $s_page_t = @imagecreatefromjpeg($page_t); 313 319 } 314 320 315 321 if (!$s_page_t) { 316 322 throw new exception(__('Unable to open image.')); 317 323 } 318 324 319 325 $fill = imagecolorallocate($d_page_t,$body_color[0],$body_color[1],$body_color[2]); 320 326 imagefill($d_page_t,0,0,$fill); 321 327 322 328 if ($type == 'image/png') 323 329 { … … 331 337 # JPEG, we add image and a frame with rounded corners 332 338 imagecopy($d_page_t,$s_page_t,0,0,0,0,800,$size); 333 339 334 340 imagecopy($d_page_t,$d_body_bg,0,0,0,50,8,4); 335 341 imagecopy($d_page_t,$d_body_bg,0,4,0,54,4,4); 336 342 imagecopy($d_page_t,$d_body_bg,792,0,0,50,8,4); 337 343 imagecopy($d_page_t,$d_body_bg,796,4,0,54,4,4); 338 344 339 345 $mask = imagecreatefrompng($page_t_mask); 340 346 imagealphablending($mask,true); 341 347 imagecopy($d_page_t,$mask,0,0,0,0,800,11); 342 348 imagedestroy($mask); 343 349 344 350 $fill = imagecolorallocate($d_page_t,255,255,255); 345 351 imagefilledrectangle($d_page_t,0,11,3,$size-1,$fill); … … 347 353 imagefilledrectangle($d_page_t,0,$size-9,799,$size-1,$fill); 348 354 } 349 355 350 356 $config['top_height'] = ($size).'px'; 351 357 352 358 imagepng($d_page_t,self::imagesPath().'/page-t.png'); 353 359 354 360 imagedestroy($d_body_bg); 355 361 imagedestroy($d_page_t); 356 362 imagedestroy($s_page_t); 357 363 358 364 # Create bottom image with color 359 365 $d_page_b = imagecreatetruecolor(800,8); 360 366 $fill = imagecolorallocate($d_page_b,$body_color[0],$body_color[1],$body_color[2]); 361 367 imagefill($d_page_b,0,0,$fill); 362 368 363 369 $s_page_b = imagecreatefrompng($page_b); 364 370 imagealphablending($s_page_b,true); 365 371 imagecopy($d_page_b,$s_page_b,0,0,0,0,800,160); 366 372 367 373 imagepng($d_page_b,self::imagesPath().'/'.basename($page_b)); 368 374 369 375 imagedestroy($d_page_b); 370 376 imagedestroy($s_page_b); 371 377 } 372 378 373 379 if ($comment_color) { 374 380 self::commentImages($comment_color,$comment_t,$comment_b,basename($comment_t),basename($comment_b)); … … 378 384 } 379 385 } 380 386 381 387 protected static function commentImages($comment_color,$comment_t,$comment_b,$dest_t,$dest_b) 382 388 { 383 389 $comment_color = sscanf($comment_color,'#%2X%2X%2X'); 384 390 385 391 $d_comment_t = imagecreatetruecolor(500,25); 386 392 $fill = imagecolorallocate($d_comment_t,$comment_color[0],$comment_color[1],$comment_color[2]); 387 393 imagefill($d_comment_t,0,0,$fill); 388 394 389 395 $s_comment_t = imagecreatefrompng($comment_t); 390 396 imagealphablending($s_comment_t,true); 391 397 imagecopy($d_comment_t,$s_comment_t,0,0,0,0,500,25); 392 398 393 399 imagepng($d_comment_t,self::imagesPath().'/'.$dest_t); 394 400 imagedestroy($d_comment_t); 395 401 imagedestroy($s_comment_t); 396 402 397 403 $d_comment_b = imagecreatetruecolor(500,7); 398 404 $fill = imagecolorallocate($d_comment_b,$comment_color[0],$comment_color[1],$comment_color[2]); 399 405 imagefill($d_comment_b,0,0,$fill); 400 406 401 407 $s_comment_b = imagecreatefrompng($comment_b); 402 408 imagealphablending($s_comment_b,true); 403 409 imagecopy($d_comment_b,$s_comment_b,0,0,0,0,500,7); 404 410 405 411 imagepng($d_comment_b,self::imagesPath().'/'.$dest_b); 406 412 imagedestroy($d_comment_b); 407 413 imagedestroy($s_comment_b); 408 414 } 409 415 410 416 public static function dropImage($img) 411 417 {
Note: See TracChangeset
for help on using the changeset viewer.