Ejemplo n.º 1
0
 public function generate_custom_css()
 {
     global $post;
     // caching will work only if post is provided
     if (isset($post)) {
         if (defined('ESSB_CACHE_ACTIVE_RESOURCE')) {
             $cache_key = "essb_inline_styles_" . $post->ID;
             $cached_data = ESSBCache::get_resource($cache_key, 'css');
             if ($cached_data != '') {
                 echo "<link rel='stylesheet' id='essb-cache-css'  href='" . $cached_data . "' type='text/css' media='all' />";
                 return;
             }
         }
     }
     $this->fix_css_float_from_top();
     $this->generate_essb_more_popup_css();
     // $custom_css_builder_executed
     $options = get_option(EasySocialShareButtons::$plugin_settings_name);
     $is_active = isset($options['customizer_is_active']) ? $options['customizer_is_active'] : 'false';
     if (isset($post)) {
         $post_activate_customizer = get_post_meta($post->ID, 'essb_activate_customizer', true);
         if ($post_activate_customizer != '') {
             if ($post_activate_customizer == "yes") {
                 $is_active = "true";
             } else {
                 $is_active = "false";
             }
         }
     }
     if ($is_active == "true" && !$this->custom_css_builder_executed) {
         $this->customizer_compile_css_second();
     }
     if (count($this->css) > 0) {
         //echo '<!-- ESSB v. '.$this->version.' CSS Builder -->';
         $output_css = "";
         foreach ($this->css as $cssRule) {
             //$cssRule = str_replace(array("\n","\r\n"), '', $cssRule);
             $cssRule = trim(preg_replace('/\\s+/', ' ', $cssRule));
             $output_css .= $cssRule;
         }
         if (isset($post)) {
             if (defined('ESSB_CACHE_ACTIVE_RESOURCE')) {
                 $cache_key = "essb_inline_styles_" . $post->ID;
                 ESSBCache::put_resource($cache_key, $output_css, 'css');
                 $cached_data = ESSBCache::get_resource($cache_key, 'css');
                 if ($cached_data != '') {
                     echo "<link rel='stylesheet' id='essb-cache-css'  href='" . $cached_data . "' type='text/css' media='all' />";
                     return;
                 }
             }
         }
         echo '<style type="text/css">';
         echo $output_css;
         echo '</style>';
     }
 }
Ejemplo n.º 2
0
    /**
     * Custom Javascript injection function into page footer
     * @since 1.3.9.8
     * @update 2.0 added support for cache include
     */
    public function generate_custom_js()
    {
        global $post;
        if (count($this->js_lazyload) > 0) {
            //echo '<!-- easy-async-scripts-ver-'.ESSB_VERSION. '-->';
            echo '<script type="text/javascript">';
            $list = array_unique($this->js_lazyload);
            foreach ($list as $script) {
                if ($this->load_defer) {
                    echo '
					(function() {
					var po = document.createElement(\'script\'); po.type = \'text/javascript\'; po.defer = true;
					po.src = \'' . $script . '\';
					var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s);
					})();';
                } else {
                    echo '
				(function() {
				var po = document.createElement(\'script\'); po.type = \'text/javascript\'; po.async = true;
				po.src = \'' . $script . '\';
				var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s);
				})();';
                }
            }
            echo '</script>';
        }
        // social scripts are loaded at the end
        if (count($this->js_socialscripts) > 0) {
            //echo '<!-- easy-social-scripts-ver-'.ESSB_VERSION. '-->';
            foreach ($this->js_socialscripts as $key => $code) {
                echo $code;
            }
        }
        if (count($this->js_builder) > 0) {
            //echo '<!-- easy-inline-scripts-ver-'.ESSB_VERSION. '-->';
            if (isset($post)) {
                if (defined('ESSB_CACHE_ACTIVE_RESOURCE')) {
                    $cache_key = "essb_inline_scripts_" . $post->ID;
                    $cached_data = ESSBCache::get_resource($cache_key, 'js');
                    if ($cached_data != '') {
                        echo "<script type='text/javascript' src='" . $cached_data . "' defer></script>";
                        return;
                    }
                }
            }
            $inline_scritps = "";
            foreach ($this->js_builder as $singleCode) {
                //$singleCode = trim(preg_replace('/\s+/', ' ', $singleCode));
                $inline_scritps .= $singleCode;
            }
            if (isset($post)) {
                if (defined('ESSB_CACHE_ACTIVE_RESOURCE')) {
                    $cache_key = "essb_inline_scripts_" . $post->ID;
                    ESSBCache::put_resource($cache_key, $inline_scritps, 'js');
                    $cached_data = ESSBCache::get_resource($cache_key, 'js');
                    if ($cached_data != '') {
                        echo "<script type='text/javascript' src='" . $cached_data . "' defer></script>";
                        return;
                    }
                }
            }
            echo '<script type="text/javascript">';
            echo $inline_scritps;
            echo '</script>';
        }
    }