| 1 |
<?php |
| 2 |
namespace Kibo\PhastPlugins\PhastPress; |
| 3 |
|
| 4 |
use Kibo\Phast\ValueObjects\URL; |
| 5 |
|
| 6 |
class CDN { |
| 7 |
public static function installHook() { |
| 8 |
add_filter('phastpress_cdn_url', [static::class, 'getCdnUrl']); |
| 9 |
} |
| 10 |
|
| 11 |
public static function getCdnUrl($url) { |
| 12 |
if (($options = self::getBunnyCdnOptions()) |
| 13 |
&& strlen(trim($options['cdn_domain_name'])) |
| 14 |
) { |
| 15 |
return URL::fromString($url)->rewrite( |
| 16 |
URL::fromString($options['site_url']), |
| 17 |
URL::fromString((is_ssl() ? 'https://' : 'http://') . $options['cdn_domain_name']) |
| 18 |
); |
| 19 |
} |
| 20 |
|
| 21 |
return $url; |
| 22 |
} |
| 23 |
|
| 24 |
public static function getBunnyCdnOptions() { |
| 25 |
try { |
| 26 |
$class = new \ReflectionClass('BunnyCDN'); |
| 27 |
$method = $class->getMethod('getOptions'); |
| 28 |
return $method->invoke(null); |
| 29 |
} catch (\Exception $e) { |
| 30 |
} catch (\Throwable $e) { |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
|