PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 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 All 35 releases
← All changes | includes/base/cdn.php +51 -13 1.0.21.4.1 View file →
@@ -26,29 +26,67 @@
26 26 * CDN url generate
27 27 * @since 1.0.0
28 28 *
29 29 */
30 - public static function may_generate_cdn_url($url, $key){
30 + public static function may_generate_cdn_url($url, $key) {
31 31 $settings = Utils::get_settings();
32 +
32 33 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)
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 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 + }
38 46
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 - }
47 + return $url;
48 + }
46 49
50 +
51 + /**
52 + * Is CDN URL ?
53 + * @since 1.3.6
54 + */
55 + public static function is_cdn_url($url) {
56 + $settings = Utils::get_settings();
57 +
58 + if (
59 + isset($settings['enable_cdn'], $settings['cdn_url']) &&
60 + $settings['enable_cdn'] && !empty($settings['cdn_url']) &&
61 + isset($url) && !Utils::is_empty($url)
62 + ) {
63 + $cdn_url = 'https://' . preg_replace('#^https?://#i', '', trim($settings['cdn_url']));
64 + return (strpos($url, $cdn_url . '/') !== false);
47 65 }
48 - return $url;
66 +
67 + return false;
49 68 }
50 69
70 +
71 + /**
72 + * Get the CDN domain.
73 + *
74 + * @since 1.3.6
75 + * @return string The CDN domain URL if enabled, otherwise an empty string.
76 + */
77 + public static function get_domain() {
78 + $settings = Utils::get_settings();
79 +
80 + if (
81 + isset($settings['enable_cdn'], $settings['cdn_url']) &&
82 + $settings['enable_cdn'] && !empty($settings['cdn_url'])
83 + ) {
84 + return 'https://' . preg_replace('#^https?://#i', '', trim($settings['cdn_url']));
85 + }
86 +
87 + return '';
88 + }
51 89
52 90
53 91 public static function instance(){
54 92 if (is_null(self::$instance)) {