Ejemplo n.º 1
0
 /**
  * Adds Google Font initialization to style LESS
  * @param  array  $style_data style data
  * @param  string $less       style LESS code
  * @return string style LESS code
  */
 private function addGoogleFonts($style_data, $less)
 {
     $content = array();
     $less = preg_replace("#/\\*{$this->gfonts_tag}\\*/(.*?)/\\*/{$this->gfonts_tag}\\*/#s", '', $less);
     foreach ($this->schema['fonts']['fields'] as $field => $data) {
         $font_name = trim($style_data[$field], "'\"");
         if (empty($this->schema['fonts']['families'][$font_name])) {
             // Google font!
             if (empty($content[$font_name])) {
                 $font_data = $this->getGoogleFontData($font_name);
                 // Set user agent manually to get IE-specific code
                 $css = Http::get('http://fonts.googleapis.com/css?family=' . $font_name . (!empty($font_data['weight']) ? ':' . $font_data['weight'] : '') . '&subset=latin,cyrillic', array(), array('headers' => array('User-Agent: Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; Trident/5.0)')));
                 if (Http::getStatus() == Http::STATUS_OK && !empty($css)) {
                     $content[$font_name] = str_replace('http://', '//', $css);
                 }
             }
         }
     }
     if (!empty($content)) {
         $less .= "\n/*{$this->gfonts_tag}*/" . "\n" . implode("\n", $content) . "\n/*/{$this->gfonts_tag}*/";
     }
     return $less;
 }