/** * Down a file. * * @param int $fileID * @param string $mouse * @access public * @return void */ public function download($fileID, $mouse = '', $confirm = '') { if ($confirm == 'no') { die(js::close()); } $file = $this->file->getById($fileID); /* Change savePath if objectType is source or slide. */ if (strpos(',slide,source,', ",{$file->objectType},") !== false) { $this->file->setSavePath('source'); $file = $this->file->getById($fileID); } /* Judge the mode, down or open. */ $mode = 'down'; $fileTypes = 'txt|jpg|jpeg|gif|png|bmp|xml|html'; if (stripos($fileTypes, $file->extension) !== false and $mouse == 'left') { $mode = 'open'; } $account = $this->app->user->account; if (!$file->public && $account == 'guest') { $this->locate($this->createLink('user', 'login')); } /* If the mode is open, locate directly. */ if ($mode == 'open') { if (file_exists($file->realPath)) { $this->locate($file->webPath); } $this->app->triggerError("The file you visit {$fileID} not found.", __FILE__, __LINE__, true); } else { /* Down the file. */ if (file_exists($file->realPath)) { $fileName = $file->title . '.' . $file->extension; $fileData = file_get_contents($file->realPath); if (commonModel::isAvailable('score')) { /* Check for update extension.*/ if (!$this->loadModel('score')->hasFileDowned($account, $fileID) and $account != $file->addedBy) { if (!empty($file->score) and $file->addedBy != $account and $confirm != 'yes') { die(js::confirm(sprintf($this->lang->file->confirm, $file->score), inlink('download', "id={$fileID}&mouse=&confirm=yes"), inlink('download', "id={$fileID}&mouse=&confirm=no"))); } if (!$this->score->cost('download', $file->score, 'file', $fileID)) { $this->view->score = $file->score; die($this->display()); } } } /* Recording download times, downloads of this file plus one. */ $this->file->log($fileID); $this->file->sendDownHeader($fileName, $file->extension, $fileData, filesize($file->realPath)); } else { $this->app->triggerError("The file you visit {$fileID} not found.", __FILE__, __LINE__, true); } } }