| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | // wcf imports |
|---|
| 4 | require_once(WCF_DIR.'lib/page/AbstractPage.class.php'); |
|---|
| 5 | require_once(WCF_DIR.'lib/data/downloadDB/DownloadDBDataEditor.class.php'); |
|---|
| 6 | |
|---|
| 7 | /** |
|---|
| 8 | * Download Database Datei Download |
|---|
| 9 | * |
|---|
| 10 | * @author Robert "Tatzelwurm" Hempel |
|---|
| 11 | * @copyright 2007/2008 INSIDE das Hrspiel |
|---|
| 12 | * @license GNU LGPL http://www.gnu.org/licenses/lgpl.txt |
|---|
| 13 | * @package de.inside.wcf.DownloadDatabase |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | class DownloadDBFileDownloadPage extends AbstractPage { |
|---|
| 17 | |
|---|
| 18 | public $dataID; |
|---|
| 19 | private $fileName; |
|---|
| 20 | private $fileType; |
|---|
| 21 | private $link; |
|---|
| 22 | |
|---|
| 23 | public function readParameters() { |
|---|
| 24 | parent :: readParameters(); |
|---|
| 25 | if (isset($_REQUEST['dataID'])) $this->dataID = intval($_REQUEST['dataID']); |
|---|
| 26 | if (!$this->dataID){ |
|---|
| 27 | require_once(WCF_DIR.'lib/system/exception/NamedUserException.class.php'); |
|---|
| 28 | throw new NamedUserException(WCF::getLanguage()->get('wcf.dldb.wrongid')); |
|---|
| 29 | exit; |
|---|
| 30 | } |
|---|
| 31 | WCF::getCache()->addResource('dldbData', |
|---|
| 32 | WCF_DIR.'cache/cache.dldbData.php', |
|---|
| 33 | WCF_DIR.'lib/system/cache/CacheBuilderDLDBData.class.php'); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | public function show() { |
|---|
| 37 | $this->readDaten(); |
|---|
| 38 | // Anzahl der Downloads erhöhen |
|---|
| 39 | $sql = "UPDATE wcf".WCF_N."_dldb_data |
|---|
| 40 | SET downloads = downloads + 1 |
|---|
| 41 | WHERE `dataID` = ".$this->dataID; |
|---|
| 42 | $row = WCF::getDB()->registerShutdownUpdate($sql); |
|---|
| 43 | // reset cache |
|---|
| 44 | WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbData.php'); |
|---|
| 45 | if (!$this->fileType) { |
|---|
| 46 | if (FileUtil::isURL($this->link)) { |
|---|
| 47 | HeaderUtil::redirect($this->link,false); |
|---|
| 48 | exit; |
|---|
| 49 | } else { |
|---|
| 50 | $link = FileUtil::getRealPath(RELATIVE_WCF_DIR.$this->link); |
|---|
| 51 | $type = 'application/unknown'; |
|---|
| 52 | } |
|---|
| 53 | } else { |
|---|
| 54 | $dataset = new downloadDBDataEditor($this->dataID); |
|---|
| 55 | $link = FileUtil::getRealPath(RELATIVE_WCF_DIR.$dataset->getURL()); |
|---|
| 56 | $type = $this->fileType; |
|---|
| 57 | } |
|---|
| 58 | // Set Download Infos |
|---|
| 59 | @ header('Content-Description: File Transfer'); |
|---|
| 60 | @ header('Content-Type: '. $type); |
|---|
| 61 | @ header('Content-disposition: attachment; filename="' . $this->fileName . '"'); |
|---|
| 62 | @ header('Content-Length: ' . filesize($link)); |
|---|
| 63 | @ header('Pragma: no-cache'); |
|---|
| 64 | @ header('Expires: 0'); |
|---|
| 65 | // Start Download |
|---|
| 66 | @readfile($link); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | protected function readDaten() { |
|---|
| 70 | // Cache lesen |
|---|
| 71 | $data = WCF::getCache()->get('dldbData'); |
|---|
| 72 | foreach ($data as $daten) { |
|---|
| 73 | if ($daten['dataID'] == $this->dataID) { |
|---|
| 74 | $this->fileType = $daten['mimeType']; |
|---|
| 75 | $this->fileName = $daten['fileName']; |
|---|
| 76 | $this->link = $daten['link']; |
|---|
| 77 | // Kontrolle der Zugangsberechtigung; |
|---|
| 78 | $IDs = explode(',',$daten['groupcheck']); |
|---|
| 79 | $daten['canViewCat'] = false; |
|---|
| 80 | foreach ($IDs as $gruppe) { |
|---|
| 81 | if (in_array($gruppe, WCF::getUser()->getGroupIDs())) { |
|---|
| 82 | $daten['canViewCat'] = true; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | if ($daten['canViewCat'] != true){ |
|---|
| 86 | require_once(WCF_DIR.'lib/system/exception/PermissionDeniedException.class.php'); |
|---|
| 87 | throw new PermissionDeniedException(); |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | ?> |
|---|