| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimateStoreKit; |
| 4 |
|
| 5 |
use Elementor\Plugin; |
| 6 |
use Elementor\Core\Kits\Documents\Kit; |
| 7 |
use UltimateStoreKit\Manager; |
| 8 |
use UltimateStoreKit\Admin\Dashboard; |
| 9 |
|
| 10 |
if (!defined('ABSPATH')) |
| 11 |
exit; // Exit if accessed directly |
| 12 |
|
| 13 |
/** |
| 14 |
* Main class for element pack |
| 15 |
*/ |
| 16 |
class Ultimate_Store_Kit_Loader { |
| 17 |
/** |
| 18 |
* @var Ultimate_Store_Kit_Loader |
| 19 |
*/ |
| 20 |
private static $_instance; |
| 21 |
|
| 22 |
/** |
| 23 |
* @var Manager |
| 24 |
*/ |
| 25 |
private $_modules_manager; |
| 26 |
|
| 27 |
private $classes_aliases = [ |
| 28 |
'UltimateStoreKit\Modules\PanelPostsControl\Module' => 'UltimateStoreKit\Modules\QueryControl\Module', |
| 29 |
'UltimateStoreKit\Modules\PanelPostsControl\Controls\Group_Control_Posts' => 'UltimateStoreKit\Modules\QueryControl\Controls\Group_Control_Posts', |
| 30 |
'UltimateStoreKit\Modules\PanelPostsControl\Controls\Query' => 'UltimateStoreKit\Modules\QueryControl\Controls\Query', |
| 31 |
]; |
| 32 |
|
| 33 |
public $elements_data = [ |
| 34 |
'sections' => [], |
| 35 |
'columns' => [], |
| 36 |
'widgets' => [], |
| 37 |
]; |
| 38 |
|
| 39 |
/** |
| 40 |
* @return string |
| 41 |
* @deprecated |
| 42 |
* |
| 43 |
*/ |
| 44 |
public function get_version() { |
| 45 |
return BDTUSK_VER; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* return active theme |
| 50 |
*/ |
| 51 |
public function get_theme() { |
| 52 |
return wp_get_theme(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Throw error on object clone |
| 57 |
* |
| 58 |
* The whole idea of the singleton design pattern is that there is a single |
| 59 |
* object therefore, we don't want the object to be cloned. |
| 60 |
* |
| 61 |
* @return void |
| 62 |
* @since 1.0.0 |
| 63 |
*/ |
| 64 |
public function __clone() { |
| 65 |
// Cloning instances of the class is forbidden |
| 66 |
_doing_it_wrong(__FUNCTION__, esc_html__('Cheatin’ huh?', 'ultimate-store-kit'), '1.6.0'); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Disable unserializing of the class |
| 71 |
* |
| 72 |
* @return void |
| 73 |
* @since 1.0.0 |
| 74 |
*/ |
| 75 |
public function __wakeup() { |
| 76 |
// Unserializing instances of the class is forbidden |
| 77 |
_doing_it_wrong(__FUNCTION__, esc_html__('Cheatin’ huh?', 'ultimate-store-kit'), '1.6.0'); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* @return Plugin |
| 82 |
*/ |
| 83 |
|
| 84 |
public static function elementor() { |
| 85 |
return Plugin::$instance; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* @return Ultimate_Store_Kit_Loader |
| 90 |
*/ |
| 91 |
public static function instance() { |
| 92 |
if (is_null(self::$_instance)) { |
| 93 |
self::$_instance = new self(); |
| 94 |
} |
| 95 |
|
| 96 |
do_action('bdthemes_ultimate_store_kit/init'); |
| 97 |
return self::$_instance; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
/** |
| 102 |
* we loaded module manager + admin php from here |
| 103 |
* @return [type] [description] |
| 104 |
*/ |
| 105 |
private function _includes() { |
| 106 |
|
| 107 |
// require_once BDTUSK_ADMIN_PATH . 'module-settings.php'; |
| 108 |
// ======================== |
| 109 |
// Helper for global usec |
| 110 |
//========================== |
| 111 |
require(BDTUSK_PATH . 'base/support/helpers.php'); |
| 112 |
//=========================== |
| 113 |
// WISHLIST |
| 114 |
//=========================== |
| 115 |
require(BDTUSK_INC_PATH . 'wishlist-compare.php'); |
| 116 |
//=========================== |
| 117 |
// WISHLIST |
| 118 |
//=========================== |
| 119 |
|
| 120 |
|
| 121 |
// all widgets control from here |
| 122 |
// require BDTUSK_INC_PATH . 'global-controls.php'; |
| 123 |
require BDTUSK_INC_PATH . 'modules-manager.php'; |
| 124 |
// Dynamic Select control |
| 125 |
// require BDTUSK_INC_PATH . 'controls/group-query/group-control-query.php'; |
| 126 |
require BDTUSK_INC_PATH . 'controls/select-input/dynamic-select-input-module.php'; |
| 127 |
require BDTUSK_INC_PATH . 'controls/select-input/dynamic-select.php'; |
| 128 |
|
| 129 |
|
| 130 |
require_once 'includes/modal/modal-settings.php'; |
| 131 |
|
| 132 |
|
| 133 |
//GLOBAL CONTROLS |
| 134 |
require_once BDTUSK_PATH . 'traits/global-widget-controls.php'; |
| 135 |
require_once BDTUSK_PATH . 'traits/global-widget-template.php'; |
| 136 |
|
| 137 |
// GRID TEMPLATES |
| 138 |
require_once BDTUSK_PATH . 'templates/shiny-grid.php'; |
| 139 |
require_once BDTUSK_PATH . 'templates/florence-grid.php'; |
| 140 |
require_once BDTUSK_PATH . 'templates/glossy-grid.php'; |
| 141 |
if (class_exists('woocommerce')) { |
| 142 |
require_once BDTUSK_PATH . 'includes/builder/loading-builder.php'; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Autoloader function for all classes files |
| 148 |
* @param [type] string |
| 149 |
* @return [type] [description] |
| 150 |
*/ |
| 151 |
public function autoload($class) { |
| 152 |
if (0 !== strpos($class, __NAMESPACE__)) { |
| 153 |
return; |
| 154 |
} |
| 155 |
|
| 156 |
$has_class_alias = isset($this->classes_aliases[$class]); |
| 157 |
|
| 158 |
// Backward Compatibility: Save old class name for set an alias after the new class is loaded |
| 159 |
if ($has_class_alias) { |
| 160 |
$class_alias_name = $this->classes_aliases[$class]; |
| 161 |
$class_to_load = $class_alias_name; |
| 162 |
} else { |
| 163 |
$class_to_load = $class; |
| 164 |
} |
| 165 |
|
| 166 |
if (!class_exists($class_to_load)) { |
| 167 |
$filename = strtolower( |
| 168 |
preg_replace( |
| 169 |
['/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/'], |
| 170 |
['', '$1-$2', '-', DIRECTORY_SEPARATOR], |
| 171 |
$class_to_load |
| 172 |
) |
| 173 |
); |
| 174 |
$filename = BDTUSK_PATH . $filename . '.php'; |
| 175 |
|
| 176 |
if (is_readable($filename)) { |
| 177 |
include($filename); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
if ($has_class_alias) { |
| 182 |
class_alias($class_alias_name, $class); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* Register all script that need for any specific widget on call basis. |
| 188 |
* @return [type] [description] |
| 189 |
*/ |
| 190 |
public function register_site_scripts() { |
| 191 |
wp_register_script('datatables', BDTUSK_ASSETS_URL . 'vendor/js/datatables.js', [], '1.0.0', true); |
| 192 |
wp_register_script('micromodal', BDTUSK_ASSETS_URL . 'vendor/js/micromodal.js', [], '1.0.0', true); |
| 193 |
wp_register_script('usk-accordion', BDTUSK_ASSETS_URL . 'vendor/js/accordion.js', [], '1.0.0', true); |
| 194 |
|
| 195 |
if (ultimate_store_kit_is_widget_enabled('image-hotspot')) { |
| 196 |
wp_register_script('popper', BDTUSK_ASSETS_URL . 'vendor/js/popper.min.js', ['jquery'], null, true); |
| 197 |
wp_register_script('tippyjs', BDTUSK_ASSETS_URL . 'vendor/js/tippy.all.min.js', ['jquery'], null, true); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
public function register_site_styles() { |
| 202 |
$direction_suffix = is_rtl() ? '.rtl' : ''; |
| 203 |
wp_register_style('usk-all-styles', BDTUSK_URL . 'assets/css/all-styles' . $direction_suffix . '.css', [], BDTUSK_VER); |
| 204 |
wp_register_style('usk-font', BDTUSK_URL . 'assets/css/font' . $direction_suffix . '.css', [], BDTUSK_VER); |
| 205 |
|
| 206 |
if (ultimate_store_kit_is_widget_enabled('image-hotspot')) { |
| 207 |
wp_register_style('tippy', BDTUSK_URL . 'assets/css/tippy' . $direction_suffix . '.css', [], BDTUSK_VER); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Loading site related style from here. |
| 213 |
* @return [type] [description] |
| 214 |
*/ |
| 215 |
public function enqueue_site_styles() { |
| 216 |
|
| 217 |
$direction_suffix = is_rtl() ? '.rtl' : ''; |
| 218 |
|
| 219 |
wp_register_style('usk-site', BDTUSK_ASSETS_URL . 'css/site' . $direction_suffix . '.css', [], BDTUSK_VER); |
| 220 |
wp_register_style('slick-modal', BDTUSK_ASSETS_URL . 'vendor/css/slickmodal.css', [], BDTUSK_VER); |
| 221 |
wp_register_style('toolslide-css', BDTUSK_ASSETS_URL . 'vendor/css/toolslide.css', [], BDTUSK_VER); |
| 222 |
|
| 223 |
wp_enqueue_style('usk-site'); |
| 224 |
wp_enqueue_style('slick-modal'); |
| 225 |
wp_enqueue_style('toolslide-css'); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
/** |
| 230 |
* Loading site related script that needs all time such as uikit. |
| 231 |
* @return [type] [description] |
| 232 |
*/ |
| 233 |
public function enqueue_site_scripts() { |
| 234 |
|
| 235 |
wp_register_script('usk-core', BDTUSK_ASSETS_URL . 'js/core.js', ['jquery'], BDTUSK_VER, true); // tooltip file should be separate |
| 236 |
wp_register_script('usk-site', BDTUSK_ASSETS_URL . 'js/site.js', ['jquery'], BDTUSK_VER, true); // tooltip file should be separate |
| 237 |
wp_register_script('slick-modal', BDTUSK_ASSETS_URL . 'vendor/js/jquery.slickmodal.js', ['jquery'], BDTUSK_VER, true); // tooltip file should be separate |
| 238 |
wp_register_script('toolslide-js', BDTUSK_ASSETS_URL . 'vendor/js/toolslide.js', [], BDTUSK_VER, true); // tooltip file should be separate |
| 239 |
|
| 240 |
wp_enqueue_script('usk-core'); |
| 241 |
// wp_enqueue_script('usk-site'); |
| 242 |
wp_enqueue_script('slick-modal'); |
| 243 |
wp_enqueue_script('toolslide-js'); |
| 244 |
|
| 245 |
wp_localize_script('usk-core', 'ultimate_store_kit_ajax_config', array( |
| 246 |
'ajaxurl' => admin_url('admin-ajax.php'), |
| 247 |
// Only consumed for logged-in requests — see WishlistCompare::verify_request(). |
| 248 |
'nonce' => wp_create_nonce('usk_wishlist_compare'), |
| 249 |
)); |
| 250 |
} |
| 251 |
|
| 252 |
public function enqueue_editor_scripts() { |
| 253 |
|
| 254 |
wp_register_script('usk-editor', BDTUSK_ASSETS_URL . 'js/editor.js', ['backbone-marionette', 'elementor-common-modules', 'elementor-editor-modules',], BDTUSK_VER, true); |
| 255 |
|
| 256 |
wp_enqueue_script('usk-editor'); |
| 257 |
|
| 258 |
$_is_usk_pro_activated = false; |
| 259 |
if (function_exists('usk_license_validation') && true === usk_license_validation()) { |
| 260 |
$_is_usk_pro_activated = true; |
| 261 |
} |
| 262 |
|
| 263 |
$localize_data = [ |
| 264 |
'pro_installed' => _is_usk_pro_activated(), |
| 265 |
'pro_license_activated' => $_is_usk_pro_activated, |
| 266 |
'promotional_widgets' => [], |
| 267 |
]; |
| 268 |
|
| 269 |
if (!$_is_usk_pro_activated) { |
| 270 |
$pro_widget_map = new \UltimateStoreKit\Includes\Pro_Widget_Map(); |
| 271 |
$localize_data['promotional_widgets'] = $pro_widget_map->get_pro_widget_map(); |
| 272 |
} |
| 273 |
|
| 274 |
wp_localize_script('usk-editor', 'UltimateStoreKitConfigEditor', $localize_data); |
| 275 |
} |
| 276 |
|
| 277 |
public function enqueue_admin_scripts() { |
| 278 |
wp_register_script('usk-admin', BDTUSK_ASSETS_URL . 'js/admin.js', ['jquery'], BDTUSK_VER, true); |
| 279 |
wp_enqueue_script('usk-admin'); |
| 280 |
} |
| 281 |
|
| 282 |
public function enqueue_editor_styles() { |
| 283 |
$direction_suffix = is_rtl() ? '.rtl' : ''; |
| 284 |
|
| 285 |
wp_register_style('usk-editor', BDTUSK_ASSETS_URL . 'css/editor' . $direction_suffix . '.css', [], BDTUSK_VER); |
| 286 |
wp_register_style('usk-font', BDTUSK_ASSETS_URL . 'css/font' . $direction_suffix . '.css', [], BDTUSK_VER); |
| 287 |
|
| 288 |
wp_enqueue_style('usk-editor'); |
| 289 |
wp_enqueue_style('usk-font'); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
public function ultimate_store_kit_init() { |
| 295 |
$this->_modules_manager = new Manager(); |
| 296 |
$this->ultimate_store_kit_modal_settings_init(); |
| 297 |
do_action('bdthemes_ultimate_store_kit/init'); |
| 298 |
} |
| 299 |
|
| 300 |
/** |
| 301 |
* initialize the category |
| 302 |
* @return [type] [description] |
| 303 |
*/ |
| 304 |
public function ultimate_store_kit_category_register() { |
| 305 |
|
| 306 |
$elementor = Plugin::$instance; |
| 307 |
|
| 308 |
$new_category = [ |
| 309 |
'ultimate-store-kit-single' => [ |
| 310 |
'title' => 'Ultimate Store Kit (Single)', |
| 311 |
'icon' => 'font', |
| 312 |
], |
| 313 |
'ultimate-store-kit-my-account' => [ |
| 314 |
'title' => 'Ultimate Store Kit (Account)', |
| 315 |
'icon' => 'font', |
| 316 |
], |
| 317 |
'ultimate-store-kit-checkout' => [ |
| 318 |
'title' => 'Ultimate Store Kit (Checkout)', |
| 319 |
'icon' => 'font', |
| 320 |
'active' => false, |
| 321 |
], |
| 322 |
'ultimate-store-kit-order-thankyou' => [ |
| 323 |
'title' => 'Ultimate Store Kit (ThankYou)', |
| 324 |
'icon' => 'font', |
| 325 |
'active' => false, |
| 326 |
], |
| 327 |
]; |
| 328 |
|
| 329 |
$existing_categories = $elementor->elements_manager->get_categories(); |
| 330 |
$merged_categories = $new_category + $existing_categories; |
| 331 |
|
| 332 |
/** |
| 333 |
* Override categories using reflection (since it's private) |
| 334 |
*/ |
| 335 |
$reflection = new \ReflectionClass($elementor->elements_manager); |
| 336 |
$property = $reflection->getProperty('categories'); |
| 337 |
// $property->setAccessible(true); |
| 338 |
$property->setValue($elementor->elements_manager, $merged_categories); |
| 339 |
|
| 340 |
|
| 341 |
$elementor->elements_manager->add_category(BDTUSK_SLUG, ['title' => BDTUSK_TITLE, 'icon' => 'font']); |
| 342 |
} |
| 343 |
|
| 344 |
/** |
| 345 |
* Setup all hooks here |
| 346 |
* @return [type] [description] |
| 347 |
*/ |
| 348 |
private function setup_hooks() { |
| 349 |
add_filter('body_class', [$this, 'add_body_classes']); |
| 350 |
add_action('elementor/elements/categories_registered', [$this, 'ultimate_store_kit_category_register'], 1, 1); |
| 351 |
add_action('elementor/init', [$this, 'ultimate_store_kit_init']); |
| 352 |
add_action('elementor/editor/after_enqueue_styles', [$this, 'enqueue_editor_styles']); |
| 353 |
|
| 354 |
add_action('wp_enqueue_scripts', [$this, 'register_site_styles'], 99999); |
| 355 |
add_action('wp_enqueue_scripts', [$this, 'register_site_scripts'], 99999); |
| 356 |
add_action('wp_enqueue_scripts', [$this, 'enqueue_site_styles'], 99999); |
| 357 |
add_action('wp_enqueue_scripts', [$this, 'enqueue_site_scripts'], 99999); |
| 358 |
|
| 359 |
add_action('elementor/editor/after_enqueue_scripts', [$this, 'enqueue_editor_scripts']); |
| 360 |
add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']); |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
public function add_body_classes($classes) { |
| 365 |
$single_page_checkout_classes = ['ultimate-store-kit']; |
| 366 |
return is_array($classes) |
| 367 |
? array_merge($classes, $single_page_checkout_classes) |
| 368 |
: $classes . ' ' . implode(' ', $single_page_checkout_classes); |
| 369 |
} |
| 370 |
|
| 371 |
public function ultimate_store_kit_modal_settings_init() { |
| 372 |
require 'includes/modal/modal-controls.php'; |
| 373 |
add_action('elementor/kit/register_tabs', function (Kit $kit) { |
| 374 |
$kit->register_tab('ultimate-store-kit-modal', Includes\Settings\Settings_Modal::class); |
| 375 |
}, 1, 40); |
| 376 |
} |
| 377 |
|
| 378 |
public function init() { |
| 379 |
if (!defined('BDTUSK_CH') && is_admin()) { |
| 380 |
Dashboard::get_instance(); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
/** |
| 385 |
* Ultimate_Store_Kit_Loader constructor. |
| 386 |
*/ |
| 387 |
private function __construct() { |
| 388 |
// Register class automatically |
| 389 |
spl_autoload_register([$this, 'autoload']); |
| 390 |
// Include some backend files |
| 391 |
$this->_includes(); |
| 392 |
|
| 393 |
// Finally hooked up all things here |
| 394 |
$this->setup_hooks(); |
| 395 |
|
| 396 |
// Register REST API routes unconditionally (outside is_admin) |
| 397 |
\UltimateStoreKit\API\Settings::get_instance(); |
| 398 |
|
| 399 |
add_action('init', [$this, 'init']); |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
if (!defined('BDTUSK_TESTS')) { |
| 404 |
// In tests we run the instance manually. |
| 405 |
Ultimate_Store_Kit_Loader::instance(); |
| 406 |
} |
| 407 |
|
| 408 |
// handy fundtion for push data |
| 409 |
function ultimate_store_kit_config() { |
| 410 |
return Ultimate_Store_Kit_Loader::instance(); |
| 411 |
} |
| 412 |
|