Advertisement
Guest User

Untitled

a guest
Jul 21st, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.20 KB | None | 0 0
  1. <?php
  2.  
  3. // create the shortcode
  4. add_shortcode( 'portfolio_slideshow', 'portfolio_slideshow_shortcode' );
  5.  
  6. // define the shortcode function
  7. function portfolio_slideshow_shortcode( $atts ) {
  8.    
  9.     STATIC $i=0;
  10.  
  11.     global $ps_options;
  12.  
  13.     extract( shortcode_atts( array(
  14.         'size' => $ps_options['size'],
  15.         'nowrap' => '',
  16.         'loop' => $ps_options['loop'],
  17.         'speed' => $ps_options['speed'],
  18.         'trans' => $ps_options['trans'],
  19.         'timeout' => $ps_options['timeout'],
  20.         'exclude_featured'  => $ps_options['exclude_featured'],
  21.         'autoplay' => $ps_options['autoplay'],
  22.         'pagerpos' => $ps_options['pagerpos'],
  23.         'navpos' => $ps_options['navpos'],
  24.         'showcaps' => $ps_options['showcaps'],
  25.         'showtitles' => $ps_options['showtitles'],
  26.         'showdesc' => $ps_options['showdesc'],
  27.         'click' =>  $ps_options['click'],
  28.         'thumbs' => '',
  29.         'fluid' =>  $ps_options['allowfluid'],
  30.         'slideheight' => '',
  31.         'id' => '',
  32.         'exclude' => '',
  33.         'include' => ''
  34.     ), $atts ) );
  35.    
  36.     //mapping for people using older versions of the plugin
  37.     if ( $thumbs == "true" ) $pagerpos = "bottom";
  38.  
  39.     /* Preserve the nowrap option if people are still using it */
  40.     if ( $nowrap == "false" || $loop == "true" ) { $loop = "true"; } else { $loop = "false"; }
  41.  
  42.     //has a custom post id been declared or should we use current page ID?
  43.     if ( ! $id ) { $id = get_the_ID(); }
  44.  
  45.     //if the exclude_featured attribute is set, get the featured thumb ID and add it to the $exclude string
  46.     if ( $exclude_featured == "true" ) {
  47.         $featured_id = get_post_thumbnail_id( $id );
  48.         if ( ! $include ) { // we don't need an exclude variable if $include is set
  49.             if ( $exclude ) { //if $exclude is set, concatenate it
  50.                 $exclude = $exclude . "," . $featured_id;  
  51.              } else { //$exclude is simply equal to $featured_id
  52.                 $exclude = $featured_id;
  53.              }
  54.         }  
  55.     }
  56.  
  57.     //count the attachments
  58.     if ( $include ) {
  59.         $include = preg_replace( '/[^0-9,]+/', '', $include );
  60.         $attachments = get_children( array('post_parent' => $id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'include' => $include) );
  61.        
  62.     } elseif ( $exclude ) {
  63.         $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
  64.         $attachments = get_children( array('post_parent' => $id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'exclude' => $exclude) );
  65.     } else {
  66.         $attachments = get_children( array ( 'post_parent' => $id, 'post_type' => 'attachment', 'post_mime_type' => 'image' ) );
  67.     }
  68.    
  69.     global $ps_count;
  70.     $ps_count = count( $attachments );
  71.        
  72.     // Navigation
  73.     if ( ! is_feed() && $ps_count > 1 ) { //no need for navigation if there's only one slide
  74.    
  75.     $ps_nav = '<div id="slideshow-nav'.$i.'" class="slideshow-nav">';
  76.  
  77.     $ps_nav .='<a class="pause" style="display:none" href="javascript:void(0);">Pause</a><a class="play" href="javascript:void(0);">Play</a><a class="restart" style="display:none" href="javascript: void(0);">Play</a><a class="slideshow-prev" href="javascript: void(0);">Prev</a><span class="sep">|</span><a class="slideshow-next" href="javascript: void(0);">Next</a><span class="slideshow-info' . $i . ' slideshow-info"></span>';
  78.                    
  79.     $ps_nav .= '</div><!-- .slideshow-nav-->
  80.     ';
  81.     }
  82.  
  83.     //Pager
  84.    
  85.     //Do we show thumbnails?
  86.     if ( ! is_feed() &&  $ps_count > 1 ) {
  87.         $ps_pager = '<div class="pscarousel';
  88.  
  89.         $ps_pager .='">';
  90.                            
  91.         $ps_pager .= '<div id="pager' . $i . '" class="pager items clearfix">';
  92.  
  93.         if ( $include ) {
  94.             $include = preg_replace( '/[^0-9,]+/', '', $include );
  95.             $attachments = get_posts( array(
  96.             'order'          => 'ASC',
  97.             'orderby'        => 'menu_order ID',
  98.             'post_type'      => 'attachment',
  99.             'post_parent'    => $id,
  100.             'post_mime_type' => 'image',
  101.             'post_status'    => null,
  102.             'numberposts'    => -1,
  103.             'size'           => 'thumbnail',
  104.             'include'        => $include) );
  105.         } elseif ( $exclude ) {
  106.             $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
  107.             $attachments = get_posts( array(
  108.             'order'          => 'ASC',
  109.             'orderby'        => 'menu_order ID',
  110.             'post_type'      => 'attachment',
  111.             'post_parent'    => $id,
  112.             'post_mime_type' => 'image',
  113.             'post_status'    => null,
  114.             'numberposts'    => -1,
  115.             'size'           => 'thumbnail',
  116.             'exclude'        => $exclude) );
  117.         } else {
  118.             $attachments = get_posts( array(
  119.             'order'          => 'ASC',
  120.             'orderby'        => 'menu_order ID',
  121.             'post_type'      => 'attachment',
  122.             'post_parent'    => $id,
  123.             'post_mime_type' => 'image',
  124.             'post_status'    => null,
  125.             'numberposts'    => -1,
  126.             'size'           => 'thumbnail') );
  127.         }
  128.                    
  129.         if ($attachments) {
  130.             $j = 1;
  131.            
  132.             foreach ( $attachments as $attachment ) {
  133.            
  134.             $ps_pager .= wp_get_attachment_image($attachment->ID, 'thumbnail', false, false);;     
  135.  
  136.             $j++;
  137.             }
  138.         }
  139.        
  140.         $ps_pager .= '</div>';
  141.                            
  142.         $ps_pager .= '</div>';
  143.     }  
  144.        
  145.     if ( ! is_feed() ) {
  146.  
  147.     $slideshow =
  148.         '<script type="text/javascript">/* <![CDATA[ */ psTimeout['.$i.']='.$timeout.';psAutoplay['.$i.']='.$autoplay.';psTrans['.$i.']=\''.$trans.'\';psLoop['.$i.']='.$loop.';psSpeed['.$i.']='.$speed.';/* ]]> */</script>
  149.         ';
  150.    
  151.         //wrap the whole thing in a div for styling    
  152.         $slideshow .= '<div id="slideshow-wrapper'.$i.'" class="slideshow-wrapper clearfix';
  153.        
  154.         if ( $fluid == "true" ) {
  155.             $slideshow .= " fluid";
  156.         }
  157.  
  158.         if ( $ps_options['showloader'] == "true" ) {
  159.             $slideshow .= " showloader";
  160.         }
  161.    
  162.         $slideshow .= '">';
  163.        
  164.         if ( $navpos == "top" ) {
  165.             $slideshow .= $ps_nav;
  166.         }
  167.    
  168.         if ( $pagerpos == "top" ) {
  169.             $slideshow .= $ps_pager;
  170.         }
  171.        
  172.     } //end ! is_feed()
  173.  
  174.     $slideshow .= '<div id="portfolio-slideshow'.$i.'" class="portfolio-slideshow"';
  175.    
  176.     /* An inline style if they need to set a height for the main slideshow container */
  177.    
  178.     if ( $slideheight ) {
  179.         $slideshow .= ' style="min-height:' . $slideheight . 'px !important;"';
  180.     }
  181.    
  182.     $slideshow .='>
  183.     ';
  184.  
  185.     $slideID = 0;
  186.    
  187.     if ( $include ) {
  188.         $include = preg_replace( '/[^0-9,]+/', '', $include );
  189.         $attachments = get_posts( array( 'order'          => 'ASC',
  190.         'orderby'        => 'menu_order ID',
  191.         'post_type'      => 'attachment',
  192.         'post_parent'    => $id,
  193.         'post_mime_type' => 'image',
  194.         'post_status'    => null,
  195.         'numberposts'    => -1,
  196.         'size'           => $size,
  197.         'include'        => $include) );
  198.        
  199.     } elseif ( $exclude ) {
  200.         $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
  201.         $attachments = get_posts( array( 'order'          => 'ASC',
  202.         'orderby'        => 'menu_order ID',
  203.         'post_type'      => 'attachment',
  204.         'post_parent'    => $id,
  205.         'post_mime_type' => 'image',
  206.         'post_status'    => null,
  207.         'numberposts'    => -1,
  208.         'size'           => $size,
  209.         'exclude'        => $exclude) );
  210.     } else {
  211.         $attachments = get_posts( array( 'order'          => 'ASC',
  212.         'orderby'        => 'menu_order ID',
  213.         'post_type'      => 'attachment',
  214.         'post_parent'    => $id,
  215.         'post_mime_type' => 'image',
  216.         'post_status'    => null,
  217.         'numberposts'    => -1,
  218.         'size'           => $size) );
  219.     }
  220.  
  221.     if ( $attachments ) { //if attachments are found, run the slideshow
  222.    
  223.         //begin the slideshow loop
  224.         foreach ( $attachments as $attachment ) {
  225.            
  226.             $alttext = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true );
  227.  
  228.             if ( ! $alttext ) {
  229.                 $alttext = $attachment->post_title;
  230.             }
  231.                
  232.             $slideshow .= '<div class="';
  233.             if ( $slideID != "0" ) { $slideshow .= "not-first "; }
  234.             $slideshow .= 'slideshow-next slideshow-content';
  235.             $slideshow .= '">
  236.             ';
  237.                  
  238.             switch ( $click ) {
  239.  
  240.                 case "openurl" :
  241.                     $imagelink = get_post_meta( $attachment->ID, '_ps_image_link', true );
  242.                     if ( $imagelink ) { $imagelink = $imagelink . '" target="' . $ps_options['click_target']; } else { $imagelink = 'javascript: void(0);" class="slideshow-next';}
  243.                     break;
  244.  
  245.                 default :
  246.                     $imagelink = 'javascript: void(0);" class="slideshow-next';
  247.                     break; 
  248.             }      
  249.            
  250. if ( $loop == "false" && $ps_count - 1 != $slideID || $loop != "false" ) { $slideshow .= '<a href="'.$imagelink.'">';}
  251.            
  252. /*
  253.  * This is the part of the loop that actually returns the images
  254.  */
  255.            
  256.             $ps_placeholder = PORTFOLIO_SLIDESHOW_URL . '/img/tiny.png';
  257.                      
  258.             /* Otherwise it's just one of the WP defaults */
  259.            
  260.             $img =  wp_get_attachment_image_src( $attachment->ID, $size );
  261.                    
  262.             $slideshow .= '<img class="psp-active" data-img="' . $img[0] . '"';
  263.                
  264.             if ( $slideID < 1 ) {
  265.                 $slideshow .= ' src="' . $img[0] . '"';
  266.             } else {
  267.                 $slideshow .= ' src="' . $ps_placeholder . '"';
  268.             }
  269.             //include the src attribute for the first slide only
  270.                
  271.             $slideshow .= ' height="' . $img[2] . '" width="' . $img[1] . '" alt="' . $alttext . '" /><noscript><img src="' . $img[0] . '" height="' . $img[2] . '" width="' . $img[1] . '" alt="' . $alttext . '" /></noscript>';
  272.                                    
  273.            
  274. /*
  275.  * That's it for the images
  276.  */        
  277.            
  278.             if ( $loop == "false" && $ps_count - 1 != $slideID || $loop !="false" ) {
  279.                         $slideshow .= "</a>";
  280.             }      
  281.        
  282.        
  283.             if ( $showtitles == "true" || $showcaps == "true" || $showdesc == "true" ) {
  284.                 $slideshow .= '<div class="slideshow-meta">';
  285.             }
  286.  
  287.             //if titles option is selected
  288.             if ( $showtitles == "true" ) {
  289.                 $title = $attachment->post_title;
  290.                 if ( $title ) {
  291.                     $slideshow .= '<p class="slideshow-title">'.$title.'</p>';
  292.                 }
  293.             }
  294.            
  295.             //if captions option is selected
  296.             if ( $showcaps == "true" ) {           
  297.                 $caption = $attachment->post_excerpt;
  298.                 if ( $caption ) {
  299.                     $slideshow .= '<p class="slideshow-caption">'.$caption.'</p>';
  300.                 }
  301.             }
  302.            
  303.             //if descriptions option is selected
  304.             if ( $showdesc == "true" ) {           
  305.                 $description = $attachment->post_content;
  306.                 if ( $description ) {
  307.                     $slideshow .= '<div class="slideshow-description">'. wpautop( $description ) .'</div>';
  308.                 }
  309.             }
  310.             if ( $showtitles == "true" || $showcaps == "true" || $showdesc == "true" ) {
  311.                 $slideshow .= '</div>';
  312.             }
  313.  
  314.             $slideshow .= '</div>
  315.             ';
  316.            
  317.             $slideID++;
  318.                    
  319.         }  // end slideshow loop
  320.     } // end if ( $attachments)
  321.  
  322.     $slideshow .= "</div><!--#portfolio-slideshow-->";
  323.    
  324.     if ( $navpos == "bottom" ) {
  325.         $slideshow .= $ps_nav;
  326.     }
  327.    
  328.     if ( $pagerpos == "bottom" ) {
  329.         $slideshow .= $ps_pager;
  330.     }
  331.    
  332.     $slideshow .='</div><!--#slideshow-wrapper-->';
  333.  
  334.     $i++;
  335.  
  336.     return $slideshow;  //that's the slideshow
  337.    
  338.    
  339. } //ends the portfolio_shortcode function ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement