bdthemes-element-pack-lite
Last commit date
assets
4 years ago
base
4 years ago
includes
4 years ago
languages
4 years ago
modules
4 years ago
traits
4 years ago
bdthemes-element-pack-lite.php
4 years ago
loader.php
4 years ago
readme.txt
4 years ago
loader.php
398 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ElementPack; |
| 4 | |
| 5 | use Elementor\Utils; |
| 6 | use ElementPack\Includes\Element_Pack_WPML; |
| 7 | use ElementPack\Includes\Feeds; |
| 8 | |
| 9 | if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 10 | |
| 11 | /** |
| 12 | * Main class for element pack |
| 13 | */ |
| 14 | class Element_Pack_Loader { |
| 15 | |
| 16 | /** |
| 17 | * @var Element_Pack_Loader |
| 18 | */ |
| 19 | private static $_instance; |
| 20 | |
| 21 | /** |
| 22 | * @var Manager |
| 23 | */ |
| 24 | private $_modules_manager; |
| 25 | |
| 26 | private $classes_aliases = [ |
| 27 | 'ElementPack\Modules\PanelPostsControl\Module' => 'ElementPack\Modules\QueryControl\Module', |
| 28 | 'ElementPack\Modules\PanelPostsControl\Controls\Group_Control_Posts' => 'ElementPack\Modules\QueryControl\Controls\Group_Control_Posts', |
| 29 | 'ElementPack\Modules\PanelPostsControl\Controls\Query' => 'ElementPack\Modules\QueryControl\Controls\Query', |
| 30 | ]; |
| 31 | |
| 32 | public $elements_data = [ |
| 33 | 'sections' => [], |
| 34 | 'columns' => [], |
| 35 | 'widgets' => [], |
| 36 | ]; |
| 37 | |
| 38 | /** |
| 39 | * @deprecated |
| 40 | * |
| 41 | * @return string |
| 42 | */ |
| 43 | public function get_version() { |
| 44 | return BDTEP_VER; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * return active theme |
| 49 | */ |
| 50 | public function get_theme() { |
| 51 | return wp_get_theme(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Throw error on object clone |
| 56 | * |
| 57 | * The whole idea of the singleton design pattern is that there is a single |
| 58 | * object therefore, we don't want the object to be cloned. |
| 59 | * |
| 60 | * @since 1.0.0 |
| 61 | * @return void |
| 62 | */ |
| 63 | public function __clone() { |
| 64 | // Cloning instances of the class is forbidden |
| 65 | _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin’ huh?', 'bdthemes-element-pack-lite'), '1.6.0'); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Disable unserializing of the class |
| 70 | * |
| 71 | * @since 1.0.0 |
| 72 | * @return void |
| 73 | */ |
| 74 | public function __wakeup() { |
| 75 | // Unserializing instances of the class is forbidden |
| 76 | _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin’ huh?', 'bdthemes-element-pack-lite'), '1.6.0'); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @return \Elementor\Element_Pack_Loader |
| 81 | */ |
| 82 | |
| 83 | public static function elementor() { |
| 84 | return \Elementor\Plugin::$instance; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @return Element_Pack_Loader |
| 89 | */ |
| 90 | public static function instance() { |
| 91 | if (is_null(self::$_instance)) { |
| 92 | self::$_instance = new self(); |
| 93 | } |
| 94 | |
| 95 | return self::$_instance; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | |
| 100 | /** |
| 101 | * we loaded module manager + admin php from here |
| 102 | * @return [type] [description] |
| 103 | */ |
| 104 | private function _includes() { |
| 105 | |
| 106 | $live_copy = element_pack_option('live_copy', 'element_pack_other_settings', 'off'); |
| 107 | |
| 108 | // Dynamic Select control |
| 109 | require BDTEP_INC_PATH . 'controls/select-input/dynamic-select-input-module.php'; |
| 110 | require BDTEP_INC_PATH . 'controls/select-input/dynamic-select.php'; |
| 111 | |
| 112 | // Global Controls |
| 113 | require_once BDTEP_PATH . 'traits/global-widget-controls.php'; |
| 114 | require_once BDTEP_PATH . 'traits/global-swiper-controls.php'; |
| 115 | require_once BDTEP_PATH . 'traits/global-mask-controls.php'; |
| 116 | |
| 117 | require BDTEP_INC_PATH . 'modules-manager.php'; |
| 118 | require BDTEP_INC_PATH . 'class-elements-wpml-compatibility.php'; |
| 119 | |
| 120 | // Live copy paste from demo website |
| 121 | if ($live_copy == 'on') { |
| 122 | require BDTEP_INC_PATH . 'live-copy/class-live-copy.php'; |
| 123 | } |
| 124 | |
| 125 | // Rooten theme header footer compatibility |
| 126 | if ('Rooten' === $this->get_theme()->name or 'Rooten' === $this->get_theme()->parent_theme) { |
| 127 | if (!class_exists('RootenCustomTemplate')) { |
| 128 | require BDTEP_INC_PATH . 'class-rooten-theme-compatibility.php'; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // editor template library |
| 133 | $template_library = element_pack_option('template_library', 'element_pack_other_settings', 'off'); |
| 134 | if (!defined('BDTEP_CH') and $template_library == 'on') { |
| 135 | require(BDTEP_INC_PATH . 'template-library/editor/init.php'); |
| 136 | } |
| 137 | |
| 138 | |
| 139 | if (is_admin()) { |
| 140 | if (!defined('BDTEP_CH')) { |
| 141 | require(BDTEP_INC_PATH . 'admin.php'); |
| 142 | // require(BDTEP_INC_PATH . 'admin-feeds.php'); |
| 143 | require(BDTEP_INC_PATH . 'template-library/template-library-base.php'); |
| 144 | require(BDTEP_INC_PATH . 'template-library/editor/manager/api.php'); |
| 145 | // Load admin class for admin related content process |
| 146 | new Admin(); |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Autoloader function for all classes files |
| 153 | * @param [type] class [description] |
| 154 | * @return [type] [description] |
| 155 | */ |
| 156 | public function autoload($class) { |
| 157 | if (0 !== strpos($class, __NAMESPACE__)) { |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | $has_class_alias = isset($this->classes_aliases[$class]); |
| 162 | |
| 163 | // Backward Compatibility: Save old class name for set an alias after the new class is loaded |
| 164 | if ($has_class_alias) { |
| 165 | $class_alias_name = $this->classes_aliases[$class]; |
| 166 | $class_to_load = $class_alias_name; |
| 167 | } else { |
| 168 | $class_to_load = $class; |
| 169 | } |
| 170 | |
| 171 | if (!class_exists($class_to_load)) { |
| 172 | $filename = strtolower( |
| 173 | preg_replace( |
| 174 | ['/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/'], |
| 175 | ['', '$1-$2', '-', DIRECTORY_SEPARATOR], |
| 176 | $class_to_load |
| 177 | ) |
| 178 | ); |
| 179 | $filename = BDTEP_PATH . $filename . '.php'; |
| 180 | |
| 181 | if (is_readable($filename)) { |
| 182 | include($filename); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | if ($has_class_alias) { |
| 187 | class_alias($class_alias_name, $class); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Register all script that need for any specific widget on call basis. |
| 193 | * @return [type] [description] |
| 194 | */ |
| 195 | public function register_site_scripts() { |
| 196 | |
| 197 | $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
| 198 | $settings = get_option('element_pack_api_settings'); |
| 199 | |
| 200 | wp_register_script('bdt-uikit-icons', BDTEP_URL . 'assets/js/bdt-uikit-icons' . $suffix . '.js', ['jquery', 'bdt-uikit'], '3.0.3', true); |
| 201 | wp_register_script('image-compare-viewer', BDTEP_URL . 'assets/vendor/js/image-compare-viewer' . $suffix . '.js', ['jquery'], '0.1.0', true); |
| 202 | wp_register_script('jclock', BDTEP_URL . 'assets/vendor/js/jquery.jclock' . $suffix . '.js', ['jquery'], '0.0.1', true); |
| 203 | wp_register_script('eventmove', BDTEP_URL . 'assets/vendor/js/jquery.event.move' . $suffix . '.js', ['jquery'], '2.0.0', true); |
| 204 | wp_register_script('aspieprogress', BDTEP_URL . 'assets/vendor/js/jquery-asPieProgress' . $suffix . '.js', ['jquery'], '0.4.7', true); |
| 205 | wp_register_script('cookieconsent', BDTEP_URL . 'assets/vendor/js/cookieconsent' . $suffix . '.js', ['jquery'], '3.1.0', true); |
| 206 | wp_register_script('imagezoom', BDTEP_ASSETS_URL . 'vendor/js/jquery.imagezoom' . $suffix . '.js', ['jquery'], null, true); |
| 207 | wp_register_script('popper', BDTEP_ASSETS_URL . 'vendor/js/popper' . $suffix . '.js', ['jquery'], null, true); |
| 208 | wp_register_script('tippyjs', BDTEP_ASSETS_URL . 'vendor/js/tippy.all' . $suffix . '.js', ['jquery'], null, true); |
| 209 | wp_register_script('leaflet', BDTEP_ASSETS_URL . 'vendor/js/leaflet' . $suffix . '.js', ['jquery'], '', true); |
| 210 | |
| 211 | |
| 212 | wp_register_script('recaptcha', 'https://www.google.com/recaptcha/api.js', ['jquery'], null, true); |
| 213 | |
| 214 | wp_register_script('tilt', BDTEP_URL . 'assets/vendor/js/tilt.jquery' . $suffix . '.js', ['jquery'], null, true); |
| 215 | wp_register_script('bdt-justified-gallery', BDTEP_URL . 'assets/vendor/js/jquery.justifiedGallery' . $suffix . '.js', ['jquery'], '1.0.0', true); |
| 216 | |
| 217 | wp_register_script('progressHorizontal', BDTEP_ASSETS_URL . 'vendor/js/jquery.progressHorizontal' . $suffix . '.js', ['jquery'], '2.0.2', true); |
| 218 | wp_register_script('progressScroll', BDTEP_ASSETS_URL . 'vendor/js/jquery.progressScroll' . $suffix . '.js', ['jquery'], '2.0.2', true); |
| 219 | wp_register_script('bdt-parallax', BDTEP_ASSETS_URL . 'vendor/js/parallax' . $suffix . '.js', ['jquery'], null, true); |
| 220 | } |
| 221 | |
| 222 | public function register_site_styles() { |
| 223 | $direction_suffix = is_rtl() ? '.rtl' : ''; |
| 224 | |
| 225 | wp_register_style('ep-all-styles', BDTEP_URL . 'assets/css/ep-all-styles' . $direction_suffix . '.css', [], BDTEP_VER); |
| 226 | |
| 227 | wp_register_style('imagezoom', BDTEP_ASSETS_URL . 'css/imagezoom' . $direction_suffix . '.css', [], BDTEP_VER); |
| 228 | wp_register_style('cookieconsent', BDTEP_URL . 'assets/css/cookieconsent' . $direction_suffix . '.css', [], BDTEP_VER); |
| 229 | wp_register_style('element-pack-font', BDTEP_ASSETS_URL . 'css/element-pack-font' . $direction_suffix . '.css', [], BDTEP_VER); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Loading site related style from here. |
| 234 | * @return [type] [description] |
| 235 | */ |
| 236 | public function enqueue_site_styles() { |
| 237 | |
| 238 | $direction_suffix = is_rtl() ? '.rtl' : ''; |
| 239 | wp_enqueue_style('bdt-uikit', BDTEP_ASSETS_URL . 'css/bdt-uikit' . $direction_suffix . '.css', [], '3.2'); |
| 240 | wp_enqueue_style('element-pack-site', BDTEP_ASSETS_URL . 'css/element-pack-site' . $direction_suffix . '.css', [], BDTEP_VER); |
| 241 | } |
| 242 | |
| 243 | |
| 244 | /** |
| 245 | * Loading site related script that needs all time such as uikit. |
| 246 | * @return [type] [description] |
| 247 | */ |
| 248 | public function enqueue_site_scripts() { |
| 249 | |
| 250 | $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
| 251 | |
| 252 | wp_enqueue_script('bdt-uikit', BDTEP_URL . 'assets/js/bdt-uikit' . $suffix . '.js', ['jquery'], BDTEP_VER); |
| 253 | wp_enqueue_script('element-pack-site', BDTEP_URL . 'assets/js/element-pack-site' . $suffix . '.js', ['jquery', 'elementor-frontend'], BDTEP_VER); |
| 254 | |
| 255 | $script_config = [ |
| 256 | 'ajaxurl' => admin_url('admin-ajax.php'), |
| 257 | 'nonce' => wp_create_nonce('element-pack-site'), |
| 258 | 'contact_form' => [ |
| 259 | 'sending_msg' => esc_html_x('Sending message please wait...', 'Contact Form String', 'bdthemes-element-pack-lite'), |
| 260 | 'captcha_nd' => esc_html_x('Invisible captcha not defined!', 'Contact Form String', 'bdthemes-element-pack-lite'), |
| 261 | 'captcha_nr' => esc_html_x('Could not get invisible captcha response!', 'Contact Form String', 'bdthemes-element-pack-lite'), |
| 262 | |
| 263 | ], |
| 264 | 'elements_data' => $this->elements_data, |
| 265 | ]; |
| 266 | |
| 267 | |
| 268 | // localize for user login widget ajax login script |
| 269 | wp_localize_script('bdt-uikit', 'element_pack_ajax_login_config', array( |
| 270 | 'ajaxurl' => admin_url('admin-ajax.php'), |
| 271 | 'loadingmessage' => esc_html__('Sending user info, please wait...', 'bdthemes-element-pack-lite'), |
| 272 | )); |
| 273 | |
| 274 | $script_config = apply_filters('element_pack/frontend/localize_settings', $script_config); |
| 275 | |
| 276 | // TODO for editor script |
| 277 | wp_localize_script('bdt-uikit', 'ElementPackConfig', $script_config); |
| 278 | } |
| 279 | |
| 280 | public function enqueue_admin_scripts() { |
| 281 | |
| 282 | $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
| 283 | |
| 284 | wp_enqueue_script('element-pack-admin', BDTEP_URL . 'assets/js/element-pack-admin' . $suffix . '.js', ['jquery'], BDTEP_VER, true); |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Load editor editor related style from here |
| 289 | * @return [type] [description] |
| 290 | */ |
| 291 | public function enqueue_preview_styles() { |
| 292 | $direction_suffix = is_rtl() ? '.rtl' : ''; |
| 293 | |
| 294 | wp_enqueue_style('element-pack-preview', BDTEP_URL . 'assets/css/element-pack-preview' . $direction_suffix . '.css', '', BDTEP_VER); |
| 295 | } |
| 296 | |
| 297 | |
| 298 | public function enqueue_editor_styles() { |
| 299 | $direction_suffix = is_rtl() ? '.rtl' : ''; |
| 300 | |
| 301 | wp_enqueue_style('element-pack-editor', BDTEP_URL . 'assets/css/element-pack-editor' . $direction_suffix . '.css', '', BDTEP_VER); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | /** |
| 306 | * Callback to shortcode. |
| 307 | * @param array $atts attributes for shortcode. |
| 308 | */ |
| 309 | public function shortcode_template($atts) { |
| 310 | |
| 311 | $atts = shortcode_atts( |
| 312 | array( |
| 313 | 'id' => '', |
| 314 | ), |
| 315 | $atts, |
| 316 | 'rooten_custom_template' |
| 317 | ); |
| 318 | |
| 319 | $id = !empty($atts['id']) ? intval($atts['id']) : ''; |
| 320 | |
| 321 | if (empty($id)) { |
| 322 | return ''; |
| 323 | } |
| 324 | |
| 325 | if (class_exists('\Elementor\Post_CSS_File')) { |
| 326 | |
| 327 | // Load elementor styles. |
| 328 | $css_file = new \Elementor\Post_CSS_File($id); |
| 329 | $css_file->enqueue(); |
| 330 | } |
| 331 | |
| 332 | return self::$elementor_instance->frontend->get_builder_content_for_display($id); |
| 333 | } |
| 334 | |
| 335 | |
| 336 | // Load WPML compatibility instance |
| 337 | public function wpml_compatiblity() { |
| 338 | return Element_Pack_WPML::get_instance(); |
| 339 | } |
| 340 | |
| 341 | |
| 342 | /** |
| 343 | * initialize the category |
| 344 | * @return [type] [description] |
| 345 | */ |
| 346 | public function element_pack_init() { |
| 347 | $this->_modules_manager = new Manager(); |
| 348 | |
| 349 | $elementor = \Elementor\Plugin::$instance; |
| 350 | |
| 351 | // Add element category in panel |
| 352 | $elementor->elements_manager->add_category(BDTEP_SLUG, ['title' => BDTEP_TITLE, 'icon' => 'font'], 1); |
| 353 | |
| 354 | do_action('bdthemes_element_pack/init'); |
| 355 | } |
| 356 | |
| 357 | private function setup_hooks() { |
| 358 | add_action('elementor/init', [$this, 'element_pack_init']); |
| 359 | add_action('elementor/editor/after_enqueue_styles', [$this, 'enqueue_editor_styles']); |
| 360 | |
| 361 | add_action('elementor/frontend/before_register_styles', [$this, 'register_site_styles']); |
| 362 | add_action('elementor/frontend/before_register_scripts', [$this, 'register_site_scripts']); |
| 363 | |
| 364 | add_action('elementor/preview/enqueue_styles', [$this, 'enqueue_preview_styles']); |
| 365 | |
| 366 | add_action('elementor/frontend/after_register_styles', [$this, 'enqueue_site_styles']); |
| 367 | add_action('elementor/frontend/before_enqueue_scripts', [$this, 'enqueue_site_scripts']); |
| 368 | |
| 369 | add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']); |
| 370 | |
| 371 | add_shortcode('rooten_custom_template', array($this, 'shortcode_template')); |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * Element_Pack_Loader constructor. |
| 376 | */ |
| 377 | private function __construct() { |
| 378 | // Register class automatically |
| 379 | spl_autoload_register([$this, 'autoload']); |
| 380 | // Include some backend files |
| 381 | $this->_includes(); |
| 382 | // Finally hooked up all things here |
| 383 | $this->setup_hooks(); |
| 384 | |
| 385 | $this->wpml_compatiblity()->init(); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | if (!defined('BDTEP_TESTS')) { |
| 390 | // In tests we run the instance manually. |
| 391 | Element_Pack_Loader::instance(); |
| 392 | } |
| 393 | |
| 394 | // handy fundtion for push data |
| 395 | function element_pack_config() { |
| 396 | return Element_Pack_Loader::instance(); |
| 397 | } |
| 398 |