Example #1
0
function sc_parallax($atts, $content = null)
{
    if (in_shortcode_blogger()) {
        return '';
    }
    extract(shortcode_atts(array("id" => "", "class" => "", "gap" => "no", "style" => "light", "dir" => "up", "speed" => 0.3, "video" => "", "video_ratio" => "16:9", "image" => "", "image_x" => "", "image_y" => "", "color" => "", "overlay" => "", "texture" => "", "top" => "", "bottom" => "", "left" => "", "right" => "", "width" => "", "height" => ""), $atts));
    if ($video != '') {
        $info = pathinfo($video);
        $ext = !empty($info['extension']) ? $info['extension'] : 'mp4';
        $video_ratio = empty($video_ratio) ? "16:9" : str_replace(array('/', '\\', '-'), ':', $video_ratio);
        $ratio = explode(':', $video_ratio);
        $video_width = !empty($width) && themerex_substr($width, -1) >= '0' && themerex_substr($width, -1) <= '9' ? $width : 1280;
        $video_height = round($video_width / $ratio[0] * $ratio[1]);
        if (get_theme_option('use_mediaelement') == 'yes') {
            themerex_enqueue_script('wp-mediaelement');
        }
    }
    if ($image > 0) {
        $attach = wp_get_attachment_image_src($image, 'full');
        if (isset($attach[0]) && $attach[0] != '') {
            $image = $attach[0];
        }
    }
    $image_x = $image_x != '' ? str_replace('%', '', $image_x) . '%' : "50%";
    $image_y = $image_y != '' ? str_replace('%', '', $image_y) . '%' : "50%";
    $speed = ($dir == 'down' ? -1 : 1) * abs($speed);
    if ($overlay > 0) {
        if ($color == '') {
            $color = apply_filters('theme_skin_get_theme_bgcolor', '#ffffff');
        }
        $rgb = hex2rgb($color);
    }
    $s = getStyleString($top, '!' . $right, $bottom, '!' . $left, $width, $height) . ($color !== '' && $overlay == '' ? 'background-color:' . $color . ';' : '');
    return (sc_param_is_on($gap) ? sc_gap_start() : '') . '<div' . ($id ? ' id="' . $id . '"' : '') . ' class="sc_parallax' . ($video != '' ? ' sc_parallax_with_video' : '') . ($style != '' ? ' ' . $style : '') . (!empty($class) ? ' ' . $class : '') . '"' . ($s != '' ? ' style="' . $s . '"' : '') . ' data-parallax-speed="' . $speed . '"' . ' data-parallax-x-pos="' . $image_x . '"' . ' data-parallax-y-pos="' . $image_y . '"' . '>' . ($video != '' ? '<div class="sc_video_bg_wrapper">' . '<video class="sc_video_bg" width="' . $video_width . '" height="' . $video_height . '" data-width="' . $video_width . '" data-height="' . $video_height . '" preload="metadata" autoplay="autoplay" loop="loop" src="' . esc_attr($video) . '" data-ratio="' . esc_attr($video_ratio) . '" data-frame="no">' . '<source src="' . $video . '" type="video/' . $ext . '"></source>' . '</video>' . '</div>' : '') . '<div class="sc_parallax_content" style="' . ($image !== '' ? 'background-image:url(' . $image . '); background-position:' . $image_x . ' ' . $image_y . ';' : '') . '">' . ($overlay > 0 || $texture > 0 ? '<div class="sc_parallax_overlay' . ($texture != '' ? ' texture_bg_' . $texture : '') . '" style="' . ($overlay > 0 ? 'background-color:rgba(' . $rgb['r'] . ',' . $rgb['g'] . ',' . $rgb['b'] . ',' . min(1, max(0, $overlay)) . ');' : '') . '">' : '') . do_shortcode($content) . ($overlay > 0 || $texture > 0 ? '</div>' : '') . '</div>' . '</div>' . (sc_param_is_on($gap) ? sc_gap_end() : '');
}
function sc_gap_wrapper($str)
{
    // Move VC row and column and wrapper inside gap
    $str_new = preg_replace('/(<div\\s+class="vc_row[^>]*>)[\\r\\n\\s]*(<div\\s+class="vc_col[^>]*>)[\\r\\n\\s]*(<div\\s+class="wpb_wrapper[^>]*>)[\\r\\n\\s]*(' . sc_gap_start() . ')/i', '\\4\\1\\2\\3', $str);
    if ($str_new != $str) {
        $str = preg_replace('/(' . sc_gap_end() . ')[\\r\\n\\s]*(<\\/div>)[\\r\\n\\s]*(<\\/div>)[\\r\\n\\s]*(<\\/div>)/i', '\\2\\3\\4\\1', $str_new);
    }
    // Gap layout
    return str_replace(array(sc_gap_start(), sc_gap_end()), array(closeAllWrappers(false) . '<div class="sc_gap">', '</div>' . openAllWrappers(false)), $str);
}