WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: NextGEN Gallery] Adding a Search Bar (35 posts)

  1. Fyuvix
    Member
    Posted 4 years ago #

    Hello, I've found lots of variants on how people are adding the search capability to NextGen gallery but I've tried the coding and wound up with a syntax error. Here's some other links I've found relating to the search capabilities
    http://www.ikiru.ch/blog/2008/how-to-add-a-search-function-for-nextgen-gallery-wordpress-plugin
    And it's an ongoing topic here http://wordpress.org/support/topic/230905?replies=1#post-944495

    But I was just wondering if anyone has a single solid working piece of code for the latest 1.3 version of NextGen. I just want people to be able to search for character names in the search bar, and for the engine to find it in the TAGS, titles, and descriptions of NextGen images, comic pages, and posts. Please help!

  2. nancyb7
    Member
    Posted 4 years ago #

    I've been working really hard on this the last week or so, and I have code that works, as well as possible using a MySQL full-text search. I have relied heavily on the links given above, as well as others that they lead to.

    I am using NextGen Gallery 1.3.5 and WordPress 2.8.4. My shared server provides PHP 4.3.11 and MySQL 4.1.14.

    In the folder for the theme you are using, look for search.php and functions.php. If you don't have a search.php, you may use the index.php or you can make a search.php by copying the index.php.

    In your search.php file, insert this code at the place where you want the pictures to appear. In my search.php, I put it outside the "<?php if (have_posts()) : ?>" section because I wanted to search pictures whether or not there were posts found.

    Add this code to the end of functions.php. The code I found through other discussions was written for versions of NextGen Gallery prior to 1.0, or was poorly adapted for 1.0 and did not work correctly.

    My code searches a picture's file name, description, alternate text, and tags. I require an exact match for the first three because I was getting too many false positives using an inexact match. The tag search looks for tags that start with the keyword. You can easily change the exact/inexact match behavior to suit yourself: In the AGAINST phrase, use '$keywords' to require an exact match and '$keywords*' for an inexact match. The first part of the SELECT searches file name, description, and alternate text, and the second part searches the tags.

    This search method does have some peculiarities due to MySQL limitations: It will not find words that have less than 4 characters or are on this list. If you want to use short tags or ones on the list, I suggest adding enough characters to the end of the tag to remove the problem, then using an inexact search to find it. Remember that your visitors cannot see the actual tag on the picture. In one of the discussion threads, a person was having problems with the tag "elk"; this is why. He could get around the problem by using "elkk" or "elk_" or "elk2" or any number of other variations on "elk".

    Since the WordPress post search does not have these problems, I assume they use a different search method, but I do not know MySQL or WordPress well enough to figure out what it might be.

  3. nancyb7
    Member
    Posted 4 years ago #

    Here is the code that goes into the search.php file:

    <?php
    // Start of NextGen Gallery search
    if(is_search()) {
    	$search = $wp_query->get('s');
    	$keywords = preg_replace('/\+/',' ',$search);
    	if (function_exists ('ngg_get_search_pictures')) {  // function from functions.php
    		$nggpictures = ngg_get_search_pictures($keywords, ''); // put the number of pictures by row you want, if you don't want "4"
    
    		echo "<h2>Pictures</h2>";
    		if ($nggpictures) {
    			echo $nggpictures;
    			echo '<div class="clear">&nbsp;</div>';
    		}
    		else {
    			echo '<p>No pictures were found.</p>';
    		}
    	}
    }
    // End of NextGen Gallery search
    ?>

    And here is the code to add to the functions.php file:

    <?php
    ## Function to do search on gallery pics from NextGen Gallery plugin
    ##
    ## 2 vars : 	(1) $keywords (usually coming from the standard search query from wordpress)
    ##		(2) $numberPicCol (number of pic by row, if null it takes 4 )
    function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
    	global $wpdb;
    //	$count=1;
    //	if (!$numberPicRow) { $numberPicRow = "4"; }
    
    	$nngquery = "
    				SELECT pid,description,alttext
    				FROM wp_ngg_pictures
    				WHERE MATCH (description, filename, alttext) AGAINST ('$keywords' IN BOOLEAN MODE)
    				AND exclude = '0'
    ## start of tags code
    				UNION
    				SELECT pid,wp_ngg_pictures.description,alttext
    				FROM wp_ngg_pictures, wp_terms, wp_term_taxonomy, wp_term_relationships
    				WHERE wp_terms.term_id = wp_term_taxonomy.term_id and
    					wp_term_taxonomy.taxonomy = 'ngg_tag' and
    					wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id and
    					wp_term_relationships.object_id = wp_ngg_pictures.pid and
    				MATCH (wp_terms.name) AGAINST ('$keywords*' IN BOOLEAN MODE)
    				AND exclude = '0'
    ## end of tags code
    				";
    	$pictures = $wpdb->get_results($nngquery, ARRAY_A);
    
    	if ($pictures) foreach($pictures as $pic) { 
    
    		$out .= '<div class="ngg-gallery-thumbnail">';
    		$out .= '<a href="'.nggGallery::get_image_url($pic[pid]).'" title="'.stripslashes($pic[description]).'" class="thickbox" rel="singlepic'.$pic[pid].'">';
    		$out .=  '<img src="'.nggGallery::get_thumbnail_url($pic[pid]).'" alt="'.stripslashes($pic[alttext]).'" title="'.stripslashes($pic[alttext]).'" />';
    		$out .=  "</a></div>\n";
    // pictures use float left, so don't need the code that outputs a <br />
    //				if ($count == 0) {
    //				$out .= "<br />";
    //				}
    //				++$count;
    //				$count%=$numberPicRow;
    	}
    	return $out;
    };
    ?>

    If you don't want the description, file name, and alternate text to all be searched, just remove the appropriate field(s) from
    WHERE MATCH (description, filename, alttext) AGAINST ('$keywords' IN BOOLEAN MODE)

    I commented out some code that I copied from Psykotik's post because I didn't need it, but didn't want to lose the way the code had originally been written.

    To search tags on posts we use this plugin https://redmine.sproutventure.com/projects/show/search-everything.

  4. maggymae
    Member
    Posted 4 years ago #

    hi nancyb7,

    that's what I'm looking for!!!
    But I don't know what I'm doing wrong - it doesn't work in my Gallery.

    Could you look and maybe tell me whats wrong??!!!

    thanks in advance!

    maggy
    http://www.oesterreichbilder.at

  5. maggymae
    Member
    Posted 4 years ago #

    ok - I found it. now it works.

    maggy

  6. gasjeerbij
    Member
    Posted 4 years ago #

    isn't it possible to get the admin search function working on the frontend of the website? That search function works perfect.

    I am using almost the same code as above for my site some time now.
    But if people for example search on NEXTGEN GALLERY, they get both the results for the word NEXTGEN and GALLERY. And i know u can use ", but most of the people browsing the internet don't know that. So what i want is that the results show only pictures that match both NEXTGEN and GALLERY.

    Maybe someone has a solution to this?

  7. nancyb7
    Member
    Posted 4 years ago #

    Hi gasjeerbij,
    I think you would have to modify your keyword string to put "+" in front of both words. See http://dev.mysql.com/doc/refman/4.1/en/fulltext-boolean.html.

  8. gasjeerbij
    Member
    Posted 4 years ago #

    Hi nancyb7, i allready saw that page, but it didn't really help me since im not really an expert in mysql.

    What i basicly want is a phrase search without the user have to put te text manualy in "example text"...

  9. nancyb7
    Member
    Posted 4 years ago #

    gasjeerbij,
    Actually, you use PHP to modify the keyword string, and the code to put a "+" in front of each word could get rather involved. You'd have to break the string into words, put the "+" in front of each word, then put them back into one string. But if you just want to make it a phrase search, try
    $keywords = '"' . $keywords . '"';
    near the beginning of the function, any place before the $nngquery = " line. Note: I have not tested this code.

    In the code that I copied from Psykotik's post, the code that you put into search.php removes \, +, and / from the keyword string by replacing them with blanks. I'm not sure of the reason for this and left it in. You could try modifying this line to allow the visitor more control over their search. The line is
    $keywords = preg_replace('/\+/',' ',$search);
    You cannot take it out completely. If you want to eliminate all the character changes, replace the line with this one
    $keywords = $search;

  10. gasjeerbij
    Member
    Posted 4 years ago #

    thanks alot, thats what i wanted!

  11. site2shan
    Member
    Posted 4 years ago #

    Does anyone know how we can get this to return a result of galleries, instead of single images? We would like the search function to search the gallery description and then return a result of links to galleries that fall within the search parameters. Thanks for any help!

  12. bgardner@niermannweeks.com
    Member
    Posted 4 years ago #

    Thanks for the great code for my search feature.

    My question is why the code is overriding my theme's color palette and resetting them to the theme default colors?

    I'm very inexperienced with coding, and really need specific help to overcome this problem. Thanks so much.

  13. bgardner@niermannweeks.com
    Member
    Posted 4 years ago #

    Nevermind guys, I got it.

  14. Steve S
    Member
    Posted 4 years ago #

    I have my image search working, but I need to limit the search to a few specific galleries. Does anyone have a way to do this?

    I need to either specify which galleries to search, or maybe even add a specific keyword to all the images in those galleries, and then invisibly add that keyword to the user's search term.

    Any ideas?

  15. FotoAndy
    Member
    Posted 4 years ago #

    Thanks to everyone who's worked this far to get this searching to play nice with WordPress search.

    I've implemented the code and run a search (both wih and without quoted), and my only reselt is an empty page with the text:

    no database caching for now!

    Any thoughts? Do I simply need to wait for the cache to build up?

  16. FotoAndy
    Member
    Posted 4 years ago #

    Edit: "my only result...".

    Word Nerd.

  17. FotoAndy
    Member
    Posted 4 years ago #

    Please help re: 'no database caching for now'...

  18. gasjeerbij
    Member
    Posted 4 years ago #

    It's sad that this search function is not working so good as the one in nextgen admin, wich gives perfect results.
    I hope alex will add this searchfunction soon to the frontend of this plugin!

  19. FotoAndy
    Member
    Posted 4 years ago #

    @gasjeerbi: Agreed, and seconded as a desired option! :)

  20. FotoAndy
    Member
    Posted 4 years ago #

    Sorted my "no database caching...", never mind.

    My search works (my site), although can't get pagination going, having trouble finding the right snippet of code to get it.

    Worth noting if doing this little hack:

    on functions.php, be sure to change

    class="thickbox"
    if you use another s/show option. Otherwise it's white window and teeny picture.

    I lost an hour of my life to that fact, hope it saves someone the same.

  21. FotoAndy
    Member
    Posted 4 years ago #

    To second myself (out of desperation), help on getting pagination would be greatly appreciated.

  22. andythology
    Member
    Posted 4 years ago #

    Do you guys have this issue of thumbnails showing in search result is not the same as when you viewing gallery? The major concern is the size, it should be uniform as per the gallery view.

    I am helping a friend to sort this out:
    the search result: http://www.wow-couture.com/?s=Cheongsam
    the Gallery view: http://www.wow-couture.com/nggallery/page-11/album-1/gallery-1/

    Kindly advise. thanks.

  23. Achim Meurer
    Member
    Posted 4 years ago #

    Hi

    do anybody know, why this code does'nt work with my gallery? I'm using WP 2.8.4, nextGen 1.3.6, PHP 5.2.11.

    I insert in the title, description alt and tags some words but still no search results, eg. "standbild".

    Here's the site: http://infohund.de

    I read all the post in the forum. Everybody's pointing to nearly the same peace of code. But it's not working in my gallery.

    What is wrong? Anybody an idea?

    1000000000000 Thanx!
    Greetings from Austria
    Achim

  24. I_Know_God
    Member
    Posted 4 years ago #

    this is completely awesome if i can get it working, ive been looking at this code for a very long time and im not having any luck getting it working. my ngg picture search comes back 100% of the time with "no results"

    im using the code linked at the top with Version 1.4.3 and wp 2.8.6
    ill post the custom code added
    search.php

    <?php
    // Start of NextGen Gallery search
    if(is_search()) {
    	$search = $wp_query->get('s');
    	$keywords = preg_replace('/\+/',' ',$search);
    	if (function_exists ('ngg_get_search_pictures')) {  // function from functions.php
    		$nggpictures = ngg_get_search_pictures($keywords, ''); // put the number of pictures by row you want, if you don't want "4"
    
    		echo "<h2 class='pagetitle'>Pictures</h2>";
    		if ($nggpictures) {
    			echo $nggpictures;
    			echo '<div class="clear">&nbsp;</div>';
    		}
    		else {
    			echo '<p>No pictures were found.</p>';
    		}
    	}
    }
    // End of NextGen Gallery search
    ?>

    FUNCTIONS.php

    ## Function to do search on gallery pics from NextGen Gallery plugin
    ##
    ## 2 vars : 	(1) $keywords (usually coming from the standard search query from wordpress)
    ##		(2) $numberPicCol (number of pic by row, if null it takes 4 )
    function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
    	global $wpdb;
    //	$count=1;
    //	if (!$numberPicRow) { $numberPicRow = "4"; }
    
    	$nngquery = "
    				SELECT pid,description,alttext
    				FROM wp_ngg_pictures
    				WHERE MATCH (description, filename, alttext) AGAINST ('$keywords' IN BOOLEAN MODE)
    				AND exclude = '0'
    ## start of tags code
    				UNION
    				SELECT pid,wp_ngg_pictures.description,alttext
    				FROM wp_ngg_pictures, wp_terms, wp_term_taxonomy, wp_term_relationships
    				WHERE wp_terms.term_id = wp_term_taxonomy.term_id and
    					wp_term_taxonomy.taxonomy = 'ngg_tag' and
    					wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id and
    					wp_term_relationships.object_id = wp_ngg_pictures.pid and
    				MATCH (wp_terms.name) AGAINST ('$keywords*' IN BOOLEAN MODE)
    				AND exclude = '0'
    ## end of tags code
    				";
    	$pictures = $wpdb->get_results($nngquery, ARRAY_A);
    
    	if ($pictures) foreach($pictures as $pic) { 
    
    		$out .= '<div class="ngg-gallery-thumbnail">';
    		$out .= '<a href="'.nggGallery::get_image_url($pic[pid]).'" title="'.stripslashes($pic[description]).'" class="thickbox" rel="singlepic'.$pic[pid].'">';
    		$out .=  '<img src="'.nggGallery::get_thumbnail_url($pic[pid]).'" alt="'.stripslashes($pic[alttext]).'" title="'.stripslashes($pic[alttext]).'" />';
    		$out .=  "</a></div>\n";
    // pictures use float left, so don't need the code that outputs a <br />
    //				if ($count == 0) {
    //				$out .= "<br />";
    //				}
    //				++$count;
    //				$count%=$numberPicRow;
    	}
    	return $out;
    };

    please help.

  25. I_Know_God
    Member
    Posted 4 years ago #

    I was able to figure this out, the problem was that my tables didn't support FULLTEXT indexes, had to go in and try the SQL directly

  26. cvenegasf
    Member
    Posted 4 years ago #

    Hey I_Know_God, can you help me with this?? I don't know how to add the search feature I have Version 1.4.3 and wp 2.8.6 also. Thanks for any help.

  27. katn
    Member
    Posted 4 years ago #

    Just a heads up for anyone using Lytebox and adding this search function. I had to change the functions.php section as mentioned above from

    " class="thickbox" rel="singlepic'.$pic[pid].'">' "

    to

    " class="singlepic" rel="lytebox'.$pic[pid].'"> "
    to get the lytebox to work.

    Not sure if that's correct code (I can't code I'm just using trial and error!) but it works on my site. :)

    Thanks for all the help fellow wordpressers!!

  28. Cerafil
    Member
    Posted 4 years ago #

    First of all.. Admins.. If you see a way to Shorten my post.
    Pls do so. I got nu clue what I should Copy and not.

    Hello Everybody,

    Well I have to say reading trough this I find myself in a world of unknown language. I want to set up my NextGen Gallery to the point people will be able to search trough the images.

    While reading this post I tried to find the "search.php" but i cant find it @ all. And functions.php is way to complicated/expanded for me to adjust.

    I will post both function area's I found. Please tell me what I need to alter. (Also tell me if I by accident post any information I wouldn;t like to share)

    Thanks on forehand.

    <?php

    if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }

    /**
    * Return a script for the Imagerotator flash slideshow. Can be used in any tmeplate with <?php echo nggShowSlideshow($galleryID, $width, $height) ?>
    * Require the script swfobject.js in the header or footer
    *
    * @access public
    * @param integer $galleryID ID of the gallery
    * @param integer $irWidth Width of the flash container
    * @param integer $irHeight Height of the flash container
    * @return the content
    */
    function nggShowSlideshow($galleryID, $width, $height) {

    require_once (dirname (__FILE__).'/lib/swfobject.php');

    $ngg_options = nggGallery::get_option('ngg_options');

    // remove media file from RSS feed
    if ( is_feed() ) {
    $out = '[' . nggGallery::i18n($ngg_options['galTextSlide']) . ']';
    return $out;
    }

    // If the Imagerotator didn't exist, skip the output
    if ( NGGALLERY_IREXIST == false )
    return;

    if (empty($width) ) $width = (int) $ngg_options['irWidth'];
    if (empty($height)) $height = (int) $ngg_options['irHeight'];

    // init the flash output
    $swfobject = new swfobject( $ngg_options['irURL'] , 'so' . $galleryID, $width, $height, '7.0.0', 'false');

    $swfobject->message = '<p>'. __('The Flash Player and a browser with Javascript support are needed..', 'nggallery').'</p>';
    $swfobject->add_params('wmode', 'opaque');
    $swfobject->add_params('allowfullscreen', 'true');
    $swfobject->add_params('bgcolor', $ngg_options['irScreencolor'], '000000', 'string', '#');
    $swfobject->add_attributes('styleclass', 'slideshow');
    $swfobject->add_attributes('name', 'so' . $galleryID);

    // adding the flash parameter
    $swfobject->add_flashvars( 'file', urlencode (get_option ('siteurl') . '/' . 'index.php?slideshow=true&gid=' . $galleryID ) );
    $swfobject->add_flashvars( 'shuffle', $ngg_options['irShuffle'], 'true', 'bool');
    $swfobject->add_flashvars( 'linkfromdisplay', $ngg_options['irLinkfromdisplay'], 'false', 'bool');
    $swfobject->add_flashvars( 'shownavigation', $ngg_options['irShownavigation'], 'true', 'bool');
    $swfobject->add_flashvars( 'showicons', $ngg_options['irShowicons'], 'true', 'bool');
    $swfobject->add_flashvars( 'kenburns', $ngg_options['irKenburns'], 'false', 'bool');
    $swfobject->add_flashvars( 'overstretch', $ngg_options['irOverstretch'], 'false', 'string');
    $swfobject->add_flashvars( 'rotatetime', $ngg_options['irRotatetime'], 5, 'int');
    $swfobject->add_flashvars( 'transition', $ngg_options['irTransition'], 'random', 'string');
    $swfobject->add_flashvars( 'backcolor', $ngg_options['irBackcolor'], 'FFFFFF', 'string', '0x');
    $swfobject->add_flashvars( 'frontcolor', $ngg_options['irFrontcolor'], '000000', 'string', '0x');
    $swfobject->add_flashvars( 'lightcolor', $ngg_options['irLightcolor'], '000000', 'string', '0x');
    $swfobject->add_flashvars( 'screencolor', $ngg_options['irScreencolor'], '000000', 'string', '0x');
    if ($ngg_options['irWatermark'])
    $swfobject->add_flashvars( 'logo', $ngg_options['wmPath'], '', 'string');
    $swfobject->add_flashvars( 'audio', $ngg_options['irAudio'], '', 'string');
    $swfobject->add_flashvars( 'width', $width, '260');
    $swfobject->add_flashvars( 'height', $height, '320');
    // create the output
    $out = '<div class="slideshow">' . $swfobject->output() . '</div>';
    // add now the script code
    $out .= "\n".'<script type="text/javascript" defer="defer">';
    if ($ngg_options['irXHTMLvalid']) $out .= "\n".'<!--';
    if ($ngg_options['irXHTMLvalid']) $out .= "\n".'//<![CDATA[';
    $out .= $swfobject->javascript();
    if ($ngg_options['irXHTMLvalid']) $out .= "\n".'//]]>';
    if ($ngg_options['irXHTMLvalid']) $out .= "\n".'-->';
    $out .= "\n".'</script>';

    $out = apply_filters('ngg_show_slideshow_content', $out);

    return $out;
    }

    /**
    * nggShowGallery() - return a gallery
    *
    * @access public
    * @param int $galleryID
    * @param string $template (optional) name for a template file, look for gallery-$template
    * @param int $images (optional) number of images per page
    * @return the content
    */
    function nggShowGallery( $galleryID, $template = '', $images = false ) {

    global $nggRewrite;

    $ngg_options = nggGallery::get_option('ngg_options');
    $galleryID = (int) $galleryID;

    //Set sort order value, if not used (upgrade issue)
    $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
    $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';

    // get gallery values
    $picturelist = nggdb::get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);

    if ( !$picturelist )
    return __('[Gallery not found]','nggallery');

    // $_GET from wp_query
    $show = get_query_var('show');
    $pid = get_query_var('pid');
    $pageid = get_query_var('pageid');

    // set $show if slideshow first
    if ( empty( $show ) AND ($ngg_options['galShowOrder'] == 'slide')) {
    if ( is_home() )
    $pageid = get_the_ID();

    $show = 'slide';
    }

    // go on only on this page
    if ( !is_home() || $pageid == get_the_ID() ) {

    // 1st look for ImageBrowser link
    if ( !empty($pid) && $ngg_options['galImgBrowser'] && ($template != 'carousel') ) {
    $out = nggShowImageBrowser( $galleryID, $template );
    return $out;
    }

    // 2nd look for slideshow
    if ( $show == 'slide' ) {
    $args['show'] = "gallery";
    $out = '<div class="ngg-galleryoverview">';
    $out .= '<div class="slideshowlink">get_permalink($args) . '">'.nggGallery::i18n($ngg_options['galTextGallery']).'</div>';
    $out .= nggShowSlideshow($galleryID, $ngg_options['irWidth'], $ngg_options['irHeight']);
    $out .= '</div>'."\n";
    $out .= '<div class="ngg-clear"></div>'."\n";
    return $out;
    }
    }

    // get all picture with this galleryid
    if ( is_array($picturelist) )
    $out = nggCreateGallery($picturelist, $galleryID, $template, $images);

    $out = apply_filters('ngg_show_gallery_content', $out, intval($galleryID));
    return $out;
    }

    /**
    * Build a gallery output
    *
    * @access internal
    * @param array $picturelist
    * @param bool $galleryID, if you supply a gallery ID, you can add a slideshow link
    * @param string $template (optional) name for a template file, look for gallery-$template
    * @param int $images (optional) number of images per page
    * @return the content
    */
    function nggCreateGallery($picturelist, $galleryID = false, $template = '', $images = false) {
    global $nggRewrite;

    $ngg_options = nggGallery::get_option('ngg_options');

    //the shortcode parameter will override global settings, TODO: rewrite this to a class
    $ngg_options['galImages'] = ( $images === false ) ? $ngg_options['galImages'] : (int) $images;

    $current_pid = false;

    // $_GET from wp_query
    $nggpage = get_query_var('nggpage');
    $pageid = get_query_var('pageid');
    $pid = get_query_var('pid');

    // we need to know the current page id
    $current_page = (get_the_ID() == false) ? 0 : get_the_ID();

    if ( !is_array($picturelist) )
    $picturelist = array($picturelist);

    // Populate galleries values from the first image
    $first_image = current($picturelist);
    $gallery = new stdclass;
    $gallery->ID = (int) $galleryID;
    $gallery->show_slideshow = false;
    $gallery->name = stripslashes ( $first_image->name );
    $gallery->title = stripslashes( $first_image->title );
    $gallery->description = html_entity_decode(stripslashes( $first_image->galdesc));
    $gallery->pageid = $first_image->pageid;
    $gallery->anchor = 'ngg-gallery-' . $galleryID . '-' . $current_page;
    reset($picturelist);

    $maxElement = $ngg_options['galImages'];
    $thumbwidth = $ngg_options['thumbwidth'];
    $thumbheight = $ngg_options['thumbheight'];

    // fixed width if needed
    $gallery->columns = intval($ngg_options['galColumns']);
    $gallery->imagewidth = ($gallery->columns > 0) ? 'style="width:' . floor(100/$gallery->columns) . '%;"' : '';

    // obsolete in V1.4.0, but kept for compat reason
    // pre set thumbnail size, from the option, later we look for meta data.
    $thumbsize = ($ngg_options['thumbfix']) ? $thumbsize = 'width="' . $thumbwidth . '" height="'.$thumbheight . '"' : '';

    // show slideshow link
    if ($galleryID) {
    if (($ngg_options['galShowSlide']) AND (NGGALLERY_IREXIST)) {
    $gallery->show_slideshow = true;
    $gallery->slideshow_link = $nggRewrite->get_permalink(array ( 'show' => 'slide') );
    $gallery->slideshow_link_text = nggGallery::i18n($ngg_options['galTextSlide']);
    }

    if ($ngg_options['usePicLens']) {
    $gallery->show_piclens = true;
    $gallery->piclens_link = "javascript:PicLensLite.start({feedUrl:'" . htmlspecialchars( nggMediaRss::get_gallery_mrss_url($gallery->ID) ) . "'});";
    }
    }

    // check for page navigation
    if ($maxElement > 0) {

    if ( !is_home() || $pageid == $current_page )
    $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
    else
    $page = 1;

    $start = $offset = ( $page - 1 ) * $maxElement;

    $total = count($picturelist);

    //we can work with display:hidden for some javascript effects
    if (!$ngg_options['galHiddenImg']){
    // remove the element if we didn't start at the beginning
    if ($start > 0 )
    array_splice($picturelist, 0, $start);

    // return the list of images we need
    array_splice($picturelist, $maxElement);
    }

    $nggNav = new nggNavigation;
    $navigation = $nggNav->create_navigation($page, $total, $maxElement);
    } else {
    $navigation = '<div class="ngg-clear"> </div>';
    }

    //we cannot use the key as index, cause it's filled with the pid
    $index = 0;
    foreach ($picturelist as $key => $picture) {

    //needed for hidden images (THX to Sweigold for the main idea at : http://wordpress.org/support/topic/228743/ )
    $picturelist[$key]->hidden = false;
    $picturelist[$key]->style = $gallery->imagewidth;

    if ($maxElement > 0 && $ngg_options['galHiddenImg']) {
    if ( ($index < $start) || ($index > ($start + $maxElement -1)) ){
    $picturelist[$key]->hidden = true;
    $picturelist[$key]->style = ($gallery->columns > 0) ? 'style="width:' . floor(100/$gallery->columns) . '%;display: none;"' : 'style="display: none;"';
    }
    $index++;
    }

    // get the effect code
    if ($galleryID)
    $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode('set_' . $galleryID);
    else
    $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode(get_the_title());

    // create link for imagebrowser and other effects
    $args ['nggpage'] = empty($nggpage) ? false : $nggpage;
    $args ['pid'] = $picture->pid;
    $picturelist[$key]->pidlink = $nggRewrite->get_permalink( $args );

    // generate the thumbnail size if the meta data available
    if (is_array ($size = $picturelist[$key]->meta_data['thumbnail']) )
    $thumbsize = 'width="' . $size['width'] . '" height="' . $size['height'] . '"';

    // choose link between imagebrowser or effect
    $link = ($ngg_options['galImgBrowser']) ? $picturelist[$key]->pidlink : $picture->imageURL;
    // bad solution : for now we need the url always for the carousel, should be reworked in the future
    $picturelist[$key]->url = $picture->imageURL;
    // add a filter for the link
    $picturelist[$key]->imageURL = apply_filters('ngg_create_gallery_link', $link, $picture);
    $picturelist[$key]->thumbnailURL = $picture->thumbURL;
    $picturelist[$key]->size = $thumbsize;
    $picturelist[$key]->thumbcode = $thumbcode;
    $picturelist[$key]->caption = ( empty($picture->description) ) ? ' ' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->description)) );
    $picturelist[$key]->description = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->description)) );
    $picturelist[$key]->alttext = ( empty($picture->alttext) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->alttext)) );

    // filter to add custom content for the output
    $picturelist[$key] = apply_filters('ngg_image_object', $picturelist[$key], $picture->pid);

    //check if $pid is in the array
    if ($picture->pid == $pid)
    $current_pid = $picturelist[$key];
    }
    reset($picturelist);

    //for paged galleries, take the first image in the array if it's not in the list
    $current_pid = ( empty($current_pid) ) ? current( $picturelist ) : $current_pid;

    // look for gallery-$template.php or pure gallery.php
    $filename = ( empty($template) ) ? 'gallery' : 'gallery-' . $template;

    //filter functions for custom addons
    $gallery = apply_filters( 'ngg_gallery_object', $gallery, $galleryID );
    $picturelist = apply_filters( 'ngg_picturelist_object', $picturelist, $galleryID );

    //additional navigation links
    $next = ( empty($nggNav->next) ) ? false : $nggNav->next;
    $prev = ( empty($nggNav->prev) ) ? false : $nggNav->prev;

    // create the output
    $out = nggGallery::capture ( $filename, array ('gallery' => $gallery, 'images' => $picturelist, 'pagination' => $navigation, 'current' => $current_pid, 'next' => $next, 'prev' => $prev) );

    // apply a filter after the output
    $out = apply_filters('ngg_gallery_output', $out, $picturelist);

    return $out;
    }

    /**
    * nggShowAlbum() - return a album based on the id
    *
    * @access public
    * @param int | string $albumID
    * @param string (optional) $template
    * @return the content
    */
    function nggShowAlbum($albumID, $template = 'extend') {

    // $_GET from wp_query
    $gallery = get_query_var('gallery');
    $album = get_query_var('album');

    // in the case somebody uses the '0', it should be 'all' to show all galleries
    $albumID = ($albumID == 0) ? 'all' : $albumID;

    // first look for gallery variable
    if (!empty( $gallery )) {

    // subalbum support only one instance, you can't use more of them in one post
    if ( isset($GLOBALS['subalbum']) || isset($GLOBALS['nggShowGallery']) )
    return;

    // if gallery is is submit , then show the gallery instead
    $out = nggShowGallery( intval($gallery) );
    $GLOBALS['nggShowGallery'] = true;

    return $out;
    }

    if ( (empty( $gallery )) && (isset($GLOBALS['subalbum'])) )
    return;

    //redirect to subalbum only one time
    if (!empty( $album )) {
    $GLOBALS['subalbum'] = true;
    $albumID = $album;
    }

    // lookup in the database
    $album = nggdb::find_album( $albumID );

    // still no success ? , die !
    if( !$album )
    return __('[Album not found]','nggallery');

    $mode = ltrim($mode, ',');

    if ( is_array($album->gallery_ids) )
    $out = nggCreateAlbum( $album->gallery_ids, $template, $album );

    $out = apply_filters( 'ngg_show_album_content', $out, $album->id );

    return $out;
    }

    /**
    * create a gallery overview output
    *
    * @access internal
    * @param array $galleriesID
    * @param string (optional) $template name for a template file, look for album-$template
    * @param object (optional) $album result from the db
    * @return the content
    */
    function nggCreateAlbum( $galleriesID, $template = 'extend', $album = 0) {

    global $wpdb, $nggRewrite, $nggdb;

    // $_GET from wp_query
    $nggpage = get_query_var('nggpage');

    $ngg_options = nggGallery::get_option('ngg_options');

    //this option can currently only set via the custom fields
    $maxElement = (int) $ngg_options['galPagedGalleries'];

    $sortorder = $galleriesID;
    $galleries = array();

    // get the galleries information
    foreach ($galleriesID as $i => $value)
    $galleriesID[$i] = addslashes($value);

    $unsort_galleries = $wpdb->get_results('SELECT * FROM '.$wpdb->nggallery.' WHERE gid IN (\''.implode('\',\'', $galleriesID).'\')', OBJECT_K);

    //TODO: Check this, problem exist when previewpic = 0
    //$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);

    // get the counter values
    $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);
    if ( is_array($picturesCounter) ) {
    foreach ($picturesCounter as $key => $value)
    $unsort_galleries[$key]->counter = $value->counter;
    }

    // get the id's of the preview images
    $imagesID = array();
    if ( is_array($unsort_galleries) ) {
    foreach ($unsort_galleries as $gallery_row)
    $imagesID[] = $gallery_row->previewpic;
    }
    $albumPreview = $wpdb->get_results('SELECT pid, filename FROM '.$wpdb->nggpictures.' WHERE pid IN (\''.implode('\',\'', $imagesID).'\')', OBJECT_K);

    // re-order them and populate some
    foreach ($sortorder as $key) {

    //if we have a prefix 'a' then it's a subalbum, instead a gallery
    if (substr( $key, 0, 1) == 'a') {
    // get the album content
    if ( !$subalbum = $nggdb->find_album(substr( $key, 1)) )
    continue;

    //populate the sub album values
    $galleries[$key]->counter = 0;
    if ($subalbum->previewpic > 0)
    $image = $nggdb->find_image( $subalbum->previewpic );
    $galleries[$key]->previewpic = $subalbum->previewpic;
    $galleries[$key]->previewurl = ($image->thumbURL) ? $image->thumbURL : '';
    $galleries[$key]->previewname = $subalbum->name;

    //link to the subalbum
    $args['album'] = $subalbum->id;
    $args['gallery'] = false;
    $args['nggpage'] = false;
    $pageid = (isset($subalbum->pageid) ? $subalbum->pageid : 0);
    if ($pageid > 0) {
    $galleries[$key]->pagelink = get_permalink($pageid);
    } else {
    $galleries[$key]->pagelink = $nggRewrite->get_permalink($args);
    }
    $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n($subalbum->albumdesc) );
    $galleries[$key]->title = html_entity_decode ( nggGallery::i18n($subalbum->name) );

    // apply a filter on gallery object before the output
    $galleries[$key] = apply_filters('ngg_album_galleryobject', $galleries[$key]);

    continue;
    }

    // If a gallery is not found it should be ignored
    if (!$unsort_galleries[$key])
    continue;

    // Add the counter value if avaible
    $galleries[$key] = $unsort_galleries[$key];

    // add the file name and the link
    if ($galleries[$key]->previewpic != 0) {
    $galleries[$key]->previewname = $albumPreview[$galleries[$key]->previewpic]->filename;
    $galleries[$key]->previewurl = get_option ('siteurl').'/' . $galleries[$key]->path . '/thumbs/thumbs_' . $albumPreview[$galleries[$key]->previewpic]->filename;
    } else {
    $first_image = $wpdb->get_row('SELECT * FROM '. $wpdb->nggpictures .' WHERE exclude != 1 AND galleryid = '. $key .' ORDER by pid DESC limit 0,1');
    $galleries[$key]->previewpic = $first_image->pid;
    $galleries[$key]->previewname = $first_image->filename;
    $galleries[$key]->previewurl = get_option ('siteurl') . '/' . $galleries[$key]->path . '/thumbs/thumbs_' . $first_image->filename;
    }

    // choose between variable and page link
    if ($ngg_options['galNoPages']) {
    $args['album'] = $album->id;
    $args['gallery'] = $key;
    $args['nggpage'] = false;
    $galleries[$key]->pagelink = $nggRewrite->get_permalink($args);

    } else {
    $galleries[$key]->pagelink = get_permalink( $galleries[$key]->pageid );
    }

    // description can contain HTML tags
    $galleries[$key]->galdesc = html_entity_decode ( stripslashes($galleries[$key]->galdesc) ) ;

    // i18n
    $galleries[$key]->title = html_entity_decode ( nggGallery::i18n($galleries[$key]->title) ) ;

    // apply a filter on gallery object before the output
    $galleries[$key] = apply_filters('ngg_album_galleryobject', $galleries[$key]);
    }

    // check for page navigation
    if ($maxElement > 0) {
    if ( !is_home() || $pageid == get_the_ID() ) {
    $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
    }
    else $page = 1;

    $start = $offset = ( $page - 1 ) * $maxElement;

    $total = count($galleries);

    // remove the element if we didn't start at the beginning
    if ($start > 0 ) array_splice($galleries, 0, $start);

    // return the list of images we need
    array_splice($galleries, $maxElement);

    $nggNav = new nggNavigation;
    $navigation = $nggNav->create_navigation($page, $total, $maxElement);
    } else {
    $navigation = '<div class="ngg-clear"> </div>';
    }

    // apply a filter on $galleries before the output
    $galleries = apply_filters('ngg_album_galleries', $galleries);

    // if sombody didn't enter any template , take the extend version
    $filename = ( empty($template) ) ? 'album-extend' : 'album-' . $template ;

    // create the output
    $out = nggGallery::capture ( $filename, array ('album' => $album, 'galleries' => $galleries, 'pagination' => $navigation) );

    return $out;

    }

    /**
    * nggShowImageBrowser()
    *
    * @access public
    * @param int|string $galleryID or gallery name
    * @param string $template (optional) name for a template file, look for imagebrowser-$template
    * @return the content
    */
    function nggShowImageBrowser($galleryID, $template = '') {

    global $wpdb;

    $ngg_options = nggGallery::get_option('ngg_options');

    //Set sort order value, if not used (upgrade issue)
    $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
    $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';

    // get the pictures
    $picturelist = nggdb::get_ids_from_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);

    if ( is_array($picturelist) )
    $out = nggCreateImageBrowser($picturelist, $template);
    else
    $out = __('[Gallery not found]','nggallery');

    $out = apply_filters('ngg_show_imagebrowser_content', $out, $galleryID);

    return $out;

    }

    /**
    * nggCreateImageBrowser()
    *
    * @access internal
    * @param array $picarray with pid
    * @param string $template (optional) name for a template file, look for imagebrowser-$template
    * @return the content
    */
    function nggCreateImageBrowser($picarray, $template = '') {

    global $nggRewrite;

    require_once( dirname (__FILE__) . '/lib/meta.php' );

    // $_GET from wp_query
    $pid = get_query_var('pid');

    // we need to know the current page id
    $current_page = (get_the_ID() == false) ? 0 : get_the_ID();

    if ( !is_array($picarray) )
    $picarray = array($picarray);

    $total = count($picarray);

    // look for gallery variable
    if ( !empty( $pid )) {
    $act_pid = (int) $pid;
    } else {
    reset($picarray);
    $act_pid = current($picarray);
    }

    // get ids for back/next
    $key = array_search($act_pid,$picarray);
    if (!$key) {
    $act_pid = reset($picarray);
    $key = key($picarray);
    }
    $back_pid = ( $key >= 1 ) ? $picarray[$key-1] : end($picarray) ;
    $next_pid = ( $key < ($total-1) ) ? $picarray[$key+1] : reset($picarray) ;

    // get the picture data
    $picture = nggdb::find_image($act_pid);

    // if we didn't get some data, exit now
    if ($picture == null)
    return;

    // add more variables for render output
    $picture->href_link = $picture->get_href_link();
    $picture->previous_image_link = $nggRewrite->get_permalink(array ('pid' => $back_pid));
    $picture->previous_pid = $back_pid;
    $picture->next_image_link = $nggRewrite->get_permalink(array ('pid' => $next_pid));
    $picture->next_pid = $next_pid;
    $picture->number = $key + 1;
    $picture->total = $total;
    $picture->linktitle = htmlspecialchars( stripslashes($picture->description) );
    $picture->alttext = html_entity_decode( stripslashes($picture->alttext) );
    $picture->description = html_entity_decode( stripslashes($picture->description) );
    $picture->anchor = 'ngg-imagebrowser-' . $picture->galleryid . '-' . $current_page;

    // filter to add custom content for the output
    $picture = apply_filters('ngg_image_object', $picture, $act_pid);

    // let's get the meta data
    $meta = new nggMeta($act_pid);
    $exif = $meta->get_EXIF();
    $iptc = $meta->get_IPTC();
    $xmp = $meta->get_XMP();
    $db = $meta->get_saved_meta();

    //if we get no exif information we try the database
    $exif = ($exif == false) ? $db : $exif;

    // look for imagebrowser-$template.php or pure imagebrowser.php
    $filename = ( empty($template) ) ? 'imagebrowser' : 'imagebrowser-' . $template;

    // create the output
    $out = nggGallery::capture ( $filename , array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db) );

    return $out;

    }

    /**
    * nggSinglePicture() - show a single picture based on the id
    *
    * @access public
    * @param int $imageID, db-ID of the image
    * @param int (optional) $width, width of the image
    * @param int (optional) $height, height of the image
    * @param string $mode (optional) could be none, watermark, web20
    * @param string $float (optional) could be none, left, right
    * @param string $template (optional) name for a template file, look for singlepic-$template
    * @param string $caption (optional) additional caption text
    * @param string $link (optional) link to a other url instead the full image
    * @return the content
    */
    function nggSinglePicture($imageID, $width = 250, $height = 250, $mode = '', $float = '' , $template = '', $caption = '', $link = '') {
    global $post;

    $ngg_options = nggGallery::get_option('ngg_options');

    // get picturedata
    $picture = nggdb::find_image($imageID);

    // if we didn't get some data, exit now
    if ($picture == null)
    return __('[SinglePic not found]','nggallery');

    // add float to img
    switch ($float) {

    case 'left':
    $float =' ngg-left';
    break;

    case 'right':
    $float =' ngg-right';
    break;

    case 'center':
    $float =' ngg-center';
    break;

    default:
    $float ='';
    break;
    }

    // clean mode if needed
    $mode = ( preg_match('/(web20|watermark)/i', $mode) ) ? $mode : '';

    //let's initiate the url
    $picture->thumbnailURL = false;

    // check fo cached picture
    if ( ($ngg_options['imgCacheSinglePic']) && ($post->post_status == 'publish') )
    $picture->thumbnailURL = $picture->cached_singlepic_file($width, $height, $mode );

    // if we didn't use a cached image then we take the on-the-fly mode
    if (!$picture->thumbnailURL)
    $picture->thumbnailURL = NGGALLERY_URLPATH . 'nggshow.php?pid=' . $imageID . '&width=' . $width . '&height=' . $height . '&mode=' . $mode;

    // add more variables for render output
    $picture->imageURL = ( empty($link) ) ? $picture->imageURL : $link;
    $picture->href_link = $picture->get_href_link();
    $picture->alttext = html_entity_decode( stripslashes($picture->alttext) );
    $picture->linktitle = htmlspecialchars( stripslashes($picture->description) );
    $picture->description = html_entity_decode( stripslashes($picture->description) );
    $picture->classname = 'ngg-singlepic'. $float;
    $picture->thumbcode = $picture->get_thumbcode( 'singlepic' . $imageID);
    $picture->height = (int) $height;
    $picture->width = (int) $width;
    $picture->caption = $caption;

    // filter to add custom content for the output
    $picture = apply_filters('ngg_image_object', $picture, $imageID);

    // let's get the meta data
    $meta = new nggMeta($imageID);
    $exif = $meta->get_EXIF();
    $iptc = $meta->get_IPTC();
    $xmp = $meta->get_XMP();
    $db = $meta->get_saved_meta();

    //if we get no exif information we try the database
    $exif = ($exif == false) ? $db : $exif;

    // look for singlepic-$template.php or pure singlepic.php
    $filename = ( empty($template) ) ? 'singlepic' : 'singlepic-' . $template;

    // create the output
    $out = nggGallery::capture ( $filename, array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db) );

    $out = apply_filters('ngg_show_singlepic_content', $out, $picture );

    return $out;
    }

    /**
    * nggShowGalleryTags() - create a gallery based on the tags
    *
    * @access public
    * @param string $taglist list of tags as csv
    * @return the content
    */
    function nggShowGalleryTags($taglist) {

    // $_GET from wp_query
    $pid = get_query_var('pid');
    $pageid = get_query_var('pageid');

    // get now the related images
    $picturelist = nggTags::find_images_for_tags($taglist , 'ASC');

    // look for ImageBrowser if we have a $_GET('pid')
    if ( $pageid == get_the_ID() || !is_home() )
    if (!empty( $pid )) {
    foreach ($picturelist as $picture) {
    $picarray[] = $picture->pid;
    }
    $out = nggCreateImageBrowser($picarray);
    return $out;
    }

    // go on if not empty
    if ( empty($picturelist) )
    return;

    // show gallery
    if ( is_array($picturelist) )
    $out = nggCreateGallery($picturelist, false);

    $out = apply_filters('ngg_show_gallery_tags_content', $out, $taglist);
    return $out;
    }

    /**
    * nggShowRelatedGallery() - create a gallery based on the tags
    *
    * @access public
    * @param string $taglist list of tags as csv
    * @param integer $maxImages (optional) limit the number of images to show
    * @return the content
    */
    function nggShowRelatedGallery($taglist, $maxImages = 0) {

    $ngg_options = nggGallery::get_option('ngg_options');

    // get now the related images
    $picturelist = nggTags::find_images_for_tags($taglist, 'RAND');

    // go on if not empty
    if ( empty($picturelist) )
    return;

    // cut the list to maxImages
    if ( $maxImages > 0 )
    array_splice($picturelist, $maxImages);

    // *** build the gallery output
    $out = '<div class="ngg-related-gallery">';
    foreach ($picturelist as $picture) {

    // get the effect code
    $thumbcode = $picture->get_thumbcode( __('Related images for', 'nggallery') . ' ' . get_the_title());

    $out .= 'imageURL . '" title="' . stripslashes(nggGallery::i18n($picture->description)) . '" ' . $thumbcode . ' >';
    $out .= '<img title="' . stripslashes(nggGallery::i18n($picture->alttext)) . '" alt="' . stripslashes(nggGallery::i18n($picture->alttext)) . '" src="' . $picture->thumbURL . '" />';
    $out .= '
    ' . "\n";
    }
    $out .= '</div>' . "\n";

    $out = apply_filters('ngg_show_related_gallery_content', $out, $taglist);

    return $out;
    }

    /**
    * nggShowAlbumTags() - create a gallery based on the tags
    *
    * @access public
    * @param string $taglist list of tags as csv
    * @return the content
    */
    function nggShowAlbumTags($taglist) {

    global $wpdb, $nggRewrite;

    // $_GET from wp_query
    $tag = get_query_var('gallerytag');
    $pageid = get_query_var('pageid');

    // look for gallerytag variable
    if ( $pageid == get_the_ID() || !is_home() ) {
    if (!empty( $tag )) {

    // 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';
    $slug = esc_attr( $tag );
    $tagname = $wpdb->get_var( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE slug = %s", $slug ) );
    $out = '<div id="albumnav"><span>'.__('Overview', 'nggallery').' | '.$tagname.'</span></div>';
    $out .= nggShowGalleryTags($slug);
    return $out;

    }
    }

    // get now the related images
    $picturelist = nggTags::get_album_images($taglist);

    // go on if not empty
    if ( empty($picturelist) )
    return;

    // re-structure the object that we can use the standard template
    foreach ($picturelist as $key => $picture) {
    $picturelist[$key]->previewpic = $picture->pid;
    $picturelist[$key]->previewname = $picture->filename;
    $picturelist[$key]->previewurl = get_option ('siteurl') . '/' . $picture->path . '/thumbs/thumbs_' . $picture->filename;
    $picturelist[$key]->counter = $picture->count;
    $picturelist[$key]->title = $picture->name;
    $picturelist[$key]->pagelink = $nggRewrite->get_permalink( array('gallerytag'=>$picture->slug) );
    }

    //TODO: Add pagination later
    $navigation = '<div class="ngg-clear"> </div>';

    // create the output
    $out = nggGallery::capture ('album-compact', array ('album' => 0, 'galleries' => $picturelist, 'pagination' => $navigation) );

    $out = apply_filters('ngg_show_album_tags_content', $out, $taglist);

    return $out;
    }

    /**
    * nggShowRelatedImages() - return related images based on category or tags
    *
    * @access public
    * @param string $type could be 'tags' or 'category'
    * @param integer $maxImages of images
    * @return the content
    */
    function nggShowRelatedImages($type = '', $maxImages = 0) {
    $ngg_options = nggGallery::get_option('ngg_options');

    if ($type == '') {
    $type = $ngg_options['appendType'];
    $maxImages = $ngg_options['maxImages'];
    }

    $sluglist = array();

    switch ($type) {
    case 'tags':
    if (function_exists('get_the_tags')) {
    $taglist = get_the_tags();

    if (is_array($taglist)) {
    foreach ($taglist as $tag) {
    $sluglist[] = $tag->slug;
    }
    }
    }
    break;

    case 'category':
    $catlist = get_the_category();

    if (is_array($catlist)) {
    foreach ($catlist as $cat) {
    $sluglist[] = $cat->category_nicename;
    }
    }
    break;
    }

    $sluglist = implode(',', $sluglist);
    $out = nggShowRelatedGallery($sluglist, $maxImages);

    return $out;
    }

    /**
    * Template function for theme authors
    *
    * @access public
    * @param string (optional) $type could be 'tags' or 'category'
    * @param integer (optional) $maxNumbers of images
    * @return void
    */
    function the_related_images($type = 'tags', $maxNumbers = 7) {
    echo nggShowRelatedImages($type, $maxNumbers);
    }

    /**
    * nggShowRandomRecent($type, $maxImages,$template) - return recent or random images
    *
    * @access public
    * @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'
    * @param integer $maxImages of images
    * @param string $template (optional) name for a template file, look for gallery-$template
    * @param int $galleryId Limit to a specific gallery
    * @return the content
    */
    function nggShowRandomRecent($type, $maxImages, $template = '', $galleryId = 0) {

    // $_GET from wp_query
    $pid = get_query_var('pid');
    $pageid = get_query_var('pageid');

    // get now the recent or random images
    switch ($type) {
    case 'random':
    $picturelist = nggdb::get_random_images($maxImages, $galleryId);
    break;
    case 'id':
    $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id');
    break;
    case 'date':
    $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'date');
    break;
    case 'sort':
    $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'sort');
    break;
    default:
    // default is by pid
    $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id');
    }

    // look for ImageBrowser if we have a $_GET('pid')
    if ( $pageid == get_the_ID() || !is_home() )
    if (!empty( $pid )) {
    foreach ($picturelist as $picture) {
    $picarray[] = $picture->pid;
    }
    $out = nggCreateImageBrowser($picarray);
    return $out;
    }

    // go on if not empty
    if ( empty($picturelist) )
    return;

    // show gallery
    if ( is_array($picturelist) )
    $out = nggCreateGallery($picturelist, false, $template);

    $out = apply_filters('ngg_show_images_content', $out, $taglist);

    return $out;
    }

    /**
    * nggTagCloud() - return a tag cloud based on the wp core tag cloud system
    *
    * @param array $args
    * @param string $template (optional) name for a template file, look for gallery-$template
    * @return the content
    */
    function nggTagCloud($args ='', $template = '') {
    global $nggRewrite;

    // $_GET from wp_query
    $tag = get_query_var('gallerytag');
    $pageid = get_query_var('pageid');

    // look for gallerytag variable
    if ( $pageid == get_the_ID() || !is_home() ) {
    if (!empty( $tag )) {

    $slug = esc_attr( $tag );
    $out = nggShowGalleryTags( $slug );
    return $out;
    }
    }

    $defaults = array(
    'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
    'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
    'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'ngg_tag'
    );
    $args = wp_parse_args( $args, $defaults );

    $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags

    foreach ($tags as $key => $tag ) {

    $tags[ $key ]->link = $nggRewrite->get_permalink(array ('gallerytag' => $tag->slug));
    $tags[ $key ]->id = $tag->term_id;
    }

    $out = '<div class="ngg-tagcloud">' . wp_generate_tag_cloud( $tags, $args ) . '</div>';

    return $out;
    }
    ?>

  29. katn
    Member
    Posted 4 years ago #

    This looks like your nextgen gallery functions.php file. What you want to edit is your theme's functions.php. (that should be somewhere like wp-content -> themes -> "your theme name"-> functions.php)Your theme directory should also contain your search.php if you have one. Hope that helps. :) P.S. You should prob just erase your above post if you can.

  30. Alex Rabe
    Member
    Posted 4 years ago #

    See my solution here : http://alexrabe.de/2010/01/13/search-for-images/

    Hope this helps as first idea, it's NOT completed and may need more rework

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.