Fixed a bug when bizou was operating at the top root of a site
[bizou.git] / index.php
index 61b22d6..828b06c 100644 (file)
--- a/index.php
+++ b/index.php
 
 require 'config.php';
 
+// global variables, globals should remain contant
+$scriptUrl = $_SERVER["SCRIPT_NAME"];
+$rootUrl = dirname($scriptUrl);
+if (substr($rootUrl, -1) !== '/') $rootUrl.='/';  // add a trailing / to rootUrl
+// $scriptUrl =  "/path/to/bizou/index.php"
+// $rootUrl =  "/path/to/bizou/"
+
 // load plugins
 $plugins = array();
 if (is_dir("plugins")) {
@@ -37,7 +44,7 @@ function plugins_include($phpFile)
 if (! function_exists('getImageLink')) {
 function getImageLink($imageSimplePath)
 {
-       return dirname($_SERVER["SCRIPT_NAME"]).'/'.IMAGES_DIR.$imageSimplePath;
+       return $GLOBALS['rootUrl'].IMAGES_DIR.$imageSimplePath;
 }
 }
 
@@ -86,7 +93,7 @@ function getPreview($imgFile, $maxSize = THUMB_SIZE)
                imagedestroy($newImg);
        }
 
-       return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
+       return $GLOBALS['rootUrl'].$newImgFile;
 }
 
 function getAlbumPreview($dir)
@@ -100,11 +107,6 @@ function getAlbumPreview($dir)
        return '';
 }
 
-$scriptUrl = $_SERVER["SCRIPT_NAME"];
-$rootUrl = dirname($scriptUrl);
-// $scriptUrl =  "/path/to/bizou/index.php"
-// $rootUrl =  "/path/to/bizou"
-
 // if url == http://localhost/photos/index.php/toto/titi, path_info == /toto/titi
 // if url == http://localhost/photos/index.php, path_info is not set
 // if url == http://localhost/photos/, path_info is not set
@@ -146,7 +148,7 @@ foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
                if ($ext == ".jpg" or $ext == ".png") {
                        $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => getImageLink("$simplePath/$file") );
                } else {
-                       $otherFiles[] = array( "name" => $file, "link" => "$rootUrl/$realDir/$file" );
+                       $otherFiles[] = array( "name" => $file, "link" => "$rootUrl$realDir/$file" );
                }
        }
 }
@@ -164,6 +166,7 @@ header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
 ?>
 <html>
 <head>
+<title> <?php echo $realDir ?> </title>
 <style type="text/css">
 body {
        margin-top: 0;
@@ -197,9 +200,14 @@ a {
        font-weight: bold;
        height: 0.6em;
 }
+#credit {
+       text-align: right;
+       font-size: 0.25cm;
+       color: gray;
+}
 </style>
 <?php foreach ($plugins as $p) if (is_file("plugins/$p/style.css")) { ?>
-       <link rel="stylesheet" type="text/css" href="<?php echo "$rootUrl/plugins/$p/style.css" ?>" />
+       <link rel="stylesheet" type="text/css" href="<?php echo $rootUrl."plugins/$p/style.css" ?>" />
 <?php } ?>
 </head>
 <body>
@@ -232,5 +240,9 @@ a {
        <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>
 <?php } ?>
 
+<p id="credit">
+Generated by <a href="http://www.positon.org/bizou/">Bizou</a>
+</p>
+
 </body>
 </html>