1: <?php
2: /**
3: * XOOPS zip downloader
4: *
5: * You may not change or alter any portion of this comment or credits
6: * of supporting developers from this source code or any supporting source code
7: * which is considered copyrighted (c) material of the original comment or credit authors.
8: * This program is distributed in the hope that it will be useful,
9: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
13: * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14: * @package kernel
15: * @since 2.0.0
16: * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/
17: */
18:
19: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
20:
21: include_once $GLOBALS['xoops']->path('class/downloader.php');
22: include_once $GLOBALS['xoops']->path('class/class.zipfile.php');
23:
24: /**
25: * Abstract base class for forms
26: *
27: * @author Kazumi Ono <onokazu@xoops.org>
28: * @author John Neill <catzwolf@xoops.org>
29: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
30: * @package kernel
31: * @subpackage Xoops Zip Downloader
32: * @access public
33: */
34: class XoopsZipDownloader extends XoopsDownloader
35: {
36: /**
37: * Constructor
38: *
39: * @param string $ext
40: * @param string $mimyType
41: * @return XoopsZipDownloader
42: */
43:
44: public function __construct($ext = '.zip', $mimyType = 'application/x-zip')
45: {
46: $this->archiver = new Zipfile();
47: $this->ext = trim($ext);
48: $this->mimetype = trim($mimyType);
49: }
50:
51: /**
52: * Add file
53: *
54: * @param string $filepath
55: * @param string $newfilename
56: */
57: public function addFile($filepath, $newfilename = null)
58: {
59: // Read in the file's contents
60: $fp = fopen($filepath, 'r');
61: $data = fread($fp, filesize($filepath));
62: fclose($fp);
63: $filename = (isset($newfilename) && trim($newfilename) != '') ? trim($newfilename) : $filepath;
64: $this->archiver->addFile($data, $filename, filemtime($filename));
65: }
66:
67: /**
68: * Add Binary File
69: *
70: * @param string $filepath
71: * @param string $newfilename
72: */
73: public function addBinaryFile($filepath, $newfilename = null)
74: {
75: // Read in the file's contents
76: $fp = fopen($filepath, 'rb');
77: $data = fread($fp, filesize($filepath));
78: fclose($fp);
79: $filename = (isset($newfilename) && trim($newfilename) != '') ? trim($newfilename) : $filepath;
80: $this->archiver->addFile($data, $filename, filemtime($filename));
81: }
82:
83: /**
84: * Add File Data
85: *
86: * @param string $data
87: * @param string $filename
88: * @param int|mixed $time
89: */
90: public function addFileData(&$data, $filename, $time = 0)
91: {
92: $this->archiver->addFile($data, $filename, $time);
93: }
94:
95: /**
96: * Add Binary File Data
97: *
98: * @param string $data
99: * @param string $filename
100: * @param int|string $time
101: */
102: public function addBinaryFileData(&$data, $filename, $time = 0)
103: {
104: $this->addFileData($data, $filename, $time);
105: }
106:
107: /**
108: * Fownload Data as a Zip file
109: *
110: * @param string $name
111: * @param bool $gzip
112: */
113: public function download($name, $gzip = true)
114: {
115: $this->_header($name . $this->ext);
116: echo $this->archiver->file();
117: }
118: }
119: