Did some css improvements : parent folder link and non album directories
[bizou.git] / index.php
index c20a4dc..61b22d6 100644 (file)
--- a/index.php
+++ b/index.php
 
 require 'config.php';
 
+// load plugins
+$plugins = array();
+if (is_dir("plugins")) {
+       $plugins = scandir("plugins");
+       array_shift($plugins); array_shift($plugins); // remove . and ..
+       foreach ($plugins as $p) if (is_file("plugins/$p/functions.php"))
+               require "plugins/$p/functions.php";
+}
+
+function plugins_include($phpFile)
+{
+       foreach ($GLOBALS['plugins'] as $p) if (is_file("plugins/$p/$phpFile"))
+               require "plugins/$p/$phpFile";
+}
+
+if (! function_exists('getImageLink')) {
+function getImageLink($imageSimplePath)
+{
+       return dirname($_SERVER["SCRIPT_NAME"]).'/'.IMAGES_DIR.$imageSimplePath;
+}
+}
+
 function getPreview($imgFile, $maxSize = THUMB_SIZE)
 {
        # example: data/myalbum/100.mypic.jpg
@@ -78,27 +100,34 @@ function getAlbumPreview($dir)
        return '';
 }
 
-$scriptUrlPath = $_SERVER["SCRIPT_NAME"];
+$scriptUrl = $_SERVER["SCRIPT_NAME"];
+$rootUrl = dirname($scriptUrl);
+// $scriptUrl =  "/path/to/bizou/index.php"
+// $rootUrl =  "/path/to/bizou"
 
-// if url == http://localhost/photos/index/toto/titi, path_info == /toto/titi
-// if url == http://localhost/photos/index, path_info is not set
+// 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
-// if path_info is not set, we are at top level, so we redirect to /photos/index/
+// if path_info is not set, we are at top level, so we redirect to /photos/index.php/
 if (! isset($_SERVER["PATH_INFO"])) {
-       header("Location: $scriptUrlPath/");
+       header("Location: $scriptUrl/");
        exit();
 }
 
-$shortPath = $_SERVER["PATH_INFO"];
-if ($shortPath == '/') $shortPath = '';
+# simplePath is the simple path to the image
+# /index.php/toto/titi => simplePath == /toto/titi
+$simplePath = $_SERVER["PATH_INFO"];
+if ($simplePath == '/') $simplePath = '';
 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
-if (strpos($shortPath, '..') !== false) die(".. found in url");
+if (strpos($simplePath, '..') !== false) die(".. found in url");
 
 $folders = array();
 $imageFiles = array();
 $otherFiles = array();
 
-$realDir = IMAGES_DIR.$shortPath;
+# realDir is the directory in filesystem
+# seen from current script directory
+$realDir = IMAGES_DIR.$simplePath;
 
 if (! is_dir($realDir)) {
        header("HTTP/1.1 404 Not Found");
@@ -109,27 +138,21 @@ foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
 {
        if (is_dir("$realDir/$file"))
        {
-               $folders[] = array( "name" => $file, "link" => "$scriptUrlPath$shortPath/$file", "preview" => getAlbumPreview("$realDir/$file") );
+               $folders[] = array( "name" => $file, "link" => "$scriptUrl$simplePath/$file", "preview" => getAlbumPreview("$realDir/$file") );
        }
        else
        {
                $ext = strtolower(substr($file, -4));
                if ($ext == ".jpg" or $ext == ".png") {
-                       if (USE_VIEWER)
-                               $link = dirname($scriptUrlPath)."/view.php$shortPath/$file";
-                       else
-                               $link = dirname($scriptUrlPath)."/$realDir/$file";
-
-                       $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => $link );
-
+                       $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => getImageLink("$simplePath/$file") );
                } else {
-                       $otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" );
+                       $otherFiles[] = array( "name" => $file, "link" => "$rootUrl/$realDir/$file" );
                }
        }
 }
 
-if (dirname($shortPath) !== '')
-       $parentLink = $scriptUrlPath.dirname($shortPath);
+if (dirname($simplePath) !== '')
+       $parentLink = $scriptUrl.dirname($simplePath);
 else
        $parentLink = "";
 
@@ -143,7 +166,8 @@ header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
 <head>
 <style type="text/css">
 body {
-       padding-top: 2em;
+       margin-top: 0;
+       font-family: sans-serif;
 }
 img {
        border: 0;
@@ -154,40 +178,48 @@ a {
 .square {
        display: inline-block;
 }
-.image {
-       width: <?php echo THUMB_SIZE ?>px;
-       height: <?php echo THUMB_SIZE ?>px;
+.image, .foldername, .image_nopreview, .foldername_nopreview {
        display: table-cell;
-       text-align: center;
        vertical-align: middle;
 }
-.foldername {
+.image, .image_nopreview {
+       width: <?php echo THUMB_SIZE ?>px;
+       text-align: center;
+}
+.image, .foldername {
        height: <?php echo THUMB_SIZE ?>px;
-       display: table-cell;
-       vertical-align: middle;
+}
+.foldername, .foldername_nopreview {
+       padding-left: 1ex;
 }
 #parentfolder {
-       position: fixed;
        font-size: 4em;
        font-weight: bold;
-       top: 0;
-       left: 0;
+       height: 0.6em;
 }
 </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" ?>" />
+<?php } ?>
 </head>
 <body>
 
+<div id="parentfolder"><a href="<?php echo $parentLink ?>">
 <?php if ($parentLink !== '') { ?>
-       <div id="parentfolder"><a href="<?php echo $parentLink ?>">^</a></div>
+^
 <?php } ?>
+&nbsp;</a></div>
+
+<?php plugins_include("before_content.php") ?>
 
 <?php foreach($folders as $folder) { ?>
        <div class="folder">
        <?php if ($folder["preview"] === "") { ?>
-               <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a>
+               <div class="square"><div class="image_nopreview"> - </div></div>
+               <div class="square"><div class="foldername_nopreview"> <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a> </div></div>
        <?php } else { ?>
-               <div class="square"><div class="image"><a href="<?php echo $folder["link"] ?>"><img src="<?php echo $folder["preview"] ?>" /></a></div></div>
-               <div class="square"><div class="foldername"><a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a></div></div>
+               <div class="square"><div class="image"> <a href="<?php echo $folder["link"] ?>"><img src="<?php echo $folder["preview"] ?>" /></a> </div></div>
+               <div class="square"><div class="foldername"> <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a> </div></div>
        <?php } ?>
        </div>
 <?php } ?>