/** * private функция формирует RSS для статей * * @param (int) $id - id раздела, статьи которого необходимо показать (по умолчанию false) * * @return string */ protected function rssArticles($id = false) { // создаем объекты $articles = new articles(); $artsections = new artsections(); // получаем список разделов $sections = $artsections->getSections("token IN ('active')"); // формируем данные шапки $this->title[] = array('name' => MENU_ARTICLES); $this->link = chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?do=rss&action=articles'); $this->description = MENU_ARTICLES; // проверяем просмотр по разделу if (!empty($id) && !empty($sections[$id])) { // выбираем статьи с учетом раздела $arrArticles = $articles->getPuplishedArticles("id_section=" . secure::escQuoteData($id), false, array('strLimit' => '0,' . CONF_RSS_ARTICLES_COUNT, 'calcRows' => false), array('id', 'title', 'small_text', 'datetime', 'id_section')); // Дописываем данные по разделу в шапку $this->title[] = array('name' => $sections[$id]['name']); $this->description .= ' - ' . $sections[$id]['name']; } else { $arrArticles = $articles->getPuplishedArticles(false, false, array('strLimit' => '0,' . CONF_RSS_ARTICLES_COUNT, 'calcRows' => false), array('id', 'title', 'small_text', 'datetime', 'id_section')); } /***** Формируем XML-документ *****/ $data = '<?xml version="1.0" encoding="' . CONF_DEFAULT_CHARSET . '" ?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <atom:link href="' . $this->link . '" rel="self" type="application/rss+xml" /> <title>' . strings::formTitle($this->title) . '</title> <link>' . $this->link . '</link> <description>' . $this->description . '</description> <language>ru</language> <pubDate>' . $this->pubDate . '</pubDate> <image> <url>' . $this->siteLogo . '</url> <title>' . strings::formTitle($this->title) . '</title> <link>' . $this->link . '</link> </image>'; // если статьи есть if (!empty($arrArticles) && is_array($arrArticles)) { foreach ($arrArticles as $value) { $data .= '<item> <title>' . $value['title'] . '</title> <link>' . chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?do=articles&action=view&id=' . $value['tId']) . '</link> <pubDate>' . terms::RFCDate($value['datetime']) . '</pubDate> <guid>' . chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?do=articles&action=view&id=' . $value['tId']) . '</guid> <category domain="' . chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?do=articles&action=section&id=' . $sections[$value['id_section']]['tId']) . '">' . $sections[$value['id_section']]['name'] . '</category> <description><![CDATA[' . $value['small_text'] . ']]></description> </item>'; } } $data .= '</channel> </rss>'; return $data; }
} if ($section = $artsections->getSectionById($_GET['id'])) { $arrNamePage = array(array('name' => MENU_ARTICLES, 'link' => chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?ut=' . $_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type'] . '&do=articles')), array('name' => $section['name'], 'link' => false)); // Формируем TITLE страницы $arrTitle = array(); CONF_ARTICLES_TITLE_SECTION_SITE ? $arrTitle[] = array('name' => MENU_ARTICLES) : null; $arrTitle[] = array('name' => $section['name']); //смещение, всегда 0 (затем берется из $_GET) $offset = !empty($_GET['offset']) && validate::checkNaturalNumber($_GET['offset']) ? validate::checkNaturalNumber($_GET['offset']) : 0; //получаем массив, содержащий текущий обработанный URL $path = CONF_SCRIPT_URL . 'index.php?ut=' . $_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type'] . '&do=articles&action=section&id=' . $_GET['id'] . '&page=offset&'; $strWhere = "id_section=" . secure::escQuoteData($section['id']); $arrLimit = array('strLimit' => $offset . ',' . CONF_ARTICLES_PERPAGE, 'calcRows' => true); $arrFields = array('id', 'title', 'small_text', 'datetime', 'id_section', 'author', 'rating', 'votes'); // массив всех статей $arrArticles = $articles->getPuplishedArticles($strWhere, false, $arrLimit, $arrFields); $smarty->assign('articles', $arrArticles); // формируем страницы // получаем общее количество статей $allRecords = $articles->cntArticles(); // формируем странцы $strPages = strings::generatePage($allRecords, $offset, CONF_ARTICLES_PERPAGE, $path); //передаем в шаблон строку сформированных страниц $smarty->assignByRef('strPages', $strPages); // СЕО данные $smarty->assign('meta_keywords', MENU_ARTICLES . ', ' . $section['name']); $smarty->assign('meta_description', MENU_ARTICLES . ' - ' . $section['name']); $arrAction['section'] = true; } else { messages::error404(); }