public function get_root_category() { $root = new RichRootCategory(); $root->set_authorizations(NewsConfig::load()->get_authorizations()); $root->set_description(StringVars::replace_vars(LangLoader::get_message('news.seo.description.root', 'common', 'news'), array('site' => GeneralConfig::load()->get_site_name()))); 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(NewsConfig::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('news', $this->lang['news']); $form->add_fieldset($fieldset); $fieldset->add_field(new FormFieldTextEditor('name', $this->common_lang['form.name'], $this->get_news()->get_name(), array('required' => true))); if (!$this->is_contributor_member()) { $fieldset->add_field(new FormFieldCheckbox('personalize_rewrited_name', $this->common_lang['form.rewrited_name.personalize'], $this->get_news()->rewrited_name_is_personalized(), array('events' => array('click' => ' if (HTMLForms.getField("personalize_rewrited_name").getValue()) { HTMLForms.getField("rewrited_name").enable(); } else { HTMLForms.getField("rewrited_name").disable(); }')))); $fieldset->add_field(new FormFieldTextEditor('rewrited_name', $this->common_lang['form.rewrited_name'], $this->get_news()->get_rewrited_name(), array('description' => $this->common_lang['form.rewrited_name.description'], 'hidden' => !$this->get_news()->rewrited_name_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(NewsService::get_categories_manager()->get_select_categories_form_field('id_cat', $this->common_lang['form.category'], $this->get_news()->get_id_cat(), $search_category_children_options)); $fieldset->add_field(new FormFieldRichTextEditor('contents', $this->common_lang['form.contents'], $this->get_news()->get_contents(), array('rows' => 15, 'required' => true))); $fieldset->add_field(new FormFieldCheckbox('enable_short_contents', $this->lang['news.form.short_contents.enabled'], $this->get_news()->get_short_contents_enabled(), array('description' => StringVars::replace_vars($this->lang['news.form.short_contents.enabled.description'], array('number' => NewsConfig::load()->get_number_character_to_cut())), 'events' => array('click' => ' if (HTMLForms.getField("enable_short_contents").getValue()) { HTMLForms.getField("short_contents").enable(); } else { HTMLForms.getField("short_contents").disable(); }')))); $fieldset->add_field(new FormFieldRichTextEditor('short_contents', $this->lang['news.form.short_contents'], $this->get_news()->get_short_contents(), array('hidden' => !$this->get_news()->get_short_contents_enabled(), 'description' => !NewsConfig::load()->get_display_condensed_enabled() ? '<span class="color-alert">' . $this->lang['news.form.short_contents.description'] . '</span>' : ''))); $other_fieldset = new FormFieldsetHTML('other', $this->common_lang['form.other']); $form->add_fieldset($other_fieldset); $other_fieldset->add_field(new FormFieldUploadFile('picture', $this->common_lang['form.picture'], $this->get_news()->get_picture()->relative())); $other_fieldset->add_field(NewsService::get_keywords_manager()->get_form_field($this->get_news()->get_id(), 'keywords', $this->common_lang['form.keywords'], array('description' => $this->common_lang['form.keywords.description']))); $other_fieldset->add_field(new NewsFormFieldSelectSources('sources', $this->common_lang['form.sources'], $this->get_news()->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('creation_date', $this->common_lang['form.date.creation'], $this->get_news()->get_creation_date(), array('required' => true))); $publication_fieldset->add_field(new FormFieldSimpleSelectChoice('approbation_type', $this->common_lang['form.approbation'], $this->get_news()->get_approbation_type(), array(new FormFieldSelectChoiceOption($this->common_lang['form.approbation.not'], News::NOT_APPROVAL), new FormFieldSelectChoiceOption($this->common_lang['form.approbation.now'], News::APPROVAL_NOW), new FormFieldSelectChoiceOption($this->common_lang['status.approved.date'], News::APPROVAL_DATE)), array('events' => array('change' => ' if (HTMLForms.getField("approbation_type").getValue() == 2) { jQuery("#' . __CLASS__ . '_start_date_field").show(); HTMLForms.getField("end_date_enable").enable(); } else { jQuery("#' . __CLASS__ . '_start_date_field").hide(); HTMLForms.getField("end_date_enable").disable(); }')))); $publication_fieldset->add_field(new FormFieldDateTime('start_date', $this->common_lang['form.date.start'], $this->get_news()->get_start_date() === null ? new Date() : $this->get_news()->get_start_date(), array('hidden' => $this->get_news()->get_approbation_type() != News::APPROVAL_DATE))); $publication_fieldset->add_field(new FormFieldCheckbox('end_date_enable', $this->common_lang['form.date.end.enable'], $this->get_news()->end_date_enabled(), array('hidden' => $this->get_news()->get_approbation_type() != News::APPROVAL_DATE, 'events' => array('click' => ' if (HTMLForms.getField("end_date_enable").getValue()) { HTMLForms.getField("end_date").enable(); } else { HTMLForms.getField("end_date").disable(); }')))); $publication_fieldset->add_field(new FormFieldDateTime('end_date', $this->common_lang['form.date.end'], $this->get_news()->get_end_date() === null ? new Date() : $this->get_news()->get_end_date(), array('hidden' => !$this->get_news()->end_date_enabled()))); $publication_fieldset->add_field(new FormFieldCheckbox('top_list', $this->lang['news.form.top_list'], $this->get_news()->top_list_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; }
private function get_pagination($condition, $parameters, $page) { $result = PersistenceContext::get_querier()->select_single_row_query('SELECT COUNT(*) AS nbr_news FROM ' . NewsSetup::$news_table . ' news LEFT JOIN ' . DB_TABLE_KEYWORDS_RELATIONS . ' relation ON relation.module_id = \'news\' AND relation.id_in_module = news.id ' . $condition, $parameters); $pagination = new ModulePagination($page, $result['nbr_news'], (int) NewsConfig::load()->get_number_news_per_page()); $pagination->set_url(NewsUrlBuilder::display_tag($this->get_keyword()->get_rewrited_name(), '%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', 'news'); $this->admin_common_lang = LangLoader::get('admin-common'); $this->config = NewsConfig::load(); }
private function get_pagination($condition, $parameters, $page) { $number_news = PersistenceContext::get_querier()->count(NewsSetup::$news_table, $condition, $parameters); $pagination = new ModulePagination($page, $number_news, (int) NewsConfig::load()->get_number_news_per_page()); $pagination->set_url(NewsUrlBuilder::display_pending_news('%d')); if ($pagination->current_page_is_empty() && $page > 1) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } return $pagination; }
public function get_array_tpl_vars() { $news_config = NewsConfig::load(); $category = $this->get_category(); $contents = FormatingHelper::second_parse($this->contents); $description = $this->get_real_short_contents(); $user = $this->get_author_user(); $user_group_color = User::get_group_color($user->get_groups(), $user->get_level(), true); $number_comments = CommentsService::get_number_comments('news', $this->id); $sources = $this->get_sources(); $nbr_sources = count($sources); return array('C_VISIBLE' => $this->is_visible(), 'C_EDIT' => $this->is_authorized_to_edit(), 'C_DELETE' => $this->is_authorized_to_delete(), 'C_PICTURE' => $this->has_picture(), 'C_USER_GROUP_COLOR' => !empty($user_group_color), 'C_AUTHOR_DISPLAYED' => $news_config->get_author_displayed(), 'C_READ_MORE' => !$this->get_short_contents_enabled() && $description != $contents && strlen($description) >= $news_config->get_number_character_to_cut(), 'C_SOURCES' => $nbr_sources > 0, 'ID' => $this->id, 'NAME' => $this->name, 'CONTENTS' => $contents, 'DESCRIPTION' => $description, 'DATE' => $this->creation_date->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE_TEXT), 'DATE_DAY' => $this->creation_date->get_day(), 'DATE_MONTH' => $this->creation_date->get_month(), 'DATE_YEAR' => $this->creation_date->get_year(), 'DATE_ISO8601' => $this->creation_date->format(Date::FORMAT_ISO8601), 'DATE_DAY' => $this->creation_date->get_day(), 'DATE_MONTH' => $this->creation_date->get_month(), 'DATE_YEAR' => $this->creation_date->get_year(), 'STATUS' => $this->get_status(), 'C_AUTHOR_EXIST' => $user->get_id() !== User::VISITOR_LEVEL, 'PSEUDO' => $user->get_display_name(), 'USER_LEVEL_CLASS' => UserService::get_level_class($user->get_level()), 'USER_GROUP_COLOR' => $user_group_color, 'C_COMMENTS' => !empty($number_comments), 'L_COMMENTS' => CommentsService::get_lang_comments('news', $this->id), 'NUMBER_COMMENTS' => CommentsService::get_number_comments('news', $this->id), '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 ? NewsUrlBuilder::configuration()->rel() : NewsUrlBuilder::edit_category($category->get_id())->rel(), 'U_SYNDICATION' => SyndicationUrlBuilder::rss('news', $this->id_cat)->rel(), 'U_AUTHOR_PROFILE' => UserUrlBuilder::profile($this->get_author_user()->get_id())->rel(), 'U_LINK' => NewsUrlBuilder::display_news($category->get_id(), $category->get_rewrited_name(), $this->id, $this->rewrited_name)->rel(), 'U_CATEGORY' => NewsUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name())->rel(), 'U_EDIT' => NewsUrlBuilder::edit_news($this->id)->rel(), 'U_DELETE' => NewsUrlBuilder::delete_news($this->id)->rel(), 'U_PICTURE' => $this->get_picture()->rel(), 'U_COMMENTS' => NewsUrlBuilder::display_comments_news($category->get_id(), $category->get_rewrited_name(), $this->id, $this->rewrited_name)->rel()); }
private function build_suggested_news(News $news) { $now = new Date(); $result = PersistenceContext::get_querier()->select(' SELECT id, name, id_category, rewrited_name, (2 * FT_SEARCH_RELEVANCE(name, :search_content) + FT_SEARCH_RELEVANCE(contents, :search_content) / 3) AS relevance FROM ' . NewsSetup::$news_table . ' WHERE (FT_SEARCH(name, :search_content) OR FT_SEARCH(contents, :search_content)) AND id <> :excluded_id AND (approbation_type = 1 OR (approbation_type = 2 AND start_date < :timestamp_now AND (end_date > :timestamp_now OR end_date = 0))) ORDER BY relevance DESC LIMIT 0, 10', array('excluded_id' => $news->get_id(), 'search_content' => $news->get_name() . ',' . $news->get_contents(), 'timestamp_now' => $now->get_timestamp())); $this->tpl->put('C_SUGGESTED_NEWS', $result->get_rows_count() > 0 && NewsConfig::load()->get_news_suggestions_enabled()); while ($row = $result->fetch()) { $this->tpl->assign_block_vars('suggested', array('NAME' => $row['name'], 'URL' => NewsUrlBuilder::display_news($row['id_category'], NewsService::get_categories_manager()->get_categories_cache()->get_category($row['id_category'])->get_rewrited_name(), $row['id'], $row['rewrited_name'])->rel())); } $result->dispose(); }