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; |   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,25 +369,22 @@ 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); |     $urlparams = array(); | ||||||
|     if (galleryExists($basename)) { |     $urlparams['galleryname'] = $gallery[1]; | ||||||
|       $urlparams = array(); |     if (array_key_exists('theme', $_GET)) { | ||||||
|       $urlparams['galleryname'] = $basename; |       $urlparams['theme'] = $_GET['theme']; | ||||||
|       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)); |  | ||||||
|     } |     } | ||||||
|  |     $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; |   return $retval; | ||||||
| } | } | ||||||
|  |  | ||||||
		Reference in a new issue