bdthemes-prime-slider-lite
Last commit date
admin
3 years ago
assets
3 years ago
base
3 years ago
freemius
3 years ago
includes
3 years ago
languages
3 years ago
modules
3 years ago
traits
3 years ago
bdthemes-prime-slider.php
3 years ago
changelog.txt
3 years ago
loader.php
3 years ago
readme.txt
3 years ago
loader.php
412 lines
| 1 | <?php |
| 2 | |
| 3 | namespace PrimeSlider; |
| 4 | |
| 5 | use Elementor\Plugin ; |
| 6 | if ( !defined( 'ABSPATH' ) ) { |
| 7 | exit; |
| 8 | } |
| 9 | // Exit if accessed directly |
| 10 | /** |
| 11 | * Main class for element pack |
| 12 | */ |
| 13 | class Prime_Slider_Loader |
| 14 | { |
| 15 | /** |
| 16 | * @var Prime_Slider_Loader |
| 17 | */ |
| 18 | private static $_instance ; |
| 19 | /** |
| 20 | * @var Manager |
| 21 | */ |
| 22 | private $_modules_manager ; |
| 23 | private $classes_aliases = array( |
| 24 | 'PrimeSlider\\Modules\\PanelPostsControl\\Module' => 'PrimeSlider\\Modules\\QueryControl\\Module', |
| 25 | 'PrimeSlider\\Modules\\PanelPostsControl\\Controls\\Group_Control_Posts' => 'PrimeSlider\\Modules\\QueryControl\\Controls\\Group_Control_Posts', |
| 26 | 'PrimeSlider\\Modules\\PanelPostsControl\\Controls\\Query' => 'PrimeSlider\\Modules\\QueryControl\\Controls\\Query', |
| 27 | ) ; |
| 28 | public $elements_data = array( |
| 29 | 'sections' => array(), |
| 30 | 'columns' => array(), |
| 31 | 'widgets' => array(), |
| 32 | ) ; |
| 33 | /** |
| 34 | * @deprecated |
| 35 | * |
| 36 | * @return string |
| 37 | */ |
| 38 | public function get_version() |
| 39 | { |
| 40 | return BDTPS_VER; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Throw error on object clone |
| 45 | * |
| 46 | * The whole idea of the singleton design pattern is that there is a single |
| 47 | * object therefore, we don't want the object to be cloned. |
| 48 | * |
| 49 | * @since 1.0.0 |
| 50 | * @return void |
| 51 | */ |
| 52 | public function __clone() |
| 53 | { |
| 54 | // Cloning instances of the class is forbidden |
| 55 | _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'bdthemes-prime-slider' ), '1.6.0' ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Disable unserializing of the class |
| 60 | * |
| 61 | * @since 1.0.0 |
| 62 | * @return void |
| 63 | */ |
| 64 | public function __wakeup() |
| 65 | { |
| 66 | // Unserializing instances of the class is forbidden |
| 67 | _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'bdthemes-prime-slider' ), '1.6.0' ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @return Plugin |
| 72 | */ |
| 73 | public static function elementor() |
| 74 | { |
| 75 | return Plugin::$instance; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @return Prime_Slider_Loader |
| 80 | */ |
| 81 | public static function instance() |
| 82 | { |
| 83 | if ( is_null( self::$_instance ) ) { |
| 84 | self::$_instance = new self(); |
| 85 | } |
| 86 | return self::$_instance; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * we loaded module manager + admin php from here |
| 91 | * @return [type] [description] |
| 92 | */ |
| 93 | private function _includes() |
| 94 | { |
| 95 | $duplicator = prime_slider_option( 'duplicator', 'prime_slider_other_settings', 'off' ); |
| 96 | $live_copy = prime_slider_option( 'live-copy', 'prime_slider_other_settings', 'off' ); |
| 97 | // Admin settings controller |
| 98 | require_once BDTPS_ADMIN_PATH . 'module-settings.php'; |
| 99 | //Assets Manager |
| 100 | // require_once 'admin/optimizer/asset-minifier-manager.php'; |
| 101 | // Dynamic Select control |
| 102 | require BDTPS_PATH . 'traits/query-controls/select-input/dynamic-select-input-module.php'; |
| 103 | require BDTPS_PATH . 'traits/query-controls/select-input/dynamic-select.php'; |
| 104 | // Global Controls |
| 105 | require_once BDTPS_PATH . 'traits/global-widget-controls.php'; |
| 106 | //require_once BDTPS_PATH . 'traits/global-swiper-controls.php'; |
| 107 | //require_once BDTPS_PATH . 'traits/global-mask-controls.php'; |
| 108 | require BDTPS_PATH . 'includes/modules-manager.php'; |
| 109 | if ( !class_exists( 'BdThemes_Duplicator' ) ) { |
| 110 | if ( $duplicator == 'on' ) { |
| 111 | require BDTPS_PATH . 'includes/class-duplicator.php'; |
| 112 | } |
| 113 | } |
| 114 | if ( !class_exists( 'BdThemes_Live_Copy' ) ) { |
| 115 | if ( $live_copy == 'on' && !is_plugin_active( 'live-copy-paste/live-copy-paste.php' ) ) { |
| 116 | require_once BDTPS_PATH . 'includes/live-copy/class-live-copy.php'; |
| 117 | } |
| 118 | } |
| 119 | if ( ps_is_dashboard_enabled() ) { |
| 120 | |
| 121 | if ( is_admin() ) { |
| 122 | // Load admin class for admin related content process |
| 123 | require_once BDTPS_ADMIN_PATH . 'admin.php'; |
| 124 | // require BDTPS_PATH . 'includes/admin-feeds.php'; |
| 125 | new Admin(); |
| 126 | } |
| 127 | |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Autoloader function for all classes files |
| 133 | * @param [type] $class [description] |
| 134 | * @return [type] [description] |
| 135 | */ |
| 136 | public function autoload( $class ) |
| 137 | { |
| 138 | if ( 0 !== strpos( $class, __NAMESPACE__ ) ) { |
| 139 | return; |
| 140 | } |
| 141 | $has_class_alias = isset( $this->classes_aliases[$class] ); |
| 142 | // Backward Compatibility: Save old class name for set an alias after the new class is loaded |
| 143 | |
| 144 | if ( $has_class_alias ) { |
| 145 | $class_alias_name = $this->classes_aliases[$class]; |
| 146 | $class_to_load = $class_alias_name; |
| 147 | } else { |
| 148 | $class_to_load = $class; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | if ( !class_exists( $class_to_load ) ) { |
| 153 | $filename = strtolower( preg_replace( [ |
| 154 | '/^' . __NAMESPACE__ . '\\\\/', |
| 155 | '/([a-z])([A-Z])/', |
| 156 | '/_/', |
| 157 | '/\\\\/' |
| 158 | ], [ |
| 159 | '', |
| 160 | '$1-$2', |
| 161 | '-', |
| 162 | DIRECTORY_SEPARATOR |
| 163 | ], $class_to_load ) ); |
| 164 | $filename = BDTPS_PATH . $filename . '.php'; |
| 165 | if ( is_readable( $filename ) ) { |
| 166 | include $filename; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | if ( $has_class_alias ) { |
| 171 | class_alias( $class_alias_name, $class ); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Register all script that need for any specific widget on call basis. |
| 177 | * @return [type] [description] |
| 178 | */ |
| 179 | public function register_site_scripts() |
| 180 | { |
| 181 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ); |
| 182 | //TODO more attractive animation |
| 183 | //Thirdparty widgets |
| 184 | |
| 185 | if ( prime_slider_is_widget_enabled( 'multiscroll' ) ) { |
| 186 | wp_register_script( |
| 187 | 'jquery-multiscroll', |
| 188 | BDTPS_ASSETS_URL . 'vendor/js/jquery.multiscroll.min.js', |
| 189 | [ 'jquery', 'elementor-frontend' ], |
| 190 | BDTPS_VER, |
| 191 | true |
| 192 | ); |
| 193 | wp_register_script( |
| 194 | 'easings', |
| 195 | BDTPS_ASSETS_URL . 'vendor/js/jquery.easings.min.js', |
| 196 | [ 'jquery', 'elementor-frontend' ], |
| 197 | BDTPS_VER, |
| 198 | true |
| 199 | ); |
| 200 | } |
| 201 | |
| 202 | if ( prime_slider_is_widget_enabled( 'pagepiling' ) ) { |
| 203 | wp_register_script( |
| 204 | 'jquery-pagepiling', |
| 205 | BDTPS_ASSETS_URL . 'vendor/js/jquery.pagepiling.min.js', |
| 206 | [ 'jquery', 'elementor-frontend' ], |
| 207 | BDTPS_VER, |
| 208 | true |
| 209 | ); |
| 210 | } |
| 211 | if ( prime_slider_is_widget_enabled( 'knily' ) or prime_slider_is_widget_enabled( 'woolamp' ) ) { |
| 212 | wp_register_script( |
| 213 | 'goodshare', |
| 214 | BDTPS_ASSETS_URL . 'vendor/js/goodshare.min.js', |
| 215 | [ 'jquery', 'elementor-frontend' ], |
| 216 | BDTPS_VER, |
| 217 | true |
| 218 | ); |
| 219 | } |
| 220 | |
| 221 | if ( prime_slider_is_widget_enabled( 'woocircle' ) ) { |
| 222 | wp_register_script( |
| 223 | 'classie', |
| 224 | BDTPS_ASSETS_URL . 'vendor/js/classie.min.js', |
| 225 | [ 'jquery', 'elementor-frontend' ], |
| 226 | BDTPS_VER, |
| 227 | true |
| 228 | ); |
| 229 | wp_register_script( |
| 230 | 'dynamics', |
| 231 | BDTPS_ASSETS_URL . 'vendor/js/dynamics.min.js', |
| 232 | [ 'jquery', 'elementor-frontend' ], |
| 233 | BDTPS_VER, |
| 234 | true |
| 235 | ); |
| 236 | } |
| 237 | |
| 238 | if ( prime_slider_is_widget_enabled( 'pieces' ) ) { |
| 239 | wp_register_script( |
| 240 | 'pieces', |
| 241 | BDTPS_ASSETS_URL . 'vendor/js/pieces.min.js', |
| 242 | [ 'jquery', 'elementor-frontend' ], |
| 243 | BDTPS_VER, |
| 244 | true |
| 245 | ); |
| 246 | } |
| 247 | wp_register_script( |
| 248 | 'bdt-parallax', |
| 249 | BDTPS_ASSETS_URL . 'vendor/js/parallax.min.js', |
| 250 | [ 'jquery' ], |
| 251 | null, |
| 252 | true |
| 253 | ); |
| 254 | } |
| 255 | |
| 256 | public function register_site_styles() |
| 257 | { |
| 258 | $direction_suffix = ( is_rtl() ? '.rtl' : '' ); |
| 259 | wp_register_style( |
| 260 | 'prime-slider-font', |
| 261 | BDTPS_ASSETS_URL . 'css/prime-slider-font' . $direction_suffix . '.css', |
| 262 | [], |
| 263 | BDTPS_VER |
| 264 | ); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Loading site related style from here. |
| 269 | * @return [type] [description] |
| 270 | */ |
| 271 | public function enqueue_site_styles() |
| 272 | { |
| 273 | $direction_suffix = ( is_rtl() ? '.rtl' : '' ); |
| 274 | wp_enqueue_style( |
| 275 | 'bdt-uikit', |
| 276 | BDTPS_ASSETS_URL . 'css/bdt-uikit' . $direction_suffix . '.css', |
| 277 | [], |
| 278 | '3.2' |
| 279 | ); |
| 280 | wp_enqueue_style( |
| 281 | 'prime-slider-site', |
| 282 | BDTPS_ASSETS_URL . 'css/prime-slider-site' . $direction_suffix . '.css', |
| 283 | [], |
| 284 | BDTPS_VER |
| 285 | ); |
| 286 | wp_register_style( |
| 287 | 'splitting', |
| 288 | BDTPS_ASSETS_URL . 'vendor/css/splitting' . $direction_suffix . '.css', |
| 289 | [], |
| 290 | BDTPS_VER |
| 291 | ); |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Loading site related script that needs all time such as uikit. |
| 296 | * @return [type] [description] |
| 297 | */ |
| 298 | public function enqueue_site_scripts() |
| 299 | { |
| 300 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ); |
| 301 | wp_enqueue_script( |
| 302 | 'bdt-uikit', |
| 303 | BDTPS_ASSETS_URL . 'js/bdt-uikit.min.js', |
| 304 | [ 'jquery' ], |
| 305 | '3.2' |
| 306 | ); |
| 307 | wp_enqueue_script( |
| 308 | 'prime-slider-site', |
| 309 | BDTPS_ASSETS_URL . 'js/prime-slider-site' . $suffix . '.js', |
| 310 | [ 'jquery', 'elementor-frontend' ], |
| 311 | BDTPS_VER |
| 312 | ); |
| 313 | } |
| 314 | |
| 315 | public function enqueue_editor_scripts() |
| 316 | { |
| 317 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ); |
| 318 | wp_enqueue_script( |
| 319 | 'prime-slider', |
| 320 | BDTPS_ASSETS_URL . 'js/prime-slider-editor' . $suffix . '.js', |
| 321 | [ 'backbone-marionette', 'elementor-common-modules', 'elementor-editor-modules' ], |
| 322 | BDTPS_VER, |
| 323 | true |
| 324 | ); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Load editor editor related style from here |
| 329 | * @return [type] [description] |
| 330 | */ |
| 331 | public function enqueue_preview_styles() |
| 332 | { |
| 333 | $direction_suffix = ( is_rtl() ? '.rtl' : '' ); |
| 334 | wp_enqueue_style( |
| 335 | 'prime-slider-preview', |
| 336 | BDTPS_ASSETS_URL . 'css/prime-slider-preview' . $direction_suffix . '.css', |
| 337 | '', |
| 338 | BDTPS_VER |
| 339 | ); |
| 340 | } |
| 341 | |
| 342 | public function enqueue_editor_styles() |
| 343 | { |
| 344 | $direction_suffix = ( is_rtl() ? '-rtl' : '' ); |
| 345 | wp_enqueue_style( |
| 346 | 'prime-slider-editor', |
| 347 | BDTPS_ASSETS_URL . 'css/prime-slider-editor' . $direction_suffix . '.css', |
| 348 | '', |
| 349 | BDTPS_VER |
| 350 | ); |
| 351 | wp_enqueue_style( |
| 352 | 'prime-slider-font', |
| 353 | BDTPS_ASSETS_URL . 'css/prime-slider-font' . $direction_suffix . '.css', |
| 354 | [], |
| 355 | BDTPS_VER |
| 356 | ); |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * initialize the category |
| 361 | * @return [type] [description] |
| 362 | */ |
| 363 | public function prime_slider_init() |
| 364 | { |
| 365 | $this->_modules_manager = new Manager(); |
| 366 | $elementor = Plugin::$instance; |
| 367 | // Add element category in panel |
| 368 | $elementor->elements_manager->add_category( BDTPS_SLUG, [ |
| 369 | 'title' => BDTPS_TITLE, |
| 370 | 'icon' => 'font', |
| 371 | ] ); |
| 372 | do_action( 'bdthemes_prime_slider/init' ); |
| 373 | } |
| 374 | |
| 375 | private function setup_hooks() |
| 376 | { |
| 377 | add_action( 'elementor/init', [ $this, 'prime_slider_init' ] ); |
| 378 | add_action( 'elementor/editor/after_enqueue_styles', [ $this, 'enqueue_editor_styles' ] ); |
| 379 | add_action( 'elementor/frontend/before_register_styles', [ $this, 'register_site_styles' ] ); |
| 380 | add_action( 'elementor/frontend/before_register_scripts', [ $this, 'register_site_scripts' ] ); |
| 381 | add_action( 'elementor/preview/enqueue_styles', [ $this, 'enqueue_preview_styles' ] ); |
| 382 | //add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] ); // TODO |
| 383 | add_action( 'elementor/frontend/after_register_styles', [ $this, 'enqueue_site_styles' ] ); |
| 384 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] ); |
| 385 | add_action( 'elementor/frontend/before_enqueue_scripts', [ $this, 'enqueue_site_scripts' ] ); |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Prime_Slider_Loader constructor. |
| 390 | * @throws \Exception |
| 391 | */ |
| 392 | private function __construct() |
| 393 | { |
| 394 | // Register class automatically |
| 395 | spl_autoload_register( [ $this, 'autoload' ] ); |
| 396 | // Include some backend files |
| 397 | $this->_includes(); |
| 398 | // Finally hooked up all things here |
| 399 | $this->setup_hooks(); |
| 400 | } |
| 401 | |
| 402 | } |
| 403 | if ( !defined( 'BDTPS_TESTS' ) ) { |
| 404 | // In tests we run the instance manually. |
| 405 | Prime_Slider_Loader::instance(); |
| 406 | } |
| 407 | // handy function for push data |
| 408 | function prime_slider_config() |
| 409 | { |
| 410 | return Prime_Slider_Loader::instance(); |
| 411 | } |
| 412 |