PluginProbe
LoftLoader / 1.0.2
LoftLoader v1.0.2
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
loftloader / front / class-loftloader-front.php

class-loftloader-front.php in LoftLoader 1.0.2, at front/class-loftloader-front.php

98 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Not allowed by directly accessing.
3 if(!defined('ABSPATH')){
4 die('Access not allowed!');
5 }
6
7 /**
8 * Main class for front display
9 *
10 * @package LoftLoader
11 * @link http://www.loftocean.com/
12 * @author Suihai Huang from Loft Ocean Team
13
14 * @since version 1.0
15 */
16
17 if(!class_exists('LoftLoader_Front')){
18 class LoftLoader_Front{
19 private $loader_enabled; // Flag to tell whether loftloader enabled
20 private $homepage_only; // Flag to tell show loftloader on homepage only
21 private $loader_settings; // Get the loader settings
22 public function __construct(){
23 $this->get_settings();
24 if($this->loader_enabled){
25 if(!$this->homepage || is_front_page()){
26 add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
27 add_action('wp_head', array($this, 'loader_custom_styles'), 100);
28 add_action('wp_footer', array($this, 'show_loader_html'));
29 }
30 }
31 }
32 /**
33 * @description get the plugin settings
34 */
35 public function get_settings(){
36 $default = apply_filters('loftloader_settings_default_value', array());
37 $settings = get_option('loftloader-custom-settings', $default);
38 $this->loader_enabled = (!empty($settings['enable']) && ($settings['enable'] == 'on')) ? true : false;
39 $this->homepage = (!empty($settings['homepage']) && ($settings['homepage'] == 'on')) ? true : false;
40 $this->loader_settings = $settings;
41 }
42 /**
43 * @description enqueue the scripts and styles for front end
44 */
45 public function enqueue_scripts(){
46 wp_enqueue_script('loftloader-front-main', LOFTLOADER_JS_URI . 'front/loftloader.js', array('jquery'), '1.0', true);
47 wp_enqueue_style('loftloader-animation');
48 }
49 /**
50 * @description custom css for front end
51 */
52 public function loader_custom_styles(){
53 $styles = get_option('loftloader-custom-styles', '');
54 echo empty($styles) ? '' : '<style type="text/css">' . $styles . '</style>';
55 ob_start();
56 }
57 /**
58 * @description loftloader html
59 */
60 public function show_loader_html(){
61 $loader = $this->loader_settings['settings']; // Preloader settings
62 $background = $loader['background']; // Preloader background settings
63 $animation = $loader['animation']; // Preloader animation settings
64 $html = '<div id="loftloader-wrapper" class="' . $animation['type'] . '">';
65 $html .= '<div class="loader-inner"><div id="loader">';
66 $html .= in_array($animation['type'], array('pl-frame', 'pl-imgloading'))
67 ? '<span></span><img srcset="' . $animation['image']['url'] . '" src="' . $animation['image']['url'] . '" alt="preloder">' : '<span></span>';
68 $html .= '</div></div>';
69 switch($background['effect']){
70 case 'fade':
71 $html .= '<div class="loader-section section-fade"></div>';
72 break;
73 case 'slide-up':
74 $html .= '<div class="loader-section section-slide-up"></div>';
75 break;
76 case 'slide-up-down':
77 $html .= '<div class="loader-section section-up"></div>';
78 $html .= '<div class="loader-section section-down"></div>';
79 break;
80 default:
81 $html .= '<div class="loader-section section-left">';
82 $html .= '</div><div class="loader-section section-right"></div>';
83 }
84 $html .= '</div>';
85
86 $origin = ob_get_clean();
87 $regexp ='/<body[^>]*>/i';
88 if(preg_match($regexp, $origin, $match)){
89 $html = $match[0] . $html;
90 echo preg_replace($regexp, $html, $origin);
91 }
92 else{
93 echo $origin . $html;
94 }
95 }
96 }
97 new LoftLoader_Front();
98 }