Esempio n. 1
0
 /**
  * Initialize the class and set its properties.
  *
  * @since    2.0
  * @var      object    $CTRL       The above the fold admin controller..
  */
 public function __construct(&$CTRL)
 {
     $this->classname = str_replace('Abovethefold_LocalizeJSModule_', '', get_called_class());
     if (!$this->name) {
         $this->name = $this->classname;
     }
     if (!isset($CTRL->options['localizejs'])) {
         $CTRL->options['localizejs'] = array();
     }
     $this->CTRL =& $CTRL;
     $this->options = $CTRL->options['localizejs'][$this->classname];
     $this->cachepath = $this->CTRL->cache_path() . 'localizejs/';
     if (!is_dir($this->cachepath)) {
         mkdir($this->cachepath, 0775);
     }
 }
Esempio n. 2
0
    /**
     * WordPress Header hook
     *
     * Parse and modify WordPress header. This part includes inline Javascript and CSS and controls the renderproces.,
     *
     * @since    1.0
     */
    public function header()
    {
        if ($this->CTRL->noop) {
            return;
        }
        if ($this->buffertype === 'ob') {
            ob_start(array($this, 'rewrite_callback'));
        }
        $cssfile = $this->CTRL->cache_path() . 'inline.min.css';
        $jsfiles = array();
        $jsfiles[] = plugin_dir_path(dirname(__FILE__)) . 'public/js/abovethefold.min.js';
        if (intval($this->CTRL->options['loadcss_enhanced']) === 1) {
            $jsfiles[] = plugin_dir_path(dirname(__FILE__)) . 'public/js/abovethefold-loadcss-enhanced.min.js';
        } else {
            $jsfiles[] = plugin_dir_path(dirname(__FILE__)) . 'public/js/abovethefold-loadcss.min.js';
        }
        $jscode = '';
        foreach ($jsfiles as $file) {
            $jscode .= ' ' . file_get_contents($file);
        }
        $jssettings = array('css' => $this->criticalcss_replacement_string);
        if (isset($this->CTRL->options['cssdelivery_renderdelay']) && intval($this->CTRL->options['cssdelivery_renderdelay']) > 0) {
            $jssettings['delay'] = intval($this->CTRL->options['cssdelivery_renderdelay']);
        }
        ?>
<style type="text/css">
/*! Above The Fold Optimization <?php 
        print $this->CTRL->get_version();
        ?>
 */
<?php 
        if (file_exists($cssfile)) {
            print file_get_contents($cssfile);
        }
        ?>
</style>
<script type="text/javascript" id="atfcss"><?php 
        print $jscode;
        if (current_user_can('manage_options') && intval($this->CTRL->options['debug']) === 1) {
            print 'window.abovethefold.debug = true;';
        }
        if (!empty($jssettings)) {
            print "window['abovethefold'].config(" . json_encode($jssettings) . ");";
        }
        if ($this->CTRL->options['cssdelivery_position'] === 'header') {
            print "window['abovethefold'].css();";
        }
        ?>
</script>
<?php 
        //
    }
    /**
     * WordPress Header hook
     *
     * Parse and modify WordPress header. This part includes inline Javascript and CSS and controls the renderproces.,
     *
     * @since    1.0
     */
    public function header()
    {
        if ($this->CTRL->noop) {
            return;
        }
        if ($this->buffertype === 'ob') {
            ob_start(array($this, 'rewrite_callback'));
        }
        $cssfile = $this->CTRL->cache_path() . 'inline.min.css';
        $jsfiles = array();
        $jsfiles[] = plugin_dir_path(dirname(__FILE__)) . 'public/js/abovethefold.min.js';
        if (intval($this->CTRL->options['loadcss_enhanced']) === 1) {
            $jsfiles[] = plugin_dir_path(dirname(__FILE__)) . 'public/js/abovethefold-loadcss-enhanced.min.js';
        } else {
            $jsfiles[] = plugin_dir_path(dirname(__FILE__)) . 'public/js/abovethefold-loadcss.min.js';
        }
        $jscode = '';
        foreach ($jsfiles as $file) {
            $jscode .= ' ' . file_get_contents($file);
        }
        ?>
<style type="text/css">
/*!
 * Above The Fold Optimization <?php 
        print $this->CTRL->get_version() . "\n";
        ?>
 * (c) 2015 https://optimalisatie.nl
 */
<?php 
        if (file_exists($cssfile)) {
            print file_get_contents($cssfile);
        }
        ?>
</style>
<script type="text/javascript"><?php 
        print $jscode;
        ?>
 var CRITICALCSS;
<?php 
        if (current_user_can('manage_options') && intval($this->CTRL->options['debug']) === 1) {
            print 'window.abovethefold.debug = true;';
        }
        if ($this->CTRL->options['cssdelivery_position'] === 'header') {
            print "if (window['abovethefold']) { window['abovethefold'].css(CRITICALCSS); }";
        }
        ?>
</script>
<?php 
        //
    }
 /**
  * Cache file path
  */
 public function cache_file_path($hash, $type, $create = true)
 {
     // verify hash
     if (strlen($hash) !== 32) {
         wp_die('Invalid cache file hash');
     }
     // Initialize cache path
     $cache_path = $this->CTRL->cache_path() . 'proxy/';
     if (!is_dir($cache_path)) {
         if (!@mkdir($cache_path, $this->CTRL->CHMOD_DIR, true)) {
             wp_die('Failed to create directory ' . $cache_path);
         }
     }
     $dir_blocks = array_slice(str_split($hash, 2), 0, 5);
     foreach ($dir_blocks as $block) {
         $cache_path .= $block . '/';
         if (!$create && !is_dir($cache_path)) {
             return false;
         }
     }
     if (!is_dir($cache_path)) {
         if (!@mkdir($cache_path, $this->CTRL->CHMOD_DIR, true)) {
             wp_die('Failed to create directory ' . $cache_path);
         }
     }
     $cache_path .= $hash;
     if ($type === 'js') {
         $cache_path .= '.js';
     } else {
         if ($type === 'css') {
             $cache_path .= '.css';
         }
     }
     if (!$create && !file_exists($cache_path)) {
         return false;
     }
     return $cache_path;
 }
Esempio n. 5
0
    public function settings_page()
    {
        global $pagenow;
        $options = get_site_option('abovethefold');
        if (!is_array($options)) {
            $options = array();
        }
        $inlinecss = '';
        $cssfile = $this->CTRL->cache_path() . 'inline.min.css';
        if (file_exists($cssfile)) {
            $inlinecss = file_get_contents($cssfile);
        }
        /**
         * Load default paths
         */
        $default_paths = array('/');
        // Get random post
        $args = array('post_type' => 'post', 'numberposts' => 1, 'orderby' => 'rand');
        query_posts($args);
        if (have_posts()) {
            while (have_posts()) {
                the_post();
                $default_paths[] = str_replace(get_option('siteurl'), '', get_permalink($post->ID));
                break;
            }
        }
        // Get random page
        $args = array('post_type' => 'page', 'numberposts' => 1, 'orderby' => 'rand');
        query_posts($args);
        if (have_posts()) {
            while (have_posts()) {
                the_post();
                $default_paths[] = str_replace(get_option('siteurl'), '', get_permalink($post->ID));
                break;
            }
        }
        // Random category
        $taxonomy = 'category';
        $terms = get_terms($taxonomy);
        shuffle($terms);
        if ($terms) {
            foreach ($terms as $term) {
                $default_paths[] = str_replace(get_option('siteurl'), '', get_category_link($term->term_id));
                break;
            }
        }
        ?>
<div class="wrap"></div>

<h2 class="option_title"><?php 
        _e('Above The Fold Optimization', 'abovethefold');
        ?>
</h2>
<p>This plugin enables to pass the "<em>Eliminate render-blocking JavaScript and CSS in above-the-fold content</em>"-rule from <a href="https://developers.google.com/speed/pagespeed/insights/" target="_blank">Google PageSpeed Insights</a>.</p>

<?php 
        if (!isset($_GET['tab'])) {
            $_GET['tab'] = 'settings';
        }
        $this->settings_tabs($_GET['tab']);
        switch (strtolower(trim($_GET['tab']))) {
            case "settings":
                require_once 'admin.settings.class.php';
                break;
            case "online":
                require_once 'admin.online.class.php';
                break;
            case "server":
                require_once 'admin.server.class.php';
                break;
            case "extract":
                require_once 'admin.extract.class.php';
                break;
        }
    }
Esempio n. 6
0
    public function settings_page()
    {
        global $pagenow, $wp_query;
        $options = get_site_option('abovethefold');
        if (!is_array($options)) {
            $options = array();
        }
        $inlinecss = '';
        $cssfile = $this->CTRL->cache_path() . 'inline.min.css';
        if (file_exists($cssfile)) {
            $inlinecss = file_get_contents($cssfile);
        }
        /**
         * Load default paths
         */
        $default_paths = array('/');
        // Get random post
        $args = array('post_type' => 'post', 'numberposts' => 1, 'orderby' => 'rand');
        query_posts($args);
        if (have_posts()) {
            while (have_posts()) {
                the_post();
                $default_paths[] = str_replace(get_option('siteurl'), '', get_permalink($wp_query->post->ID));
                break;
            }
        }
        // Get random page
        $post = false;
        $args = array('post_type' => 'page', 'numberposts' => 1, 'orderby' => 'rand');
        query_posts($args);
        if (have_posts()) {
            while (have_posts()) {
                the_post();
                $default_paths[] = str_replace(get_option('siteurl'), '', get_permalink($wp_query->post->ID));
                break;
            }
        }
        // Random category
        $taxonomy = 'category';
        $terms = get_terms($taxonomy);
        shuffle($terms);
        if ($terms) {
            foreach ($terms as $term) {
                $default_paths[] = str_replace(get_option('siteurl'), '', get_category_link($term->term_id));
                break;
            }
        }
        ?>
<div class="wrap">
<h1><?php 
        _e('Above The Fold Optimization', 'abovethefold');
        ?>
</h1>
</div>
<?php 
        if (!isset($_GET['tab'])) {
            $_GET['tab'] = 'settings';
        }
        $this->settings_tabs($_GET['tab']);
        switch (strtolower(trim($_GET['tab']))) {
            case "settings":
                require_once 'admin.settings.class.php';
                break;
            case "generator":
                require_once 'admin.generator.class.php';
                break;
            case "extract":
                require_once 'admin.extract.class.php';
                break;
            case "localizejs":
                require_once 'admin.localizejs.class.php';
                break;
        }
    }