- Timestamp:
- 11/13/08 22:03:46 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
downloadDatabase/files/lib/data/downloadDB/DownloadDBData.class.php
r668 r715 19 19 */ 20 20 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; 25 31 $row = WCF::getDB()->getFirstRow($sql); 26 32 } 27 parent::__construct($row);33 parent::__construct($row); 28 34 } 29 35 … … 48 54 49 55 // delete Preview 50 $this->deletePreview($this->previewFile);56 if ($this->previewFile) $this->deletePreview($this->previewFile); 51 57 52 58 // delete database entry 53 59 $sql = "DELETE FROM wcf".WCF_N."_dldb_data 54 WHERE dataID =".$this->dataID;60 WHERE `dataID` =".$this->dataID; 55 61 WCF::getDB()->sendQuery($sql); 56 62 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 57 73 // clear Cache 58 74 $this->resetCache(); … … 65 81 public function deleteFile($fName) { 66 82 // 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); 69 85 } else { 70 86 @unlink(WCF_DIR . DOWNLOADDB_FILE_DIR . 'Upload-' .$this->dataID . '.' . $this->fileExtension); … … 78 94 public function deletePreview($fName) { 79 95 // 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)){ 81 97 @unlink(WCF_DIR . DOWNLOADDB_PREVIEW_DIR . $this->dataID . '_' . $fName); 82 98 @unlink(WCF_DIR . DOWNLOADDB_PREVIEW_DIR . 'thumbnail-' . $this->dataID . '_' . $fName); … … 88 104 } 89 105 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 90 118 public static function resetCache() { 91 119 // reset cache 92 120 WCF::getCache()->clear(WCF_DIR.'cache/', 'cache.dldbData.php'); 93 121 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.'" />'; 94 151 } 95 152
