| @@ -4,79 +4,14 @@ | ||
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * @return Boxzilla |
| 7 | 7 | */ |
| 8 | -function boxzilla() | |
| 9 | -{ | |
| 8 | +function boxzilla() { | |
| 10 | 9 | static $instance; |
| 11 | 10 | |
| 12 | - if (is_null($instance)) { | |
| 13 | - $instance = new Boxzilla(); | |
| 11 | + if( is_null( $instance ) ) { | |
| 12 | + $instance = new Boxzilla(); | |
| 14 | 13 | } |
| 15 | 14 | |
| 16 | 15 | return $instance; |
| 17 | 16 | } |
| 18 | 17 | |
| 19 | -/** | |
| 20 | - * Normalize a relative URL for Boxzilla rule storage and matching. | |
| 21 | - * | |
| 22 | - * @param string $url_string | |
| 23 | - * | |
| 24 | - * @return string | |
| 25 | - */ | |
| 26 | -function boxzilla_normalize_relative_url($url_string) | |
| 27 | -{ | |
| 28 | - $url_string = trim((string) $url_string); | |
| 29 | - if ($url_string === '') { | |
| 30 | - return '/'; | |
| 31 | - } | |
| 32 | - | |
| 33 | - if (strpos($url_string, '//') === 0) { | |
| 34 | - $url_string = 'https:' . $url_string; | |
| 35 | - } elseif (preg_match('/^[\w.-]+\.[a-z]{2,}(?:[\/?#]|$)/i', $url_string)) { | |
| 36 | - $url_string = 'https://' . $url_string; | |
| 37 | - } | |
| 38 | - | |
| 39 | - $parts = wp_parse_url($url_string); | |
| 40 | - if (! is_array($parts)) { | |
| 41 | - return '/'; | |
| 42 | - } | |
| 43 | - | |
| 44 | - $path = isset($parts['path']) ? $parts['path'] : '/'; | |
| 45 | - $path = '/' . ltrim((string) $path, '/'); | |
| 46 | - $path = untrailingslashit($path); | |
| 47 | - if ($path === '') { | |
| 48 | - $path = '/'; | |
| 49 | - } | |
| 50 | - | |
| 51 | - if (empty($parts['query'])) { | |
| 52 | - return $path; | |
| 53 | - } | |
| 54 | - | |
| 55 | - parse_str($parts['query'], $query_args); | |
| 56 | - if (empty($query_args)) { | |
| 57 | - return $path; | |
| 58 | - } | |
| 59 | - | |
| 60 | - $tracking_keys = [ | |
| 61 | - '_ga', | |
| 62 | - '_gl', | |
| 63 | - 'dclid', | |
| 64 | - 'fbclid', | |
| 65 | - 'gclid', | |
| 66 | - 'mc_cid', | |
| 67 | - 'mc_eid', | |
| 68 | - 'msclkid', | |
| 69 | - ]; | |
| 70 | - | |
| 71 | - foreach (array_keys($query_args) as $key) { | |
| 72 | - if (strpos($key, 'utm_') === 0 || in_array($key, $tracking_keys, true)) { | |
| 73 | - unset($query_args[ $key ]); | |
| 74 | - } | |
| 75 | - } | |
| 76 | - | |
| 77 | - if (empty($query_args)) { | |
| 78 | - return $path; | |
| 79 | - } | |
| 80 | - | |
| 81 | - return $path . '?' . build_query($query_args); | |
| 82 | -} | |