PageRenderTime 62ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/nggfunctions.php

https://bitbucket.org/benkeen/nextgen-gallery
PHP | 1198 lines | 657 code | 240 blank | 301 comment | 150 complexity | 56ac53eba22e8109141b77b5514a4e7e MD5 | raw file
  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. $picturelist[$key]->lightboxCaption = nggGetLightboxCaption($picture, $ngg_options);
  305. // filter to add custom content for the output
  306. $picturelist[$key] = apply_filters('ngg_image_object', $picturelist[$key], $picture->pid);
  307. //check if $pid is in the array
  308. if ($picture->pid == $pid)
  309. $current_pid = $picturelist[$key];
  310. }
  311. reset($picturelist);
  312. //for paged galleries, take the first image in the array if it's not in the list
  313. $current_pid = ( empty($current_pid) ) ? current( $picturelist ) : $current_pid;
  314. // look for gallery-$template.php or pure gallery.php
  315. $filename = ( empty($template) ) ? 'gallery' : 'gallery-' . $template;
  316. //filter functions for custom addons
  317. $gallery = apply_filters( 'ngg_gallery_object', $gallery, $galleryID );
  318. $picturelist = apply_filters( 'ngg_picturelist_object', $picturelist, $galleryID );
  319. //additional navigation links
  320. $next = ( empty($nggNav->next) ) ? false : $nggNav->next;
  321. $prev = ( empty($nggNav->prev) ) ? false : $nggNav->prev;
  322. // create the output
  323. $out = nggGallery::capture ( $filename, array ('gallery' => $gallery, 'images' => $picturelist, 'pagination' => $navigation, 'current' => $current_pid, 'next' => $next, 'prev' => $prev) );
  324. // apply a filter after the output
  325. $out = apply_filters('ngg_gallery_output', $out, $picturelist);
  326. return $out;
  327. }
  328. /**
  329. * nggShowAlbum() - return a album based on the id
  330. *
  331. * @access public
  332. * @param int | string $albumID
  333. * @param string (optional) $template
  334. * @param string (optional) $gallery_template
  335. * @return the content
  336. */
  337. function nggShowAlbum($albumID, $template = 'extend', $gallery_template = '') {
  338. // $_GET from wp_query
  339. $gallery = get_query_var('gallery');
  340. $album = get_query_var('album');
  341. // in the case somebody uses the '0', it should be 'all' to show all galleries
  342. $albumID = ($albumID == 0) ? 'all' : $albumID;
  343. // first look for gallery variable
  344. if (!empty( $gallery )) {
  345. // subalbum support only one instance, you can't use more of them in one post
  346. //TODO: causes problems with SFC plugin, due to a second filter callback
  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;
  384. // $_GET from wp_query
  385. $nggpage = get_query_var('nggpage');
  386. $ngg_options = nggGallery::get_option('ngg_options');
  387. //this option can currently only set via the custom fields
  388. $maxElement = (int) $ngg_options['galPagedGalleries'];
  389. $sortorder = $galleriesID;
  390. $galleries = array();
  391. // get the galleries information
  392. foreach ($galleriesID as $i => $value)
  393. $galleriesID[$i] = addslashes($value);
  394. $unsort_galleries = $wpdb->get_results('SELECT * FROM '.$wpdb->nggallery.' WHERE gid IN (\''.implode('\',\'', $galleriesID).'\')', OBJECT_K);
  395. //TODO: Check this, problem exist when previewpic = 0
  396. //$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);
  397. // get the counter values
  398. $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);
  399. if ( is_array($picturesCounter) ) {
  400. foreach ($picturesCounter as $key => $value)
  401. $unsort_galleries[$key]->counter = $value->counter;
  402. }
  403. // get the id's of the preview images
  404. $imagesID = array();
  405. if ( is_array($unsort_galleries) ) {
  406. foreach ($unsort_galleries as $gallery_row)
  407. $imagesID[] = $gallery_row->previewpic;
  408. }
  409. $albumPreview = $wpdb->get_results('SELECT pid, filename FROM '.$wpdb->nggpictures.' WHERE pid IN (\''.implode('\',\'', $imagesID).'\')', OBJECT_K);
  410. // re-order them and populate some
  411. foreach ($sortorder as $key) {
  412. //if we have a prefix 'a' then it's a subalbum, instead a gallery
  413. if (substr( $key, 0, 1) == 'a') {
  414. // get the album content
  415. if ( !$subalbum = $nggdb->find_album(substr( $key, 1)) )
  416. continue;
  417. //populate the sub album values
  418. $galleries[$key]->counter = 0;
  419. $galleries[$key]->previewurl = '';
  420. // ensure that album contain a preview image
  421. if ($subalbum->previewpic > 0){
  422. $image = $nggdb->find_image( $subalbum->previewpic );
  423. $galleries[$key]->previewurl = isset($image->thumbURL) ? $image->thumbURL : '';
  424. }
  425. $galleries[$key]->previewpic = $subalbum->previewpic;
  426. $galleries[$key]->previewname = $subalbum->name;
  427. //link to the subalbum
  428. $args['album'] = ( $ngg_options['usePermalinks'] ) ? $subalbum->slug : $subalbum->id;
  429. $args['gallery'] = false;
  430. $args['nggpage'] = false;
  431. $pageid = (isset($subalbum->pageid) ? $subalbum->pageid : 0);
  432. $galleries[$key]->pagelink = ($pageid > 0) ? get_permalink($pageid) : $nggRewrite->get_permalink($args);
  433. $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n($subalbum->albumdesc) );
  434. $galleries[$key]->title = html_entity_decode ( nggGallery::i18n($subalbum->name) );
  435. // apply a filter on gallery object before the output
  436. $galleries[$key] = apply_filters('ngg_album_galleryobject', $galleries[$key]);
  437. continue;
  438. }
  439. // If a gallery is not found it should be ignored
  440. if (!$unsort_galleries[$key])
  441. continue;
  442. // No images found, set counter to 0
  443. if (!isset($galleries[$key]->counter)){
  444. $galleries[$key]->counter = 0;
  445. $galleries[$key]->previewurl = '';
  446. }
  447. // Add the counter value if avaible
  448. $galleries[$key] = $unsort_galleries[$key];
  449. // add the file name and the link
  450. if ($galleries[$key]->previewpic != 0) {
  451. $galleries[$key]->previewname = $albumPreview[$galleries[$key]->previewpic]->filename;
  452. $galleries[$key]->previewurl = site_url().'/' . $galleries[$key]->path . '/thumbs/thumbs_' . $albumPreview[$galleries[$key]->previewpic]->filename;
  453. } else {
  454. $first_image = $wpdb->get_row('SELECT * FROM '. $wpdb->nggpictures .' WHERE exclude != 1 AND galleryid = '. $key .' ORDER by pid DESC limit 0,1');
  455. if (isset($first_image)) {
  456. $galleries[$key]->previewpic = $first_image->pid;
  457. $galleries[$key]->previewname = $first_image->filename;
  458. $galleries[$key]->previewurl = site_url() . '/' . $galleries[$key]->path . '/thumbs/thumbs_' . $first_image->filename;
  459. }
  460. }
  461. // choose between variable and page link
  462. if ($ngg_options['galNoPages']) {
  463. $args['album'] = ( $ngg_options['usePermalinks'] ) ? $album->slug : $album->id;
  464. $args['gallery'] = ( $ngg_options['usePermalinks'] ) ? $galleries[$key]->slug : $key;
  465. $args['nggpage'] = false;
  466. $galleries[$key]->pagelink = $nggRewrite->get_permalink($args);
  467. } else {
  468. $galleries[$key]->pagelink = get_permalink( $galleries[$key]->pageid );
  469. }
  470. // description can contain HTML tags
  471. $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n( stripslashes($galleries[$key]->galdesc), 'gal_' . $galleries[$key]->gid . '_description') ) ;
  472. // i18n
  473. $galleries[$key]->title = html_entity_decode ( nggGallery::i18n( stripslashes($galleries[$key]->title), 'gal_' . $galleries[$key]->gid . '_title') ) ;
  474. // apply a filter on gallery object before the output
  475. $galleries[$key] = apply_filters('ngg_album_galleryobject', $galleries[$key]);
  476. }
  477. // apply a filter on gallery object before paging starts
  478. $galleries = apply_filters('ngg_album_galleries_before_paging', $galleries, $album);
  479. // check for page navigation
  480. if ($maxElement > 0) {
  481. if ( !is_home() || $pageid == get_the_ID() ) {
  482. $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
  483. }
  484. else $page = 1;
  485. $start = $offset = ( $page - 1 ) * $maxElement;
  486. $total = count($galleries);
  487. // remove the element if we didn't start at the beginning
  488. if ($start > 0 ) array_splice($galleries, 0, $start);
  489. // return the list of images we need
  490. array_splice($galleries, $maxElement);
  491. $nggNav = new nggNavigation;
  492. $navigation = $nggNav->create_navigation($page, $total, $maxElement);
  493. } else {
  494. $navigation = '<div class="ngg-clear"></div>';
  495. }
  496. // apply a filter on $galleries before the output
  497. $galleries = apply_filters('ngg_album_galleries', $galleries);
  498. // if sombody didn't enter any template , take the extend version
  499. $filename = ( empty($template) ) ? 'album-extend' : 'album-' . $template ;
  500. // create the output
  501. $out = nggGallery::capture ( $filename, array ('album' => $album, 'galleries' => $galleries, 'pagination' => $navigation) );
  502. return $out;
  503. }
  504. /**
  505. * nggShowImageBrowser()
  506. *
  507. * @access public
  508. * @param int|string $galleryID or gallery name
  509. * @param string $template (optional) name for a template file, look for imagebrowser-$template
  510. * @return the content
  511. */
  512. function nggShowImageBrowser($galleryID, $template = '') {
  513. global $wpdb;
  514. $ngg_options = nggGallery::get_option('ngg_options');
  515. //Set sort order value, if not used (upgrade issue)
  516. $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
  517. $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';
  518. // get the pictures
  519. $picturelist = nggdb::get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);
  520. if ( is_array($picturelist) )
  521. $out = nggCreateImageBrowser($picturelist, $template);
  522. else
  523. $out = __('[Gallery not found]','nggallery');
  524. $out = apply_filters('ngg_show_imagebrowser_content', $out, $galleryID);
  525. return $out;
  526. }
  527. /**
  528. * nggCreateImageBrowser()
  529. *
  530. * @access internal
  531. * @param array $picturelist
  532. * @param string $template (optional) name for a template file, look for imagebrowser-$template
  533. * @return the content
  534. */
  535. function nggCreateImageBrowser($picturelist, $template = '') {
  536. global $nggRewrite, $ngg;
  537. require_once( dirname (__FILE__) . '/lib/meta.php' );
  538. // $_GET from wp_query
  539. $pid = get_query_var('pid');
  540. // we need to know the current page id
  541. $current_page = (get_the_ID() == false) ? 0 : get_the_ID();
  542. // create a array with id's for better walk inside
  543. foreach ($picturelist as $picture)
  544. $picarray[] = $picture->pid;
  545. $total = count($picarray);
  546. if ( !empty( $pid )) {
  547. if ( is_numeric($pid) )
  548. $act_pid = intval($pid);
  549. else {
  550. // in the case it's a slug we need to search for the pid
  551. foreach ($picturelist as $key => $picture) {
  552. if ($picture->image_slug == $pid) {
  553. $act_pid = $key;
  554. break;
  555. }
  556. }
  557. }
  558. } else {
  559. reset($picarray);
  560. $act_pid = current($picarray);
  561. }
  562. // get ids for back/next
  563. $key = array_search($act_pid, $picarray);
  564. if (!$key) {
  565. $act_pid = reset($picarray);
  566. $key = key($picarray);
  567. }
  568. $back_pid = ( $key >= 1 ) ? $picarray[$key-1] : end($picarray) ;
  569. $next_pid = ( $key < ($total-1) ) ? $picarray[$key+1] : reset($picarray) ;
  570. // get the picture data
  571. $picture = nggdb::find_image($act_pid);
  572. // if we didn't get some data, exit now
  573. if ($picture == null)
  574. return;
  575. // add more variables for render output
  576. $picture->href_link = $picture->get_href_link();
  577. $args ['pid'] = ($ngg->options['usePermalinks']) ? $picturelist[$back_pid]->image_slug : $back_pid;
  578. $picture->previous_image_link = $nggRewrite->get_permalink( $args );
  579. $picture->previous_pid = $back_pid;
  580. $args ['pid'] = ($ngg->options['usePermalinks']) ? $picturelist[$next_pid]->image_slug : $next_pid;
  581. $picture->next_image_link = $nggRewrite->get_permalink( $args );
  582. $picture->next_pid = $next_pid;
  583. $picture->number = $key + 1;
  584. $picture->total = $total;
  585. $picture->linktitle = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) );
  586. $picture->alttext = ( empty($picture->alttext) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) );
  587. $picture->description = ( empty($picture->description) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) );
  588. $picture->anchor = 'ngg-imagebrowser-' . $picture->galleryid . '-' . $current_page;
  589. $picture->lightboxCaption = nggGetLightboxCaption($picture);
  590. // filter to add custom content for the output
  591. $picture = apply_filters('ngg_image_object', $picture, $act_pid);
  592. // let's get the meta data
  593. $meta = new nggMeta($act_pid);
  594. $meta->sanitize();
  595. $exif = $meta->get_EXIF();
  596. $iptc = $meta->get_IPTC();
  597. $xmp = $meta->get_XMP();
  598. $db = $meta->get_saved_meta();
  599. //if we get no exif information we try the database
  600. $exif = ($exif == false) ? $db : $exif;
  601. // look for imagebrowser-$template.php or pure imagebrowser.php
  602. $filename = ( empty($template) ) ? 'imagebrowser' : 'imagebrowser-' . $template;
  603. // create the output
  604. $out = nggGallery::capture ( $filename , array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db) );
  605. return $out;
  606. }
  607. /**
  608. * nggSinglePicture() - show a single picture based on the id
  609. *
  610. * @access public
  611. * @param int $imageID, db-ID of the image
  612. * @param int (optional) $width, width of the image
  613. * @param int (optional) $height, height of the image
  614. * @param string $mode (optional) could be none, watermark, web20
  615. * @param string $float (optional) could be none, left, right
  616. * @param string $template (optional) name for a template file, look for singlepic-$template
  617. * @param string $caption (optional) additional caption text
  618. * @param string $link (optional) link to a other url instead the full image
  619. * @return the content
  620. */
  621. function nggSinglePicture($imageID, $width = 250, $height = 250, $mode = '', $float = '' , $template = '', $caption = '', $link = '') {
  622. global $post;
  623. $ngg_options = nggGallery::get_option('ngg_options');
  624. // get picturedata
  625. $picture = nggdb::find_image($imageID);
  626. // if we didn't get some data, exit now
  627. if ($picture == null)
  628. return __('[SinglePic not found]','nggallery');
  629. // add float to img
  630. switch ($float) {
  631. case 'left':
  632. $float =' ngg-left';
  633. break;
  634. case 'right':
  635. $float =' ngg-right';
  636. break;
  637. case 'center':
  638. $float =' ngg-center';
  639. break;
  640. default:
  641. $float ='';
  642. break;
  643. }
  644. // clean mode if needed
  645. $mode = ( preg_match('/(web20|watermark)/i', $mode) ) ? $mode : '';
  646. //let's initiate the url
  647. $picture->thumbnailURL = false;
  648. // check fo cached picture
  649. if ( $post->post_status == 'publish' )
  650. $picture->thumbnailURL = $picture->cached_singlepic_file($width, $height, $mode );
  651. // if we didn't use a cached image then we take the on-the-fly mode
  652. if (!$picture->thumbnailURL)
  653. $picture->thumbnailURL = trailingslashit( home_url() ) . 'index.php?callback=image&amp;pid=' . $imageID . '&amp;width=' . $width . '&amp;height=' . $height . '&amp;mode=' . $mode;
  654. // add more variables for render output
  655. $picture->imageURL = ( empty($link) ) ? $picture->imageURL : $link;
  656. $picture->href_link = $picture->get_href_link();
  657. $picture->alttext = html_entity_decode( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) );
  658. $picture->linktitle = htmlspecialchars( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) );
  659. $picture->description = html_entity_decode( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) );
  660. $picture->classname = 'ngg-singlepic'. $float;
  661. $picture->thumbcode = $picture->get_thumbcode( 'singlepic' . $imageID);
  662. $picture->height = (int) $height;
  663. $picture->width = (int) $width;
  664. $picture->caption = nggGallery::i18n($caption);
  665. // filter to add custom content for the output
  666. $picture = apply_filters('ngg_image_object', $picture, $imageID);
  667. // let's get the meta data
  668. $meta = new nggMeta($imageID);
  669. $meta->sanitize();
  670. $exif = $meta->get_EXIF();
  671. $iptc = $meta->get_IPTC();
  672. $xmp = $meta->get_XMP();
  673. $db = $meta->get_saved_meta();
  674. //if we get no exif information we try the database
  675. $exif = ($exif == false) ? $db : $exif;
  676. // look for singlepic-$template.php or pure singlepic.php
  677. $filename = ( empty($template) ) ? 'singlepic' : 'singlepic-' . $template;
  678. // create the output
  679. $out = nggGallery::capture ( $filename, array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db) );
  680. $out = apply_filters('ngg_show_singlepic_content', $out, $picture );
  681. return $out;
  682. }
  683. /**
  684. * nggShowGalleryTags() - create a gallery based on the tags
  685. *
  686. * @access public
  687. * @param string $taglist list of tags as csv
  688. * @return the content
  689. */
  690. function nggShowGalleryTags($taglist) {
  691. // $_GET from wp_query
  692. $pid = get_query_var('pid');
  693. $pageid = get_query_var('pageid');
  694. // get now the related images
  695. $picturelist = nggTags::find_images_for_tags($taglist , 'ASC');
  696. // look for ImageBrowser if we have a $_GET('pid')
  697. if ( $pageid == get_the_ID() || !is_home() )
  698. if (!empty( $pid )) {
  699. $out = nggCreateImageBrowser( $picturelist );
  700. return $out;
  701. }
  702. // go on if not empty
  703. if ( empty($picturelist) )
  704. return;
  705. // show gallery
  706. if ( is_array($picturelist) )
  707. $out = nggCreateGallery($picturelist, false);
  708. $out = apply_filters('ngg_show_gallery_tags_content', $out, $taglist);
  709. return $out;
  710. }
  711. /**
  712. * nggShowRelatedGallery() - create a gallery based on the tags
  713. *
  714. * @access public
  715. * @param string $taglist list of tags as csv
  716. * @param integer $maxImages (optional) limit the number of images to show
  717. * @return the content
  718. */
  719. function nggShowRelatedGallery($taglist, $maxImages = 0) {
  720. $ngg_options = nggGallery::get_option('ngg_options');
  721. // get now the related images
  722. $picturelist = nggTags::find_images_for_tags($taglist, 'RAND');
  723. // go on if not empty
  724. if ( empty($picturelist) )
  725. return;
  726. // cut the list to maxImages
  727. if ( $maxImages > 0 )
  728. array_splice($picturelist, $maxImages);
  729. // *** build the gallery output
  730. $out = '<div class="ngg-related-gallery">';
  731. foreach ($picturelist as $picture) {
  732. // get the effect code
  733. $thumbcode = $picture->get_thumbcode( __('Related images for', 'nggallery') . ' ' . get_the_title());
  734. $out .= '<a href="' . $picture->imageURL . '" title="' . stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) . '" ' . $thumbcode . ' >';
  735. $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 . '" />';
  736. $out .= '</a>' . "\n";
  737. }
  738. $out .= '</div>' . "\n";
  739. $out = apply_filters('ngg_show_related_gallery_content', $out, $taglist);
  740. return $out;
  741. }
  742. /**
  743. * nggShowAlbumTags() - create a gallery based on the tags
  744. *
  745. * @access public
  746. * @param string $taglist list of tags as csv
  747. * @return the content
  748. */
  749. function nggShowAlbumTags($taglist) {
  750. global $wpdb, $nggRewrite;
  751. // $_GET from wp_query
  752. $tag = get_query_var('gallerytag');
  753. $pageid = get_query_var('pageid');
  754. // look for gallerytag variable
  755. if ( $pageid == get_the_ID() || !is_home() ) {
  756. if (!empty( $tag )) {
  757. // 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';
  758. $slug = esc_attr( $tag );
  759. $tagname = $wpdb->get_var( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE slug = %s", $slug ) );
  760. $out = '<div id="albumnav"><span><a href="' . get_permalink() . '" title="' . __('Overview', 'nggallery') .' ">'.__('Overview', 'nggallery').'</a> | '.$tagname.'</span></div>';
  761. $out .= nggShowGalleryTags($slug);
  762. return $out;
  763. }
  764. }
  765. // get now the related images
  766. $picturelist = nggTags::get_album_images($taglist);
  767. // go on if not empty
  768. if ( empty($picturelist) )
  769. return;
  770. // re-structure the object that we can use the standard template
  771. foreach ($picturelist as $key => $picture) {
  772. $picturelist[$key]->previewpic = $picture->pid;
  773. $picturelist[$key]->previewname = $picture->filename;
  774. $picturelist[$key]->previewurl = site_url() . '/' . $picture->path . '/thumbs/thumbs_' . $picture->filename;
  775. $picturelist[$key]->counter = $picture->count;
  776. $picturelist[$key]->title = $picture->name;
  777. $picturelist[$key]->pagelink = $nggRewrite->get_permalink( array('gallerytag'=>$picture->slug) );
  778. }
  779. //TODO: Add pagination later
  780. $navigation = '<div class="ngg-clear"></div>';
  781. // create the output
  782. $out = nggGallery::capture ('album-compact', array ('album' => 0, 'galleries' => $picturelist, 'pagination' => $navigation) );
  783. $out = apply_filters('ngg_show_album_tags_content', $out, $taglist);
  784. return $out;
  785. }
  786. /**
  787. * nggShowRelatedImages() - return related images based on category or tags
  788. *
  789. * @access public
  790. * @param string $type could be 'tags' or 'category'
  791. * @param integer $maxImages of images
  792. * @return the content
  793. */
  794. function nggShowRelatedImages($type = '', $maxImages = 0) {
  795. $ngg_options = nggGallery::get_option('ngg_options');
  796. if ($type == '') {
  797. $type = $ngg_options['appendType'];
  798. $maxImages = $ngg_options['maxImages'];
  799. }
  800. $sluglist = array();
  801. switch ($type) {
  802. case 'tags':
  803. if (function_exists('get_the_tags')) {
  804. $taglist = get_the_tags();
  805. if (is_array($taglist)) {
  806. foreach ($taglist as $tag) {
  807. $sluglist[] = $tag->slug;
  808. }
  809. }
  810. }
  811. break;
  812. case 'category':
  813. $catlist = get_the_category();
  814. if (is_array($catlist)) {
  815. foreach ($catlist as $cat) {
  816. $sluglist[] = $cat->category_nicename;
  817. }
  818. }
  819. break;
  820. }
  821. $sluglist = implode(',', $sluglist);
  822. $out = nggShowRelatedGallery($sluglist, $maxImages);
  823. return $out;
  824. }
  825. /**
  826. * Template function for theme authors
  827. *
  828. * @access public
  829. * @param string (optional) $type could be 'tags' or 'category'
  830. * @param integer (optional) $maxNumbers of images
  831. * @return void
  832. */
  833. function the_related_images($type = 'tags', $maxNumbers = 7) {
  834. echo nggShowRelatedImages($type, $maxNumbers);
  835. }
  836. /**
  837. * nggShowRandomRecent($type, $maxImages, $template, $galleryId) - return recent or random images
  838. *
  839. * @access public
  840. * @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'
  841. * @param integer $maxImages of images
  842. * @param string $template (optional) name for a template file, look for gallery-$template
  843. * @param int $galleryId Limit to a specific gallery
  844. * @return the content
  845. */
  846. function nggShowRandomRecent($type, $maxImages, $template = '', $galleryId = 0) {
  847. // $_GET from wp_query
  848. $pid = get_query_var('pid');
  849. $pageid = get_query_var('pageid');
  850. // get now the recent or random images
  851. switch ($type) {
  852. case 'random':
  853. $picturelist = nggdb::get_random_images($maxImages, $galleryId);
  854. break;
  855. case 'id':
  856. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id');
  857. break;
  858. case 'date':
  859. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'date');
  860. break;
  861. case 'sort':
  862. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'sort');
  863. break;
  864. default:
  865. // default is by pid
  866. $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id');
  867. }
  868. // look for ImageBrowser if we have a $_GET('pid')
  869. if ( $pageid == get_the_ID() || !is_home() )
  870. if (!empty( $pid )) {
  871. $out = nggCreateImageBrowser( $picturelist );
  872. return $out;
  873. }
  874. // go on if not empty
  875. if ( empty($picturelist) )
  876. return;
  877. // show gallery
  878. if ( is_array($picturelist) )
  879. $out = nggCreateGallery($picturelist, false, $template);
  880. $out = apply_filters('ngg_show_images_content', $out, $picturelist);
  881. return $out;
  882. }
  883. /**
  884. * nggTagCloud() - return a tag cloud based on the wp core tag cloud system
  885. *
  886. * @param array $args
  887. * @param string $template (optional) name for a template file, look for gallery-$template
  888. * @return the content
  889. */
  890. function nggTagCloud($args ='', $template = '') {
  891. global $nggRewrite;
  892. // $_GET from wp_query
  893. $tag = get_query_var('gallerytag');
  894. $pageid = get_query_var('pageid');
  895. // look for gallerytag variable
  896. if ( $pageid == get_the_ID() || !is_home() ) {
  897. if (!empty( $tag )) {
  898. $slug = esc_attr( $tag );
  899. $out = nggShowGalleryTags( $slug );
  900. return $out;
  901. }
  902. }
  903. $defaults = array(
  904. 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
  905. 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
  906. 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'ngg_tag'
  907. );
  908. $args = wp_parse_args( $args, $defaults );
  909. $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
  910. foreach ($tags as $key => $tag ) {
  911. $tags[ $key ]->link = $nggRewrite->get_permalink(array ('gallerytag' => $tag->slug));
  912. $tags[ $key ]->id = $tag->term_id;
  913. }
  914. $out = '<div class="ngg-tagcloud">' . wp_generate_tag_cloud( $tags, $args ) . '</div>';
  915. return $out;
  916. }
  917. /**
  918. * nggGetLightboxCaption() - returns the appropriate caption for an image, based on the "Lightbox Caption Format" option
  919. * on the Options -> Gallery page.
  920. *
  921. *
  922. */
  923. function nggGetLightboxCaption($picture, $ngg_options = array()) {
  924. if (empty($ngg_options)) {
  925. $ngg_options = nggGallery::get_option('ngg_options');
  926. }
  927. $caption = "";
  928. if ($ngg_options["galCaptionFormat"] == "custom") {
  929. $patterns = array('/%GALLERY_NAME%/', '/%DESCRIPTION%/', '/%ALT_TEXT%/', '/%FILENAME%/');
  930. $replacements = array($picture->title, $picture->description, $picture->alttext, $picture->filename);
  931. $caption = preg_replace($patterns, $replacements, $ngg_options["galCaptionFormatCustom"]);
  932. } else {
  933. // fussy, but very convenient for the user in that it's smart enough to never include the : , or - separator chars
  934. // when no alt text (description) is supplied
  935. switch ($ngg_options["galCaptionFormat"]) {
  936. case "%DESCRIPTION%":
  937. $caption = $picture->description;
  938. break;
  939. case "%ALT_TEXT%":
  940. $caption = $picture->alttext;
  941. break;
  942. default:
  943. if (empty($picture->alttext)) {
  944. $caption = $picture->title;
  945. } else {
  946. $separators = array(
  947. "%GALLERY_NAME%, %ALT_TEXT%" => ", ",
  948. "%GALLERY_NAME%: %ALT_TEXT%" => ": ",
  949. "%GALLERY_NAME% - %ALT_TEXT%" => " - ",
  950. );
  951. $caption = $picture->title . $separators[$ngg_options["galCaptionFormat"]] . $picture->alttext;
  952. }
  953. break;
  954. }
  955. }
  956. return $caption;
  957. }
  958. ?>