PluginProbe
PhastPress / 3.9
PhastPress v3.9
3.12 3.11 1.75 1.76 1.77 1.78 1.79 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.90 1.91 1.92 1.93 1.94 1.95 1.96 1.97 All 119 releases
phastpress / classes / CDN.php

CDN.php in PhastPress 3.9, at classes/CDN.php

34 lines 942 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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