PluginProbe
LoftLoader / 2.1.10
LoftLoader v2.1.10
trunk 1.0.0 1.0.1 1.0.2 2.0.0 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3 2.3.1 2.3.2 2.3.3 All 34 releases
← All changes | inc/class-loftloader-front.php +18 -72 2.3.22.1.10 View file →
@@ -16,45 +16,37 @@
16 16 protected $site_footer_loaded = false;
17 17 protected $type; // Get the loader settings
18 18 public function __construct() {
19 19 $this->get_settings();
20 - $this->init_cache();
20 + $this->start_cache();
21 21 if ( $this->loader_enabled() ) {
22 22 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
23 23 add_action( 'wp_head', array( $this, 'loader_custom_styles' ), 100 );
24 24 add_action( 'wp_footer', array( $this, 'load_inline_js' ), 99 );
25 25 add_filter( 'loftloader_modify_html', array( $this, 'show_loader_html' ) );
26 - add_filter( 'body_class', array( $this, 'body_class' ) );
27 26 }
28 27 }
29 28 /**
30 - * Init cache for outputing
29 + * Start cache for outputing
31 30 */
32 - public function init_cache() {
31 + public function start_cache() {
33 32 // Only for front view
34 33 if ( ! is_admin() ) {
35 - add_action( 'wp_head', array( $this, 'start_cache' ) );
36 - add_action( 'wp_footer', array( $this, 'modify_html' ), 99999 );
34 + // Start cache the output with callback function
35 + ob_start( array( $this, 'modify_html' ) );
37 36 }
38 37 }
39 38 /**
40 - * Start cache for outputing
41 - */
42 - public function start_cache() {
43 - ob_start();
44 - }
45 - /**
46 39 * Will be called when flush cache
47 40 *
48 41 * @param string cached string
49 42 * @return string modified cached string
50 43 */
51 - public function modify_html() {
52 - $html = ob_get_clean();
44 + public function modify_html( $html ) {
53 45 if ( $this->site_header_loaded && $this->site_footer_loaded ) {
54 - echo apply_filters( 'loftloader_modify_html', $html );
46 + return apply_filters( 'loftloader_modify_html', $html );
55 47 } else {
56 - echo $html;
48 + return $html;
57 49 }
58 50 }
59 51 /**
60 52 * @description get the plugin settings
@@ -72,9 +64,9 @@
72 64 */
73 65 public function enqueue_scripts() {
74 66 $loadJSStyle = $this->get_loader_setting( 'loftloader_inline_js' );
75 67 if ( ! is_customize_preview() && ( 'inline' !== $loadJSStyle ) ) {
76 - wp_enqueue_script( 'loftloader-lite-front-main', LOFTLOADER_URI . 'assets/js/loftloader.min.js', array(), LOFTLOADER_ASSET_VERSION, true );
68 + wp_enqueue_script( 'loftloader-lite-front-main', LOFTLOADER_URI . 'assets/js/loftloader.min.js', array( 'jquery' ), LOFTLOADER_ASSET_VERSION, true );
77 69 }
78 70 wp_enqueue_style('loftloader-lite-animation', LOFTLOADER_URI . 'assets/css/loftloader.min.css', array(), LOFTLOADER_ASSET_VERSION);
79 71 }
80 72 /**
@@ -93,9 +85,9 @@
93 85 window.addEventListener( 'load', function( e ) {
94 86 loftloader_finished();
95 87 } );
96 88 if ( loader.dataset && loader.dataset.showCloseTime ) {
97 - var showCloseTime = parseInt( loader.dataset.showCloseTime, 10 ), maxLoadTime = false,
89 + var showCloseTime = parseInt( loader.dataset.showCloseTime ),
98 90 closeBtn = loader.getElementsByClassName( 'loader-close-button' );
99 91 if ( showCloseTime && closeBtn.length ) {
100 92 setTimeout( function() {
101 93 closeBtn[0].style.display = '';
@@ -104,17 +96,8 @@
104 96 loftloader_finished();
105 97 } );
106 98 }
107 99 }
108 - if ( loader.dataset.maxLoadTime ) {
109 - maxLoadTime = loader.dataset.maxLoadTime;
110 - maxLoadTime = parseInt( maxLoadTime, 10 );
111 - if ( maxLoadTime ) {
112 - setTimeout( function() {
113 - loftloader_finished();
114 - }, maxLoadTime );
115 - }
116 - }
117 100 }
118 101 } ) ();
119 102 </script> <?php
120 103 }
@@ -186,13 +169,9 @@
186 169 if ( in_array( $this->type, array( 'imgloading' ) ) ) {
187 170 $html .= $this->get_loader_type_loading_bg_image( $image );
188 171 }
189 172 if ( in_array( $this->type, array( 'frame', 'imgloading' ) ) ) {
190 - $html .= sprintf(
191 - '<img data-no-lazy="1" class="skip-lazy" alt="%1$s" src="%2$s">',
192 - esc_attr__( 'loader image', 'loftloader-pro' ),
193 - esc_url( $image )
194 - );
173 + $html .= sprintf( '<img alt="%1$s" src="%2$s">', esc_attr__( 'loader image', 'loftloader-pro' ), esc_url( $image ) );
195 174 }
196 175 }
197 176 $html .= in_array( $this->type, array( 'imgloading' ) ) ? '' : '<span></span>';
198 177 $html .= '</div></div>';
@@ -246,15 +225,8 @@
246 225 $attrs = '';
247 226 $show_close_time = $this->get_loader_setting( 'loftloader_show_close_timer' );
248 227 $show_close_time = number_format( $show_close_time, 0, '.', '' );
249 228 $attrs .= sprintf( ' data-show-close-time="%s"', esc_js( esc_attr( $show_close_time * 1000 ) ) );
250 -
251 - $max_load_time = $this->get_loader_setting( 'loftloader_max_load_time' );
252 - $max_load_time = number_format( $max_load_time, 1, '.', '' );
253 - if ( ! empty( $max_load_time ) ) {
254 - $attrs .= sprintf( ' data-max-load-time="%s"', esc_js( esc_attr( $max_load_time * 1000 ) ) );
255 - }
256 -
257 229 return apply_filters( 'loftloader_loader_attributes', $attrs );
258 230 }
259 231 /**
260 232 * Helper function to test whether show loftloader
@@ -260,21 +232,17 @@
260 232 * Helper function to test whether show loftloader
261 233 * @return boolean return true if loftloader enabled and display on current page, otherwise false
262 234 */
263 235 private function loader_enabled() {
264 - if ( $this->test_builder() ) {
265 - return false;
266 - } else {
267 - if ( ( $this->get_loader_setting( 'loftloader_main_switch' ) === 'on' ) ) {
268 - $range = $this->get_loader_setting( 'loftloader_show_range' );
269 - if ( ( $range === 'sitewide' ) || ( ( $range === 'homepage' ) && is_front_page() ) ) {
270 - return true;
271 - } else {
272 - return false;
273 - }
236 + if ( ( $this->get_loader_setting( 'loftloader_main_switch' ) === 'on' ) ) {
237 + $range = $this->get_loader_setting( 'loftloader_show_range' );
238 + if ( ( $range === 'sitewide' ) || ( ( $range === 'homepage' ) && is_front_page() ) ) {
239 + return true;
274 240 } else {
275 - return apply_filters( 'loftloader_loader_enabled', false );
241 + return false;
276 242 }
243 + } else {
244 + return apply_filters( 'loftloader_loader_enabled', false );
277 245 }
278 246 }
279 247 /**
280 248 * Helper function get setting option
@@ -298,30 +266,8 @@
298 266 * Make the footer loaded flag
299 267 */
300 268 public function set_footer_loaded() {
301 269 $this->site_footer_loaded = true;
302 - }
303 - /**
304 - * Not show loader in builder and theme customizer
305 - */
306 - protected function test_builder() {
307 - if ( defined( 'ELEMENTOR_PATH' ) && isset( $_GET['elementor-preview'] ) && ! empty( sanitize_text_field( wp_unslash( $_GET['elementor-preview'] ) ) ) ) {
308 - return true;
309 - } else if ( class_exists( 'FLBuilderLoader' ) && isset( $_GET['fl_builder'] ) ) {
310 - return true;
311 - } else if ( defined( 'WPB_VC_VERSION' ) && ( ! empty( $_GET['vc_editable'] ) ) ) {
312 - return true;
313 - } else if ( is_customize_preview() && ( empty( $_GET['plugin'] ) || ( 'loftloader-lite' != sanitize_text_field( wp_unslash( $_GET['plugin'] ) ) ) ) ) {
314 - return true;
315 - }
316 - return false;
317 - }
318 - /**
319 - * Identify from loftloader lite
320 - */
321 - public function body_class( $class ) {
322 - array_push( $class, 'loftloader-lite-enabled' );
323 - return $class;
324 270 }
325 271 }
326 272 new LoftLoader_Front();
327 273 }