Show
Ignore:
Timestamp:
11/13/08 22:03:46 (5 years ago)
Author:
Tatzelwurm
Message:

Last version (1.1.0 pl 1)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • downloadDatabase/files/lib/data/downloadDB/DownloadDBData.class.php

    r668 r715  
    1919         */ 
    2020        public function __construct($dataID, $row = null) { 
    21                 if ($dataID != null) { 
    22                         $sql = "SELECT  * 
    23                                 FROM    wcf".WCF_N."_dldb_data 
    24                                 WHERE   dataID = ".$dataID; 
     21                if ($dataID !== null) { 
     22                        // select thread and thread subscription, visit and rating  
     23                        $sql = "SELECT          data.*  
     24                                                ".(DOWNLOADDB_ENABLE_RATING ? ", data_rating.rating AS userRating" : "")." 
     25                                FROM            wcf".WCF_N."_dldb_data data 
     26                                ".(DOWNLOADDB_ENABLE_RATING ? " 
     27                                LEFT JOIN       wcf".WCF_N."_dldb_rating data_rating 
     28                                ON              (data_rating.dataID = data.dataID 
     29                                                AND ".(WCF::getUser()->userID ? "data_rating.userID = ".WCF::getUser()->userID : "data_rating.ipAddress = '".escapeString(WCF::getSession()->ipAddress)."'").")" : "")." 
     30                                WHERE           data.dataID = ".$dataID; 
    2531                        $row = WCF::getDB()->getFirstRow($sql); 
    2632                } 
    27                         parent::__construct($row); 
     33                parent::__construct($row); 
    2834        } 
    2935         
     
    4854 
    4955                // delete Preview 
    50                 $this->deletePreview($this->previewFile); 
     56                if ($this->previewFile) $this->deletePreview($this->previewFile); 
    5157 
    5258                // delete database entry 
    5359                $sql = "DELETE FROM     wcf".WCF_N."_dldb_data 
    54                                 WHERE           dataID = ".$this->dataID; 
     60                                WHERE   `dataID` =".$this->dataID; 
    5561                WCF::getDB()->sendQuery($sql); 
    5662 
     63                // delete ratings 
     64                $sql = "DELETE FROM     wcf".WCF_N."_dldb_rating 
     65                                WHERE   `dataID` =".$this->dataID; 
     66                WCF::getDB()->sendQuery($sql); 
     67                 
     68                // delete database log 
     69                $sql = "DELETE FROM     wcf".WCF_N."_dldb_xfer 
     70                                WHERE   `dataID` =".$this->dataID; 
     71                WCF::getDB()->sendQuery($sql); 
     72                 
    5773                // clear Cache 
    5874                $this->resetCache(); 
     
    6581        public function deleteFile($fName) { 
    6682                // delete file 
    67                 if(file_exists(RELATIVE_WCF_DIR.DOWNLOADDB_FILE_DIR . intval($this->dataID) . '_' . StringUtil::encodeHTML($fName))){ 
    68                         @unlink(WCF_DIR.DOWNLOADDB_FILE_DIR . $this->dataID . '_' . $fName); 
     83                if(file_exists(WCF_DIR . DOWNLOADDB_FILE_DIR . intval($this->dataID) . '_' . StringUtil::encodeHTML($fName))){ 
     84                        @unlink(WCF_DIR . DOWNLOADDB_FILE_DIR . $this->dataID . '_' . $fName); 
    6985                } else { 
    7086                        @unlink(WCF_DIR . DOWNLOADDB_FILE_DIR . 'Upload-' .$this->dataID . '.' . $this->fileExtension); 
     
    7894        public function deletePreview($fName) { 
    7995                // delete file 
    80                 if(file_exists(RELATIVE_WCF_DIR.DOWNLOADDB_PREVIEW_DIR . $this->dataID . '_' . $fName)){ 
     96                if(file_exists(WCF_DIR . DOWNLOADDB_PREVIEW_DIR . $this->dataID . '_' . $fName)){ 
    8197                        @unlink(WCF_DIR . DOWNLOADDB_PREVIEW_DIR . $this->dataID . '_' . $fName); 
    8298                        @unlink(WCF_DIR . DOWNLOADDB_PREVIEW_DIR . 'thumbnail-' . $this->dataID . '_' . $fName); 
     
    88104        } 
    89105         
     106        /** 
     107         * Deletes one Logentry. 
     108         * @param  integer $xferID 
     109         */ 
     110        public static function deleteXfer($xferID) { 
     111                // delete file 
     112                // delete database entry 
     113                $sql = "DELETE FROM     wcf".WCF_N."_dldb_xfer 
     114                                WHERE           xferID = ".$xferID; 
     115                WCF::getDB()->sendQuery($sql); 
     116        } 
     117         
    90118        public static function resetCache() { 
    91119                // reset cache 
    92120                WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbData.php'); 
    93121                WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbKat.php'); 
     122        } 
     123 
     124        /** 
     125         * Returns the result of the rating of this download. 
     126         *  
     127         * @return      mixed           result of the rating of this download 
     128         */ 
     129        public function getRating() { 
     130                if ($this->ratings > 0 && $this->ratings >= DOWNLOADDB_MIN_RATINGS) { 
     131                        return $this->rating / $this->ratings; 
     132                } 
     133                return false; 
     134        } 
     135         
     136        /** 
     137         * Gets the download rating result for template output. 
     138         * 
     139         * @return      string          download rating result for template output 
     140         */ 
     141        public function getRatingOutput() { 
     142                $rating = $this->getRating(); 
     143                if ($rating !== false) $roundedRating = round($rating, 0); 
     144                else $roundedRating = 0; 
     145                $description = ''; 
     146                if ($this->ratings > 0) { 
     147                        $description = WCF::getLanguage()->get('wcf.dldb.dataset.rate.description', array('$votes' => StringUtil::formatNumeric($this->ratings), '$vote' => StringUtil::formatNumeric($rating))); 
     148                } 
     149                 
     150                return '<img src="'.RELATIVE_WCF_DIR.'icon/downloadDBRating'.$roundedRating.'.png" class="dldbRatingImage" alt="" title="'.$description.'" />'; 
    94151        } 
    95152