[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

/sections/carousel/ -> section.php (source)

   1  <?php
   2  /*
   3      Section: Carousel
   4      Author: PageLines
   5      Author URI: http://www.pagelines.com
   6      Description: Creates a flickr, nextgen, or featured image carousel.
   7      Class Name: PageLinesCarousel
   8      Cloning: true
   9      Workswith: content, header, footer
  10      Edition: pro
  11  */
  12  
  13  /**
  14   * Carousel Section
  15   *
  16   * @package PageLines Framework
  17   * @author PageLines
  18   */
  19  class PageLinesCarousel extends PageLinesSection {
  20  
  21  
  22      /**
  23      * Load js
  24      */
  25  	function section_styles(){
  26          wp_enqueue_script( 'jcarousel', $this->base_url.'/jcarousel.js', array( 'jquery'), null, true);
  27      }
  28  
  29  
  30  
  31          /**
  32          *
  33          * @TODO document
  34          *
  35          */
  36  		function section_head( $clone_id = null ) {
  37  
  38              $carousel_class = ( isset( $clone_id ) && $clone_id != 1 ) ? 'crsl' . $clone_id : 'crsl';
  39  
  40              $num_items = ( ploption('carousel_display_items', $this->oset) ) ? ploption('carousel_display_items', $this->oset) : 9;
  41              $scroll_items = ( ploption('carousel_scroll_items', $this->oset) ) ? ploption('carousel_scroll_items', $this->oset) : 6;
  42              $anim_speed = ( ploption('carousel_animation_speed', $this->oset) ) ? ploption('carousel_animation_speed', $this->oset) : 800;
  43              $callback = ( 0 != ploption('carousel_scroll_time', $this->oset) ) ? ',initCallback: mycarousel_initCallback' : '';
  44              $auto = ( 0 != ploption('carousel_scroll_time', $this->oset) ) ? round( ploption('carousel_scroll_time', $this->oset) ) / 1000 : 0;
  45  
  46  
  47              $carousel_args = sprintf('wrap: "circular", visible: %s, easing: "%s", scroll: %s, animation: %s, auto: %s %s', $num_items, 'swing', $scroll_items, $anim_speed, $auto, $callback);
  48              ?>
  49      <script type="text/javascript">
  50      /* <![CDATA[ */
  51      <?php if ( 0 != ploption('carousel_scroll_time', $this->oset) ) : ?>
  52  
  53      /**
  54      *
  55      * @TODO document
  56      *
  57      */
  58  	function mycarousel_initCallback(carousel)
  59      {
  60          // Disable autoscrolling if the user clicks the prev or next button.
  61          carousel.buttonNext.bind('click', function() {
  62              carousel.startAuto(0);
  63          });
  64  
  65          carousel.buttonPrev.bind('click', function() {
  66              carousel.startAuto(0);
  67          });
  68  
  69          // Pause autoscrolling if the user moves with the cursor over the clip.
  70          carousel.clip.hover(function() {
  71              carousel.stopAuto();
  72          }, function() {
  73              carousel.startAuto();
  74          });
  75      };
  76  <?php endif; ?>
  77          jQuery(document).ready(function () {
  78              <?php printf('jQuery(".%s").show().jcarousel({%s});', $carousel_class, $carousel_args); ?>
  79              jQuery(".jcarousel-prev, .jcarousel-next").disableTextSelect().hover(function(){
  80                  jQuery(this).fadeTo('fast', 1); },
  81                  function(){ jQuery(this).fadeTo('fast', 0.5);}
  82              );
  83  
  84  
  85          });
  86      /* ]]> */
  87      </script>
  88      <?php }
  89  
  90  
  91      /**
  92      *
  93      * @TODO document
  94      *
  95      */
  96  	function section_optionator( $settings ){
  97          $settings = wp_parse_args($settings, $this->optionator_default);
  98  
  99              $metatab_array = array(
 100                      'carousel_numbers' => array(
 101                              'type'         => 'text_multi',
 102                              'inputsize'    => 'small',
 103                              'selectvalues'=> array(
 104                                  'carousel_items'            => array('inputlabel'=>__( 'Total Carousel Items', 'pagelines' ) ),
 105                                  'carousel_display_items'    => array('inputlabel'=>__( 'Displayed Carousel Items', 'pagelines' ) , 'default' => 7),
 106                                  'carousel_scroll_items'        => array('inputlabel'=>__( 'Scrolled Carousel Items', 'pagelines' ) , 'default' => 4),
 107                                  'carousel_animation_speed'    => array('inputlabel'=>__( 'Transition Speed (milliseconds)', 'pagelines' ) , 'default' => 800),
 108                                  'carousel_scroll_time'        => array('inputlabel'=>__( 'Autoscroll Speed (milliseconds)', 'pagelines' ) , 'default' => 0),
 109                              ),
 110                              'title'     => __( 'Carousel Display and Scroll', 'pagelines' ),
 111                              'shortexp'     => __( 'The total numbers for total, shown and scrolled images', 'pagelines' ),
 112                              'exp'         => __( 'Use this option to control the number of carousel items, the total shown, and the number scrolled at one time.', 'pagelines' )
 113                      ),
 114                      'carousel_mode' => array(
 115                          'version' => 'pro',
 116                          'type' => 'select',
 117                          'default'    => 'posts',
 118                          'selectvalues'=> array(
 119                              'posts'         => array( 'name' => __( 'Post Thumbnails (posts)', 'pagelines' ) ),
 120                              'flickr'        => array( 'name' => __( 'Flickr', 'pagelines' ) ),
 121                              'ngen_gallery'     => array( 'name' => __( 'NextGen Gallery', 'pagelines' ) ),
 122                              'hook'            => array( 'name' => __( 'Hook: pagelines_carousel_list', 'pagelines' ) )
 123                          ),
 124                          'title'     => __( 'Carousel Image/Link Mode (Carousel Page Template)', 'pagelines' ),
 125                          'shortexp'     => __( 'Select the mode that the carousel should use for its thumbnails.', 'pagelines' ),
 126                          'exp'        => __( '<strong> Post Thumbnails (default)</strong> - Uses links and thumbnails from posts <br/><strong>Flickr</strong> - Uses thumbs from FlickrRSS plugin.<br/><strong>NextGen Gallery</strong> - Uses an image gallery from the NextGen Gallery Plugin', 'pagelines' )
 127                      ),
 128                      'carousel_image_dimensions' => array(
 129                              'type'         => 'text_multi',
 130                              'inputsize'    => 'small',
 131                              'selectvalues'=> array(
 132                                  'carousel_image_width'        => array('inputlabel'=>__( 'Max Image Width (in pixels)', 'pagelines' ), 'default'    => 64),
 133                                  'carousel_image_height'        => array('inputlabel'=>__( 'Max Image Height (in pixels)', 'pagelines' ), 'default' => 64),
 134                              ),
 135                              'title'     => __( 'Carousel Image Dimensions (Posts Mode Only)', 'pagelines' ),
 136                              'shortexp'     => __( 'Control the dimensions of the carousel images', 'pagelines' ),
 137                              'exp'         => __( 'Use this option to control the max height and width of the images in the carousel. You may have to use this option in conjunction with the scroll items option.<br/><br/> For the FlickrRSS and NextGen Gallery modes, image sizes are set by Flickr thumb sizes and the NextGen Gallery plugin respectively.', 'pagelines' )
 138                      ),
 139                      'carousel_post_id' => array(
 140                          'default'        => '',
 141                          'type'             => 'select_taxonomy',
 142                          'taxonomy_id'    => 'category',
 143                          'title'            => __( 'Posts Mode - Select Post Category', 'pagelines' ),
 144                          'shortexp'        => __( 'The category slug to pull posts from', 'pagelines' ),
 145                          'inputlabel'     => __( 'Select Category for Carousel', 'pagelines' ),
 146                          'exp'             => __( 'Posts Mode - Select the default category for carousel post images.  If not set, the carousel will get the most recent posts.', 'pagelines' )
 147                      ),
 148                      'carousel_ngen_gallery' => array(
 149                          'version' => 'pro',
 150                          'type' => 'text',
 151                          'title' => __( 'NextGen Gallery ID For Carousel (Carousel Page Template / NextGen Mode)', 'pagelines' ),
 152                          'shortexp' => __( 'Enter the ID of the NextGen Image gallery for the carousel.', 'pagelines' ),
 153                          'exp'        => __( '<strong>Note:</strong>The NextGen Gallery and carousel template must be selected.', 'pagelines' )
 154                      )
 155                  );
 156  
 157              $metatab_settings = array(
 158                      'id'         => 'carousel_meta',
 159                      'name'         => 'Carousel',
 160                      'icon'         => $this->icon,
 161                      'clone_id'    => $settings['clone_id'],
 162                      'active'    => $settings['active']
 163                  );
 164  
 165              register_metatab($metatab_settings, $metatab_array);
 166      }
 167  
 168     function section_template( $clone_id ) {
 169  
 170          $carousel_class = (isset($clone_id) && $clone_id != 1) ? 'crsl'.$clone_id : 'crsl';
 171  
 172          // Set Up Variables
 173          $carouselitems = (ploption('carousel_items', $this->oset)) ? ploption('carousel_items', $this->oset) : 30;
 174          $carousel_post_id = (ploption('carousel_post_id', $this->oset)) ? ploption('carousel_post_id', $this->oset) : null;
 175          $carousel_image_width = (ploption('carousel_image_width', $this->oset)) ? ploption('carousel_image_width', $this->oset) : 64;
 176          $carousel_image_height = (ploption('carousel_image_height', $this->oset)) ? ploption('carousel_image_height', $this->oset) : 64;
 177          $cmode = (ploption('carousel_mode', $this->oset)) ? ploption('carousel_mode', $this->oset): null;
 178          $ngen_id = (ploption('carousel_ngen_gallery', $this->oset)) ? ploption('carousel_ngen_gallery', $this->oset) : 1;
 179  
 180  
 181      if( ($cmode == 'flickr' && !function_exists('get_flickrRSS')) || ($cmode == 'ngen_gallery' && !function_exists('nggDisplayRandomImages')) ){
 182  
 183          echo setup_section_notify($this, __("The <strong>plugin</strong> for the selected carousel mode needs to be activated (FlickrRSS or NextGen Gallery).", 'pagelines'), admin_url().'plugins.php', 'Setup Plugin');
 184  
 185      } else {
 186      ?>
 187      <div class="<?php echo $carousel_class;?> thecarousel">
 188          <ul id="mycarousel" class="mycarousel">
 189              <?php
 190  
 191              if(function_exists('nggDisplayRandomImages')  && $cmode == 'ngen_gallery'){
 192  
 193                  echo do_shortcode('[nggallery id='.$ngen_id.' template=plcarousel]');
 194  
 195              }elseif(function_exists('get_flickrRSS') && $cmode == 'flickr'){
 196  
 197                  if(!function_exists('get_and_delete_option')):  // fixes instantiation within the function in the plugin :/
 198                      get_flickrRSS( array(
 199                          'num_items' => $carouselitems,
 200                          'html' => '<li><a href="%flickr_page%" title="%title%"><img src="%image_square%" alt="%title%"/><span class="list-title">%title%</span></a></li>'
 201                      ));
 202                  endif;
 203  
 204              }elseif($cmode == 'hook')
 205                  pagelines_register_hook('pagelines_carousel_list');
 206  
 207              else{
 208  
 209                  $carousel_post_query = 'numberposts='.$carouselitems;
 210  
 211                  if($carousel_post_id)
 212                      $carousel_post_query .= '&category_name='.$carousel_post_id;
 213  
 214                  $recentposts = get_posts($carousel_post_query);
 215  
 216                  foreach($recentposts as $cid => $c){
 217  
 218                      $a = array();
 219  
 220                      if(has_post_thumbnail($c->ID)){
 221                          $img_data = wp_get_attachment_image_src( get_post_thumbnail_id( $c->ID ));
 222  
 223                          $a['img'] = ($img_data[0] != '') ? $img_data[0] : $this->base_url.'/post-blank.jpg';
 224  
 225                          $a['width'] = $img_data[1];
 226                          $a['height'] = $img_data[2];
 227  
 228                      } else {
 229                          $a['img'] = $this->base_url.'/post-blank.jpg';
 230                          $a['width'] = 100;
 231                          $a['height'] = 100;
 232                      }
 233  
 234                      $args = array(
 235                          'title'            => $c->post_title,
 236                          'link'            => get_permalink($c->ID),
 237                          'img'            => $a['img'],
 238                          'maxheight'        => $carousel_image_height,
 239                          'maxwidth'        => $carousel_image_width,
 240                          'height'        => $a['height'],
 241                          'width'            => $a['width']
 242                      );
 243  
 244  
 245  
 246                      echo $this->carousel_item($args);
 247                  }
 248  
 249              } ?>
 250          </ul>
 251      </div>
 252  
 253  <?php
 254  
 255          }
 256      }
 257  
 258  
 259      /**
 260      *
 261      * @TODO document
 262      *
 263      */
 264  	function carousel_item( $args ){
 265  
 266          $d = array(
 267              'title'            => '',
 268              'link'            => '',
 269              'height'        => '100',
 270              'width'            => '100',
 271              'maxheight'        => '100',
 272              'maxwidth'        => '100',
 273              'img'            => '',
 274              'class'            => '',
 275          );
 276  
 277          $a = wp_parse_args($args, $d);
 278  
 279          $img_style = sprintf('style="max-height: %spx; max-width: %spx;"', $a['maxheight'], $a['maxwidth']);
 280  
 281          $img = sprintf('<img src="%s" width="%s" height="%s" %s />', $a['img'], $a['width'], $a['height'], $img_style);
 282  
 283          $link = sprintf('<a class="carousel_image_link" href="%s">%s<span class="list-title">%s</span></a>', $a['link'], $img, $a['title']);
 284  
 285          $out = sprintf('<li class="list-item fix">%s</li>', $link);
 286  
 287          return $out;
 288      }
 289  }


Generated: Thu May 23 23:52:43 2013 Cross-referenced by PHPXref 0.7.1