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