PageRenderTime 246ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 1ms

/htdocs/wp-content/plugins/nextgen-gallery/nggfunctions.php

https://bitbucket.org/dkrzos/phc
PHP | 1141 lines | 622 code | 230 blank | 289 comment | 144 complexity | 9b3d77b77b1e8e196835fdd7fb2ef442 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
  3. /**
  4. * Return a script for the Imagerotator flash slideshow. Can be used in any template with <?php echo nggShowSlideshow($galleryID, $width, $height) ?>
  5. * Require the script swfobject.js in the header or footer
  6. *
  7. * @access public
  8. * @param integer $galleryID ID of the gallery
  9. * @param integer $irWidth Width of the flash container
  10. * @param integer $irHeight Height of the flash container
  11. * @return the content
  12. */
  13. function nggShowSlideshow($galleryID, $width, $height) {
  14. require_once (dirname (__FILE__).'/lib/swfobject.php');
  15. $ngg_options = nggGallery::get_option('ngg_options');
  16. // remove media file from RSS feed
  17. if ( is_feed() ) {
  18. $out = '[' . nggGallery::i18n($ngg_options['galTextSlide']) . ']';
  19. return $out;
  20. }
  21. //Redirect all calls to the JavaScript slideshow if wanted
  22. if ( $ngg_options['enableIR'] !== '1' || nggGallery::detect_mobile_phone() === true )
  23. return nggShow_JS_Slideshow($galleryID, $width, $height);
  24. // If the Imagerotator didn't exist, skip the output
  25. if ( NGGALLERY_IREXIST == false )
  26. return;
  27. if (empty($width) ) $width = (int) $ngg_options['irWidth'];
  28. if (empty($height)) $height = (int) $ngg_options['irHeight'];
  29. // Doesn't work fine with zero
  30. $ngg_options['irRotatetime'] = ($ngg_options['irRotatetime'] == 0) ? 5 : $ngg_options['irRotatetime'];
  31. // init the flash output
  32. $swfobject = new swfobject( $ngg_options['irURL'] , 'so' . $galleryID, $width, $height, '7.0.0', 'false');
  33. $swfobject->message = '<p>'. __('The <a href="http://www.macromedia.com/go/getflashplayer">Flash Player</a> and <a href="http://www.mozilla.com/firefox/">a browser with Javascript support</a> are needed.', 'nggallery').'</p>';
  34. $swfobject->add_params('wmode', 'opaque');
  35. $swfobject->add_params('allowfullscreen', 'true');
  36. $swfobject->add_params('bgcolor', $ngg_options['irScreencolor'], 'FFFFFF', 'string', '#');
  37. $swfobject->add_attributes('styleclass', 'slideshow');
  38. $swfobject->add_attributes('name', 'so' . $galleryID);
  39. // adding the flash parameter
  40. $swfobject->add_flashvars( 'file', urlencode ( trailingslashit ( home_url() ) . 'index.php?callback=imagerotator&gid=' . $galleryID ) );
  41. $swfobject->add_flashvars( 'shuffle', $ngg_options['irShuffle'], 'true', 'bool');
  42. // option has oposite meaning : true should switch to next image
  43. $swfobject->add_flashvars( 'linkfromdisplay', !$ngg_options['irLinkfromdisplay'], 'false', 'bool');
  44. $swfobject->add_flashvars( 'shownavigation', $ngg_options['irShownavigation'], 'true', 'bool');
  45. $swfobject->add_flashvars( 'showicons', $ngg_options['irShowicons'], 'true', 'bool');
  46. $swfobject->add_flashvars( 'kenburns', $ngg_options['irKenburns'], 'false', 'bool');
  47. $swfobject->add_flashvars( 'overstretch', $ngg_options['irOverstretch'], 'false', 'string');
  48. $swfobject->add_flashvars( 'rotatetime', $ngg_options['irRotatetime'], 5, 'int');
  49. $swfobject->add_flashvars( 'transition', $ngg_options['irTransition'], 'random', 'string');
  50. $swfobject->add_flashvars( 'backcolor', $ngg_options['irBackcolor'], 'FFFFFF', 'string', '0x');
  51. $swfobject->add_flashvars( 'frontcolor', $ngg_options['irFrontcolor'], '000000', 'string', '0x');
  52. $swfobject->add_flashvars( 'lightcolor', $ngg_options['irLightcolor'], '000000', 'string', '0x');
  53. $swfobject->add_flashvars( 'screencolor', $ngg_options['irScreencolor'], '000000', 'string', '0x');
  54. if ($ngg_options['irWatermark'])
  55. $swfobject->add_flashvars( 'logo', $ngg_options['wmPath'], '', 'string');
  56. $swfobject->add_flashvars( 'audio', $ngg_options['irAudio'], '', 'string');
  57. $swfobject->add_flashvars( 'width', $width, '260');
  58. $swfobject->add_flashvars( 'height', $height, '320');
  59. // create the output
  60. $out = '<div class="slideshow">' . $swfobject->output() . '</div>';
  61. // add now the script code
  62. $out .= "\n".'<script type="text/javascript" defer="defer">';
  63. // load script via jQuery afterwards
  64. // $out .= "\n".'jQuery.getScript( "' . esc_js( includes_url('js/swfobject.js') ) . '", function() {} );';
  65. if ($ngg_options['irXHTMLvalid']) $out .= "\n".'<!--';
  66. if ($ngg_options['irXHTMLvalid']) $out .= "\n".'//<![CDATA[';
  67. $out .= $swfobject->javascript();
  68. if ($ngg_options['irXHTMLvalid']) $out .= "\n".'//]]>';
  69. if ($ngg_options['irXHTMLvalid']) $out .= "\n".'-->';
  70. $out .= "\n".'</script>';
  71. $out = apply_filters('ngg_show_slideshow_content', $out, $galleryID, $width, $height);
  72. return $out;
  73. }
  74. /**
  75. * Return a script for the jQuery based slideshow. Can be used in any template with <?php echo nggShow_JS_Slideshow($galleryID, $width, $height) ?>
  76. * Require the script jquery.cycle.all.js
  77. *
  78. * @since 1.6.0
  79. * @access public
  80. * @param integer $galleryID ID of the gallery
  81. * @param integer $width Width of the slideshow container
  82. * @param integer $height Height of the slideshow container
  83. * @param string $class Classname of the div container
  84. * @return the content
  85. */
  86. function nggShow_JS_Slideshow($galleryID, $width, $height, $class = 'ngg-slideshow') {
  87. global $slideCounter;
  88. $ngg_options = nggGallery::get_option('ngg_options');
  89. // we need to know the current page id
  90. $current_page = (get_the_ID() == false) ? rand(5, 15) : get_the_ID();
  91. // look for a other slideshow instance
  92. if ( !isset($slideCounter) ) $slideCounter = 1;
  93. // create unique anchor
  94. $anchor = 'ngg-slideshow-' . $galleryID . '-' . $current_page . '-' . $slideCounter++;
  95. if (empty($width) ) $width = (int) $ngg_options['irWidth'];
  96. if (empty($height)) $height = (int) $ngg_options['irHeight'];
  97. //filter to resize images for mobile browser
  98. list($width, $height) = apply_filters('ngg_slideshow_size', array( $width, $height ) );
  99. $width = (int) $width;
  100. $height = (int) $height;
  101. $out = '<div id="' . $anchor . '" class="' . $class . '" style="height:' . $height . 'px;width:' . $width . 'px;">';
  102. $out .= "\n". '<div id="' . $anchor . '-loader" class="ngg-slideshow-loader" style="height:' . $height . 'px;width:' . $width . 'px;">';
  103. $out .= "\n". '<img src="'. NGGALLERY_URLPATH . 'images/loader.gif" alt="" />';
  104. $out .= "\n". '</div>';
  105. $out .= '</div>'."\n";
  106. $out .= "\n".'<script type="text/javascript" defer="defer">';
  107. $out .= "\n" . 'jQuery(document).ready(function(){ ' . "\n" . 'jQuery("#' . $anchor . '").nggSlideshow( {' .
  108. 'id: ' . $galleryID . ',' .
  109. 'fx:"' . $ngg_options['slideFx'] . '",' .
  110. 'width:' . $width . ',' .
  111. 'height:' . $height . ',' .
  112. 'domain: "' . trailingslashit ( home_url() ) . '",' .
  113. 'timeout:' . $ngg_options['irRotatetime'] * 1000 .
  114. '});' . "\n" . '});';
  115. $out .= "\n".'</script>';
  116. return $out;
  117. }
  118. /**
  119. * nggShowGallery() - return a gallery
  120. *
  121. * @access public
  122. * @param int | string ID or slug from a gallery
  123. * @param string $template (optional) name for a template file, look for gallery-$template
  124. * @param int $images (optional) number of images per page
  125. * @return the content
  126. */
  127. function nggShowGallery( $galleryID, $template = '', $images = false ) {
  128. global $nggRewrite;
  129. $ngg_options = nggGallery::get_option('ngg_options');
  130. //Set sort order value, if not used (upgrade issue)
  131. $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
  132. $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';
  133. // get gallery values
  134. //TODO: Use pagination limits here to reduce memory needs
  135. $picturelist = nggdb::get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);
  136. if ( !$picturelist )
  137. return __('[Gallery not found]','nggallery');
  138. // If we have we slug instead the id, we should extract the ID from the first image
  139. if ( !is_numeric($galleryID) ) {
  140. $first_image = current($picturelist);
  141. $galleryID = intval($first_image->gid);
  142. }
  143. // $_GET from wp_query
  144. $show = get_query_var('show');
  145. $pid = get_query_var('pid');
  146. $pageid = get_query_var('pageid');
  147. // set $show if slideshow first
  148. if ( empty( $show ) AND ($ngg_options['galShowOrder'] == 'slide')) {
  149. if ( is_home() )
  150. $pageid = get_the_ID();
  151. $show = 'slide';
  152. }
  153. // filter to call up the imagebrowser instead of the gallery
  154. // use in your theme : add_action( 'ngg_show_imagebrowser_first', create_function('', 'return true;') );
  155. if ( apply_filters('ngg_show_imagebrowser_first', false, $galleryID ) && $show != 'thumbnails' ) {
  156. $out = nggShowImageBrowser( $galleryID, $template );
  157. return $out;
  158. }
  159. // go on only on this page
  160. if ( !is_home() || $pageid == get_the_ID() ) {
  161. // 1st look for ImageBrowser link
  162. if ( !empty($pid) && $ngg_options['galImgBrowser'] && ($template != 'carousel') ) {
  163. $out = nggShowImageBrowser( $galleryID, $template );
  164. return $out;
  165. }
  166. // 2nd look for slideshow
  167. if ( $show == 'slide' ) {
  168. $args['show'] = "gallery";
  169. $out = '<div class="ngg-galleryoverview">';
  170. $out .= '<div class="slideshowlink"><a class="slideshowlink" href="' . $nggRewrite->get_permalink($args) . '">'.nggGallery::i18n($ngg_options['galTextGallery']).'</a></div>';
  171. $out .= nggShowSlideshow($galleryID, $ngg_options['irWidth'], $ngg_options['irHeight']);
  172. $out .= '</div>'."\n";
  173. $out .= '<div class="ngg-clear"></div>'."\n";
  174. return $out;
  175. }
  176. }
  177. // get all picture with this galleryid
  178. if ( is_array($picturelist) )
  179. $out = nggCreateGallery($picturelist, $galleryID, $template, $images);
  180. $out = apply_filters('ngg_show_gallery_content', $out, intval($galleryID));
  181. return $out;
  182. }
  183. /**
  184. * Build a gallery output
  185. *
  186. * @access internal
  187. * @param array $picturelist
  188. * @param bool $galleryID, if you supply a gallery ID, you can add a slideshow link
  189. * @param string $template (optional) name for a template file, look for gallery-$template
  190. * @param int $images (optional) number of images per page
  191. * @return the content
  192. */
  193. function nggCreateGallery($picturelist, $galleryID = false, $template = '', $images = false) {
  194. global $nggRewrite;
  195. require_once (dirname (__FILE__) . '/lib/media-rss.php');
  196. $ngg_options = nggGallery::get_option('ngg_options');
  197. //the shortcode parameter will override global settings, TODO: rewrite this to a class
  198. $ngg_options['galImages'] = ( $images === false ) ? $ngg_options['galImages'] : (int) $images;
  199. $current_pid = false;
  200. // $_GET from wp_query
  201. $nggpage = get_query_var('nggpage');
  202. $pageid = get_query_var('pageid');
  203. $pid = get_query_var('pid');
  204. // in case of permalinks the pid is a slug, we need the id
  205. if( !is_numeric($pid) && !empty($pid) ) {
  206. $picture = nggdb::find_image($pid);
  207. $pid = $picture->pid;
  208. }
  209. // we need to know the current page id
  210. $current_page = (get_the_ID() == false) ? 0 : get_the_ID();
  211. if ( !is_array($picturelist) )
  212. $picturelist = array($picturelist);
  213. // Populate galleries values from the first image
  214. $first_image = current($picturelist);
  215. $gallery = new stdclass;
  216. $gallery->ID = (int) $galleryID;
  217. $gallery->show_slideshow = false;
  218. $gallery->show_piclens = false;
  219. $gallery->name = stripslashes ( $first_image->name );
  220. $gallery->title = stripslashes( $first_image->title );
  221. $gallery->description = html_entity_decode(stripslashes( $first_image->galdesc));
  222. $gallery->pageid = $first_image->pageid;
  223. $gallery->anchor = 'ngg-gallery-' . $galleryID . '-' . $current_page;
  224. reset($picturelist);
  225. $maxElement = $ngg_options['galImages'];
  226. $thumbwidth = $ngg_options['thumbwidth'];
  227. $thumbheight = $ngg_options['thumbheight'];
  228. // fixed width if needed
  229. $gallery->columns = intval($ngg_options['galColumns']);
  230. $gallery->imagewidth = ($gallery->columns > 0) ? 'style="width:' . floor(100/$gallery->columns) . '%;"' : '';
  231. // obsolete in V1.4.0, but kept for compat reason
  232. // pre set thumbnail size, from the option, later we look for meta data.
  233. $thumbsize = ($ngg_options['thumbfix']) ? $thumbsize = 'width="' . $thumbwidth . '" height="'.$thumbheight . '"' : '';
  234. // show slideshow link
  235. if ($galleryID) {
  236. if ($ngg_options['galShowSlide']) {
  237. $gallery->show_slideshow = true;
  238. $gallery->slideshow_link = $nggRewrite->get_permalink(array ( 'show' => 'slide') );
  239. $gallery->slideshow_link_text = nggGallery::i18n($ngg_options['galTextSlide']);
  240. }
  241. if ($ngg_options['usePicLens']) {
  242. $gallery->show_piclens = true;
  243. $gallery->piclens_link = "javascript:PicLensLite.start({feedUrl:'" . htmlspecialchars( nggMediaRss::get_gallery_mrss_url($gallery->ID) ) . "'});";
  244. }
  245. }
  246. // check for page navigation
  247. if ($maxElement > 0) {
  248. if ( !is_home() || $pageid == $current_page )
  249. $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
  250. else
  251. $page = 1;
  252. $start = $offset = ( $page - 1 ) * $maxElement;
  253. $total = count($picturelist);
  254. //we can work with display:hidden for some javascript effects
  255. if (!$ngg_options['galHiddenImg']){
  256. // remove the element if we didn't start at the beginning
  257. if ($start > 0 )
  258. array_splice($picturelist, 0, $start);
  259. // return the list of images we need
  260. array_splice($picturelist, $maxElement);
  261. }
  262. $nggNav = new nggNavigation;
  263. $navigation = $nggNav->create_navigation($page, $total, $maxElement);
  264. } else {
  265. $navigation = '<div class="ngg-clear"></div>';
  266. }
  267. //we cannot use the key as index, cause it's filled with the pid
  268. $index = 0;
  269. foreach ($picturelist as $key => $picture) {
  270. //needed for hidden images (THX to Sweigold for the main idea at : http://wordpress.org/support/topic/228743/ )
  271. $picturelist[$key]->hidden = false;
  272. $picturelist[$key]->style = $gallery->imagewidth;
  273. if ($maxElement > 0 && $ngg_options['galHiddenImg']) {
  274. if ( ($index < $start) || ($index > ($start + $maxElement -1)) ){
  275. $picturelist[$key]->hidden = true;
  276. $picturelist[$key]->style = ($gallery->columns > 0) ? 'style="width:' . floor(100/$gallery->columns) . '%;display: none;"' : 'style="display: none;"';
  277. }
  278. $index++;
  279. }
  280. // get the effect code
  281. if ($galleryID)
  282. $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode('set_' . $galleryID);
  283. else
  284. $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode(get_the_title());
  285. // create link for imagebrowser and other effects
  286. $args ['nggpage'] = empty($nggpage) || ($template != 'carousel') ? false : $nggpage; // only needed for carousel mode
  287. $args ['pid'] = ($ngg_options['usePermalinks']) ? $picture->image_slug : $picture->pid;
  288. $picturelist[$key]->pidlink = $nggRewrite->get_permalink( $args );
  289. // generate the thumbnail size if the meta data available
  290. if ( isset($picturelist[$key]->meta_data['thumbnail']) && is_array ($size = $picturelist[$key]->meta_data['thumbnail']) )
  291. $thumbsize = 'width="' . $size['width'] . '" height="' . $size['height'] . '"';
  292. // choose link between imagebrowser or effect
  293. $link = ($ngg_options['galImgBrowser']) ? $picturelist[$key]->pidlink : $picture->imageURL;
  294. // bad solution : for now we need the url always for the carousel, should be reworked in the future
  295. $picturelist[$key]->url = $picture->imageURL;
  296. // add a filter for the link
  297. $picturelist[$key]->imageURL = apply_filters('ngg_create_gallery_link', $link, $picture);
  298. $picturelist[$key]->thumbnailURL = $picture->thumbURL;
  299. $picturelist[$key]->size = $thumbsize;
  300. $picturelist[$key]->thumbcode = $thumbcode;
  301. $picturelist[$key]->caption = ( empty($picture->description) ) ? '&nbsp;' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) );
  302. $picturelist[$key]->description = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) );
  303. $picturelist[$key]->alttext = ( empty($picture->alttext) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) );
  304. // filter to add custom content for the output
  305. $picturelist[$key] = apply_filters('ngg_image_object', $picturelist[$key], $picture->pid);
  306. //check if $pid is in the array
  307. if ($picture->pid == $pid)
  308. $current_pid = $picturelist[$key];
  309. }
  310. reset($picturelist);
  311. //for paged galleries, take the first image in the array if it's not in the list
  312. $current_pid = ( empty($current_pid) ) ? current( $picturelist ) : $current_pid;
  313. // look for gallery-$template.php or pure gallery.php
  314. $filename = ( empty($template) ) ? 'gallery' : 'gallery-' . $template;
  315. //filter functions for custom addons
  316. $gallery = apply_filters( 'ngg_gallery_object', $gallery, $galleryID );
  317. $picturelist = apply_filters( 'ngg_picturelist_object', $picturelist, $galleryID );
  318. //additional navigation links
  319. $next = ( empty($nggNav->next) ) ? false : $nggNav->next;
  320. $prev = ( empty($nggNav->prev) ) ? false : $nggNav->prev;
  321. // create the output
  322. $out = nggGallery::capture ( $filename, array ('gallery' => $gallery, 'images' => $picturelist, 'pagination' => $navigation, 'current' => $current_pid, 'next' => $next, 'prev' => $prev) );
  323. // apply a filter after the output
  324. $out = apply_filters('ngg_gallery_output', $out, $picturelist);
  325. return $out;
  326. }
  327. /**
  328. * nggShowAlbum() - return a album based on the id
  329. *
  330. * @access public
  331. * @param int | string $albumID
  332. * @param string (optional) $template
  333. * @param string (optional) $gallery_template
  334. * @return the content
  335. */
  336. function nggShowAlbum($albumID, $template = 'extend', $gallery_template = '') {
  337. // $_GET from wp_query
  338. $gallery = get_query_var('gallery');
  339. $album = get_query_var('album');
  340. // in the case somebody uses the '0', it should be 'all' to show all galleries
  341. $albumID = ($albumID == 0) ? 'all' : $albumID;
  342. // first look for gallery variable
  343. if (!empty( $gallery )) {
  344. // subalbum support only one instance, you can't use more of them in one post
  345. //TODO: causes problems with SFC plugin, due to a second filter callback
  346. global $wp_current_filter;
  347. if ( isset($GLOBALS['subalbum']) || isset($GLOBALS['nggShowGallery']))
  348. return;
  349. // if gallery is submit , then show the gallery instead
  350. $out = nggShowGallery( $gallery, $gallery_template );
  351. $GLOBALS['nggShowGallery'] = true;
  352. return $out;
  353. }
  354. if ( (empty( $gallery )) && (isset($GLOBALS['subalbum'])) )
  355. return;
  356. //redirect to subalbum only one time
  357. if (!empty( $album )) {
  358. $GLOBALS['subalbum'] = true;
  359. $albumID = $album;
  360. }
  361. // lookup in the database
  362. $album = nggdb::find_album( $albumID );
  363. // still no success ? , die !
  364. if( !$album )
  365. return __('[Album not found]','nggallery');
  366. // ensure to set the slug for "all" albums
  367. $album->slug = ($albumID == 'all') ? $album->id : $album->slug;
  368. if ( is_array($album->gallery_ids) )
  369. $out = nggCreateAlbum( $album->gallery_ids, $template, $album );
  370. $out = apply_filters( 'ngg_show_album_content', $out, $album->id );
  371. return $out;
  372. }
  373. /**
  374. * create a gallery overview output
  375. *
  376. * @access internal
  377. * @param array $galleriesID
  378. * @param string (optional) $template name for a template file, look for album-$template
  379. * @param object (optional) $album result from the db
  380. * @return the content
  381. */
  382. function nggCreateAlbum( $galleriesID, $template = 'extend', $album = 0) {
  383. global $wpdb, $nggRewrite, $nggdb, $ngg;
  384. // $_GET from wp_query
  385. $nggpage = get_query_var('nggpage');
  386. // Get options
  387. $ngg_options = $ngg->options;
  388. //this option can currently only set via the custom fields
  389. $maxElement = (int) $ngg_options['galPagedGalleries'];
  390. $sortorder = $galleriesID;
  391. $galleries = array();
  392. // get the galleries information
  393. foreach ($galleriesID as $i => $value)
  394. $galleriesID[$i] = addslashes($value);
  395. $unsort_galleries = $wpdb->get_results('SELECT * FROM '.$wpdb->nggallery.' WHERE gid IN (\''.implode('\',\'', $galleriesID).'\')', OBJECT_K);
  396. //TODO: Check this, problem exist when previewpic = 0
  397. //$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);
  398. // get the counter values
  399. $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);
  400. if ( is_array($picturesCounter) ) {
  401. foreach ($picturesCounter as $key => $value)
  402. $unsort_galleries[$key]->counter = $value->counter;
  403. }
  404. // get the id's of the preview images
  405. $imagesID = array();
  406. if ( is_array($unsort_galleries) ) {
  407. foreach ($unsort_galleries as $gallery_row)
  408. $imagesID[] = $gallery_row->previewpic;
  409. }
  410. $albumPreview = $wpdb->get_results('SELECT pid, filename FROM '.$wpdb->nggpictures.' WHERE pid IN (\''.implode('\',\'', $imagesID).'\')', OBJECT_K);
  411. // re-order them and populate some
  412. foreach ($sortorder as $key) {
  413. // Create a gallery object
  414. if (isset($unsort_galleries[$key])) $galleries[$key] = $unsort_galleries[$key];
  415. else $galleries[$key] = new stdClass;
  416. //if we have a prefix 'a' then it's a subalbum, instead a gallery
  417. if (substr( $key, 0, 1) == 'a') {
  418. if (($subalbum = $nggdb->find_album(substr($key, 1)))) {
  419. $galleries[$key]->counter = count($subalbum->gallery_ids);
  420. if ($subalbum->previewpic > 0){
  421. $image = $nggdb->find_image( $subalbum->previewpic );
  422. $galleries[$key]->previewurl = isset($image->thumbURL) ? $image->thumbURL : '';
  423. }
  424. $galleries[$key]->previewpic = $subalbum->previewpic;
  425. $galleries[$key]->previewname = $subalbum->name;
  426. //link to the subalbum
  427. $args['album'] = ( $ngg_options['usePermalinks'] ) ? $subalbum->slug : $subalbum->id;
  428. $args['gallery'] = false;
  429. $args['nggpage'] = false;
  430. $pageid = (isset($subalbum->pageid) ? $subalbum->pageid : 0);
  431. $galleries[$key]->pagelink = ($pageid > 0) ? get_permalink($pageid) : $nggRewrite->get_permalink($args);
  432. $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n($subalbum->albumdesc) );
  433. $galleries[$key]->title = html_entity_decode ( nggGallery::i18n($subalbum->name) );
  434. }
  435. }
  436. elseif (isset($unsort_galleries[$key])) {
  437. $galleries[$key] = $unsort_galleries[$key];
  438. // No images found, set counter to 0
  439. if (!isset($galleries[$key]->counter)){
  440. $galleries[$key]->counter = 0;
  441. $galleries[$key]->previewurl = '';
  442. }
  443. // add the file name and the link
  444. if ($galleries[$key]->previewpic != 0) {
  445. $galleries[$key]->previewname = $albumPreview[$galleries[$key]->previewpic]->filename;
  446. $galleries[$key]->previewurl = site_url().'/' . $galleries[$key]->path . '/thumbs/thumbs_' . $albumPreview[$galleries[$key]->previewpic]->filename;
  447. } else {
  448. $first_image = $wpdb->get_row('SELECT * FROM '. $wpdb->nggpictures .' WHERE exclude != 1 AND galleryid = '. $key .' ORDER by pid DESC limit 0,1');
  449. if (isset($first_image)) {
  450. $galleries[$key]->previewpic = $first_image->pid;
  451. $galleries[$key]->previewname = $first_image->filename;
  452. $galleries[$key]->previewurl = site_url() . '/' . $galleries[$key]->path . '/thumbs/thumbs_' . $first_image->filename;
  453. }
  454. }
  455. // choose between variable and page link
  456. if ($ngg_options['galNoPages']) {
  457. $args['album'] = ( $ngg_options['usePermalinks'] ) ? $album->slug : $album->id;
  458. $args['gallery'] = ( $ngg_options['usePermalinks'] ) ? $galleries[$key]->slug : $key;
  459. $args['nggpage'] = false;
  460. $galleries[$key]->pagelink = $nggRewrite->get_permalink($args);
  461. } else {
  462. $galleries[$key]->pagelink = get_permalink( $galleries[$key]->pageid );
  463. }
  464. // description can contain HTML tags
  465. $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n( stripslashes($galleries[$key]->galdesc), 'gal_' . $galleries[$key]->gid . '_description') ) ;
  466. // i18n
  467. $galleries[$key]->title = html_entity_decode ( nggGallery::i18n( stripslashes($galleries[$key]->title), 'gal_' . $galleries[$key]->gid . '_title') ) ;
  468. }
  469. // apply a filter on gallery object before the output
  470. $galleries[$key] = apply_filters('ngg_album_galleryobject', $galleries[$key]);
  471. }
  472. // apply a filter on gallery object before paging starts
  473. $galleries = apply_filters('ngg_album_galleries_before_paging', $galleries, $album);
  474. // check for page navigation
  475. if ($maxElement > 0) {
  476. if ( !is_home() || $pageid == get_the_ID() ) {
  477. $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
  478. }
  479. else $page = 1;
  480. $start = $offset = ( $page - 1 ) * $maxElement;
  481. $total = count($galleries);
  482. // remove the element if we didn't start at the beginning
  483. if ($start > 0 ) array_splice($galleries, 0, $start);
  484. // return the list of images we need
  485. array_splice($galleries, $maxElement);
  486. $nggNav = new nggNavigation;
  487. $navigation = $nggNav->create_navigation($page, $total, $maxElement);
  488. } else {
  489. $navigation = '<div class="ngg-clear"></div>';
  490. }
  491. // apply a filter on $galleries before the output
  492. $galleries = apply_filters('ngg_album_galleries', $galleries);
  493. // if sombody didn't enter any template , take the extend version
  494. $filename = ( empty($template) ) ? 'album-extend' : 'album-' . $template ;
  495. // create the output
  496. $out = nggGallery::capture ( $filename, array ('album' => $album, 'galleries' => $galleries, 'pagination' => $navigation) );
  497. return $out;
  498. }
  499. /**
  500. * nggShowImageBrowser()
  501. *
  502. * @access public
  503. * @param int|string $galleryID or gallery name
  504. * @param string $template (optional) name for a template file, look for imagebrowser-$template
  505. * @return the content
  506. */
  507. function nggShowImageBrowser($galleryID, $template = '') {
  508. global $wpdb;
  509. $ngg_options = nggGallery::get_option('ngg_options');
  510. //Set sort order value, if not used (upgrade issue)
  511. $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
  512. $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';
  513. // get the pictures
  514. $picturelist = nggdb::get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);
  515. if ( is_array($picturelist) )
  516. $out = nggCreateImageBrowser($picturelist, $template);
  517. else
  518. $out = __('[Gallery not found]','nggallery');
  519. $out = apply_filters('ngg_show_imagebrowser_content', $out, $galleryID);
  520. return $out;
  521. }
  522. /**
  523. * nggCreateImageBrowser()
  524. *
  525. * @access internal
  526. * @param array $picturelist
  527. * @param string $template (optional) name for a template file, look for imagebrowser-$template
  528. * @return the content
  529. */
  530. function nggCreateImageBrowser($picturelist, $template = '') {
  531. global $nggRewrite, $ngg;
  532. require_once( dirname (__FILE__) . '/lib/meta.php' );
  533. // $_GET from wp_query
  534. $pid = get_query_var('pid');
  535. // we need to know the current page id
  536. $current_page = (get_the_ID() == false) ? 0 : get_the_ID();
  537. // create a array with id's for better walk inside
  538. foreach ($picturelist as $picture)
  539. $picarray[] = $picture->pid;
  540. $total = count($picarray);
  541. if ( !empty( $pid )) {
  542. if ( is_numeric($pid) )
  543. $act_pid = intval($pid);
  544. else {
  545. // in the case it's a slug we need to search for the pid
  546. foreach ($picturelist as $key => $picture) {
  547. if ($picture->image_slug == $pid) {
  548. $act_pid = $key;
  549. break;
  550. }
  551. }
  552. }
  553. } else {
  554. reset($picarray);
  555. $act_pid = current($picarray);
  556. }
  557. // get ids for back/next
  558. $key = array_search($act_pid, $picarray);
  559. if (!$key) {
  560. $act_pid = reset($picarray);
  561. $key = key($picarray);
  562. }
  563. $back_pid = ( $key >= 1 ) ? $picarray[$key-1] : end($picarray) ;
  564. $next_pid = ( $key < ($total-1) ) ? $picarray[$key+1] : reset($picarray) ;
  565. // get the picture data
  566. $picture = nggdb::find_image($act_pid);
  567. // if we didn't get some data, exit now
  568. if ($picture == null)
  569. return;
  570. // add more variables for render output
  571. $picture->href_link = $picture->get_href_link();
  572. $args ['pid'] = ($ngg->options['usePermalinks']) ? $picturelist[$back_pid]->image_slug : $back_pid;
  573. $picture->previous_image_link = $nggRewrite->get_permalink( $args );
  574. $picture->previous_pid = $back_pid;
  575. $args ['pid'] = ($ngg->options['usePermalinks']) ? $picturelist[$next_pid]->image_slug : $next_pid;
  576. $picture->next_image_link = $nggRewrite->get_permalink( $args );
  577. $picture->next_pid = $next_pid;
  578. $picture->number = $key + 1;
  579. $picture->total = $total;
  580. $picture->linktitle = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) );
  581. $picture->alttext = ( empty($picture->alttext) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) );
  582. $picture->description = ( empty($picture->description) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) );
  583. $picture->anchor = 'ngg-imagebrowser-' . $picture->galleryid . '-' . $current_page;
  584. // filter to add custom content for the output
  585. $picture = apply_filters('ngg_image_object', $picture, $act_pid);
  586. // let's get the meta data
  587. $meta = new nggMeta($act_pid);
  588. $meta->sanitize();
  589. $exif = $meta->get_EXIF();
  590. $iptc = $meta->get_IPTC();
  591. $xmp = $meta->get_XMP();
  592. $db = $meta->get_saved_meta();
  593. //if we get no exif information we try the database
  594. $exif = ($exif == false) ? $db : $exif;
  595. // look for imagebrowser-$template.php or pure imagebrowser.php
  596. $filename = ( empty($template) ) ? 'imagebrowser' : 'imagebrowser-' . $template;
  597. // create the output
  598. $out = nggGallery::capture ( $filename , array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db) );
  599. return $out;
  600. }
  601. /**
  602. * nggSinglePicture() - show a single picture based on the id
  603. *
  604. * @access public
  605. * @param int $imageID, db-ID of the image
  606. * @param int (optional) $width, width of the image
  607. * @param int (optional) $height, height of the image
  608. * @param string $mode (optional) could be none, watermark, web20
  609. * @param string $float (optional) could be none, left, right
  610. * @param string $template (optional) name for a template file, look for singlepic-$template
  611. * @param string $caption (optional) additional caption text
  612. * @param string $link (optional) link to a other url instead the full image
  613. * @return the content
  614. */
  615. function nggSinglePicture($imageID, $width = 250, $height = 250, $mode = '', $float = '' , $template = '', $caption = '', $link = '') {
  616. global $post;
  617. $ngg_options = nggGallery::get_option('ngg_options');
  618. // get picturedata
  619. $picture = nggdb::find_image($imageID);
  620. // if we didn't get some data, exit now
  621. if ($picture == null)
  622. return __('[SinglePic not found]','nggallery');
  623. // add float to img
  624. switch ($float) {
  625. case 'left':
  626. $float =' ngg-left';
  627. break;
  628. case 'right':
  629. $float =' ngg-right';
  630. break;
  631. case 'center':
  632. $float =' ngg-center';
  633. break;
  634. default:
  635. $float ='';
  636. break;
  637. }
  638. // clean mode if needed
  639. $mode = ( preg_match('/(web20|watermark)/i', $mode) ) ? $mode : '';
  640. //let's initiate the url
  641. $picture->thumbnailURL = false;
  642. // check fo cached picture
  643. if ( $post->post_status == 'publish' )
  644. $picture->thumbnailURL = $picture->cached_singlepic_file($width, $height, $mode );
  645. // if we didn't use a cached image then we take the on-the-fly mode
  646. if (!$picture->thumbnailURL)
  647. $picture->thumbnailURL = trailingslashit( home_url() ) . 'index.php?callback=image&amp;pid=' . $imageID . '&amp;width=' . $width . '&amp;height=' . $height . '&amp;mode=' . $mode;
  648. // add more variables for render output
  649. $picture->imageURL = ( empty($link) ) ? $picture->imageURL : $link;
  650. $picture->href_link = $picture->get_href_link();
  651. $picture->alttext = html_entity_decode( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) );
  652. $picture->linktitle = htmlspecialchars( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) );
  653. $picture->description = html_entity_decode( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) );
  654. $picture->classname = 'ngg-singlepic'. $float;
  655. $picture->thumbcode = $picture->get_thumbcode( 'singlepic' . $imageID);
  656. $picture->height = (int) $height;
  657. $picture->width = (int) $width;
  658. $picture->caption = nggGallery::i18n($caption);
  659. // filter to add custom content for the output
  660. $picture = apply_filters('ngg_image_object', $picture, $imageID);
  661. // let's get the meta data
  662. $meta = new nggMeta($imageID);
  663. $meta->sanitize();
  664. $exif = $meta->get_EXIF();
  665. $iptc = $meta->get_IPTC();
  666. $xmp = $meta->get_XMP();
  667. $db = $meta->get_saved_meta();
  668. //if we get no exif information we try the database
  669. $exif = ($exif == false) ? $db : $exif;
  670. // look for singlepic-$template.php or pure singlepic.php
  671. $filename = ( empty($template) ) ? 'singlepic' : 'singlepic-' . $template;
  672. // create the output
  673. $out = nggGallery::capture ( $filename, array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db) );
  674. $out = apply_filters('ngg_show_singlepic_content', $out, $picture );
  675. return $out;
  676. }
  677. /**
  678. * nggShowGalleryTags() - create a gallery based on the tags
  679. *
  680. * @access public
  681. * @param string $taglist list of tags as csv
  682. * @return the content
  683. */
  684. function nggShowGalleryTags($taglist) {
  685. // $_GET from wp_query
  686. $pid = get_query_var('pid');
  687. $pageid = get_query_var('pageid');
  688. // get now the related images
  689. $picturelist = nggTags::find_images_for_tags($taglist , 'ASC');
  690. // look for ImageBrowser if we have a $_GET('pid')
  691. if ( $pageid == get_the_ID() || !is_home() )
  692. if (!empty( $pid )) {
  693. $out = nggCreateImageBrowser( $picturelist );
  694. return $out;
  695. }
  696. // go on if not empty
  697. if ( empty($picturelist) )
  698. return;
  699. // show gallery
  700. if ( is_array($picturelist) )
  701. $out = nggCreateGallery($picturelist, false);
  702. $out = apply_filters('ngg_show_gallery_tags_content', $out, $taglist);
  703. return $out;
  704. }
  705. /**
  706. * nggShowRelatedGallery() - create a gallery based on the tags
  707. *
  708. * @access public
  709. * @param string $taglist list of tags as csv
  710. * @param integer $maxImages (optional) limit the number of images to show
  711. * @return the content
  712. */
  713. function nggShowRelatedGallery($taglist, $maxImages = 0) {
  714. $ngg_options = nggGallery::get_option('ngg_options');
  715. // get now the related images
  716. $picturelist = nggTags::find_images_for_tags($taglist, 'RAND');
  717. // go on if not empty
  718. if ( empty($picturelist) )
  719. return;
  720. // cut the list to maxImages
  721. if ( $maxImages > 0 )
  722. array_splice($picturelist, $maxImages);
  723. // *** build the gallery output
  724. $out = '<div class="ngg-related-gallery">';
  725. foreach ($picturelist as $picture) {
  726. // get the effect code
  727. $thumbcode = $picture->get_thumbcode( __('Related images for', 'nggallery') . ' ' . get_the_title());
  728. $out .= '<a href="' . $picture->imageURL . '" title="' . stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) . '" ' . $thumbcode . ' >';
  729. $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 . '" />';
  730. $out .= '</a>' . "\n";
  731. }
  732. $out .= '</div>' . "\n";
  733. $out = apply_filters('ngg_show_related_gallery_content', $out, $taglist);
  734. return $out;
  735. }
  736. /**
  737. * nggShowAlbumTags() - create a gallery based on the tags
  738. *
  739. * @access public
  740. * @param string $taglist list of tags as csv
  741. * @return the content
  742. */
  743. function nggShowAlbumTags($taglist) {
  744. global $wpdb, $nggRewrite;
  745. // $_GET from wp_query
  746. $tag = get_query_var('gallerytag');
  747. $pageid = get_query_var('pageid');
  748. // look for gallerytag variable
  749. if ( $pageid == get_the_ID() || !is_home() ) {
  750. if (!empty( $tag )) {
  751. // 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';
  752. $slug = esc_attr( $tag );
  753. $tagname = $wpdb->get_var( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE slug = %s", $slug ) );
  754. $out = '<div id="albumnav"><span><a href="' . get_permalink() . '" title="' . __('Overview', 'nggallery') .' ">'.__('Overview', 'nggallery').'</a> | '.$tagname.'</span></div>';
  755. $out .= nggShowGalleryTags($slug);
  756. return $out;
  757. }
  758. }
  759. // get now the related images
  760. $picturelist = nggTags::get_album_images($taglist);
  761. // go on if not empty
  762. if ( empty($picturelist) )
  763. return;
  764. // re-structure the object that we can use the standard template
  765. foreach ($picturelist as $key => $picture) {
  766. $picturelist[$key]->previewpic = $picture->pid;
  767. $picturelist[$key]->previewname = $picture->filename;
  768. $picturelist[$key]->previewurl = site_url() . '/' . $picture->path . '/thumbs/thumbs_' . $picture->filename;
  769. $picturelist[$key]->counter = $picture->count;
  770. $picturelist[$key]->title = $picture->name;
  771. $picturelist[$key]->pagelink = $nggRewrite->get_permalink( array('gallerytag'=>$picture->slug) );
  772. }
  773. //TODO: Add pagination later
  774. $navigation = '<div class="ngg-clear"></div>';
  775. // create the output
  776. $out = nggGallery::capture ('album-compact', array ('album' => 0, 'galleries' => $picturelist, 'pagination' => $navigation) );
  777. $out = apply_filters('ngg_show_album_tags_content', $out, $taglist);
  778. return $out;
  779. }
  780. /**
  781. * nggShowRelatedImages() - return related images based on category or tags
  782. *
  783. * @access public
  784. * @param string $type could be 'tags' or 'category'
  785. * @param integer $maxImages of images
  786. * @return the content
  787. */
  788. function nggShowRelatedImages($type = '', $maxImages = 0) {
  789. $ngg_options = nggGallery::get_option('ngg_options');
  790. if ($type == '') {
  791. $type = $ngg_options['appendType'];
  792. $maxImages = $ngg_options['maxImages'];
  793. }
  794. $sluglist = array();
  795. switch ($type) {
  796. case 'tags':
  797. if (function_exists('get_the_tags')) {
  798. $taglist = get_the_tags();
  799. if (is_array($taglist)) {
  800. foreach ($taglist as $tag) {
  801. $sluglist[] = $tag->slug;
  802. }
  803. }
  804. }
  805. break;
  806. case 'category':
  807. $catlist = get_the_category();
  808. if (is_array($catlist)) {
  809. foreach ($catlist as $cat) {
  810. $sluglist[] = $cat->category_nicename;
  811. }
  812. }
  813. break;
  814. }
  815. $sluglist = implode(',', $sluglist);
  816. $out = nggShowRelatedGallery($sluglist, $maxImages);
  817. return $out;
  818. }
  819. /**
  820. * Template function for theme authors
  821. *
  822. * @access public
  823. * @param string (optional) $type could be 'tags' or 'category'
  824. * @param integer (optional) $maxNumbers of images
  825. * @return void
  826. */
  827. function the_related_images($type = 'tags', $maxNumbers = 7) {
  828. echo nggShowRelatedImages($type, $maxNumbers);
  829. }
  830. /**
  831. * nggShowRandomRecent($type, $maxImages, $template, $galleryId) - return recent or random images
  832. *
  833. * @access public
  834. * @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'
  835. * @param integer $maxImages of images
  836. * @param string $template (optional) name for a template file, look for gallery-$template
  837. * @param int $galleryId Limit to a specific gallery
  838. * @return the content
  839. */
  840. function nggShowRandomRecent($type, $maxImages, $template = '', $galleryId = 0) {
  841. // $_GET from wp_query
  842. $pid = get_query_var('pid');
  843. $pageid = get_query_var('pageid');
  844. // get now the recent or random images
  845. switch ($type) {
  846. case 'random':
  847. $picturelist = nggdb::get_random_images($maxImages, $galleryId);
  848. break;
  849. case 'id':
  850. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id');
  851. break;
  852. case 'date':
  853. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'date');
  854. break;
  855. case 'sort':
  856. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'sort');
  857. break;
  858. default:
  859. // default is by pid
  860. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id');
  861. }
  862. // look for ImageBrowser if we have a $_GET('pid')
  863. if ( $pageid == get_the_ID() || !is_home() )
  864. if (!empty( $pid )) {
  865. $out = nggCreateImageBrowser( $picturelist );
  866. return $out;
  867. }
  868. // go on if not empty
  869. if ( empty($picturelist) )
  870. return;
  871. // show gallery
  872. if ( is_array($picturelist) )
  873. $out = nggCreateGallery($picturelist, false, $template);
  874. $out = apply_filters('ngg_show_images_content', $out, $picturelist);
  875. return $out;
  876. }
  877. /**
  878. * nggTagCloud() - return a tag cloud based on the wp core tag cloud system
  879. *
  880. * @param array $args
  881. * @param string $template (optional) name for a template file, look for gallery-$template
  882. * @return the content
  883. */
  884. function nggTagCloud($args ='', $template = '') {
  885. global $nggRewrite;
  886. // $_GET from wp_query
  887. $tag = get_query_var('gallerytag');
  888. $pageid = get_query_var('pageid');
  889. // look for gallerytag variable
  890. if ( $pageid == get_the_ID() || !is_home() ) {
  891. if (!empty( $tag )) {
  892. $slug = esc_attr( $tag );
  893. $out = nggShowGalleryTags( $slug );
  894. return $out;
  895. }
  896. }
  897. $defaults = array(
  898. 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
  899. 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
  900. 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'ngg_tag'
  901. );
  902. $args = wp_parse_args( $args, $defaults );
  903. $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
  904. foreach ($tags as $key => $tag ) {
  905. $tags[ $key ]->link = $nggRewrite->get_permalink(array ('gallerytag' => $tag->slug));
  906. $tags[ $key ]->id = $tag->term_id;
  907. }
  908. $out = '<div class="ngg-tagcloud">' . wp_generate_tag_cloud( $tags, $args ) . '</div>';
  909. return $out;
  910. }
  911. ?>