/** * Get the XML <rss> node corresponding to a gallery * * @param $gallery (object) The gallery to include in RSS * @param $prev_gallery (object) The previous gallery to link in RSS (null if none) * @param $next_gallery (object) The next gallery to link in RSS (null if none) */ function get_gallery_mrss($gallery, $prev_gallery = null, $next_gallery = null) { $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'; $title = stripslashes(M_I18N::translate($gallery->title)); $description = stripslashes(M_I18N::translate($gallery->galdesc)); $link = nggMediaRss::get_permalink($gallery->pageid); $prev_link = $prev_gallery != null ? nggMediaRss::get_gallery_mrss_url($prev_gallery->gid, true) : ''; $next_link = $next_gallery != null ? nggMediaRss::get_gallery_mrss_url($next_gallery->gid, true) : ''; $images = nggdb::get_gallery($gallery->gid, $ngg_options['galSort'], $ngg_options['galSortDir']); return nggMediaRss::get_mrss_root_node($title, $description, $link, $prev_link, $next_link, $images); }
/** * 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; require_once dirname(__FILE__) . '/lib/media-rss.php'; $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'); // in case of permalinks the pid is a slug, we need the id if (!is_numeric($pid) && !empty($pid)) { $picture = nggdb::find_image($pid); $pid = $picture->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->show_piclens = 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']) { $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) || $template != 'carousel' ? false : $nggpage; // only needed for carousel mode $args['pid'] = $ngg_options['usePermalinks'] ? $picture->image_slug : $picture->pid; $picturelist[$key]->pidlink = $nggRewrite->get_permalink($args); // generate the thumbnail size if the meta data available if (isset($picturelist[$key]->meta_data['thumbnail']) && 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, 'pic_' . $picture->pid . '_description'))); $picturelist[$key]->description = empty($picture->description) ? ' ' : htmlspecialchars(stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description'))); $picturelist[$key]->alttext = empty($picture->alttext) ? ' ' : htmlspecialchars(stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_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; }
/** * Get the XML <rss> node corresponding to a gallery * * @param $gallery (object) The gallery to include in RSS * @param $prev_gallery (object) The previous gallery to link in RSS (null if none) * @param $next_gallery (object) The next gallery to link in RSS (null if none) */ static function get_gallery_mrss($gallery, $prev_gallery = null, $next_gallery = null) { global $nggdb; $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'; $title = stripslashes(nggGallery::i18n($gallery->title)); $description = stripslashes(nggGallery::i18n($gallery->galdesc)); $link = nggMediaRss::get_permalink($gallery->pageid); $prev_link = $prev_gallery != null ? nggMediaRss::get_gallery_mrss_url($prev_gallery->gid, true) : ''; $next_link = $next_gallery != null ? nggMediaRss::get_gallery_mrss_url($next_gallery->gid, true) : ''; //20140106:shouldn't call it statically when is not... //$images = nggdb::get_gallery($gallery->gid, $ngg_options['galSort'], $ngg_options['galSortDir']); $images = $nggdb->get_gallery($gallery->gid, $ngg_options['galSort'], $ngg_options['galSortDir']); return nggMediaRss::get_mrss_root_node($title, $description, $link, $prev_link, $next_link, $images); }
/** * 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 * @return the content */ function nggCreateGallery($picturelist, $galleryID = false, $template = '') { global $nggRewrite; $ngg_options = nggGallery::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); } $gallery = new stdclass(); $gallery->ID = (int) $galleryID; $gallery->show_slideshow = false; $maxElement = $ngg_options['galImages']; $thumbwidth = $ngg_options['thumbwidth']; $thumbheight = $ngg_options['thumbheight']; // set thumb size $thumbsize = ''; if ($ngg_options['thumbfix']) { $thumbsize = 'width="' . $thumbwidth . '" height="' . $thumbheight . '"'; } if ($ngg_options['thumbcrop']) { $thumbsize = 'width="' . $thumbwidth . '" height="' . $thumbwidth . '"'; } // 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 = $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 == 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 = nggGallery::create_navigation($page, $total, $maxElement); } else { $navigation = '<div class="ngg-clear"> </div>'; } //var_dump($picturelist); foreach ($picturelist as $key => $picture) { // choose link between imagebrowser or effect $link = $ngg_options['galImgBrowser'] ? $nggRewrite->get_permalink(array('pid' => $picture->pid)) : $picture->imageURL; // get the effect code if ($galleryID) { $thumbcode = $ngg_options['galImgBrowser'] ? '' : $picture->get_thumbcode($picturelist[0]->name); } else { $thumbcode = $ngg_options['galImgBrowser'] ? '' : $picture->get_thumbcode(get_the_title()); } // 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]->description = empty($picture->description) ? ' ' : stripslashes($picture->description); $picturelist[$key]->alttext = empty($picture->alttext) ? ' ' : stripslashes($picture->alttext); } // look for gallery-$template.php or pure gallery.php $filename = empty($template) ? 'gallery' : 'gallery-' . $template; // create the output $out = nggGallery::capture($filename, array('gallery' => $gallery, 'images' => $picturelist, 'pagination' => $navigation)); // apply a filter after the output $out = apply_filters('ngg_gallery_output', $out, $picturelist); return $out; }