| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.2.2 |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 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 |
if (!function_exists('add_action')) |
| 13 |
{ |
| 14 |
// We are running outside of the context of WordPress. |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
if (!function_exists('firepluginsframework_getFrameworkVersion')) |
| 19 |
{ |
| 20 |
/** |
| 21 |
* Return the framework version |
| 22 |
* |
| 23 |
* @param string $dir |
| 24 |
* |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
function firepluginsframework_getFrameworkVersion($dir) |
| 28 |
{ |
| 29 |
// Memoize the parsed framework.xml per directory so it is only parsed once per request. |
| 30 |
static $versions = []; |
| 31 |
|
| 32 |
if (isset($versions[$dir])) |
| 33 |
{ |
| 34 |
return $versions[$dir]; |
| 35 |
} |
| 36 |
|
| 37 |
$framework_file = 'framework.xml'; |
| 38 |
|
| 39 |
$xmlFile = $dir . '/Framework/' . $framework_file; |
| 40 |
|
| 41 |
/** |
| 42 |
* On development the xml file is located in /framework/source/framework.xml. |
| 43 |
* On final zip, the file will rest on /Framework/framework.xml. |
| 44 |
* |
| 45 |
* Thus the check below. |
| 46 |
*/ |
| 47 |
$xmlFile = file_exists($xmlFile) ? $xmlFile : $dir . '/source/' . $framework_file; |
| 48 |
|
| 49 |
$xml = []; |
| 50 |
|
| 51 |
// load XML file |
| 52 |
if (function_exists('simplexml_load_file')) |
| 53 |
{ |
| 54 |
$xml = simplexml_load_file($xmlFile); |
| 55 |
} |
| 56 |
|
| 57 |
return ($versions[$dir] = isset($xml->version) ? (string) $xml->version : '1.0.0'); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
if (!function_exists('firepluginsframework_getFrameworkPriority')) |
| 62 |
{ |
| 63 |
/** |
| 64 |
* Return the framework priority |
| 65 |
* |
| 66 |
* @param string $dir |
| 67 |
* |
| 68 |
* @return void |
| 69 |
*/ |
| 70 |
function firepluginsframework_getFrameworkPriority($dir) |
| 71 |
{ |
| 72 |
static $priorities = []; |
| 73 |
|
| 74 |
if (isset($priorities[$dir])) |
| 75 |
{ |
| 76 |
return $priorities[$dir]; |
| 77 |
} |
| 78 |
|
| 79 |
$version = firepluginsframework_getFrameworkVersion($dir); |
| 80 |
$version = array_map('intval', array_pad(explode('.', $version), 3, 0)); |
| 81 |
|
| 82 |
/** |
| 83 |
* Order the bundled frameworks so the newest one always registers first. |
| 84 |
* |
| 85 |
* Each component is weighted so it can never be outranked by the components below it. |
| 86 |
* The previous weights (105 / 55 / 1) let the patch number outgrow a minor bump, so |
| 87 |
* 1.1.150 loaded ahead of 1.2.0 and the older framework won. |
| 88 |
* |
| 89 |
* Bundles still shipping those weights produce offsets in the low hundreds, so any |
| 90 |
* bundle using the weights below outranks them. That is the correct outcome, as every |
| 91 |
* such bundle is by definition newer than the ones using the old weights. |
| 92 |
*/ |
| 93 |
$id = PHP_INT_MAX - (($version[0] * 1000000) + ($version[1] * 1000) + $version[2]); |
| 94 |
|
| 95 |
return ($priorities[$dir] = $id); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Initialize the Framework |
| 101 |
* |
| 102 |
* @return void |
| 103 |
*/ |
| 104 |
add_action('init', function() |
| 105 |
{ |
| 106 |
if (class_exists('\FPFramework\Framework')) |
| 107 |
{ |
| 108 |
return; |
| 109 |
} |
| 110 |
|
| 111 |
$version = firepluginsframework_getFrameworkVersion(dirname(__DIR__)); |
| 112 |
$priority = firepluginsframework_getFrameworkPriority(dirname(__DIR__)); |
| 113 |
|
| 114 |
// Framework priority |
| 115 |
if (!defined('FPF_LOADED')) |
| 116 |
{ |
| 117 |
define('FPF_LOADED', $priority); |
| 118 |
} |
| 119 |
|
| 120 |
// Framework version |
| 121 |
if (!defined('FPF_VERSION')) |
| 122 |
{ |
| 123 |
define('FPF_VERSION', $version); |
| 124 |
} |
| 125 |
|
| 126 |
// Site URL |
| 127 |
if (!defined('FPF_SITE_URL')) |
| 128 |
{ |
| 129 |
define('FPF_SITE_URL', 'https://www.fireplugins.com/'); |
| 130 |
} |
| 131 |
|
| 132 |
// Framework Folder Path |
| 133 |
if (!defined('FPF_BASE_DIR')) |
| 134 |
{ |
| 135 |
define('FPF_BASE_DIR', dirname(__DIR__)); |
| 136 |
} |
| 137 |
|
| 138 |
// Framework Folder Path |
| 139 |
if (!defined('FPF_DIR')) |
| 140 |
{ |
| 141 |
define('FPF_DIR', plugin_dir_path(__FILE__) . 'Inc'); |
| 142 |
} |
| 143 |
|
| 144 |
// Framework Layouts Folder Path |
| 145 |
if (!defined('FPF_LAYOUTS_DIR')) |
| 146 |
{ |
| 147 |
define('FPF_LAYOUTS_DIR', FPF_DIR . '/Layouts/'); |
| 148 |
} |
| 149 |
|
| 150 |
// Support URL |
| 151 |
if (!defined('FPF_SUPPORT_URL')) |
| 152 |
{ |
| 153 |
define('FPF_SUPPORT_URL', FPF_SITE_URL . 'contact/'); |
| 154 |
} |
| 155 |
|
| 156 |
// Site Tower Endpoint |
| 157 |
if (!defined('FPF_TOWER_ENDPOINT')) |
| 158 |
{ |
| 159 |
define('FPF_TOWER_ENDPOINT', FPF_SITE_URL . 'wp-json/tower/v1/'); |
| 160 |
} |
| 161 |
|
| 162 |
// The templates.fireplugins.com Site URL |
| 163 |
if (!defined('FPF_TEMPLATES_SITE_URL')) |
| 164 |
{ |
| 165 |
define('FPF_TEMPLATES_SITE_URL', 'https://templates.fireplugins.com/'); |
| 166 |
} |
| 167 |
|
| 168 |
// Site Tower Endpoint |
| 169 |
if (!defined('FPF_TEMPLATES_TOWER_ENDPOINT')) |
| 170 |
{ |
| 171 |
define('FPF_TEMPLATES_TOWER_ENDPOINT', FPF_TEMPLATES_SITE_URL . 'wp-json/tower/v1/'); |
| 172 |
} |
| 173 |
|
| 174 |
// URL to retrieve templates |
| 175 |
if (!defined('FPF_TEMPLATES_GET_URL')) |
| 176 |
{ |
| 177 |
define('FPF_TEMPLATES_GET_URL', FPF_TEMPLATES_TOWER_ENDPOINT . 'templates/{{PLUGIN}}/{{LICENSE_KEY}}/{{PLUGIN_VERSION}}/{{SITE_URL}}/get'); |
| 178 |
} |
| 179 |
|
| 180 |
// URL to retrieve a template |
| 181 |
if (!defined('FPF_TEMPLATE_GET_URL')) |
| 182 |
{ |
| 183 |
define('FPF_TEMPLATE_GET_URL', FPF_TEMPLATES_TOWER_ENDPOINT . 'template/{{PLUGIN}}/{{TEMPLATE}}/{{LICENSE_KEY}}/{{SITE_URL}}/get'); |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* Get License Version URL |
| 188 |
*/ |
| 189 |
if (!defined('FPF_GET_LICENSE_VERSION_URL')) |
| 190 |
{ |
| 191 |
define('FPF_GET_LICENSE_VERSION_URL', FPF_TOWER_ENDPOINT . 'plugins/get_version/'); |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Plugin Changelog URL |
| 196 |
*/ |
| 197 |
if (!defined('FPF_PLUGIN_CHANGELOG_URL')) |
| 198 |
{ |
| 199 |
define('FPF_PLUGIN_CHANGELOG_URL', FPF_SITE_URL . '%s/changelog/'); |
| 200 |
} |
| 201 |
|
| 202 |
// Now kick off the class autoloader. |
| 203 |
spl_autoload_register( |
| 204 |
/** |
| 205 |
* Autoload classes |
| 206 |
* |
| 207 |
* @param string $class |
| 208 |
* |
| 209 |
* @return void |
| 210 |
*/ |
| 211 |
function ($class) |
| 212 |
{ |
| 213 |
static $namespaces = null; |
| 214 |
|
| 215 |
if ($namespaces === null) |
| 216 |
{ |
| 217 |
$base = dirname(__FILE__) . '/Inc/'; |
| 218 |
|
| 219 |
$namespaces = [ |
| 220 |
'FPFramework\\GeoIp2\\' => $base . 'Libs/Vendors/geoip2/geoip2/src/', |
| 221 |
'FPFramework\\' => $base, |
| 222 |
'MaxMind\\Db\\' => $base . 'Libs/Vendors/maxmind-db/reader/src/MaxMind/Db/', |
| 223 |
'MaxMind\\' => $base . 'Libs/Vendors/maxmind/web-service-common/src/', |
| 224 |
'splitbrain\\PHPArchive\\' => $base . 'Libs/Vendors/splitbrain/php-archive/src/', |
| 225 |
]; |
| 226 |
} |
| 227 |
|
| 228 |
foreach ($namespaces as $prefix => $dir) |
| 229 |
{ |
| 230 |
if (strpos($class, $prefix) === 0) |
| 231 |
{ |
| 232 |
$file = $dir . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php'; |
| 233 |
|
| 234 |
if (file_exists($file)) |
| 235 |
{ |
| 236 |
require_once $file; |
| 237 |
} |
| 238 |
|
| 239 |
return; |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
); |
| 244 |
|
| 245 |
// load once |
| 246 |
if (FPF_LOADED == $priority) |
| 247 |
{ |
| 248 |
/** |
| 249 |
* Fires when FPFramework is included/loaded |
| 250 |
*/ |
| 251 |
do_action('fpf_init'); |
| 252 |
|
| 253 |
if (is_admin()) |
| 254 |
{ |
| 255 |
/** |
| 256 |
* Fires on the admin side when FPFramework is included/loaded. |
| 257 |
*/ |
| 258 |
do_action('fpf_admin_init'); |
| 259 |
} |
| 260 |
} |
| 261 |
}, firepluginsframework_getFrameworkPriority(dirname(__DIR__))); |
| 262 |
|