[0] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @brief blowupConfig, a plugin for Dotclear 2 |
---|
| 4 | * |
---|
| 5 | * @package Dotclear |
---|
| 6 | * @subpackage Plugins |
---|
| 7 | * |
---|
| 8 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 9 | * @copyright GPL-2.0-only |
---|
| 10 | */ |
---|
| 11 | |
---|
[3730] | 12 | if (!defined('DC_RC_PATH')) {return;} |
---|
[0] | 13 | |
---|
| 14 | class blowupConfig |
---|
| 15 | { |
---|
[3730] | 16 | protected static $css_folder = 'blowup-css'; |
---|
| 17 | protected static $img_folder = 'blowup-images'; |
---|
[2657] | 18 | |
---|
[3874] | 19 | protected static $fonts = [ |
---|
| 20 | 'sans-serif' => [ |
---|
[3730] | 21 | 'ss1' => 'Arial, Helvetica, sans-serif', |
---|
| 22 | 'ss2' => 'Verdana,Geneva, Arial, Helvetica, sans-serif', |
---|
| 23 | 'ss3' => '"Lucida Grande", "Lucida Sans Unicode", sans-serif', |
---|
| 24 | 'ss4' => '"Trebuchet MS", Helvetica, sans-serif', |
---|
| 25 | 'ss5' => 'Impact, Charcoal, sans-serif' |
---|
[3874] | 26 | ], |
---|
[295] | 27 | |
---|
[3874] | 28 | 'serif' => [ |
---|
[3730] | 29 | 's1' => 'Times, "Times New Roman", serif', |
---|
| 30 | 's2' => 'Georgia, serif', |
---|
| 31 | 's3' => 'Baskerville, "Palatino Linotype", serif' |
---|
[3874] | 32 | ], |
---|
[295] | 33 | |
---|
[3874] | 34 | 'monospace' => [ |
---|
[3730] | 35 | 'm1' => '"Andale Mono", "Courier New", monospace', |
---|
| 36 | 'm2' => '"Courier New", Courier, mono, monospace' |
---|
[3874] | 37 | ] |
---|
| 38 | ]; |
---|
[295] | 39 | |
---|
[3874] | 40 | protected static $fonts_combo = []; |
---|
| 41 | protected static $fonts_list = []; |
---|
[295] | 42 | |
---|
[3874] | 43 | public static $top_images = [ |
---|
[3730] | 44 | 'default' => 'Default', |
---|
| 45 | 'blank' => 'Blank', |
---|
| 46 | 'light-trails-1' => 'Light Trails 1', |
---|
| 47 | 'light-trails-2' => 'Light Trails 2', |
---|
| 48 | 'light-trails-3' => 'Light Trails 3', |
---|
| 49 | 'light-trails-4' => 'Light Trails 4', |
---|
| 50 | 'butterflies' => 'Butterflies', |
---|
| 51 | 'flourish-1' => 'Flourished 1', |
---|
| 52 | 'flourish-2' => 'Flourished 2', |
---|
| 53 | 'animals' => 'Animals', |
---|
| 54 | 'plumetis' => 'Plumetis', |
---|
| 55 | 'flamingo' => 'Flamingo', |
---|
| 56 | 'rabbit' => 'Rabbit', |
---|
| 57 | 'roadrunner-1' => 'Road Runner 1', |
---|
| 58 | 'roadrunner-2' => 'Road Runner 2', |
---|
| 59 | 'typo' => 'Typo' |
---|
[3874] | 60 | ]; |
---|
[295] | 61 | |
---|
[3730] | 62 | public static function fontsList() |
---|
| 63 | { |
---|
| 64 | if (empty(self::$fonts_combo)) { |
---|
| 65 | self::$fonts_combo[__('default')] = ''; |
---|
| 66 | foreach (self::$fonts as $family => $g) { |
---|
[3874] | 67 | $fonts = []; |
---|
[3730] | 68 | foreach ($g as $code => $font) { |
---|
| 69 | $fonts[str_replace('"', '', $font)] = $code; |
---|
| 70 | } |
---|
| 71 | self::$fonts_combo[$family] = $fonts; |
---|
| 72 | } |
---|
| 73 | } |
---|
[295] | 74 | |
---|
[3730] | 75 | return self::$fonts_combo; |
---|
| 76 | } |
---|
[295] | 77 | |
---|
[3730] | 78 | public static function fontDef($c) |
---|
| 79 | { |
---|
| 80 | if (empty(self::$fonts_list)) { |
---|
| 81 | foreach (self::$fonts as $family => $g) { |
---|
| 82 | foreach ($g as $code => $font) { |
---|
| 83 | self::$fonts_list[$code] = $font; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | } |
---|
[295] | 87 | |
---|
[3730] | 88 | return isset(self::$fonts_list[$c]) ? self::$fonts_list[$c] : null; |
---|
| 89 | } |
---|
[295] | 90 | |
---|
[3730] | 91 | public static function cssPath() |
---|
| 92 | { |
---|
| 93 | return dcThemeConfig::cssPath(self::$css_folder); |
---|
| 94 | } |
---|
[1436] | 95 | |
---|
[3730] | 96 | public static function cssURL() |
---|
| 97 | { |
---|
| 98 | return dcThemeConfig::cssURL(self::$css_folder); |
---|
| 99 | } |
---|
[1436] | 100 | |
---|
[3730] | 101 | public static function canWriteCss($create = false) |
---|
| 102 | { |
---|
| 103 | return dcThemeConfig::canWriteCss(self::$css_folder, $create); |
---|
| 104 | } |
---|
[1436] | 105 | |
---|
[3730] | 106 | protected static function backgroundImg(&$css, $selector, $value, $image) |
---|
| 107 | { |
---|
| 108 | dcThemeConfig::backgroundImg(self::$img_folder, $css, $selector, $value, $image); |
---|
| 109 | } |
---|
[1436] | 110 | |
---|
[3730] | 111 | private static function writeCss($theme, $css) |
---|
| 112 | { |
---|
| 113 | dcThemeConfig::writeCSS(self::$css_folder, $theme, $css); |
---|
| 114 | } |
---|
[1436] | 115 | |
---|
[3730] | 116 | public static function dropCss($theme) |
---|
| 117 | { |
---|
| 118 | dcThemeConfig::dropCss(self::$css_folder, $theme); |
---|
| 119 | } |
---|
[1436] | 120 | |
---|
[3730] | 121 | public static function publicCssUrlHelper() |
---|
| 122 | { |
---|
| 123 | return dcThemeConfig::publicCssUrlHelper(self::$css_folder); |
---|
| 124 | } |
---|
[1436] | 125 | |
---|
[3730] | 126 | public static function imagesPath() |
---|
| 127 | { |
---|
| 128 | return dcThemeConfig::imagesPath(self::$img_folder); |
---|
| 129 | } |
---|
[2657] | 130 | |
---|
[3730] | 131 | public static function imagesURL() |
---|
| 132 | { |
---|
| 133 | return dcThemeConfig::imagesURL(self::$img_folder); |
---|
| 134 | } |
---|
[2657] | 135 | |
---|
[3730] | 136 | public static function canWriteImages($create = false) |
---|
| 137 | { |
---|
| 138 | return dcThemeConfig::canWriteImages(self::$img_folder, $create); |
---|
| 139 | } |
---|
[2657] | 140 | |
---|
[3730] | 141 | public static function uploadImage($f) |
---|
| 142 | { |
---|
| 143 | return dcThemeConfig::uploadImage(self::$img_folder, $f, 800); |
---|
| 144 | } |
---|
[2657] | 145 | |
---|
[3730] | 146 | public static function dropImage($img) |
---|
| 147 | { |
---|
| 148 | dcThemeConfig::dropImage(self::$img_folder, $img); |
---|
| 149 | } |
---|
[1436] | 150 | |
---|
[3730] | 151 | public static function createCss($s) |
---|
| 152 | { |
---|
| 153 | global $core; |
---|
[2566] | 154 | |
---|
[3730] | 155 | if ($s === null) { |
---|
| 156 | return; |
---|
| 157 | } |
---|
[1436] | 158 | |
---|
[3874] | 159 | $css = []; |
---|
[1436] | 160 | |
---|
[3730] | 161 | /* Sidebar position |
---|
| 162 | ---------------------------------------------- */ |
---|
| 163 | if ($s['sidebar_position'] == 'left') { |
---|
| 164 | $css['#wrapper']['background-position'] = '-300px 0'; |
---|
| 165 | $css['#main']['float'] = 'right'; |
---|
| 166 | $css['#sidebar']['float'] = 'left'; |
---|
| 167 | } |
---|
[1436] | 168 | |
---|
[3730] | 169 | /* Properties |
---|
| 170 | ---------------------------------------------- */ |
---|
| 171 | dcThemeConfig::prop($css, 'body', 'background-color', $s['body_bg_c']); |
---|
[1436] | 172 | |
---|
[3730] | 173 | dcThemeConfig::prop($css, 'body', 'color', $s['body_txt_c']); |
---|
| 174 | dcThemeConfig::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']); |
---|
| 175 | dcThemeConfig::prop($css, '#page', 'font-size', $s['body_txt_s']); |
---|
| 176 | dcThemeConfig::prop($css, 'body', 'font-family', self::fontDef($s['body_txt_f'])); |
---|
[1436] | 177 | |
---|
[3730] | 178 | dcThemeConfig::prop($css, '.post-content, .post-excerpt, #comments dd, #pings dd, dd.comment-preview', 'line-height', $s['body_line_height']); |
---|
[1436] | 179 | |
---|
[3730] | 180 | if (!$s['blog_title_hide']) { |
---|
| 181 | dcThemeConfig::prop($css, '#top h1 a', 'color', $s['blog_title_c']); |
---|
| 182 | dcThemeConfig::prop($css, '#top h1', 'font-size', $s['blog_title_s']); |
---|
| 183 | dcThemeConfig::prop($css, '#top h1', 'font-family', self::fontDef($s['blog_title_f'])); |
---|
[1436] | 184 | |
---|
[3730] | 185 | if ($s['blog_title_a'] == 'right' || $s['blog_title_a'] == 'left') { |
---|
| 186 | $css['#top h1'][$s['blog_title_a']] = '0px'; |
---|
| 187 | $css['#top h1']['width'] = 'auto'; |
---|
| 188 | } |
---|
[1436] | 189 | |
---|
[3730] | 190 | if ($s['blog_title_p']) { |
---|
| 191 | $_p = explode(':', $s['blog_title_p']); |
---|
| 192 | $css['#top h1']['top'] = $_p[1] . 'px'; |
---|
| 193 | if ($s['blog_title_a'] != 'center') { |
---|
| 194 | $_a = $s['blog_title_a'] == 'right' ? 'right' : 'left'; |
---|
| 195 | $css['#top h1'][$_a] = $_p[0] . 'px'; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | } else { |
---|
| 199 | dcThemeConfig::prop($css, '#top h1 span', 'text-indent', '-5000px'); |
---|
| 200 | dcThemeConfig::prop($css, '#top h1', 'top', '0px'); |
---|
[3874] | 201 | $css['#top h1 a'] = [ |
---|
[3730] | 202 | 'display' => 'block', |
---|
| 203 | 'height' => $s['top_height'] ? ($s['top_height'] - 10) . 'px' : '120px', |
---|
| 204 | 'width' => '800px' |
---|
[3874] | 205 | ]; |
---|
[3730] | 206 | } |
---|
| 207 | dcThemeConfig::prop($css, '#top', 'height', $s['top_height']); |
---|
[1436] | 208 | |
---|
[3730] | 209 | dcThemeConfig::prop($css, '.day-date', 'color', $s['date_title_c']); |
---|
| 210 | dcThemeConfig::prop($css, '.day-date', 'font-family', self::fontDef($s['date_title_f'])); |
---|
| 211 | dcThemeConfig::prop($css, '.day-date', 'font-size', $s['date_title_s']); |
---|
[1436] | 212 | |
---|
[3730] | 213 | dcThemeConfig::prop($css, 'a', 'color', $s['body_link_c']); |
---|
| 214 | dcThemeConfig::prop($css, 'a:visited', 'color', $s['body_link_v_c']); |
---|
| 215 | dcThemeConfig::prop($css, 'a:hover, a:focus, a:active', 'color', $s['body_link_f_c']); |
---|
[1436] | 216 | |
---|
[3730] | 217 | dcThemeConfig::prop($css, '#comment-form input, #comment-form textarea', 'color', $s['body_link_c']); |
---|
| 218 | dcThemeConfig::prop($css, '#comment-form input.preview', 'color', $s['body_link_c']); |
---|
| 219 | dcThemeConfig::prop($css, '#comment-form input.preview:hover', 'background', $s['body_link_f_c']); |
---|
| 220 | dcThemeConfig::prop($css, '#comment-form input.preview:hover', 'border-color', $s['body_link_f_c']); |
---|
| 221 | dcThemeConfig::prop($css, '#comment-form input.submit', 'color', $s['body_link_c']); |
---|
| 222 | dcThemeConfig::prop($css, '#comment-form input.submit:hover', 'background', $s['body_link_f_c']); |
---|
| 223 | dcThemeConfig::prop($css, '#comment-form input.submit:hover', 'border-color', $s['body_link_f_c']); |
---|
[1436] | 224 | |
---|
[3730] | 225 | dcThemeConfig::prop($css, '#sidebar', 'font-family', self::fontDef($s['sidebar_text_f'])); |
---|
| 226 | dcThemeConfig::prop($css, '#sidebar', 'font-size', $s['sidebar_text_s']); |
---|
| 227 | dcThemeConfig::prop($css, '#sidebar', 'color', $s['sidebar_text_c']); |
---|
[1436] | 228 | |
---|
[3730] | 229 | dcThemeConfig::prop($css, '#sidebar h2', 'font-family', self::fontDef($s['sidebar_title_f'])); |
---|
| 230 | dcThemeConfig::prop($css, '#sidebar h2', 'font-size', $s['sidebar_title_s']); |
---|
| 231 | dcThemeConfig::prop($css, '#sidebar h2', 'color', $s['sidebar_title_c']); |
---|
[1436] | 232 | |
---|
[3730] | 233 | dcThemeConfig::prop($css, '#sidebar h3', 'font-family', self::fontDef($s['sidebar_title2_f'])); |
---|
| 234 | dcThemeConfig::prop($css, '#sidebar h3', 'font-size', $s['sidebar_title2_s']); |
---|
| 235 | dcThemeConfig::prop($css, '#sidebar h3', 'color', $s['sidebar_title2_c']); |
---|
[1436] | 236 | |
---|
[3730] | 237 | dcThemeConfig::prop($css, '#sidebar ul', 'border-top-color', $s['sidebar_line_c']); |
---|
| 238 | dcThemeConfig::prop($css, '#sidebar li', 'border-bottom-color', $s['sidebar_line_c']); |
---|
| 239 | dcThemeConfig::prop($css, '#topnav ul', 'border-bottom-color', $s['sidebar_line_c']); |
---|
[1436] | 240 | |
---|
[3730] | 241 | dcThemeConfig::prop($css, '#sidebar li a', 'color', $s['sidebar_link_c']); |
---|
| 242 | dcThemeConfig::prop($css, '#sidebar li a:visited', 'color', $s['sidebar_link_v_c']); |
---|
| 243 | dcThemeConfig::prop($css, '#sidebar li a:hover, #sidebar li a:focus, #sidebar li a:active', 'color', $s['sidebar_link_f_c']); |
---|
| 244 | dcThemeConfig::prop($css, '#search input', 'color', $s['sidebar_link_c']); |
---|
| 245 | dcThemeConfig::prop($css, '#search .submit', 'color', $s['sidebar_link_c']); |
---|
| 246 | dcThemeConfig::prop($css, '#search .submit:hover', 'background', $s['sidebar_link_f_c']); |
---|
| 247 | dcThemeConfig::prop($css, '#search .submit:hover', 'border-color', $s['sidebar_link_f_c']); |
---|
[1436] | 248 | |
---|
[3730] | 249 | dcThemeConfig::prop($css, '.post-title', 'color', $s['post_title_c']); |
---|
| 250 | dcThemeConfig::prop($css, '.post-title a, .post-title a:visited', 'color', $s['post_title_c']); |
---|
| 251 | dcThemeConfig::prop($css, '.post-title', 'font-family', self::fontDef($s['post_title_f'])); |
---|
| 252 | dcThemeConfig::prop($css, '.post-title', 'font-size', $s['post_title_s']); |
---|
[1436] | 253 | |
---|
[3730] | 254 | dcThemeConfig::prop($css, '#comments dd', 'background-color', $s['post_comment_bg_c']); |
---|
| 255 | dcThemeConfig::prop($css, '#comments dd', 'color', $s['post_comment_c']); |
---|
| 256 | dcThemeConfig::prop($css, '#comments dd.me', 'background-color', $s['post_commentmy_bg_c']); |
---|
| 257 | dcThemeConfig::prop($css, '#comments dd.me', 'color', $s['post_commentmy_c']); |
---|
[1436] | 258 | |
---|
[3730] | 259 | dcThemeConfig::prop($css, '#prelude, #prelude a', 'color', $s['prelude_c']); |
---|
[1436] | 260 | |
---|
[3730] | 261 | dcThemeConfig::prop($css, '#footer p', 'background-color', $s['footer_bg_c']); |
---|
| 262 | dcThemeConfig::prop($css, '#footer p', 'color', $s['footer_c']); |
---|
| 263 | dcThemeConfig::prop($css, '#footer p', 'font-size', $s['footer_s']); |
---|
| 264 | dcThemeConfig::prop($css, '#footer p', 'font-family', self::fontDef($s['footer_f'])); |
---|
| 265 | dcThemeConfig::prop($css, '#footer p a', 'color', $s['footer_l_c']); |
---|
[1436] | 266 | |
---|
[3730] | 267 | /* Images |
---|
| 268 | ------------------------------------------------------ */ |
---|
| 269 | self::backgroundImg($css, 'body', $s['body_bg_c'], 'body-bg.png'); |
---|
| 270 | self::backgroundImg($css, 'body', $s['body_bg_g'] != 'light', 'body-bg.png'); |
---|
| 271 | self::backgroundImg($css, 'body', $s['prelude_c'], 'body-bg.png'); |
---|
| 272 | self::backgroundImg($css, '#top', $s['body_bg_c'], 'page-t.png'); |
---|
| 273 | self::backgroundImg($css, '#top', $s['body_bg_g'] != 'light', 'page-t.png'); |
---|
| 274 | self::backgroundImg($css, '#top', $s['uploaded'] || $s['top_image'], 'page-t.png'); |
---|
| 275 | self::backgroundImg($css, '#footer', $s['body_bg_c'], 'page-b.png'); |
---|
| 276 | self::backgroundImg($css, '#comments dt', $s['post_comment_bg_c'], 'comment-t.png'); |
---|
| 277 | self::backgroundImg($css, '#comments dd', $s['post_comment_bg_c'], 'comment-b.png'); |
---|
| 278 | self::backgroundImg($css, '#comments dt.me', $s['post_commentmy_bg_c'], 'commentmy-t.png'); |
---|
| 279 | self::backgroundImg($css, '#comments dd.me', $s['post_commentmy_bg_c'], 'commentmy-b.png'); |
---|
[1436] | 280 | |
---|
[3730] | 281 | $res = ''; |
---|
| 282 | foreach ($css as $selector => $values) { |
---|
| 283 | $res .= $selector . " {\n"; |
---|
| 284 | foreach ($values as $k => $v) { |
---|
| 285 | $res .= $k . ':' . $v . ";\n"; |
---|
| 286 | } |
---|
| 287 | $res .= "}\n"; |
---|
| 288 | } |
---|
[1436] | 289 | |
---|
[3730] | 290 | $res .= $s['extra_css']; |
---|
[1436] | 291 | |
---|
[3730] | 292 | if (!self::canWriteCss(true)) { |
---|
| 293 | throw new Exception(__('Unable to create css file.')); |
---|
| 294 | } |
---|
[1436] | 295 | |
---|
[3730] | 296 | # erase old css file |
---|
| 297 | self::dropCss($core->blog->settings->system->theme); |
---|
[1436] | 298 | |
---|
[3730] | 299 | # create new css file into public blowup-css subdirectory |
---|
| 300 | self::writeCss($core->blog->settings->system->theme, $res); |
---|
[1436] | 301 | |
---|
[3730] | 302 | return $res; |
---|
| 303 | } |
---|
[1436] | 304 | |
---|
[3730] | 305 | public static function createImages(&$config, $uploaded) |
---|
| 306 | { |
---|
| 307 | $body_color = $config['body_bg_c']; |
---|
| 308 | $prelude_color = $config['prelude_c']; |
---|
| 309 | $gradient = $config['body_bg_g']; |
---|
| 310 | $comment_color = $config['post_comment_bg_c']; |
---|
| 311 | $comment_color_my = $config['post_commentmy_bg_c']; |
---|
| 312 | $top_image = $config['top_image']; |
---|
[295] | 313 | |
---|
[3730] | 314 | $config['top_height'] = null; |
---|
[295] | 315 | |
---|
[3730] | 316 | if ($top_image != 'custom' && !isset(self::$top_images[$top_image])) { |
---|
| 317 | $top_image = 'default'; |
---|
| 318 | } |
---|
| 319 | if ($uploaded && !is_file($uploaded)) { |
---|
| 320 | $uploaded = null; |
---|
| 321 | } |
---|
[295] | 322 | |
---|
[3730] | 323 | if (!self::canWriteImages(true)) { |
---|
| 324 | throw new Exception(__('Unable to create images.')); |
---|
| 325 | } |
---|
[295] | 326 | |
---|
[3874] | 327 | $body_fill = [ |
---|
[3730] | 328 | 'light' => dirname(__FILE__) . '/../alpha-img/gradient-l.png', |
---|
| 329 | 'medium' => dirname(__FILE__) . '/../alpha-img/gradient-m.png', |
---|
| 330 | 'dark' => dirname(__FILE__) . '/../alpha-img/gradient-d.png' |
---|
[3874] | 331 | ]; |
---|
[295] | 332 | |
---|
[3730] | 333 | $body_g = isset($body_fill[$gradient]) ? $body_fill[$gradient] : false; |
---|
[295] | 334 | |
---|
[3730] | 335 | if ($top_image == 'custom' && $uploaded) { |
---|
| 336 | $page_t = $uploaded; |
---|
| 337 | } else { |
---|
| 338 | $page_t = dirname(__FILE__) . '/../alpha-img/page-t/' . $top_image . '.png'; |
---|
| 339 | } |
---|
[295] | 340 | |
---|
[3730] | 341 | $body_bg = dirname(__FILE__) . '/../alpha-img/body-bg.png'; |
---|
| 342 | $page_t_mask = dirname(__FILE__) . '/../alpha-img/page-t/image-mask.png'; |
---|
| 343 | $page_b = dirname(__FILE__) . '/../alpha-img/page-b.png'; |
---|
| 344 | $comment_t = dirname(__FILE__) . '/../alpha-img/comment-t.png'; |
---|
| 345 | $comment_b = dirname(__FILE__) . '/../alpha-img/comment-b.png'; |
---|
| 346 | $default_bg = '#e0e0e0'; |
---|
| 347 | $default_prelude = '#ededed'; |
---|
[295] | 348 | |
---|
[3730] | 349 | self::dropImage(basename($body_bg)); |
---|
| 350 | self::dropImage('page-t.png'); |
---|
| 351 | self::dropImage(basename($page_b)); |
---|
| 352 | self::dropImage(basename($comment_t)); |
---|
| 353 | self::dropImage(basename($comment_b)); |
---|
[295] | 354 | |
---|
[3730] | 355 | $body_color = dcThemeConfig::adjustColor($body_color); |
---|
| 356 | $prelude_color = dcThemeConfig::adjustColor($prelude_color); |
---|
| 357 | $comment_color = dcThemeConfig::adjustColor($comment_color); |
---|
[295] | 358 | |
---|
[3730] | 359 | if ($top_image || $body_color || $gradient != 'light' || $prelude_color || $uploaded) { |
---|
| 360 | if (!$body_color) { |
---|
| 361 | $body_color = $default_bg; |
---|
| 362 | } |
---|
| 363 | $body_color = sscanf($body_color, '#%2X%2X%2X'); |
---|
[295] | 364 | |
---|
[3730] | 365 | # Create body gradient with color |
---|
| 366 | $d_body_bg = imagecreatetruecolor(50, 180); |
---|
| 367 | $fill = imagecolorallocate($d_body_bg, $body_color[0], $body_color[1], $body_color[2]); |
---|
| 368 | imagefill($d_body_bg, 0, 0, $fill); |
---|
[295] | 369 | |
---|
[3730] | 370 | # User choosed a gradient |
---|
| 371 | if ($body_g) { |
---|
| 372 | $s_body_bg = imagecreatefrompng($body_g); |
---|
| 373 | imagealphablending($s_body_bg, true); |
---|
| 374 | imagecopy($d_body_bg, $s_body_bg, 0, 0, 0, 0, 50, 180); |
---|
| 375 | imagedestroy($s_body_bg); |
---|
| 376 | } |
---|
[295] | 377 | |
---|
[3730] | 378 | if (!$prelude_color) { |
---|
| 379 | $prelude_color = $default_prelude; |
---|
| 380 | } |
---|
| 381 | $prelude_color = sscanf($prelude_color, '#%2X%2X%2X'); |
---|
[295] | 382 | |
---|
[3730] | 383 | $s_prelude = imagecreatetruecolor(50, 30); |
---|
| 384 | $fill = imagecolorallocate($s_prelude, $prelude_color[0], $prelude_color[1], $prelude_color[2]); |
---|
| 385 | imagefill($s_prelude, 0, 0, $fill); |
---|
| 386 | imagecopy($d_body_bg, $s_prelude, 0, 0, 0, 0, 50, 30); |
---|
[295] | 387 | |
---|
[3730] | 388 | imagepng($d_body_bg, self::imagesPath() . '/' . basename($body_bg)); |
---|
| 389 | } |
---|
[295] | 390 | |
---|
[3730] | 391 | if ($top_image || $body_color || $gradient != 'light') { |
---|
| 392 | # Create top image from uploaded image |
---|
| 393 | $size = getimagesize($page_t); |
---|
| 394 | $size = $size[1]; |
---|
| 395 | $type = files::getMimeType($page_t); |
---|
[295] | 396 | |
---|
[3730] | 397 | $d_page_t = imagecreatetruecolor(800, $size); |
---|
[295] | 398 | |
---|
[3730] | 399 | if ($type == 'image/png') { |
---|
| 400 | $s_page_t = @imagecreatefrompng($page_t); |
---|
| 401 | } else { |
---|
| 402 | $s_page_t = @imagecreatefromjpeg($page_t); |
---|
| 403 | } |
---|
[295] | 404 | |
---|
[3730] | 405 | if (!$s_page_t) { |
---|
| 406 | throw new exception(__('Unable to open image.')); |
---|
| 407 | } |
---|
[295] | 408 | |
---|
[3730] | 409 | $fill = imagecolorallocate($d_page_t, $body_color[0], $body_color[1], $body_color[2]); |
---|
| 410 | imagefill($d_page_t, 0, 0, $fill); |
---|
[295] | 411 | |
---|
[3730] | 412 | if ($type == 'image/png') { |
---|
| 413 | # PNG, we only add body gradient and image |
---|
| 414 | imagealphablending($s_page_t, true); |
---|
| 415 | imagecopyresized($d_page_t, $d_body_bg, 0, 0, 0, 50, 800, 130, 50, 130); |
---|
| 416 | imagecopy($d_page_t, $s_page_t, 0, 0, 0, 0, 800, $size); |
---|
| 417 | } else { |
---|
| 418 | # JPEG, we add image and a frame with rounded corners |
---|
| 419 | imagecopy($d_page_t, $s_page_t, 0, 0, 0, 0, 800, $size); |
---|
[295] | 420 | |
---|
[3730] | 421 | imagecopy($d_page_t, $d_body_bg, 0, 0, 0, 50, 8, 4); |
---|
| 422 | imagecopy($d_page_t, $d_body_bg, 0, 4, 0, 54, 4, 4); |
---|
| 423 | imagecopy($d_page_t, $d_body_bg, 792, 0, 0, 50, 8, 4); |
---|
| 424 | imagecopy($d_page_t, $d_body_bg, 796, 4, 0, 54, 4, 4); |
---|
[295] | 425 | |
---|
[3730] | 426 | $mask = imagecreatefrompng($page_t_mask); |
---|
| 427 | imagealphablending($mask, true); |
---|
| 428 | imagecopy($d_page_t, $mask, 0, 0, 0, 0, 800, 11); |
---|
| 429 | imagedestroy($mask); |
---|
[295] | 430 | |
---|
[3730] | 431 | $fill = imagecolorallocate($d_page_t, 255, 255, 255); |
---|
| 432 | imagefilledrectangle($d_page_t, 0, 11, 3, $size - 1, $fill); |
---|
| 433 | imagefilledrectangle($d_page_t, 796, 11, 799, $size - 1, $fill); |
---|
| 434 | imagefilledrectangle($d_page_t, 0, $size - 9, 799, $size - 1, $fill); |
---|
| 435 | } |
---|
[295] | 436 | |
---|
[3730] | 437 | $config['top_height'] = ($size) . 'px'; |
---|
[295] | 438 | |
---|
[3730] | 439 | imagepng($d_page_t, self::imagesPath() . '/page-t.png'); |
---|
[295] | 440 | |
---|
[3730] | 441 | imagedestroy($d_body_bg); |
---|
| 442 | imagedestroy($d_page_t); |
---|
| 443 | imagedestroy($s_page_t); |
---|
[295] | 444 | |
---|
[3730] | 445 | # Create bottom image with color |
---|
| 446 | $d_page_b = imagecreatetruecolor(800, 8); |
---|
| 447 | $fill = imagecolorallocate($d_page_b, $body_color[0], $body_color[1], $body_color[2]); |
---|
| 448 | imagefill($d_page_b, 0, 0, $fill); |
---|
[295] | 449 | |
---|
[3730] | 450 | $s_page_b = imagecreatefrompng($page_b); |
---|
| 451 | imagealphablending($s_page_b, true); |
---|
| 452 | imagecopy($d_page_b, $s_page_b, 0, 0, 0, 0, 800, 160); |
---|
[295] | 453 | |
---|
[3730] | 454 | imagepng($d_page_b, self::imagesPath() . '/' . basename($page_b)); |
---|
[295] | 455 | |
---|
[3730] | 456 | imagedestroy($d_page_b); |
---|
| 457 | imagedestroy($s_page_b); |
---|
| 458 | } |
---|
[295] | 459 | |
---|
[3730] | 460 | if ($comment_color) { |
---|
| 461 | self::commentImages($comment_color, $comment_t, $comment_b, basename($comment_t), basename($comment_b)); |
---|
| 462 | } |
---|
| 463 | if ($comment_color_my) { |
---|
| 464 | self::commentImages($comment_color_my, $comment_t, $comment_b, 'commentmy-t.png', 'commentmy-b.png'); |
---|
| 465 | } |
---|
| 466 | } |
---|
[295] | 467 | |
---|
[3730] | 468 | protected static function commentImages($comment_color, $comment_t, $comment_b, $dest_t, $dest_b) |
---|
| 469 | { |
---|
| 470 | $comment_color = sscanf($comment_color, '#%2X%2X%2X'); |
---|
[295] | 471 | |
---|
[3730] | 472 | $d_comment_t = imagecreatetruecolor(500, 25); |
---|
| 473 | $fill = imagecolorallocate($d_comment_t, $comment_color[0], $comment_color[1], $comment_color[2]); |
---|
| 474 | imagefill($d_comment_t, 0, 0, $fill); |
---|
[295] | 475 | |
---|
[3730] | 476 | $s_comment_t = imagecreatefrompng($comment_t); |
---|
| 477 | imagealphablending($s_comment_t, true); |
---|
| 478 | imagecopy($d_comment_t, $s_comment_t, 0, 0, 0, 0, 500, 25); |
---|
[295] | 479 | |
---|
[3730] | 480 | imagepng($d_comment_t, self::imagesPath() . '/' . $dest_t); |
---|
| 481 | imagedestroy($d_comment_t); |
---|
| 482 | imagedestroy($s_comment_t); |
---|
[295] | 483 | |
---|
[3730] | 484 | $d_comment_b = imagecreatetruecolor(500, 7); |
---|
| 485 | $fill = imagecolorallocate($d_comment_b, $comment_color[0], $comment_color[1], $comment_color[2]); |
---|
| 486 | imagefill($d_comment_b, 0, 0, $fill); |
---|
[295] | 487 | |
---|
[3730] | 488 | $s_comment_b = imagecreatefrompng($comment_b); |
---|
| 489 | imagealphablending($s_comment_b, true); |
---|
| 490 | imagecopy($d_comment_b, $s_comment_b, 0, 0, 0, 0, 500, 7); |
---|
[295] | 491 | |
---|
[3730] | 492 | imagepng($d_comment_b, self::imagesPath() . '/' . $dest_b); |
---|
| 493 | imagedestroy($d_comment_b); |
---|
| 494 | imagedestroy($s_comment_b); |
---|
| 495 | } |
---|
[295] | 496 | |
---|
[0] | 497 | } |
---|