| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.2.6 |
| 5 |
* |
| 6 |
* @author FirePlugins <[email protected]> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FPFramework\Base; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class Factory |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Returns Site Data |
| 23 |
* |
| 24 |
* @return object |
| 25 |
*/ |
| 26 |
public function getSiteData() |
| 27 |
{ |
| 28 |
return new Factory\SiteData(); |
| 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 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* WordPress Database Object |
| 45 |
* |
| 46 |
* @return object |
| 47 |
*/ |
| 48 |
public function getDbo() |
| 49 |
{ |
| 50 |
global $wpdb; |
| 51 |
return $wpdb; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Get Query Strings |
| 56 |
* |
| 57 |
* @return array |
| 58 |
*/ |
| 59 |
public function getQueryStrings() |
| 60 |
{ |
| 61 |
return isset($_GET) ? wp_unslash($_GET) : []; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Retrieves the language code |
| 66 |
* |
| 67 |
* @return string |
| 68 |
*/ |
| 69 |
public function getLanguage() |
| 70 |
{ |
| 71 |
static $instance = null; |
| 72 |
|
| 73 |
if ($instance === null) |
| 74 |
{ |
| 75 |
$instance = new Factory\Language(); |
| 76 |
} |
| 77 |
|
| 78 |
return $instance; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Retrieves public query variables that are recognized by WP_Query |
| 83 |
* See https://core.trac.wordpress.org/browser/tags/5.3/src/wp-includes/class-wp-query.php#L530 |
| 84 |
* |
| 85 |
* @param string $var |
| 86 |
* @param string $default |
| 87 |
* |
| 88 |
* @return string |
| 89 |
*/ |
| 90 |
public function getQueryVar($var, $default = '') |
| 91 |
{ |
| 92 |
return get_query_var($var, $default); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Retrives the date |
| 97 |
* |
| 98 |
* @param string $date |
| 99 |
* @param object $tz |
| 100 |
*/ |
| 101 |
public function getDate($date = 'now', $tz = null) |
| 102 |
{ |
| 103 |
return date_create($date ?? '', $tz); |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Get the user by a given field |
| 108 |
* |
| 109 |
* @param string $field |
| 110 |
* @param string $value |
| 111 |
* |
| 112 |
* @return mixed |
| 113 |
*/ |
| 114 |
public function getUser($field = '', $value = '') |
| 115 |
{ |
| 116 |
return \FPFramework\Base\User::get($value, $field); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Get Config |
| 121 |
* |
| 122 |
* @var Object |
| 123 |
*/ |
| 124 |
public static function getConfig() |
| 125 |
{ |
| 126 |
static $instance = null; |
| 127 |
|
| 128 |
if ($instance === null) |
| 129 |
{ |
| 130 |
$instance = new Factory\Config(); |
| 131 |
} |
| 132 |
|
| 133 |
return $instance; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Get referrer |
| 138 |
* |
| 139 |
* @return string |
| 140 |
*/ |
| 141 |
public function getReferrer() |
| 142 |
{ |
| 143 |
return wp_get_referer(); |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Returns the current page url |
| 148 |
* |
| 149 |
* @return string |
| 150 |
*/ |
| 151 |
public function getURL() |
| 152 |
{ |
| 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([])); |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* Get Device Type |
| 160 |
* |
| 161 |
* @return string |
| 162 |
*/ |
| 163 |
public function getDevice() |
| 164 |
{ |
| 165 |
return \FPFramework\Base\WebClient::getDeviceType(); |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Get Browser |
| 170 |
* |
| 171 |
* @return string |
| 172 |
*/ |
| 173 |
public function getBrowser() |
| 174 |
{ |
| 175 |
return \FPFramework\Base\WebClient::getBrowser(); |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Get OS |
| 180 |
* |
| 181 |
* @return string |
| 182 |
*/ |
| 183 |
public function getOS() |
| 184 |
{ |
| 185 |
return \FPFramework\Base\WebClient::getOS(); |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Get User Agent |
| 190 |
* |
| 191 |
* @return string |
| 192 |
*/ |
| 193 |
public function getUserAgent() |
| 194 |
{ |
| 195 |
$client = \FPFramework\Base\WebClient::getClient(); |
| 196 |
|
| 197 |
return $client ? $client->userAgent : ''; |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* Get a GeoIP Instance |
| 202 |
* |
| 203 |
* @param string $ip |
| 204 |
* |
| 205 |
* @return GeoIP |
| 206 |
*/ |
| 207 |
public function getGeoIP($ip = null) |
| 208 |
{ |
| 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]; |
| 219 |
} |
| 220 |
|
| 221 |
/** |
| 222 |
* Get Session |
| 223 |
* |
| 224 |
* @return array |
| 225 |
*/ |
| 226 |
public function getSession() |
| 227 |
{ |
| 228 |
static $instance = null; |
| 229 |
|
| 230 |
if ($instance === null) |
| 231 |
{ |
| 232 |
$instance = new Factory\Session(); |
| 233 |
} |
| 234 |
|
| 235 |
return $instance; |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Get Cookie |
| 240 |
* |
| 241 |
* @param string $cookie_name |
| 242 |
* |
| 243 |
* @return array |
| 244 |
*/ |
| 245 |
public function getCookie($cookie_name = null) |
| 246 |
{ |
| 247 |
return (new Factory\Cookie($cookie_name))->get(); |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* Get Visitor ID |
| 252 |
* |
| 253 |
* @return array |
| 254 |
*/ |
| 255 |
public function getVisitorID() |
| 256 |
{ |
| 257 |
return \FPFramework\Helpers\VisitorToken::getInstance()->get(); |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* Executes PHP code |
| 262 |
* |
| 263 |
* @return mixed |
| 264 |
*/ |
| 265 |
public function getExecuter($php_code) |
| 266 |
{ |
| 267 |
return new \FPFramework\Base\Executer($php_code); |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Return Custom Post Type of post |
| 272 |
* |
| 273 |
* @param object $post |
| 274 |
* |
| 275 |
* @return string |
| 276 |
*/ |
| 277 |
public function getCustomPostType($post = null) |
| 278 |
{ |
| 279 |
return get_post_type($post); |
| 280 |
} |
| 281 |
} |