Ejemplo n.º 1
0
    public function get_feed_data_struct($idcat = 0, $name = '')
    {
        if (FaqService::get_categories_manager()->get_categories_cache()->category_exists($idcat)) {
            $querier = PersistenceContext::get_querier();
            $category = FaqService::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', 'faq');
            $data = new FeedData();
            $data->set_title($feed_module_name . ' - ' . $site_name);
            $data->set_date(new Date());
            $data->set_link(SyndicationUrlBuilder::rss('faq', $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 = FaqService::get_categories_manager()->get_childrens($idcat, new SearchCategoryChildrensOptions(), true);
            $ids_categories = array_keys($categories);
            $results = $querier->select('SELECT faq.id, faq.id_category, faq.question, faq.answer, faq.creation_date, cat.rewrited_name AS rewrited_name_cat
				FROM ' . FaqSetup::$faq_table . ' faq
				LEFT JOIN ' . FaqSetup::$faq_cats_table . ' cat ON cat.id = faq.id_category
				WHERE approved = 1
				AND faq.id_category IN :ids_categories
				ORDER BY faq.creation_date DESC', array('ids_categories' => $ids_categories));
            foreach ($results as $row) {
                $row['rewrited_name_cat'] = !empty($row['id_category']) ? $row['rewrited_name_cat'] : 'root';
                $link = FaqUrlBuilder::display($row['id_category'], $row['rewrited_name_cat'], $row['id']);
                $item = new FeedItem();
                $item->set_title($row['question']);
                $item->set_link($link);
                $item->set_guid($link);
                $item->set_desc(FormatingHelper::second_parse($row['answer']));
                $item->set_date(new Date($row['creation_date'], Timezone::SERVER_TIMEZONE));
                $item->set_auth(FaqService::get_categories_manager()->get_heritated_authorizations($row['id_category'], Category::READ_AUTHORIZATIONS, Authorizations::AUTH_PARENT_PRIORITY));
                $data->add_item($item);
            }
            $results->dispose();
            return $data;
        }
    }
Ejemplo n.º 2
0
 public function get_menu_content()
 {
     //Create file template
     $tpl = new FileTemplate('faq/FaqModuleMiniMenu.tpl');
     //Assign the lang file to the tpl
     $tpl->add_lang(LangLoader::get('common', 'faq'));
     //Load module cache
     $faq_cache = FaqCache::load();
     //Get authorized categories for the current user
     $authorized_categories = FaqService::get_authorized_categories(Category::ROOT_CATEGORY);
     $categories = array_intersect($faq_cache->get_categories(), $authorized_categories);
     if (!empty($categories)) {
         $id_category = $categories[array_rand($categories)];
         $category_questions = $faq_cache->get_category_questions($id_category);
         $random_question = $category_questions[array_rand($category_questions)];
         if (!empty($random_question)) {
             $category = FaqService::get_categories_manager()->get_categories_cache()->get_category($id_category);
             $tpl->put_all(array('C_QUESTION' => true, 'QUESTION' => $random_question['question'], 'U_LINK' => FaqUrlBuilder::display($category->get_id(), $category->get_rewrited_name(), $random_question['id'])->rel()));
         }
     }
     return $tpl->render();
 }
 private function is_authorized($bit, $mode = Authorizations::AUTH_CHILD_PRIORITY)
 {
     $auth = FaqService::get_categories_manager()->get_heritated_authorizations($this->id_category, $bit, $mode);
     return AppContext::get_current_user()->check_auth($auth, $bit);
 }
 protected function get_categories_manager()
 {
     return FaqService::get_categories_manager();
 }
Ejemplo n.º 5
0
 public function get_category()
 {
     return FaqService::get_categories_manager()->get_categories_cache()->get_category($this->id_category);
 }
 private function save()
 {
     $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_display_type($this->form->get_value('display_type')->get_raw_value());
     $this->config->set_root_category_description($this->form->get_value('root_category_description'));
     $this->config->set_authorizations($this->form->get_value('authorizations')->build_auth_array());
     FaqConfig::save();
     FaqService::get_categories_manager()->regenerate_cache();
     FaqCache::invalidate();
 }
 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);
 }
 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(FaqUrlBuilder::display_category($this->get_category()->get_id(), $this->get_category()->get_rewrited_name(), AppContext::get_request()->get_getint('page', 1)));
     $breadcrumb = $graphical_environment->get_breadcrumb();
     $breadcrumb->add($this->lang['module_title'], FaqUrlBuilder::home());
     $categories = array_reverse(FaqService::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(), FaqUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name()));
         }
     }
     return $response;
 }
Ejemplo n.º 9
0
 private function generate_response(View $tpl)
 {
     $faq_question = $this->get_faq_question();
     $response = new SiteDisplayResponse($tpl);
     $graphical_environment = $response->get_graphical_environment();
     $breadcrumb = $graphical_environment->get_breadcrumb();
     $breadcrumb->add($this->lang['module_title'], FaqUrlBuilder::home());
     if ($faq_question->get_id() === null) {
         $graphical_environment->set_page_title($this->lang['faq.add'], $this->lang['module_title']);
         $breadcrumb->add($this->lang['faq.add'], FaqUrlBuilder::add($faq_question->get_id_category()));
         $graphical_environment->get_seo_meta_data()->set_description($this->lang['faq.add']);
         $graphical_environment->get_seo_meta_data()->set_canonical_url(FaqUrlBuilder::add($faq_question->get_id_category()));
     } else {
         $graphical_environment->set_page_title($this->lang['faq.edit'], $this->lang['module_title']);
         $graphical_environment->get_seo_meta_data()->set_description($this->lang['faq.edit']);
         $graphical_environment->get_seo_meta_data()->set_canonical_url(FaqUrlBuilder::edit($faq_question->get_id()));
         $categories = array_reverse(FaqService::get_categories_manager()->get_parents($faq_question->get_id_category(), true));
         foreach ($categories as $id => $category) {
             if ($category->get_id() != Category::ROOT_CATEGORY) {
                 $breadcrumb->add($category->get_name(), FaqUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name()));
             }
         }
         $category = $faq_question->get_category();
         $breadcrumb->add($faq_question->get_question(), FaqUrlBuilder::display($category->get_id(), $category->get_rewrited_name(), $faq_question->get_id()));
         $breadcrumb->add($this->lang['faq.edit'], FaqUrlBuilder::edit($faq_question->get_id()));
     }
     return $response;
 }
 public function __construct()
 {
     parent::__construct(FaqService::get_categories_manager());
 }