Added the tar plugin
authorMarc MAURICE <dooblempub@positon.org>
Fri, 3 Jun 2011 16:40:20 +0000 (18:40 +0200)
committerMarc MAURICE <dooblempub@positon.org>
Fri, 3 Jun 2011 16:40:20 +0000 (18:40 +0200)
plugins/tar/after_content.php [new file with mode: 0644]
plugins/tar/tar.php [new file with mode: 0644]
template.php

diff --git a/plugins/tar/after_content.php b/plugins/tar/after_content.php
new file mode 100644 (file)
index 0000000..8629df6
--- /dev/null
@@ -0,0 +1,5 @@
+<?php if ($GLOBALS['imageFiles'] or $GLOBALS['otherFiles']) { ?>
+<div style="text-align: center; font-size: 0.25cm;">
+<a href="<?php echo $GLOBALS['rootUrl']."plugins/tar/tar.php".$GLOBALS['simplePath'] ?>">Download all files in this directory</a>
+</div>
+<?php } ?>
diff --git a/plugins/tar/tar.php b/plugins/tar/tar.php
new file mode 100644 (file)
index 0000000..9395e41
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+$bizouRootFromHere = '../..';
+require "$bizouRootFromHere/config.php";
+
+if (isset($_SERVER["PATH_INFO"])) {
+       $simplePath = $_SERVER["PATH_INFO"];
+} else {
+       $simplePath = '/';
+}
+
+if (strpos($simplePath, '..') !== false) die(".. found in url");
+
+$realDir = "$bizouRootFromHere/".IMAGES_DIR.$simplePath;
+
+if ( ! is_dir($realDir) ) {
+       header("HTTP/1.1 404 Not Found");
+       die("Directory Not Found");
+}
+
+# change to the parent directory
+chdir(dirname($realDir));
+
+$filesarg = escapeshellarg(basename($realDir))."/*";
+
+$out = exec("tar --no-recursion --totals -cf /dev/null $filesarg 2>&1");
+preg_match('/^Total bytes written: ([0-9]+) /', $out, $matches);
+$totalsize = $matches[1];
+
+#$out = exec("du -c $filesarg");
+#preg_match('/^([0-9]+).*total$/', $out, $matches);
+#$totalsize = $matches[1] * 1024;
+
+#var_dump($totalsize);
+
+#var_dump("tar --no-recursion -c $filesarg");
+#die();
+
+header("Content-Length: $totalsize");
+header('Content-Type: application/x-tar');
+header('Content-Disposition: attachment; filename="'.basename($realDir).'.tar"');
+
+passthru("tar --no-recursion -c $filesarg");
+
+?>
index 90ca799..34443c2 100644 (file)
@@ -74,6 +74,8 @@ a {
        <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>
 <?php } ?>
 
+<?php plugins_include("after_content.php") ?>
+
 <p id="credit">
 Generated by <a href="http://www.positon.org/bizou/">Bizou</a>
 </p>