]> git.lizzy.rs Git - dirlistozxa.git/blobdiff - dirlistozxa.php
gen-thumbs: generate video thumbnails
[dirlistozxa.git] / dirlistozxa.php
index 6d3c4b5e45a7c0c092945d8c1675656065549ca7..eff24698b0be349ea63e4100b30d2c1b3bde3588 100644 (file)
@@ -1,13 +1,28 @@
 <?php
+/* dirlistozxa - Basic directory lister script written in PHP
+ * Copyright (C) 2023 ROllerozxa
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * This software is best enjoyed with soused herring!
+ */
+
 // Configuration:
 
 // List of filenames (and folder names) that should be ignored.
 $ignore_file_list = [
-       '.htaccess', '.htpasswd',       // Apache junk files
-       'Thumbs.db', '.DS_Store',       // OS junk files
-       'index.php', 'index.html',      // Potential other index files
-       '.git', 'vendor',                       // Dev
-       'dirlistozxa.php', '.dirlistozxa', '.thumbs', 'gen-thumbs' // dirlistozxa
+       'dirlistozxa.php', 'gen-thumbs' // dirlistozxa
 ];
 
 // ================
@@ -16,6 +31,9 @@ $ignore_file_list = [
 // nginx with default configuration (merge_slashes) doesn't actually need this.
 $_SERVER['REQUEST_URI'] = str_replace('../', '', $_SERVER['REQUEST_URI']);
 
+// Allow spaces and other heretical stuff in folder names.
+$_SERVER['REQUEST_URI'] = urldecode($_SERVER['REQUEST_URI']);
+
 $folder = str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']);
 $path = $_SERVER['DOCUMENT_ROOT'].$folder;
 
@@ -42,8 +60,12 @@ function row($name, $date, $size, $thumb) {
        };
 
        return sprintf(
-               '<tr><td class="tum"><img src="%s" loading="lazy"></td><td><a href="%s">%s</a></td><td>%s</td><td class="r">%s</td></tr>',
-       $img, $name, $name, $date, $size);
+               '<tr>
+                       <td class="tum"><a href="%s"><img src="%s" loading="lazy"></td>
+                       <td><a href="%s">%s</a></td>
+                       <td>%s</td><td class="r">%s</td>
+               </tr>',
+       $name, $img, $name, $name, $date, $size);
 }
 
 function build_blocks($items) {
@@ -54,7 +76,7 @@ function build_blocks($items) {
        $objects = [ 'directories' => [], 'files' => [] ];
 
        foreach ($items as $item) {
-               if ($item == '..' || $item == '.' || in_array($item, $ignore_file_list)) continue;
+               if (in_array($item, $ignore_file_list) || str_starts_with($item, '.')) continue;
 
                if (is_dir($path.$item))
                        $objects['directories'][$item] = $item;