static function singleton() { if (!isset(self::$_instance)) { $className = __CLASS__; self::$_instance = new $className(); } return self::$_instance; }
/** * Extract Google fonts from CSS */ public function extract_google_fonts($css) { $googlefonts = array(); if (preg_match_all('#(?:@import)(?:\\s)(?:url)?(?:(?:(?:\\()(["\'])?(?:[^"\')]+)\\1(?:\\))|(["\'])(?:.+)\\2)(?:[A-Z\\s])*)+(?:;)#Ui', $css, $out) && !empty($out[0])) { foreach ($out[0] as $n => $fontLink) { if (substr_count($fontLink, "fonts.googleapis.com/css") > 0) { $fontLink = preg_replace('|^.*(//fonts\\.[^\\s\'\\"\\)]+)[\\s\\|\'\\|\\"\\|\\)].*|is', '$1', $fontLink); $googlefonts[] = $fontLink; } } if (!empty($googlefonts)) { $fonts = ''; foreach ($googlefonts as $font) { $fonts .= '<link rel="stylesheet" type="text/css" href="' . htmlentities($font) . '" />'; } $html = '<html><head><title>Fonts 2</title>' . $fonts . '</head><body></body></html>'; $fonts = GWFO::googlefonts_find_google_fonts($html); return $fonts; } } return false; }