output_rss_feed($date); exit; } } /** * Получаем URL иконки сайта */ private function get_site_icon_url() { $site_icon_id = get_option('site_icon'); if ($site_icon_id) { return wp_get_attachment_image_url($site_icon_id, 'full'); } // Fallback на логотип или дефолтную иконку $custom_logo_id = get_theme_mod('custom_logo'); if ($custom_logo_id) { return wp_get_attachment_image_url($custom_logo_id, 'full'); } return home_url('/wp-admin/images/wordpress-logo.png'); } private function get_clean_post_content($post) { $content = apply_filters('the_content', $post->post_content); // Удаляем запрещенные для Турбо элементы $content = preg_replace('/]*>.*?<\/script>/is', '', $content); $content = preg_replace('/]*>.*?<\/style>/is', '', $content); $content = preg_replace('/]*>.*?<\/iframe>/is', '', $content); $content = preg_replace('/]*>.*?<\/form>/is', '', $content); $content = preg_replace('/]*>/is', '', $content); $content = preg_replace('/]*>.*?<\/button>/is', '', $content); $content = preg_replace('/]*>.*?<\/select>/is', '', $content); $content = preg_replace('/]*>.*?<\/textarea>/is', '', $content); $content = str_replace('

', '', $content); // Удаляем определенные классы $content = preg_replace('/]*class="[^"]*(ads|advert|banner|social|share|widget|comments)[^"]*"[^>]*>.*?<\/div>/is', '', $content); // Разрешаем только турбо-совместимые теги $allowed_tags = [ 'p' => ['class' => [], 'style' => []], 'br' => [], 'strong' => [], 'em' => [], 'b' => [], 'i' => [], 'ul' => [], 'ol' => [], 'li' => [], 'h1' => [], 'h2' => [], 'h3' => [], 'h4' => [], 'h5' => [], 'h6' => [], 'a' => ['href' => [], 'title' => []], 'img' => ['src' => [], 'alt' => [], 'title' => [], 'width' => [], 'height' => []], 'blockquote' => [], 'figure' => [], 'header' => [], ]; $content = wp_kses($content, $allowed_tags); return $content; } /** * Формируем XML ленту */ private function output_rss_feed($date) { global $wpdb; // Определяем диапазон дат: 7 дней до указанной даты $end_date = $date; // указанная дата $start_date = date('Y-m-d', strtotime($date . ' -6 days')); // 7 дней назад (включая указанную дату) //такая лента формируется на каждую дату и содержит все статьи за 7 дней до указанной даты $posts = $wpdb->get_results($wpdb->prepare(" SELECT * FROM {$wpdb->posts} WHERE post_type = 'profile_article' AND post_status = 'publish' AND DATE(post_date) BETWEEN %s AND %s AND post_password = '' AND ID NOT IN ( SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ('_no_aeroflot', '_is_advertisement', '_only_link_access', '_hide_on_website', '_hide_on_mainpage') AND meta_value = '1' ) ORDER BY post_date DESC ", $start_date, $end_date)); // Конвертируем в объекты WP_Post $posts = array_map(function($post) { return new WP_Post($post); }, $posts); // Устанавливаем заголовки header('Content-Type: application/rss+xml; charset=' . get_option('blog_charset'), true); // Начинаем вывод XML echo ''; ?> <?php echo esc_xml(get_bloginfo('name')); ?> https://profile.ru Информационное агенство Деловой журнал Профиль get_site_icon_url()); ?> <?php echo esc_xml(get_bloginfo('name')); ?> No posts for period <?php echo esc_xml($start_date); ?> to <?php echo esc_xml($end_date); ?> No posts found for this period no-posts- ID); $post_date = gmdate(DATE_RSS, strtotime($post->post_date_gmt)); $excerpt = get_the_excerpt($post->ID); $content = $this->get_clean_post_content($post); $thumbnail = get_the_post_thumbnail_url($post->ID, 'large'); // Получаем авторов из плагина Co-Authors $authors = get_coauthors($post->ID); ?> <?php echo esc_xml(get_the_title($post->ID)); ?> display_name; } ?> post_author); ?> <?php echo esc_xml(get_the_title($post->ID)); ?> <?php echo esc_xml(get_the_title($post->ID)); ?> ID); foreach ($categories as $category) { echo '' . esc_xml($category->name) . ''; } ?> ]]> post_content); $content = str_replace(']]>', ']]>', $content); return $content; } /** * Активация - сбрасываем rewrite rules */ public static function activate() { flush_rewrite_rules(); } /** * Деактивация - чистим rewrite rules */ public static function deactivate() { flush_rewrite_rules(); } } // Инициализация new CustomProfileArticleRSS(); // Хуки активации/деактивации register_activation_hook(__FILE__, ['CustomProfileArticleRSS', 'activate']); register_deactivation_hook(__FILE__, ['CustomProfileArticleRSS', 'deactivate']);