Changeset 2658:0686a9a71a3f for themes/ductile/_config.php
- Timestamp:
- 02/13/14 14:13:01 (12 years ago)
- Branch:
- default
- File:
-
- 1 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']).
Note: See TracChangeset
for help on using the changeset viewer.