public function get_search_request($args) { $now = new Date(); $authorized_categories = ArticlesService::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\tarticles.id AS id_content,\n\t\t\tarticles.title AS title,\n\t\t\t(2 * FT_SEARCH_RELEVANCE(articles.title, '" . $args['search'] . "') + (FT_SEARCH_RELEVANCE(articles.contents, '" . $args['search'] . "') +\n\t\t\tFT_SEARCH_RELEVANCE(articles.description, '" . $args['search'] . "')) / 2 ) / 3 * " . $weight . " AS relevance,\n\t\t\tCONCAT('" . PATH_TO_ROOT . "/articles/index.php?url=/', id_category, '-', IF(id_category != 0, cat.rewrited_name, 'root'), '/', articles.id, '-', articles.rewrited_title) AS link\n\t\t\tFROM " . ArticlesSetup::$articles_table . " articles\n\t\t\tLEFT JOIN " . ArticlesSetup::$articles_cats_table . " cat ON cat.id = articles.id_category\n\t\t\tWHERE ( FT_SEARCH(articles.title, '" . $args['search'] . "') OR FT_SEARCH(articles.contents, '" . $args['search'] . "') OR FT_SEARCH_RELEVANCE(articles.description, '" . $args['search'] . "') )\n\t\t\tAND id_category IN(" . implode(", ", $authorized_categories) . ")\n\t\t\tAND (published = 1 OR (published = 2 AND publishing_start_date < '" . $now->get_timestamp() . "' AND (publishing_end_date > '" . $now->get_timestamp() . "' OR publishing_end_date = 0)))\n\t\t\tORDER BY relevance DESC\n\t\t\tLIMIT 100 OFFSET 0"; }
private function get_article() { if ($this->article === null) { $this->article = ArticlesService::get_article('WHERE articles.id=:id', array('id' => $this->get_id_in_module())); } return $this->article; }
private function build_view($request) { $now = new Date(); $authorized_categories = ArticlesService::get_authorized_categories(Category::ROOT_CATEGORY); $config = ArticlesConfig::load(); $mode = $request->get_getstring('sort', 'desc'); $field = $request->get_getstring('field', 'date'); $sort_mode = $mode == 'asc' ? 'ASC' : 'DESC'; switch ($field) { case 'title': $sort_field = 'title'; break; case 'view': $sort_field = 'number_view'; break; case 'com': $sort_field = 'number_comments'; break; case 'note': $sort_field = 'average_notes'; break; case 'author': $sort_field = 'display_name'; break; default: $sort_field = 'date_created'; break; } $condition = 'WHERE id_category IN :authorized_categories ' . (!ArticlesAuthorizationsService::check_authorizations()->moderation() ? ' AND author_user_id = :user_id' : '') . ' AND (published = 0 OR (published = 2 AND (publishing_start_date > :timestamp_now OR (publishing_end_date != 0 AND publishing_end_date < :timestamp_now))))'; $parameters = array('authorized_categories' => $authorized_categories, 'user_id' => AppContext::get_current_user()->get_id(), 'timestamp_now' => $now->get_timestamp()); $page = AppContext::get_request()->get_getint('page', 1); $pagination = $this->get_pagination($condition, $parameters, $field, $mode, $page); $result = PersistenceContext::get_querier()->select('SELECT articles.*, member.*, com.number_comments, notes.number_notes, notes.average_notes, note.note FROM ' . ArticlesSetup::$articles_table . ' articles LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = articles.author_user_id LEFT JOIN ' . DB_TABLE_COMMENTS_TOPIC . ' com ON com.id_in_module = articles.id AND com.module_id = "articles" LEFT JOIN ' . DB_TABLE_AVERAGE_NOTES . ' notes ON notes.id_in_module = articles.id AND notes.module_name = "articles" LEFT JOIN ' . DB_TABLE_NOTE . ' note ON note.id_in_module = articles.id AND note.module_name = "articles" AND note.user_id = :user_id ' . $condition . ' ORDER BY ' . $sort_field . ' ' . $sort_mode . ' LIMIT :number_items_per_page OFFSET :display_from', array_merge($parameters, array('number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from()))); $nbr_articles_pending = $result->get_rows_count(); $this->build_form($field, $mode); $this->view->put_all(array('C_PENDING' => true, 'C_MOSAIC' => $config->get_display_type() == ArticlesConfig::DISPLAY_MOSAIC, 'C_NO_ARTICLE_AVAILABLE' => $nbr_articles_pending == 0)); if ($nbr_articles_pending > 0) { $this->view->put_all(array('C_ARTICLES_FILTERS' => true, 'C_COMMENTS_ENABLED' => $config->are_comments_enabled(), 'C_NOTATION_ENABLED' => $config->is_notation_enabled(), 'C_PAGINATION' => $pagination->has_several_pages(), 'PAGINATION' => $pagination->display())); while ($row = $result->fetch()) { $article = new Article(); $article->set_properties($row); $this->build_keywords_view($article); $this->view->assign_block_vars('articles', $article->get_tpl_vars()); $this->build_sources_view($article); } } $result->dispose(); $this->view->put('FORM', $this->form->display()); }
private function get_article(HTTPRequestCustom $request) { $id = $request->get_getint('id', 0); if (!empty($id)) { try { return ArticlesService::get_article('WHERE articles.id=:id', array('id' => $id)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } }
private function get_article() { if ($this->article === null) { $id = AppContext::get_request()->get_getint('id', 0); if (!empty($id)) { try { $this->article = ArticlesService::get_article('WHERE articles.id=:id', array('id' => $id)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } else { $this->article = new Article(); } } return $this->article; }
public function get_feed_data_struct($idcat = 0, $name = '') { if (ArticlesService::get_categories_manager()->get_categories_cache()->category_exists($idcat)) { $querier = PersistenceContext::get_querier(); $category = ArticlesService::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('articles.feed_name', 'common', 'articles'); $data = new FeedData(); $data->set_title($feed_module_name . ' - ' . $site_name); $data->set_date(new Date()); $data->set_link(SyndicationUrlBuilder::rss('articles', $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 = ArticlesService::get_categories_manager()->get_childrens($idcat, new SearchCategoryChildrensOptions(), true); $ids_categories = array_keys($categories); $now = new Date(); $results = $querier->select('SELECT articles.id, articles.id_category, articles.title, articles.rewrited_title, articles.picture_url, articles.contents, articles.description, articles.date_created, cat.rewrited_name AS rewrited_name_cat FROM ' . ArticlesSetup::$articles_table . ' articles LEFT JOIN ' . ArticlesSetup::$articles_cats_table . ' cat ON cat.id = articles.id_category WHERE articles.id_category IN :cats_ids AND (published = 1 OR (published = 2 AND publishing_start_date < :timestamp_now AND (publishing_end_date > :timestamp_now OR publishing_end_date = 0))) ORDER BY articles.date_created DESC', array('cats_ids' => $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 = ArticlesUrlBuilder::display_article($row['id_category'], $row['rewrited_name_cat'], $row['id'], $row['rewrited_title']); $item = new FeedItem(); $item->set_title($row['title']); $item->set_link($link); $item->set_guid($link); $item->set_desc(FormatingHelper::second_parse($row['contents'])); $item->set_date(new Date($row['date_created'], Timezone::SERVER_TIMEZONE)); $item->set_image_url($row['picture_url']); $item->set_auth(ArticlesService::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 process() { $container = $this->getProperty('container', false); if (!$container) { return false; } $parent = $this->modx->getObject('modResource', $container); if (!$parent) { return false; } $articles = $parent->getMany('Children', array('deleted' => 0)); $articleIDs = array(); foreach ($articles as $article) { $articleIDs[] = $article->id; } $templateVariable = $this->modx->getObject('modTemplateVar', array('name' => 'articlestags')); if (!$templateVariable) { return false; } $c = $this->modx->newQuery('modTemplateVarResource'); $c->where(array('tmplvarid' => $templateVariable->id, 'contentid:IN' => $articleIDs)); $tagsObject = $this->modx->getCollection('modTemplateVarResource', $c); $tags = array(); foreach ($tagsObject as $tagObject) { $addTags = explode(',', $tagObject->value); foreach ($addTags as &$addTag) { $addTag = trim($addTag); } $tags = array_merge($tags, $addTags); } $tags = ArticlesService::arrayUnique($tags); sort($tags); $returnArray = array(); foreach ($tags as $tag) { $returnArray[] = array($tag); } return $this->success('', $returnArray); }
public static function get_keywords_manager() { if (self::$keywords_manager === null) { self::$keywords_manager = new KeywordsManager('articles'); } return self::$keywords_manager; }
public function __construct() { parent::__construct(ArticlesService::get_categories_manager()); }
private function is_authorized($bit, $mode = Authorizations::AUTH_CHILD_PRIORITY) { $auth = ArticlesService::get_categories_manager()->get_heritated_authorizations($this->id_category, $bit, $mode); return AppContext::get_current_user()->check_auth($auth, $bit); }
private function save() { $this->config->set_number_articles_per_page($this->form->get_value('number_articles_per_page')); if ($this->form->get_value('display_icon_cats')) { $this->config->enable_cats_icon(); $this->config->set_number_cols_display_cats($this->form->get_value('number_cols_display_cats')); } else { $this->config->disable_cats_icon(); } $this->config->set_number_categories_per_page($this->form->get_value('number_categories_per_page')); $this->config->set_number_character_to_cut($this->form->get_value('number_character_to_cut', $this->config->get_number_character_to_cut())); 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('articles', $this->config->get_notation_scale(), $this->form->get_value('notation_scale')); } } else { $this->config->disable_notation(); } if ($this->form->get_value('comments_enabled')) { $this->config->enable_comments(); } else { $this->config->disable_comments(); } if ($this->form->get_value('display_descriptions_to_guests')) { $this->config->display_descriptions_to_guests(); } else { $this->config->hide_descriptions_to_guests(); } $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()); ArticlesConfig::save(); ArticlesService::get_categories_manager()->regenerate_cache(); }
public function uninstall() { $this->drop_tables(); ConfigManager::delete('articles', 'config'); ArticlesService::get_keywords_manager()->delete_module_relations(); }
private function generate_response() { $response = new SiteDisplayResponse($this->tpl); $graphical_environment = $response->get_graphical_environment(); $graphical_environment->set_page_title($this->article->get_title(), $this->lang['articles']); $graphical_environment->get_seo_meta_data()->set_description($this->article->get_description()); $graphical_environment->get_seo_meta_data()->set_canonical_url(ArticlesUrlBuilder::display_article($this->category->get_id(), $this->category->get_rewrited_name(), $this->article->get_id(), $this->article->get_rewrited_title(), AppContext::get_request()->get_getint('page', 1))); $breadcrumb = $graphical_environment->get_breadcrumb(); $breadcrumb->add($this->lang['articles'], ArticlesUrlBuilder::home()); $categories = array_reverse(ArticlesService::get_categories_manager()->get_parents($this->article->get_id_category(), true)); foreach ($categories as $id => $category) { if ($category->get_id() != Category::ROOT_CATEGORY) { $breadcrumb->add($category->get_name(), ArticlesUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name())); } } $breadcrumb->add($this->article->get_title(), ArticlesUrlBuilder::display_article($category->get_id(), $category->get_rewrited_name(), $this->article->get_id(), $this->article->get_rewrited_title())); return $response; }
public function get_keywords() { if ($this->keywords === null) { $this->keywords = ArticlesService::get_keywords_manager()->get_keywords($this->id); } return $this->keywords; }
protected function get_categories_manager() { return ArticlesService::get_categories_manager(); }
private function build_response(View $tpl) { $article = $this->get_article(); $response = new SiteDisplayResponse($tpl); $graphical_environment = $response->get_graphical_environment(); $breadcrumb = $graphical_environment->get_breadcrumb(); $breadcrumb->add($this->lang['articles'], ArticlesUrlBuilder::home()); if ($article->get_id() === null) { $breadcrumb->add($this->lang['articles.add'], ArticlesUrlBuilder::add_article($article->get_id_category())); $graphical_environment->set_page_title($this->lang['articles.add'], $this->lang['articles']); $graphical_environment->get_seo_meta_data()->set_description($this->lang['articles.add']); $graphical_environment->get_seo_meta_data()->set_canonical_url(ArticlesUrlBuilder::add_article($article->get_id_category())); } else { $categories = array_reverse(ArticlesService::get_categories_manager()->get_parents($article->get_id_category(), true)); foreach ($categories as $id => $category) { if ($category->get_id() != Category::ROOT_CATEGORY) { $breadcrumb->add($category->get_name(), ArticlesUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name())); } } $breadcrumb->add($article->get_title(), ArticlesUrlBuilder::display_article($category->get_id(), $category->get_rewrited_name(), $article->get_id(), $article->get_rewrited_title())); $breadcrumb->add($this->lang['articles.edit'], ArticlesUrlBuilder::edit_article($article->get_id())); $graphical_environment->set_page_title($this->lang['articles.edit'], $this->lang['articles']); $graphical_environment->get_seo_meta_data()->set_description($this->lang['articles.edit']); $graphical_environment->get_seo_meta_data()->set_canonical_url(ArticlesUrlBuilder::edit_article($article->get_id())); } return $response; }
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); }