nggCreateAlbum

Create a gallery overview output.

Description

nggCreateAlbum( (array) $galleriesID, (string) $template = 'extend', (int) $album = 0 ); 

Parameters (3)

0. $galleriesid (array)
The galleriesid.
1. $template — Optional. (string) => 'extend'
$template name for a template file, look for album-$template
2. $album — Optional. (int)
$album result from the db

Usage

  1. if ( !function_exists( 'nggCreateAlbum' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextcellent-gallery/nggfunctions.php'; 
  3.  
  4. // The galleriesid. 
  5. $galleriesid = array(); 
  6.  
  7. // (optional) $template name for a template file, look for album-$template 
  8. $template = 'extend'; 
  9.  
  10. // (optional) $album result from the db 
  11. $album = -1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = nggCreateAlbum($galleriesid, $template, $album); 
  15.  

Defined (1)

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

/nggfunctions.php  
  1. function nggCreateAlbum( $galleriesID, $template = 'extend', $album = 0) { 
  2. global $wpdb, $nggRewrite, $nggdb, $ngg; 
  3.  
  4. // $_GET from wp_query 
  5. $nggpage = get_query_var('nggpage'); 
  6.  
  7. // Get options 
  8. $ngg_options = $ngg->options; 
  9.  
  10. //this option can currently only set via the custom fields 
  11. $maxElement = (int) $ngg_options['galPagedGalleries']; 
  12.  
  13. $sortorder = $galleriesID; 
  14. $galleries = array(); 
  15.  
  16. // get the galleries information 
  17. foreach ($galleriesID as $i => $value) 
  18. $galleriesID[$i] = addslashes($value); 
  19.  
  20. $unsort_galleries = $wpdb->get_results('SELECT * FROM '.$wpdb->nggallery.' WHERE gid IN (\''.implode('\', \'', $galleriesID).'\')', OBJECT_K); 
  21.  
  22. //TODO: Check this, problem exist when previewpic = 0 
  23. //$galleries = $wpdb->get_results('SELECT t.*, tt.* FROM '.$wpdb->nggallery.' AS t INNER JOIN '.$wpdb->nggpictures.' AS tt ON t.previewpic = tt.pid WHERE t.gid IN (\''.implode('\', \'', $galleriesID).'\')', OBJECT_K); 
  24.  
  25. // get the counter values 
  26. $picturesCounter = $wpdb->get_results('SELECT galleryid, COUNT(*) as counter FROM '.$wpdb->nggpictures.' WHERE galleryid IN (\''.implode('\', \'', $galleriesID).'\') AND exclude != 1 GROUP BY galleryid', OBJECT_K); 
  27. if ( is_array($picturesCounter) ) { 
  28. foreach ($picturesCounter as $key => $value) 
  29. $unsort_galleries[$key]->counter = $value->counter; 
  30.  
  31. // get the id's of the preview images 
  32. $imagesID = array(); 
  33. if ( is_array($unsort_galleries) ) { 
  34. foreach ($unsort_galleries as $gallery_row) 
  35. $imagesID[] = $gallery_row->previewpic; 
  36. $albumPreview = $wpdb->get_results('SELECT pid, filename FROM '.$wpdb->nggpictures.' WHERE pid IN (\''.implode('\', \'', $imagesID).'\')', OBJECT_K); 
  37.  
  38. // re-order them and populate some 
  39. foreach ($sortorder as $key) { 
  40.  
  41. // Create a gallery object 
  42. if (isset($unsort_galleries[$key])) $galleries[$key] = $unsort_galleries[$key]; 
  43. else $galleries[$key] = new stdClass; 
  44.  
  45. //if we have a prefix 'a' then it's a subalbum, instead a gallery 
  46. if (substr( $key, 0, 1) == 'a') { 
  47. if (($subalbum = nggdb::find_album(substr($key, 1)))) { 
  48. $galleries[$key]->counter = count($subalbum->gallery_ids); 
  49. if ($subalbum->previewpic > 0) { 
  50. $image = $nggdb->find_image( $subalbum->previewpic ); 
  51. $galleries[$key]->previewurl = isset($image->thumbURL) ? $image->thumbURL : ''; 
  52. $galleries[$key]->previewpic = $subalbum->previewpic; 
  53. $galleries[$key]->previewname = $subalbum->name; 
  54.  
  55. //link to the subalbum 
  56. $args['album'] = ( $ngg_options['usePermalinks'] ) ? $subalbum->slug : $subalbum->id; 
  57. $args['gallery'] = false; 
  58. $args['nggpage'] = false; 
  59. $pageid = (isset($subalbum->pageid) ? $subalbum->pageid : 0); 
  60. $galleries[$key]->pagelink = ($pageid > 0) ? get_permalink($pageid) : $nggRewrite->get_permalink($args); 
  61. $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n($subalbum->albumdesc) ); 
  62. $galleries[$key]->title = esc_attr(html_entity_decode ( nggGallery::i18n($subalbum->name) )); 
  63. elseif (isset($unsort_galleries[$key])) { 
  64. $galleries[$key] = $unsort_galleries[$key]; 
  65.  
  66. // No images found, set counter to 0 
  67. if (!isset($galleries[$key]->counter)) { 
  68. $galleries[$key]->counter = 0; 
  69. $galleries[$key]->previewurl = ''; 
  70.  
  71. // add the file name and the link 
  72. if ($galleries[$key]->previewpic != 0) { 
  73. $galleries[$key]->previewname = $albumPreview[$galleries[$key]->previewpic]->filename; 
  74. $galleries[$key]->previewurl = site_url().'/' . $galleries[$key]->path . '/thumbs/thumbs_' . $albumPreview[$galleries[$key]->previewpic]->filename; 
  75. } else { 
  76. $first_image = $wpdb->get_row('SELECT * FROM '. $wpdb->nggpictures .' WHERE exclude != 1 AND galleryid = '. $key .' ORDER by pid DESC limit 0, 1'); 
  77. if (isset($first_image)) { 
  78. $galleries[$key]->previewpic = $first_image->pid; 
  79. $galleries[$key]->previewname = $first_image->filename; 
  80. $galleries[$key]->previewurl = site_url() . '/' . $galleries[$key]->path . '/thumbs/thumbs_' . $first_image->filename; 
  81.  
  82. // choose between variable and page link 
  83. if ($ngg_options['galNoPages']) { 
  84. $args['album'] = ( $ngg_options['usePermalinks'] ) ? $album->slug : $album->id; 
  85. $args['gallery'] = ( $ngg_options['usePermalinks'] ) ? $galleries[$key]->slug : $key; 
  86. $args['nggpage'] = false; 
  87. $galleries[$key]->pagelink = $nggRewrite->get_permalink($args); 
  88.  
  89. } else { 
  90. $galleries[$key]->pagelink = get_permalink( $galleries[$key]->pageid ); 
  91.  
  92. // description can contain HTML tags 
  93. $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n( stripslashes($galleries[$key]->galdesc), 'gal_' . $galleries[$key]->gid . '_description') ); 
  94.  
  95. // i18n 
  96. $galleries[$key]->title = esc_attr( html_entity_decode( nggGallery::i18n( $galleries[$key]->title, 'gal_' . $galleries[$key]->gid . '_title' ) ) ); 
  97.  
  98. // apply a filter on gallery object before the output 
  99. $galleries[$key] = apply_filters('ngg_album_galleryobject', $galleries[$key]); 
  100.  
  101. // apply a filter on gallery object before paging starts 
  102. $galleries = apply_filters('ngg_album_galleries_before_paging', $galleries, $album); 
  103.  
  104. // check for page navigation 
  105. if ($maxElement > 0) { 
  106. if ( !is_home() || $pageid == get_the_ID() ) { 
  107. $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1; 
  108. else $page = 1; 
  109.  
  110. $start = $offset = ( $page - 1 ) * $maxElement; 
  111.  
  112. $total = count($galleries); 
  113.  
  114. // remove the element if we didn't start at the beginning 
  115. if ($start > 0 ) array_splice($galleries, 0, $start); 
  116.  
  117. // return the list of images we need 
  118. array_splice($galleries, $maxElement); 
  119.  
  120. $nggNav = new nggNavigation; 
  121. $navigation = $nggNav->create_navigation($page, $total, $maxElement); 
  122. } else { 
  123. $navigation = '<div class="ngg-clear"></div>'; 
  124.  
  125. // apply a filter on $galleries before the output 
  126. $galleries = apply_filters('ngg_album_galleries', $galleries); 
  127.  
  128. // if sombody didn't enter any template , take the extend version 
  129. $filename = ( empty($template) ) ? 'album-extend' : 'album-' . $template ; 
  130.  
  131. // create the output 
  132. $out = nggGallery::capture ( $filename, array ('album' => $album, 'galleries' => $galleries, 'pagination' => $navigation) ); 
  133.  
  134. return $out; 
  135.