Skip to content

Commit

Permalink
feat: release 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Kobzarev committed Apr 22, 2024
1 parent 8b12eba commit 5aeb4c0
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 271 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"wptrt/admin-notices": "^1.0",
"ext-dom": "*",
"ext-libxml": "*",
"imangazaliev/didom": "^2.0"
"imangazaliev/didom": "^2.0",
"symfony/serializer": "^5.4"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
Expand Down
9 changes: 5 additions & 4 deletions mihdan-mailru-pulse-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* Author: Mikhail Kobzarev
* Author URI: https://www.kobzarev.com/
* Requires at least: 5.3
* Tested up to: 6.4
* Version: 0.7.1
* Stable tag: 0.7.1
* Tested up to: 6.5
* Version: 0.8.0
* Stable tag: 0.8.0
*
* Text Domain: mihdan-mailru-pulse-feed
* Domain Path: /languages/
Expand All @@ -28,10 +28,11 @@
exit;
}

const MIHDAN_MAILRU_PULSE_FEED_VERSION = '0.7.1';
const MIHDAN_MAILRU_PULSE_FEED_VERSION = '0.8.0';
const MIHDAN_MAILRU_PULSE_FEED_PATH = __DIR__;
const MIHDAN_MAILRU_PULSE_FEED_FILE = __FILE__;
const MIHDAN_MAILRU_PULSE_FEED_SLUG = 'mihdan-mailru-pulse-feed';
const MIHDAN_MAILRU_PULSE_FEED_PREFIX = 'mihdan_mailru_pulse_feed';

define( 'MIHDAN_MAILRU_PULSE_FEED_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );

Expand Down
10 changes: 8 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: mihdan
Tags: zen, dzen, vk, mailru, pulse, feed, seo, seo-friendly
Requires at least: 5.3
Tested up to: 6.4
Stable tag: 0.7.1
Tested up to: 6.5
Stable tag: 0.8.0
Requires PHP: 7.4

Плагин формирует RSS-ленту (фид) для платформы Дзен (ранее Яндекс.Дзен и Пульс), которая создана для просмотра и создания контента.
Expand Down Expand Up @@ -120,6 +120,12 @@ add_filter(

== Changelog ==

= 0.8.0 (22.04.2024) =
* Включена возможность использования полнотекстового формата на постояной основе
* Отключен функционал виджета и его шорткода, так он больше не используется
* Исправлена ошибка с отключением таксономий
* Начат плавный переход от старой бибилиотеки `imangazaliev/didom` в пользу `imangazaliev/didom`

= 0.7.1 (18.11.2023) =
* Добавлена возможность изменять название ленты
* Добавлена поддержка WordPress 6.4+
Expand Down
188 changes: 188 additions & 0 deletions src/Feed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php
/**
* Шаблон вывода RSS ленты.
*
* @var Main $this
* @package mihdan-mailru-pulse-feed
*/

namespace Mihdan\MailRuPulseFeed;

use Symfony\Component\Serializer\Encoder\XmlEncoder;

/**
* Клас генерации ленты
*/
class Feed {
/**
* Данные ленты
*
* @var array
*/
private array $data = [];

/**
* Экземпляр класса XmlEncoder
*/
private XmlEncoder $encoder;

/**
* Экземпляр класса Options
*/
private Options $options;

/**
* Инициализация зависимостей.
*
* @param XmlEncoder $encoder Экземпляр класса XmlEncoder.
* @param Options $options Экземпляр класса Options.
*/
public function __construct( XmlEncoder $encoder, Options $options ) {
$this->encoder = $encoder;
$this->options = $options;

$this->populate();
}

/**
* Наполняет массив.
*
* @return array
*/
public function populate() {

$type = $this->options->get_option( 'type', 'feed' );

$this->data['@version'] = '2.0';
$this->data['@xmlns:content'] = 'http://purl.org/rss/1.0/modules/content/';
$this->data['@xmlns:dc'] = 'http://purl.org/dc/elements/1.1/';
$this->data['@xmlns:media'] = 'http://search.yahoo.com/mrss/';
$this->data['@xmlns:atom'] = 'http://www.w3.org/2005/Atom';
$this->data['@xmlns:georss'] = 'http://www.georss.org/georss';
$this->data['@xmlns:yandex'] = 'http://news.yandex.ru';

$channel = [
'title' => esc_html( $this->options->get_option( 'title', 'source' ) ),
'link' => esc_url( $this->options->get_option( 'link', 'source' ) ),
'description' => esc_html( $this->options->get_option( 'description', 'source' ) ),
'language' => esc_html( $this->options->get_option( 'language', 'source' ) ),
'generator' => 'Zen Feed by mihdan, v' . esc_html( MIHDAN_MAILRU_PULSE_FEED_VERSION ),
'webMaster' => '[email protected] (Mikhail Kobzarev)',
'docs' => 'https://ru.wordpress.org/plugins/mihdan-mailru-pulse-feed/',
'image' => [
'url' => esc_url( $this->options->get_option( 'image', 'source' ) ),
'title' => esc_html( $this->options->get_option( 'title', 'source' ) ),
'link' => esc_url( $this->options->get_option( 'link', 'source' ) ),
],
];

// Фильтрует шапку канала.
$this->data['channel'] = apply_filters( 'mihdan_mailru_pulse_feed_head', $channel );

if ( have_posts() ) {
while ( have_posts() ) {
the_post();

$item = [
'link' => apply_filters( 'the_permalink_rss', get_permalink() ),
'guid' => get_the_guid(),
'title' => $this->get_post_title( get_the_ID() ),
'author' => get_the_author(),
'pubDate' => get_post_time( 'r', true ),
'description' => $this->get_post_excerpt( get_the_ID() ),
];

/**
* Тип ленты.
*
* @link https://dzen.ru/help/ru/website/rss-modify.html
* @link https://dzen.ru/help/news/ru/export-content/export
*/
if ( $type === 'webmaster' || $type === '' ) {
$item['content:encoded'] = apply_filters( 'mihdan_mailru_pulse_feed_item_content', $this->get_the_content_feed( get_the_ID() ), get_the_ID() );
} else {
$item['yandex:fulltext'] = apply_filters( 'mihdan_mailru_pulse_feed_item_content', $this->get_the_content_feed( get_the_ID() ), get_the_ID() );
}

// Фильтрует конкретный item.
$this->data['item'][] = apply_filters(
'mihdan_mailru_pulse_feed_item',
$item,
get_the_ID()
);
}
}

return $this->data;
}

/**
* Отрисовывает XML.
*
* @return void
*/
public function render(): void {
header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . $this->options->get_option( 'charset', 'feed' ), true );

// phpcs:disable.
echo $this->encoder->encode(
$this->data,
XmlEncoder::FORMAT,
[
XmlEncoder::ROOT_NODE_NAME => 'rss',
XmlEncoder::ENCODING => 'UTF-8',
XmlEncoder::REMOVE_EMPTY_TAGS => true,
XmlEncoder::FORMAT_OUTPUT => true,
]
);
// phpcs:enable.
}

/**
* Get post title for rss item.
*
* @param int $post_id Post ID.
*
* @return string
*/
public function get_post_title( $post_id = null ) {
$title = get_the_title_rss();

if ( ! empty( get_post_meta( $post_id, MIHDAN_MAILRU_PULSE_FEED_PREFIX . '_title', true ) ) ) {
$title = get_post_meta( $post_id, MIHDAN_MAILRU_PULSE_FEED_PREFIX . '_title', true );
}

return apply_filters( 'mihdan_mailru_pulse_feed_item_title', $title, $post_id );
}

/**
* Get post excerpt for rss item.
*
* @param int $post_id Post ID.
*
* @return string
*/
public function get_post_excerpt( $post_id = null ) {
$excerpt = get_the_excerpt();

if ( ! empty( get_post_meta( $post_id, MIHDAN_MAILRU_PULSE_FEED_PREFIX . '_excerpt', true ) ) ) {
$excerpt = get_post_meta( $post_id, MIHDAN_MAILRU_PULSE_FEED_PREFIX . '_excerpt', true );
}

return apply_filters( 'mihdan_mailru_pulse_feed_item_excerpt', $excerpt, $post_id );
}

/**
* Get post content for rss item.
*
* @param int $post_id Post ID.
*
* @return mixed|string|string[]|void
*/
public function get_the_content_feed( $post_id = null ) {
$content = apply_filters( 'the_content', get_the_content( null, false, $post_id ) );
$content = str_replace( ']]>', ']]&gt;', $content );

return $content;
}
}
Loading

0 comments on commit 5aeb4c0

Please sign in to comment.