PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/nextgen-gallery/nggfunctions.php

https://github.com/archives-of-michigan/seekingmichigan.org-Wordpress
PHP | 794 lines | 426 code | 168 blank | 200 comment | 92 complexity | 9a24d0bc725c91773fb3d162353b075d 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. * nggShowSlideshow()
  5. *
  6. * @access public
  7. * @param integer $galleryID
  8. * @param integer $irWidth
  9. * @param integer $irHeight
  10. * @return the content
  11. */
  12. function nggShowSlideshow($galleryID, $width, $height) {
  13. require_once (dirname (__FILE__).'/lib/swfobject.php');
  14. $ngg_options = nggGallery::get_option('ngg_options');
  15. // remove media file from RSS feed
  16. if ( is_feed() ) {
  17. $out = '[' . $ngg_options['galTextSlide'] . ']';
  18. return $out;
  19. }
  20. // If the Imagerotator didn't exist, skip the output
  21. if ( NGGALLERY_IREXIST == false )
  22. return;
  23. if (empty($width) ) $width = (int) $ngg_options['irWidth'];
  24. if (empty($height)) $height = (int) $ngg_options['irHeight'];
  25. // init the flash output
  26. $swfobject = new swfobject( $ngg_options['irURL'] , 'so' . $galleryID, $width, $height, '7.0.0', 'false');
  27. $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>';
  28. $swfobject->add_params('wmode', 'opaque');
  29. $swfobject->add_params('allowfullscreen', 'true');
  30. $swfobject->add_params('bgcolor', $ngg_options['irScreencolor'], '000000', 'string', '#');
  31. $swfobject->add_attributes('styleclass', 'slideshow');
  32. $swfobject->add_attributes('name', 'so' . $galleryID);
  33. // adding the flash parameter
  34. $swfobject->add_flashvars( 'file', NGGALLERY_URLPATH.'xml/imagerotator.php?gid=' . $galleryID );
  35. $swfobject->add_flashvars( 'shuffle', $ngg_options['irShuffle'], 'true', 'bool');
  36. $swfobject->add_flashvars( 'linkfromdisplay', $ngg_options['irLinkfromdisplay'], 'false', 'bool');
  37. $swfobject->add_flashvars( 'shownavigation', $ngg_options['irShownavigation'], 'true', 'bool');
  38. $swfobject->add_flashvars( 'showicons', $ngg_options['irShowicons'], 'true', 'bool');
  39. $swfobject->add_flashvars( 'kenburns', $ngg_options['irKenburns'], 'false', 'bool');
  40. $swfobject->add_flashvars( 'overstretch', $ngg_options['irOverstretch'], 'false', 'string');
  41. $swfobject->add_flashvars( 'rotatetime', $ngg_options['irRotatetime'], 5, 'int');
  42. $swfobject->add_flashvars( 'transition', $ngg_options['irTransition'], 'random', 'string');
  43. $swfobject->add_flashvars( 'backcolor', $ngg_options['irBackcolor'], 'FFFFFF', 'string', '0x');
  44. $swfobject->add_flashvars( 'frontcolor', $ngg_options['irFrontcolor'], '000000', 'string', '0x');
  45. $swfobject->add_flashvars( 'lightcolor', $ngg_options['irLightcolor'], '000000', 'string', '0x');
  46. $swfobject->add_flashvars( 'screencolor', $ngg_options['irScreencolor'], '000000', 'string', '0x');
  47. if ($ngg_options['irWatermark'])
  48. $swfobject->add_flashvars( 'logo', $ngg_options['wmPath'], '', 'string');
  49. $swfobject->add_flashvars( 'audio', $ngg_options['irAudio'], '', 'string');
  50. $swfobject->add_flashvars( 'width', $width, '260');
  51. $swfobject->add_flashvars( 'height', $height, '320');
  52. // create the output
  53. $out = '<div class="slideshow">' . $swfobject->output() . '</div>';
  54. // add now the script code
  55. $out .= "\n".'<script type="text/javascript" defer="defer">';
  56. if ($ngg_options['irXHTMLvalid']) $out .= "\n".'<!--';
  57. if ($ngg_options['irXHTMLvalid']) $out .= "\n".'//<![CDATA[';
  58. $out .= $swfobject->javascript();
  59. if ($ngg_options['irXHTMLvalid']) $out .= "\n".'//]]>';
  60. if ($ngg_options['irXHTMLvalid']) $out .= "\n".'-->';
  61. $out .= "\n".'</script>';
  62. $out = apply_filters('ngg_show_slideshow_content', $out);
  63. return $out;
  64. }
  65. /**
  66. * nggShowGallery() - return a gallery
  67. *
  68. * @access public
  69. * @param int $galleryID
  70. * @param string $template (optional) name for a template file, look for gallery-$template
  71. * @return the content
  72. */
  73. function nggShowGallery( $galleryID, $template = '' ) {
  74. global $nggRewrite;
  75. $ngg_options = nggGallery::get_option('ngg_options');
  76. //Set sort order value, if not used (upgrade issue)
  77. $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
  78. $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';
  79. // get gallery values
  80. $picturelist = nggdb::get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);
  81. if ( !$picturelist->gid )
  82. __('[Gallery not found]','nggallery');
  83. else
  84. $galleryID = (int) $picturelist->gid;
  85. // $_GET from wp_query
  86. $show = get_query_var('show');
  87. $pid = get_query_var('pid');
  88. $pageid = get_query_var('pageid');
  89. // set $show if slideshow first
  90. if ( empty( $show ) AND ($ngg_options['galShowOrder'] == 'slide')) {
  91. if (is_home()) $pageid = get_the_ID();
  92. $show = 'slide';
  93. }
  94. // go on only on this page
  95. if ( !is_home() || $pageid == get_the_ID() ) {
  96. // 1st look for ImageBrowser link
  97. if ( !empty($pid) && $ngg_options['galImgBrowser'] ) {
  98. $out = nggShowImageBrowser( $galleryID, $mode );
  99. return $out;
  100. }
  101. // 2nd look for slideshow
  102. if ( $show == 'slide' ) {
  103. $args['show'] = "gallery";
  104. $out = '<div class="ngg-galleryoverview">';
  105. $out .= '<div class="slideshowlink"><a class="slideshowlink" href="' . $nggRewrite->get_permalink($args) . '">'.$ngg_options['galTextGallery'].'</a></div>';
  106. $out .= nggShowSlideshow($galleryID, $ngg_options['irWidth'], $ngg_options['irHeight']);
  107. $out .= '</div>'."\n";
  108. $out .= '<div class="ngg-clear"></div>'."\n";
  109. return $out;
  110. }
  111. }
  112. // get all picture with this galleryid
  113. if ( is_array($picturelist) )
  114. $out = nggCreateGallery($picturelist, $galleryID, $template);
  115. $out = apply_filters('ngg_show_gallery_content', $out, intval($galleryID));
  116. return $out;
  117. }
  118. /**
  119. * Build a gallery output
  120. *
  121. * @access internal
  122. * @param array $picturelist
  123. * @param bool $galleryID, if you supply a gallery ID, you can add a slideshow link
  124. * @param string $template (optional) name for a template file, look for gallery-$template
  125. * @return the content
  126. */
  127. function nggCreateGallery($picturelist, $galleryID = false, $template = '') {
  128. global $nggRewrite;
  129. $ngg_options = nggGallery::get_option('ngg_options');
  130. // $_GET from wp_query
  131. $nggpage = get_query_var('nggpage');
  132. $pageid = get_query_var('pageid');
  133. if ( !is_array($picturelist) )
  134. $picturelist = array($picturelist);
  135. // Populate galleries values from the first image
  136. $first_image = current($picturelist);
  137. $gallery = new stdclass;
  138. $gallery->ID = (int) $galleryID;
  139. $gallery->show_slideshow = false;
  140. $gallery->name = stripslashes ( $first_image->name );
  141. $gallery->title = stripslashes( $first_image->title );
  142. $gallery->description = html_entity_decode(stripslashes( $first_image->galdesc));
  143. $gallery->pageid = $first_image->pageid;
  144. reset($picturelist);
  145. $maxElement = $ngg_options['galImages'];
  146. $thumbwidth = $ngg_options['thumbwidth'];
  147. $thumbheight = $ngg_options['thumbheight'];
  148. // fixed width if needed
  149. $gallery->columns = intval($ngg_options['galColumns']);
  150. $gallery->imagewidth = ($gallery->columns > 0) ? 'style="width:'. floor(100/$gallery->columns) .'%;"' : '';
  151. // set thumb size
  152. $thumbsize = '';
  153. if ($ngg_options['thumbfix']) $thumbsize = 'width="'.$thumbwidth.'" height="'.$thumbheight.'"';
  154. if ($ngg_options['thumbcrop']) $thumbsize = 'width="'.$thumbwidth.'" height="'.$thumbwidth.'"';
  155. // show slideshow link
  156. if ($galleryID) {
  157. if (($ngg_options['galShowSlide']) AND (NGGALLERY_IREXIST)) {
  158. $gallery->show_slideshow = true;
  159. $gallery->slideshow_link = $nggRewrite->get_permalink(array ('show' => "slide"));
  160. $gallery->slideshow_link_text = $ngg_options['galTextSlide'];
  161. }
  162. if ($ngg_options['usePicLens']) {
  163. $gallery->show_piclens = true;
  164. $gallery->piclens_link = "javascript:PicLensLite.start({feedUrl:'" . htmlspecialchars( nggMediaRss::get_gallery_mrss_url($gallery->ID) ) . "'});";
  165. }
  166. }
  167. // check for page navigation
  168. if ($maxElement > 0) {
  169. if ( !is_home() || $pageid == get_the_ID() ) {
  170. $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
  171. }
  172. else $page = 1;
  173. $start = $offset = ( $page - 1 ) * $maxElement;
  174. $total = count($picturelist);
  175. // remove the element if we didn't start at the beginning
  176. if ($start > 0 ) array_splice($picturelist, 0, $start);
  177. // return the list of images we need
  178. array_splice($picturelist, $maxElement);
  179. $navigation = nggGallery::create_navigation($page, $total, $maxElement);
  180. } else {
  181. $navigation = '<div class="ngg-clear">&nbsp;</div>';
  182. }
  183. //var_dump($picturelist);
  184. foreach ($picturelist as $key => $picture) {
  185. // choose link between imagebrowser or effect
  186. $link = ($ngg_options['galImgBrowser']) ? $nggRewrite->get_permalink( array('pid'=>$picture->pid) ) : $picture->imageURL;
  187. // get the effect code
  188. if ($galleryID)
  189. $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode($picturelist[0]->name);
  190. else
  191. $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode(get_the_title());
  192. // add a filter for the link
  193. $picturelist[$key]->imageURL = apply_filters('ngg_create_gallery_link', $link, $picture);
  194. $picturelist[$key]->thumbnailURL = $picture->thumbURL;
  195. $picturelist[$key]->size = $thumbsize;
  196. $picturelist[$key]->thumbcode = $thumbcode;
  197. $picturelist[$key]->description = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes($picture->description) );
  198. $picturelist[$key]->alttext = ( empty($picture->alttext) ) ? ' ' : htmlspecialchars ( stripslashes($picture->alttext) );
  199. $picturelist[$key]->caption = ( empty($picture->description) ) ? '&nbsp;' : html_entity_decode( stripslashes($picture->description) );
  200. }
  201. // look for gallery-$template.php or pure gallery.php
  202. $filename = ( empty($template) ) ? 'gallery' : 'gallery-' . $template;
  203. // create the output
  204. $out = nggGallery::capture ( $filename, array ('gallery' => $gallery, 'images' => $picturelist, 'pagination' => $navigation) );
  205. // apply a filter after the output
  206. $out = apply_filters('ngg_gallery_output', $out, $picturelist);
  207. return $out;
  208. }
  209. /**
  210. * nggShowAlbum() - return a album based on the id
  211. *
  212. * @access public
  213. * @param int | string $albumID
  214. * @param string (optional) $template
  215. * @return the content
  216. */
  217. function nggShowAlbum($albumID, $template = 'extend') {
  218. // $_GET from wp_query
  219. $gallery = get_query_var('gallery');
  220. $album = get_query_var('album');
  221. // in the case somebody uses the '0', it should be 'all' to show all galleries
  222. $albumID = ($albumID == 0) ? 'all' : $albumID;
  223. // first look for gallery variable
  224. if (!empty( $gallery )) {
  225. if ( ($albumID != $album) && ($albumID != 'all') )
  226. return;
  227. // if gallery is is submit , then show the gallery instead
  228. $galleryID = (int) $gallery;
  229. $out = nggShowGallery($galleryID);
  230. return $out;
  231. }
  232. // lookup in the database
  233. $album = nggdb::find_album( $albumID );
  234. // still no success ? , die !
  235. if( !$album )
  236. return __('[Album not found]','nggallery');
  237. $mode = ltrim($mode, ',');
  238. if ( is_array($album->gallery_ids) )
  239. $out = nggCreateAlbum( $album->gallery_ids, $template, $album );
  240. $out = apply_filters( 'ngg_show_album_content', $out, $album->id );
  241. return $out;
  242. }
  243. /**
  244. * nggCreateAlbum()
  245. *
  246. * @access internal
  247. * @param array $galleriesID
  248. * @param string (optional) $template
  249. * @param object (optional) $album result from the db
  250. * @return the content
  251. */
  252. function nggCreateAlbum( $galleriesID, $template = 'extend', $album = 0) {
  253. // create a gallery overview div
  254. global $wpdb, $nggRewrite;
  255. // $_GET from wp_query
  256. $nggpage = get_query_var('nggpage');
  257. $ngg_options = nggGallery::get_option('ngg_options');
  258. //this option can currently only set via the custom fields
  259. $maxElement = (int) $ngg_options['galPagedGalleries'];
  260. $sortorder = $galleriesID;
  261. $galleries = array();
  262. // get the galleries information
  263. foreach ($galleriesID as $i => $value)
  264. $galleriesID[$i] = addslashes($value);
  265. $unsort_galleries = $wpdb->get_results('SELECT * FROM '.$wpdb->nggallery.' WHERE gid IN (\''.implode('\',\'', $galleriesID).'\')', OBJECT_K);
  266. //TODO: Check this, problem exist when previewpic = 0
  267. //$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);
  268. // get the counter values
  269. $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);
  270. if ( is_array($picturesCounter) ) {
  271. foreach ($picturesCounter as $key => $value)
  272. $unsort_galleries[$key]->counter = $value->counter;
  273. }
  274. // get the id's of the preview images
  275. $imagesID = array();
  276. foreach ($unsort_galleries as $gallery_row)
  277. $imagesID[] = $gallery_row->previewpic;
  278. $albumPreview = $wpdb->get_results('SELECT pid, filename FROM '.$wpdb->nggpictures.' WHERE pid IN (\''.implode('\',\'', $imagesID).'\')', OBJECT_K);
  279. // re-order them and populate some
  280. foreach ($sortorder as $key) {
  281. $galleries[$key] = $unsort_galleries[$key];
  282. // add the file name and the link
  283. if ($galleries[$key]->previewpic != 0) {
  284. $galleries[$key]->previewname = $albumPreview[$galleries[$key]->previewpic]->filename;
  285. $galleries[$key]->previewurl = get_option ('siteurl').'/' . $galleries[$key]->path . '/thumbs/thumbs_' . $albumPreview[$galleries[$key]->previewpic]->filename;
  286. } else {
  287. $first_image = $wpdb->get_row('SELECT * FROM '. $wpdb->nggpictures .' WHERE exclude != 1 AND galleryid = '. $key .' ORDER by pid DESC limit 0,1');
  288. $galleries[$key]->previewpic = $first_image->pid;
  289. $galleries[$key]->previewname = $first_image->filename;
  290. $galleries[$key]->previewurl = get_option ('siteurl') . '/' . $galleries[$key]->path . '/thumbs/thumbs_' . $first_image->filename;
  291. }
  292. // choose between variable and page link
  293. if ($ngg_options['galNoPages']) {
  294. $args['album'] = $album->id;
  295. $args['gallery'] = $key;
  296. $args['nggpage'] = false;
  297. $galleries[$key]->pagelink = $nggRewrite->get_permalink($args);
  298. } else {
  299. $galleries[$key]->pagelink = get_permalink( $galleries[$key]->pageid );
  300. }
  301. // description can contain HTML tags
  302. $galleries[$key]->galdesc = html_entity_decode ( stripslashes($galleries[$key]->galdesc) ) ;
  303. }
  304. // check for page navigation
  305. if ($maxElement > 0) {
  306. if ( !is_home() || $pageid == get_the_ID() ) {
  307. $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
  308. }
  309. else $page = 1;
  310. $start = $offset = ( $page - 1 ) * $maxElement;
  311. $total = count($galleries);
  312. // remove the element if we didn't start at the beginning
  313. if ($start > 0 ) array_splice($galleries, 0, $start);
  314. // return the list of images we need
  315. array_splice($galleries, $maxElement);
  316. $navigation = nggGallery::create_navigation($page, $total, $maxElement);
  317. } else {
  318. $navigation = '<div class="ngg-clear">&nbsp;</div>';
  319. }
  320. // if sombody didn't enter any template , take the extend version
  321. $filename = ( empty($template) ) ? 'album-extend' : 'album-' . $template ;
  322. // create the output
  323. $out = nggGallery::capture ( $filename, array ('album' => $album, 'galleries' => $galleries, 'pagination' => $navigation) );
  324. return $out;
  325. }
  326. /**
  327. * nggShowImageBrowser()
  328. *
  329. * @access public
  330. * @param int|string $galleryID or gallery name
  331. * @param string $template (optional) name for a template file, look for imagebrowser-$template
  332. * @return the content
  333. */
  334. function nggShowImageBrowser($galleryID, $template = '') {
  335. global $wpdb;
  336. $ngg_options = nggGallery::get_option('ngg_options');
  337. //Set sort order value, if not used (upgrade issue)
  338. $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
  339. $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';
  340. // get the pictures
  341. $picturelist = nggdb::get_ids_from_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);
  342. if ( is_array($picturelist) )
  343. $out = nggCreateImageBrowser($picturelist, $template);
  344. else
  345. $out = __('[Gallery not found]','nggallery');
  346. $out = apply_filters('ngg_show_imagebrowser_content', $out, $galleryID);
  347. return $out;
  348. }
  349. /**
  350. * nggCreateImageBrowser()
  351. *
  352. * @access internal
  353. * @param array $picarray with pid
  354. * @param string $template (optional) name for a template file, look for imagebrowser-$template
  355. * @return the content
  356. */
  357. function nggCreateImageBrowser($picarray, $template = '') {
  358. global $nggRewrite;
  359. require_once( dirname (__FILE__) . '/lib/meta.php' );
  360. // $_GET from wp_query
  361. $pid = get_query_var('pid');
  362. if ( !is_array($picarray) )
  363. $picarray = array($picarray);
  364. $total = count($picarray);
  365. // look for gallery variable
  366. if ( !empty( $pid )) {
  367. $act_pid = (int) $pid;
  368. } else {
  369. reset($picarray);
  370. $act_pid = current($picarray);
  371. }
  372. // get ids for back/next
  373. $key = array_search($act_pid,$picarray);
  374. if (!$key) {
  375. $act_pid = reset($picarray);
  376. $key = key($picarray);
  377. }
  378. $back_pid = ( $key >= 1 ) ? $picarray[$key-1] : end($picarray) ;
  379. $next_pid = ( $key < ($total-1) ) ? $picarray[$key+1] : reset($picarray) ;
  380. // get the picture data
  381. $picture = nggdb::find_image($act_pid);
  382. // if we didn't get some data, exit now
  383. if ($picture == null)
  384. return;
  385. // add more variables for render output
  386. $picture->href_link = $picture->get_href_link();
  387. $picture->previous_image_link = $nggRewrite->get_permalink(array ('pid' => $back_pid));
  388. $picture->next_image_link = $nggRewrite->get_permalink(array ('pid' => $next_pid));
  389. $picture->number = $key + 1;
  390. $picture->total = $total;
  391. $picture->linktitle = htmlentities(stripslashes($picture->description));
  392. $picture->alttext = html_entity_decode(stripslashes($picture->alttext));
  393. $picture->description = html_entity_decode(stripslashes($picture->description));
  394. // let's get the meta data
  395. $meta = new nggMeta($picture->imagePath);
  396. $exif = $meta->get_EXIF();
  397. $iptc = $meta->get_IPTC();
  398. $xmp = $meta->get_XMP();
  399. // look for imagebrowser-$template.php or pure imagebrowser.php
  400. $filename = ( empty($template) ) ? 'imagebrowser' : 'imagebrowser-' . $template;
  401. // create the output
  402. $out = nggGallery::capture ( $filename , array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp) );
  403. return $out;
  404. }
  405. /**
  406. * nggSinglePicture() - show a single picture based on the id
  407. *
  408. * @access public
  409. * @param int $imageID, db-ID of the image
  410. * @param int (optional) $width, width of the image
  411. * @param int (optional) $height, height of the image
  412. * @param string $mode (optional) could be none, watermark, web20
  413. * @param string $float (optional) could be none, left, right
  414. * @param string $template (optional) name for a template file, look for singlepic-$template
  415. * @param string $caption (optional) additional caption text
  416. * @return the content
  417. */
  418. function nggSinglePicture($imageID, $width = 250, $height = 250, $mode = '', $float = '' , $template = '', $caption = '') {
  419. global $post;
  420. $ngg_options = nggGallery::get_option('ngg_options');
  421. // get picturedata
  422. $picture = nggdb::find_image($imageID);
  423. // if we didn't get some data, exit now
  424. if ($picture == null)
  425. return __('[SinglePic not found]','nggallery');
  426. // add float to img
  427. switch ($float) {
  428. case 'left':
  429. $float =' ngg-left';
  430. break;
  431. case 'right':
  432. $float =' ngg-right';
  433. break;
  434. case 'center':
  435. $float =' ngg-center';
  436. break;
  437. default:
  438. $float ='';
  439. break;
  440. }
  441. // clean mode if needed
  442. $mode = ( eregi('web20|watermark', $mode) ) ? $mode : '';
  443. // check fo cached picture
  444. if ( ($ngg_options['imgCacheSinglePic']) && ($post->post_status == 'publish') )
  445. $picture->thumbnailURL = $picture->cached_singlepic_file($width, $height, $mode );
  446. else
  447. $picture->thumbnailURL = NGGALLERY_URLPATH . 'nggshow.php?pid=' . $imageID . '&amp;width=' . $width . '&amp;height=' . $height . '&amp;mode=' . $mode;
  448. // add more variables for render output
  449. $picture->href_link = $picture->get_href_link();
  450. $picture->alttext = html_entity_decode(stripslashes($picture->alttext));
  451. $picture->description = html_entity_decode(stripslashes($picture->description));
  452. $picture->linktitle = htmlentities(stripslashes($picture->description));
  453. $picture->classname = 'ngg-singlepic'. $float;
  454. $picture->thumbcode = $picture->get_thumbcode( 'singlepic' . $imageID);
  455. $picture->height = (int) $height;
  456. $picture->width = (int) $width;
  457. $picture->caption = $caption;
  458. // let's get the meta data
  459. $meta = new nggMeta($picture->imagePath);
  460. $exif = $meta->get_EXIF();
  461. $iptc = $meta->get_IPTC();
  462. $xmp = $meta->get_XMP();
  463. // look for singlepic-$template.php or pure singlepic.php
  464. $filename = ( empty($template) ) ? 'singlepic' : 'singlepic-' . $template;
  465. // create the output
  466. $out = nggGallery::capture ( $filename, array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp) );
  467. $out = apply_filters('ngg_show_singlepic_content', $out, $picture );
  468. return $out;
  469. }
  470. /**
  471. * nggShowGalleryTags() - create a gallery based on the tags
  472. *
  473. * @access public
  474. * @param string $taglist list of tags as csv
  475. * @return the content
  476. */
  477. function nggShowGalleryTags($taglist) {
  478. // $_GET from wp_query
  479. $pid = get_query_var('pid');
  480. $pageid = get_query_var('pageid');
  481. // get now the related images
  482. $picturelist = nggTags::find_images_for_tags($taglist , 'ASC');
  483. // look for ImageBrowser if we have a $_GET('pid')
  484. if ( $pageid == get_the_ID() || !is_home() )
  485. if (!empty( $pid )) {
  486. foreach ($picturelist as $picture) {
  487. $picarray[] = $picture->pid;
  488. }
  489. $out = nggCreateImageBrowser($picarray);
  490. return $out;
  491. }
  492. // go on if not empty
  493. if ( empty($picturelist) )
  494. return;
  495. // show gallery
  496. if ( is_array($picturelist) )
  497. $out = nggCreateGallery($picturelist, false);
  498. $out = apply_filters('ngg_show_gallery_tags_content', $out, $taglist);
  499. return $out;
  500. }
  501. /**
  502. * nggShowRelatedGallery() - create a gallery based on the tags
  503. *
  504. * @access public
  505. * @param string $taglist list of tags as csv
  506. * @param integer $maxImages (optional) limit the number of images to show
  507. * @return the content
  508. */
  509. function nggShowRelatedGallery($taglist, $maxImages = 0) {
  510. $ngg_options = nggGallery::get_option('ngg_options');
  511. // get now the related images
  512. $picturelist = nggTags::find_images_for_tags($taglist, 'RAND');
  513. // go on if not empty
  514. if ( empty($picturelist) )
  515. return;
  516. // cut the list to maxImages
  517. if ( $maxImages > 0 )
  518. array_splice($picturelist, $maxImages);
  519. // *** build the gallery output
  520. $out = '<div class="ngg-related-gallery">';
  521. foreach ($picturelist as $picture) {
  522. // get the effect code
  523. $thumbcode = $picture->get_thumbcode( __('Related images for', 'nggallery') . ' ' . get_the_title());
  524. $out .= '<a href="' . $picture->imageURL . '" title="' . stripslashes($picture->description) . '" ' . $thumbcode . ' >';
  525. $out .= '<img title="' . stripslashes($picture->alttext) . '" alt="' . stripslashes($picture->alttext) . '" src="' . $picture->thumbURL . '" />';
  526. $out .= '</a>' . "\n";
  527. }
  528. $out .= '</div>' . "\n";
  529. $out = apply_filters('ngg_show_related_gallery_content', $out, $taglist);
  530. return $out;
  531. }
  532. /**
  533. * nggShowAlbumTags() - create a gallery based on the tags
  534. *
  535. * @access public
  536. * @param string $taglist list of tags as csv
  537. * @return the content
  538. */
  539. function nggShowAlbumTags($taglist) {
  540. global $wpdb, $nggRewrite;
  541. // $_GET from wp_query
  542. $tag = get_query_var('gallerytag');
  543. $pageid = get_query_var('pageid');
  544. // look for gallerytag variable
  545. if ( $pageid == get_the_ID() || !is_home() ) {
  546. if (!empty( $tag )) {
  547. // 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';
  548. $slug = attribute_escape( $tag );
  549. $tagname = $wpdb->get_var( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE slug = %s", $slug ) );
  550. $out = '<div id="albumnav"><span><a href="' . get_permalink() . '" title="' . __('Overview', 'nggallery') .' ">'.__('Overview', 'nggallery').'</a> | '.$tagname.'</span></div>';
  551. $out .= nggShowGalleryTags($slug);
  552. return $out;
  553. }
  554. }
  555. // get now the related images
  556. $picturelist = nggTags::get_album_images($taglist);
  557. // go on if not empty
  558. if ( empty($picturelist) )
  559. return;
  560. // re-structure the object that we can use the standard template
  561. foreach ($picturelist as $key => $picture) {
  562. $picturelist[$key]->previewpic = $picture->pid;
  563. $picturelist[$key]->previewname = $picture->filename;
  564. $picturelist[$key]->previewurl = get_option ('siteurl') . '/' . $picture->path . '/thumbs/thumbs_' . $picture->filename;
  565. $picturelist[$key]->counter = $picture->count;
  566. $picturelist[$key]->title = $picture->name;
  567. $picturelist[$key]->pagelink = $nggRewrite->get_permalink( array('gallerytag'=>$picture->slug) );
  568. }
  569. //TODO: Add pagination later
  570. $navigation = '<div class="ngg-clear">&nbsp;</div>';
  571. // create the output
  572. $out = nggGallery::capture ('album-compact', array ('album' => 0, 'galleries' => $picturelist, 'pagination' => $navigation) );
  573. $out = apply_filters('ngg_show_album_tags_content', $out, $taglist);
  574. return $out;
  575. }
  576. /**
  577. * nggShowRelatedImages() - return related images based on category or tags
  578. *
  579. * @access public
  580. * @param string $type could be 'tags' or 'category'
  581. * @param integer $maxImages of images
  582. * @return the content
  583. */
  584. function nggShowRelatedImages($type = '', $maxImages = 0) {
  585. $ngg_options = nggGallery::get_option('ngg_options');
  586. if ($type == '') {
  587. $type = $ngg_options['appendType'];
  588. $maxImages = $ngg_options['maxImages'];
  589. }
  590. $sluglist = array();
  591. switch ($type) {
  592. case 'tags':
  593. if (function_exists('get_the_tags')) {
  594. $taglist = get_the_tags();
  595. if (is_array($taglist)) {
  596. foreach ($taglist as $tag) {
  597. $sluglist[] = $tag->slug;
  598. }
  599. }
  600. }
  601. break;
  602. case 'category':
  603. $catlist = get_the_category();
  604. if (is_array($catlist)) {
  605. foreach ($catlist as $cat) {
  606. $sluglist[] = $cat->category_nicename;
  607. }
  608. }
  609. break;
  610. }
  611. $sluglist = implode(',', $sluglist);
  612. $out = nggShowRelatedGallery($sluglist, $maxImages);
  613. return $out;
  614. }
  615. /**
  616. * Template function for theme authors
  617. *
  618. * @access public
  619. * @param string (optional) $type could be 'tags' or 'category'
  620. * @param integer (optional) $maxNumbers of images
  621. * @return void
  622. */
  623. function the_related_images($type = 'tags', $maxNumbers = 7) {
  624. echo nggShowRelatedImages($type, $maxNumbers);
  625. }
  626. ?>