add sorting by weight option in galleryinfo.ini files (fixes #61)
This commit is contained in:
parent
62d1ba55fe
commit
4090ea5881
1 changed files with 44 additions and 32 deletions
|
@ -187,6 +187,33 @@ function getGalleryLabel($galleryname) {
|
|||
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
|
||||
* GET-Parameter @c galleryname stehen, als Wert @a default in der
|
||||
|
@ -203,20 +230,8 @@ function getCurrentGallery() {
|
|||
galleryExists($_GET["galleryname"])) {
|
||||
return $_GET["galleryname"];
|
||||
}
|
||||
$filepath = realpath($configuration['gallerydir'] . DIRECTORY_SEPARATOR . 'galleryinfo.ini');
|
||||
if (!empty($filepath)) {
|
||||
$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;
|
||||
$galleries = getOrderedGalleries();
|
||||
return (count($galleries) > 0) ? $galleries[0][1] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -354,25 +369,22 @@ function getGalleryLinks() {
|
|||
global $configuration;
|
||||
|
||||
$retval = array();
|
||||
foreach (glob(realpath($configuration['gallerydir']) . DIRECTORY_SEPARATOR . '*',
|
||||
GLOB_ONLYDIR) as $directory) {
|
||||
$basename = basename($directory);
|
||||
if (galleryExists($basename)) {
|
||||
$urlparams = array();
|
||||
$urlparams['galleryname'] = $basename;
|
||||
if (array_key_exists('theme', $_GET)) {
|
||||
$urlparams['theme'] = $_GET['theme'];
|
||||
}
|
||||
$parts = array();
|
||||
foreach ($urlparams as $key => $value) {
|
||||
$parts[] = sprintf("%s=%s", $key, urlencode($value));
|
||||
}
|
||||
$url = sprintf('index.php?%s',
|
||||
implode(ini_get('arg_separator.output'), $parts));
|
||||
$retval[] = array('gallery' => $basename,
|
||||
'label' => getGalleryLabel($basename),
|
||||
'url' => htmlspecialchars($url));
|
||||
$galleries = getOrderedGalleries();
|
||||
foreach ($galleries as $gallery) {
|
||||
$urlparams = array();
|
||||
$urlparams['galleryname'] = $gallery[1];
|
||||
if (array_key_exists('theme', $_GET)) {
|
||||
$urlparams['theme'] = $_GET['theme'];
|
||||
}
|
||||
$parts = array();
|
||||
foreach ($urlparams as $key => $value) {
|
||||
$parts[] = sprintf("%s=%s", $key, urlencode($value));
|
||||
}
|
||||
$url = sprintf('index.php?%s',
|
||||
implode(ini_get('arg_separator.output'), $parts));
|
||||
$retval[] = array('gallery' => $gallery[1],
|
||||
'label' => getGalleryLabel($gallery[1]),
|
||||
'url' => htmlspecialchars($url));
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
|
Reference in a new issue