Files
vij/rsscreate.php

165 lines
3.6 KiB
PHP
Raw Permalink Normal View History

2021-10-11 22:29:11 +03:00
<?php
2024-01-18 16:42:39 +03:00
include_once '/vhosts/vetandlife.ru/wp-load.php';
2021-10-11 22:29:11 +03:00
2024-01-18 16:42:39 +03:00
date_default_timezone_set('Europe/Moscow');
2021-10-11 22:29:11 +03:00
2021-12-28 21:37:04 +03:00
2024-01-18 16:42:39 +03:00
//Яндекс Новости
create_rss_yandex();
2021-12-28 21:37:04 +03:00
2024-01-18 16:42:39 +03:00
//Дзен
2024-05-31 10:40:33 +03:00
//create_rss_dzen();
2021-12-28 21:37:04 +03:00
2021-10-11 22:29:11 +03:00
2024-01-18 16:42:39 +03:00
exit;
2021-10-11 22:29:11 +03:00
2024-01-18 16:42:39 +03:00
function create_rss_yandex(){
2022-02-21 13:53:43 +03:00
2024-01-18 16:42:39 +03:00
$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 запроса
2024-06-27 19:31:24 +03:00
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_erid_token',
'value' => '',
'compare' => '='
),
array(
'key' => '_erid_token',
'compare' => 'NOT EXISTS'
)
)
2024-01-18 16:42:39 +03:00
));
2022-02-21 13:53:43 +03:00
2024-01-18 16:42:39 +03:00
// Яндекс Новости
create_rss_file($posts, 'views/rss/yanews.php', '/vhosts/vetandlife.ru/rss/yanews.xml');
// Общая лента
create_rss_file($posts, 'views/rss/rssnews.php', '/vhosts/vetandlife.ru/rss/news.xml');
2022-02-21 13:53:43 +03:00
2024-01-18 16:42:39 +03:00
//Турбо
create_rss_file($posts, 'views/rss/yaturbo.php', '/vhosts/vetandlife.ru/rss/turbo.xml');
2022-02-21 13:53:43 +03:00
2024-01-18 16:42:39 +03:00
return;
2022-02-21 13:53:43 +03:00
2024-01-18 16:42:39 +03:00
}
2021-10-11 22:29:11 +03:00
2022-02-15 21:00:14 +03:00
2024-01-18 16:42:39 +03:00
function create_rss_dzen(){
2022-02-15 21:00:14 +03:00
2024-01-18 16:42:39 +03:00
$subcategories = get_categories(array(
'child_of' => 14, // pets
));
2022-02-15 21:00:14 +03:00
2024-01-18 16:42:39 +03:00
$subcategories_ids = array($parent_category_id);
2022-02-15 21:00:14 +03:00
2024-01-18 16:42:39 +03:00
foreach ($subcategories as $subcategory) {
$subcategories_ids[] = $subcategory->term_id;
}
$args = array(
'category__in' => $subcategories_ids,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 30,
'orderby' => 'date',
'order' => 'DESC',
);
$posts = get_posts($args);
create_rss_file($posts, 'views/rss/dzen.php', '/vhosts/vetandlife.ru/rss/dzen.xml');
return;
2021-10-11 22:29:11 +03:00
}
2022-02-21 13:53:43 +03:00
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));
}
}
}
2024-01-18 16:42:39 +03:00
function getMimeTypeFromExtension($imageUrl) {
$extension = pathinfo($imageUrl, PATHINFO_EXTENSION);
switch (strtolower($extension)) {
case 'jpg':
case 'jpeg':
return 'image/jpeg';
case 'png':
return 'image/png';
case 'gif':
return 'image/gif';
case 'webp':
return 'image/webp';
default:
return false; // Неизвестное расширение
}
}
function filterHtml($html) {
$html = trim($html);
$html = preg_replace('/(\>)\s*(\<)/m', '$1$2', $html);
return preg_replace('/<!--(.*?)-->/', '', $html);
}
function filtercontent($html){
$content = str_replace('<br /><br />', '</p><p>', $content);
$content = str_replace('<br />', '</p><p>', $content);
$content = preg_replace('/<\/p>\s*<p>/', '</p><p>', $content);
$content = str_replace('<strong>', '<b>', $content);
$content = str_replace('</strong>', '</b>', $content);
$content = str_replace('<b></b>', '', $content);
$content = str_replace('<p></p>', '', $content);
$content = strip_tags($content, '<p><a><b><i><u><ul><ol><li><h1><h2><h3><h4><blockquote><iframe><img><figure>');
return $content;
}
2021-10-11 22:29:11 +03:00