/** * nggShowAlbum() - return a album based on the id * * @access public * @param int | string $albumID * @param string (optional) $template * @param string (optional) $gallery_template * @return the content */ function nggShowAlbum($albumID, $template = 'extend', $gallery_template = '') { // $_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 //TODO: causes problems with SFC plugin, due to a second filter callback if (isset($GLOBALS['subalbum']) || isset($GLOBALS['nggShowGallery'])) { return; } // if gallery is submit , then show the gallery instead $out = nggShowGallery($gallery, $gallery_template); $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'); } // ensure to set the slug for "all" albums $album->slug = $albumID == 'all' ? $album->id : $album->slug; 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; }
// two step forward... Could be easier ? How ? next($galleries); $next_gallery = next($galleries); } $rss = nggMediaRss::get_gallery_mrss($gallery, $prev_gallery, $next_gallery); } else { if ($mode == 'album') { // Get additional parameters $aid = isset($_GET['aid']) ? (int) $_GET['aid'] : 0; if ($aid == 0) { header('content-type:text/plain;charset=utf-8'); _e("No album ID has been provided as parameter", "nggallery"); exit; } // Get the album object $album = nggdb::find_album($aid); if (!isset($album) || $album == null) { header('content-type:text/plain;charset=utf-8'); echo sprintf(__("The album ID=%s does not exist.", "nggallery"), intval($aid)); exit; } $rss = nggMediaRss::get_album_mrss($album); } else { header('content-type:text/plain;charset=utf-8'); echo __('Invalid MediaRSS command', 'nggallery'); exit; } } } // Output header for media RSS header("content-type:text/xml;charset=utf-8");
/** * Get all the images from a given album * * @param object|int $album The album object or the id * @param string $order_by * @param string $order_dir * @param bool $exclude * @return An array containing the nggImage objects representing the images in the album. */ static function find_images_in_album($album, $order_by = 'galleryid', $order_dir = 'ASC', $exclude = true) { global $wpdb; if (!is_object($album)) { $album = nggdb::find_album($album); } // Get gallery list $gallery_list = implode(',', $album->gallery_ids); // Check for the exclude setting $exclude_clause = $exclude ? ' AND tt.exclude<>1 ' : ''; // Say no to any other value $order_dir = $order_dir == 'DESC' ? 'DESC' : 'ASC'; $order_by = empty($order_by) ? 'galleryid' : $order_by; $result = $wpdb->get_results("SELECT t.*, tt.* FROM {$wpdb->nggallery} AS t INNER JOIN {$wpdb->nggpictures} AS tt ON t.gid = tt.galleryid WHERE tt.galleryid IN ({$gallery_list}) {$exclude_clause} ORDER BY tt.{$order_by} {$order_dir}"); // Return the object from the query result if ($result) { foreach ($result as $image) { $images[] = new nggImage($image); } return $images; } return null; }
/** * Method "ngg.deleteAlbum" * Delete a album from the database * * @since 1.7.0 * * @param array $args Method parameters. * - int blog_id * - string username * - string password * - int album id * @return true */ function deleteAlbum($args) { global $nggdb; $this->escape($args); $blog_ID = (int) $args[0]; $username = $args[1]; $password = $args[2]; $id = (int) $args[3]; if (!($user = $this->login($username, $password))) { return $this->error; } if (!($album = nggdb::find_album($id))) { return new IXR_Error(404, __("Invalid album ID")); } if (!current_user_can('NextGEN Edit album') && !nggGallery::current_user_can('NextGEN Add/Delete album')) { return new IXR_Error(401, __('Sorry, you must be able to manage albums')); } $nggdb->delete_album($id); return true; }
function start_process() { global $ngg; if (!$this->valid_access()) { return; } switch ($this->method) { case 'search': //search for some images $this->result['images'] = array_merge((array) nggdb::search_for_images($this->term), (array) nggTags::find_images_for_tags($this->term, 'ASC')); break; case 'album': //search for some album //TODO : Get images for each gallery, could end in a big db query $this->result['album'] = nggdb::find_album($this->id); break; case 'gallery': //search for some gallery $this->result['images'] = $this->id == 0 ? nggdb::find_last_images(0, 100) : nggdb::get_gallery($this->id, $ngg->options['galSort'], $ngg->options['galSortDir'], true, 0, 0, true); break; case 'image': //search for some image $this->result['images'] = nggdb::find_image($this->id); break; case 'tag': //search for images based on tags $this->result['images'] = nggTags::find_images_for_tags($this->term, 'ASC'); break; case 'recent': //search for images based on tags $this->result['images'] = nggdb::find_last_images(0, $this->limit); break; case 'autocomplete': //return images, galleries or albums for autocomplete drop down list return $this->autocomplete(); break; case 'version': $this->result = array('stat' => 'ok', 'version' => $ngg->version); return; break; default: $this->result = array('stat' => 'fail', 'code' => '98', 'message' => 'Method not known.'); return false; break; } // result should be fine $this->result['stat'] = 'ok'; }
/** * 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, $ngg; // $_GET from wp_query $nggpage = get_query_var('nggpage'); // Get options $ngg_options = $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) { // Create a gallery object if (isset($unsort_galleries[$key])) { $galleries[$key] = $unsort_galleries[$key]; } else { $galleries[$key] = new stdClass(); } //if we have a prefix 'a' then it's a subalbum, instead a gallery if (substr($key, 0, 1) == 'a') { if ($subalbum = nggdb::find_album(substr($key, 1))) { $galleries[$key]->counter = count($subalbum->gallery_ids); if ($subalbum->previewpic > 0) { $image = $nggdb->find_image($subalbum->previewpic); $galleries[$key]->previewurl = isset($image->thumbURL) ? $image->thumbURL : ''; } $galleries[$key]->previewpic = $subalbum->previewpic; $galleries[$key]->previewname = $subalbum->name; //link to the subalbum $args['album'] = $ngg_options['usePermalinks'] ? $subalbum->slug : $subalbum->id; $args['gallery'] = false; $args['nggpage'] = false; $pageid = isset($subalbum->pageid) ? $subalbum->pageid : 0; $galleries[$key]->pagelink = $pageid > 0 ? get_permalink($pageid) : $nggRewrite->get_permalink($args); $galleries[$key]->galdesc = html_entity_decode(nggGallery::i18n($subalbum->albumdesc)); $galleries[$key]->title = html_entity_decode(nggGallery::i18n($subalbum->name)); } } elseif (isset($unsort_galleries[$key])) { $galleries[$key] = $unsort_galleries[$key]; // No images found, set counter to 0 if (!isset($galleries[$key]->counter)) { $galleries[$key]->counter = 0; $galleries[$key]->previewurl = ''; } // add the file name and the link if ($galleries[$key]->previewpic != 0) { $galleries[$key]->previewname = $albumPreview[$galleries[$key]->previewpic]->filename; $galleries[$key]->previewurl = site_url() . '/' . $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'); if (isset($first_image)) { $galleries[$key]->previewpic = $first_image->pid; $galleries[$key]->previewname = $first_image->filename; $galleries[$key]->previewurl = site_url() . '/' . $galleries[$key]->path . '/thumbs/thumbs_' . $first_image->filename; } } // choose between variable and page link if ($ngg_options['galNoPages']) { $args['album'] = $ngg_options['usePermalinks'] ? $album->slug : $album->id; $args['gallery'] = $ngg_options['usePermalinks'] ? $galleries[$key]->slug : $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(nggGallery::i18n(stripslashes($galleries[$key]->galdesc), 'gal_' . $galleries[$key]->gid . '_description')); // i18n $galleries[$key]->title = html_entity_decode(nggGallery::i18n(stripslashes($galleries[$key]->title), 'gal_' . $galleries[$key]->gid . '_title')); } // apply a filter on gallery object before the output $galleries[$key] = apply_filters('ngg_album_galleryobject', $galleries[$key]); } // apply a filter on gallery object before paging starts $galleries = apply_filters('ngg_album_galleries_before_paging', $galleries, $album); // 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; }
/** * 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 'all' keyword, it should be '0' to show all galleries $albumID = $albumID == 'all' ? 0 : $albumID; // first look for gallery variable if (!empty($gallery)) { if ($albumID != $album && $albumID != 0) { return; } // if gallery is is submit , then show the gallery instead $galleryID = (int) $gallery; $out = nggShowGallery($galleryID); return $out; } // 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, intval($album->id)); return $out; }
/** * Method "ngg.getAlbum" * Return the specified album * * @since 1.9.2 * * @param array $args Method parameters. * - int blog_id * - string username * - string password * - int album_id * @return array with the album object */ function getAlbum($args) { $this->escape($args); $blog_ID = (int) $args[0]; $username = $args[1]; $password = $args[2]; $id = (int) $args[3]; if (!($user = $this->login($username, $password))) { return $this->error; } if (!current_user_can('NextGEN Edit album')) { return new IXR_Error(401, __('Sorry, you must be able to manage albums')); } $album = nggdb::find_album($id); return $album; }