/** * Get Albums will create our $albums array with a fully populated set of Album * names in the correct order. * * Returns an array of albums (a pages worth if $page is not zero) * * @param int $page An option parameter that can be used to return a slice of the array. * @param string $sorttype the kind of sort desired * @param string $direction set to a direction to override the default option * * @return array */ function getAlbums($page = 0, $sorttype = null, $direction = null) { // Have the albums been loaded yet? if (is_null($this->albums) || $sorttype . $direction !== $this->lastalbumsort) { $albumnames = $this->loadAlbumNames(); $key = $this->getGallerySortKey($sorttype); if (is_null($direction)) { if (getOption('gallery_sortdirection')) { $key .= ' DESC'; } } else { $key .= ' ' . $direction; } $albums = sortAlbumArray(NULL, $albumnames, $key); // Store the values $this->albums = $albums; $this->lastalbumsort = $sorttype . $direction; } if ($page == 0) { return $this->albums; } else { return array_slice($this->albums, galleryAlbumsPerPage() * ($page - 1), galleryAlbumsPerPage()); } }
/** * Returns all folder names for all the subdirectories. * * @param string $page Which page of subalbums to display. * @param string $sorttype The sort strategy * @param string $sortdirection The direction of the sort * @return array */ function getSubAlbums($page = 0, $sorttype = null, $sortdirection = null) { if (is_null($this->subalbums) || $sorttype . $sortdirection !== $this->lastsubalbumsort) { $dirs = $this->loadFileNames(true); $subalbums = array(); foreach ($dirs as $dir) { $dir = $this->name . '/' . $dir; $subalbums[] = $dir; } $key = $this->getSubalbumSortKey($sorttype); if ($key != '`sort_order`') { if (is_null($sortdirection)) { if ($this->getSortDirection('album')) { $key .= ' DESC'; } } else { $key .= ' ' . $sortdirection; } } $sortedSubalbums = sortAlbumArray($this, $subalbums, $key); $this->subalbums = $sortedSubalbums; $this->lastsubalbumsort = $sorttype . $sortdirection; } if ($page == 0) { return $this->subalbums; } else { $albums_per_page = max(1, getOption('albums_per_page')); return array_slice($this->subalbums, $albums_per_page * ($page - 1), $albums_per_page); } }