Changeset 2658:0686a9a71a3f for themes
- Timestamp:
- 02/13/14 14:13:01 (11 years ago)
- Branch:
- default
- Location:
- themes/ductile
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
themes/ductile/_config.php
r2581 r2658 78 78 ); 79 79 80 function adjustFontSize($s)81 {82 if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex)?$/',$s,$m)) {83 if (empty($m[2])) {84 $m[2] = 'em';85 }86 return $m[1].$m[2];87 }88 89 return null;90 }91 92 80 $font_families = array( 93 81 // Theme standard … … 117 105 118 106 return isset($font_families[$c]) ? '<span style="position:absolute;top:0;left:32em;">'.$font_families[$c].'</span>' : ''; 119 }120 121 function adjustColor($c)122 {123 if ($c === '') {124 return '';125 }126 127 $c = strtoupper($c);128 129 if (preg_match('/^[A-F0-9]{3,6}$/',$c)) {130 $c = '#'.$c;131 }132 133 if (preg_match('/^#[A-F0-9]{6}$/',$c)) {134 return $c;135 }136 137 if (preg_match('/^#[A-F0-9]{3,}$/',$c)) {138 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);139 }140 141 return '';142 }143 144 function computeContrastRatio($color,$background)145 {146 // Compute contrast ratio between two colors147 148 $color = adjustColor($color);149 if (($color == '') || (strlen($color) != 7)) return 0;150 $background = adjustColor($background);151 if (($background == '') || (strlen($background) != 7)) return 0;152 153 $l1 = (0.2126 * pow(hexdec(substr($color,1,2))/255,2.2)) +154 (0.7152 * pow(hexdec(substr($color,3,2))/255,2.2)) +155 (0.0722 * pow(hexdec(substr($color,5,2))/255,2.2));156 157 $l2 = (0.2126 * pow(hexdec(substr($background,1,2))/255,2.2)) +158 (0.7152 * pow(hexdec(substr($background,3,2))/255,2.2)) +159 (0.0722 * pow(hexdec(substr($background,5,2))/255,2.2));160 161 if ($l1 > $l2) {162 $ratio = ($l1 + 0.05) / ($l2 + 0.05);163 } else {164 $ratio = ($l2 + 0.05) / ($l1 + 0.05);165 }166 return $ratio;167 }168 169 function contrastRatioLevel($ratio,$size,$bold)170 {171 if ($size == '') {172 return '';173 }174 175 // Eval font size in em (assume base font size in pixels equal to 16)176 if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex)?$/',$size,$m)) {177 if (empty($m[2])) {178 $m[2] = 'em';179 }180 } else {181 return '';182 }183 switch ($m[2]) {184 case '%':185 $s = (float) $m[1] / 100;186 break;187 case 'pt':188 $s = (float) $m[1] / 12;189 break;190 case 'px':191 $s = (float) $m[1] / 16;192 break;193 case 'em':194 $s = (float) $m[1];195 break;196 case 'ex':197 $s = (float) $m[1] / 2;198 break;199 default:200 return '';201 }202 203 $large = ((($s > 1.5) && ($bold == false)) || (($s > 1.2) && ($bold == true)));204 205 // Check ratio206 if ($ratio > 7) {207 return 'AAA';208 } elseif (($ratio > 4.5) && $large) {209 return 'AAA';210 } elseif ($ratio > 4.5) {211 return 'AA';212 } elseif (($ratio > 3) && $large) {213 return 'AA';214 }215 return '';216 }217 218 function contrastRatio($color,$background,$size='',$bold=false)219 {220 if (($color != '') && ($background != '')) {221 $ratio = computeContrastRatio($color,$background);222 $level = contrastRatioLevel($ratio,$size,$bold);223 return224 '<span style="position:absolute;top:0;left:23em;">'.225 sprintf(__('ratio %.1f'),$ratio).226 ($level != '' ? ' '.sprintf(__('(%s)'),$level) : '').227 '</span>';228 }229 return '';230 107 } 231 108 … … 398 275 399 276 $ductile_user['blog_title_w'] = (integer) !empty($_POST['blog_title_w']); 400 $ductile_user['blog_title_s'] = adjustFontSize($_POST['blog_title_s']);401 $ductile_user['blog_title_c'] = adjustColor($_POST['blog_title_c']);277 $ductile_user['blog_title_s'] = dcThemeConfig::adjustFontSize($_POST['blog_title_s']); 278 $ductile_user['blog_title_c'] = dcThemeConfig::adjustColor($_POST['blog_title_c']); 402 279 403 280 $ductile_user['post_title_w'] = (integer) !empty($_POST['post_title_w']); 404 $ductile_user['post_title_s'] = adjustFontSize($_POST['post_title_s']);405 $ductile_user['post_title_c'] = adjustColor($_POST['post_title_c']);281 $ductile_user['post_title_s'] = dcThemeConfig::adjustFontSize($_POST['post_title_s']); 282 $ductile_user['post_title_c'] = dcThemeConfig::adjustColor($_POST['post_title_c']); 406 283 407 284 $ductile_user['post_link_w'] = (integer) !empty($_POST['post_link_w']); 408 $ductile_user['post_link_v_c'] = adjustColor($_POST['post_link_v_c']);409 $ductile_user['post_link_f_c'] = adjustColor($_POST['post_link_f_c']);410 411 $ductile_user['post_simple_title_c'] = adjustColor($_POST['post_simple_title_c']);285 $ductile_user['post_link_v_c'] = dcThemeConfig::adjustColor($_POST['post_link_v_c']); 286 $ductile_user['post_link_f_c'] = dcThemeConfig::adjustColor($_POST['post_link_f_c']); 287 288 $ductile_user['post_simple_title_c'] = dcThemeConfig::adjustColor($_POST['post_simple_title_c']); 412 289 413 290 $ductile_user['blog_title_w_m'] = (integer) !empty($_POST['blog_title_w_m']); 414 $ductile_user['blog_title_s_m'] = adjustFontSize($_POST['blog_title_s_m']);415 $ductile_user['blog_title_c_m'] = adjustColor($_POST['blog_title_c_m']);291 $ductile_user['blog_title_s_m'] = dcThemeConfig::adjustFontSize($_POST['blog_title_s_m']); 292 $ductile_user['blog_title_c_m'] = dcThemeConfig::adjustColor($_POST['blog_title_c_m']); 416 293 417 294 $ductile_user['post_title_w_m'] = (integer) !empty($_POST['post_title_w_m']); 418 $ductile_user['post_title_s_m'] = adjustFontSize($_POST['post_title_s_m']);419 $ductile_user['post_title_c_m'] = adjustColor($_POST['post_title_c_m']);295 $ductile_user['post_title_s_m'] = dcThemeConfig::adjustFontSize($_POST['post_title_s_m']); 296 $ductile_user['post_title_c_m'] = dcThemeConfig::adjustColor($_POST['post_title_c_m']); 420 297 } 421 298 … … 583 460 '<p class="field picker"><label for="blog_title_c">'.__('Color:').'</label> '. 584 461 form::field('blog_title_c',7,7,$ductile_user['blog_title_c'],'colorpicker'). 585 contrastRatio($ductile_user['blog_title_c'],'#ffffff',462 dcThemeConfig::contrastRatio($ductile_user['blog_title_c'],'#ffffff', 586 463 (!empty($ductile_user['blog_title_s']) ? $ductile_user['blog_title_s'] : '2em'), 587 464 $ductile_user['blog_title_w']). … … 600 477 '<p class="field picker"><label for="post_title_c">'.__('Color:').'</label> '. 601 478 form::field('post_title_c',7,7,$ductile_user['post_title_c'],'colorpicker'). 602 contrastRatio($ductile_user['post_title_c'],'#ffffff',479 dcThemeConfig::contrastRatio($ductile_user['post_title_c'],'#ffffff', 603 480 (!empty($ductile_user['post_title_s']) ? $ductile_user['post_title_s'] : '2.5em'), 604 481 $ductile_user['post_title_w']). … … 612 489 '<p class="field picker"><label for="post_simple_title_c">'.__('Color:').'</label> '. 613 490 form::field('post_simple_title_c',7,7,$ductile_user['post_simple_title_c'],'colorpicker'). 614 contrastRatio($ductile_user['post_simple_title_c'],'#ffffff',491 dcThemeConfig::contrastRatio($ductile_user['post_simple_title_c'],'#ffffff', 615 492 '1.1em', // H5 minimum size 616 493 false). … … 623 500 '<p class="field picker"><label for="post_link_v_c">'.__('Normal and visited links color:').'</label> '. 624 501 form::field('post_link_v_c',7,7,$ductile_user['post_link_v_c'],'colorpicker'). 625 contrastRatio($ductile_user['post_link_v_c'],'#ffffff',502 dcThemeConfig::contrastRatio($ductile_user['post_link_v_c'],'#ffffff', 626 503 '1em', 627 504 $ductile_user['post_link_w']). … … 630 507 '<p class="field picker"><label for="post_link_f_c">'.__('Active, hover and focus links color:').'</label> '. 631 508 form::field('post_link_f_c',7,7,$ductile_user['post_link_f_c'],'colorpicker'). 632 contrastRatio($ductile_user['post_link_f_c'],'#ebebee',509 dcThemeConfig::contrastRatio($ductile_user['post_link_f_c'],'#ebebee', 633 510 '1em', 634 511 $ductile_user['post_link_w']). … … 649 526 '<p class="field picker"><label for="blog_title_c_m">'.__('Color:').'</label> '. 650 527 form::field('blog_title_c_m',7,7,$ductile_user['blog_title_c_m'],'colorpicker'). 651 contrastRatio($ductile_user['blog_title_c_m'],'#d7d7dc',528 dcThemeConfig::contrastRatio($ductile_user['blog_title_c_m'],'#d7d7dc', 652 529 (!empty($ductile_user['blog_title_s_m']) ? $ductile_user['blog_title_s_m'] : '1.8em'), 653 530 $ductile_user['blog_title_w_m']). … … 666 543 '<p class="field picker"><label for="post_title_c_m">'.__('Color:').'</label> '. 667 544 form::field('post_title_c_m',7,7,$ductile_user['post_title_c_m'],'colorpicker'). 668 contrastRatio($ductile_user['post_title_c_m'],'#ffffff',545 dcThemeConfig::contrastRatio($ductile_user['post_title_c_m'],'#ffffff', 669 546 (!empty($ductile_user['post_title_s_m']) ? $ductile_user['post_title_s_m'] : '1.5em'), 670 547 $ductile_user['post_title_w_m']). -
themes/ductile/_public.php
r2581 r2658 314 314 # Main font 315 315 $selectors = 'body, .supranav li a span, #comments.me, a.comment-number'; 316 self::prop($css,$selectors,'font-family',$s['body_webfont_family']);316 dcThemeConfig::prop($css,$selectors,'font-family',$s['body_webfont_family']); 317 317 } 318 318 } … … 332 332 # Secondary font 333 333 $selectors = '#blogdesc, .supranav, #content-info, #subcategories, #comments-feed, #sidebar h2, #sidebar h3, #footer'; 334 self::prop($css,$selectors,'font-family',$s['alternate_webfont_family']);334 dcThemeConfig::prop($css,$selectors,'font-family',$s['alternate_webfont_family']); 335 335 } 336 336 } … … 370 370 # Blog description 371 371 $selectors = '#blogdesc'; 372 if (isset($s['subtitle_hidden'])) self::prop($css,$selectors,'display',($s['subtitle_hidden'] ? 'none' : null));372 if (isset($s['subtitle_hidden'])) dcThemeConfig::prop($css,$selectors,'display',($s['subtitle_hidden'] ? 'none' : null)); 373 373 374 374 # Main font 375 375 $selectors = 'body, .supranav li a span, #comments.me, a.comment-number'; 376 if (isset($s['body_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['body_font']));376 if (isset($s['body_font'])) dcThemeConfig::prop($css,$selectors,'font-family',self::fontDef($s['body_font'])); 377 377 378 378 # Secondary font 379 379 $selectors = '#blogdesc, .supranav, #content-info, #subcategories, #comments-feed, #sidebar h2, #sidebar h3, #footer'; 380 if (isset($s['alternate_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['alternate_font']));380 if (isset($s['alternate_font'])) dcThemeConfig::prop($css,$selectors,'font-family',self::fontDef($s['alternate_font'])); 381 381 382 382 # Inside posts links font weight 383 383 $selectors = '.post-excerpt a, .post-content a'; 384 if (isset($s['post_link_w'])) self::prop($css,$selectors,'font-weight',($s['post_link_w'] ? 'bold' : 'normal'));384 if (isset($s['post_link_w'])) dcThemeConfig::prop($css,$selectors,'font-weight',($s['post_link_w'] ? 'bold' : 'normal')); 385 385 386 386 # Inside posts links colors (normal, visited) 387 387 $selectors = '.post-excerpt a:link, .post-excerpt a:visited, .post-content a:link, .post-content a:visited'; 388 if (isset($s['post_link_v_c'])) self::prop($css,$selectors,'color',$s['post_link_v_c']);388 if (isset($s['post_link_v_c'])) dcThemeConfig::prop($css,$selectors,'color',$s['post_link_v_c']); 389 389 390 390 # Inside posts links colors (hover, active, focus) 391 391 $selectors = '.post-excerpt a:hover, .post-excerpt a:active, .post-excerpt a:focus, .post-content a:hover, .post-content a:active, .post-content a:focus'; 392 if (isset($s['post_link_f_c'])) self::prop($css,$selectors,'color',$s['post_link_f_c']);392 if (isset($s['post_link_f_c'])) dcThemeConfig::prop($css,$selectors,'color',$s['post_link_f_c']); 393 393 394 394 # Style directives … … 407 407 # Blog title font weight 408 408 $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; 409 if (isset($s['blog_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['blog_title_w'] ? 'bold' : 'normal'));409 if (isset($s['blog_title_w'])) dcThemeConfig::prop($css_large,$selectors,'font-weight',($s['blog_title_w'] ? 'bold' : 'normal')); 410 410 411 411 # Blog title font size 412 412 $selectors = 'h1'; 413 if (isset($s['blog_title_s'])) self::prop($css_large,$selectors,'font-size',$s['blog_title_s']);413 if (isset($s['blog_title_s'])) dcThemeConfig::prop($css_large,$selectors,'font-size',$s['blog_title_s']); 414 414 415 415 # Blog title color 416 416 $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; 417 if (isset($s['blog_title_c'])) self::prop($css_large,$selectors,'color',$s['blog_title_c']);417 if (isset($s['blog_title_c'])) dcThemeConfig::prop($css_large,$selectors,'color',$s['blog_title_c']); 418 418 419 419 # Post title font weight 420 420 $selectors = 'h2.post-title, h2.post-title a:link, h2.post-title a:visited, h2.post-title a:hover, h2.post-title a:visited, h2.post-title a:focus'; 421 if (isset($s['post_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['post_title_w'] ? 'bold' : 'normal'));421 if (isset($s['post_title_w'])) dcThemeConfig::prop($css_large,$selectors,'font-weight',($s['post_title_w'] ? 'bold' : 'normal')); 422 422 423 423 # Post title font size 424 424 $selectors = 'h2.post-title'; 425 if (isset($s['post_title_s'])) self::prop($css_large,$selectors,'font-size',$s['post_title_s']);425 if (isset($s['post_title_s'])) dcThemeConfig::prop($css_large,$selectors,'font-size',$s['post_title_s']); 426 426 427 427 # Post title color 428 428 $selectors = 'h2.post-title a:link, h2.post-title a:visited, h2.post-title a:hover, h2.post-title a:visited, h2.post-title a:focus'; 429 if (isset($s['post_title_c'])) self::prop($css_large,$selectors,'color',$s['post_title_c']);429 if (isset($s['post_title_c'])) dcThemeConfig::prop($css_large,$selectors,'color',$s['post_title_c']); 430 430 431 431 # Simple title color (title without link) 432 432 $selectors = '#content-info h2, .post-title, .post h3, .post h4, .post h5, .post h6, .arch-block h3'; 433 if (isset($s['post_simple_title_c'])) self::prop($css_large,$selectors,'color',$s['post_simple_title_c']);433 if (isset($s['post_simple_title_c'])) dcThemeConfig::prop($css_large,$selectors,'color',$s['post_simple_title_c']); 434 434 435 435 # Style directives for large screens … … 451 451 # Blog title font weight 452 452 $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; 453 if (isset($s['blog_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['blog_title_w_m'] ? 'bold' : 'normal'));453 if (isset($s['blog_title_w_m'])) dcThemeConfig::prop($css_small,$selectors,'font-weight',($s['blog_title_w_m'] ? 'bold' : 'normal')); 454 454 455 455 # Blog title font size 456 456 $selectors = 'h1'; 457 if (isset($s['blog_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['blog_title_s_m']);457 if (isset($s['blog_title_s_m'])) dcThemeConfig::prop($css_small,$selectors,'font-size',$s['blog_title_s_m']); 458 458 459 459 # Blog title color 460 460 $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; 461 if (isset($s['blog_title_c_m'])) self::prop($css_small,$selectors,'color',$s['blog_title_c_m']);461 if (isset($s['blog_title_c_m'])) dcThemeConfig::prop($css_small,$selectors,'color',$s['blog_title_c_m']); 462 462 463 463 # Post title font weight 464 464 $selectors = 'h2.post-title, h2.post-title a:link, h2.post-title a:visited, h2.post-title a:hover, h2.post-title a:visited, h2.post-title a:focus'; 465 if (isset($s['post_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['post_title_w_m'] ? 'bold' : 'normal'));465 if (isset($s['post_title_w_m'])) dcThemeConfig::prop($css_small,$selectors,'font-weight',($s['post_title_w_m'] ? 'bold' : 'normal')); 466 466 467 467 # Post title font size 468 468 $selectors = 'h2.post-title'; 469 if (isset($s['post_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['post_title_s_m']);469 if (isset($s['post_title_s_m'])) dcThemeConfig::prop($css_small,$selectors,'font-size',$s['post_title_s_m']); 470 470 471 471 # Post title color 472 472 $selectors = 'h2.post-title a:link, h2.post-title a:visited, h2.post-title a:hover, h2.post-title a:visited, h2.post-title a:focus'; 473 if (isset($s['post_title_c_m'])) self::prop($css_small,$selectors,'color',$s['post_title_c_m']);473 if (isset($s['post_title_c_m'])) dcThemeConfig::prop($css_small,$selectors,'color',$s['post_title_c_m']); 474 474 475 475 # Style directives for small screens … … 515 515 return isset(self::$fonts[$c]) ? self::$fonts[$c] : null; 516 516 } 517 518 protected static function prop(&$css,$selector,$prop,$value)519 {520 if ($value) {521 $css[$selector][$prop] = $value;522 }523 }524 517 }
Note: See TracChangeset
for help on using the changeset viewer.