aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/ExtendedZip.php
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2016-08-31 06:32:54 +1000
committerGitHub <noreply@github.com>2016-08-31 06:32:54 +1000
commitb485d09847852efe935cd84f5f8f0ebf067c1f68 (patch)
treeca090d4dcb461dc46ba79d726c39cda388deeef6 /Zotlabs/Lib/ExtendedZip.php
parent202b757bc46d17b324f79751ce754e16ba737386 (diff)
parentad5c93d6738d705b9ca196cc7481c26a3a9b9962 (diff)
downloadvolse-hubzilla-b485d09847852efe935cd84f5f8f0ebf067c1f68.tar.gz
volse-hubzilla-b485d09847852efe935cd84f5f8f0ebf067c1f68.tar.bz2
volse-hubzilla-b485d09847852efe935cd84f5f8f0ebf067c1f68.zip
Merge pull request #506 from anaqreon/website-export
Website export
Diffstat (limited to 'Zotlabs/Lib/ExtendedZip.php')
-rw-r--r--Zotlabs/Lib/ExtendedZip.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/Zotlabs/Lib/ExtendedZip.php b/Zotlabs/Lib/ExtendedZip.php
new file mode 100644
index 000000000..a40110c55
--- /dev/null
+++ b/Zotlabs/Lib/ExtendedZip.php
@@ -0,0 +1,57 @@
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+namespace Zotlabs\Lib;
+
+/**
+ * Description of ExtendedZip
+ *
+ * @author andrew
+ */
+class ExtendedZip extends \ZipArchive {
+
+ // Member function to add a whole file system subtree to the archive
+ public function addTree($dirname, $localname = '') {
+ if ($localname)
+ $this->addEmptyDir($localname);
+ $this->_addTree($dirname, $localname);
+ }
+
+ // Internal function, to recurse
+ protected function _addTree($dirname, $localname) {
+ $dir = opendir($dirname);
+ while ($filename = readdir($dir)) {
+ // Discard . and ..
+ if ($filename == '.' || $filename == '..')
+ continue;
+
+ // Proceed according to type
+ $path = $dirname . '/' . $filename;
+ $localpath = $localname ? ($localname . '/' . $filename) : $filename;
+ if (is_dir($path)) {
+ // Directory: add & recurse
+ $this->addEmptyDir($localpath);
+ $this->_addTree($path, $localpath);
+ }
+ else if (is_file($path)) {
+ // File: just add
+ $this->addFile($path, $localpath);
+ }
+ }
+ closedir($dir);
+ }
+
+ // Helper function
+ public static function zipTree($dirname, $zipFilename, $flags = 0, $localname = '') {
+ $zip = new self();
+ $zip->open($zipFilename, $flags);
+ $zip->addTree($dirname, $localname);
+ $zip->close();
+ }
+
+}