| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FirePlugins Framework |
| 4 | - * @version 1.0.13 | |
| 4 | + * @version 1.2.6 | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2021 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; |
| @@ -26,8 +26,20 @@ | ||
| 26 | 26 | public function getSiteData() |
| 27 | 27 | { |
| 28 | 28 | return new Factory\SiteData(); |
| 29 | 29 | } |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Returns the condition. | |
| 33 | + * | |
| 34 | + * @param string $name | |
| 35 | + * | |
| 36 | + * @return Object | |
| 37 | + */ | |
| 38 | + public static function getCondition($name) | |
| 39 | + { | |
| 40 | + return \FPFramework\Base\Conditions\ConditionsHelper::getInstance()->getCondition($name); | |
| 41 | + } | |
| 30 | 42 | |
| 31 | 43 | /** |
| 32 | 44 | * WordPress Database Object |
| 33 | 45 | * |
| @@ -45,9 +57,9 @@ | ||
| 45 | 57 | * @return array |
| 46 | 58 | */ |
| 47 | 59 | public function getQueryStrings() |
| 48 | 60 | { |
| 49 | - return isset($_GET) ? wp_unslash($_GET) : []; | |
| 61 | + return isset($_GET) ? wp_unslash($_GET) : []; //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 50 | 62 | } |
| 51 | 63 | |
| 52 | 64 | /** |
| 53 | 65 | * Retrieves the language code |
| @@ -55,9 +67,16 @@ | ||
| 55 | 67 | * @return string |
| 56 | 68 | */ |
| 57 | 69 | public function getLanguage() |
| 58 | 70 | { |
| 59 | - return new Factory\Language(); | |
| 71 | + static $instance = null; | |
| 72 | + | |
| 73 | + if ($instance === null) | |
| 74 | + { | |
| 75 | + $instance = new Factory\Language(); | |
| 76 | + } | |
| 77 | + | |
| 78 | + return $instance; | |
| 60 | 79 | } |
| 61 | 80 | |
| 62 | 81 | /** |
| 63 | 82 | * Retrieves public query variables that are recognized by WP_Query |
| @@ -69,9 +88,9 @@ | ||
| 69 | 88 | * @return string |
| 70 | 89 | */ |
| 71 | 90 | public function getQueryVar($var, $default = '') |
| 72 | 91 | { |
| 73 | - return get_query_var($var, $default = ''); | |
| 92 | + return get_query_var($var, $default); | |
| 74 | 93 | } |
| 75 | 94 | |
| 76 | 95 | /** |
| 77 | 96 | * Retrives the date |
| @@ -80,9 +99,9 @@ | ||
| 80 | 99 | * @param object $tz |
| 81 | 100 | */ |
| 82 | 101 | public function getDate($date = 'now', $tz = null) |
| 83 | 102 | { |
| 84 | - return date_create($date, $tz); | |
| 103 | + return date_create($date ?? '', $tz); | |
| 85 | 104 | } |
| 86 | 105 | |
| 87 | 106 | /** |
| 88 | 107 | * Get the user by a given field |
| @@ -103,9 +122,16 @@ | ||
| 103 | 122 | * @var Object |
| 104 | 123 | */ |
| 105 | 124 | public static function getConfig() |
| 106 | 125 | { |
| 107 | - return new Factory\Config(); | |
| 126 | + static $instance = null; | |
| 127 | + | |
| 128 | + if ($instance === null) | |
| 129 | + { | |
| 130 | + $instance = new Factory\Config(); | |
| 131 | + } | |
| 132 | + | |
| 133 | + return $instance; | |
| 108 | 134 | } |
| 109 | 135 | |
| 110 | 136 | /** |
| 111 | 137 | * Get referrer |
| @@ -123,9 +149,11 @@ | ||
| 123 | 149 | * @return string |
| 124 | 150 | */ |
| 125 | 151 | public function getURL() |
| 126 | 152 | { |
| 127 | - return home_url(add_query_arg(NULL, NULL)); | |
| 153 | + // The array form keeps the current request's query string without handing | |
| 154 | + // add_query_arg() a null key, which PHP 8.5 deprecates as an array offset. | |
| 155 | + return home_url(add_query_arg([])); | |
| 128 | 156 | } |
| 129 | 157 | |
| 130 | 158 | /** |
| 131 | 159 | * Get Device Type |
| @@ -163,9 +191,11 @@ | ||
| 163 | 191 | * @return string |
| 164 | 192 | */ |
| 165 | 193 | public function getUserAgent() |
| 166 | 194 | { |
| 167 | - return \FPFramework\Base\WebClient::getClient()->userAgent; | |
| 195 | + $client = \FPFramework\Base\WebClient::getClient(); | |
| 196 | + | |
| 197 | + return $client ? $client->userAgent : ''; | |
| 168 | 198 | } |
| 169 | 199 | |
| 170 | 200 | /** |
| 171 | 201 | * Get a GeoIP Instance |
| @@ -175,9 +205,18 @@ | ||
| 175 | 205 | * @return GeoIP |
| 176 | 206 | */ |
| 177 | 207 | public function getGeoIP($ip = null) |
| 178 | 208 | { |
| 179 | - return new \FPFramework\Libs\Vendors\GeoIP\GeoIP($ip); | |
| 209 | + static $instances = array(); | |
| 210 | + | |
| 211 | + $key = $ip ?: ''; | |
| 212 | + | |
| 213 | + if (!isset($instances[$key])) | |
| 214 | + { | |
| 215 | + $instances[$key] = new \FPFramework\Libs\Vendors\GeoIP\GeoIP($ip); | |
| 216 | + } | |
| 217 | + | |
| 218 | + return $instances[$key]; | |
| 180 | 219 | } |
| 181 | 220 | |
| 182 | 221 | /** |
| 183 | 222 | * Get Session |
| @@ -185,9 +224,16 @@ | ||
| 185 | 224 | * @return array |
| 186 | 225 | */ |
| 187 | 226 | public function getSession() |
| 188 | 227 | { |
| 189 | - return new Factory\Session(); | |
| 228 | + static $instance = null; | |
| 229 | + | |
| 230 | + if ($instance === null) | |
| 231 | + { | |
| 232 | + $instance = new Factory\Session(); | |
| 233 | + } | |
| 234 | + | |
| 235 | + return $instance; | |
| 190 | 236 | } |
| 191 | 237 | |
| 192 | 238 | /** |
| 193 | 239 | * Get Cookie |
| @@ -197,9 +243,9 @@ | ||
| 197 | 243 | * @return array |
| 198 | 244 | */ |
| 199 | 245 | public function getCookie($cookie_name = null) |
| 200 | 246 | { |
| 201 | - return new Factory\Cookie($cookie_name); | |
| 247 | + return (new Factory\Cookie($cookie_name))->get(); | |
| 202 | 248 | } |
| 203 | 249 | |
| 204 | 250 | /** |
| 205 | 251 | * Get Visitor ID |