/nggfunctions.php

  1. <?php 
  2.  
  3. class NGG_Not_Found extends Exception { 
  4.  
  5.  
  6. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); } 
  7.  
  8. /** 
  9. * Return a slideshow. 
  10. * 
  11. * @param int $galleryID ID of the gallery. 
  12. * @param array $args (optional) An array of options. 
  13. * 
  14. * @return string The HTML code for the slideshow. 
  15. * @throws NGG_Not_Found 
  16. */ 
  17. function nggShowSlideshow( $galleryID, $args = null) { 
  18.  
  19. global $slideCounter, $nggdb, $ngg; 
  20. $ngg_options = $ngg->options; 
  21.  
  22. // remove media file from RSS feed 
  23. if ( is_feed() ) { 
  24. $out = '[' . nggGallery::i18n($ngg_options['galTextSlide']) . ']'; 
  25. return $out; 
  26.  
  27. // we need to know the current page id 
  28. if ( !get_the_ID() ) { 
  29. $current_page = rand( 5, 15 ); 
  30. } else { 
  31. $current_page = get_the_ID(); 
  32. // look for a other slideshow instance 
  33. if ( !isset( $slideCounter ) ) $slideCounter = 0; 
  34.  
  35. // create unique anchor 
  36. $anchor = 'ngg_slideshow' . $galleryID . $current_page . $slideCounter++; 
  37.  
  38. $param = wp_parse_args( $args, array( 
  39. 'width' => $ngg_options['irWidth'],  
  40. 'height' => $ngg_options['irHeight'],  
  41. 'class' => 'ngg-slideshow',  
  42. 'anchor' => 'ngg_slideshow' . $galleryID . $current_page . $slideCounter++,  
  43. 'time' => $ngg_options['irRotatetime']*1000,  
  44. 'loop' => $ngg_options['irLoop'],  
  45. 'drag' => $ngg_options['irDrag'],  
  46. 'nav' => $ngg_options['irNavigation'],  
  47. 'nav_dots' => $ngg_options['irNavigationDots'],  
  48. 'autoplay' => $ngg_options['irAutoplay'],  
  49. 'hover' => $ngg_options['irAutoplayHover'],  
  50. 'effect' => $ngg_options['slideFx'],  
  51. 'click' => $ngg_options['irClick'],  
  52. 'autodim' => $ngg_options['irAutoDim'],  
  53. 'number' => $ngg_options['irNumber'] 
  54. )); 
  55.  
  56. /** 
  57. * Edit the args for a NextCellent slideshow. 
  58. * 
  59. * @since 1.9.25beta2 
  60. * 
  61. * @param array $args { 
  62. * All the arguments. 
  63. * 
  64. * @var int $width The width of the slideshow. Will be ignored if $autodim is true. 
  65. * @var int $height The height of the slideshow. Will be ignored if $autodim is set. 
  66. * @var string $class The class that will be assigned to the div containing the slideshow. 
  67. * @var string $anchor The id that will be assigned to the div containing the slideshow. 
  68. * @var int $time The duration of a slide in milliseconds. 
  69. * @var bool $loop If the slideshow should loop. 
  70. * @var bool $drag If the user can drag through the images. 
  71. * @var bool $nav If the navigation elements (next/previous) should be shown. 
  72. * @var bool $nav_dots If the navigation dots should be shown. 
  73. * @var bool $autoplay If the slideshow should automatically start. 
  74. * @var bool $hover If the slideshow should pause when hovering over it. 
  75. * @var string $effect With which effect the slideshow should use. 
  76. * @var bool $click If the slideshow should go to the next image on click. 
  77. * @var bool $autodim If the slideshow should automatically fit (responsive). When true, this will 
  78. * ignore the $width and $height. 
  79. * @var int $number The number of images that should be displayed. Only works when the gallery ID 
  80. * is set to random or recent. 
  81. * } 
  82. */ 
  83. $param = apply_filters( 'ngg_slideshow_args', $param ); 
  84.  
  85. //Get the images 
  86. if ($galleryID == 'random') { 
  87. $images = nggdb::get_random_images( $param['number'] ); //random images 
  88. } elseif ($galleryID == 'recent') { 
  89. $images = nggdb::find_last_images(0 , $param['number'] ); //the last images 
  90. } else { 
  91. $images = $nggdb->get_gallery($galleryID); //a gallery 
  92.  
  93. if( empty($images) ) { 
  94. throw new NGG_Not_Found( __( "The gallery was not found.", 'nggallery' ) ); 
  95.  
  96. $out = '<div class="slideshow"><div id="' . $param['anchor'] . '" class="' . $param['class'] . ' owl-carousel" '; 
  97.  
  98. if( !$param['autodim'] ) { 
  99. $out .= 'style="max-width: ' . $param['width'] . 'px; max-height: ' . $param['height'] . 'px;"'; 
  100. $out .= '>'; 
  101.  
  102. foreach ( $images as $image ) { 
  103. if( !$param['autodim'] ) { 
  104. $out .= '<img src="' . $image->imageURL .'" alt="' . $image->alttext . '" style="max-width: ' . $param['width'] . 'px; max-height: ' . $param['height'] . 'px; width: auto; height:auto; margin:auto">'; 
  105. } else { 
  106. $out .= '<img src="' . $image->imageURL .'" alt="' . $image->alttext . '" >'; 
  107.  
  108. $out .= '</div></div>'."\n"; 
  109. $out .= "\n".'<script type="text/javascript">'; 
  110. $out .= "jQuery(document).ready(function($) { 
  111. var owl = $('#" . $param['anchor'] . "'); 
  112. owl.owlCarousel({ 
  113. items: 1,  
  114. autoHeight: " . var_export($param['autodim'], true) . ", "; 
  115. if ( $param['nav'] ) { 
  116. $out .= "nav: true,  
  117. navText: ['" . __('previous', 'nggallery') ."', '" . __('next', 'nggallery') ."'], "; 
  118. $out .= " 
  119. dots: " . var_export($param['nav_dots'], true) .",  
  120. autoplay: ". var_export($param['autoplay'], true) .",  
  121. autoplayTimeout: " . $param['time'] . ",  
  122. autoplayHoverPause: " . var_export($param['hover'], true) . ",  
  123. animateIn: '" . $param['effect'] . "',  
  124. animateOut: 'fadeOut',  
  125. loop: " . var_export($param['loop'], true) . ",  
  126. mouseDrag: " . var_export($param['drag'], true) .",  
  127. touchDrag: " . var_export($param['drag'], true) . " 
  128. });"; 
  129. if ( $param['click'] ) { 
  130. $out .= "\n" . "owl.click( function () { 
  131. owl.trigger( 'next.owl.carousel' ); 
  132. } );"; 
  133. $out .= "});"; 
  134.  
  135. $out .= "\n" . '</script>'; 
  136.  
  137. return $out; 
  138.  
  139. /** 
  140. * nggShowGallery() - return a gallery 
  141. * 
  142. * @access public 
  143. * @param int | string ID or slug from a gallery 
  144. * @param string $template (optional) name for a template file, look for gallery-$template 
  145. * @param int $images (optional) number of images per page 
  146. * @return the content 
  147. */ 
  148. function nggShowGallery( $galleryID, $template = '', $images = false ) { 
  149.  
  150. global $nggRewrite, $nggdb; 
  151.  
  152. $ngg_options = nggGallery::get_option('ngg_options'); 
  153.  
  154. //Set sort order value, if not used (upgrade issue) 
  155. $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid'; 
  156. $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC'; 
  157.  
  158. // get gallery values 
  159. //TODO: Use pagination limits here to reduce memory needs 
  160. //20130106:shouldn't call it statically if is not... 
  161. //$picturelist = nggdb::get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']); 
  162. //array of nggImage objects returned 
  163. $picturelist = $nggdb->get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']); 
  164.  
  165. if ( !$picturelist ) 
  166. return __('[Gallery not found]', 'nggallery'); 
  167.  
  168. // If we have we slug instead the id, we should extract the ID from the first image 
  169. if ( !is_numeric($galleryID) ) { 
  170. $first_image = current($picturelist); 
  171. $galleryID = intval($first_image->gid); 
  172.  
  173. // $_GET from wp_query 
  174. $show = get_query_var('show'); 
  175. $pid = get_query_var('pid'); 
  176. $pageid = get_query_var('pageid'); 
  177.  
  178. // set $show if slideshow first 
  179. if ( empty( $show ) AND ($ngg_options['galShowOrder'] == 'slide')) { 
  180. if ( is_home() ) 
  181. $pageid = get_the_ID(); 
  182.  
  183. $show = 'slide'; 
  184.  
  185. // filter to call up the imagebrowser instead of the gallery 
  186. // use in your theme : add_action( 'ngg_show_imagebrowser_first', create_function('', 'return true;') ); 
  187. if ( apply_filters('ngg_show_imagebrowser_first', false, $galleryID ) && $show != 'thumbnails' ) { 
  188. $out = nggShowImageBrowser( $galleryID, $template ); 
  189. return $out; 
  190.  
  191. // go on only on this page 
  192. if ( !is_home() || $pageid == get_the_ID() ) { 
  193.  
  194. // 1st look for ImageBrowser link 
  195. if ( !empty($pid) && $ngg_options['galImgBrowser'] && ($template != 'carousel') ) { 
  196. $out = nggShowImageBrowser( $galleryID, $template ); 
  197. return $out; 
  198.  
  199. // 2nd look for slideshow 
  200. if ( $show == 'slide' ) { 
  201. $args['show'] = "gallery"; 
  202. $out = '<div class="ngg-galleryoverview">'; 
  203. $out .= '<div class="slideshowlink"><a class="slideshowlink" href="' . $nggRewrite->get_permalink($args) . '">'.nggGallery::i18n($ngg_options['galTextGallery']).'</a></div>'; 
  204. $out .= nggShowSlideshow($galleryID); 
  205. $out .= '</div>'."\n"; 
  206. $out .= '<div class="ngg-clear"></div>'."\n"; 
  207. return $out; 
  208.  
  209. // get all picture with this galleryid 
  210. if ( is_array($picturelist) ) 
  211. $out = nggCreateGallery($picturelist, $galleryID, $template, $images); 
  212.  
  213. $out = apply_filters('ngg_show_gallery_content', $out, intval($galleryID)); 
  214. return $out; 
  215.  
  216. /** 
  217. * Build a gallery output 
  218. * 
  219. * @access internal 
  220. * @param array $picturelist 
  221. * @param bool $galleryID, if you supply a gallery ID, you can add a slideshow link 
  222. * @param string $template (optional) name for a template file, look for gallery-$template 
  223. * @param int $images (optional) number of images per page 
  224. * @return the content 
  225. */ 
  226. function nggCreateGallery($picturelist, $galleryID = false, $template = '', $images = false) { 
  227. global $nggRewrite; 
  228.  
  229. require_once (dirname (__FILE__) . '/lib/media-rss.php'); 
  230.  
  231. $ngg_options = nggGallery::get_option('ngg_options'); 
  232.  
  233. //the shortcode parameter will override global settings, TODO: rewrite this to a class 
  234. $ngg_options['galImages'] = ( $images === false ) ? $ngg_options['galImages'] : (int) $images; 
  235.  
  236. $current_pid = false; 
  237.  
  238. // $_GET from wp_query 
  239. $nggpage = get_query_var('nggpage'); 
  240. $pageid = get_query_var('pageid'); 
  241. $pid = get_query_var('pid'); 
  242.  
  243. // in case of permalinks the pid is a slug, we need the id 
  244. if( !is_numeric($pid) && !empty($pid) ) { 
  245. $picture = nggdb::find_image($pid); 
  246. $pid = $picture->pid; 
  247.  
  248. // we need to know the current page id 
  249. $current_page = (get_the_ID() == false) ? 0 : get_the_ID(); 
  250.  
  251. if ( !is_array($picturelist) ) 
  252. $picturelist = array($picturelist); 
  253.  
  254. // Populate galleries values from the first image 
  255. $first_image = current($picturelist); 
  256. $gallery = new stdclass; 
  257. $gallery->ID = (int) $galleryID; 
  258. $gallery->show_slideshow = false; 
  259. $gallery->show_piclens = false; 
  260. $gallery->name = stripslashes ( $first_image->name ); 
  261. $gallery->title = stripslashes( $first_image->title ); 
  262. $gallery->description = html_entity_decode(stripslashes( $first_image->galdesc)); 
  263. $gallery->pageid = $first_image->pageid; 
  264. $gallery->anchor = 'ngg-gallery-' . $galleryID . '-' . $current_page; 
  265. reset($picturelist); 
  266.  
  267. $maxElement = $ngg_options['galImages']; 
  268. $thumbwidth = $ngg_options['thumbwidth']; 
  269. $thumbheight = $ngg_options['thumbheight']; 
  270.  
  271. // fixed width if needed 
  272. $gallery->columns = intval($ngg_options['galColumns']); 
  273. $gallery->imagewidth = ($gallery->columns > 0) ? 'style="width:' . floor(100/$gallery->columns) . '%;"' : ''; 
  274.  
  275. // obsolete in V1.4.0, but kept for compat reason 
  276. // pre set thumbnail size, from the option, later we look for meta data. 
  277. $thumbsize = ($ngg_options['thumbfix']) ? $thumbsize = 'width="' . $thumbwidth . '" height="'.$thumbheight . '"' : ''; 
  278.  
  279. // show slideshow link 
  280. if ($galleryID) { 
  281. if ($ngg_options['galShowSlide']) { 
  282. $gallery->show_slideshow = true; 
  283. $gallery->slideshow_link = $nggRewrite->get_permalink(array ( 'show' => 'slide') ); 
  284. $gallery->slideshow_link_text = nggGallery::i18n($ngg_options['galTextSlide']); 
  285.  
  286. if ($ngg_options['usePicLens']) { 
  287. $gallery->show_piclens = true; 
  288. $gallery->piclens_link = "javascript:PicLensLite.start({feedUrl:'" . htmlspecialchars( nggMediaRss::get_gallery_mrss_url($gallery->ID) ) . "'});"; 
  289.  
  290. // check for page navigation 
  291. if ($maxElement > 0) { 
  292.  
  293. if ( !is_home() || $pageid == $current_page ) 
  294. $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1; 
  295. else 
  296. $page = 1; 
  297.  
  298. $start = $offset = ( $page - 1 ) * $maxElement; 
  299.  
  300. $total = count($picturelist); 
  301.  
  302. //we can work with display:hidden for some javascript effects 
  303. if (!$ngg_options['galHiddenImg']) { 
  304. // remove the element if we didn't start at the beginning 
  305. if ($start > 0 ) 
  306. array_splice($picturelist, 0, $start); 
  307.  
  308. // return the list of images we need 
  309. array_splice($picturelist, $maxElement); 
  310.  
  311. $nggNav = new nggNavigation; 
  312. $navigation = $nggNav->create_navigation($page, $total, $maxElement); 
  313. } else { 
  314. $navigation = '<div class="ngg-clear"></div>'; 
  315.  
  316. //we cannot use the key as index, cause it's filled with the pid 
  317. $index = 0; 
  318. foreach ($picturelist as $key => $picture) { 
  319.  
  320. //needed for hidden images (THX to Sweigold for the main idea at : http://wordpress.org/support/topic/228743/ ) 
  321. $picturelist[$key]->hidden = false; 
  322. $picturelist[$key]->style = $gallery->imagewidth; 
  323.  
  324. if ($maxElement > 0 && $ngg_options['galHiddenImg']) { 
  325. if ( ($index < $start) || ($index > ($start + $maxElement -1)) ) { 
  326. //FZSM Check: dinamically created nggImage doesn't have this properties 
  327. $picturelist[$key]->hidden = true; 
  328. $picturelist[$key]->style = ($gallery->columns > 0) ? 'style="width:' . floor(100/$gallery->columns) . '%;display: none;"' : 'style="display: none;"'; 
  329. $index++; 
  330.  
  331. // get the effect code 
  332. if ($galleryID) 
  333. $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode('set_' . $galleryID); 
  334. else 
  335. $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode(get_the_title()); 
  336.  
  337. // create link for imagebrowser and other effects 
  338. $args ['nggpage'] = empty($nggpage) || ($template != 'carousel') ? false : $nggpage; // only needed for carousel mode 
  339. $args ['pid'] = ($ngg_options['usePermalinks']) ? $picture->image_slug : $picture->pid; 
  340. $picturelist[$key]->pidlink = $nggRewrite->get_permalink( $args ); 
  341.  
  342. // generate the thumbnail size if the meta data available 
  343. if ( isset($picturelist[$key]->meta_data['thumbnail']) && is_array ($size = $picturelist[$key]->meta_data['thumbnail']) ) 
  344. $thumbsize = 'width="' . $size['width'] . '" height="' . $size['height'] . '"'; 
  345.  
  346. // choose link between imagebrowser or effect 
  347. $link = ($ngg_options['galImgBrowser']) ? $picturelist[$key]->pidlink : $picture->imageURL; 
  348. // bad solution : for now we need the url always for the carousel, should be reworked in the future 
  349. $picturelist[$key]->url = $picture->imageURL; 
  350. // add a filter for the link 
  351. $picturelist[$key]->imageURL = apply_filters('ngg_create_gallery_link', $link, $picture); 
  352. $picturelist[$key]->thumbnailURL = $picture->thumbURL; 
  353. $picturelist[$key]->size = $thumbsize; 
  354. $picturelist[$key]->thumbcode = $thumbcode; 
  355. $picturelist[$key]->caption = ( empty($picture->description) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  356. $picturelist[$key]->description = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  357. $picturelist[$key]->alttext = ( empty($picture->alttext) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) ); 
  358.  
  359. // filter to add custom content for the output 
  360. $picturelist[$key] = apply_filters('ngg_image_object', $picturelist[$key], $picture->pid); 
  361.  
  362. //check if $pid is in the array 
  363. if ($picture->pid == $pid) 
  364. $current_pid = $picturelist[$key]; 
  365. reset($picturelist); 
  366.  
  367. //for paged galleries, take the first image in the array if it's not in the list 
  368. $current_pid = ( empty($current_pid) ) ? current( $picturelist ) : $current_pid; 
  369.  
  370. // look for gallery-$template.php or pure gallery.php 
  371. $filename = ( empty($template) ) ? 'gallery' : 'gallery-' . $template; 
  372.  
  373. //filter functions for custom addons 
  374. $gallery = apply_filters( 'ngg_gallery_object', $gallery, $galleryID ); 
  375. $picturelist = apply_filters( 'ngg_picturelist_object', $picturelist, $galleryID ); 
  376.  
  377. //additional navigation links 
  378. $next = ( empty($nggNav->next) ) ? false : $nggNav->next; 
  379. $prev = ( empty($nggNav->prev) ) ? false : $nggNav->prev; 
  380.  
  381. // create the output 
  382. $out = nggGallery::capture( $filename, array ('gallery' => $gallery, 'images' => $picturelist, 'pagination' => $navigation, 'current' => $current_pid, 'next' => $next, 'prev' => $prev) ); 
  383.  
  384. // apply a filter after the output 
  385. $out = apply_filters('ngg_gallery_output', $out, $picturelist); 
  386.  
  387. return $out; 
  388.  
  389. /** 
  390. * nggShowAlbum() - return a album based on the id 
  391. * 
  392. * @access public 
  393. * @param int | string $albumID 
  394. * @param string (optional) $template 
  395. * @param string (optional) $gallery_template 
  396. * @return the content 
  397. */ 
  398. function nggShowAlbum($albumID, $template = 'extend', $gallery_template = '') { 
  399.  
  400. // $_GET from wp_query 
  401. $gallery = get_query_var('gallery'); 
  402. $album = get_query_var('album'); 
  403.  
  404. // in the case somebody uses the '0', it should be 'all' to show all galleries 
  405. $albumID = ($albumID == 0) ? 'all' : $albumID; 
  406.  
  407. // first look for gallery variable 
  408. if (!empty( $gallery )) { 
  409.  
  410. // subalbum support only one instance, you can't use more of them in one post 
  411. //TODO: causes problems with SFC plugin, due to a second filter callback 
  412. global $wp_current_filter; 
  413. if ( isset($GLOBALS['subalbum']) || isset($GLOBALS['nggShowGallery'])) 
  414. return; 
  415.  
  416. // if gallery is submit , then show the gallery instead 
  417. $out = nggShowGallery( $gallery, $gallery_template ); 
  418. $GLOBALS['nggShowGallery'] = true; 
  419.  
  420. return $out; 
  421.  
  422. if ( (empty( $gallery )) && (isset($GLOBALS['subalbum'])) ) 
  423. return; 
  424.  
  425. //redirect to subalbum only one time 
  426. if (!empty( $album )) { 
  427. $GLOBALS['subalbum'] = true; 
  428. $albumID = $album; 
  429.  
  430. // lookup in the database 
  431. $album = nggdb::find_album( $albumID ); 
  432.  
  433. // still no success ? , die ! 
  434. if( !$album ) 
  435. return __('[Album not found]', 'nggallery'); 
  436.  
  437. // ensure to set the slug for "all" albums 
  438. $album->slug = ($albumID == 'all') ? $album->id : $album->slug; 
  439.  
  440. if ( is_array($album->gallery_ids) ) 
  441. $out = nggCreateAlbum( $album->gallery_ids, $template, $album ); 
  442.  
  443. $out = apply_filters( 'ngg_show_album_content', $out, $album->id ); 
  444.  
  445. return $out; 
  446.  
  447. /** 
  448. * create a gallery overview output 
  449. * 
  450. * @access internal 
  451. * @param array $galleriesID 
  452. * @param string (optional) $template name for a template file, look for album-$template 
  453. * @param object (optional) $album result from the db 
  454. * @return the content 
  455. */ 
  456. function nggCreateAlbum( $galleriesID, $template = 'extend', $album = 0) { 
  457. global $wpdb, $nggRewrite, $nggdb, $ngg; 
  458.  
  459. // $_GET from wp_query 
  460. $nggpage = get_query_var('nggpage'); 
  461.  
  462. // Get options 
  463. $ngg_options = $ngg->options; 
  464.  
  465. //this option can currently only set via the custom fields 
  466. $maxElement = (int) $ngg_options['galPagedGalleries']; 
  467.  
  468. $sortorder = $galleriesID; 
  469. $galleries = array(); 
  470.  
  471. // get the galleries information 
  472. foreach ($galleriesID as $i => $value) 
  473. $galleriesID[$i] = addslashes($value); 
  474.  
  475. $unsort_galleries = $wpdb->get_results('SELECT * FROM '.$wpdb->nggallery.' WHERE gid IN (\''.implode('\', \'', $galleriesID).'\')', OBJECT_K); 
  476.  
  477. //TODO: Check this, problem exist when previewpic = 0 
  478. //$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); 
  479.  
  480. // get the counter values 
  481. $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); 
  482. if ( is_array($picturesCounter) ) { 
  483. foreach ($picturesCounter as $key => $value) 
  484. $unsort_galleries[$key]->counter = $value->counter; 
  485.  
  486. // get the id's of the preview images 
  487. $imagesID = array(); 
  488. if ( is_array($unsort_galleries) ) { 
  489. foreach ($unsort_galleries as $gallery_row) 
  490. $imagesID[] = $gallery_row->previewpic; 
  491. $albumPreview = $wpdb->get_results('SELECT pid, filename FROM '.$wpdb->nggpictures.' WHERE pid IN (\''.implode('\', \'', $imagesID).'\')', OBJECT_K); 
  492.  
  493. // re-order them and populate some 
  494. foreach ($sortorder as $key) { 
  495.  
  496. // Create a gallery object 
  497. if (isset($unsort_galleries[$key])) $galleries[$key] = $unsort_galleries[$key]; 
  498. else $galleries[$key] = new stdClass; 
  499.  
  500. //if we have a prefix 'a' then it's a subalbum, instead a gallery 
  501. if (substr( $key, 0, 1) == 'a') { 
  502. if (($subalbum = nggdb::find_album(substr($key, 1)))) { 
  503. $galleries[$key]->counter = count($subalbum->gallery_ids); 
  504. if ($subalbum->previewpic > 0) { 
  505. $image = $nggdb->find_image( $subalbum->previewpic ); 
  506. $galleries[$key]->previewurl = isset($image->thumbURL) ? $image->thumbURL : ''; 
  507. $galleries[$key]->previewpic = $subalbum->previewpic; 
  508. $galleries[$key]->previewname = $subalbum->name; 
  509.  
  510. //link to the subalbum 
  511. $args['album'] = ( $ngg_options['usePermalinks'] ) ? $subalbum->slug : $subalbum->id; 
  512. $args['gallery'] = false; 
  513. $args['nggpage'] = false; 
  514. $pageid = (isset($subalbum->pageid) ? $subalbum->pageid : 0); 
  515. $galleries[$key]->pagelink = ($pageid > 0) ? get_permalink($pageid) : $nggRewrite->get_permalink($args); 
  516. $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n($subalbum->albumdesc) ); 
  517. $galleries[$key]->title = esc_attr(html_entity_decode ( nggGallery::i18n($subalbum->name) )); 
  518. elseif (isset($unsort_galleries[$key])) { 
  519. $galleries[$key] = $unsort_galleries[$key]; 
  520.  
  521. // No images found, set counter to 0 
  522. if (!isset($galleries[$key]->counter)) { 
  523. $galleries[$key]->counter = 0; 
  524. $galleries[$key]->previewurl = ''; 
  525.  
  526. // add the file name and the link 
  527. if ($galleries[$key]->previewpic != 0) { 
  528. $galleries[$key]->previewname = $albumPreview[$galleries[$key]->previewpic]->filename; 
  529. $galleries[$key]->previewurl = site_url().'/' . $galleries[$key]->path . '/thumbs/thumbs_' . $albumPreview[$galleries[$key]->previewpic]->filename; 
  530. } else { 
  531. $first_image = $wpdb->get_row('SELECT * FROM '. $wpdb->nggpictures .' WHERE exclude != 1 AND galleryid = '. $key .' ORDER by pid DESC limit 0, 1'); 
  532. if (isset($first_image)) { 
  533. $galleries[$key]->previewpic = $first_image->pid; 
  534. $galleries[$key]->previewname = $first_image->filename; 
  535. $galleries[$key]->previewurl = site_url() . '/' . $galleries[$key]->path . '/thumbs/thumbs_' . $first_image->filename; 
  536.  
  537. // choose between variable and page link 
  538. if ($ngg_options['galNoPages']) { 
  539. $args['album'] = ( $ngg_options['usePermalinks'] ) ? $album->slug : $album->id; 
  540. $args['gallery'] = ( $ngg_options['usePermalinks'] ) ? $galleries[$key]->slug : $key; 
  541. $args['nggpage'] = false; 
  542. $galleries[$key]->pagelink = $nggRewrite->get_permalink($args); 
  543.  
  544. } else { 
  545. $galleries[$key]->pagelink = get_permalink( $galleries[$key]->pageid ); 
  546.  
  547. // description can contain HTML tags 
  548. $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n( stripslashes($galleries[$key]->galdesc), 'gal_' . $galleries[$key]->gid . '_description') ); 
  549.  
  550. // i18n 
  551. $galleries[$key]->title = esc_attr( html_entity_decode( nggGallery::i18n( $galleries[$key]->title, 'gal_' . $galleries[$key]->gid . '_title' ) ) ); 
  552.  
  553. // apply a filter on gallery object before the output 
  554. $galleries[$key] = apply_filters('ngg_album_galleryobject', $galleries[$key]); 
  555.  
  556. // apply a filter on gallery object before paging starts 
  557. $galleries = apply_filters('ngg_album_galleries_before_paging', $galleries, $album); 
  558.  
  559. // check for page navigation 
  560. if ($maxElement > 0) { 
  561. if ( !is_home() || $pageid == get_the_ID() ) { 
  562. $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1; 
  563. else $page = 1; 
  564.  
  565. $start = $offset = ( $page - 1 ) * $maxElement; 
  566.  
  567. $total = count($galleries); 
  568.  
  569. // remove the element if we didn't start at the beginning 
  570. if ($start > 0 ) array_splice($galleries, 0, $start); 
  571.  
  572. // return the list of images we need 
  573. array_splice($galleries, $maxElement); 
  574.  
  575. $nggNav = new nggNavigation; 
  576. $navigation = $nggNav->create_navigation($page, $total, $maxElement); 
  577. } else { 
  578. $navigation = '<div class="ngg-clear"></div>'; 
  579.  
  580. // apply a filter on $galleries before the output 
  581. $galleries = apply_filters('ngg_album_galleries', $galleries); 
  582.  
  583. // if sombody didn't enter any template , take the extend version 
  584. $filename = ( empty($template) ) ? 'album-extend' : 'album-' . $template ; 
  585.  
  586. // create the output 
  587. $out = nggGallery::capture ( $filename, array ('album' => $album, 'galleries' => $galleries, 'pagination' => $navigation) ); 
  588.  
  589. return $out; 
  590.  
  591.  
  592. /** 
  593. * nggShowImageBrowser() 
  594. * 
  595. * @access public 
  596. * @param int|string $galleryID or gallery name 
  597. * @param string $template (optional) name for a template file, look for imagebrowser-$template 
  598. * @return the content 
  599. */ 
  600. function nggShowImageBrowser($galleryID, $template = '') { 
  601.  
  602. global $wpdb, $nggdb; 
  603.  
  604. $ngg_options = nggGallery::get_option('ngg_options'); 
  605.  
  606. //Set sort order value, if not used (upgrade issue) 
  607. $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid'; 
  608. $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC'; 
  609.  
  610. // get the pictures 
  611. //20140106:shouldn't call it statically if is not... 
  612. //$picturelist = nggdb::get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']); 
  613. //return array of nggImages 
  614. $picturelist = $nggdb->get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']); 
  615.  
  616. if ( is_array($picturelist) ) 
  617. $out = nggCreateImageBrowser($picturelist, $template); 
  618. else 
  619. $out = __('[Gallery not found]', 'nggallery'); 
  620.  
  621. $out = apply_filters('ngg_show_imagebrowser_content', $out, $galleryID); 
  622.  
  623. return $out; 
  624.  
  625.  
  626. /** 
  627. * nggCreateImageBrowser() 
  628. * 
  629. * @access internal 
  630. * @param array $picturelist 
  631. * @param string $template (optional) name for a template file, look for imagebrowser-$template 
  632. * @return the content 
  633. */ 
  634. function nggCreateImageBrowser($picturelist, $template = '') { 
  635.  
  636. global $nggRewrite, $ngg; 
  637.  
  638. require_once( dirname (__FILE__) . '/lib/meta.php' ); 
  639.  
  640. // $_GET from wp_query 
  641. $pid = get_query_var('pid'); 
  642.  
  643. // we need to know the current page id 
  644. $current_page = (get_the_ID() == false) ? 0 : get_the_ID(); 
  645.  
  646. // create a array with id's for better walk inside 
  647. $picarray = array(); 
  648. foreach ($picturelist as $picture) 
  649. $picarray[] = $picture->pid; 
  650.  
  651. $total = count($picarray); 
  652.  
  653. if ( !empty( $pid )) { 
  654. if ( is_numeric($pid) ) 
  655. $act_pid = intval($pid); 
  656. else { 
  657. // in the case it's a slug we need to search for the pid 
  658. foreach ($picturelist as $key => $picture) { 
  659. if ($picture->image_slug == $pid) { 
  660. $act_pid = $key; 
  661. break; 
  662. } else { 
  663. reset($picarray); 
  664. $act_pid = current($picarray); 
  665.  
  666. // get ids for back/next 
  667. $key = array_search($act_pid, $picarray); 
  668. if (!$key) { 
  669. $act_pid = reset($picarray); 
  670. $key = key($picarray); 
  671. $back_pid = ( $key >= 1 ) ? $picarray[$key-1] : end($picarray) ; 
  672. $next_pid = ( $key < ($total-1) ) ? $picarray[$key+1] : reset($picarray) ; 
  673.  
  674. // get the picture data 
  675. $picture = nggdb::find_image($act_pid); 
  676.  
  677. // if we didn't get some data, exit now 
  678. if ($picture == null) 
  679. return; 
  680.  
  681. // add more variables for render output 
  682. $picture->href_link = $picture->get_href_link(); 
  683. $args ['pid'] = ($ngg->options['usePermalinks']) ? $picturelist[$back_pid]->image_slug : $back_pid; 
  684. $picture->previous_image_link = $nggRewrite->get_permalink( $args ); 
  685. $picture->previous_pid = $back_pid; 
  686. $args ['pid'] = ($ngg->options['usePermalinks']) ? $picturelist[$next_pid]->image_slug : $next_pid; 
  687. $picture->next_image_link = $nggRewrite->get_permalink( $args ); 
  688. $picture->next_pid = $next_pid; 
  689. $picture->number = $key + 1; 
  690. $picture->total = $total; 
  691. $picture->linktitle = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  692. $picture->alttext = ( empty($picture->alttext) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) ); 
  693. $picture->description = ( empty($picture->description) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  694. $picture->anchor = 'ngg-imagebrowser-' . $picture->galleryid . '-' . $current_page; 
  695.  
  696. // filter to add custom content for the output 
  697. $picture = apply_filters('ngg_image_object', $picture, $act_pid); 
  698.  
  699. // let's get the meta data 
  700. $meta = new nggMeta($act_pid); 
  701. $meta->sanitize(); 
  702. $exif = $meta->get_EXIF(); 
  703. $iptc = $meta->get_IPTC(); 
  704. $xmp = $meta->get_XMP(); 
  705. $db = $meta->get_saved_meta(); 
  706.  
  707. //if we get no exif information we try the database 
  708. $exif = ($exif == false) ? $db : $exif; 
  709.  
  710. // look for imagebrowser-$template.php or pure imagebrowser.php 
  711. $filename = ( empty($template) ) ? 'imagebrowser' : 'imagebrowser-' . $template; 
  712.  
  713. // create the output 
  714. $out = nggGallery::capture ( $filename , array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db) ); 
  715.  
  716. return $out; 
  717.  
  718.  
  719. /** 
  720. * nggSinglePicture() - show a single picture based on the id 
  721. * 
  722. * @access public 
  723. * @param int $imageID, db-ID of the image 
  724. * @param int (optional) $width, width of the image 
  725. * @param int (optional) $height, height of the image 
  726. * @param string $mode (optional) could be none, watermark, web20 
  727. * @param string $float (optional) could be none, left, right 
  728. * @param string $template (optional) name for a template file, look for singlepic-$template 
  729. * @param string $caption (optional) additional caption text 
  730. * @param string $link (optional) link to a other url instead the full image 
  731. * @return the content 
  732. */ 
  733. function nggSinglePicture($imageID, $width = 250, $height = 250, $mode = '', $float = '' , $template = '', $caption = '', $link = '') { 
  734. global $post; 
  735.  
  736. $ngg_options = nggGallery::get_option('ngg_options'); 
  737.  
  738. // get picturedata 
  739. $picture = nggdb::find_image($imageID); 
  740.  
  741. // if we didn't get some data, exit now 
  742. if ($picture == null) 
  743. return __('[SinglePic not found]', 'nggallery'); 
  744.  
  745. // add float to img 
  746. switch ($float) { 
  747.  
  748. case 'left': 
  749. $float =' ngg-left'; 
  750. break; 
  751.  
  752. case 'right': 
  753. $float =' ngg-right'; 
  754. break; 
  755.  
  756. case 'center': 
  757. $float =' ngg-center'; 
  758. break; 
  759.  
  760. default: 
  761. $float =''; 
  762. break; 
  763.  
  764. // clean mode if needed 
  765. $mode = ( preg_match('/(web20|watermark)/i', $mode) ) ? $mode : ''; 
  766.  
  767. //let's initiate the url 
  768. $picture->thumbnailURL = false; 
  769.  
  770. // check fo cached picture 
  771. if ( $post->post_status == 'publish' ) 
  772. $picture->thumbnailURL = $picture->cached_singlepic_file($width, $height, $mode ); 
  773.  
  774. // if we didn't use a cached image then we take the on-the-fly mode 
  775. if (!$picture->thumbnailURL) 
  776. $picture->thumbnailURL = trailingslashit( home_url() ) . 'index.php?callback=image&pid=' . $imageID . '&width=' . $width . '&height=' . $height . '&mode=' . $mode; 
  777.  
  778. // add more variables for render output 
  779. $picture->imageURL = ( empty($link) ) ? $picture->imageURL : $link; 
  780. $picture->href_link = $picture->get_href_link(); 
  781. $picture->alttext = html_entity_decode( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) ); 
  782. $picture->linktitle = htmlspecialchars( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  783. $picture->description = html_entity_decode( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  784. $picture->classname = 'ngg-singlepic'. $float; 
  785. $picture->thumbcode = $picture->get_thumbcode( 'singlepic' . $imageID); 
  786. $picture->height = (int) $height; 
  787. $picture->width = (int) $width; 
  788. $picture->caption = nggGallery::i18n($caption); 
  789.  
  790. // filter to add custom content for the output 
  791. $picture = apply_filters('ngg_image_object', $picture, $imageID); 
  792.  
  793. // let's get the meta data 
  794. $meta = new nggMeta($imageID); 
  795. $meta->sanitize(); 
  796. $exif = $meta->get_EXIF(); 
  797. $iptc = $meta->get_IPTC(); 
  798. $xmp = $meta->get_XMP(); 
  799. $db = $meta->get_saved_meta(); 
  800.  
  801. //if we get no exif information we try the database 
  802. $exif = ($exif == false) ? $db : $exif; 
  803.  
  804. // look for singlepic-$template.php or pure singlepic.php 
  805. $filename = ( empty($template) ) ? 'singlepic' : 'singlepic-' . $template; 
  806.  
  807. // create the output 
  808. $out = nggGallery::capture ( $filename, array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db) ); 
  809.  
  810. $out = apply_filters('ngg_show_singlepic_content', $out, $picture ); 
  811.  
  812. return $out; 
  813. /** 
  814. * nggShowGalleryTags() - create a gallery based on the tags 
  815. * 
  816. * @access public 
  817. * @param string $taglist list of tags as csv 
  818. * @return the content 
  819. */ 
  820. function nggShowGalleryTags($taglist, $template = '', $sorting = 'ASC') { 
  821.  
  822. // $_GET from wp_query 
  823. $pid = get_query_var('pid'); 
  824. $pageid = get_query_var('pageid'); 
  825.  
  826. // get now the related images 
  827. $picturelist = nggTags::find_images_for_tags($taglist , $sorting); 
  828.  
  829. // look for ImageBrowser if we have a $_GET('pid') 
  830. if ( $pageid == get_the_ID() || !is_home() ) 
  831. if (!empty( $pid )) { 
  832. $out = nggCreateImageBrowser( $picturelist, $template ); 
  833. return $out; 
  834.  
  835. // go on if not empty 
  836. if ( empty($picturelist) ) 
  837. return; 
  838.  
  839. // show gallery 
  840. if ( is_array($picturelist) ) 
  841. $out = nggCreateGallery($picturelist, false, $template); 
  842.  
  843. $out = apply_filters('ngg_show_gallery_tags_content', $out, $taglist); 
  844. return $out; 
  845.  
  846.  
  847. /** 
  848. * nggShowRelatedGallery() - create a gallery based on the tags 
  849. * 
  850. * @access public 
  851. * @param string $taglist list of tags as csv 
  852. * @param integer $maxImages (optional) limit the number of images to show. 0=no limit 
  853. * @return the content 
  854. */ 
  855. function nggShowRelatedGallery($taglist, $maxImages = 0) { 
  856.  
  857. $ngg_options = nggGallery::get_option('ngg_options'); 
  858.  
  859. // get now the related images 
  860. $picturelist = nggTags::find_images_for_tags($taglist, 'RAND'); 
  861.  
  862. // go on if not empty 
  863. if ( empty($picturelist) ) 
  864. return; 
  865.  
  866. // cut the list to maxImages 
  867. if ( $maxImages > 0 ) 
  868. array_splice($picturelist, $maxImages); 
  869.  
  870. // *** build the gallery output 
  871. $out = '<div class="ngg-related-gallery">'; 
  872. foreach ($picturelist as $picture) { 
  873.  
  874. // get the effect code 
  875. $thumbcode = $picture->get_thumbcode( __('Related images for', 'nggallery') . ' ' . get_the_title()); 
  876.  
  877. $out .= '<a href="' . $picture->imageURL . '" title="' . stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) . '" ' . $thumbcode . ' >'; 
  878. $out .= '<img title="' . stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) . '" alt="' . stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) . '" src="' . $picture->thumbURL . '" />'; 
  879. $out .= '</a>' . "\n"; 
  880. $out .= '</div>' . "\n"; 
  881.  
  882. $out = apply_filters('ngg_show_related_gallery_content', $out, $taglist); 
  883.  
  884. return $out; 
  885.  
  886. /** 
  887. * nggShowAlbumTags() - create a gallery based on the tags 
  888. * 20140119: Added template and sort 
  889. * @access public 
  890. * @param string $taglist list of tags as csv 
  891. * @return the content 
  892. */ 
  893. function nggShowAlbumTags($taglist, $template='', $sorting = 'ASC') { 
  894.  
  895. global $wpdb, $nggRewrite; 
  896.  
  897. // $_GET from wp_query 
  898. $tag = get_query_var('gallerytag'); 
  899. $pageid = get_query_var('pageid'); 
  900.  
  901. // look for gallerytag variable 
  902. if ( $pageid == get_the_ID() || !is_home() ) { 
  903. if (!empty( $tag )) { 
  904.  
  905. // avoid this evil code $sql = 'SELECT name FROM wp_ngg_tags WHERE slug = \'slug\' union select concat(0x7c, user_login, 0x7c, user_pass, 0x7c) from wp_users WHERE 1 = 1'; 
  906. $slug = esc_attr( $tag ); 
  907. $tagname = $wpdb->get_var( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE slug = %s", $slug ) ); 
  908. $out = '<div id="albumnav"><span><a href="' . get_permalink() . '" title="' . __('Overview', 'nggallery') .' ">'.__('Overview', 'nggallery').'</a> | '.$tagname.'</span></div>'; 
  909. $out .= nggShowGalleryTags($slug, $template, $sorting); 
  910. return $out; 
  911.  
  912.  
  913. // get now the related images 
  914. $picturelist = nggTags::get_album_images($taglist); 
  915.  
  916. // go on if not empty 
  917. if ( empty($picturelist) ) 
  918. return; 
  919.  
  920. // re-structure the object that we can use the standard template 
  921. foreach ($picturelist as $key => $picture) { 
  922. $picturelist[$key]->previewpic = $picture->pid; 
  923. $picturelist[$key]->previewname = $picture->filename; 
  924. $picturelist[$key]->previewurl = site_url() . '/' . $picture->path . '/thumbs/thumbs_' . $picture->filename; 
  925. $picturelist[$key]->counter = $picture->count; 
  926. $picturelist[$key]->title = $picture->name; 
  927. $picturelist[$key]->pagelink = $nggRewrite->get_permalink( array('gallerytag'=>$picture->slug) ); 
  928.  
  929. //TODO: Add pagination later 
  930. $navigation = '<div class="ngg-clear"></div>'; 
  931.  
  932. // create the output 
  933. $out = nggGallery::capture ('album-compact', array ('album' => 0, 'galleries' => $picturelist, 'pagination' => $navigation) ); 
  934.  
  935. $out = apply_filters('ngg_show_album_tags_content', $out, $taglist); 
  936.  
  937. return $out; 
  938.  
  939. /** 
  940. * nggShowRelatedImages() - return related images based on category or tags 
  941. * 
  942. * @access public 
  943. * @param string $type could be 'tags' or 'category' 
  944. * @param integer $maxImages of images 
  945. * @return related gallery output or empty string if not tags/categories 
  946. * 20150309: fix: error when no tags in site. 
  947. * Few simplifications 
  948. */ 
  949. function nggShowRelatedImages($type = '', $maxImages = 0) { 
  950. $ngg_options = nggGallery::get_option('ngg_options'); 
  951.  
  952. if ($type == '') { 
  953. $type = $ngg_options['appendType']; 
  954. $maxImages = $ngg_options['maxImages']; 
  955.  
  956. $sluglist = array(); 
  957.  
  958. switch ($type) { 
  959. case 'tags': 
  960. $taglist = get_the_tags(); //Return array of tag objects, false on failure or empty 
  961. //This is a tag list for posts non Nextcellent tag lists. 
  962. if (!$taglist) return ""; 
  963. foreach ($taglist as $tag) { 
  964. $sluglist[] = $tag->slug; 
  965. break; 
  966.  
  967. case 'category': 
  968. $catlist = get_the_category(); //return array (empty if no categories) 
  969. if (empty ($catlist)) return ""; 
  970. foreach ($catlist as $cat) { 
  971. $sluglist[] = $cat->category_nicename; 
  972. break; 
  973. $sluglist = implode(', ', $sluglist); 
  974. $out = nggShowRelatedGallery($sluglist, $maxImages); 
  975. return $out; 
  976.  
  977. /** 
  978. * Template function for theme authors 
  979. * 
  980. * @access public 
  981. * @param string (optional) $type could be 'tags' or 'category' 
  982. * @param integer (optional) $maxNumbers of images 
  983. * @return void 
  984. */ 
  985. function the_related_images($type = 'tags', $maxNumbers = 7) { 
  986. echo nggShowRelatedImages($type, $maxNumbers); 
  987.  
  988. /** 
  989. * nggShowRandomRecent($type, $maxImages, $template, $galleryId) - return recent or random images 
  990. * 
  991. * @access public 
  992. * @param string $type 'id' (for latest addition to DB), 'date' (for image with the latest date), 'sort' (for image sorted by user order) or 'random' 
  993. * @param integer $maxImages of images 
  994. * @param string $template (optional) name for a template file, look for gallery-$template 
  995. * @param int $galleryId Limit to a specific gallery 
  996. * @return the content 
  997. */ 
  998. function nggShowRandomRecent($type, $maxImages, $template = '', $galleryId = 0) { 
  999.  
  1000. // $_GET from wp_query 
  1001. $pid = get_query_var('pid'); 
  1002. $pageid = get_query_var('pageid'); 
  1003.  
  1004. // get now the recent or random images 
  1005. switch ($type) { 
  1006. case 'random': 
  1007. $picturelist = nggdb::get_random_images($maxImages, $galleryId); 
  1008. break; 
  1009. case 'id': 
  1010. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id'); 
  1011. break; 
  1012. case 'date': 
  1013. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'date'); 
  1014. break; 
  1015. case 'sort': 
  1016. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'sort'); 
  1017. break; 
  1018. default: 
  1019. // default is by pid 
  1020. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id'); 
  1021.  
  1022. // look for ImageBrowser if we have a $_GET('pid') 
  1023. if ( $pageid == get_the_ID() || !is_home() ) 
  1024. if (!empty( $pid )) { 
  1025. $out = nggCreateImageBrowser( $picturelist ); 
  1026. return $out; 
  1027.  
  1028. // go on if not empty 
  1029. if ( empty($picturelist) ) 
  1030. return; 
  1031.  
  1032. // show gallery 
  1033. if ( is_array($picturelist) ) 
  1034. $out = nggCreateGallery($picturelist, false, $template); 
  1035.  
  1036. $out = apply_filters('ngg_show_images_content', $out, $picturelist); 
  1037.  
  1038. return $out; 
  1039.  
  1040. /** 
  1041. * nggTagCloud() - return a tag cloud based on the wp core tag cloud system 
  1042. * 
  1043. * @param array $args 
  1044. * @param string $template (optional) name for a template file, look for gallery-$template 
  1045. * @return the content 
  1046. */ 
  1047. function nggTagCloud($args ='', $template = '') { 
  1048. global $nggRewrite; 
  1049.  
  1050. // $_GET from wp_query 
  1051. $tag = get_query_var('gallerytag'); 
  1052. $pageid = get_query_var('pageid'); 
  1053.  
  1054. // look for gallerytag variable 
  1055. if ( $pageid == get_the_ID() || !is_home() ) { 
  1056. if (!empty( $tag )) { 
  1057.  
  1058. $slug = esc_attr( $tag ); 
  1059. $out = nggShowGalleryTags( $slug ); 
  1060. return $out; 
  1061.  
  1062. $defaults = array( 
  1063. 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,  
  1064. 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',  
  1065. 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'ngg_tag' 
  1066. ); 
  1067. $args = wp_parse_args( $args, $defaults ); 
  1068.  
  1069. $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags 
  1070.  
  1071. foreach ($tags as $key => $tag ) { 
  1072.  
  1073. $tags[ $key ]->link = $nggRewrite->get_permalink(array ('gallerytag' => $tag->slug)); 
  1074. $tags[ $key ]->id = $tag->term_id; 
  1075.  
  1076. $out = '<div class="ngg-tagcloud">' . wp_generate_tag_cloud( $tags, $args ) . '</div>'; 
  1077.  
  1078. return $out; 
  1079. ?> 
.