get_settings(); $this->start_cache(); if ( $this->loader_enabled() ) { add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'wp_head', array( $this, 'loader_custom_styles' ), 100 ); add_action( 'wp_footer', array( $this, 'load_inline_js' ), 99 ); add_filter( 'loftloader_modify_html', array( $this, 'show_loader_html' ) ); } } /** * Start cache for outputing */ public function start_cache() { // Only for front view if ( ! is_admin() ) { // Start cache the output with callback function ob_start( array( $this, 'modify_html' ) ); } } /** * Will be called when flush cache * * @param string cached string * @return string modified cached string */ public function modify_html( $html ) { if ( $this->site_header_loaded && $this->site_footer_loaded ) { return apply_filters( 'loftloader_modify_html', $html ); } else { return $html; } } /** * @description get the plugin settings */ public function get_settings() { global $loftloader_default_settings; $this->defaults = $loftloader_default_settings; do_action( 'loftloader_settings' ); $this->type = esc_attr( $this->get_loader_setting( 'loftloader_loader_type' ) ); add_action( 'wp_head', array( $this, 'set_header_loaded' ) ); add_action( 'wp_footer', array( $this, 'set_footer_loaded' ) ); } /** * @description enqueue the scripts and styles for front end */ public function enqueue_scripts() { $loadJSStyle = $this->get_loader_setting( 'loftloader_inline_js' ); if ( ! is_customize_preview() && ( 'inline' !== $loadJSStyle ) ) { wp_enqueue_script( 'loftloader-lite-front-main', LOFTLOADER_URI . 'assets/js/loftloader.min.js', array( 'jquery' ), LOFTLOADER_ASSET_VERSION, true ); } wp_enqueue_style('loftloader-lite-animation', LOFTLOADER_URI . 'assets/css/loftloader.min.css', array(), LOFTLOADER_ASSET_VERSION); } /** * Load inline JavaScript code if set */ public function load_inline_js() { $loadJSStyle = $this->get_loader_setting( 'loftloader_inline_js' ); if ( ( 'inline' === $loadJSStyle ) && ! is_customize_preview() ) { ?> get_loader_setting( 'loftloader_loader_color' ) ); $bgColor = esc_attr( $this->get_loader_setting( 'loftloader_bg_color' ) ); $bgOpacity = intval( $this->get_loader_setting('loftloader_bg_opacity' ) ) / 100; $styles = $this->generate_style( 'loftloader-lite-custom-bg-color', '#loftloader-wrapper .loader-section {' . PHP_EOL . "\t" . 'background: ' . $bgColor . ';' . PHP_EOL . '}' . PHP_EOL ); $styles .= $this->generate_style( 'loftloader-lite-custom-bg-opacity', '#loftloader-wrapper .loader-section {' . PHP_EOL . "\t" . 'opacity: ' . $bgOpacity . ';' . PHP_EOL . '}' . PHP_EOL ); $css = ''; switch ( $this->type ) { case 'sun': $css = '#loftloader-wrapper.pl-sun #loader {' . PHP_EOL . "\t" . 'color: ' . $color . ';' . PHP_EOL . '}' . PHP_EOL; break; case 'circles': $css = '#loftloader-wrapper.pl-circles #loader {' . PHP_EOL . "\t" . 'color: ' . $color . ';' . PHP_EOL . '}' . PHP_EOL; break; case 'wave': $css = '#loftloader-wrapper.pl-wave #loader {' . PHP_EOL . "\t" . 'color: ' . $color . ';' . PHP_EOL . '}' . PHP_EOL; break; case 'square': $css = '#loftloader-wrapper.pl-square #loader span {' . PHP_EOL . "\t" . 'border: 4px solid ' . $color . ';' . PHP_EOL . '}' . PHP_EOL; break; case 'frame': $css = '#loftloader-wrapper.pl-frame #loader {' . PHP_EOL . "\t" . 'color: ' . $color . ';' . PHP_EOL . '}' . PHP_EOL; break; case 'imgloading': $width = absint($this->get_loader_setting('loftloader_img_width')); $image = esc_url($this->get_loader_setting('loftloader_custom_img')); $css = empty($width) ? '' : '#loftloader-wrapper.pl-imgloading #loader {' . PHP_EOL . "\t" . 'width: ' . $width . 'px;' . PHP_EOL . '}' . PHP_EOL; $css .= '#loftloader-wrapper.pl-imgloading #loader span {' . PHP_EOL . "\t" . 'background-size: cover;' . PHP_EOL . "\t" . 'background-image: url(' . $image . ');' . PHP_EOL . '}' . PHP_EOL; break; case 'beating': $css = '#loftloader-wrapper.pl-beating #loader {' . PHP_EOL . "\t" . 'color: ' . $color . ';' . PHP_EOL . '}' . PHP_EOL; break; } $styles .= $this->generate_style( 'loftloader-lite-custom-loader', $css ); echo wp_kses( $styles, array( 'style' => array( 'type' => array(), 'id' => array(), 'media' => array() ) ) ); } /** * @description loftloader html */ public function show_loader_html( $origin ) { if ( ! empty( $origin ) ) { $regexp ='/(
]*>)/i'; $split = preg_split( $regexp, $origin, 3, PREG_SPLIT_DELIM_CAPTURE ); if ( is_array( $split ) && ( 3 <= count( $split ) ) ) { $image = esc_url($this->get_loader_setting('loftloader_custom_img')); $ending = esc_attr($this->get_loader_setting('loftloader_bg_animation')); $html = '