Пример #1
0
 function thb_get_css_rule($rule, $value, $prefix = '', $suffix = '')
 {
     if ($value !== '') {
         if ($rule == 'font-family') {
             $value = str_replace('+', ' ', $value);
         } elseif ($rule == 'text-variant') {
             $font_style = thb_text_contains('italic', $value) ? 'italic' : 'normal';
             $font_weight = str_replace('italic', '', $value);
             if (thb_text_contains('regular', $font_weight) || empty($font_weight)) {
                 $font_weight = 'normal';
             }
             return thb_get_css_rule('font-weight', $font_weight) . ' ' . thb_get_css_rule('font-style', $font_style);
         }
         return $rule . ': ' . $prefix . $value . $suffix . ';';
     }
     return '';
 }
 /**
  * Print a well formed CSS stylesheet based on the registered settings.
  *
  * @param boolean $hideTag True to hide the <style> tag.
  * @return void
  */
 public function render($hideTag = false)
 {
     if (!$hideTag) {
         thb_css_start('thb-style-customizer');
     }
     $this->importFonts();
     $style_rules = array();
     $style_mixins = array();
     foreach ($this->_sections as $section) {
         foreach ($section['settings'] as $setting) {
             $value = get_theme_mod($setting['key']);
             if (empty($value)) {
                 $value = $setting['default'];
             }
             foreach ($setting['selectors'] as $selector => $rules) {
                 if (!isset($style_rules[$selector])) {
                     $style_rules[$selector] = array();
                 }
                 foreach ($rules as $rule) {
                     if (thb_text_startsWith($rule, 'mixin-')) {
                         $mixin = str_replace('mixin-', '', $rule);
                         if (function_exists($mixin)) {
                             $style_mixins[] = call_user_func($mixin, $value, $selector);
                         }
                     } else {
                         list($prefix, $suffix) = thb_css_prefix_suffix($rule);
                         $style_rules[$selector][] = thb_get_css_rule($rule, $value, $prefix, $suffix);
                     }
                 }
             }
         }
     }
     foreach ($style_rules as $selector => $rules) {
         thb_css_selector($selector, $rules);
     }
     foreach ($style_mixins as $mixin) {
         echo $mixin;
     }
     ksort($this->additionalStyles);
     foreach ($this->additionalStyles as $style) {
         if (function_exists($style)) {
             echo ' ' . call_user_func($style);
         }
     }
     if (!$hideTag) {
         thb_css_end();
     }
 }