Archived
1
0
Fork 0

add sorting by weight option in galleryinfo.ini files (fixes #61)

This commit is contained in:
Jan Dittberner 2009-07-31 20:00:13 +00:00
parent 62d1ba55fe
commit 4090ea5881

View file

@ -187,6 +187,33 @@ function getGalleryLabel($galleryname) {
return $label; return $label;
} }
function cmpGalleryByWeight($a, $b) {
if (($a[0] == $b[0]) && (strcmp($a[1], $b[1]) == 0)) {
return 0;
}
if ($a[0] == $b[0]) {
return strcmp($a[1], $b[1]);
}
return ($a[0] < $b[0]) ? -1 : 1;
}
function getOrderedGalleries() {
global $configuration;
$galleries = array();
foreach (glob(realpath($configuration['gallerydir']) . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR) as $directory) {
$basename = basename($directory);
if (galleryExists($basename)) {
$inidata = getGalleryConfig($basename);
$weight = (array_key_exists('weight', $inidata[GALLERYSEC])) ?
intval($inidata[GALLERYSEC]['weight']) : 0;
$galleries[] = array($weight, $basename);
}
}
usort($galleries, 'cmpGalleryByWeight');
return $galleries;
}
/** /**
* Liefert die aktuelle Galerie. Die Galerie kann entweder im * Liefert die aktuelle Galerie. Die Galerie kann entweder im
* GET-Parameter @c galleryname stehen, als Wert @a default in der * GET-Parameter @c galleryname stehen, als Wert @a default in der
@ -203,20 +230,8 @@ function getCurrentGallery() {
galleryExists($_GET["galleryname"])) { galleryExists($_GET["galleryname"])) {
return $_GET["galleryname"]; return $_GET["galleryname"];
} }
$filepath = realpath($configuration['gallerydir'] . DIRECTORY_SEPARATOR . 'galleryinfo.ini'); $galleries = getOrderedGalleries();
if (!empty($filepath)) { return (count($galleries) > 0) ? $galleries[0][1] : null;
$inidata = getGalleryConfig();
if (galleryExists($inidata[GALLERYSEC]["default"])) {
return $inidata[GALLERYSEC]["default"];
}
}
foreach (glob(realpath($configuration['gallerydir']) . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR) as $directory) {
$basename = basename($directory);
if (galleryExists($basename)) {
return $basename;
}
}
return null;
} }
/** /**
@ -354,12 +369,10 @@ function getGalleryLinks() {
global $configuration; global $configuration;
$retval = array(); $retval = array();
foreach (glob(realpath($configuration['gallerydir']) . DIRECTORY_SEPARATOR . '*', $galleries = getOrderedGalleries();
GLOB_ONLYDIR) as $directory) { foreach ($galleries as $gallery) {
$basename = basename($directory);
if (galleryExists($basename)) {
$urlparams = array(); $urlparams = array();
$urlparams['galleryname'] = $basename; $urlparams['galleryname'] = $gallery[1];
if (array_key_exists('theme', $_GET)) { if (array_key_exists('theme', $_GET)) {
$urlparams['theme'] = $_GET['theme']; $urlparams['theme'] = $_GET['theme'];
} }
@ -369,11 +382,10 @@ function getGalleryLinks() {
} }
$url = sprintf('index.php?%s', $url = sprintf('index.php?%s',
implode(ini_get('arg_separator.output'), $parts)); implode(ini_get('arg_separator.output'), $parts));
$retval[] = array('gallery' => $basename, $retval[] = array('gallery' => $gallery[1],
'label' => getGalleryLabel($basename), 'label' => getGalleryLabel($gallery[1]),
'url' => htmlspecialchars($url)); 'url' => htmlspecialchars($url));
} }
}
return $retval; return $retval;
} }