| @@ -1,15 +1,21 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FirePlugins Framework |
| 4 | - * @version 1.0.16 | |
| 4 | + * @version 1.2.6 | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2021 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,19 +25,27 @@ | ||
| 19 | 25 | * @return void |
| 20 | 26 | */ |
| 21 | 27 | function firepluginsframework_getFrameworkVersion($dir) |
| 22 | 28 | { |
| 23 | - $framework_file = '/framework.xml'; | |
| 24 | - | |
| 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 | + | |
| 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 | - $xmlFile = file_exists($xmlFile) ? $xmlFile : $dir . '/source' . $framework_file; | |
| 47 | + $xmlFile = file_exists($xmlFile) ? $xmlFile : $dir . '/source/' . $framework_file; | |
| 34 | 48 | |
| 35 | 49 | $xml = []; |
| 36 | 50 | |
| 37 | 51 | // load XML file |
| @@ -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 | /** |
| @@ -68,9 +100,9 @@ | ||
| 68 | 100 | * Initialize the Framework |
| 69 | 101 | * |
| 70 | 102 | * @return void |
| 71 | 103 | */ |
| 72 | -add_action( 'init', function() | |
| 104 | +add_action('init', function() | |
| 73 | 105 | { |
| 74 | 106 | if (class_exists('\FPFramework\Framework')) |
| 75 | 107 | { |
| 76 | 108 | return; |
| @@ -75,17 +107,11 @@ | ||
| 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 |
| 89 | 115 | if (!defined('FPF_LOADED')) |
| 90 | 116 | { |
| 91 | 117 | define('FPF_LOADED', $priority); |
| @@ -102,8 +128,32 @@ | ||
| 102 | 128 | { |
| 103 | 129 | define('FPF_SITE_URL', 'https://www.fireplugins.com/'); |
| 104 | 130 | } |
| 105 | 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 | + | |
| 106 | 156 | // Site Tower Endpoint |
| 107 | 157 | if (!defined('FPF_TOWER_ENDPOINT')) |
| 108 | 158 | { |
| 109 | 159 | define('FPF_TOWER_ENDPOINT', FPF_SITE_URL . 'wp-json/tower/v1/'); |
| @@ -108,33 +158,48 @@ | ||
| 108 | 158 | { |
| 109 | 159 | define('FPF_TOWER_ENDPOINT', FPF_SITE_URL . 'wp-json/tower/v1/'); |
| 110 | 160 | } |
| 111 | 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 | + | |
| 112 | 174 | // URL to retrieve templates |
| 113 | 175 | if (!defined('FPF_TEMPLATES_GET_URL')) |
| 114 | 176 | { |
| 115 | - 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'); | |
| 116 | 178 | } |
| 117 | 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 | + | |
| 118 | 186 | /** |
| 119 | 187 | * Get License Version URL |
| 120 | 188 | */ |
| 121 | - if (!defined( 'FPF_GET_LICENSE_VERSION_URL' )) { | |
| 122 | - define ( 'FPF_GET_LICENSE_VERSION_URL' , FPF_TOWER_ENDPOINT . 'plugins/get_version/'); | |
| 189 | + if (!defined('FPF_GET_LICENSE_VERSION_URL')) | |
| 190 | + { | |
| 191 | + define('FPF_GET_LICENSE_VERSION_URL', FPF_TOWER_ENDPOINT . 'plugins/get_version/'); | |
| 123 | 192 | } |
| 124 | 193 | |
| 125 | 194 | /** |
| 126 | 195 | * Plugin Changelog URL |
| 127 | 196 | */ |
| 128 | - if (!defined( 'FPF_PLUGIN_CHANGELOG_URL' )) { | |
| 129 | - define ( 'FPF_PLUGIN_CHANGELOG_URL' , FPF_SITE_URL . '%s/changelog/'); | |
| 197 | + if (!defined('FPF_PLUGIN_CHANGELOG_URL')) | |
| 198 | + { | |
| 199 | + define('FPF_PLUGIN_CHANGELOG_URL', FPF_SITE_URL . '%s/changelog/'); | |
| 130 | 200 | } |
| 131 | 201 | |
| 132 | - firepluginsframework_load_textdomain(dirname(__DIR__)); | |
| 133 | - | |
| 134 | - // Include helper functions. | |
| 135 | - require_once 'Inc/Framework.php'; | |
| 136 | - | |
| 137 | 202 | // Now kick off the class autoloader. |
| 138 | 203 | spl_autoload_register( |
| 139 | 204 | /** |
| 140 | 205 | * Autoload classes |
| @@ -144,44 +209,40 @@ | ||
| 144 | 209 | * @return void |
| 145 | 210 | */ |
| 146 | 211 | function ($class) |
| 147 | 212 | { |
| 148 | - $base = dirname(__FILE__) . '/Inc/'; | |
| 213 | + static $namespaces = null; | |
| 149 | 214 | |
| 150 | - $namespaces = [ | |
| 151 | - 'FPFramework\\' => [ $base ], | |
| 152 | - 'GeoIp2\\' => [ $base . 'Libs/Vendors/geoip2/geoip2/src/' ], | |
| 153 | - 'MaxMind\\Db\\' => [ $base . 'Libs/Vendors/maxmind-db/reader/src/MaxMind/Db/' ], | |
| 154 | - 'MaxMind\\' => [ $base . 'Libs/Vendors/maxmind/web-service-common/src/' ], | |
| 155 | - 'splitbrain\\PHPArchive\\' => [$base . 'Libs/Vendors/splitbrain/php-archive/src/' ], | |
| 156 | - ]; | |
| 157 | - | |
| 158 | - $found = false; | |
| 159 | - foreach ($namespaces as $key => $value) | |
| 215 | + if ($namespaces === null) | |
| 160 | 216 | { |
| 161 | - if (strpos($class, $key) === 0) | |
| 162 | - { | |
| 163 | - $found = true; | |
| 164 | - break; | |
| 165 | - } | |
| 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 | + ]; | |
| 166 | 226 | } |
| 167 | 227 | |
| 168 | - if (!$found) | |
| 228 | + foreach ($namespaces as $prefix => $dir) | |
| 169 | 229 | { |
| 170 | - return; | |
| 171 | - } | |
| 172 | - | |
| 173 | - $class = firepluginsframework_fixClassBasedOnNamespace($namespaces, $class); | |
| 230 | + if (strpos($class, $prefix) === 0) | |
| 231 | + { | |
| 232 | + $file = $dir . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php'; | |
| 174 | 233 | |
| 175 | - $file = str_replace('\\', '/', $class) . '.php'; | |
| 234 | + if (file_exists($file)) | |
| 235 | + { | |
| 236 | + require_once $file; | |
| 237 | + } | |
| 176 | 238 | |
| 177 | - if (file_exists($file)) | |
| 178 | - { | |
| 179 | - require_once $file; | |
| 239 | + return; | |
| 240 | + } | |
| 180 | 241 | } |
| 181 | 242 | } |
| 182 | 243 | ); |
| 183 | - | |
| 244 | + | |
| 184 | 245 | // load once |
| 185 | 246 | if (FPF_LOADED == $priority) |
| 186 | 247 | { |
| 187 | 248 | /** |
| @@ -197,41 +258,4 @@ | ||
| 197 | 258 | do_action('fpf_admin_init'); |
| 198 | 259 | } |
| 199 | 260 | } |
| 200 | 261 | }, firepluginsframework_getFrameworkPriority(dirname(__DIR__))); |
| 201 | - | |
| 202 | -if (!function_exists('firepluginsframework_load_textdomain')) | |
| 203 | -{ | |
| 204 | - /** | |
| 205 | - * Load textdomain of plugin | |
| 206 | - * | |
| 207 | - * @return void | |
| 208 | - */ | |
| 209 | - function firepluginsframework_load_textdomain($dir) | |
| 210 | - { | |
| 211 | - load_plugin_textdomain('fp-framework', false, $dir . '/Framework/languages/'); | |
| 212 | - } | |
| 213 | -} | |
| 214 | - | |
| 215 | -if (!function_exists('firepluginsframework_fixClassBasedOnNamespace')) | |
| 216 | -{ | |
| 217 | - /** | |
| 218 | - * Fixes the class paths | |
| 219 | - * | |
| 220 | - * @param string $namespaces | |
| 221 | - * @param string $class | |
| 222 | - * | |
| 223 | - * @return void | |
| 224 | - */ | |
| 225 | - function firepluginsframework_fixClassBasedOnNamespace($namespaces, $class) | |
| 226 | - { | |
| 227 | - foreach ($namespaces as $key => $value) | |
| 228 | - { | |
| 229 | - if (strpos($class, $key) !== FALSE) | |
| 230 | - { | |
| 231 | - $class = str_replace($key, $value[0], $class); | |
| 232 | - } | |
| 233 | - } | |
| 234 | - | |
| 235 | - return $class; | |
| 236 | - } | |
| 237 | -} | |