honor jpeg orientation
[bizou.git] / index.php
1 <?php
2 /*
3     Bizou - a (french) KISS php image gallery
4     Copyright (C) 2010  Marc MAURICE
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 require 'config.php';
21
22 // global variables, globals should remain contant
23 $scriptUrl = $_SERVER["SCRIPT_NAME"];
24 $rootUrl = dirname($scriptUrl);
25 if (substr($rootUrl, -1) !== '/') $rootUrl.='/';  // add a trailing / to rootUrl
26 // $scriptUrl =  "/path/to/bizou/index.php"
27 // $rootUrl =  "/path/to/bizou/"
28
29 require 'functions.php';
30
31
32 // if url == http://localhost/photos/index.php/toto/titi, path_info == /toto/titi
33 // if url == http://localhost/photos/index.php, path_info is not set
34 // if url == http://localhost/photos/, path_info is not set
35 // if path_info is not set, we are at top level, so we redirect to /photos/index.php/
36 if (! isset($_SERVER["PATH_INFO"])) {
37         header("Location: $scriptUrl/");
38         exit();
39 }
40
41 // simplePath is the simple path to the directory
42 // extract /path/to/dir/ from /index.php/path/to/dir/
43 $simplePath = getPathInfo();
44
45 # realDir is the directory in filesystem
46 # seen from current script directory
47 $realDir = IMAGES_DIR.$simplePath;
48
49 if (! is_dir($realDir)) {
50         header("HTTP/1.1 404 Not Found");
51         die("Directory Not Found");
52 }
53
54 $folders = array();
55 $imageFiles = array();
56 $otherFiles = array();
57
58 foreach (scandir($realDir) as $file) if ($file[0] != '.')
59 {
60         if (is_dir("$realDir/$file"))
61         {
62                 $folders[] = array( "name" => $file, "file" => "$realDir/$file", "link" => "$scriptUrl$simplePath/$file" );
63         }
64         else
65         {
66                 $ext = strtolower(substr($file, -4));
67                 if ($ext == ".jpg" or $ext == ".png") {
68                         $imageFiles[] = array( "name" => $file, "file" => "$realDir/$file", "link" => getImageLink("$simplePath/$file") );
69                 } else {
70                         $otherFiles[] = array( "name" => $file, "link" => "$rootUrl$realDir/$file" );
71                 }
72         }
73 }
74
75 if (dirname($simplePath) !== '')
76         $parentLink = $scriptUrl.dirname($simplePath);
77 else
78         $parentLink = "";
79
80 plugins_include("before_tpl.php");
81
82 ///// template starts here /////
83 header('Content-Type: text/html; charset=utf-8');
84 header('Cache-Control: max-age=3600');
85
86 require 'template.php';
87
88 ?>