XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
tardownloader.php
Go to the documentation of this file.
1 <?php
19 defined('XOOPS_ROOT_PATH') or die('Restricted access');
20 
24 include_once XOOPS_ROOT_PATH . '/class/downloader.php';
28 include_once XOOPS_ROOT_PATH . '/class/class.tar.php';
29 
31 {
38  function XoopsTarDownloader($ext = '.tar.gz', $mimyType = 'application/x-gzip')
39  {
40  $this->archiver = new tar();
41  $this->ext = trim($ext);
42  $this->mimeType = trim($mimyType);
43  }
44 
51  function addFile($filepath, $newfilename = null)
52  {
53  $this->archiver->addFile($filepath);
54  if (isset($newfilename)) {
55  // dirty, but no other way
56  for($i = 0; $i < $this->archiver->numFiles; $i ++) {
57  if ($this->archiver->files[$i]['name'] == $filepath) {
58  $this->archiver->files[$i]['name'] = trim($newfilename);
59  break;
60  }
61  }
62  }
63  }
64 
71  function addBinaryFile($filepath, $newfilename = null)
72  {
73  $this->archiver->addFile($filepath, true);
74  if (isset($newfilename)) {
75  // dirty, but no other way
76  for($i = 0; $i < $this->archiver->numFiles; $i ++) {
77  if ($this->archiver->files[$i]['name'] == $filepath) {
78  $this->archiver->files[$i]['name'] = trim($newfilename);
79  break;
80  }
81  }
82  }
83  }
84 
92  function addFileData(&$data, $filename, $time = 0)
93  {
94  $dummyfile = XOOPS_CACHE_PATH . '/dummy_' . time() . '.html';
95  $fp = fopen($dummyfile, 'w');
96  fwrite($fp, $data);
97  fclose($fp);
98  $this->archiver->addFile($dummyfile);
99  unlink($dummyfile);
100  // dirty, but no other way
101  for($i = 0; $i < $this->archiver->numFiles; $i ++) {
102  if ($this->archiver->files[$i]['name'] == $dummyfile) {
103  $this->archiver->files[$i]['name'] = $filename;
104  if ($time != 0) {
105  $this->archiver->files[$i]['time'] = $time;
106  }
107  break;
108  }
109  }
110  }
111 
119  function addBinaryFileData(&$data, $filename, $time = 0)
120  {
121  $dummyfile = XOOPS_CACHE_PATH . '/dummy_' . time() . '.html';
122  $fp = fopen($dummyfile, 'wb');
123  fwrite($fp, $data);
124  fclose($fp);
125  $this->archiver->addFile($dummyfile, true);
126  unlink($dummyfile);
127  // dirty, but no other way
128  for($i = 0; $i < $this->archiver->numFiles; $i ++) {
129  if ($this->archiver->files[$i]['name'] == $dummyfile) {
130  $this->archiver->files[$i]['name'] = $filename;
131  if ($time != 0) {
132  $this->archiver->files[$i]['time'] = $time;
133  }
134  break;
135  }
136  }
137  }
138 
145  function download($name, $gzip = true)
146  {
147  $this->_header($name . $this->ext);
148  echo $this->archiver->toTarOutput($name . $this->ext, $gzip);
149  }
150 }
151 
152 ?>