function __rocket_fix_cdn_for_avada_theme($vars, $handle)
{
    if ($handle == 'avada-dynamic' && get_rocket_option('cdn')) {
        $src = get_rocket_cdn_url(get_template_directory_uri() . '/assets/less/theme/dynamic.less');
        $vars['template-directory'] = sprintf('~"%s"', dirname(dirname(dirname(dirname($src)))));
        $vars['lessurl'] = sprintf('~"%s"', dirname($src));
    }
    return $vars;
}
示例#2
0
function rocket_lazyload_script()
{
    if (!get_rocket_option('lazyload') && !get_rocket_option('lazyload_iframes') || !apply_filters('do_rocket_lazyload', true) && !apply_filters('do_rocket_lazyload_iframes', true)) {
        return;
    }
    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
    $lazyload_url = get_rocket_cdn_url(WP_ROCKET_FRONT_JS_URL . 'lazyload.' . WP_ROCKET_LAZYLOAD_JS_VERSION . $suffix . '.js');
    echo '<script data-no-minify="1">(function(w,d){function a(){var b=d.createElement("script");b.async=!0;b.src="' . $lazyload_url . '";var a=d.getElementsByTagName("script")[0];a.parentNode.insertBefore(b,a)}w.attachEvent?w.attachEvent("onload",a):w.addEventListener("load",a,!1)})(window,document);</script>';
}
示例#3
0
function rocket_insert_deferred_js($buffer)
{
    // Don't add anything on 404 page or on a page without these query strings
    if (is_404() || !empty($_GET) && !isset($_GET['utm_source'], $_GET['utm_medium'], $_GET['utm_campaign']) && !isset($_GET['fb_action_ids'], $_GET['fb_action_types'], $_GET['fb_source']) && !isset($_GET['gclid']) && !isset($_GET['permalink_name']) && !isset($_GET['lp-variation-id']) && !isset($_GET['lang'])) {
        return;
    }
    /**
     * Filter LABjs file URL
     *
     * @since 1.1.0
     *
     * @param string LABjs file URL
     */
    $labjs_src = WP_ROCKET_FRONT_JS_URL . 'LAB.' . WP_ROCKET_LAB_JS_VERSION . '.min.js';
    $labjs_src = get_rocket_cdn_url($labjs_src, array('all', 'css_js', 'js'));
    $labjs_src = apply_filters('rocket_labjs_src', $labjs_src);
    /**
     * Filter list of LABjs options
     *
     * @since 1.1.0
     *
     * @param array List of LABjs options
     */
    $labjs_options = apply_filters('rocket_labjs_options', array('AlwaysPreserveOrder' => true));
    /**
     * Filter list of Deferred JavaScript files waiting to load
     *
     * @since 1.1.0
     *
     * @param array List of Deferred JavaScript files waiting to load
     */
    $deferred_js_wait = apply_filters('rocket_minify_deferred_js_wait', get_rocket_option('deferred_js_wait'));
    $defer = '<script src="' . $labjs_src . '" data-no-minify="1"></script>';
    $defer .= '<script>';
    $defer .= '$LAB';
    // Set LABjs options
    // All options is available in http://labjs.com/documentation.php#optionsobject
    if (count($labjs_options)) {
        $defer .= '.setOptions(' . json_encode($labjs_options) . ')';
    }
    $deferred_js_files = get_rocket_deferred_js_files();
    foreach ($deferred_js_files as $k => $js) {
        $wait = $deferred_js_wait[$k] == '1' ? '.wait(' . esc_js(apply_filters('rocket_labjs_wait_callback', false, $js)) . ')' : '';
        $defer .= '.script("' . esc_js($js) . '")' . $wait;
    }
    $defer .= ';</script>';
    echo $defer;
}
示例#4
0
function rocket_cdn_enqueue($src)
{
    // Don't use CDN if in admin, in login page, in register page or in a post preview
    if (is_admin() || is_preview() || in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) {
        return $src;
    }
    $src = set_url_scheme($src);
    $zone = array('all', 'css_and_js');
    // Add only CSS zone
    if (current_filter() == 'style_loader_src') {
        $zone[] = 'css';
    }
    // Add only JS zone
    if (current_filter() == 'script_loader_src') {
        $zone[] = 'js';
    }
    if ($cnames = get_rocket_cdn_cnames($zone)) {
        list($src_host, $src_path) = get_rocket_parse_url($src);
        // Check if the link isn't external
        if ($src_host == parse_url(home_url(), PHP_URL_HOST) && trim($src_path, '/') != '') {
            $src = get_rocket_cdn_url($src, $zone);
        }
    }
    return $src;
}
function __rocket_cdn_on_images_from_wp_retina_x2($url)
{
    if (wr2x_is_pro()) {
        $cdn_domain = wr2x_getoption("cdn_domain", "wr2x_advanced", "");
    }
    if (empty($cdn_domain)) {
        return get_rocket_cdn_url($url, array('all', 'images'));
    }
    return $url;
}
示例#6
0
/**
 * Get tag of a group of files or JS minified CSS
 *
 * @since 2.1
 *
 * @param array  $files List of files to minify (CSS or JS)
 * @param bool   $force_pretty_url (default: true)
 * @param string $pretty_filename (default: null) The new filename if $force_pretty_url set to true
 * @return string $tags
 */
function get_rocket_minify_files($files, $force_pretty_url = true, $pretty_filename = null)
{
    // Get the internal CSS Files
    // To avoid conflicts with file URLs are too long for browsers,
    // cut into several parts concatenated files
    $tags = '';
    $data_attr = 'data-minify="1"';
    $urls = array(0 => '');
    $base_url = WP_ROCKET_URL . 'min/?f=';
    $files = is_array($files) ? $files : (array) $files;
    if (count($files)) {
        $i = 0;
        foreach ($files as $file) {
            $file = parse_url($file, PHP_URL_PATH);
            // Replace "//" by "/" because it cause an issue with Google Code Minify!
            $file = str_replace('//', '/', $file);
            /**
             * Filter the total number of files generated by the minification
             *
             * @since 2.1
             *
             * @param string The maximum number of characters in a URL
             * @param string The file's extension
             */
            $filename_length = apply_filters('rocket_minify_filename_length', 255, pathinfo($file, PATHINFO_EXTENSION));
            // +1 : we count the extra comma
            if (strlen($urls[$i] . $base_url . $file) + 1 >= $filename_length) {
                $i++;
            }
            /**
             * Filter file to add in minification process
             *
             * @since 2.4
             *
             * @param string $file The file path
             */
            $file = apply_filters('rocket_pre_minify_path', $file);
            $urls[$i] .= $file . ',';
        }
        foreach ($urls as $url) {
            $url = $base_url . rtrim($url, ',');
            $ext = pathinfo($url, PATHINFO_EXTENSION);
            if ($force_pretty_url && (defined('SCRIPT_DEBUG') && !SCRIPT_DEBUG)) {
                /**
                 * Filter the minify URL
                 *
                 * If true returns,
                 * the minify URL like example.com/wp-content/plugins/wp-rocket/min/?f=...
                 *
                 * @since 2.1
                 *
                 * @param bool
                 */
                if (!apply_filters('rocket_minify_debug', false)) {
                    $blog_id = get_current_blog_id();
                    $pretty_url = !$pretty_filename ? WP_ROCKET_MINIFY_CACHE_URL . $blog_id . '/' . md5($url . get_rocket_option('minify_' . $ext . '_key', create_rocket_uniqid())) . '.' . $ext : WP_ROCKET_MINIFY_CACHE_URL . $blog_id . '/' . $pretty_filename . '.' . $ext;
                    /**
                     * Filter the pretty minify URL
                     *
                     * @since 2.1
                     *
                     * @param string $pretty_url
                     * @param string $pretty_filename
                     */
                    $pretty_url = apply_filters('rocket_minify_pretty_url', $pretty_url, $pretty_filename);
                    $url = rocket_fetch_and_cache_minify($url, $pretty_url) ? $pretty_url : $url;
                }
            }
            // If CSS & JS use a CDN
            $url = get_rocket_cdn_url($url, array('all', 'css_and_js', $ext));
            if ($ext == 'css') {
                /**
                 * Filter CSS file URL with CDN hostname
                 *
                 * @since 2.1
                 *
                 * @param string $url
                 */
                $url = apply_filters('rocket_css_url', $url);
                $tags .= sprintf('<link rel="stylesheet" href="%s" %s/>', esc_attr($url), $data_attr);
            } elseif ($ext == 'js') {
                /**
                 * Filter JavaScript file URL with CDN hostname
                 *
                 * @since 2.1
                 *
                 * @param string $url
                 */
                $url = apply_filters('rocket_js_url', $url);
                $tags .= sprintf('<script src="%s" %s></script>', esc_attr($url), $data_attr);
            }
        }
    }
    return $tags;
}
示例#7
0
function rocket_add_cdn_on_custom_attr($html)
{
    if (preg_match('/(data-lazy-src|data-lazyload|data-src|data-retina)=[\'"]?([^\'"\\s>]+)[\'"]/i', $html, $matches)) {
        $html = str_replace($matches[2], get_rocket_cdn_url($matches[2], array('all', 'images')), $html);
    }
    return $html;
}
 public function tm_image_url($url = "")
 {
     // WP Rocket cdn
     if (defined('WP_ROCKET_VERSION') && function_exists('get_rocket_cdn_cnames') && function_exists('get_rocket_cdn_url')) {
         $zone = array('all', 'images');
         if (is_array($url)) {
             foreach ($url as $key => $value) {
                 $ext = pathinfo($value, PATHINFO_EXTENSION);
                 if (is_admin() && $ext != 'php') {
                     continue;
                 }
                 if ($cnames = get_rocket_cdn_cnames($zone)) {
                     $url[$key] = get_rocket_cdn_url($value, $zone);
                 }
             }
         } else {
             $ext = pathinfo($url, PATHINFO_EXTENSION);
             if (is_admin() && $ext != 'php') {
                 //skip
             } else {
                 if ($cnames = get_rocket_cdn_cnames($zone)) {
                     $url = get_rocket_cdn_url($url, $zone);
                 }
             }
         }
     }
     return $url;
 }