private function build_view(HTTPRequestCustom $request) { $current_page = $request->get_getint('page', 1); $config = ArticlesConfig::load(); $this->category = $this->article->get_category(); $article_contents = $this->article->get_contents(); //If article doesn't begin with a page, we insert one if (substr(trim($article_contents), 0, 6) != '[page]') { $article_contents = '[page] [/page]' . $article_contents; } //Removing [page] bbcode $article_contents_clean = preg_split('`\\[page\\].+\\[/page\\](.*)`Us', $article_contents, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); //Retrieving pages preg_match_all('`\\[page\\]([^[]+)\\[/page\\]`U', $article_contents, $array_page); $nbr_pages = count($array_page[1]); if ($nbr_pages > 1) { $this->build_form($array_page, $current_page); } $this->build_sources_view(); $this->build_keywords_view(); $page_name = isset($array_page[1][$current_page - 1]) && $array_page[1][$current_page - 1] != ' ' ? $array_page[1][$current_page - 1] : ''; $this->tpl->put_all(array_merge($this->article->get_tpl_vars(), array('C_COMMENTS_ENABLED' => $config->are_comments_enabled(), 'C_NOTATION_ENABLED' => $config->is_notation_enabled(), 'KERNEL_NOTATION' => NotationService::display_active_image($this->article->get_notation()), 'CONTENTS' => isset($article_contents_clean[$current_page - 1]) ? FormatingHelper::second_parse($article_contents_clean[$current_page - 1]) : '', 'PAGE_NAME' => $page_name, 'U_EDIT_ARTICLE' => $page_name !== '' ? ArticlesUrlBuilder::edit_article($this->article->get_id(), $current_page)->rel() : ArticlesUrlBuilder::edit_article($this->article->get_id())->rel()))); $this->build_pages_pagination($current_page, $nbr_pages, $array_page); //Affichage commentaires if ($config->are_comments_enabled()) { $comments_topic = new ArticlesCommentsTopic($this->article); $comments_topic->set_id_in_module($this->article->get_id()); $comments_topic->set_url(ArticlesUrlBuilder::display_article($this->category->get_id(), $this->category->get_rewrited_name(), $this->article->get_id(), $this->article->get_rewrited_title())); $this->tpl->put('COMMENTS', $comments_topic->display()); } }
public function get_root_category() { $root = new RichRootCategory(); $root->set_authorizations(ArticlesConfig::load()->get_authorizations()); $root->set_description(ArticlesConfig::load()->get_root_category_description()); return $root; }
public static function get_authorized_categories($current_id_category) { $search_category_children_options = new SearchCategoryChildrensOptions(); $search_category_children_options->add_authorizations_bits(Category::READ_AUTHORIZATIONS); if (AppContext::get_current_user()->is_guest()) { $search_category_children_options->set_allow_only_member_level_authorizations(ArticlesConfig::load()->are_descriptions_displayed_to_guests()); } $categories = self::get_categories_manager()->get_childrens($current_id_category, $search_category_children_options, true); return array_keys($categories); }
private function build_form(HTTPRequestCustom $request) { $form = new HTMLForm(__CLASS__); $fieldset = new FormFieldsetHTML('articles', $this->lang['articles']); $form->add_fieldset($fieldset); $fieldset->add_field(new FormFieldTextEditor('title', $this->common_lang['form.title'], $this->get_article()->get_title(), array('required' => true))); if (!$this->is_contributor_member()) { $fieldset->add_field(new FormFieldCheckbox('personalize_rewrited_title', $this->common_lang['form.rewrited_name.personalize'], $this->get_article()->rewrited_title_is_personalized(), array('events' => array('click' => ' if (HTMLForms.getField("personalize_rewrited_title").getValue()) { HTMLForms.getField("rewrited_title").enable(); } else { HTMLForms.getField("rewrited_title").disable(); }')))); $fieldset->add_field(new FormFieldTextEditor('rewrited_title', $this->common_lang['form.rewrited_name'], $this->get_article()->get_rewrited_title(), array('description' => $this->common_lang['form.rewrited_name.description'], 'hidden' => !$this->get_article()->rewrited_title_is_personalized()), array(new FormFieldConstraintRegex('`^[a-z0-9\\-]+$`i')))); } $search_category_children_options = new SearchCategoryChildrensOptions(); $search_category_children_options->add_authorizations_bits(Category::READ_AUTHORIZATIONS); $search_category_children_options->add_authorizations_bits(Category::CONTRIBUTION_AUTHORIZATIONS); $fieldset->add_field(ArticlesService::get_categories_manager()->get_select_categories_form_field('id_category', $this->common_lang['form.category'], $this->get_article()->get_id_category(), $search_category_children_options)); $fieldset->add_field(new FormFieldCheckbox('enable_description', $this->lang['articles.form.description_enabled'], $this->get_article()->get_description_enabled(), array('description' => StringVars::replace_vars($this->lang['articles.form.description_enabled.description'], array('number' => ArticlesConfig::load()->get_number_character_to_cut())), 'events' => array('click' => ' if (HTMLForms.getField("enable_description").getValue()) { HTMLForms.getField("description").enable(); } else { HTMLForms.getField("description").disable(); }')))); $fieldset->add_field(new FormFieldRichTextEditor('description', StringVars::replace_vars($this->lang['articles.form.description'], array('number' => ArticlesConfig::load()->get_number_character_to_cut())), $this->get_article()->get_description(), array('rows' => 3, 'hidden' => !$this->get_article()->get_description_enabled()))); $fieldset->add_field(new FormFieldRichTextEditor('contents', $this->common_lang['form.contents'], $this->get_article()->get_contents(), array('rows' => 15, 'required' => true))); $onclick_action = 'javascript:bbcode_page();'; $fieldset->add_field(new FormFieldActionLink('add_page', $this->lang['articles.form.add_page'], $onclick_action, PATH_TO_ROOT . '/articles/templates/images/pagebreak.png')); $other_fieldset = new FormFieldsetHTML('other', $this->common_lang['form.other']); $form->add_fieldset($other_fieldset); $other_fieldset->add_field(new FormFieldCheckbox('author_name_displayed', LangLoader::get_message('config.author_displayed', 'admin-common'), $this->get_article()->get_author_name_displayed())); $other_fieldset->add_field(new FormFieldCheckbox('notation_enabled', LangLoader::get_message('config.notation_enabled', 'admin-common'), $this->get_article()->get_notation_enabled())); $other_fieldset->add_field(new FormFieldUploadPictureFile('picture', $this->common_lang['form.picture'], $this->get_article()->get_picture()->relative())); $other_fieldset->add_field(ArticlesService::get_keywords_manager()->get_form_field($this->get_article()->get_id(), 'keywords', $this->common_lang['form.keywords'], array('description' => $this->common_lang['form.keywords.description']))); $other_fieldset->add_field(new ArticlesFormFieldSelectSources('sources', $this->common_lang['form.sources'], $this->get_article()->get_sources())); if (!$this->is_contributor_member()) { $publication_fieldset = new FormFieldsetHTML('publication', $this->common_lang['form.approbation']); $form->add_fieldset($publication_fieldset); $publication_fieldset->add_field(new FormFieldDateTime('date_created', $this->common_lang['form.date.creation'], $this->get_article()->get_date_created(), array('required' => true))); $publication_fieldset->add_field(new FormFieldSimpleSelectChoice('publishing_state', $this->common_lang['form.approbation'], $this->get_article()->get_publishing_state(), array(new FormFieldSelectChoiceOption($this->common_lang['form.approbation.not'], Article::NOT_PUBLISHED), new FormFieldSelectChoiceOption($this->common_lang['form.approbation.now'], Article::PUBLISHED_NOW), new FormFieldSelectChoiceOption($this->common_lang['status.approved.date'], Article::PUBLISHED_DATE)), array('events' => array('change' => ' if (HTMLForms.getField("publishing_state").getValue() == 2) { jQuery("#' . __CLASS__ . '_publishing_start_date_field").show(); HTMLForms.getField("end_date_enable").enable(); } else { jQuery("#' . __CLASS__ . '_publishing_start_date_field").hide(); HTMLForms.getField("end_date_enable").disable(); }')))); $publication_fieldset->add_field(new FormFieldDateTime('publishing_start_date', $this->common_lang['form.date.start'], $this->get_article()->get_publishing_start_date() === null ? new Date() : $this->get_article()->get_publishing_start_date(), array('hidden' => $this->get_article()->get_publishing_state() != Article::PUBLISHED_DATE))); $publication_fieldset->add_field(new FormFieldCheckbox('end_date_enable', $this->common_lang['form.date.end.enable'], $this->get_article()->end_date_enabled(), array('hidden' => $this->get_article()->get_publishing_state() != Article::PUBLISHED_DATE, 'events' => array('click' => ' if (HTMLForms.getField("end_date_enable").getValue()) { HTMLForms.getField("publishing_end_date").enable(); } else { HTMLForms.getField("publishing_end_date").disable(); }')))); $publication_fieldset->add_field(new FormFieldDateTime('publishing_end_date', $this->common_lang['form.date.end'], $this->get_article()->get_publishing_end_date() === null ? new date() : $this->get_article()->get_publishing_end_date(), array('hidden' => !$this->get_article()->end_date_enabled()))); } $this->build_contribution_fieldset($form); $fieldset->add_field(new FormFieldHidden('referrer', $request->get_url_referrer())); $this->submit_button = new FormButtonDefaultSubmit(); $form->add_button($this->submit_button); $form->add_button(new FormButtonReset()); $this->form = $form; // Positionnement à la bonne page quand on édite un article avec plusieurs pages if ($this->get_article()->get_id() !== null) { $current_page = $request->get_getstring('page', ''); $this->tpl->put('C_PAGE', !empty($current_page)); if (!empty($current_page)) { $article_contents = $this->article->get_contents(); //If article doesn't begin with a page, we insert one if (substr(trim($article_contents), 0, 6) != '[page]') { $article_contents = '[page] [/page]' . $article_contents; } //Removing [page] bbcode $article_contents_clean = preg_split('`\\[page\\].+\\[/page\\](.*)`Us', $article_contents, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); //Retrieving pages preg_match_all('`\\[page\\]([^[]+)\\[/page\\]`U', $article_contents, $array_page); $page_name = isset($array_page[1][$current_page - 1]) && $array_page[1][$current_page - 1] != ' ' ? $array_page[1][$current_page - 1] : ''; $this->tpl->put('PAGE', TextHelper::to_js_string($page_name)); } } }
private function get_pagination($condition, $parameters, $field, $mode, $page) { $number_articles = PersistenceContext::get_querier()->count(ArticlesSetup::$articles_table, $condition, $parameters); $pagination = new ModulePagination($page, $number_articles, (int) ArticlesConfig::load()->get_number_articles_per_page()); $pagination->set_url(ArticlesUrlBuilder::display_pending_articles($field, $mode, '/%d')); if ($pagination->current_page_is_empty() && $page > 1) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } return $pagination; }
public function get_tpl_vars() { $category = $this->get_category(); $description = $this->get_real_description(); $user = $this->get_author_user(); $user_group_color = User::get_group_color($user->get_groups(), $user->get_level(), true); $sources = $this->get_sources(); $nbr_sources = count($sources); return array('C_EDIT' => $this->is_authorized_to_edit(), 'C_DELETE' => $this->is_authorized_to_delete(), 'C_HAS_PICTURE' => $this->has_picture(), 'C_USER_GROUP_COLOR' => !empty($user_group_color), 'C_PUBLISHED' => $this->is_published(), 'C_PUBLISHING_START_AND_END_DATE' => $this->publishing_start_date != null && $this->publishing_end_date != null, 'C_PUBLISHING_START_DATE' => $this->publishing_start_date != null, 'C_PUBLISHING_END_DATE' => $this->publishing_end_date != null, 'C_DATE_UPDATED' => $this->date_updated != null, 'C_AUTHOR_DISPLAYED' => $this->get_author_name_displayed(), 'C_NOTATION_ENABLED' => $this->get_notation_enabled(), 'C_READ_MORE' => !$this->get_description_enabled() && $description != FormatingHelper::second_parse($this->contents) && strlen($description) >= ArticlesConfig::load()->get_number_character_to_cut(), 'C_SOURCES' => $nbr_sources > 0, 'ID' => $this->get_id(), 'TITLE' => $this->get_title(), 'DATE' => $this->get_date_created()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE_TEXT), 'DATE_DAY' => $this->get_date_created()->get_day(), 'DATE_MONTH' => $this->get_date_created()->get_month(), 'DATE_YEAR' => $this->get_date_created()->get_year(), 'DATE_ISO8601' => $this->get_date_created()->format(Date::FORMAT_ISO8601), 'DATE_SHORT' => $this->get_date_created()->format(Date::FORMAT_DAY_MONTH_YEAR), 'STATUS' => $this->get_status(), 'PUBLISHING_START_DATE' => $this->publishing_start_date != null ? $this->publishing_start_date->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE) : '', 'PUBLISHING_START_DATE_ISO8601' => $this->publishing_start_date != null ? $this->publishing_start_date->format(Date::FORMAT_ISO8601) : '', 'PUBLISHING_END_DATE' => $this->publishing_end_date != null ? $this->publishing_end_date->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE) : '', 'PUBLISHING_END_DATE_ISO8601' => $this->publishing_end_date != null ? $this->publishing_end_date->format(Date::FORMAT_ISO8601) : '', 'DATE_UPDATED' => $this->date_updated != null ? $this->date_updated->format(Date::FORMAT_DAY_MONTH_YEAR) : '', 'DATE_UPDATED_DAY' => $this->date_updated != null ? $this->date_updated->get_day() : '', 'DATE_UPDATED_MONTH' => $this->date_updated != null ? $this->date_updated->get_month() : '', 'DATE_UPDATED_YEAR' => $this->date_updated != null ? $this->date_updated->get_year() : '', 'DATE_UPDATED_ISO8601' => $this->date_updated != null ? $this->date_updated->format(Date::FORMAT_ISO8601) : '', 'DATE_UPDATED_SHORT' => $this->date_updated != null ? $this->date_updated->format(Date::FORMAT_DAY_MONTH_YEAR) : '', 'L_COMMENTS' => CommentsService::get_number_and_lang_comments('articles', $this->get_id()), 'NUMBER_COMMENTS' => CommentsService::get_number_comments('articles', $this->get_id()), 'NUMBER_VIEW' => $this->get_number_view(), 'NOTE' => $this->get_notation()->get_number_notes() > 0 ? NotationService::display_static_image($this->get_notation()) : ' ', 'C_AUTHOR_EXIST' => $user->get_id() !== User::VISITOR_LEVEL, 'PSEUDO' => $user->get_display_name(), 'DESCRIPTION' => $description, 'PICTURE' => $this->get_picture()->rel(), 'USER_LEVEL_CLASS' => UserService::get_level_class($user->get_level()), 'USER_GROUP_COLOR' => $user_group_color, 'C_ROOT_CATEGORY' => $category->get_id() == Category::ROOT_CATEGORY, 'CATEGORY_ID' => $category->get_id(), 'CATEGORY_NAME' => $category->get_name(), 'CATEGORY_DESCRIPTION' => $category->get_description(), 'CATEGORY_IMAGE' => $category->get_image()->rel(), 'U_EDIT_CATEGORY' => $category->get_id() == Category::ROOT_CATEGORY ? ArticlesUrlBuilder::configuration()->rel() : ArticlesUrlBuilder::edit_category($category->get_id())->rel(), 'U_COMMENTS' => ArticlesUrlBuilder::display_comments_article($category->get_id(), $category->get_rewrited_name(), $this->get_id(), $this->get_rewrited_title())->rel(), 'U_AUTHOR' => UserUrlBuilder::profile($this->get_author_user()->get_id())->rel(), 'U_CATEGORY' => ArticlesUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name())->rel(), 'U_ARTICLE' => ArticlesUrlBuilder::display_article($category->get_id(), $category->get_rewrited_name(), $this->get_id(), $this->get_rewrited_title())->rel(), 'U_EDIT_ARTICLE' => ArticlesUrlBuilder::edit_article($this->id, AppContext::get_request()->get_getint('page', 1))->rel(), 'U_DELETE_ARTICLE' => ArticlesUrlBuilder::delete_article($this->id)->rel(), 'U_SYNDICATION' => ArticlesUrlBuilder::category_syndication($category->get_id())->rel(), 'U_PRINT_ARTICLE' => ArticlesUrlBuilder::print_article($this->get_id(), $this->get_rewrited_title())->rel()); }
private function get_pagination($condition, $parameters, $field, $mode, $page) { $result = PersistenceContext::get_querier()->select_single_row_query('SELECT COUNT(*) AS nbr_articles FROM ' . ArticlesSetup::$articles_table . ' articles LEFT JOIN ' . DB_TABLE_KEYWORDS_RELATIONS . ' relation ON relation.module_id = \'articles\' AND relation.id_in_module = articles.id ' . $condition, $parameters); $pagination = new ModulePagination($page, $result['nbr_articles'], ArticlesConfig::load()->get_number_articles_per_page()); $pagination->set_url(ArticlesUrlBuilder::display_tag($this->get_keyword()->get_rewrited_name(), $field, $mode, '%d')); if ($pagination->current_page_is_empty() && $page > 1) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } return $pagination; }
private function init() { $this->lang = LangLoader::get('common', 'articles'); $this->admin_common_lang = LangLoader::get('admin-common'); $this->config = ArticlesConfig::load(); }