| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FirePlugins Framework |
| 4 | - * @version 1.2.5 | |
| 4 | + * @version 1.1.117 | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2026 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2024 FirePlugins All Rights Reserved | |
| 9 | 9 | * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | if (!function_exists('add_action')) |
| @@ -25,24 +25,16 @@ | ||
| 25 | 25 | * @return void |
| 26 | 26 | */ |
| 27 | 27 | function firepluginsframework_getFrameworkVersion($dir) |
| 28 | 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 | 29 | $framework_file = 'framework.xml'; |
| 38 | - | |
| 30 | + | |
| 39 | 31 | $xmlFile = $dir . '/Framework/' . $framework_file; |
| 40 | - | |
| 32 | + | |
| 41 | 33 | /** |
| 42 | 34 | * On development the xml file is located in /framework/source/framework.xml. |
| 43 | 35 | * On final zip, the file will rest on /Framework/framework.xml. |
| 44 | - * | |
| 36 | + * | |
| 45 | 37 | * Thus the check below. |
| 46 | 38 | */ |
| 47 | 39 | $xmlFile = file_exists($xmlFile) ? $xmlFile : $dir . '/source/' . $framework_file; |
| 48 | 40 | |
| @@ -53,9 +45,9 @@ | ||
| 53 | 45 | { |
| 54 | 46 | $xml = simplexml_load_file($xmlFile); |
| 55 | 47 | } |
| 56 | 48 | |
| 57 | - return ($versions[$dir] = isset($xml->version) ? (string) $xml->version : '1.0.0'); | |
| 49 | + return isset($xml->version) ? (string) $xml->version : '1.0.0'; | |
| 58 | 50 | } |
| 59 | 51 | } |
| 60 | 52 | |
| 61 | 53 | if (!function_exists('firepluginsframework_getFrameworkPriority')) |
| @@ -68,32 +60,30 @@ | ||
| 68 | 60 | * @return void |
| 69 | 61 | */ |
| 70 | 62 | function firepluginsframework_getFrameworkPriority($dir) |
| 71 | 63 | { |
| 72 | - static $priorities = []; | |
| 64 | + $id = PHP_INT_MAX; | |
| 73 | 65 | |
| 74 | - if (isset($priorities[$dir])) | |
| 66 | + $version = firepluginsframework_getFrameworkVersion($dir); | |
| 67 | + $version = array_map('intval', explode('.', $version)); | |
| 68 | + | |
| 69 | + for ($i = 0; $i < count($version); $i++) | |
| 75 | 70 | { |
| 76 | - return $priorities[$dir]; | |
| 71 | + if ($i == 0) | |
| 72 | + { | |
| 73 | + $id -= $version[$i] * 105; | |
| 74 | + } | |
| 75 | + else if ($i == 1) | |
| 76 | + { | |
| 77 | + $id -= $version[$i] * 55; | |
| 78 | + } | |
| 79 | + else | |
| 80 | + { | |
| 81 | + $id -= $version[$i]; | |
| 82 | + } | |
| 77 | 83 | } |
| 78 | 84 | |
| 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); | |
| 85 | + return $id; | |
| 96 | 86 | } |
| 97 | 87 | } |
| 98 | 88 | |
| 99 | 89 | /** |
| @@ -209,40 +199,46 @@ | ||
| 209 | 199 | * @return void |
| 210 | 200 | */ |
| 211 | 201 | function ($class) |
| 212 | 202 | { |
| 213 | - static $namespaces = null; | |
| 203 | + $base = dirname(__FILE__) . '/Inc/'; | |
| 214 | 204 | |
| 215 | - if ($namespaces === null) | |
| 205 | + $namespaces = [ | |
| 206 | + 'FPFramework\\GeoIp2\\' => [ $base . 'Libs/Vendors/geoip2/geoip2/src/' ], | |
| 207 | + 'FPFramework\\' => [ $base ], | |
| 208 | + 'MaxMind\\Db\\' => [ $base . 'Libs/Vendors/maxmind-db/reader/src/MaxMind/Db/' ], | |
| 209 | + 'MaxMind\\' => [ $base . 'Libs/Vendors/maxmind/web-service-common/src/' ], | |
| 210 | + 'splitbrain\\PHPArchive\\' => [$base . 'Libs/Vendors/splitbrain/php-archive/src/' ], | |
| 211 | + ]; | |
| 212 | + | |
| 213 | + $found = false; | |
| 214 | + foreach ($namespaces as $key => $value) | |
| 216 | 215 | { |
| 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 | - ]; | |
| 216 | + if (strpos($class, $key) === 0) | |
| 217 | + { | |
| 218 | + $found = true; | |
| 219 | + break; | |
| 220 | + } | |
| 226 | 221 | } |
| 227 | 222 | |
| 228 | - foreach ($namespaces as $prefix => $dir) | |
| 223 | + if (!$found) | |
| 229 | 224 | { |
| 230 | - if (strpos($class, $prefix) === 0) | |
| 231 | - { | |
| 232 | - $file = $dir . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php'; | |
| 225 | + return; | |
| 226 | + } | |
| 227 | + | |
| 228 | + $class = firepluginsframework_fixClassBasedOnNamespace($namespaces, $class); | |
| 233 | 229 | |
| 234 | - if (file_exists($file)) | |
| 235 | - { | |
| 236 | - require_once $file; | |
| 237 | - } | |
| 230 | + $file = str_replace('\\', '/', $class) . '.php'; | |
| 238 | 231 | |
| 239 | - return; | |
| 240 | - } | |
| 232 | + if (file_exists($file)) | |
| 233 | + { | |
| 234 | + require_once $file; | |
| 241 | 235 | } |
| 242 | 236 | } |
| 243 | 237 | ); |
| 244 | 238 | |
| 239 | + \FPFramework\Base\Session::getInstance()->init(); | |
| 240 | + | |
| 245 | 241 | // load once |
| 246 | 242 | if (FPF_LOADED == $priority) |
| 247 | 243 | { |
| 248 | 244 | /** |
| @@ -258,4 +254,28 @@ | ||
| 258 | 254 | do_action('fpf_admin_init'); |
| 259 | 255 | } |
| 260 | 256 | } |
| 261 | 257 | }, firepluginsframework_getFrameworkPriority(dirname(__DIR__))); |
| 258 | + | |
| 259 | +if (!function_exists('firepluginsframework_fixClassBasedOnNamespace')) | |
| 260 | +{ | |
| 261 | + /** | |
| 262 | + * Fixes the class paths | |
| 263 | + * | |
| 264 | + * @param string $namespaces | |
| 265 | + * @param string $class | |
| 266 | + * | |
| 267 | + * @return void | |
| 268 | + */ | |
| 269 | + function firepluginsframework_fixClassBasedOnNamespace($namespaces, $class) | |
| 270 | + { | |
| 271 | + foreach ($namespaces as $key => $value) | |
| 272 | + { | |
| 273 | + if (strpos($class, $key) !== FALSE) | |
| 274 | + { | |
| 275 | + $class = str_replace($key, $value[0], $class); | |
| 276 | + } | |
| 277 | + } | |
| 278 | + | |
| 279 | + return $class; | |
| 280 | + } | |
| 281 | +} | |