$v0) {
// check for correct id
$result = $wpdb->get_var("SELECT filename FROM $wpdb->nggpictures WHERE pid = '$v0' ");
if($result){
$search = $matches[0][$key];
$replace= nggSinglePicture($v0,$matches[2][$key],$matches[3][$key],$matches[4][$key],$matches[5][$key]);
$content= str_replace ($search, $replace, $content);
}
}
}
}
}// end singelpic
if ( stristr( $content, '[album' )) {
$search = "@(?:
)*\s*\[album\s*=\s*(\w+|^\+)(|,extend|,compact)\]\s*(?:
)*@i";
if (preg_match_all($search, $content, $matches)) {
if (is_array($matches)) {
foreach ($matches[1] as $key =>$v0) {
// check for album id
$albumID = $wpdb->get_var("SELECT id FROM $wpdb->nggalbum WHERE id = '$v0' ");
if(!$albumID) $albumID = $wpdb->get_var("SELECT id FROM $wpdb->nggalbum WHERE name = '$v0' ");
if($albumID) {
$search = $matches[0][$key];
$replace= nggShowAlbum($albumID,$matches[2][$key]);
$content= str_replace ($search, $replace, $content);
}
}
}
}
}// end album
if ( stristr( $content, '[gallery' )) {
$search = "@(?:)*\s*\[gallery\s*=\s*(\w+|^\+)\]\s*(?:
)*@i";
if (preg_match_all($search, $content, $matches)) {
if (is_array($matches)) {
foreach ($matches[1] as $key =>$v0) {
// check for gallery id
$galleryID = $wpdb->get_var("SELECT gid FROM $wpdb->nggallery WHERE gid = '$v0' ");
if(!$galleryID) $galleryID = $wpdb->get_var("SELECT gid FROM $wpdb->nggallery WHERE name = '$v0' ");
if($galleryID) {
$search = $matches[0][$key];
$replace= nggShowGallery($galleryID);
$content= str_replace ($search, $replace, $content);
}
}
}
}
}// end gallery
if ( stristr( $content, '[imagebrowser' )) {
$search = "@(?:)*\s*\[imagebrowser\s*=\s*(\w+|^\+)\]\s*(?:
)*@i";
if (preg_match_all($search, $content, $matches)) {
if (is_array($matches)) {
foreach ($matches[1] as $key =>$v0) {
// check for gallery id
$galleryID = $wpdb->get_var("SELECT gid FROM $wpdb->nggallery WHERE gid = '$v0' ");
if(!$galleryID) $galleryID = $wpdb->get_var("SELECT gid FROM $wpdb->nggallery WHERE name = '$v0' ");
if($galleryID) {
$search = $matches[0][$key];
$replace= nggShowImageBrowser($galleryID);
$content= str_replace ($search, $replace, $content);
}
}
}
}
}// end gallery
if ( stristr( $content, '[slideshow' )) {
$search = "@(?:)*\s*\[slideshow\s*=\s*(\w+|^\+)(|,(\d+)|,)(|,(\d+))\]\s*(?:
)*@i";
if (preg_match_all($search, $content, $matches)) {
if (is_array($matches)) {
foreach ($matches[1] as $key =>$v0) {
// check for gallery id
$galleryID = $wpdb->get_var("SELECT gid FROM $wpdb->nggallery WHERE gid = '$v0' ");
if(!$galleryID) $galleryID = $wpdb->get_var("SELECT gid FROM $wpdb->nggallery WHERE name = '$v0' ");
if( $galleryID || $v0 == 0 ) {
$search = $matches[0][$key];
// get the size if they are set
$irWidth = $matches[3][$key];
$irHeight = $matches[5][$key];
$replace= nggShowSlideshow($galleryID,$irWidth,$irHeight);
$content= str_replace ($search, $replace, $content);
}
}
}
}
}// end slideshow
if ( stristr( $content, '[tags' )) {
$search = "@(?:)*\s*\[tags\s*=\s*(.*?)\s*\]\s*(?:
)*@i";
if (preg_match_all($search, $content, $matches)) {
if (is_array($matches)) {
foreach ($matches[1] as $key =>$v0) {
$search = $matches[0][$key];
$replace= nggShowGalleryTags($v0);
$content= str_replace ($search, $replace, $content);
}
}
}
}// end gallery tags
if ( stristr( $content, '[albumtags' )) {
$search = "@(?:)*\s*\[albumtags\s*=\s*(.*?)\s*\]\s*(?:
)*@i";
if (preg_match_all($search, $content, $matches)) {
if (is_array($matches)) {
foreach ($matches[1] as $key =>$v0) {
$search = $matches[0][$key];
$replace= nggShowAlbumTags($v0);
$content= str_replace ($search, $replace, $content);
}
}
}
}// end album tags
// attach related images based on category or tags
if ($ngg_options['activateTags'])
$content .= nggShowRelatedImages();
return $content;
}// end search content
/**********************************************************/
function nggShowSlideshow($galleryID,$irWidth,$irHeight) {
global $wpdb;
$ngg_options = nggallery::get_option('ngg_options');
//TODO: bad intermediate solution until refactor to class
$obj = 'so' . $galleryID . rand(10,1000);
if (empty($irWidth) ) $irWidth = (int) $ngg_options['irWidth'];
if (empty($irHeight)) $irHeight = (int) $ngg_options['irHeight'];
$out = "\n".'';
$out .= "\n\t".'';
$out = apply_filters('ngg_show_slideshow_content', $out);
return $out;
}
/**********************************************************/
function nggShowGallery($galleryID) {
global $wpdb, $nggRewrite;
$ngg_options = nggallery::get_option('ngg_options');
// $_GET from wp_query
$show = get_query_var('show');
$pid = get_query_var('pid');
$pageid = get_query_var('pageid');
// use the jQuery Plugin if activated
if (($ngg_options['thumbEffect'] == "thickbox") && ($ngg_options['galUsejQuery'])) {
$out .= nggShowJSGallery($galleryID);
return $out;
}
// 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)) {
$out = nggShowImageBrowser($galleryID);
return $out;
}
// 2nd look for slideshow
if ( $show == 'slide' ) {
$args['show'] = "gallery";
$out = '';
$out .= '
';
$out .= nggShowSlideshow($galleryID,$ngg_options['irWidth'],$ngg_options['irHeight']);
$out .= '
'."\n";
$out .= ''."\n";
return $out;
}
}
//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 all picture with this galleryid
$picturelist = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE t.gid = '$galleryID' AND tt.exclude != 1 ORDER BY tt.$ngg_options[galSort] $ngg_options[galSortDir] ");
if (is_array($picturelist)) {
$out = nggCreateGallery($picturelist,$galleryID);
}
$out = apply_filters('ngg_show_gallery_content', $out);
return $out;
}
/**********************************************************/
function nggCreateGallery($picturelist,$galleryID = false) {
/**
* @array $picturelist
* @int $galleryID
**/
global $nggRewrite;
$ngg_options = nggallery::get_option('ngg_options');
// $_GET from wp_query
$nggpage = get_query_var('nggpage');
$pageid = get_query_var('pageid');
if (!is_array($picturelist))
$picturelist = array($picturelist);
$maxElement = $ngg_options['galImages'];
$thumbwidth = $ngg_options['thumbwidth'];
$thumbheight = $ngg_options['thumbheight'];
// set thumb size
$thumbsize = "";
if ($ngg_options['thumbfix']) $thumbsize = 'style="width:'.$thumbwidth.'px; height:'.$thumbheight.'px;"';
if ($ngg_options['thumbcrop']) $thumbsize = 'style="width:'.$thumbwidth.'px; height:'.$thumbwidth.'px;"';
// get the effect code
if ($galleryID)
$thumbcode = ($ngg_options['galImgBrowser']) ? "" : nggallery::get_thumbcode($picturelist[0]->name);
else
$thumbcode = ($ngg_options['galImgBrowser']) ? "" : nggallery::get_thumbcode(get_the_title());
// check for page navigation
if ($maxElement > 0) {
if ( !is_home() || $pageid == get_the_ID() ) {
if ( !empty( $nggpage ) )
$page = (int) $nggpage;
else
$page = 1;
}
else $page = 1;
$start = $offset = ( $page - 1 ) * $maxElement;
$total = count($picturelist);
// 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);
$navigation = nggallery::create_navigation($page, $total, $maxElement);
}
if (is_array($picturelist)) {
$out = '';
// show slideshow link
if ($galleryID)
if (($ngg_options['galShowSlide']) AND (NGGALLERY_IREXIST)) {
$args['show'] = "slide";
$out .= '
';
}
// a description below the picture, require fixed width
if (!$ngg_options['galShowDesc'])
$ngg_options['galShowDesc'] = "none";
$setwidth = ($ngg_options['galShowDesc'] != "none") ? 'style="width:'.($thumbwidth).'px;"' : '';
$class_desc = ($ngg_options['galShowDesc'] != "none") ? 'desc' : '';
foreach ($picturelist as $picture) {
// set image url
$folder_url = get_option ('siteurl')."/".$picture->path."/";
$thumbnailURL = get_option ('siteurl')."/".$picture->path.nggallery::get_thumbnail_folder($picture->path, FALSE);
$thumb_prefix = nggallery::get_thumbnail_prefix($picture->path, FALSE);
// choose link between imagebrowser or effect
$link =($ngg_options['galImgBrowser']) ? $nggRewrite->get_permalink(array('pid'=>$picture->pid)) : $folder_url.$picture->filename;
// create output
$out .= '
'."\n\t";
$out .= '
'."\n\t";
$out .= '
';
$out .= '
';
$out .= ''."\n";
if ($ngg_options['galShowDesc'] == "alttext")
$out .= '
'.html_entity_decode(stripslashes($picture->alttext)).''."\n";
if ($ngg_options['galShowDesc'] == "desc")
$out .= '
'.html_entity_decode(stripslashes($picture->description)).''."\n";
$out .= '
'."\n".'
'."\n";
}
$out .= '
'."\n";
$out .= ($maxElement > 0) ? $navigation : ''."\n";
}
return $out;
}
/**********************************************************/
function nggShowJSGallery($galleryID) {
// create a gallery with a jQuery plugin
//TODO:Refactor this to better, faster , cleaner solution
global $wpdb;
$ngg_options = nggallery::get_option('ngg_options');
$maxElement = $ngg_options['galImages'];
// get gallery values
$act_gallery = $wpdb->get_row("SELECT * FROM $wpdb->nggallery WHERE gid = '$galleryID' ");
// set gallery url
$folder_url = get_option ('siteurl')."/".$act_gallery->path."/";
$thumb_folder = str_replace('/','',nggallery::get_thumbnail_folder($act_gallery->path, FALSE));
$picturelist = $wpdb->get_results("SELECT * FROM $wpdb->nggpictures WHERE galleryid = '$galleryID' AND exclude != 1 ORDER BY $ngg_options[galSort] $ngg_options[galSortDir] ");
if (is_array($picturelist)) {
// create array
$i = 0;
$out = ''."\n";
$out .= ' '."\n";
$out .= ' '."\n";
$out .= '
'."\n";
$out .= ''."\n";
}
return $out;
}
/**********************************************************/
function nggShowAlbum($albumID,$mode = "extend") {
global $wpdb;
// $_GET from wp_query
$gallery = get_query_var('gallery');
$album = get_query_var('album');
// look for gallery variable
if (!empty( $gallery )) {
if ( $albumID != $album )
return;
$galleryID = (int) $gallery;
$out = nggShowGallery($galleryID);
return $out;
}
$mode = ltrim($mode,',');
$sortorder = $wpdb->get_var("SELECT sortorder FROM $wpdb->nggalbum WHERE id = '$albumID' ");
if (!empty($sortorder)) {
$gallery_array = unserialize($sortorder);
}
$out = '';
if (is_array($gallery_array)) {
foreach ($gallery_array as $galleryID) {
$out .= nggCreateAlbum($galleryID,$mode,$albumID);
}
}
$out .= '
'."\n";
$out .= ''."\n";
$out = apply_filters('ngg_show_album_content', $out);
return $out;
}
/**********************************************************/
function nggCreateAlbum($galleryID,$mode = "extend",$albumID = 0) {
// create a gallery overview div
global $wpdb, $nggRewrite;
$ngg_options = nggallery::get_option('ngg_options');
$gallerycontent = $wpdb->get_row("SELECT * FROM $wpdb->nggallery WHERE gid = '$galleryID' ");
// choose between variable and page link
if ($ngg_options['galNoPages']) {
$args['album'] = $albumID;
$args['gallery'] = $galleryID;
$link = $nggRewrite->get_permalink($args);
} else {
$link = get_permalink($gallerycontent->pageid);
}
if ($gallerycontent) {
$counter = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures WHERE galleryid = '$galleryID' AND exclude != 1");
if ($mode == "compact") {
if ($gallerycontent->previewpic != 0)
$insertpic = '
';
else
$insertpic = __('Watch gallery', 'nggallery');
$out = '
'.$counter.' '.__('Photos', 'nggallery').'
';
} else {
// mode extend
if ($gallerycontent->previewpic != 0)
$insertpic = '
';
else
$insertpic = __('Watch gallery', 'nggallery');
$out = '
'.html_entity_decode(stripslashes($gallerycontent->galdesc)).'
'.$counter.' '.__('Photos', 'nggallery').'
'."\n".'
'."\n".'
';
}
}
return $out;
}
/**********************************************************/
function nggShowImageBrowser($galleryID) {
/**
* show the ImageBrowser
* @galleryID int / gallery id
*/
global $wpdb;
$ngg_options = nggallery::get_option('ngg_options');
// get the pictures
$picturelist = $wpdb->get_col("SELECT pid FROM $wpdb->nggpictures WHERE galleryid = '$galleryID' AND exclude != 1 ORDER BY $ngg_options[galSort] $ngg_options[galSortDir]");
if (is_array($picturelist)) {
$out = nggCreateImageBrowser($picturelist);
}
$out = apply_filters('ngg_show_imagebrowser_content', $out);
return $out;
}
/**********************************************************/
function nggCreateImageBrowser($picarray) {
/**
* @array $picarray with pid
**/
global $nggRewrite;
// $_GET from wp_query
$pid = get_query_var('pid');
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 = new nggImage($act_pid);
if ($picture) {
$out = '
'.html_entity_decode(stripslashes($picture->alttext)).'
'.$picture->get_href_link().'
';
if ($back_pid) {
$backlink['pid'] = $back_pid;
$out .='
';
}
if ($next_pid) {
$nextlink['pid'] = $next_pid;
$out .='
';
}
$out .='
'.__('Picture', 'nggallery').' '.($key+1).' '.__('from', 'nggallery').' '.$total.'
'.html_entity_decode(stripslashes($picture->description)).'
';
}
return $out;
}
/**********************************************************/
function nggSinglePicture($imageID,$width=250,$height=250,$mode="",$float="") {
/**
* create a gallery based on the tags
* @imageID db-ID of the image
* @width width of the image
* @height height of the image
* @mode none, watermark, web20
* @float none, left, right
*/
global $wpdb, $post;
$ngg_options = nggallery::get_option('ngg_options');
// remove the comma
$float = ltrim($float,',');
$mode = ltrim($mode,',');
$width = ltrim($width,',');
$height = ltrim($height,',');
// get picturedata
$picture = new nggImage($imageID);
// add float to img
if (!empty($float)) {
switch ($float) {
case 'left': $float=' ngg-left" ';
break;
case 'right': $float=' ngg-right" ';
break;
default: $float='';
break;
}
}
// check fo cached picture
if ( ($ngg_options['imgCacheSinglePic']) && ($post->post_status == 'publish') )
$cache_url = $picture->cached_singlepic_file($width, $height, $mode );
// add fullsize picture as link
$out = 'get_thumbcode("singlepic".$imageID).' >';
if (!$cache_url)
$out .= '
';
else
$out .= '
';
$out .= '';
$out = apply_filters('ngg_show_singlepic_content', $out);
return $out;
}
/**********************************************************/
function nggShowGalleryTags($taglist) {
/**
* create a gallery based on the tags
* @taglist list of tags as csv
*/
global $wpdb;
// $_GET from wp_query
$pid = get_query_var('pid');
$pageid = get_query_var('pageid');
// get now the related images
$picturelist = ngg_Tags::get_images($taglist);
// look for ImageBrowser
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);
return $out;
}
/**********************************************************/
function nggShowRelatedGallery($taglist, $maxImages = 0) {
/**
* create a gallery based on the tags
* @taglist list of tags as csv
* @maxImages limit the number of images to show
*/
global $wpdb;
$ngg_options = nggallery::get_option('ngg_options');
// get now the related images
$picturelist = ngg_Tags::get_images($taglist);
// go on if not empty
if (empty($picturelist))
return;
// get the effect code
$thumbcode = nggallery::get_thumbcode("Related images for ".get_the_title());
// cut the list to maxImages
if ($maxImages > 0 ) array_splice($picturelist, $maxImages);
// *** build the gallery output
$out = ''."\n";
$out = apply_filters('ngg_show_related_gallery_content', $out);
return $out;
}
/**********************************************************/
function nggShowAlbumTags($taglist) {
/**
* create a gallery based on the tags
* @taglist list of tags as csv
*/
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 )) {
$galleryTag = attribute_escape( $tag );
$tagname = $wpdb->get_var("SELECT name FROM $wpdb->nggtags WHERE slug = '$galleryTag' ");
$out = '';
$out .= nggShowGalleryTags($galleryTag);
return $out;
}
}
// get now the related images
$picturelist = ngg_Tags::get_album_images($taglist);
// go on if not empty
if (empty($picturelist))
return;
$out = '';
foreach ($picturelist as $picture) {
$args['gallerytag'] = $picture["slug"];
$link = $nggRewrite->get_permalink($args);
$insertpic = '

';
$tagid = $picture['tagid'];
$counter = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpic2tags WHERE tagid = '$tagid' ");
$out .= '
'.$counter.' '.__('Photos', 'nggallery').'
';
}
$out .= '
'."\n";
$out .= ''."\n";
$out = apply_filters('ngg_show_album_tags_content', $out);
return $out;
}
/**********************************************************/
function nggShowRelatedImages($type = '', $maxImages = 0) {
// return related images based on category or tags
$ngg_options = nggallery::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;
}
$sluglist = implode(",", $sluglist);
$out = nggShowRelatedGallery($sluglist, $maxImages);
return $out;
}
/**********************************************************/
function the_related_images($type = 'tags', $maxNumbers = 7) {
// function for theme authors
echo nggShowRelatedImages($type, $maxNumbers);
}
?>