* @package de.inside.wcf.DownloadDatabase */ class DownloadDBData extends DatabaseObject { /** * Creates a new File object. * * @param array $row * @param integer $dataID */ public function __construct($dataID, $row = null) { if ($dataID != null) { $sql = "SELECT * FROM wcf".WCF_N."_dldb_data WHERE dataID = ".$dataID; $row = WCF::getDB()->getFirstRow($sql); } parent::__construct($row); } /** * Returns the url to this file. * * @return string */ public function getURL() { if(file_exists(RELATIVE_WCF_DIR.DOWNLOADDB_FILE_DIR . intval($this->dataID) . '_' . StringUtil::encodeHTML($this->fileName))){ return DOWNLOADDB_FILE_DIR . intval($this->dataID) . '_' . StringUtil::encodeHTML($this->fileName); } return DOWNLOADDB_FILE_DIR . 'Upload-' . $this->dataID . '.' . $this->fileExtension; } /** * Deletes this data in database, filesystem and clears cache */ public function delete() { // delete file $this->deleteFile($this->fileName); // delete Preview $this->deletePreview($this->previewFile); // delete database entry $sql = "DELETE FROM wcf".WCF_N."_dldb_data WHERE dataID = ".$this->dataID; WCF::getDB()->sendQuery($sql); // clear Cache $this->resetCache(); } /** * Deletes this File. * @param string $fName */ public function deleteFile($fName) { // delete file if(file_exists(RELATIVE_WCF_DIR.DOWNLOADDB_FILE_DIR . intval($this->dataID) . '_' . StringUtil::encodeHTML($fName))){ @unlink(WCF_DIR.DOWNLOADDB_FILE_DIR . $this->dataID . '_' . $fName); } else { @unlink(WCF_DIR . DOWNLOADDB_FILE_DIR . 'Upload-' .$this->dataID . '.' . $this->fileExtension); } } /** * Deletes this PreviewFile. * @param string $fName */ public function deletePreview($fName) { // delete file if(file_exists(RELATIVE_WCF_DIR.DOWNLOADDB_PREVIEW_DIR . $this->dataID . '_' . $fName)){ @unlink(WCF_DIR . DOWNLOADDB_PREVIEW_DIR . $this->dataID . '_' . $fName); @unlink(WCF_DIR . DOWNLOADDB_PREVIEW_DIR . 'thumbnail-' . $this->dataID . '_' . $fName); } else { $fExt = StringUtil::toLowerCase(StringUtil::substring($fName, StringUtil::lastIndexOf($fName, '.') + 1)); @unlink(WCF_DIR . DOWNLOADDB_PREVIEW_DIR . 'Preview-' . $this->dataID . '.' . $fExt); @unlink(WCF_DIR . DOWNLOADDB_PREVIEW_DIR . 'thumbnail-' . $this->dataID . '.' . $fExt); } } public static function resetCache() { // reset cache WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbData.php'); WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbKat.php'); } /** * get icon for filetype */ public static function setFileTypeIcon($mime_type) { switch($mime_type) { case (preg_match('/x-3dmf/i', $mime_type) == true): $type = 'mime_3dm.png'; break; case (preg_match('/x-authorware-bin/i', $mime_type) == true): $type = 'mime_aab.png'; break; case (preg_match('/x-authorware-map/i', $mime_type) == true): $type = 'mime_aam.png'; break; case (preg_match('/x-authorware-seg/i', $mime_type) == true): $type = 'mime_aas.png'; break; case (preg_match('/abc/i', $mime_type) == true): $type = 'mime_abc.png'; break; case (preg_match('/animaflex/i', $mime_type) == true): $type = 'mime_afl.png'; break; case (preg_match('/ace/i', $mime_type) == true): $type = 'mime_ace.gif'; break; case (preg_match('/aiff/i', $mime_type) == true): $type = 'mime_aiff.png'; break; case (preg_match('/postscript/i', $mime_type) == true): $type = 'mime_doc.gif'; break; case (preg_match('/aim/i', $mime_type) == true): $type = 'mime_aim.png'; break; case (preg_match('/intra/i', $mime_type) == true): $type = 'mime_aip.png'; break; case (preg_match('/animation/i', $mime_type) == true): $type = 'mime_ani.png'; break; case (preg_match('/communicator/i', $mime_type) == true): $type = 'mime_aos.png'; break; case (preg_match('/arc/i', $mime_type) == true): $type = 'mime_arc.gif'; break; case (preg_match('/arj/i', $mime_type) == true): $type = 'mime_arj.gif'; break; case (preg_match('/x-jg/i', $mime_type) == true): $type = 'mime_art.png'; break; case (preg_match('/x-ms-asf/i', $mime_type) == true): $type = 'mime_asf.png'; break; case (preg_match('/x-ms-asf-plugin/i', $mime_type) == true || preg_match('/x-mplayer2/i', $mime_type) == true): $type = 'mime_asx.png'; break; case (preg_match('/x-asm/i', $mime_type) == true): $type = 'mime_asm.png'; break; case (preg_match('/asp/i', $mime_type) == true): $type = 'mime_asp.png'; break; case (preg_match('/x-au/i', $mime_type) == true): $type = 'mime_au.png'; break; case (preg_match('/msvideo/i', $mime_type) == true): $type = 'mime_avi.gif'; break; case (preg_match('/avs/i', $mime_type) == true): $type = 'mime_avs.gif'; break; /* B */ case (preg_match('/bcpio/i', $mime_type) == true): $type = 'mime_bcpio.png'; break; case (preg_match('/bh/i', $mime_type) == true): $type = 'mime_bh.gif'; break; case (preg_match('/binary/i', $mime_type) == true): $type = 'mime_bin.png'; break; case (preg_match('/bmp/i', $mime_type) == true): $type = 'mime_bmp.png'; break; case (preg_match('/x-bzip/i', $mime_type) == true): $type = 'mime_bz.png'; break; /* C */ case (preg_match('/cab/i', $mime_type) == true): $type = 'mime_cab.gif'; break; case (preg_match('/clariscad/i', $mime_type) == true): $type = 'mime_ccad.png'; break; case (preg_match('/cocoa/i', $mime_type) == true): $type = 'mime_cco.png'; break; case (preg_match('/cdf/i', $mime_type) == true): $type = 'mime_cdf.png'; break; case (preg_match('/cert/i', $mime_type) == true): $type = 'mime_cer.png'; break; case (preg_match('/x-chat/i', $mime_type) == true): $type = 'mime_chat.png'; break; case (preg_match('/java-byte-code/i', $mime_type) == true || preg_match('/x-java-class/i', $mime_type) == true): $type = 'mime_class.png'; break; case (preg_match('/x-cpio/i', $mime_type) == true): $type = 'mime_cpio.png'; break; case (preg_match('/compactpro/i', $mime_type) == true || preg_match('/cpt/i', $mime_type) == true): $type = 'mime_cpt.png'; break; case (preg_match('/crl/i', $mime_type) == true): $type = 'mime_crl.png'; break; case (preg_match('/csh/i', $mime_type) == true): $type = 'mime_csh.png'; break; case (preg_match('/css/i', $mime_type) == true || preg_match('/x-pointplus/i', $mime_type) == true): $type = 'mime_css.png'; break; /* D */ case (preg_match('/msword/i', $mime_type) == true): $type = 'mime_doc.gif'; break; /* E */ /* F */ /* G */ case (preg_match('/gif/i', $mime_type) == true): $type = 'mime_gif.png'; break; case (preg_match('/gzip/i', $mime_type) == true || preg_match('/x-compressed/i', $mime_type) == true): $type = 'mime_gzip.gif'; break; /* H */ case (preg_match('/html/i', $mime_type) == true): $type = 'mime_html.gif'; break; /* I */ case (preg_match('/img/i', $mime_type) == true || preg_match('/pict/i', $mime_type) == true): $type = 'mime_img.gif'; break; /* J */ case (preg_match('/jar/i', $mime_type) == true): $type = 'mime_jar.gif'; break; case (preg_match('/jpeg/i', $mime_type) == true): $type = 'mime_jpg.png'; break; /* K */ /* L */ case (preg_match('/lha/i', $mime_type) == true): $type = 'mime_lha.gif'; break; case (preg_match('/lzh/i', $mime_type) == true): $type = 'mime_lzh.png'; break; /* M */ case (preg_match('/mpeg3/i', $mime_type) == true || preg_match('/mpeg-3/i', $mime_type) == true): $type = 'mime_mp3.png'; break; case (preg_match('/mpeg/i', $mime_type) == true || preg_match('/mpequrl/i', $mime_type) == true): $type = 'mime_mpeg.gif'; break; /* N */ /* O */ case (preg_match('/ogg/i', $mime_type) == true): $type = 'mime_ogg.png'; break; /* P */ case (preg_match('/pae/i', $mime_type) == true): $type = 'mime_pae.gif'; break; case (preg_match('/pbs/i', $mime_type) == true): $type = 'mime_pbs.gif'; break; case (preg_match('/pdf/i', $mime_type) == true): $type = 'mime_pdf.gif'; break; case (preg_match('/png/i', $mime_type) == true): $type = 'mime_png.png'; break; case (preg_match('/pps/i', $mime_type) == true ||preg_match('/powerpoint/i', $mime_type) == true): $type = 'mime_pps.gif'; break; /* Q */ /* R */ case (preg_match('/rar/i', $mime_type) == true): $type = 'mime_rar.gif'; break; /* S */ case (preg_match('/sit/i', $mime_type) == true || preg_match('/stuffit/i', $mime_type) == true): $type = 'mime_rat.gif'; break; /* T */ case (preg_match('/x-tar/i', $mime_type) == true || preg_match('/gnutar/i', $mime_type) == true): $type = 'mime_tar.gif'; break; /* U */ /* V */ /* W */ /* X */ case (preg_match('/xml/i', $mime_type) == true): $type = 'mime_xml.gif'; break; /* Y */ /* Z */ case (preg_match('/zip/i', $mime_type) == true): $type = 'mime_zip.gif'; break; case (preg_match('/7z/i', $mime_type) == true): $type = 'mime_zip.gif'; break; case (preg_match('/zoo/i', $mime_type) == true): $type = 'mime_zoo.gif'; break; /* unbestimmt */ case (preg_match('/octet-stream/i', $mime_type) == true): $type = 'mime_exe.gif'; break; case (preg_match('/plain/i', $mime_type) == true): $type = 'mime_txt.gif'; break; case (preg_match('/image/i', $mime_type) == true): $type = 'mime_img.gif'; break; default: $type = 'mime_default.gif'; } return $type; } } ?>