diff options
author | Andrew Manning <tamanning@zoho.com> | 2016-08-20 15:22:30 -0400 |
---|---|---|
committer | Andrew Manning <tamanning@zoho.com> | 2016-08-20 15:22:30 -0400 |
commit | 80ed05d45d0e9f7f23848919a3a8af388988fdd9 (patch) | |
tree | 1e37968678c75eac9dc062db721dc291db23f1d0 /Zotlabs/Lib | |
parent | cf93d9c3b42a4ab1dd9c4199b3b0711cc41b2dbb (diff) | |
download | volse-hubzilla-80ed05d45d0e9f7f23848919a3a8af388988fdd9.tar.gz volse-hubzilla-80ed05d45d0e9f7f23848919a3a8af388988fdd9.tar.bz2 volse-hubzilla-80ed05d45d0e9f7f23848919a3a8af388988fdd9.zip |
Export of pages and their layouts to a zip file works. Bug on importing the exported zip file for pages.
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r-- | Zotlabs/Lib/ExtendedZip.php | 57 |
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(); + } + +} |