PluginProbe
Boxzilla – WordPress Popup Builder / 3.4.8
Boxzilla – WordPress Popup Builder v3.4.8
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
boxzilla / src / functions.php

functions.php in Boxzilla – WordPress Popup Builder 3.4.8, at src/functions.php

83 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Boxzilla\Boxzilla;
4
5 /**
6 * @return Boxzilla
7 */
8 function boxzilla()
9 {
10 static $instance;
11
12 if (is_null($instance)) {
13 $instance = new Boxzilla();
14 }
15
16 return $instance;
17 }
18
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 }
83