nggCreateGallery

Build a gallery output.

Description

nggCreateGallery( (array) $picturelist, (constant) $galleryID = false, (string) $template = '', (constant) $images = false ); 

Parameters (4)

0. $picturelist (array)
The picturelist.
1. $galleryid (constant)
If you supply a gallery ID, you can add a slideshow link
2. $template — Optional. (string) => ''
name for a template file, look for gallery-$template
3. $images — Optional. (constant) => false
number of images per page

Usage

  1. if ( !function_exists( 'nggCreateGallery' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextcellent-gallery/nggfunctions.php'; 
  3.  
  4. // The picturelist. 
  5. $picturelist = array(); 
  6.  
  7. // if you supply a gallery ID, you can add a slideshow link 
  8. $galleryid = null; 
  9.  
  10. // (optional) name for a template file, look for gallery-$template 
  11. $template = ''; 
  12.  
  13. // (optional) number of images per page 
  14. $images = false; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = nggCreateGallery($picturelist, $galleryid, $template, $images); 
  18.  

Defined (1)

The function is defined in the following location(s).

/nggfunctions.php  
  1. function nggCreateGallery($picturelist, $galleryID = false, $template = '', $images = false) { 
  2. global $nggRewrite; 
  3.  
  4. require_once (dirname (__FILE__) . '/lib/media-rss.php'); 
  5.  
  6. $ngg_options = nggGallery::get_option(ngg_options); 
  7.  
  8. //the shortcode parameter will override global settings, TODO: rewrite this to a class 
  9. $ngg_options['galImages'] = ( $images === false ) ? $ngg_options['galImages'] : (int) $images; 
  10.  
  11. $current_pid = false; 
  12.  
  13. // $_GET from wp_query 
  14. $nggpage = get_query_var('nggpage'); 
  15. $pageid = get_query_var('pageid'); 
  16. $pid = get_query_var('pid'); 
  17.  
  18. // in case of permalinks the pid is a slug, we need the id 
  19. if( !is_numeric($pid) && !empty($pid) ) { 
  20. $picture = nggdb::find_image($pid); 
  21. $pid = $picture->pid; 
  22.  
  23. // we need to know the current page id 
  24. $current_page = (get_the_ID() == false) ? 0 : get_the_ID(); 
  25.  
  26. if ( !is_array($picturelist) ) 
  27. $picturelist = array($picturelist); 
  28.  
  29. // Populate galleries values from the first image 
  30. $first_image = current($picturelist); 
  31. $gallery = new stdclass; 
  32. $gallery->ID = (int) $galleryID; 
  33. $gallery->show_slideshow = false; 
  34. $gallery->show_piclens = false; 
  35. $gallery->name = stripslashes ( $first_image->name ); 
  36. $gallery->title = stripslashes( $first_image->title ); 
  37. $gallery->description = html_entity_decode(stripslashes( $first_image->galdesc)); 
  38. $gallery->pageid = $first_image->pageid; 
  39. $gallery->anchor = 'ngg-gallery-' . $galleryID . '-' . $current_page; 
  40. reset($picturelist); 
  41.  
  42. $maxElement = $ngg_options['galImages']; 
  43. $thumbwidth = $ngg_options['thumbwidth']; 
  44. $thumbheight = $ngg_options['thumbheight']; 
  45.  
  46. // fixed width if needed 
  47. $gallery->columns = intval($ngg_options['galColumns']); 
  48. $gallery->imagewidth = ($gallery->columns > 0) ? 'style="width:' . floor(100/$gallery->columns) . '%;"' : ''; 
  49.  
  50. // obsolete in V1.4.0, but kept for compat reason 
  51. // pre set thumbnail size, from the option, later we look for meta data. 
  52. $thumbsize = ($ngg_options['thumbfix']) ? $thumbsize = 'width="' . $thumbwidth . '" height="'.$thumbheight . '"' : ''; 
  53.  
  54. // show slideshow link 
  55. if ($galleryID) { 
  56. if ($ngg_options['galShowSlide']) { 
  57. $gallery->show_slideshow = true; 
  58. $gallery->slideshow_link = $nggRewrite->get_permalink(array ( 'show' => 'slide') ); 
  59. $gallery->slideshow_link_text = nggGallery::i18n($ngg_options['galTextSlide']); 
  60.  
  61. if ($ngg_options['usePicLens']) { 
  62. $gallery->show_piclens = true; 
  63. $gallery->piclens_link = "javascript:PicLensLite.start({feedUrl:'" . htmlspecialchars( nggMediaRss::get_gallery_mrss_url($gallery->ID) ) . "'});"; 
  64.  
  65. // check for page navigation 
  66. if ($maxElement > 0) { 
  67.  
  68. if ( !is_home() || $pageid == $current_page ) 
  69. $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1; 
  70. else 
  71. $page = 1; 
  72.  
  73. $start = $offset = ( $page - 1 ) * $maxElement; 
  74.  
  75. $total = count($picturelist); 
  76.  
  77. //we can work with display:hidden for some javascript effects 
  78. if (!$ngg_options['galHiddenImg']) { 
  79. // remove the element if we didn't start at the beginning 
  80. if ($start > 0 ) 
  81. array_splice($picturelist, 0, $start); 
  82.  
  83. // return the list of images we need 
  84. array_splice($picturelist, $maxElement); 
  85.  
  86. $nggNav = new nggNavigation; 
  87. $navigation = $nggNav->create_navigation($page, $total, $maxElement); 
  88. } else { 
  89. $navigation = '<div class="ngg-clear"></div>'; 
  90.  
  91. //we cannot use the key as index, cause it's filled with the pid 
  92. $index = 0; 
  93. foreach ($picturelist as $key => $picture) { 
  94.  
  95. //needed for hidden images (THX to Sweigold for the main idea at : http://wordpress.org/support/topic/228743/ ) 
  96. $picturelist[$key]->hidden = false; 
  97. $picturelist[$key]->style = $gallery->imagewidth; 
  98.  
  99. if ($maxElement > 0 && $ngg_options['galHiddenImg']) { 
  100. if ( ($index < $start) || ($index > ($start + $maxElement -1)) ) { 
  101. //FZSM Check: dinamically created nggImage doesn't have this properties 
  102. $picturelist[$key]->hidden = true; 
  103. $picturelist[$key]->style = ($gallery->columns > 0) ? 'style="width:' . floor(100/$gallery->columns) . '%;display: none;"' : 'style="display: none;"'; 
  104. $index++; 
  105.  
  106. // get the effect code 
  107. if ($galleryID) 
  108. $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode('set_' . $galleryID); 
  109. else 
  110. $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode(get_the_title()); 
  111.  
  112. // create link for imagebrowser and other effects 
  113. $args ['nggpage'] = empty($nggpage) || ($template != 'carousel') ? false : $nggpage; // only needed for carousel mode 
  114. $args ['pid'] = ($ngg_options['usePermalinks']) ? $picture->image_slug : $picture->pid; 
  115. $picturelist[$key]->pidlink = $nggRewrite->get_permalink( $args ); 
  116.  
  117. // generate the thumbnail size if the meta data available 
  118. if ( isset($picturelist[$key]->meta_data['thumbnail']) && is_array ($size = $picturelist[$key]->meta_data['thumbnail']) ) 
  119. $thumbsize = 'width="' . $size['width'] . '" height="' . $size['height'] . '"'; 
  120.  
  121. // choose link between imagebrowser or effect 
  122. $link = ($ngg_options['galImgBrowser']) ? $picturelist[$key]->pidlink : $picture->imageURL; 
  123. // bad solution : for now we need the url always for the carousel, should be reworked in the future 
  124. $picturelist[$key]->url = $picture->imageURL; 
  125. // add a filter for the link 
  126. $picturelist[$key]->imageURL = apply_filters('ngg_create_gallery_link', $link, $picture); 
  127. $picturelist[$key]->thumbnailURL = $picture->thumbURL; 
  128. $picturelist[$key]->size = $thumbsize; 
  129. $picturelist[$key]->thumbcode = $thumbcode; 
  130. $picturelist[$key]->caption = ( empty($picture->description) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  131. $picturelist[$key]->description = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  132. $picturelist[$key]->alttext = ( empty($picture->alttext) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) ); 
  133.  
  134. // filter to add custom content for the output 
  135. $picturelist[$key] = apply_filters('ngg_image_object', $picturelist[$key], $picture->pid); 
  136.  
  137. //check if $pid is in the array 
  138. if ($picture->pid == $pid) 
  139. $current_pid = $picturelist[$key]; 
  140. reset($picturelist); 
  141.  
  142. //for paged galleries, take the first image in the array if it's not in the list 
  143. $current_pid = ( empty($current_pid) ) ? current( $picturelist ) : $current_pid; 
  144.  
  145. // look for gallery-$template.php or pure gallery.php 
  146. $filename = ( empty($template) ) ? 'gallery' : 'gallery-' . $template; 
  147.  
  148. //filter functions for custom addons 
  149. $gallery = apply_filters( 'ngg_gallery_object', $gallery, $galleryID ); 
  150. $picturelist = apply_filters( 'ngg_picturelist_object', $picturelist, $galleryID ); 
  151.  
  152. //additional navigation links 
  153. $next = ( empty($nggNav->next) ) ? false : $nggNav->next; 
  154. $prev = ( empty($nggNav->prev) ) ? false : $nggNav->prev; 
  155.  
  156. // create the output 
  157. $out = nggGallery::capture( $filename, array ('gallery' => $gallery, 'images' => $picturelist, 'pagination' => $navigation, 'current' => $current_pid, 'next' => $next, 'prev' => $prev) ); 
  158.  
  159. // apply a filter after the output 
  160. $out = apply_filters('ngg_gallery_output', $out, $picturelist); 
  161.  
  162. return $out;