improve configuration (addresses #49)
This commit is contained in:
parent
fd2530cbbd
commit
631ec74b2b
4 changed files with 56 additions and 34 deletions
|
@ -1,2 +0,0 @@
|
||||||
logfile=gallery.log
|
|
||||||
defaulttheme=default_horizontal
|
|
6
gallery.ini.tmpl
Normal file
6
gallery.ini.tmpl
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
logfile=gallery.log
|
||||||
|
defaulttheme=default_horizontal
|
||||||
|
gallerydir=bilder
|
||||||
|
gallerypath=/bilder
|
||||||
|
themedir=themes
|
||||||
|
themepath=/themes
|
|
@ -28,16 +28,17 @@
|
||||||
* <http://www.gnu.org/licenses/>.
|
* <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define(GALLERYPREFIX, "bilder");
|
|
||||||
define(INFOFILE, "galleryinfo.ini");
|
|
||||||
define(IMAGESEC, "images");
|
define(IMAGESEC, "images");
|
||||||
define(GALLERYSEC, "gallery");
|
define(GALLERYSEC, "gallery");
|
||||||
define(GALLERY_RE, '/^[\w\d _-]+$/');
|
define(GALLERY_RE, '/^[\w\d _-]+$/');
|
||||||
|
|
||||||
if (!realpath('gallery.ini')) {
|
$basedir = realpath(implode(DIRECTORY_SEPARATOR, array(dirname(__file__), '..')));
|
||||||
die('gallery.ini not found in ' . getcwd());
|
$inifile = implode(DIRECTORY_SEPARATOR, array($basedir, 'gallery.ini'));
|
||||||
|
|
||||||
|
if (!file_exists($inifile)) {
|
||||||
|
die("required $inifile not found.");
|
||||||
}
|
}
|
||||||
$configuration = parse_ini_file(realpath('gallery.ini'));
|
$configuration = parse_ini_file($inifile);
|
||||||
if (array_key_exists('logfile', $configuration)) {
|
if (array_key_exists('logfile', $configuration)) {
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
ini_set('display_errors', 0);
|
ini_set('display_errors', 0);
|
||||||
|
@ -63,8 +64,10 @@ if (array_key_exists('theme', $_GET) &&
|
||||||
* Verzeichnisnamen hat, sonst @c false
|
* Verzeichnisnamen hat, sonst @c false
|
||||||
*/
|
*/
|
||||||
function galleryExists($galleryname) {
|
function galleryExists($galleryname) {
|
||||||
|
global $configuration;
|
||||||
|
|
||||||
return preg_match(GALLERY_RE, $galleryname) &&
|
return preg_match(GALLERY_RE, $galleryname) &&
|
||||||
realpath(GALLERYPREFIX . DIRECTORY_SEPARATOR . $galleryname);
|
realpath($configuration['gallerydir'] . DIRECTORY_SEPARATOR . $galleryname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,11 +84,15 @@ function galleryExists($galleryname) {
|
||||||
* wenn keine Konfigurationsdatei vorhanden ist
|
* wenn keine Konfigurationsdatei vorhanden ist
|
||||||
*/
|
*/
|
||||||
function getGalleryConfig($galleryname = null) {
|
function getGalleryConfig($galleryname = null) {
|
||||||
|
global $configuration;
|
||||||
|
|
||||||
if ($galleryname) {
|
if ($galleryname) {
|
||||||
$filepath = realpath(GALLERYPREFIX . DIRECTORY_SEPARATOR .
|
$filepath = realpath(implode(DIRECTORY_SEPARATOR,
|
||||||
$galleryname . DIRECTORY_SEPARATOR . INFOFILE);
|
array($configuration['gallerydir'], $galleryname,
|
||||||
|
'galleryinfo.ini')));
|
||||||
} else {
|
} else {
|
||||||
$filepath = realpath(GALLERYPREFIX . DIRECTORY_SEPARATOR . INFOFILE);
|
$filepath = realpath(implode(DIRECTORY_SEPARATOR,
|
||||||
|
array($configuration['gallerydir'], 'galleryinfo.ini')));
|
||||||
}
|
}
|
||||||
if (is_file($filepath)) {
|
if (is_file($filepath)) {
|
||||||
return parse_ini_file($filepath, true);
|
return parse_ini_file($filepath, true);
|
||||||
|
@ -107,17 +114,17 @@ function getGalleryConfig($galleryname = null) {
|
||||||
* @li @a full relative URL des Vollbildes
|
* @li @a full relative URL des Vollbildes
|
||||||
*/
|
*/
|
||||||
function getImageInfo($galleryname, $imagename) {
|
function getImageInfo($galleryname, $imagename) {
|
||||||
global $theme;
|
global $theme, $configuration;
|
||||||
|
|
||||||
$label = getImageLabel($galleryname, $imagename);
|
$label = getImageLabel($galleryname, $imagename);
|
||||||
$gallerylabel = getGalleryLabel($galleryname);
|
$gallerylabel = getGalleryLabel($galleryname);
|
||||||
return array("name" => $imagename,
|
return array("name" => $imagename,
|
||||||
"label" => $label,
|
"label" => $label,
|
||||||
"preview" => GALLERYPREFIX . DIRECTORY_SEPARATOR .
|
"preview" => $configuration['gallerypath'] . '/' .
|
||||||
getScaledImage($galleryname, $imagename,
|
getScaledImage($galleryname, $imagename,
|
||||||
$theme->previewsize, false),
|
$theme->previewsize, false),
|
||||||
"full" => GALLERYPREFIX . DIRECTORY_SEPARATOR . $galleryname .
|
"full" => implode('/', array($configuration['gallerypath'],
|
||||||
DIRECTORY_SEPARATOR . $imagename,
|
$galleryname, $imagename)),
|
||||||
"title" => sprintf("%s :: %s", $gallerylabel, $label)
|
"title" => sprintf("%s :: %s", $gallerylabel, $label)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -135,7 +142,9 @@ function getImageInfo($galleryname, $imagename) {
|
||||||
* @return Label zu dem Bild
|
* @return Label zu dem Bild
|
||||||
*/
|
*/
|
||||||
function getImageLabel($galleryname, $imagename) {
|
function getImageLabel($galleryname, $imagename) {
|
||||||
$gallerypath = realpath(GALLERYPREFIX . DIRECTORY_SEPARATOR . $galleryname);
|
global $configuration;
|
||||||
|
|
||||||
|
$gallerypath = realpath($configuration['gallerydir'] . DIRECTORY_SEPARATOR . $galleryname);
|
||||||
if (empty($gallerypath) || !is_dir($gallerypath)) {
|
if (empty($gallerypath) || !is_dir($gallerypath)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -175,25 +184,26 @@ function getGalleryLabel($galleryname) {
|
||||||
* 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
|
||||||
* Sektion @a gallery der zentralen @c galleryinfo.ini angegeben
|
* Sektion @a gallery der zentralen @c galleryinfo.ini angegeben
|
||||||
* werden oder es wird das erste Unterverzeichnis von @c GALLERYPREFIX
|
* werden oder es wird das erste Unterverzeichnis von @c gallerydir
|
||||||
* verwendet.
|
* verwendet.
|
||||||
*
|
*
|
||||||
* @return Galeriename
|
* @return Galeriename
|
||||||
*/
|
*/
|
||||||
function getCurrentGallery() {
|
function getCurrentGallery() {
|
||||||
|
global $configuration;
|
||||||
|
|
||||||
if (array_key_exists('galleryname', $_GET) &&
|
if (array_key_exists('galleryname', $_GET) &&
|
||||||
galleryExists($_GET["galleryname"])) {
|
galleryExists($_GET["galleryname"])) {
|
||||||
return $_GET["galleryname"];
|
return $_GET["galleryname"];
|
||||||
}
|
}
|
||||||
$filepath = realpath(GALLERYPREFIX . DIRECTORY_SEPARATOR . INFOFILE);
|
$filepath = realpath($configuration['gallerydir'] . DIRECTORY_SEPARATOR . 'galleryinfo.ini');
|
||||||
if (!empty($filepath)) {
|
if (!empty($filepath)) {
|
||||||
$inidata = getGalleryConfig();
|
$inidata = getGalleryConfig();
|
||||||
if (galleryExists($inidata[GALLERYSEC]["default"])) {
|
if (galleryExists($inidata[GALLERYSEC]["default"])) {
|
||||||
return $inidata[GALLERYSEC]["default"];
|
return $inidata[GALLERYSEC]["default"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (glob(realpath(GALLERYPREFIX) . DIRECTORY_SEPARATOR . '*',
|
foreach (glob(realpath($configuration['gallerydir']) . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR) as $directory) {
|
||||||
GLOB_ONLYDIR) as $directory) {
|
|
||||||
$basename = basename($directory);
|
$basename = basename($directory);
|
||||||
if (galleryExists($basename)) {
|
if (galleryExists($basename)) {
|
||||||
return $basename;
|
return $basename;
|
||||||
|
@ -217,13 +227,15 @@ function getCurrentGallery() {
|
||||||
* Maximalwert beachtet werden soll, wenn dieser Parameter @c true
|
* Maximalwert beachtet werden soll, wenn dieser Parameter @c true
|
||||||
* ist, wird die Höhe auf @a $maxdim skaliert, ansonsten die Breite
|
* ist, wird die Höhe auf @a $maxdim skaliert, ansonsten die Breite
|
||||||
*
|
*
|
||||||
* @return Pfad des skalierten Bildes relativ zu @a GALLERYPREFIX
|
* @return Pfad des skalierten Bildes relativ zu @a gallerydir
|
||||||
*/
|
*/
|
||||||
function getScaledImage($galleryname, $basename, $maxdim, $scaleheight=true) {
|
function getScaledImage($galleryname, $basename, $maxdim, $scaleheight=true) {
|
||||||
|
global $configuration;
|
||||||
|
|
||||||
if ($maxdim == 0) {
|
if ($maxdim == 0) {
|
||||||
debug_print_backtrace();
|
debug_print_backtrace();
|
||||||
}
|
}
|
||||||
$gallerydir = realpath(GALLERYPREFIX . DIRECTORY_SEPARATOR . $galleryname);
|
$gallerydir = realpath($configuration['gallerydir'] . DIRECTORY_SEPARATOR . $galleryname);
|
||||||
if ($scaleheight) {
|
if ($scaleheight) {
|
||||||
$scaleddir = sprintf("%s%sscaled_x%d", $galleryname,
|
$scaleddir = sprintf("%s%sscaled_x%d", $galleryname,
|
||||||
DIRECTORY_SEPARATOR, $maxdim);
|
DIRECTORY_SEPARATOR, $maxdim);
|
||||||
|
@ -231,7 +243,7 @@ function getScaledImage($galleryname, $basename, $maxdim, $scaleheight=true) {
|
||||||
$scaleddir = sprintf("%s%sscaled%dx_", $galleryname,
|
$scaleddir = sprintf("%s%sscaled%dx_", $galleryname,
|
||||||
DIRECTORY_SEPARATOR, $maxdim);
|
DIRECTORY_SEPARATOR, $maxdim);
|
||||||
}
|
}
|
||||||
$scaleddirpath = GALLERYPREFIX . DIRECTORY_SEPARATOR . $scaleddir;
|
$scaleddirpath = $configuration['gallerydir'] . DIRECTORY_SEPARATOR . $scaleddir;
|
||||||
if (!is_dir($scaleddirpath)) {
|
if (!is_dir($scaleddirpath)) {
|
||||||
// versuchen das Thumbnail-Verzeichnis anzulegen
|
// versuchen das Thumbnail-Verzeichnis anzulegen
|
||||||
$mkdir = @mkdir($scaleddirpath, 0755);
|
$mkdir = @mkdir($scaleddirpath, 0755);
|
||||||
|
@ -278,11 +290,11 @@ function getScaledImage($galleryname, $basename, $maxdim, $scaleheight=true) {
|
||||||
* und dem Ergebnis von getimagesize() als Werten ist.
|
* und dem Ergebnis von getimagesize() als Werten ist.
|
||||||
*/
|
*/
|
||||||
function getThumbNailInfo($galleryname) {
|
function getThumbNailInfo($galleryname) {
|
||||||
global $theme;
|
global $theme, $configuration;
|
||||||
|
|
||||||
$thumbsizes = array();
|
$thumbsizes = array();
|
||||||
$thumbdimsum = 2;
|
$thumbdimsum = 2;
|
||||||
foreach (glob(realpath(GALLERYPREFIX . DIRECTORY_SEPARATOR .
|
foreach (glob(realpath($configuration['gallerydir'] . DIRECTORY_SEPARATOR .
|
||||||
$galleryname) . DIRECTORY_SEPARATOR .
|
$galleryname) . DIRECTORY_SEPARATOR .
|
||||||
'*.jp{e,}g', GLOB_BRACE) as $filename) {
|
'*.jp{e,}g', GLOB_BRACE) as $filename) {
|
||||||
$basename = basename($filename);
|
$basename = basename($filename);
|
||||||
|
@ -293,7 +305,7 @@ function getThumbNailInfo($galleryname) {
|
||||||
$thumbfile = getScaledImage($galleryname, $basename, $theme->thumbsize,
|
$thumbfile = getScaledImage($galleryname, $basename, $theme->thumbsize,
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
if ($thumbsize = getimagesize(realpath(GALLERYPREFIX .
|
if ($thumbsize = getimagesize(realpath($configuration['gallerydir'] .
|
||||||
DIRECTORY_SEPARATOR .
|
DIRECTORY_SEPARATOR .
|
||||||
$thumbfile))) {
|
$thumbfile))) {
|
||||||
$thumbsizes[$basename] = array($thumbfile, $thumbsize);
|
$thumbsizes[$basename] = array($thumbfile, $thumbsize);
|
||||||
|
@ -320,8 +332,10 @@ function getThumbNailInfo($galleryname) {
|
||||||
* @see getGalleryConfig()
|
* @see getGalleryConfig()
|
||||||
*/
|
*/
|
||||||
function getGalleryLinks() {
|
function getGalleryLinks() {
|
||||||
|
global $configuration;
|
||||||
|
|
||||||
$retval = array();
|
$retval = array();
|
||||||
foreach (glob(realpath(GALLERYPREFIX) . DIRECTORY_SEPARATOR . '*',
|
foreach (glob(realpath($configuration['gallerydir']) . DIRECTORY_SEPARATOR . '*',
|
||||||
GLOB_ONLYDIR) as $directory) {
|
GLOB_ONLYDIR) as $directory) {
|
||||||
$basename = basename($directory);
|
$basename = basename($directory);
|
||||||
if (galleryExists($basename)) {
|
if (galleryExists($basename)) {
|
||||||
|
@ -359,9 +373,11 @@ function getGalleryLinks() {
|
||||||
* @see getThumbNailInfo()
|
* @see getThumbNailInfo()
|
||||||
*/
|
*/
|
||||||
function getAllThumbnails(&$thumbinfo) {
|
function getAllThumbnails(&$thumbinfo) {
|
||||||
|
global $configuration;
|
||||||
|
|
||||||
$retval = array();
|
$retval = array();
|
||||||
foreach ($thumbinfo[2] as $basename => $data) {
|
foreach ($thumbinfo[2] as $basename => $data) {
|
||||||
$retval[] = array('src' => GALLERYPREFIX . DIRECTORY_SEPARATOR . $data[0],
|
$retval[] = array('src' => $configuration['gallerydir'] . DIRECTORY_SEPARATOR . $data[0],
|
||||||
'sizes' => $data[1][3],
|
'sizes' => $data[1][3],
|
||||||
'alt' => getImageLabel($thumbinfo[1], $basename));
|
'alt' => getImageLabel($thumbinfo[1], $basename));
|
||||||
}
|
}
|
||||||
|
@ -383,23 +399,23 @@ function getAllThumbnails(&$thumbinfo) {
|
||||||
* @see getThumbNailInfo()
|
* @see getThumbNailInfo()
|
||||||
*/
|
*/
|
||||||
function getFirstPreview(&$thumbinfo) {
|
function getFirstPreview(&$thumbinfo) {
|
||||||
global $theme;
|
global $theme, $configuration;
|
||||||
|
|
||||||
reset($thumbinfo[2]);
|
reset($thumbinfo[2]);
|
||||||
$basename = key($thumbinfo[2]);
|
$basename = key($thumbinfo[2]);
|
||||||
$data = current($thumbinfo[2]);
|
$data = current($thumbinfo[2]);
|
||||||
$galleryname = $thumbinfo[1];
|
$galleryname = $thumbinfo[1];
|
||||||
$fullname = GALLERYPREFIX . DIRECTORY_SEPARATOR . $galleryname .
|
$fullname = $configuration['gallerypath'] . DIRECTORY_SEPARATOR . $galleryname .
|
||||||
DIRECTORY_SEPARATOR . $basename;
|
DIRECTORY_SEPARATOR . $basename;
|
||||||
$scaledimage = getScaledImage($galleryname, $basename,
|
$scaledimage = getScaledImage($galleryname, $basename,
|
||||||
$theme->previewsize, false);
|
$theme->previewsize, false);
|
||||||
$scaledimagesize = getimagesize(realpath(GALLERYPREFIX .
|
$scaledimagesize = getimagesize(realpath($configuration['gallerydir'] .
|
||||||
DIRECTORY_SEPARATOR .
|
DIRECTORY_SEPARATOR .
|
||||||
$scaledimage));
|
$scaledimage));
|
||||||
$label = getImageLabel($galleryname, $basename);
|
$label = getImageLabel($galleryname, $basename);
|
||||||
return array('title' => $label,
|
return array('title' => $label,
|
||||||
'full' => $fullname,
|
'full' => $fullname,
|
||||||
'src' => GALLERYPREFIX . DIRECTORY_SEPARATOR . $scaledimage,
|
'src' => $configuration['gallerypath'] . DIRECTORY_SEPARATOR . $scaledimage,
|
||||||
'alt' => $label,
|
'alt' => $label,
|
||||||
'sizes' => $scaledimagesize[3]);
|
'sizes' => $scaledimagesize[3]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,12 @@
|
||||||
* <http://www.gnu.org/licenses/>.
|
* <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$basedir = dirname(__file__);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inkludiert die Funktionsbibliothek.
|
* Inkludiert die Funktionsbibliothek.
|
||||||
*/
|
*/
|
||||||
require('includes/galleryfunctions.php');
|
require($basedir . '/includes/galleryfunctions.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name der aktuellen Galerie.
|
* Name der aktuellen Galerie.
|
||||||
|
@ -51,7 +53,7 @@ $scripts = array('js/jquery.js',
|
||||||
'js/jquery.colorBlend.js',
|
'js/jquery.colorBlend.js',
|
||||||
'js/jquery.lightbox.js',
|
'js/jquery.lightbox.js',
|
||||||
'scripts/ourhandlers.js');
|
'scripts/ourhandlers.js');
|
||||||
$styles = array('css/jquery.lightbox.css');
|
$styles = array();
|
||||||
|
|
||||||
$template = $theme->getTemplate();
|
$template = $theme->getTemplate();
|
||||||
|
|
||||||
|
|
Reference in a new issue