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);
     }
 }
 public function uninstall()
 {
     $this->drop_tables();
     ConfigManager::delete('download', 'config');
     CacheManager::invalidate('module', 'download');
     DownloadService::get_keywords_manager()->delete_module_relations();
 }
 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;
 }
 public function get_search_request($args)
 {
     $now = new Date();
     $authorized_categories = DownloadService::get_authorized_categories(Category::ROOT_CATEGORY);
     $weight = isset($args['weight']) && is_numeric($args['weight']) ? $args['weight'] : 1;
     return "SELECT " . $args['id_search'] . " AS id_search,\n\t\t\td.id AS id_content,\n\t\t\td.name AS title,\n\t\t\t( 2 * FT_SEARCH_RELEVANCE(d.name, '" . $args['search'] . "') + (FT_SEARCH_RELEVANCE(d.contents, '" . $args['search'] . "') +\n\t\t\tFT_SEARCH_RELEVANCE(d.short_contents, '" . $args['search'] . "')) / 2 ) / 3 * " . $weight . " AS relevance,\n\t\t\tCONCAT('" . PATH_TO_ROOT . "/download/index.php?url=/', id_category, '-', IF(id_category != 0, cat.rewrited_name, 'root'), '/', d.id, '-', d.rewrited_name) AS link\n\t\t\tFROM " . DownloadSetup::$download_table . " d\n\t\t\tLEFT JOIN " . DownloadSetup::$download_cats_table . " cat ON d.id_category = cat.id\n\t\t\tWHERE ( FT_SEARCH(d.name, '" . $args['search'] . "') OR FT_SEARCH(d.contents, '" . $args['search'] . "') OR FT_SEARCH_RELEVANCE(d.short_contents, '" . $args['search'] . "') )\n\t\t\tAND id_category IN (" . implode(", ", $authorized_categories) . ")\n\t\t\tAND (approbation_type = 1 OR (approbation_type = 2 AND start_date < '" . $now->get_timestamp() . "' AND (end_date > '" . $now->get_timestamp() . "' OR end_date = 0)))\n\t\t\tORDER BY relevance DESC\n\t\t\tLIMIT 100 OFFSET 0";
 }
 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);
         }
     }
 }
 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_feed_data_struct($idcat = 0, $name = '')
    {
        if (DownloadService::get_categories_manager()->get_categories_cache()->category_exists($idcat)) {
            $querier = PersistenceContext::get_querier();
            $category = DownloadService::get_categories_manager()->get_categories_cache()->get_category($idcat);
            $site_name = GeneralConfig::load()->get_site_name();
            $site_name = $idcat != Category::ROOT_CATEGORY ? $site_name . ' : ' . $category->get_name() : $site_name;
            $feed_module_name = LangLoader::get_message('module_title', 'common', 'download');
            $data = new FeedData();
            $data->set_title($feed_module_name . ' - ' . $site_name);
            $data->set_date(new Date());
            $data->set_link(SyndicationUrlBuilder::rss('download', $idcat));
            $data->set_host(HOST);
            $data->set_desc($feed_module_name . ' - ' . $site_name);
            $data->set_lang(LangLoader::get_message('xml_lang', 'main'));
            $data->set_auth_bit(Category::READ_AUTHORIZATIONS);
            $categories = DownloadService::get_categories_manager()->get_childrens($idcat, new SearchCategoryChildrensOptions(), true);
            $ids_categories = array_keys($categories);
            $now = new Date();
            $results = $querier->select('SELECT download.id, download.id_category, download.name, download.rewrited_name, download.contents, download.short_contents, download.creation_date, download.picture_url, cat.rewrited_name AS rewrited_name_cat
				FROM ' . DownloadSetup::$download_table . ' download
				LEFT JOIN ' . DownloadSetup::$download_cats_table . ' cat ON cat.id = download.id_category
				WHERE download.id_category IN :ids_categories
				AND (approbation_type = 1 OR (approbation_type = 2 AND start_date < :timestamp_now AND (end_date > :timestamp_now OR end_date = 0)))
				ORDER BY download.creation_date DESC', array('ids_categories' => $ids_categories, 'timestamp_now' => $now->get_timestamp()));
            foreach ($results as $row) {
                $row['rewrited_name_cat'] = !empty($row['id_category']) ? $row['rewrited_name_cat'] : 'root';
                $link = DownloadUrlBuilder::display($row['id_category'], $row['rewrited_name_cat'], $row['id'], $row['rewrited_name']);
                $item = new FeedItem();
                $item->set_title($row['name']);
                $item->set_link($link);
                $item->set_guid($link);
                $item->set_desc(FormatingHelper::second_parse($row['contents']));
                $item->set_date(new Date($row['creation_date'], Timezone::SERVER_TIMEZONE));
                $item->set_image_url($row['picture_url']);
                $item->set_auth(DownloadService::get_categories_manager()->get_heritated_authorizations($row['id_category'], Category::READ_AUTHORIZATIONS, Authorizations::AUTH_PARENT_PRIORITY));
                $data->add_item($item);
            }
            $results->dispose();
            return $data;
        }
    }
 public function get_menu_content()
 {
     //Create file template
     $tpl = new FileTemplate('download/DownloadModuleMiniMenu.tpl');
     //Assign the lang file to the tpl
     $tpl->add_lang(LangLoader::get('common', 'download'));
     //Load module config
     $config = DownloadConfig::load();
     //Load module cache
     $download_cache = DownloadCache::load();
     //Load categories cache
     $categories_cache = DownloadService::get_categories_manager()->get_categories_cache();
     $downloadfiles = $download_cache->get_downloadfiles();
     $tpl->put_all(array('C_FILES' => !empty($downloadfiles), 'C_SORT_BY_DATE' => $config->is_sort_type_date(), 'C_SORT_BY_NOTATION' => $config->is_sort_type_notation(), 'C_SORT_BY_NUMBER_DOWNLOADS' => $config->is_sort_type_number_downloads()));
     $displayed_position = 1;
     foreach ($downloadfiles as $file) {
         $downloadfile = new DownloadFile();
         $downloadfile->set_properties($file);
         $tpl->assign_block_vars('downloadfiles', array_merge($downloadfile->get_array_tpl_vars(), array('DISPLAYED_POSITION' => $displayed_position)));
         $displayed_position++;
     }
     return $tpl->render();
 }
 public function url_mappings()
 {
     $db_querier = PersistenceContext::get_querier();
     $phpboost_4_1_release_date = new Date('2014-07-15');
     if (GeneralConfig::load()->get_site_install_date()->is_anterior_to($phpboost_4_1_release_date)) {
         // Articles
         if (class_exists('ArticlesService')) {
             $this->urls_mappings[] = new UrlMapping('^articles/articles.php$', '/articles/', 'L,R=301');
             $categories = ArticlesService::get_categories_manager()->get_categories_cache()->get_categories();
             foreach ($categories as $id => $category) {
                 $this->urls_mappings[] = new UrlMapping('^articles/articles-' . $id . '\\+([^.]*).php$', '/articles/' . $id . '-' . $category->get_rewrited_name() . '/', 'L,R=301');
                 $this->urls_mappings[] = new UrlMapping('^articles/articles-' . $id . '-([0-9]*)\\+([^.]*).php$', '/articles/' . $id . '-' . $category->get_rewrited_name() . '/$1-$2/', 'L,R=301');
             }
         }
         // Calendar
         if (class_exists('CalendarService')) {
             $this->urls_mappings[] = new UrlMapping('^calendar/calendar$', '/calendar/', 'L,R=301');
             $this->urls_mappings[] = new UrlMapping('^calendar/calendar-([0-9]+)-([0-9]+)-([0-9]+)-?([0-9]*).php$', '/calendar/$3-$2-$1/', 'L,R=301');
         }
         // Guestbook
         if (class_exists('GuestbookService')) {
             $this->urls_mappings[] = new UrlMapping('^guestbook/guestbook.php$', '/guestbook/', 'L,R=301');
         }
         // News
         if (class_exists('NewsService')) {
             $this->urls_mappings[] = new UrlMapping('^news/news.php$', '/news/', 'L,R=301');
             $categories = NewsService::get_categories_manager()->get_categories_cache()->get_categories();
             foreach ($categories as $id => $category) {
                 $this->urls_mappings[] = new UrlMapping('^news/news-' . $id . '\\+([^.]*).php$', '/news/' . $id . '-' . $category->get_rewrited_name() . '/', 'L,R=301');
                 $this->urls_mappings[] = new UrlMapping('^news/news-' . $id . '-([0-9]*)\\+([^.]*).php$', '/news/' . $id . '-' . $category->get_rewrited_name() . '/$1-$2/', 'L,R=301');
             }
         }
     }
     // Download
     if (class_exists('DownloadService')) {
         $this->urls_mappings[] = new UrlMapping('^download/download\\.php$', '/download/', 'L,R=301');
         $categories = DownloadService::get_categories_manager()->get_categories_cache()->get_categories();
         $result = $db_querier->select_rows(PREFIX . 'download', array('id', 'id_category', 'rewrited_name'));
         while ($row = $result->fetch()) {
             $category = $categories[$row['id_category']];
             if (!empty($category)) {
                 $this->urls_mappings[] = new UrlMapping('^download/download-' . $row['id'] . '(-?[^.]*)\\.php$', '/download/' . $category->get_id() . '-' . $category->get_rewrited_name() . '/' . $row['id'] . '-' . $row['rewrited_name'], 'L,R=301');
                 $this->urls_mappings[] = new UrlMapping('^download/file-' . $row['id'] . '(-?[^.]*)\\.php$', '/download/' . $category->get_id() . '-' . $category->get_rewrited_name() . '/' . $row['id'] . '-' . $row['rewrited_name'], 'L,R=301');
             }
         }
         $result->dispose();
         foreach ($categories as $id => $category) {
             $this->urls_mappings[] = new UrlMapping('^download/category-' . $id . '(-?[^.]*)\\.php$', '/download/' . $id . '-' . $category->get_rewrited_name() . '/', 'L,R=301');
         }
     }
     // FAQ
     if (class_exists('FaqService')) {
         $this->urls_mappings[] = new UrlMapping('^faq/faq\\.php$', '/faq/', 'L,R=301');
         $categories = FaqService::get_categories_manager()->get_categories_cache()->get_categories();
         foreach ($categories as $id => $category) {
             $this->urls_mappings[] = new UrlMapping('^faq/faq-' . $category->get_id() . '(\\+?[^.]*)\\.php$', '/faq/' . $id . '-' . $category->get_rewrited_name() . '/', 'L,R=301');
         }
     }
     // Shoutbox
     if (class_exists('ShoutboxService')) {
         $this->urls_mappings[] = new UrlMapping('^shoutbox/shoutbox\\.php$', '/shoutbox/', 'L,R=301');
     }
     // Web
     if (class_exists('WebService')) {
         $this->urls_mappings[] = new UrlMapping('^web/web\\.php$', '/web/', 'L,R=301');
         $categories = WebService::get_categories_manager()->get_categories_cache()->get_categories();
         $result = $db_querier->select_rows(PREFIX . 'web', array('id', 'id_category', 'rewrited_name'));
         while ($row = $result->fetch()) {
             $category = $categories[$row['id_category']];
             if (!empty($category)) {
                 $this->urls_mappings[] = new UrlMapping('^web/web-' . $category->get_id() . '-' . $row['id'] . '([^.]*)\\.php$', '/web/' . $category->get_id() . '-' . $category->get_rewrited_name() . '/' . $row['id'] . '-' . $row['rewrited_name'], 'L,R=301');
             }
         }
         $result->dispose();
         foreach ($categories as $id => $category) {
             $this->urls_mappings[] = new UrlMapping('^web/web-' . $category->get_id() . '(-?[^.]*)\\.php$', '/web/' . $id . '-' . $category->get_rewrited_name() . '/', 'L,R=301');
         }
     }
     return new UrlMappings($this->urls_mappings);
 }
 protected function get_categories_manager()
 {
     return DownloadService::get_categories_manager();
 }
Example #11
0
 public function get_keywords()
 {
     if ($this->keywords === null) {
         $this->keywords = DownloadService::get_keywords_manager()->get_keywords($this->id);
     }
     return $this->keywords;
 }
 private function get_keyword()
 {
     if ($this->keyword === null) {
         $rewrited_name = AppContext::get_request()->get_getstring('tag', '');
         if (!empty($rewrited_name)) {
             try {
                 $this->keyword = DownloadService::get_keywords_manager()->get_keyword('WHERE rewrited_name=:rewrited_name', array('rewrited_name' => $rewrited_name));
             } catch (RowNotFoundException $e) {
                 $error_controller = PHPBoostErrors::unexisting_page();
                 DispatchManager::redirect($error_controller);
             }
         } else {
             $error_controller = PHPBoostErrors::unexisting_page();
             DispatchManager::redirect($error_controller);
         }
     }
     return $this->keyword;
 }
 private function generate_response()
 {
     $response = new SiteDisplayResponse($this->tpl);
     $graphical_environment = $response->get_graphical_environment();
     $graphical_environment->set_page_title($this->get_category()->get_name(), $this->lang['module_title']);
     $graphical_environment->get_seo_meta_data()->set_description($this->get_category()->get_description());
     $graphical_environment->get_seo_meta_data()->set_canonical_url(DownloadUrlBuilder::display_category($this->get_category()->get_id(), $this->get_category()->get_rewrited_name(), AppContext::get_request()->get_getstring('field', 'date'), AppContext::get_request()->get_getstring('sort', 'desc'), AppContext::get_request()->get_getint('page', 1)));
     $breadcrumb = $graphical_environment->get_breadcrumb();
     $breadcrumb->add($this->lang['module_title'], DownloadUrlBuilder::home());
     $categories = array_reverse(DownloadService::get_categories_manager()->get_parents($this->get_category()->get_id(), true));
     foreach ($categories as $id => $category) {
         if ($category->get_id() != Category::ROOT_CATEGORY) {
             $breadcrumb->add($category->get_name(), DownloadUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name()));
         }
     }
     return $response;
 }
 private function get_pagination($condition, $parameters, $field, $mode, $page)
 {
     $downloadfiles_number = DownloadService::count($condition, $parameters);
     $pagination = new ModulePagination($page, $downloadfiles_number, (int) DownloadConfig::load()->get_items_number_per_page());
     $pagination->set_url(DownloadUrlBuilder::display_pending($field, $mode, '%d'));
     if ($pagination->current_page_is_empty() && $page > 1) {
         $error_controller = PHPBoostErrors::unexisting_page();
         DispatchManager::redirect($error_controller);
     }
     return $pagination;
 }
 private function save()
 {
     $this->config->set_items_number_per_page($this->form->get_value('items_number_per_page'));
     $this->config->set_categories_number_per_page($this->form->get_value('categories_number_per_page'));
     $this->config->set_columns_number_per_line($this->form->get_value('columns_number_per_line'));
     $this->config->set_category_display_type($this->form->get_value('category_display_type')->get_raw_value());
     if ($this->config->get_category_display_type() != DownloadConfig::DISPLAY_ALL_CONTENT) {
         if ($this->form->get_value('display_descriptions_to_guests')) {
             $this->config->display_descriptions_to_guests();
         } else {
             $this->config->hide_descriptions_to_guests();
         }
     }
     if ($this->form->get_value('author_displayed')) {
         $this->config->display_author();
     } else {
         $this->config->hide_author();
     }
     if ($this->form->get_value('comments_enabled')) {
         $this->config->enable_comments();
     } else {
         $this->config->disable_comments();
     }
     if ($this->form->get_value('notation_enabled')) {
         $this->config->enable_notation();
         $this->config->set_notation_scale($this->form->get_value('notation_scale'));
         if ($this->form->get_value('notation_scale') != $this->config->get_notation_scale()) {
             NotationService::update_notation_scale('download', $this->config->get_notation_scale(), $this->form->get_value('notation_scale'));
         }
     } else {
         $this->config->disable_notation();
     }
     $this->config->set_root_category_description($this->form->get_value('root_category_description'));
     $this->config->set_sort_type($this->form->get_value('sort_type')->get_raw_value());
     $this->config->set_files_number_in_menu($this->form->get_value('files_number_in_menu'));
     $this->config->set_authorizations($this->form->get_value('authorizations')->build_auth_array());
     DownloadConfig::save();
     DownloadService::get_categories_manager()->regenerate_cache();
     DownloadCache::invalidate();
 }
 /**
  * @desc Return the keywords manager.
  */
 public static function get_keywords_manager()
 {
     if (self::$keywords_manager === null) {
         self::$keywords_manager = new KeywordsManager('download');
     }
     return self::$keywords_manager;
 }
 public function __construct()
 {
     parent::__construct(DownloadService::get_categories_manager());
 }
 private function generate_response(View $tpl)
 {
     $downloadfile = $this->get_downloadfile();
     $response = new SiteDisplayResponse($tpl);
     $graphical_environment = $response->get_graphical_environment();
     $breadcrumb = $graphical_environment->get_breadcrumb();
     $breadcrumb->add($this->lang['module_title'], DownloadUrlBuilder::home());
     if ($downloadfile->get_id() === null) {
         $graphical_environment->set_page_title($this->lang['download.add'], $this->lang['module_title']);
         $breadcrumb->add($this->lang['download.add'], DownloadUrlBuilder::add($downloadfile->get_id_category()));
         $graphical_environment->get_seo_meta_data()->set_description($this->lang['download.add']);
         $graphical_environment->get_seo_meta_data()->set_canonical_url(DownloadUrlBuilder::add($downloadfile->get_id_category()));
     } else {
         $graphical_environment->set_page_title($this->lang['download.edit'], $this->lang['module_title']);
         $graphical_environment->get_seo_meta_data()->set_description($this->lang['download.edit']);
         $graphical_environment->get_seo_meta_data()->set_canonical_url(DownloadUrlBuilder::edit($downloadfile->get_id()));
         $categories = array_reverse(DownloadService::get_categories_manager()->get_parents($downloadfile->get_id_category(), true));
         foreach ($categories as $id => $category) {
             if ($category->get_id() != Category::ROOT_CATEGORY) {
                 $breadcrumb->add($category->get_name(), DownloadUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name()));
             }
         }
         $category = $downloadfile->get_category();
         $breadcrumb->add($downloadfile->get_name(), DownloadUrlBuilder::display($category->get_id(), $category->get_rewrited_name(), $downloadfile->get_id(), $downloadfile->get_rewrited_name()));
         $breadcrumb->add($this->lang['download.edit'], DownloadUrlBuilder::edit($downloadfile->get_id()));
     }
     return $response;
 }
 private function is_authorized($bit, $mode = Authorizations::AUTH_CHILD_PRIORITY)
 {
     $auth = DownloadService::get_categories_manager()->get_heritated_authorizations($this->id_category, $bit, $mode);
     return AppContext::get_current_user()->check_auth($auth, $bit);
 }