1
<?php
2
/*
3
4
Index photos in a directory using the PrettyPhoto javascript library.
5
Demonstration: http://aurelien.bompard.org/photos/
6
7
Copyright (C) 2008 Aurelien Bompard <aurelien@bompard.org>
8
9
This program is free software: you can redistribute it and/or modify
10
it under the terms of the GNU Affero General Public License as
11
published by the Free Software Foundation, either version 3 of the
12
License, or (at your option) any later version.
13
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
GNU Affero General Public License for more details.
18
19
You should have received a copy of the GNU Affero General Public License
20
along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22
*/
23
24
error_reporting(E_ALL);
25
26
$indexer_dir = dirname($_SERVER["SCRIPT_NAME"]);
27
28
// Read configuration
29
$config = array(
30
                "cols_dirs" => "3",
31
                "cols_files" => "5",
32
                "lang" => "fr",
33
                );
34
$config_file = dirname($_SERVER["SCRIPT_FILENAME"])."/config.ini";
35
if (is_file($config_file)) {
36
    $config = array_merge($config, parse_ini_file($config_file, false));
37
}
38
39
// Parse path
40
$path = urldecode(str_replace("?".$_SERVER["QUERY_STRING"],"", $_SERVER["REQUEST_URI"]));
41
$path_array = explode('/', $path);
42
$path_array = array_reverse($path_array);
43
if (!$path_array[0]) {
44
    array_shift($path_array);
45
}
46
$last_dir = $path_array[0];
47
$path_array = array_reverse($path_array);
48
$path = implode("/", $path_array);
49
$full_path = $_SERVER["DOCUMENT_ROOT"].$path;
50
51
function get_metadata($dir) {
52
    $metadata = array("general"=>array("title"=>basename($dir),"date"=>""));
53
    if (is_file($dir."/_infos.ini")) {
54
        $metadata = array_merge($metadata, parse_ini_file($dir."/_infos.ini", true));
55
        if (!isset($metadata["general"]["title"])) {
56
            $metadata["general"]["title"] = basename($dir);
57
        }
58
        if (isset($metadata["general"]["date"]) and !$metadata["general"]["date"]) {
59
            unset($metadata["general"]["date"]); // defined but empty, we remove it
60
        }
61
    }
62
    //print "<!-- $dir\n"; print_r($metadata); print "-->";
63
    return $metadata;
64
}
65
66
function is_top_dir() {
67
    global $path, $full_path, $indexer_dir, $config;
68
    if (isset($config["gallery_dir"]) and $config["gallery_dir"] == $path) {
69
        return true;
70
    } elseif (is_file($full_path."/.htaccess")) {
71
        $hta = file_get_contents($full_path."/.htaccess");
72
        if (preg_match(",.*\bDirectoryIndex\s+".$indexer_dir."/?index\.php\b.*,i",$hta)) {
73
            return true;
74
        }
75
    }
76
    return false;
77
}
78
79
$metadata = get_metadata($full_path);
80
81
$i18n = array();
82
include("lang/".$config["lang"].".php");
83
84
?>
85
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
86
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
87
<html xmlns="http://www.w3.org/1999/xhtml">
88
<head>
89
<title><?php echo htmlentities(utf8_decode($metadata["general"]["title"])) ?></title>
90
<!-- Meta Tags -->
91
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
92
<meta name="robots" content="index, follow" />
93
<meta name="generator" content="http://aurelien.bompard.org/projects/photo-imp" />
94
<?php
95
if (is_file($full_path."/_atom.xml")) {
96
    echo "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"".$i18n["recent"]."\" "
97
        ."href=\"".$_SERVER["REQUEST_URI"]."_atom.xml\" />\n";
98
}
99
?>
100
<!-- CSS -->
101
<link rel="stylesheet" href="<?php echo $indexer_dir ?>/css/prettyPhoto.css" type="text/css" />
102
<link rel="stylesheet" href="<?php echo $indexer_dir ?>/css/default.css" type="text/css" media="screen" />
103
<!-- Javascripts -->
104
<script type="text/javascript" src="<?php echo $indexer_dir ?>/scripts/jquery.js"></script>
105
<script type="text/javascript" src="<?php echo $indexer_dir ?>/scripts/jquery.prettyPhoto.js"></script>
106
<script type="text/javascript" src="<?php echo $indexer_dir ?>/scripts/photo-imp.js"></script>
107
<script type="text/javascript">
108
109
    $(document).ready(function(){
110
111
    var options = {
112
        animationSpeed: 'normal', /* fast/slow/normal */
113
//        padding: 40, /* padding for each side of the picture */
114
        opacity: 0.35, /* Value between 0 and 1 */
115
        showTitle: true, /* true/false */
116
        allowresize: false, /* true/false */
117
        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
118
        changepicturecallback: photo_imp_add_links,
119
        theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
120
    };
121
122
    function openElem(filename) {
123
        $("a[rel^='prettyPhoto']")
124
            .filter("[href*="+filename+"]")
125
            .eq(0).trigger("click");
126
    }
127
128
    $("a[rel^='prettyPhoto']").prettyPhoto(options);
129
130
<?php
131
if (isset($_GET["name"])) {
132
    echo "    openElem(\""
133
        .str_replace('/','',$_GET["name"]) // basic security check
134
        ."\");";
135
}
136
?>
137
138
});
139
140
    var i18n_link_direct = "<?php echo $i18n["link_direct"]; ?>";
141
    var i18n_link_image = "<?php echo $i18n["link_image"]; ?>";
142
143
</script>
144
</head>
145
<body>
146
<div id="container">
147
<?php
148
    // Link "up"
149
    if (!is_top_dir()) {
150
        echo '<p class="up"><a href=".." title="'.$i18n["up_one_dir"].'"><img src="'
151
            .$indexer_dir.'/images/up.png" alt="'.$i18n["up_one_dir"].'" /> ';
152
        $parent_metadata = get_metadata(dirname($full_path));
153
        echo $parent_metadata["general"]["title"]."</a></p>\n";
154
    }
155
    // Link to archive
156
    if (isset($metadata["general"]["archive"])) {
157
        echo '<p class="archive"><a href="'.$metadata["general"]["archive"].'" '
158
            .'title="'.$i18n["download_all"].'"><img src="'.$indexer_dir.'/images/archive.png" '
159
            .'alt="'.$i18n["download_all"].'" /></a></p>'."\n";
160
    }
161
    echo "<h1>" . htmlentities(utf8_decode($metadata["general"]["title"])) . "</h1>\n";
162
    if (isset($metadata["general"]["date"])) {
163
        echo "<h2>".$metadata["general"]["date"]."</h2>\n";
164
    }
165
    echo "<table>\n<tr>\n";
166
    // Load files and dirs
167
    $dir = opendir($full_path) or die("Cannot open directory :" . $path);
168
    $dirs = array();
169
    $files = array();
170
    while($file = readdir($dir))  // reading the dir
171
    {
172
        if($file == '.' or $file == '..' or strpos($file, "_") === 0 or strpos($file, ".") === 0)
173
        {
174
            continue;
175
        }
176
        if (is_dir($full_path."/".$file)) {
177
            $dirs []= $file;
178
        } else {
179
            $files []= $file;
180
        }
181
    }
182
    closedir($dir);
183
    sort($dirs,SORT_STRING);
184
    sort($files,SORT_STRING);
185
    // Show subdirs
186
    for ($i=1;$i<=count($dirs);$i++) {
187
        $dir = $dirs[$i-1];
188
        $dir_metadata = get_metadata($full_path."/".$dir);
189
        $title = htmlentities(utf8_decode($dir_metadata["general"]["title"]),ENT_QUOTES);
190
        echo '<td><a href="'. $path ."/". $dir .'" title="'.$title.'"><img src="'.$indexer_dir.'/images/';
191
        if (is_file($full_path."/".$dir."/.htaccess")) {
192
            echo "directory_password.png";
193
        } else {
194
            echo "directory.png";
195
        }
196
        echo '" alt="'.$title.'" /><br />'.$title;
197
        if (isset($dir_metadata["general"]["date"])) {
198
            echo "<br /><span class='date'>".$dir_metadata["general"]["date"]."</span>";
199
        }
200
        echo "</a></td>\n";
201
        if($i % intval($config["cols_dirs"]) == 0) {
202
            echo "</tr>\n<tr>";
203
        }
204
    }
205
    if ($dirs and $files) {
206
        echo "</tr>\n<tr>";
207
    }
208
    // Show files
209
    for ($i=1;$i<=count($files);$i++) {
210
        $file = $files[$i-1];
211
        $last_dot = strrpos($file, ".");
212
        $basename = substr($file, 0, $last_dot);
213
        $extension = substr($file, $last_dot+1);
214
        if ($last_dot !== false && strtolower($extension) == "flv") {
215
            $href = $indexer_dir ."/player_flv_maxi.swf?flashvars=config=".$indexer_dir."/player_flv_maxi.txt&amp;flv=". $path ."/". $file;
216
            $extension = "jpg"; // Thumbnail will be in jpg
217
            /* Not needed with this FLV player
218
            if (isset($metadata[$file]["height"])) {
219
                $href .= "&amp;height=".$metadata[$file]["height"];
220
            }
221
            if (isset($metadata[$file]["width"])) {
222
                $href .= "&amp;width=".$metadata[$file]["width"];
223
            }*/
224
        } else {
225
            $href = $path ."/". $file;
226
        }
227
        echo "<td><a href='". $href ."' rel='prettyPhoto[gallery]'";
228
        if (isset($metadata[$file]["title"])) {
229
            echo " title='".htmlentities(utf8_decode($metadata[$file]["title"]),ENT_QUOTES)."'";
230
        }
231
        echo "><img src='". $path ."/_thumbs/". $basename .".". $extension ."'";
232
        echo " alt='' /></a></td>\n";
233
        if($i % intval($config["cols_files"]) == 0 && $i != count($files)) {
234
            echo "</tr>\n<tr>";
235
        }
236
    }
237
?>
238
        </tr>
239
    </table>
240
</div>
241
<p id="footer">Powered by <a href="http://aurelien.bompard.org/projects/photo-imp">Photo-Imp</a></p>
242
</body>
243
</html>