Quantcast
Channel: WordPress.org Forums » [Autoptimize] Support
Viewing all articles
Browse latest Browse all 14094

lutechi on "[Plugin: Autoptimize] CDN Font Support Replacement Logic or any local URL file in CSS"

$
0
0

Hi Frank,

I opened the code and was hoping for something easy to replace file types, but PHP is beyond my knowledge.

I did play with it trying to make sense of existing code for the images and apply it to the fonts. Sorry if I butchered it and probably is totally different from what I was thinking, I am just trying to help.

// Do the @font-face!
$fontreplace = array();
preg_match_all('#(*url\((?!data)(.*)\)[^;}]*)(?:;|$|})#Usm',$code,$matches);

if ((is_array($matches)) && (!empty($this->cdn_url))) {
	// change @font-face urls to cdn-url
	foreach($matches[2] as $count => $quotedurl) {
		$url = trim($quotedurl," \t\n\r\x0B\"'");
		$cdn_url=$this->url_replace_cdn($url);
		$fontreplace[$matches[1][$count]] = str_replace($quotedurl,$cdn_url,$matches[1][$count]);
		}

		$ipath = $this->getpath($url);

		}

		if($ipath != false && preg_match('#\.(eot|woff2|woff|ttf|svg)$#',$ipath)) {

			unset($icheck);

			// Add it to the list for replacement
			$fontreplace[$matches[1][$count]] = str_replace($quotedurl,$matches[1][$count]).";\n*".str_replace($quotedurl,'mhtml:%%MHTML%%!'.$mhtmlcount,$matches[1][$count]).";\n_".$matches[1][$count].';';

		}
	}
}

if(!empty($fontreplace)) {
	$code = str_replace(array_keys($fontreplace),array_values($fontreplace),$code);
	}

Viewing all articles
Browse latest Browse all 14094

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>