| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.0.22 |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2022 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
if (!function_exists('firepluginsframework_getFrameworkVersion')) |
| 13 |
{ |
| 14 |
/** |
| 15 |
* Return the framework version |
| 16 |
* |
| 17 |
* @param string $dir |
| 18 |
* |
| 19 |
* @return void |
| 20 |
*/ |
| 21 |
function firepluginsframework_getFrameworkVersion($dir) |
| 22 |
{ |
| 23 |
$framework_file = '/framework.xml'; |
| 24 |
|
| 25 |
$xmlFile = $dir . '/Framework/' . $framework_file; |
| 26 |
|
| 27 |
/** |
| 28 |
* On development the xml file is located in /framework/source/framework.xml. |
| 29 |
* On final zip, the file will rest on /Framework/framework.xml. |
| 30 |
* |
| 31 |
* Thus the check below. |
| 32 |
*/ |
| 33 |
$xmlFile = file_exists($xmlFile) ? $xmlFile : $dir . '/source' . $framework_file; |
| 34 |
|
| 35 |
$xml = []; |
| 36 |
|
| 37 |
// load XML file |
| 38 |
if (function_exists('simplexml_load_file')) |
| 39 |
{ |
| 40 |
$xml = simplexml_load_file($xmlFile); |
| 41 |
} |
| 42 |
|
| 43 |
return isset($xml->version) ? (string) $xml->version : '1.0.0'; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
if (!function_exists('firepluginsframework_getFrameworkPriority')) |
| 48 |
{ |
| 49 |
/** |
| 50 |
* Return the framework priority |
| 51 |
* |
| 52 |
* @param string $dir |
| 53 |
* |
| 54 |
* @return void |
| 55 |
*/ |
| 56 |
function firepluginsframework_getFrameworkPriority($dir) |
| 57 |
{ |
| 58 |
$max_int_size = PHP_INT_MAX; |
| 59 |
|
| 60 |
$version = firepluginsframework_getFrameworkVersion($dir); |
| 61 |
$version = str_replace('.', '', $version); |
| 62 |
|
| 63 |
return $max_int_size - (int) $version; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Initialize the Framework |
| 69 |
* |
| 70 |
* @return void |
| 71 |
*/ |
| 72 |
add_action( 'init', function() |
| 73 |
{ |
| 74 |
if (class_exists('\FPFramework\Framework')) |
| 75 |
{ |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
if (!function_exists('add_action')) |
| 80 |
{ |
| 81 |
// We are running outside of the context of WordPress. |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
$version = firepluginsframework_getFrameworkVersion(dirname(__DIR__)); |
| 86 |
$priority = firepluginsframework_getFrameworkPriority(dirname(__DIR__)); |
| 87 |
|
| 88 |
// Framework priority |
| 89 |
if (!defined('FPF_LOADED')) |
| 90 |
{ |
| 91 |
define('FPF_LOADED', $priority); |
| 92 |
} |
| 93 |
|
| 94 |
// Framework version |
| 95 |
if (!defined('FPF_VERSION')) |
| 96 |
{ |
| 97 |
define('FPF_VERSION', $version); |
| 98 |
} |
| 99 |
|
| 100 |
// Site URL |
| 101 |
if (!defined('FPF_SITE_URL')) |
| 102 |
{ |
| 103 |
define('FPF_SITE_URL', 'https://www.fireplugins.com/'); |
| 104 |
} |
| 105 |
|
| 106 |
// Site Tower Endpoint |
| 107 |
if (!defined('FPF_TOWER_ENDPOINT')) |
| 108 |
{ |
| 109 |
define('FPF_TOWER_ENDPOINT', FPF_SITE_URL . 'wp-json/tower/v1/'); |
| 110 |
} |
| 111 |
|
| 112 |
// URL to retrieve templates |
| 113 |
if (!defined('FPF_TEMPLATES_GET_URL')) |
| 114 |
{ |
| 115 |
define('FPF_TEMPLATES_GET_URL', FPF_TOWER_ENDPOINT . 'templates/{{PLUGIN}}/{{LICENSE_KEY}}/{{SITE_URL}}/get'); |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Get License Version URL |
| 120 |
*/ |
| 121 |
if (!defined( 'FPF_GET_LICENSE_VERSION_URL' )) { |
| 122 |
define ( 'FPF_GET_LICENSE_VERSION_URL' , FPF_TOWER_ENDPOINT . 'plugins/get_version/'); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Plugin Changelog URL |
| 127 |
*/ |
| 128 |
if (!defined( 'FPF_PLUGIN_CHANGELOG_URL' )) { |
| 129 |
define ( 'FPF_PLUGIN_CHANGELOG_URL' , FPF_SITE_URL . '%s/changelog/'); |
| 130 |
} |
| 131 |
|
| 132 |
firepluginsframework_load_textdomain(dirname(__DIR__)); |
| 133 |
|
| 134 |
// Include helper functions. |
| 135 |
require_once 'Inc/Framework.php'; |
| 136 |
|
| 137 |
// Now kick off the class autoloader. |
| 138 |
spl_autoload_register( |
| 139 |
/** |
| 140 |
* Autoload classes |
| 141 |
* |
| 142 |
* @param string $class |
| 143 |
* |
| 144 |
* @return void |
| 145 |
*/ |
| 146 |
function ($class) |
| 147 |
{ |
| 148 |
$base = dirname(__FILE__) . '/Inc/'; |
| 149 |
|
| 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) |
| 160 |
{ |
| 161 |
if (strpos($class, $key) === 0) |
| 162 |
{ |
| 163 |
$found = true; |
| 164 |
break; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
if (!$found) |
| 169 |
{ |
| 170 |
return; |
| 171 |
} |
| 172 |
|
| 173 |
$class = firepluginsframework_fixClassBasedOnNamespace($namespaces, $class); |
| 174 |
|
| 175 |
$file = str_replace('\\', '/', $class) . '.php'; |
| 176 |
|
| 177 |
if (file_exists($file)) |
| 178 |
{ |
| 179 |
require_once $file; |
| 180 |
} |
| 181 |
} |
| 182 |
); |
| 183 |
|
| 184 |
// load once |
| 185 |
if (FPF_LOADED == $priority) |
| 186 |
{ |
| 187 |
/** |
| 188 |
* Fires when FPFramework is included/loaded |
| 189 |
*/ |
| 190 |
do_action('fpf_init'); |
| 191 |
|
| 192 |
if (is_admin()) |
| 193 |
{ |
| 194 |
/** |
| 195 |
* Fires on the admin side when FPFramework is included/loaded. |
| 196 |
*/ |
| 197 |
do_action('fpf_admin_init'); |
| 198 |
} |
| 199 |
} |
| 200 |
}, 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 |
} |