| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FirePlugins Framework |
| 4 | - * @version 1.2.5 | |
| 4 | + * @version 1.1.102 | |
| 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 | /** |
| @@ -198,8 +188,10 @@ | ||
| 198 | 188 | { |
| 199 | 189 | define('FPF_PLUGIN_CHANGELOG_URL', FPF_SITE_URL . '%s/changelog/'); |
| 200 | 190 | } |
| 201 | 191 | |
| 192 | + firepluginsframework_load_textdomain(dirname(__DIR__)); | |
| 193 | + | |
| 202 | 194 | // Now kick off the class autoloader. |
| 203 | 195 | spl_autoload_register( |
| 204 | 196 | /** |
| 205 | 197 | * Autoload classes |
| @@ -209,40 +201,44 @@ | ||
| 209 | 201 | * @return void |
| 210 | 202 | */ |
| 211 | 203 | function ($class) |
| 212 | 204 | { |
| 213 | - static $namespaces = null; | |
| 205 | + $base = dirname(__FILE__) . '/Inc/'; | |
| 214 | 206 | |
| 215 | - if ($namespaces === null) | |
| 207 | + $namespaces = [ | |
| 208 | + 'FPFramework\\GeoIp2\\' => [ $base . 'Libs/Vendors/geoip2/geoip2/src/' ], | |
| 209 | + 'FPFramework\\' => [ $base ], | |
| 210 | + 'MaxMind\\Db\\' => [ $base . 'Libs/Vendors/maxmind-db/reader/src/MaxMind/Db/' ], | |
| 211 | + 'MaxMind\\' => [ $base . 'Libs/Vendors/maxmind/web-service-common/src/' ], | |
| 212 | + 'splitbrain\\PHPArchive\\' => [$base . 'Libs/Vendors/splitbrain/php-archive/src/' ], | |
| 213 | + ]; | |
| 214 | + | |
| 215 | + $found = false; | |
| 216 | + foreach ($namespaces as $key => $value) | |
| 216 | 217 | { |
| 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 | - ]; | |
| 218 | + if (strpos($class, $key) === 0) | |
| 219 | + { | |
| 220 | + $found = true; | |
| 221 | + break; | |
| 222 | + } | |
| 226 | 223 | } |
| 227 | 224 | |
| 228 | - foreach ($namespaces as $prefix => $dir) | |
| 225 | + if (!$found) | |
| 229 | 226 | { |
| 230 | - if (strpos($class, $prefix) === 0) | |
| 231 | - { | |
| 232 | - $file = $dir . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php'; | |
| 227 | + return; | |
| 228 | + } | |
| 229 | + | |
| 230 | + $class = firepluginsframework_fixClassBasedOnNamespace($namespaces, $class); | |
| 233 | 231 | |
| 234 | - if (file_exists($file)) | |
| 235 | - { | |
| 236 | - require_once $file; | |
| 237 | - } | |
| 232 | + $file = str_replace('\\', '/', $class) . '.php'; | |
| 238 | 233 | |
| 239 | - return; | |
| 240 | - } | |
| 234 | + if (file_exists($file)) | |
| 235 | + { | |
| 236 | + require_once $file; | |
| 241 | 237 | } |
| 242 | 238 | } |
| 243 | 239 | ); |
| 244 | - | |
| 240 | + | |
| 245 | 241 | // load once |
| 246 | 242 | if (FPF_LOADED == $priority) |
| 247 | 243 | { |
| 248 | 244 | /** |
| @@ -258,4 +254,41 @@ | ||
| 258 | 254 | do_action('fpf_admin_init'); |
| 259 | 255 | } |
| 260 | 256 | } |
| 261 | 257 | }, firepluginsframework_getFrameworkPriority(dirname(__DIR__))); |
| 258 | + | |
| 259 | +if (!function_exists('firepluginsframework_load_textdomain')) | |
| 260 | +{ | |
| 261 | + /** | |
| 262 | + * Load textdomain of plugin | |
| 263 | + * | |
| 264 | + * @return void | |
| 265 | + */ | |
| 266 | + function firepluginsframework_load_textdomain($dir) | |
| 267 | + { | |
| 268 | + load_plugin_textdomain('fpf-framework', false, $dir . '/Framework/languages/'); | |
| 269 | + } | |
| 270 | +} | |
| 271 | + | |
| 272 | +if (!function_exists('firepluginsframework_fixClassBasedOnNamespace')) | |
| 273 | +{ | |
| 274 | + /** | |
| 275 | + * Fixes the class paths | |
| 276 | + * | |
| 277 | + * @param string $namespaces | |
| 278 | + * @param string $class | |
| 279 | + * | |
| 280 | + * @return void | |
| 281 | + */ | |
| 282 | + function firepluginsframework_fixClassBasedOnNamespace($namespaces, $class) | |
| 283 | + { | |
| 284 | + foreach ($namespaces as $key => $value) | |
| 285 | + { | |
| 286 | + if (strpos($class, $key) !== FALSE) | |
| 287 | + { | |
| 288 | + $class = str_replace($key, $value[0], $class); | |
| 289 | + } | |
| 290 | + } | |
| 291 | + | |
| 292 | + return $class; | |
| 293 | + } | |
| 294 | +} | |