예제 #1
0
 function jig_ng_get_permalink($path_elements)
 {
     if ($this->ng_version == 2) {
         global $wp_rewrite;
         $ngoptions = get_option('ngg_options');
         $ng_permalink_slug = !empty($ngoptions['router_param_slug']) ? $ngoptions['router_param_slug'] : $ngoptions['permalinkSlug'];
         if ($wp_rewrite->using_permalinks() === true) {
             // If permalinks are ON
             $qmark_pos = strpos($_SERVER["REQUEST_URI"], '?');
             if ($qmark_pos !== false) {
                 // query string needs to be dropped else not found error comes up (this only applies because NG is not set up to handle that) - even original NG goes crazy if permalinks are on and a query string is added to the URL (just something like utm_source) - this is not the same query string that WP uses internally to get the post by id
                 $query_string_from_request_uri = urldecode(substr($_SERVER["REQUEST_URI"], $qmark_pos));
                 $pure_request_uri = substr($_SERVER["REQUEST_URI"], 0, $qmark_pos);
             } else {
                 $pure_request_uri = $_SERVER["REQUEST_URI"];
                 $query_string_from_request_uri = '';
             }
             $slug_pos = strpos($pure_request_uri, $ng_permalink_slug);
             // The URL may already have the NG slug in it (subalbums)
             if ($slug_pos !== false) {
                 $pure_request_uri = substr($pure_request_uri, 0, $slug_pos);
             }
             $path_to_add = $ng_permalink_slug . '/';
             if (!empty($path_elements['gallerytag'])) {
                 $path_to_add .= 'tags/' . $path_elements['gallerytag'];
             } elseif (!empty($path_elements['gallery']) && !empty($path_elements['album'])) {
                 $path_to_add .= $path_elements['album'] . '/' . $path_elements['gallery'];
             } elseif (!empty($path_elements['album'])) {
                 $path_to_add .= $path_elements['album'];
             }
             // Have to trailing slash before the query string to avoid not found error [that happens with NG 2]!
             $link = trailingslashit('http' . (is_ssl() ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $pure_request_uri . $path_to_add) . $query_string_from_request_uri;
         } else {
             // If permalinks are OFF
             // NG adds the path again, not sure why
             $path_to_add = '/' . $ng_permalink_slug . '/';
             if (!empty($path_elements['gallerytag'])) {
                 $path_to_add .= 'tags/' . $path_elements['gallerytag'];
             } elseif (!empty($path_elements['gallery']) && !empty($path_elements['album'])) {
                 $path_to_add .= $path_elements['album'] . '/' . $path_elements['gallery'];
             } elseif (!empty($path_elements['album'])) {
                 $path_to_add .= $path_elements['album'];
             }
             $query_string = $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '';
             $link = trailingslashit('http' . (is_ssl() ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER["SCRIPT_NAME"] . $path_to_add) . $query_string;
         }
     } else {
         $nggRewrite = new nggRewrite();
         $link = $nggRewrite->get_permalink($path_elements);
     }
     return $link;
 }
 /**
  * nggShowAlbumTags() - create a gallery based on the tags
  * copyright (c) Photocrati Media 2012, modified to permit a template specification
  * @param string $taglist list of tags as csv
  * @param string $template the template to use, if any
  * @param int $images how many images per page, defaults to all
  * @return string
  */
 protected static function nggShowAlbumTags($taglist, $template, $images = false)
 {
     global $nggRewrite;
     // NextGEN Gallery 2.0[.7] defines class nggRewrite but doesn't instantiate it
     if (class_exists('nggRewrite') && !isset($nggRewrite)) {
         $nggRewrite = new 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);
             $term = get_term_by('name', $slug, 'ngg_tag');
             $tagname = $term->name;
             $out = sprintf('<div id="albumnav"><span><a href="%1$s" title="%2$s">%2$s</a> | %3$s</span></div>', esc_url(get_permalink()), __('Overview', 'nextgen-download-gallery'), esc_html($tagname));
             $out .= self::nggShowGalleryTags($slug, $template, $images);
             return $out;
         }
     }
     // get now the related images
     $picturelist = nggTags::get_album_images($taglist);
     // nothing to see, move along...
     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 = site_url("/{$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;
 }