PluginProbe
Media Cloud Sync / 1.3.0
Media Cloud Sync v1.3.0
1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 All 34 releases
media-cloud-sync / includes / base / cdn.php

cdn.php in Media Cloud Sync 1.3.0, at includes/base/cdn.php

59 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
33 if (
34 isset($settings['enable_cdn'], $settings['cdn_url']) &&
35 $settings['enable_cdn'] && !empty($settings['cdn_url']) &&
36 isset($url, $key) && !Utils::is_empty($url) && !Utils::is_empty($key)
37 ) {
38 $url_parts = explode($key, $url);
39 if (!empty($url_parts[0])) {
40 $cdn_url = 'https://' . preg_replace('#^https?://#i', '', trim($settings['cdn_url']));
41 $new_url = str_replace(trailingslashit($url_parts[0]), trailingslashit($cdn_url), $url);
42 $new_url = apply_filters('wpmcs_cdn_url', $new_url, $url, $cdn_url);
43 return preg_replace('/([^:])(\/{2,})/', '$1/', $new_url); // remove double slashes
44 }
45 }
46
47 return $url;
48 }
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 }