public function execute(HTTPRequestCustom $request) { $id = $request->get_getint('id', 0); if (!empty($id) && AppContext::get_current_user()->check_level(User::MEMBER_LEVEL)) { try { $this->downloadfile = DownloadService::get_downloadfile('WHERE download.id = :id', array('id' => $id)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } if ($this->downloadfile !== null && $this->downloadfile->is_visible()) { if (!PersistenceContext::get_querier()->row_exists(PREFIX . 'events', 'WHERE id_in_module=:id_in_module AND module=\'download\' AND current_status = 0', array('id_in_module' => $this->downloadfile->get_id()))) { $contribution = new Contribution(); $contribution->set_id_in_module($this->downloadfile->get_id()); $contribution->set_entitled(StringVars::replace_vars(LangLoader::get_message('contribution.deadlink', 'common'), array('link_name' => $this->downloadfile->get_name()))); $contribution->set_fixing_url(DownloadUrlBuilder::edit($this->downloadfile->get_id())->relative()); $contribution->set_description(LangLoader::get_message('contribution.deadlink_explain', 'common')); $contribution->set_poster_id(AppContext::get_current_user()->get_id()); $contribution->set_module('download'); $contribution->set_type('alert'); $contribution->set_auth(Authorizations::capture_and_shift_bit_auth(DownloadService::get_categories_manager()->get_heritated_authorizations($this->downloadfile->get_id_category(), Category::MODERATION_AUTHORIZATIONS, Authorizations::AUTH_CHILD_PRIORITY), Category::MODERATION_AUTHORIZATIONS, Contribution::CONTRIBUTION_AUTH_BIT)); ContributionService::save_contribution($contribution); } DispatchManager::redirect(new UserContributionSuccessController()); } else { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } }
private function get_downloadfile() { if ($this->downloadfile === null) { $this->downloadfile = DownloadService::get_downloadfile('WHERE download.id=:id', array('id' => $this->get_id_in_module())); } return $this->downloadfile; }
private function get_downloadfile(HTTPRequestCustom $request) { $id = $request->get_getint('id', 0); if (!empty($id)) { try { $this->downloadfile = DownloadService::get_downloadfile('WHERE download.id=:id', array('id' => $id)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } }
private function get_downloadfile() { if ($this->downloadfile === null) { $id = AppContext::get_request()->get_getint('id', 0); if (!empty($id)) { try { $this->downloadfile = DownloadService::get_downloadfile('WHERE download.id = :id', array('id' => $id)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } else { $this->downloadfile = new DownloadFile(); } } return $this->downloadfile; }
public function execute(HTTPRequestCustom $request) { $id = $request->get_getint('id', 0); if (!empty($id)) { try { $this->downloadfile = DownloadService::get_downloadfile('WHERE download.id = :id', array('id' => $id)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } if ($this->downloadfile !== null && !DownloadAuthorizationsService::check_authorizations($this->downloadfile->get_id_category())->read()) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } else { if ($this->downloadfile !== null && $this->downloadfile->is_visible()) { $this->downloadfile->set_number_downloads($this->downloadfile->get_number_downloads() + 1); DownloadService::update_number_downloads($this->downloadfile); DownloadCache::invalidate(); $status = 200; $file_headers = get_headers($this->downloadfile->get_url()->absolute(), true); if (is_array($file_headers)) { if (preg_match('/^HTTP\\/[12]\\.[01] (\\d\\d\\d)/', $file_headers[0], $matches)) { $status = (int) $matches[1]; } } if ($status == 200) { header('Content-Disposition: attachment; filename="' . urldecode(basename($this->downloadfile->get_url()->absolute())) . '"'); header('Content-Description: File Transfer'); header('Content-Transfer-Encoding: binary'); header('Accept-Ranges: bytes'); header('Content-Type: application/force-download'); set_time_limit(0); readfile($this->downloadfile->get_url()->absolute()); } else { $error_controller = new UserErrorController(LangLoader::get_message('error', 'status-messages-common'), LangLoader::get_message('download.message.error.file_not_found', 'common', 'download'), UserErrorController::WARNING); DispatchManager::redirect($error_controller); } } else { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } }