PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.14
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.14
3.1.14 3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 All 123 releases
← All changes | Inc/Framework/Inc/Base/WebClient.php +67 -19 1.0.14 → 3.1.14 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FirePlugins Framework
4 - * @version 1.0.27
4 + * @version 1.2.6
5 5 *
6 6 * @author FirePlugins <[email protected]>
7 7 * @link https://www.fireplugins.com
8 - * @copyright Copyright © 2022 FirePlugins All Rights Reserved
8 + * @copyright Copyright © 2026 FirePlugins All Rights Reserved
9 9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 10 */
11 11
12 12 namespace FPFramework\Base;
@@ -27,10 +27,24 @@
27 27 */
28 28 public static $client;
29 29
30 30 /**
31 + * Per-request memoized results of getDeviceType()/getOS()/getBrowser(), keyed by UA string.
32 + *
33 + * @var array
34 + */
35 + private static $resultCache = array();
36 +
37 + /**
38 + * Memoized constants from JApplicationWebClient, keyed by class name.
39 + *
40 + * @var array
41 + */
42 + private static $constantsCache = array();
43 +
44 + /**
31 45 * Get visitor's Device Type
32 - *
46 + *
33 47 * @param string $ua User Agent string, if null use the implicit one from the server's enviroment
34 48 *
35 49 * @return string The client's device type. Can be: tablet, mobile, desktop
36 50 */
@@ -35,11 +49,18 @@
35 49 * @return string The client's device type. Can be: tablet, mobile, desktop
36 50 */
37 51 public static function getDeviceType($ua = null)
38 52 {
53 + $cacheKey = 'deviceType_' . ($ua === null ? '' : $ua);
54 +
55 + if (isset(self::$resultCache[$cacheKey]))
56 + {
57 + return self::$resultCache[$cacheKey];
58 + }
59 +
39 60 $detect = new Mobile_Detect(null, $ua);
40 61
41 - return ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'mobile') : 'desktop');
62 + return (self::$resultCache[$cacheKey] = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'mobile') : 'desktop'));
42 63 }
43 64
44 65 /**
45 66 * Get visitor's Operating System
@@ -44,42 +65,55 @@
44 65 /**
45 66 * Get visitor's Operating System
46 67 *
47 68 * @param string $ua User Agent string, if null use the implicit one from the server's enviroment
48 - *
49 - * @return string Possible values: any of JApplicationWebClient's OS constants (except 'iphone' and 'ipad'),
69 + *
70 + * @return string Possible values: any of JApplicationWebClient's OS constants (except 'iphone' and 'ipad'),
50 71 * 'ios', 'chromeos'
51 72 */
52 73 public static function getOS($ua = null)
53 74 {
75 + $cacheKey = 'os_' . ($ua === null ? '' : $ua);
76 +
77 + if (isset(self::$resultCache[$cacheKey]))
78 + {
79 + return self::$resultCache[$cacheKey];
80 + }
81 +
54 82 // detect iOS and CromeOS (not handled by JApplicationWebClient)
55 - $ua = self::getClient($ua)->userAgent;
83 + $client = self::getClient($ua);
84 + $userAgent = $client->userAgent;
56 85
86 + if (!$userAgent)
87 + {
88 + return;
89 + }
90 +
57 91 $ios_regex = '/iPhone|iPad|iPod/i';
58 - if (preg_match($ios_regex, $ua))
92 + if (preg_match($ios_regex, $userAgent))
59 93 {
60 - return 'ios';
94 + return (self::$resultCache[$cacheKey] = 'ios');
61 95 }
62 96
63 97 $chromeos_regex = '/CrOS/i';
64 - if (preg_match($chromeos_regex, $ua))
98 + if (preg_match($chromeos_regex, $userAgent))
65 99 {
66 - return 'chromeos';
100 + return (self::$resultCache[$cacheKey] = 'chromeos');
67 101 }
68 102
69 103 // use JApplicationWebClient for OS detection
70 - $platformInt = self::getClient($ua)->platform;
104 + $platformInt = $client->platform;
71 105 $constants = self::getClientConstants();
72 -
106 +
73 107 if (isset($constants[$platformInt]))
74 108 {
75 - return strtolower($constants[$platformInt]);
109 + return (self::$resultCache[$cacheKey] = strtolower($constants[$platformInt]));
76 110 }
77 111 }
78 112
79 113 /**
80 114 * Get visitor's Browser name / version
81 - *
115 + *
82 116 * @param string $ua User Agent string, if null use the implicit one from the server's enviroment
83 117 *
84 118 * @return array
85 119 */
@@ -84,8 +118,15 @@
84 118 * @return array
85 119 */
86 120 public static function getBrowser($ua = null)
87 121 {
122 + $cacheKey = 'browser_' . ($ua === null ? '' : $ua);
123 +
124 + if (isset(self::$resultCache[$cacheKey]))
125 + {
126 + return self::$resultCache[$cacheKey];
127 + }
128 +
88 129 $client = self::getClient($ua);
89 130 $browserInt = $client->browser;
90 131 $constants = self::getClientConstants();
91 132
@@ -90,12 +131,12 @@
90 131 $constants = self::getClientConstants();
91 132
92 133 if (isset($constants[$browserInt]))
93 134 {
94 - return array(
135 + return (self::$resultCache[$cacheKey] = array(
95 136 'name' => strtolower($constants[$browserInt]),
96 137 'version' => $client->browserVersion
97 - );
138 + ));
98 139 }
99 140 }
100 141
101 142 /**
@@ -104,13 +145,20 @@
104 145 * @return array
105 146 */
106 147 private static function getClientConstants()
107 148 {
108 - $r = new \ReflectionClass('\\FPFramework\\Helpers\\Vendors\\WebClient');
149 + $class = '\\FPFramework\\Helpers\\Vendors\\WebClient';
150 +
151 + if (isset(self::$constantsCache[$class]))
152 + {
153 + return self::$constantsCache[$class];
154 + }
155 +
156 + $r = new \ReflectionClass($class);
109 157 $constantsArray = $r->getConstants();
110 158
111 159 // flip the associative array
112 - return array_flip($constantsArray);
160 + return (self::$constantsCache[$class] = array_flip($constantsArray));
113 161 }
114 162
115 163 /**
116 164 * Get the Application Client helper