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