Advertisement
BackuPs-nl

Nixe Rt_slider.php

Nov 22nd, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.02 KB | None | 0 0
  1. <?php
  2. /**
  3.  *  
  4.  *  Shortcodes for RT Content Slider
  5.  *  
  6.  */
  7.  
  8. if( ! function_exists("rt_slider") ){
  9.     /**
  10.      * RT Slider Holder
  11.      * returns html ouput of the content slider
  12.      *
  13.      * @param  [array] $atts  
  14.      * @param  [string] $content
  15.      * @return [string] $output
  16.      */
  17.     function rt_slider( $atts, $content = null ) {
  18.         global $rt_slider_min_height;
  19.  
  20.         //defaults
  21.         extract(shortcode_atts(array(  
  22.             "id"  => 'content-slider-'.rand(100000, 1000000),          
  23.             "min_height" => 300,
  24.             "mobile_min_height" => 300,
  25.             "autoplay" => true,
  26.             "timeout" => 5000,
  27.             "parallax" => false,
  28.             "dots" => "true",
  29.             "nav" => "true"
  30.         ), $atts));
  31.  
  32.         //id
  33.         $id = !empty( $id ) ? sanitize_html_class( $id ) : 'slider-dynamicID-'.rand(100000, 1000000);
  34.  
  35.         //min height
  36.         $rt_slider_min_height = (double) $min_height;
  37.  
  38.         //parallax
  39.         $parallax = $parallax === "true" ? "true" : "false";
  40.  
  41.         //autoplay
  42.         $autoplay = $autoplay === "true" ? "true" : "false";
  43.  
  44.         //get slides
  45.         ob_start();
  46.         echo (do_shortcode($content));
  47.         $get_slides = ob_get_contents();
  48.         ob_end_clean();
  49.  
  50.         //dots holder
  51.         $dots_holder = ( $dots == "true" ) ? sprintf('
  52.                 <div id="%1$s-dots" class="dots-holder">
  53.                 </div>
  54.             ', $id) : "";
  55.  
  56.  
  57.         //create the slider holder
  58.         $output = '<div id="'.$id.'" class="rt-carousel main-carousel carousel-holder clearfix" data-item-width="1" data-mobile-height="'.intval($mobile_min_height).'" data-nav="'.$nav.'" data-dots="'.$dots.'" data-parallax="'.$parallax.'" data-timeout="'.$timeout.'" data-autoplay="'.$autoplay.'">'."\n";
  59.         $output .= '<div class="owl-carousel">'."\n";
  60.         $output .= $get_slides;
  61.         $output .= '</div>'."\n";
  62.         $output .= $dots_holder."\n";
  63.         $output .= '</div>'."\n";
  64.  
  65.         return $output;
  66.  
  67.  
  68.     }
  69. }
  70. add_shortcode('rt_slider', 'rt_slider');
  71.  
  72.  
  73. if( ! function_exists("rt_slide") ){
  74.     /**
  75.      * RT Slide
  76.      * returns html ouput of a slide
  77.      *
  78.      * @param  [array] $atts  
  79.      * @param  [string] $content
  80.      * @return [string] $output
  81.      */
  82.     function rt_slide( $atts, $content = null ) {
  83.         global $rt_slider_min_height;
  84.  
  85.         //defaults
  86.         extract(shortcode_atts(array(  
  87.             "class" => '',
  88.             "content_width" => 40,
  89.             "content_bg_color" => "",
  90.             "content_wrapper_width" => "default",
  91.             "content_color_schema" => "",
  92.             "content_align" =>  "right",
  93.             "text_align" =>  "left",
  94.             'bg_color' => '',
  95.             'bg_image' => '',
  96.             'bg_image_repeat' => '',
  97.             'bg_position' => '',
  98.             'bg_size' => '',
  99.             'top_margin' => '',
  100.             'mobile_top_margin' => '',
  101.             'link'=> '',
  102.             'link_target'=> '_self',
  103.             'link_title'=> '',
  104.  
  105.  
  106.             "button_text"   => '',
  107.             "button_icon"   => '',
  108.             "button_link"   => '',
  109.             "button_link_target"   => '',
  110.             "button_size"   => 'small',
  111.             "button_style"  => 'color',
  112.             "button_href_title" => "",
  113.            
  114.            
  115.             "button2_text"  => '',
  116.             "button2_icon"  => '',
  117.             "button2_link"  => '',
  118.             "button2_link_target"   => '',
  119.             "button2_size"  => 'small',
  120.             "button2_style" => 'color',
  121.             "button2_href_title" => "",
  122.                            
  123.             "heading"   => '',
  124.             "heading_font_size"   => '',
  125.             "heading_line_height"   => '',
  126.             "mobile_heading_font_size"   => '',
  127.             "mobile_heading_line_height"   => '',      
  128.  
  129.             "sub_heading"   => '',
  130.             "sub_heading_font_size"   => '',
  131.             "sub_heading_line_height"   => '',
  132.             "mobile_sub_heading_font_size"   => '',
  133.             "mobile_sub_heading_line_height"   => '',
  134.         ), $atts));
  135.  
  136.         $style_output = $content_style_output = $content_class = $content_wrapper_style = $background_output = "";
  137.  
  138.         //get slide content
  139.         ob_start();
  140.         echo do_shortcode(rt_visual_composer_content_fix($content));
  141.         $get_slide_content = ob_get_contents();
  142.         $get_slide_content = ! empty( $get_slide_content ) ? '<div class="slide-text">'.$get_slide_content.'</div>' : "";
  143.         ob_end_clean();
  144.  
  145.  
  146.         //heading output
  147.         $heading_style = ! empty( $heading_font_size ) ? ' font-size:'.intval($heading_font_size).'px;' : "";
  148.         $heading_style .= ! empty( $heading_line_height ) ? ' line-height:'.$heading_line_height.'' : "";
  149.         $heading_style = ! empty( $heading_style ) ? 'style="'.trim($heading_style).'"' : "";
  150.  
  151.         $mobile_heading_font_size = ! empty( $mobile_heading_font_size ) ? 'data-mobile-value="'.intval($mobile_heading_font_size).'"' : 'data-mobile-value="28"';
  152.         $mobile_heading_line_height = ! empty( $mobile_heading_line_height ) ? 'data-mobile-line-height="'.intval($mobile_heading_line_height).'%"' : 'data-mobile-line-height="1.5"';
  153.  
  154.  
  155.         $heading_output =  ! empty( $heading ) ? '<h2 class="slide_heading" '. $heading_style .' '.$mobile_heading_font_size.' '.$mobile_heading_line_height.'>'.$heading.'</h2>' : "";
  156.  
  157.         //sub heading output
  158.         $sub_heading_style = ! empty( $sub_heading_font_size ) ? ' font-size:'.intval($sub_heading_font_size).'px;' : "";
  159.         $sub_heading_style .= ! empty( $sub_heading_line_height ) ? ' line-height:'.$sub_heading_line_height.'' : "";
  160.         $sub_heading_style = ! empty( $sub_heading_style ) ? 'style="'.trim($sub_heading_style).'"' : "";
  161.  
  162.  
  163.         $mobile_sub_heading_font_size = ! empty( $mobile_sub_heading_font_size ) ? 'data-mobile-value="'.intval($mobile_sub_heading_font_size).'"' : 'data-mobile-value="22"';
  164.         $mobile_sub_heading_line_height = ! empty( $mobile_sub_heading_line_height ) ? 'data-mobile-line-height="'.intval($mobile_sub_heading_line_height).'%"' : 'data-mobile-line-height="1"';
  165.  
  166.         $sub_heading_output =  ! empty( $sub_heading ) ? '<span class="slide_sub_heading secondary-font"  '. $sub_heading_style .'  '.$mobile_sub_heading_font_size.' '.$mobile_sub_heading_line_height.'>'.$sub_heading.'</span>' : "";
  167.  
  168.  
  169.         //button 1
  170.         $button_format = '
  171.             [button
  172.                 button_size = "'.$button_size.'"
  173.                 button_text = "'.$button_text.'"
  174.                 button_link = "'.$button_link.'"
  175.                 button_icon = "'.$button_icon.'"  
  176.                 button_style = "'.$button_style.'"  
  177.                 href_title = "'.$button_text.'"
  178.                 link_open = "'.$link_target.'"
  179.                 wrapper_class="button-1"
  180.             ]
  181.         ';
  182.  
  183.         $button_output =  ! empty( $button_text ) ? do_shortcode($button_format) : "";
  184.  
  185.         //button 2
  186.         $button2_format = '
  187.             [button
  188.                 button_size = "'.$button2_size.'"
  189.                 button_text = "'.$button2_text.'"
  190.                 button_link = "'.$button2_link.'"
  191.                 button_icon = "'.$button2_icon.'"  
  192.                 button_style = "'.$button2_style.'"  
  193.                 href_title = "'.$button2_text.'"
  194.                 link_open = "'.$link_target.'"
  195.                 wrapper_class="button-2"
  196.             ]
  197.         ';
  198.  
  199.         $button2_output =  ! empty( $button2_text ) ? do_shortcode($button2_format) : "";
  200.  
  201.  
  202.         //css class
  203.         $class = ! empty( $class ) ? sanitize_html_class( $class ) : "";
  204.  
  205.         //color schema
  206.         $class .= ! empty( $content_color_schema ) ? " ".sanitize_html_class( $content_color_schema ) : "";
  207.  
  208.         //bg values
  209.         if( ! empty( $bg_image ) ){
  210.              
  211.             $bg_image = rtframework_get_attachment_image_src($bg_image);       
  212.  
  213.             //background image
  214.             $background_output  .= 'background-image: url('.$bg_image.');';
  215.            
  216.             //background repeat
  217.             $background_output  .= ! empty( $bg_image_repeat ) ? 'background-repeat: '.$bg_image_repeat.';': "";
  218.  
  219.             //background size
  220.             $background_output  .= ! empty( $bg_size ) ? 'background-size: '.$bg_size.';': "";
  221.  
  222.             //background attachment
  223.             //$style_output  .= ! empty( $bg_attachment ) ? 'background-attachment: '.$bg_attachment.';': "";
  224.  
  225.             //background position
  226.             $background_output  .= ! empty( $bg_position ) ? 'background-position: '.$bg_position.';': "";     
  227.         }  
  228.  
  229.         //background color
  230.         $background_output  .= ! empty( $bg_color ) ? 'background-color: '.$bg_color.';': "";
  231.        
  232.         //height
  233.         $style_output  .= ! empty( $rt_slider_min_height ) ? 'min-height: '.intval($rt_slider_min_height).'px;': "";
  234.  
  235.         //wrapper height
  236.         $content_wrapper_style  .= ! empty( $rt_slider_min_height ) ? 'min-height: '.intval($rt_slider_min_height).'px;': "";
  237.  
  238.         //content width
  239.         $content_style_output  .= ! empty( $content_width ) ? 'width: '.$content_width.'%;': "";
  240.  
  241.         //background color
  242.         $content_style_output  .= ! empty( $content_bg_color ) ? 'background-color: '.$content_bg_color.';': "";
  243.        
  244.  
  245.         //content align
  246.         $content_class .= ! empty( $content_align ) ? " {$content_align}":"";
  247.  
  248.         //content top margin
  249.         $content_style_output  .= $content_align == "center" ? 'left: '.((100-$content_width)/2).'%;': "";
  250.  
  251.  
  252.         //text align
  253.         $content_class .= ! empty( $text_align ) ? " text-{$text_align}":"";
  254.  
  255.         //content top margin
  256.         $content_style_output  .= ! empty( $top_margin ) ? 'margin-top: '.intval($top_margin).'px;': "";
  257.  
  258.         //content top margin mobile
  259.         $content_data = ! empty( $mobile_top_margin ) ? ' data-mobile-top-margin= "'.intval($mobile_top_margin).'"': "";
  260.  
  261.  
  262.         //style outputs
  263.         $style_output = ! empty( $style_output ) ? 'style="'.$style_output.'"' : "";
  264.         $content_style_output = ! empty( $content_style_output ) ? 'style="'.$content_style_output.'"' : "";
  265.         $content_wrapper_style_output = ! empty( $content_wrapper_style ) ? 'style="'.$content_wrapper_style.'"' : "asads";
  266.  
  267.         $link_output = ! empty( $link ) ? '<a href="'.esc_url($link).'" target="'.$link_target.'" title="'.sanitize_text_field( $link_title ).'"></a>' : "";
  268.  
  269.        
  270.         if (empty($heading_output)&&empty($sub_heading_output)&&empty($get_slide_content)) {
  271.             return sprintf('
  272.             <div class="item has-bg-image %1$s" %2$s>
  273.                 %3$s
  274.                     <div class="slide-background" style="%4$s"></div>
  275.             </div>',
  276.             $class,
  277.             $style_output,     
  278.             $link_output,
  279.             $background_output
  280.             );
  281.         }
  282.         else {
  283.             return sprintf('
  284.             <div class="item has-bg-image %1$s" %2$s>
  285.                 %3$s
  286.                 <div class="slide-content-wrapper %4$s clearfix" %13$s>
  287.                     <div class="slide-content %5$s" %6$s%12$s>         
  288.                         %7$s
  289.                         %8$s
  290.                         %9$s
  291.                         %10$s
  292.                         %11$s
  293.                     </div>
  294.                 </div>
  295.                 <div class="slide-background" style="%14$s"></div>
  296.             </div>',
  297.             $class,
  298.             $style_output,     
  299.             $link_output,
  300.             $content_wrapper_width,
  301.             $content_class,
  302.             $content_style_output,
  303.             $heading_output,//7
  304.             $sub_heading_output,   
  305.             $get_slide_content,//9
  306.             $button_output,
  307.             $button2_output,
  308.             $content_data,//12
  309.             $content_wrapper_style_output,
  310.             $background_output
  311.             );
  312.         }
  313.     }
  314. }
  315.  
  316. add_shortcode('rt_slide', 'rt_slide');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement