bdthemes-prime-slider-lite
Last commit date
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
395 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 | // Dynamic Select control |
| 96 | require BDTPS_PATH . 'traits/query-controls/select-input/dynamic-select-input-module.php'; |
| 97 | require BDTPS_PATH . 'traits/query-controls/select-input/dynamic-select.php'; |
| 98 | // Global Controls |
| 99 | require_once BDTPS_PATH . 'traits/global-widget-controls.php'; |
| 100 | //require_once BDTPS_PATH . 'traits/global-swiper-controls.php'; |
| 101 | //require_once BDTPS_PATH . 'traits/global-mask-controls.php'; |
| 102 | require BDTPS_PATH . 'includes/modules-manager.php'; |
| 103 | if ( ps_is_dashboard_enabled() ) { |
| 104 | |
| 105 | if ( is_admin() ) { |
| 106 | // Admin settings controller |
| 107 | require BDTPS_PATH . 'includes/class-settings-api.php'; |
| 108 | // Prime Slider admin settings here |
| 109 | require BDTPS_PATH . 'includes/admin-settings.php'; |
| 110 | // Load admin class for admin related content process |
| 111 | require BDTPS_PATH . 'includes/admin.php'; |
| 112 | require BDTPS_PATH . 'includes/admin-feeds.php'; |
| 113 | new Admin(); |
| 114 | new Prime_Slider_Admin_Feeds(); |
| 115 | } |
| 116 | |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Autoloader function for all classes files |
| 122 | * @param [type] $class [description] |
| 123 | * @return [type] [description] |
| 124 | */ |
| 125 | public function autoload( $class ) |
| 126 | { |
| 127 | if ( 0 !== strpos( $class, __NAMESPACE__ ) ) { |
| 128 | return; |
| 129 | } |
| 130 | $has_class_alias = isset( $this->classes_aliases[$class] ); |
| 131 | // Backward Compatibility: Save old class name for set an alias after the new class is loaded |
| 132 | |
| 133 | if ( $has_class_alias ) { |
| 134 | $class_alias_name = $this->classes_aliases[$class]; |
| 135 | $class_to_load = $class_alias_name; |
| 136 | } else { |
| 137 | $class_to_load = $class; |
| 138 | } |
| 139 | |
| 140 | |
| 141 | if ( !class_exists( $class_to_load ) ) { |
| 142 | $filename = strtolower( preg_replace( [ |
| 143 | '/^' . __NAMESPACE__ . '\\\\/', |
| 144 | '/([a-z])([A-Z])/', |
| 145 | '/_/', |
| 146 | '/\\\\/' |
| 147 | ], [ |
| 148 | '', |
| 149 | '$1-$2', |
| 150 | '-', |
| 151 | DIRECTORY_SEPARATOR |
| 152 | ], $class_to_load ) ); |
| 153 | $filename = BDTPS_PATH . $filename . '.php'; |
| 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 | //TODO more attractive animation |
| 172 | //Thirdparty widgets |
| 173 | wp_register_script( |
| 174 | 'jquery-multiscroll', |
| 175 | BDTPS_ASSETS_URL . 'vendor/js/jquery.multiscroll' . $suffix . '.js', |
| 176 | [ 'jquery', 'elementor-frontend' ], |
| 177 | BDTPS_VER, |
| 178 | true |
| 179 | ); |
| 180 | wp_register_script( |
| 181 | 'jquery-pagepiling', |
| 182 | BDTPS_ASSETS_URL . 'vendor/js/jquery.pagepiling' . $suffix . '.js', |
| 183 | [ 'jquery', 'elementor-frontend' ], |
| 184 | BDTPS_VER, |
| 185 | true |
| 186 | ); |
| 187 | wp_register_script( |
| 188 | 'easings', |
| 189 | BDTPS_ASSETS_URL . 'vendor/js/jquery.easings' . $suffix . '.js', |
| 190 | [ 'jquery', 'elementor-frontend' ], |
| 191 | BDTPS_VER, |
| 192 | true |
| 193 | ); |
| 194 | wp_register_script( |
| 195 | 'mThumbnailScroller', |
| 196 | BDTPS_ASSETS_URL . 'vendor/js/jquery.mThumbnailScroller' . $suffix . '.js', |
| 197 | [ 'jquery', 'elementor-frontend' ], |
| 198 | BDTPS_VER, |
| 199 | true |
| 200 | ); |
| 201 | wp_register_script( |
| 202 | 'goodshare', |
| 203 | BDTPS_ASSETS_URL . 'vendor/js/goodshare' . $suffix . '.js', |
| 204 | [ 'jquery', 'elementor-frontend' ], |
| 205 | BDTPS_VER, |
| 206 | true |
| 207 | ); |
| 208 | wp_register_script( |
| 209 | 'classie', |
| 210 | BDTPS_ASSETS_URL . 'vendor/js/classie' . $suffix . '.js', |
| 211 | [ 'jquery', 'elementor-frontend' ], |
| 212 | BDTPS_VER, |
| 213 | true |
| 214 | ); |
| 215 | wp_register_script( |
| 216 | 'dynamics', |
| 217 | BDTPS_ASSETS_URL . 'vendor/js/dynamics' . $suffix . '.js', |
| 218 | [ 'jquery', 'elementor-frontend' ], |
| 219 | BDTPS_VER, |
| 220 | true |
| 221 | ); |
| 222 | wp_register_script( |
| 223 | 'pieces', |
| 224 | BDTPS_ASSETS_URL . 'vendor/js/pieces' . $suffix . '.js', |
| 225 | [ 'jquery', 'elementor-frontend' ], |
| 226 | BDTPS_VER, |
| 227 | true |
| 228 | ); |
| 229 | wp_register_script( |
| 230 | 'bdt-parallax', |
| 231 | BDTPS_ASSETS_URL . 'vendor/js/parallax' . $suffix . '.js', |
| 232 | [ 'jquery' ], |
| 233 | null, |
| 234 | true |
| 235 | ); |
| 236 | } |
| 237 | |
| 238 | public function register_site_styles() |
| 239 | { |
| 240 | $direction_suffix = ( is_rtl() ? '.rtl' : '' ); |
| 241 | wp_register_script( |
| 242 | 'bdt-uikit-icons', |
| 243 | BDTPS_ASSETS_URL . 'js/bdt-uikit-icons' . $direction_suffix . '.js', |
| 244 | [ 'jquery', 'bdt-uikit' ], |
| 245 | '3.5.5', |
| 246 | true |
| 247 | ); |
| 248 | wp_register_style( |
| 249 | 'prime-slider-font', |
| 250 | BDTPS_ASSETS_URL . 'css/prime-slider-font' . $direction_suffix . '.css', |
| 251 | [], |
| 252 | BDTPS_VER |
| 253 | ); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Loading site related style from here. |
| 258 | * @return [type] [description] |
| 259 | */ |
| 260 | public function enqueue_site_styles() |
| 261 | { |
| 262 | $direction_suffix = ( is_rtl() ? '.rtl' : '' ); |
| 263 | wp_enqueue_style( |
| 264 | 'bdt-uikit', |
| 265 | BDTPS_ASSETS_URL . 'css/bdt-uikit' . $direction_suffix . '.css', |
| 266 | [], |
| 267 | '3.2' |
| 268 | ); |
| 269 | wp_enqueue_style( |
| 270 | 'prime-slider-site', |
| 271 | BDTPS_ASSETS_URL . 'css/prime-slider-site' . $direction_suffix . '.css', |
| 272 | [], |
| 273 | BDTPS_VER |
| 274 | ); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Loading site related script that needs all time such as uikit. |
| 279 | * @return [type] [description] |
| 280 | */ |
| 281 | public function enqueue_site_scripts() |
| 282 | { |
| 283 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ); |
| 284 | wp_enqueue_script( |
| 285 | 'bdt-uikit', |
| 286 | BDTPS_ASSETS_URL . 'js/bdt-uikit' . $suffix . '.js', |
| 287 | [ 'jquery' ], |
| 288 | '3.2' |
| 289 | ); |
| 290 | wp_enqueue_script( |
| 291 | 'prime-slider-site', |
| 292 | BDTPS_ASSETS_URL . 'js/prime-slider-site' . $suffix . '.js', |
| 293 | [ 'jquery', 'elementor-frontend' ], |
| 294 | BDTPS_VER |
| 295 | ); |
| 296 | } |
| 297 | |
| 298 | public function enqueue_editor_scripts() |
| 299 | { |
| 300 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ); |
| 301 | wp_enqueue_script( |
| 302 | 'prime-slider', |
| 303 | BDTPS_ASSETS_URL . 'js/prime-slider-editor' . $suffix . '.js', |
| 304 | [ 'backbone-marionette', 'elementor-common-modules', 'elementor-editor-modules' ], |
| 305 | BDTPS_VER, |
| 306 | true |
| 307 | ); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Load editor editor related style from here |
| 312 | * @return [type] [description] |
| 313 | */ |
| 314 | public function enqueue_preview_styles() |
| 315 | { |
| 316 | $direction_suffix = ( is_rtl() ? '.rtl' : '' ); |
| 317 | wp_enqueue_style( |
| 318 | 'prime-slider-preview', |
| 319 | BDTPS_ASSETS_URL . 'css/prime-slider-preview' . $direction_suffix . '.css', |
| 320 | '', |
| 321 | BDTPS_VER |
| 322 | ); |
| 323 | } |
| 324 | |
| 325 | public function enqueue_editor_styles() |
| 326 | { |
| 327 | $direction_suffix = ( is_rtl() ? '-rtl' : '' ); |
| 328 | wp_enqueue_style( |
| 329 | 'prime-slider-editor', |
| 330 | BDTPS_ASSETS_URL . 'css/prime-slider-editor' . $direction_suffix . '.css', |
| 331 | '', |
| 332 | BDTPS_VER |
| 333 | ); |
| 334 | wp_enqueue_style( |
| 335 | 'prime-slider-font', |
| 336 | BDTPS_ASSETS_URL . 'css/prime-slider-font' . $direction_suffix . '.css', |
| 337 | [], |
| 338 | BDTPS_VER |
| 339 | ); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * initialize the category |
| 344 | * @return [type] [description] |
| 345 | */ |
| 346 | public function prime_slider_init() |
| 347 | { |
| 348 | $this->_modules_manager = new Manager(); |
| 349 | $elementor = Plugin::$instance; |
| 350 | // Add element category in panel |
| 351 | $elementor->elements_manager->add_category( BDTPS_SLUG, [ |
| 352 | 'title' => BDTPS_TITLE, |
| 353 | 'icon' => 'font', |
| 354 | ] ); |
| 355 | do_action( 'bdthemes_prime_slider/init' ); |
| 356 | } |
| 357 | |
| 358 | private function setup_hooks() |
| 359 | { |
| 360 | add_action( 'elementor/init', [ $this, 'prime_slider_init' ] ); |
| 361 | add_action( 'elementor/editor/after_enqueue_styles', [ $this, 'enqueue_editor_styles' ] ); |
| 362 | add_action( 'elementor/frontend/before_register_styles', [ $this, 'register_site_styles' ] ); |
| 363 | add_action( 'elementor/frontend/before_register_scripts', [ $this, 'register_site_scripts' ] ); |
| 364 | add_action( 'elementor/preview/enqueue_styles', [ $this, 'enqueue_preview_styles' ] ); |
| 365 | //add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] ); // TODO |
| 366 | add_action( 'elementor/frontend/after_register_styles', [ $this, 'enqueue_site_styles' ] ); |
| 367 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] ); |
| 368 | add_action( 'elementor/frontend/before_enqueue_scripts', [ $this, 'enqueue_site_scripts' ] ); |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * Prime_Slider_Loader constructor. |
| 373 | * @throws \Exception |
| 374 | */ |
| 375 | private function __construct() |
| 376 | { |
| 377 | // Register class automatically |
| 378 | spl_autoload_register( [ $this, 'autoload' ] ); |
| 379 | // Include some backend files |
| 380 | $this->_includes(); |
| 381 | // Finally hooked up all things here |
| 382 | $this->setup_hooks(); |
| 383 | } |
| 384 | |
| 385 | } |
| 386 | if ( !defined( 'BDTPS_TESTS' ) ) { |
| 387 | // In tests we run the instance manually. |
| 388 | Prime_Slider_Loader::instance(); |
| 389 | } |
| 390 | // handy function for push data |
| 391 | function prime_slider_config() |
| 392 | { |
| 393 | return Prime_Slider_Loader::instance(); |
| 394 | } |
| 395 |