nggSinglePicture

NggSinglePicture() - show a single picture based on the id.

Description

nggSinglePicture( (int) $imageID, (int) $width = 250, (int) $height = 250, (string) $mode = '', (string) $float = '', (string) $template = '', (string) $caption = '', (string) $link = '' ); 

Parameters (8)

0. $imageid (int)
Db-ID of the image
1. $width — Optional. (int) => 250
$width, width of the image
2. $height — Optional. (int) => 250
$height, height of the image
3. $mode — Optional. (string) => ''
could be none, watermark, web20
4. $float — Optional. (string) => ''
could be none, left, right
5. $template — Optional. (string) => ''
name for a template file, look for singlepic-$template
6. $caption — Optional. (string) => ''
additional caption text
7. $link — Optional. (string) => ''
link to a other url instead the full image

Usage

  1. if ( !function_exists( 'nggSinglePicture' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextcellent-gallery/nggfunctions.php'; 
  3.  
  4. // db-ID of the image 
  5. $imageid = -1; 
  6.  
  7. // (optional) $width, width of the image 
  8. $width = 250; 
  9.  
  10. // (optional) $height, height of the image 
  11. $height = 250; 
  12.  
  13. // (optional) could be none, watermark, web20 
  14. $mode = ''; 
  15.  
  16. // (optional) could be none, left, right 
  17. $float = ''; 
  18.  
  19. // (optional) name for a template file, look for singlepic-$template 
  20. $template = ''; 
  21.  
  22. // (optional) additional caption text 
  23. $caption = ''; 
  24.  
  25. // (optional) link to a other url instead the full image 
  26. $link = ''; 
  27.  
  28. // NOTICE! Understand what this does before running. 
  29. $result = nggSinglePicture($imageid, $width, $height, $mode, $float, $template, $caption, $link); 
  30.  

Defined (1)

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

/nggfunctions.php  
  1. function nggSinglePicture($imageID, $width = 250, $height = 250, $mode = '', $float = '' , $template = '', $caption = '', $link = '') { 
  2. global $post; 
  3.  
  4. $ngg_options = nggGallery::get_option(ngg_options); 
  5.  
  6. // get picturedata 
  7. $picture = nggdb::find_image($imageID); 
  8.  
  9. // if we didn't get some data, exit now 
  10. if ($picture == null) 
  11. return __('[SinglePic not found]', 'nggallery'); 
  12.  
  13. // add float to img 
  14. switch ($float) { 
  15.  
  16. case 'left': 
  17. $float =' ngg-left'; 
  18. break; 
  19.  
  20. case 'right': 
  21. $float =' ngg-right'; 
  22. break; 
  23.  
  24. case 'center': 
  25. $float =' ngg-center'; 
  26. break; 
  27.  
  28. default: 
  29. $float =''; 
  30. break; 
  31.  
  32. // clean mode if needed 
  33. $mode = ( preg_match('/(web20|watermark)/i', $mode) ) ? $mode : ''; 
  34.  
  35. //let's initiate the url 
  36. $picture->thumbnailURL = false; 
  37.  
  38. // check fo cached picture 
  39. if ( $post->post_status == 'publish' ) 
  40. $picture->thumbnailURL = $picture->cached_singlepic_file($width, $height, $mode ); 
  41.  
  42. // if we didn't use a cached image then we take the on-the-fly mode 
  43. if (!$picture->thumbnailURL) 
  44. $picture->thumbnailURL = trailingslashit( home_url() ) . 'index.php?callback=image&pid=' . $imageID . '&width=' . $width . '&height=' . $height . '&mode=' . $mode; 
  45.  
  46. // add more variables for render output 
  47. $picture->imageURL = ( empty($link) ) ? $picture->imageURL : $link; 
  48. $picture->href_link = $picture->get_href_link(); 
  49. $picture->alttext = html_entity_decode( stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) ); 
  50. $picture->linktitle = htmlspecialchars( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  51. $picture->description = html_entity_decode( stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) ); 
  52. $picture->classname = 'ngg-singlepic'. $float; 
  53. $picture->thumbcode = $picture->get_thumbcode( 'singlepic' . $imageID); 
  54. $picture->height = (int) $height; 
  55. $picture->width = (int) $width; 
  56. $picture->caption = nggGallery::i18n($caption); 
  57.  
  58. // filter to add custom content for the output 
  59. $picture = apply_filters('ngg_image_object', $picture, $imageID); 
  60.  
  61. // let's get the meta data 
  62. $meta = new nggMeta($imageID); 
  63. $meta->sanitize(); 
  64. $exif = $meta->get_EXIF(); 
  65. $iptc = $meta->get_IPTC(); 
  66. $xmp = $meta->get_XMP(); 
  67. $db = $meta->get_saved_meta(); 
  68.  
  69. //if we get no exif information we try the database 
  70. $exif = ($exif == false) ? $db : $exif; 
  71.  
  72. // look for singlepic-$template.php or pure singlepic.php 
  73. $filename = ( empty($template) ) ? 'singlepic' : 'singlepic-' . $template; 
  74.  
  75. // create the output 
  76. $out = nggGallery::capture ( $filename, array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db) ); 
  77.  
  78. $out = apply_filters('ngg_show_singlepic_content', $out, $picture ); 
  79.  
  80. return $out;