| 1 |
<?php |
| 2 |
namespace Dudlewebs\WPMCS; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Cdn { |
| 7 |
private static $instance = null; |
| 8 |
private $assets_url; |
| 9 |
private $version; |
| 10 |
private $token; |
| 11 |
|
| 12 |
/** |
| 13 |
* Admin constructor. |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
$this->assets_url = WPMCS_ASSETS_URL; |
| 18 |
$this->version = WPMCS_VERSION; |
| 19 |
$this->token = WPMCS_TOKEN; |
| 20 |
|
| 21 |
// Initialize setup |
| 22 |
// $this->init(); |
| 23 |
} |
| 24 |
/** |
| 25 |
* |
| 26 |
* CDN url generate |
| 27 |
* @since 1.0.0 |
| 28 |
* |
| 29 |
*/ |
| 30 |
public static function may_generate_cdn_url($url, $key){ |
| 31 |
$settings = Utils::get_settings(); |
| 32 |
if ( |
| 33 |
isset($settings['enable_cdn']) && $settings['enable_cdn'] && |
| 34 |
isset($settings['cdn_url']) && !empty($settings['cdn_url']) && |
| 35 |
isset($url) && !empty($url) && |
| 36 |
isset($key) && !empty($key) |
| 37 |
) { |
| 38 |
|
| 39 |
$urlArray = explode($key, $url ); |
| 40 |
if(isset($urlArray) && !empty($urlArray) && isset($urlArray[0])) { |
| 41 |
$new_url = str_replace(trailingslashit($urlArray[0]), trailingslashit($settings['cdn_url']), $url); |
| 42 |
$new_url = apply_filters('wpmcs_cdn_url', $new_url, $url, $settings['cdn_url']); |
| 43 |
$new_url = preg_replace('/([^:])(\/{2,})/', '$1/', $new_url); // to remove double slash trapped during any operations |
| 44 |
return $new_url; |
| 45 |
} |
| 46 |
|
| 47 |
} |
| 48 |
return $url; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public static function instance(){ |
| 54 |
if (is_null(self::$instance)) { |
| 55 |
self::$instance = new self(); |
| 56 |
} |
| 57 |
return self::$instance; |
| 58 |
} |
| 59 |
} |