public function execute(HTTPRequestCustom $request) { $id = $request->get_getint('id', 0); if (!empty($id)) { try { $this->weblink = WebService::get_weblink('WHERE web.id = :id', array('id' => $id)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } if ($this->weblink !== null && !DownloadAuthorizationsService::check_authorizations($this->weblink->get_id_category())->read()) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } else { if ($this->weblink !== null && $this->weblink->is_visible()) { $this->weblink->set_number_views($this->weblink->get_number_views() + 1); WebService::update_number_views($this->weblink); WebCache::invalidate(); AppContext::get_response()->redirect($this->weblink->get_url()->absolute()); } else { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } }
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); } } }
public function get_actions_tree_links() { $lang = LangLoader::get('common', 'download'); $tree = new ModuleTreeLinks(); $manage_categories_link = new AdminModuleLink(LangLoader::get_message('categories.manage', 'categories-common'), DownloadUrlBuilder::manage_categories()); $manage_categories_link->add_sub_link(new AdminModuleLink(LangLoader::get_message('categories.manage', 'categories-common'), DownloadUrlBuilder::manage_categories())); $manage_categories_link->add_sub_link(new AdminModuleLink(LangLoader::get_message('category.add', 'categories-common'), DownloadUrlBuilder::add_category())); $tree->add_link($manage_categories_link); $manage_link = new AdminModuleLink($lang['download.manage'], DownloadUrlBuilder::manage()); $manage_link->add_sub_link(new AdminModuleLink($lang['download.manage'], DownloadUrlBuilder::manage())); $manage_link->add_sub_link(new AdminModuleLink($lang['download.actions.add'], DownloadUrlBuilder::add(AppContext::get_request()->get_getint('id_category', Category::ROOT_CATEGORY)))); $tree->add_link($manage_link); $tree->add_link(new AdminModuleLink(LangLoader::get_message('configuration', 'admin-common'), DownloadUrlBuilder::configuration())); if (!AppContext::get_current_user()->check_level(User::ADMIN_LEVEL)) { $tree->add_link(new ModuleLink($lang['download.actions.add'], DownloadUrlBuilder::add(AppContext::get_request()->get_getint('id_category', Category::ROOT_CATEGORY)), DownloadAuthorizationsService::check_authorizations()->write() || DownloadAuthorizationsService::check_authorizations()->contribution())); } $tree->add_link(new ModuleLink($lang['download.pending'], DownloadUrlBuilder::display_pending(), DownloadAuthorizationsService::check_authorizations()->write() || DownloadAuthorizationsService::check_authorizations()->contribution() || DownloadAuthorizationsService::check_authorizations()->moderation())); return $tree; }
private function is_contributor_member() { return !DownloadAuthorizationsService::check_authorizations()->write() && DownloadAuthorizationsService::check_authorizations()->contribution(); }
public function is_displayed() { return DownloadAuthorizationsService::check_authorizations()->read(); }
public function is_authorized_to_delete() { return DownloadAuthorizationsService::check_authorizations($this->id_category)->moderation() || (DownloadAuthorizationsService::check_authorizations($this->id_category)->write() || DownloadAuthorizationsService::check_authorizations($this->id_category)->contribution() && !$this->is_visible()) && $this->get_author_user()->get_id() == AppContext::get_current_user()->get_id() && AppContext::get_current_user()->check_level(User::MEMBER_LEVEL); }
private function check_authorizations() { $downloadfile = $this->get_downloadfile(); $not_authorized = !DownloadAuthorizationsService::check_authorizations($downloadfile->get_id_category())->moderation() && (!DownloadAuthorizationsService::check_authorizations($downloadfile->get_id_category())->write() && $downloadfile->get_author_user()->get_id() != AppContext::get_current_user()->get_id()); switch ($downloadfile->get_approbation_type()) { case DownloadFile::APPROVAL_NOW: if (!DownloadAuthorizationsService::check_authorizations($downloadfile->get_id_category())->read() && $not_authorized) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } break; case DownloadFile::NOT_APPROVAL: if ($not_authorized) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } break; case DownloadFile::APPROVAL_DATE: if (!$downloadfile->is_visible() && $not_authorized) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } break; default: $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); break; } }
private function check_authorizations() { if (AppContext::get_current_user()->is_guest()) { if ($this->config->are_descriptions_displayed_to_guests() && (!Authorizations::check_auth(RANK_TYPE, User::MEMBER_LEVEL, $this->get_category()->get_authorizations(), Category::READ_AUTHORIZATIONS) || $this->config->get_category_display_type() == DownloadConfig::DISPLAY_ALL_CONTENT) || !$this->config->are_descriptions_displayed_to_guests() && !DownloadAuthorizationsService::check_authorizations($this->get_category()->get_id())->read()) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } } else { if (!DownloadAuthorizationsService::check_authorizations($this->get_category()->get_id())->read()) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } } }
private function check_authorizations() { if (!(DownloadAuthorizationsService::check_authorizations()->write() || DownloadAuthorizationsService::check_authorizations()->contribution() || DownloadAuthorizationsService::check_authorizations()->moderation())) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } }
private function check_authorizations() { if (!DownloadAuthorizationsService::check_authorizations()->read()) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } }
public function get_authorizations() { $authorizations = new CommentsAuthorizations(); $authorizations->set_authorized_access_module(DownloadAuthorizationsService::check_authorizations($this->get_downloadfile()->get_id_category())->read()); return $authorizations; }