. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
| Server IP : 162.0.212.4 / Your IP :
216.73.216.14 [
Web Server : LiteSpeed System : Linux premium146.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 User : alshnoli ( 2431) PHP Version : 8.3.28 Disable Function : NONE Domains : 1 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/alshnoli/public_html/wp-content/plugins/perfmatters/inc/classes/ |
Upload File : |
<?php
namespace Perfmatters;
class CDN
{
//initialize cdn
public static function init()
{
add_action('wp', array('Perfmatters\CDN', 'queue'));
}
//queue functions
public static function queue()
{
//add cdn rewrite to the buffer
if(!empty(Config::$options['cdn']['enable_cdn']) && !empty(Config::$options['cdn']['cdn_url'])) {
add_action('perfmatters_output_buffer_template_redirect', array('Perfmatters\CDN', 'rewrite'));
}
}
//rewrite urls in html
public static function rewrite($html)
{
//filter check
if(!apply_filters('perfmatters_cdn', true)) {
return $html;
}
//prep site url
$siteURL = '//' . ((!empty($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : parse_url(home_url(), PHP_URL_HOST));
$escapedSiteURL = quotemeta($siteURL);
$regExURL = 'https?:' . substr($escapedSiteURL, strpos($escapedSiteURL, '//'));
//prep included directories
$directories = 'wp\-content|wp\-includes';
if(!empty(Config::$options['cdn']['cdn_directories'])) {
$directoriesArray = array_map('trim', explode(',', Config::$options['cdn']['cdn_directories']));
if(count($directoriesArray) > 0) {
$directories = implode('|', array_map('quotemeta', array_filter($directoriesArray)));
}
}
//prep included extensions
$extensions_array = apply_filters('perfmatters_cdn_extensions', array(
'avif',
'css',
'gif',
'jpeg',
'jpg',
'js',
'json',
'mp3',
'mp4',
'otf',
'pdf',
'png',
'svg',
'ttf',
'webp',
'woff',
'woff2'
));
$extensions = implode('|', $extensions_array);
//rewrite urls in html
$regEx = '#(?<=[(\"\']|")(?:' . $regExURL . ')?\/(?:(?:' . $directories . ')[^\"\')]+)\.(' . $extensions . ')[^\"\')]*(?=[\"\')]|")#';
//base exclusions
$exclusions = array('script-manager.js');
//add user exclusions
if(!empty(Config::$options['cdn']['cdn_exclusions'])) {
$exclusions_user = array_map('trim', explode(',', Config::$options['cdn']['cdn_exclusions']));
$exclusions = array_merge($exclusions, $exclusions_user);
}
//set cdn url
$cdnURL = Config::$options['cdn']['cdn_url'];
//replace urls
$html = preg_replace_callback($regEx, function($url) use ($siteURL, $cdnURL, $exclusions) {
//check for exclusions
foreach($exclusions as $exclusion) {
if(!empty($exclusion) && stristr($url[0], $exclusion) != false) {
return $url[0];
}
}
//replace url with no scheme
if(strpos($url[0], '//') === 0) {
return str_replace($siteURL, $cdnURL, $url[0]);
}
//replace non relative site url
if(strstr($url[0], $siteURL)) {
return str_replace(array('http:' . $siteURL, 'https:' . $siteURL), $cdnURL, $url[0]);
}
//replace relative url
return $cdnURL . $url[0];
}, $html);
return $html;
}
}