Files
vij/rsscreate.php
2022-02-21 14:14:36 +03:00

85 lines
1.5 KiB
PHP

<?php
include_once '/vhosts/beta/wp-load.php';
function filterHtml($html) {
$html = trim($html);
$html = preg_replace('/(\>)\s*(\<)/m', '$1$2', $html);
return preg_replace('/<!--(.*?)-->/', '', $html);
}
date_default_timezone_set('Europe/Moscow');
$posts = get_posts( array(
'numberposts' => 20,
'category' => 2,
'orderby' => 'date',
'order' => 'DESC',
'include' => array(),
'exclude' => array(),
'meta_key' => '',
'meta_value' =>'',
'post_type' => 'post',
'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
));
// Яндекс Новости
create_rss_file($posts, 'views/rss/yanews.php', '/vhosts/beta/rss/yanews.xml');
// Общая лента
create_rss_file($posts, 'views/rss/rssnews.php', '/vhosts/beta/rss/news.xml');
exit;
if( $posts ){
ob_start();
include('views/rss/yanews.php');
$result = ob_get_contents();
ob_end_clean();
$result = trim($result);
if ($result !== ''){
file_put_contents('/vhosts/beta/rss/yanews.xml', trim($result));
}
}
function create_rss_file($posts, $temp, $file){
if( $posts ){
ob_start();
include($temp);
$result = ob_get_contents();
ob_end_clean();
$result = trim($result);
if ($result !== ''){
file_put_contents($file, trim($result));
}
}
}