diff --git a/application/modules/default/controllers/DlController.php b/application/modules/default/controllers/DlController.php index f9ee9299a..28aa58f4b 100755 --- a/application/modules/default/controllers/DlController.php +++ b/application/modules/default/controllers/DlController.php @@ -1,116 +1,116 @@ . **/ class DlController extends Local_Controller_Action_DomainSwitch { public function indexAction() { $this->_helper->layout->disableLayout(); $file_id = $this->getParam('file_id'); $file_type = $this->getParam('file_type'); $file_name = $this->getParam('file_name'); $file_size = $this->getParam('file_size'); $projectId = $this->getParam('project_id'); if($this->hasParam('link_type')) { $linkType = $this->getParam('link_type'); } else { $linkType = "download"; } $modelProduct = new Default_Model_Project(); $productInfo = $modelProduct->fetchProductInfo($projectId); $this->view->link_type = $linkType; $this->view->file_name = $file_name; $this->view->file_size = $file_size; $this->view->file_size_human = $this->humanFileSize($file_size); $this->view->project_title = $productInfo->title; $memberId = $this->_authMember->member_id; if ($_SERVER['REQUEST_METHOD'] == 'POST') { if(isset($file_id) && isset($projectId) && isset($memberId)) { $memberDlHistory = new Default_Model_DbTable_MemberDownloadHistory(); $data = array('project_id' => $projectId, 'member_id' => $memberId, 'file_id' => $file_id, 'file_type' => $file_type, 'file_name' => $file_name, 'file_size' => $file_size); $memberDlHistory->createRow($data)->save(); } //create ppload download hash: secret + collection_id + expire-timestamp $salt = PPLOAD_DOWNLOAD_SECRET; $collectionID = $productInfo->ppload_collection_id; $timestamp = time() + 3600; // one hour valid //20181009 ronald: change hash from MD5 to SHA512 //$hash = md5($salt . $collectionID . $timestamp); // order isn't important at all... just do the same when verifying $hash = hash('sha512',$salt . $collectionID . $timestamp); // order isn't important at all... just do the same when verifying $url = PPLOAD_API_URI . 'files/download/id/' . $file_id . '/s/' . $hash . '/t/' . $timestamp . '/u/' . $memberId . '/' . $file_name; if($linkType == 'install') { $helperCatXdgType = new Default_View_Helper_CatXdgType(); $xdgType = $helperCatXdgType->catXdgType($productInfo->project_category_id); $url = 'ocs://install' . '?url=' . urlencode($url) . '&type=' . urlencode($xdgType) . '&filename=' . urldecode($file_name); } $this->view->url = $url; } } function formatBytes($bytes, $precision = 2) { $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); // Uncomment one of the following alternatives // $bytes /= pow(1024, $pow); // $bytes /= (1 << (10 * $pow)); return round($bytes, $precision) . ' ' . $units[$pow]; } function humanFileSize($bytes) { - if(!empty(bytes)) + if(!empty($bytes)) { $size = round($bytes / 1048576, 2); if($size == 0.0) { return '0.01 MB'; }else { return $size.' MB'; } } else { return null; } } } \ No newline at end of file