tdiaz

nggfunctions.php

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