nggCreateImageBrowser

Create an image browser from a list of image objects.

Description

nggCreateImageBrowser( (array) $picturelist, (string) $template = '' ); 

Parameters (2)

0. $picturelist (array)
The picturelist.
1. $template — Optional. (string) => ''
name for a template file, look for imagebrowser-$template

Usage

  1. if ( !function_exists( 'nggCreateImageBrowser' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextcellent-gallery/nggfunctions.php'; 
  3.  
  4. // The picturelist. 
  5. $picturelist = array(); 
  6.  
  7. // (optional) name for a template file, look for imagebrowser-$template 
  8. $template = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = nggCreateImageBrowser($picturelist, $template); 
  12.  

Defined (1)

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

/nggfunctions.php  
  1. function nggCreateImageBrowser($picturelist, $template = '') { 
  2.  
  3. global $nggRewrite, $ngg; 
  4.  
  5. require_once( dirname (__FILE__) . '/lib/meta.php' ); 
  6.  
  7. // $_GET from wp_query 
  8. $pid = get_query_var('pid'); 
  9.  
  10. // we need to know the current page id 
  11. $current_page = (get_the_ID() == false) ? 0 : get_the_ID(); 
  12.  
  13. // create a array with id's for better walk inside 
  14. $picarray = array(); 
  15. foreach ($picturelist as $picture) 
  16. $picarray[] = $picture->pid; 
  17.  
  18. $total = count($picarray); 
  19.  
  20. if ( !empty( $pid )) { 
  21. if ( is_numeric($pid) ) 
  22. $act_pid = intval($pid); 
  23. else { 
  24. // in the case it's a slug we need to search for the pid 
  25. foreach ($picturelist as $key => $picture) { 
  26. if ($picture->image_slug == $pid) { 
  27. $act_pid = $key; 
  28. break; 
  29. } else { 
  30. reset($picarray); 
  31. $act_pid = current($picarray); 
  32.  
  33. // get ids for back/next 
  34. $key = array_search($act_pid, $picarray); 
  35. if (!$key) { 
  36. $act_pid = reset($picarray); 
  37. $key = key($picarray); 
  38. $back_pid = ( $key >= 1 ) ? $picarray[$key-1] : end($picarray) ; 
  39. $next_pid = ( $key < ($total-1) ) ? $picarray[$key+1] : reset($picarray) ; 
  40.  
  41. // get the picture data 
  42. $picture = nggdb::find_image($act_pid); 
  43.  
  44. // if we didn't get some data, exit now 
  45. if ($picture == null) 
  46. return; 
  47.  
  48. // add more variables for render output 
  49. $picture->href_link = $picture->get_href_link(); 
  50. $args ['pid'] = ($ngg->options['usePermalinks']) ? $picturelist[$back_pid]->image_slug : $back_pid; 
  51. $picture->previous_image_link = $nggRewrite->get_permalink( $args ); 
  52. $picture->previous_pid = $back_pid; 
  53. $args ['pid'] = ($ngg->options['usePermalinks']) ? $picturelist[$next_pid]->image_slug : $next_pid; 
  54. $picture->next_image_link = $nggRewrite->get_permalink( $args ); 
  55. $picture->next_pid = $next_pid; 
  56. $picture->number = $key + 1; 
  57. $picture->total = $total; 
  58. $picture->linktitle = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  59. $picture->alttext = ( empty($picture->alttext) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) ); 
  60. $picture->description = ( empty($picture->description) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  61. $picture->anchor = 'ngg-imagebrowser-' . $picture->galleryid . '-' . $current_page; 
  62.  
  63. // filter to add custom content for the output 
  64. $picture = apply_filters('ngg_image_object', $picture, $act_pid); 
  65.  
  66. // let's get the meta data 
  67. $meta = new nggMeta($act_pid); 
  68. $meta->sanitize(); 
  69. $exif = $meta->get_EXIF(); 
  70. $iptc = $meta->get_IPTC(); 
  71. $xmp = $meta->get_XMP(); 
  72. $db = $meta->get_saved_meta(); 
  73.  
  74. //if we get no exif information we try the database 
  75. $exif = ($exif == false) ? $db : $exif; 
  76.  
  77. // look for imagebrowser-$template.php or pure imagebrowser.php 
  78. $filename = ( empty($template) ) ? 'imagebrowser' : 'imagebrowser-' . $template; 
  79.  
  80. // create the output 
  81. $out = nggGallery::capture ( $filename , array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db) ); 
  82.  
  83. return $out; 
  84.