| @@ -1,15 +1,21 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FirePlugins Framework |
| 4 | - * @version 1.0.27 | |
| 4 | + * @version 1.2.6 | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2022 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 | +if (!function_exists('add_action')) | |
| 13 | +{ | |
| 14 | + // We are running outside of the context of WordPress. | |
| 15 | + return; | |
| 16 | +} | |
| 17 | + | |
| 12 | 18 | if (!function_exists('firepluginsframework_getFrameworkVersion')) |
| 13 | 19 | { |
| 14 | 20 | /** |
| 15 | 21 | * Return the framework version |
| @@ -19,16 +25,24 @@ | ||
| 19 | 25 | * @return void |
| 20 | 26 | */ |
| 21 | 27 | function firepluginsframework_getFrameworkVersion($dir) |
| 22 | 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 | + | |
| 23 | 37 | $framework_file = 'framework.xml'; |
| 24 | - | |
| 38 | + | |
| 25 | 39 | $xmlFile = $dir . '/Framework/' . $framework_file; |
| 26 | - | |
| 40 | + | |
| 27 | 41 | /** |
| 28 | 42 | * On development the xml file is located in /framework/source/framework.xml. |
| 29 | 43 | * On final zip, the file will rest on /Framework/framework.xml. |
| 30 | - * | |
| 44 | + * | |
| 31 | 45 | * Thus the check below. |
| 32 | 46 | */ |
| 33 | 47 | $xmlFile = file_exists($xmlFile) ? $xmlFile : $dir . '/source/' . $framework_file; |
| 34 | 48 | |
| @@ -39,9 +53,9 @@ | ||
| 39 | 53 | { |
| 40 | 54 | $xml = simplexml_load_file($xmlFile); |
| 41 | 55 | } |
| 42 | 56 | |
| 43 | - return isset($xml->version) ? (string) $xml->version : '1.0.0'; | |
| 57 | + return ($versions[$dir] = isset($xml->version) ? (string) $xml->version : '1.0.0'); | |
| 44 | 58 | } |
| 45 | 59 | } |
| 46 | 60 | |
| 47 | 61 | if (!function_exists('firepluginsframework_getFrameworkPriority')) |
| @@ -54,14 +68,32 @@ | ||
| 54 | 68 | * @return void |
| 55 | 69 | */ |
| 56 | 70 | function firepluginsframework_getFrameworkPriority($dir) |
| 57 | 71 | { |
| 58 | - $max_int_size = PHP_INT_MAX; | |
| 72 | + static $priorities = []; | |
| 59 | 73 | |
| 74 | + if (isset($priorities[$dir])) | |
| 75 | + { | |
| 76 | + return $priorities[$dir]; | |
| 77 | + } | |
| 78 | + | |
| 60 | 79 | $version = firepluginsframework_getFrameworkVersion($dir); |
| 61 | - $version = str_replace('.', '', $version); | |
| 80 | + $version = array_map('intval', array_pad(explode('.', $version), 3, 0)); | |
| 62 | 81 | |
| 63 | - return $max_int_size - (int) $version; | |
| 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); | |
| 64 | 96 | } |
| 65 | 97 | } |
| 66 | 98 | |
| 67 | 99 | /** |
| @@ -75,14 +107,8 @@ | ||
| 75 | 107 | { |
| 76 | 108 | return; |
| 77 | 109 | } |
| 78 | 110 | |
| 79 | - if (!function_exists('add_action')) | |
| 80 | - { | |
| 81 | - // We are running outside of the context of WordPress. | |
| 82 | - return; | |
| 83 | - } | |
| 84 | - | |
| 85 | 111 | $version = firepluginsframework_getFrameworkVersion(dirname(__DIR__)); |
| 86 | 112 | $priority = firepluginsframework_getFrameworkPriority(dirname(__DIR__)); |
| 87 | 113 | |
| 88 | 114 | // Framework priority |
| @@ -123,9 +149,9 @@ | ||
| 123 | 149 | |
| 124 | 150 | // Support URL |
| 125 | 151 | if (!defined('FPF_SUPPORT_URL')) |
| 126 | 152 | { |
| 127 | - define('FPF_SUPPORT_URL', FPF_SITE_URL . 'contact'); | |
| 153 | + define('FPF_SUPPORT_URL', FPF_SITE_URL . 'contact/'); | |
| 128 | 154 | } |
| 129 | 155 | |
| 130 | 156 | // Site Tower Endpoint |
| 131 | 157 | if (!defined('FPF_TOWER_ENDPOINT')) |
| @@ -132,14 +158,32 @@ | ||
| 132 | 158 | { |
| 133 | 159 | define('FPF_TOWER_ENDPOINT', FPF_SITE_URL . 'wp-json/tower/v1/'); |
| 134 | 160 | } |
| 135 | 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 | + | |
| 136 | 174 | // URL to retrieve templates |
| 137 | 175 | if (!defined('FPF_TEMPLATES_GET_URL')) |
| 138 | 176 | { |
| 139 | - define('FPF_TEMPLATES_GET_URL', FPF_TOWER_ENDPOINT . 'templates/{{PLUGIN}}/{{LICENSE_KEY}}/{{SITE_URL}}/get'); | |
| 177 | + define('FPF_TEMPLATES_GET_URL', FPF_TEMPLATES_TOWER_ENDPOINT . 'templates/{{PLUGIN}}/{{LICENSE_KEY}}/{{PLUGIN_VERSION}}/{{SITE_URL}}/get'); | |
| 140 | 178 | } |
| 141 | 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 | + | |
| 142 | 186 | /** |
| 143 | 187 | * Get License Version URL |
| 144 | 188 | */ |
| 145 | 189 | if (!defined('FPF_GET_LICENSE_VERSION_URL')) |
| @@ -154,10 +198,8 @@ | ||
| 154 | 198 | { |
| 155 | 199 | define('FPF_PLUGIN_CHANGELOG_URL', FPF_SITE_URL . '%s/changelog/'); |
| 156 | 200 | } |
| 157 | 201 | |
| 158 | - firepluginsframework_load_textdomain(dirname(__DIR__)); | |
| 159 | - | |
| 160 | 202 | // Now kick off the class autoloader. |
| 161 | 203 | spl_autoload_register( |
| 162 | 204 | /** |
| 163 | 205 | * Autoload classes |
| @@ -167,44 +209,40 @@ | ||
| 167 | 209 | * @return void |
| 168 | 210 | */ |
| 169 | 211 | function ($class) |
| 170 | 212 | { |
| 171 | - $base = dirname(__FILE__) . '/Inc/'; | |
| 213 | + static $namespaces = null; | |
| 172 | 214 | |
| 173 | - $namespaces = [ | |
| 174 | - 'FPFramework\\' => [ $base ], | |
| 175 | - 'GeoIp2\\' => [ $base . 'Libs/Vendors/geoip2/geoip2/src/' ], | |
| 176 | - 'MaxMind\\Db\\' => [ $base . 'Libs/Vendors/maxmind-db/reader/src/MaxMind/Db/' ], | |
| 177 | - 'MaxMind\\' => [ $base . 'Libs/Vendors/maxmind/web-service-common/src/' ], | |
| 178 | - 'splitbrain\\PHPArchive\\' => [$base . 'Libs/Vendors/splitbrain/php-archive/src/' ], | |
| 179 | - ]; | |
| 180 | - | |
| 181 | - $found = false; | |
| 182 | - foreach ($namespaces as $key => $value) | |
| 215 | + if ($namespaces === null) | |
| 183 | 216 | { |
| 184 | - if (strpos($class, $key) === 0) | |
| 185 | - { | |
| 186 | - $found = true; | |
| 187 | - break; | |
| 188 | - } | |
| 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 | + ]; | |
| 189 | 226 | } |
| 190 | 227 | |
| 191 | - if (!$found) | |
| 228 | + foreach ($namespaces as $prefix => $dir) | |
| 192 | 229 | { |
| 193 | - return; | |
| 194 | - } | |
| 195 | - | |
| 196 | - $class = firepluginsframework_fixClassBasedOnNamespace($namespaces, $class); | |
| 230 | + if (strpos($class, $prefix) === 0) | |
| 231 | + { | |
| 232 | + $file = $dir . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php'; | |
| 197 | 233 | |
| 198 | - $file = str_replace('\\', '/', $class) . '.php'; | |
| 234 | + if (file_exists($file)) | |
| 235 | + { | |
| 236 | + require_once $file; | |
| 237 | + } | |
| 199 | 238 | |
| 200 | - if (file_exists($file)) | |
| 201 | - { | |
| 202 | - require_once $file; | |
| 239 | + return; | |
| 240 | + } | |
| 203 | 241 | } |
| 204 | 242 | } |
| 205 | 243 | ); |
| 206 | - | |
| 244 | + | |
| 207 | 245 | // load once |
| 208 | 246 | if (FPF_LOADED == $priority) |
| 209 | 247 | { |
| 210 | 248 | /** |
| @@ -220,41 +258,4 @@ | ||
| 220 | 258 | do_action('fpf_admin_init'); |
| 221 | 259 | } |
| 222 | 260 | } |
| 223 | 261 | }, firepluginsframework_getFrameworkPriority(dirname(__DIR__))); |
| 224 | - | |
| 225 | -if (!function_exists('firepluginsframework_load_textdomain')) | |
| 226 | -{ | |
| 227 | - /** | |
| 228 | - * Load textdomain of plugin | |
| 229 | - * | |
| 230 | - * @return void | |
| 231 | - */ | |
| 232 | - function firepluginsframework_load_textdomain($dir) | |
| 233 | - { | |
| 234 | - load_plugin_textdomain('fpf-framework', false, $dir . '/Framework/languages/'); | |
| 235 | - } | |
| 236 | -} | |
| 237 | - | |
| 238 | -if (!function_exists('firepluginsframework_fixClassBasedOnNamespace')) | |
| 239 | -{ | |
| 240 | - /** | |
| 241 | - * Fixes the class paths | |
| 242 | - * | |
| 243 | - * @param string $namespaces | |
| 244 | - * @param string $class | |
| 245 | - * | |
| 246 | - * @return void | |
| 247 | - */ | |
| 248 | - function firepluginsframework_fixClassBasedOnNamespace($namespaces, $class) | |
| 249 | - { | |
| 250 | - foreach ($namespaces as $key => $value) | |
| 251 | - { | |
| 252 | - if (strpos($class, $key) !== FALSE) | |
| 253 | - { | |
| 254 | - $class = str_replace($key, $value[0], $class); | |
| 255 | - } | |
| 256 | - } | |
| 257 | - | |
| 258 | - return $class; | |
| 259 | - } | |
| 260 | -} | |