summaryrefslogtreecommitdiffstats
path: root/wp-includes/blocks/rss
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--wp-includes/blocks/rss.php119
-rw-r--r--wp-includes/blocks/rss/block.json50
-rw-r--r--wp-includes/blocks/rss/editor-rtl.css16
-rw-r--r--wp-includes/blocks/rss/editor-rtl.min.css1
-rw-r--r--wp-includes/blocks/rss/editor.css16
-rw-r--r--wp-includes/blocks/rss/editor.min.css1
-rw-r--r--wp-includes/blocks/rss/style-rtl.css45
-rw-r--r--wp-includes/blocks/rss/style-rtl.min.css1
-rw-r--r--wp-includes/blocks/rss/style.css45
-rw-r--r--wp-includes/blocks/rss/style.min.css1
10 files changed, 295 insertions, 0 deletions
diff --git a/wp-includes/blocks/rss.php b/wp-includes/blocks/rss.php
new file mode 100644
index 0000000..91cdab3
--- /dev/null
+++ b/wp-includes/blocks/rss.php
@@ -0,0 +1,119 @@
+<?php
+/**
+ * Server-side rendering of the `core/rss` block.
+ *
+ * @package WordPress
+ */
+
+/**
+ * Renders the `core/rss` block on server.
+ *
+ * @param array $attributes The block attributes.
+ *
+ * @return string Returns the block content with received rss items.
+ */
+function render_block_core_rss( $attributes ) {
+ if ( in_array( untrailingslashit( $attributes['feedURL'] ), array( site_url(), home_url() ), true ) ) {
+ return '<div class="components-placeholder"><div class="notice notice-error">' . __( 'Adding an RSS feed to this site’s homepage is not supported, as it could lead to a loop that slows down your site. Try using another block, like the <strong>Latest Posts</strong> block, to list posts from the site.' ) . '</div></div>';
+ }
+
+ $rss = fetch_feed( $attributes['feedURL'] );
+
+ if ( is_wp_error( $rss ) ) {
+ return '<div class="components-placeholder"><div class="notice notice-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</div></div>';
+ }
+
+ if ( ! $rss->get_item_quantity() ) {
+ return '<div class="components-placeholder"><div class="notice notice-error">' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</div></div>';
+ }
+
+ $rss_items = $rss->get_items( 0, $attributes['itemsToShow'] );
+ $list_items = '';
+ foreach ( $rss_items as $item ) {
+ $title = esc_html( trim( strip_tags( $item->get_title() ) ) );
+ if ( empty( $title ) ) {
+ $title = __( '(no title)' );
+ }
+ $link = $item->get_link();
+ $link = esc_url( $link );
+ if ( $link ) {
+ $title = "<a href='{$link}'>{$title}</a>";
+ }
+ $title = "<div class='wp-block-rss__item-title'>{$title}</div>";
+
+ $date = '';
+ if ( $attributes['displayDate'] ) {
+ $date = $item->get_date( 'U' );
+
+ if ( $date ) {
+ $date = sprintf(
+ '<time datetime="%1$s" class="wp-block-rss__item-publish-date">%2$s</time> ',
+ esc_attr( date_i18n( 'c', $date ) ),
+ esc_attr( date_i18n( get_option( 'date_format' ), $date ) )
+ );
+ }
+ }
+
+ $author = '';
+ if ( $attributes['displayAuthor'] ) {
+ $author = $item->get_author();
+ if ( is_object( $author ) ) {
+ $author = $author->get_name();
+ $author = '<span class="wp-block-rss__item-author">' . sprintf(
+ /* translators: %s: the author. */
+ __( 'by %s' ),
+ esc_html( strip_tags( $author ) )
+ ) . '</span>';
+ }
+ }
+
+ $excerpt = '';
+ if ( $attributes['displayExcerpt'] ) {
+ $excerpt = html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );
+ $excerpt = esc_attr( wp_trim_words( $excerpt, $attributes['excerptLength'], ' [&hellip;]' ) );
+
+ // Change existing [...] to [&hellip;].
+ if ( '[...]' === substr( $excerpt, -5 ) ) {
+ $excerpt = substr( $excerpt, 0, -5 ) . '[&hellip;]';
+ }
+
+ $excerpt = '<div class="wp-block-rss__item-excerpt">' . esc_html( $excerpt ) . '</div>';
+ }
+
+ $list_items .= "<li class='wp-block-rss__item'>{$title}{$date}{$author}{$excerpt}</li>";
+ }
+
+ $classnames = array();
+ if ( isset( $attributes['blockLayout'] ) && 'grid' === $attributes['blockLayout'] ) {
+ $classnames[] = 'is-grid';
+ }
+ if ( isset( $attributes['columns'] ) && 'grid' === $attributes['blockLayout'] ) {
+ $classnames[] = 'columns-' . $attributes['columns'];
+ }
+ if ( $attributes['displayDate'] ) {
+ $classnames[] = 'has-dates';
+ }
+ if ( $attributes['displayAuthor'] ) {
+ $classnames[] = 'has-authors';
+ }
+ if ( $attributes['displayExcerpt'] ) {
+ $classnames[] = 'has-excerpts';
+ }
+
+ $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) );
+
+ return sprintf( '<ul %s>%s</ul>', $wrapper_attributes, $list_items );
+}
+
+/**
+ * Registers the `core/rss` block on server.
+ */
+function register_block_core_rss() {
+ register_block_type_from_metadata(
+ __DIR__ . '/rss',
+ array(
+ 'render_callback' => 'render_block_core_rss',
+ )
+ );
+}
+add_action( 'init', 'register_block_core_rss' );
diff --git a/wp-includes/blocks/rss/block.json b/wp-includes/blocks/rss/block.json
new file mode 100644
index 0000000..2535eda
--- /dev/null
+++ b/wp-includes/blocks/rss/block.json
@@ -0,0 +1,50 @@
+{
+ "$schema": "https://schemas.wp.org/trunk/block.json",
+ "apiVersion": 3,
+ "name": "core/rss",
+ "title": "RSS",
+ "category": "widgets",
+ "description": "Display entries from any RSS or Atom feed.",
+ "keywords": [ "atom", "feed" ],
+ "textdomain": "default",
+ "attributes": {
+ "columns": {
+ "type": "number",
+ "default": 2
+ },
+ "blockLayout": {
+ "type": "string",
+ "default": "list"
+ },
+ "feedURL": {
+ "type": "string",
+ "default": ""
+ },
+ "itemsToShow": {
+ "type": "number",
+ "default": 5
+ },
+ "displayExcerpt": {
+ "type": "boolean",
+ "default": false
+ },
+ "displayAuthor": {
+ "type": "boolean",
+ "default": false
+ },
+ "displayDate": {
+ "type": "boolean",
+ "default": false
+ },
+ "excerptLength": {
+ "type": "number",
+ "default": 55
+ }
+ },
+ "supports": {
+ "align": true,
+ "html": false
+ },
+ "editorStyle": "wp-block-rss-editor",
+ "style": "wp-block-rss"
+}
diff --git a/wp-includes/blocks/rss/editor-rtl.css b/wp-includes/blocks/rss/editor-rtl.css
new file mode 100644
index 0000000..43815b9
--- /dev/null
+++ b/wp-includes/blocks/rss/editor-rtl.css
@@ -0,0 +1,16 @@
+.wp-block-rss li a>div{
+ display:inline;
+}
+
+.wp-block-rss__placeholder-form>*{
+ margin-bottom:8px;
+}
+@media (min-width:782px){
+ .wp-block-rss__placeholder-form>*{
+ margin-bottom:0;
+ }
+}
+.wp-block-rss__placeholder-form .wp-block-rss__placeholder-input{
+ flex:1;
+ min-width:80%;
+} \ No newline at end of file
diff --git a/wp-includes/blocks/rss/editor-rtl.min.css b/wp-includes/blocks/rss/editor-rtl.min.css
new file mode 100644
index 0000000..25774d0
--- /dev/null
+++ b/wp-includes/blocks/rss/editor-rtl.min.css
@@ -0,0 +1 @@
+.wp-block-rss li a>div{display:inline}.wp-block-rss__placeholder-form>*{margin-bottom:8px}@media (min-width:782px){.wp-block-rss__placeholder-form>*{margin-bottom:0}}.wp-block-rss__placeholder-form .wp-block-rss__placeholder-input{flex:1;min-width:80%} \ No newline at end of file
diff --git a/wp-includes/blocks/rss/editor.css b/wp-includes/blocks/rss/editor.css
new file mode 100644
index 0000000..43815b9
--- /dev/null
+++ b/wp-includes/blocks/rss/editor.css
@@ -0,0 +1,16 @@
+.wp-block-rss li a>div{
+ display:inline;
+}
+
+.wp-block-rss__placeholder-form>*{
+ margin-bottom:8px;
+}
+@media (min-width:782px){
+ .wp-block-rss__placeholder-form>*{
+ margin-bottom:0;
+ }
+}
+.wp-block-rss__placeholder-form .wp-block-rss__placeholder-input{
+ flex:1;
+ min-width:80%;
+} \ No newline at end of file
diff --git a/wp-includes/blocks/rss/editor.min.css b/wp-includes/blocks/rss/editor.min.css
new file mode 100644
index 0000000..25774d0
--- /dev/null
+++ b/wp-includes/blocks/rss/editor.min.css
@@ -0,0 +1 @@
+.wp-block-rss li a>div{display:inline}.wp-block-rss__placeholder-form>*{margin-bottom:8px}@media (min-width:782px){.wp-block-rss__placeholder-form>*{margin-bottom:0}}.wp-block-rss__placeholder-form .wp-block-rss__placeholder-input{flex:1;min-width:80%} \ No newline at end of file
diff --git a/wp-includes/blocks/rss/style-rtl.css b/wp-includes/blocks/rss/style-rtl.css
new file mode 100644
index 0000000..2e5edd0
--- /dev/null
+++ b/wp-includes/blocks/rss/style-rtl.css
@@ -0,0 +1,45 @@
+ul.wp-block-rss{
+ list-style:none;
+ padding:0;
+}
+ul.wp-block-rss.wp-block-rss{
+ box-sizing:border-box;
+}
+ul.wp-block-rss.alignleft{
+ margin-right:2em;
+}
+ul.wp-block-rss.alignright{
+ margin-left:2em;
+}
+ul.wp-block-rss.is-grid{
+ display:flex;
+ flex-wrap:wrap;
+ list-style:none;
+ padding:0;
+}
+ul.wp-block-rss.is-grid li{
+ margin:0 0 1em 1em;
+ width:100%;
+}
+@media (min-width:600px){
+ ul.wp-block-rss.columns-2 li{
+ width:calc(50% - 1em);
+ }
+ ul.wp-block-rss.columns-3 li{
+ width:calc(33.33333% - 1em);
+ }
+ ul.wp-block-rss.columns-4 li{
+ width:calc(25% - 1em);
+ }
+ ul.wp-block-rss.columns-5 li{
+ width:calc(20% - 1em);
+ }
+ ul.wp-block-rss.columns-6 li{
+ width:calc(16.66667% - 1em);
+ }
+}
+
+.wp-block-rss__item-author,.wp-block-rss__item-publish-date{
+ display:block;
+ font-size:.8125em;
+} \ No newline at end of file
diff --git a/wp-includes/blocks/rss/style-rtl.min.css b/wp-includes/blocks/rss/style-rtl.min.css
new file mode 100644
index 0000000..6db26a0
--- /dev/null
+++ b/wp-includes/blocks/rss/style-rtl.min.css
@@ -0,0 +1 @@
+ul.wp-block-rss{list-style:none;padding:0}ul.wp-block-rss.wp-block-rss{box-sizing:border-box}ul.wp-block-rss.alignleft{margin-right:2em}ul.wp-block-rss.alignright{margin-left:2em}ul.wp-block-rss.is-grid{display:flex;flex-wrap:wrap;list-style:none;padding:0}ul.wp-block-rss.is-grid li{margin:0 0 1em 1em;width:100%}@media (min-width:600px){ul.wp-block-rss.columns-2 li{width:calc(50% - 1em)}ul.wp-block-rss.columns-3 li{width:calc(33.33333% - 1em)}ul.wp-block-rss.columns-4 li{width:calc(25% - 1em)}ul.wp-block-rss.columns-5 li{width:calc(20% - 1em)}ul.wp-block-rss.columns-6 li{width:calc(16.66667% - 1em)}}.wp-block-rss__item-author,.wp-block-rss__item-publish-date{display:block;font-size:.8125em} \ No newline at end of file
diff --git a/wp-includes/blocks/rss/style.css b/wp-includes/blocks/rss/style.css
new file mode 100644
index 0000000..e25bf93
--- /dev/null
+++ b/wp-includes/blocks/rss/style.css
@@ -0,0 +1,45 @@
+ul.wp-block-rss{
+ list-style:none;
+ padding:0;
+}
+ul.wp-block-rss.wp-block-rss{
+ box-sizing:border-box;
+}
+ul.wp-block-rss.alignleft{
+ margin-right:2em;
+}
+ul.wp-block-rss.alignright{
+ margin-left:2em;
+}
+ul.wp-block-rss.is-grid{
+ display:flex;
+ flex-wrap:wrap;
+ list-style:none;
+ padding:0;
+}
+ul.wp-block-rss.is-grid li{
+ margin:0 1em 1em 0;
+ width:100%;
+}
+@media (min-width:600px){
+ ul.wp-block-rss.columns-2 li{
+ width:calc(50% - 1em);
+ }
+ ul.wp-block-rss.columns-3 li{
+ width:calc(33.33333% - 1em);
+ }
+ ul.wp-block-rss.columns-4 li{
+ width:calc(25% - 1em);
+ }
+ ul.wp-block-rss.columns-5 li{
+ width:calc(20% - 1em);
+ }
+ ul.wp-block-rss.columns-6 li{
+ width:calc(16.66667% - 1em);
+ }
+}
+
+.wp-block-rss__item-author,.wp-block-rss__item-publish-date{
+ display:block;
+ font-size:.8125em;
+} \ No newline at end of file
diff --git a/wp-includes/blocks/rss/style.min.css b/wp-includes/blocks/rss/style.min.css
new file mode 100644
index 0000000..4ec346d
--- /dev/null
+++ b/wp-includes/blocks/rss/style.min.css
@@ -0,0 +1 @@
+ul.wp-block-rss{list-style:none;padding:0}ul.wp-block-rss.wp-block-rss{box-sizing:border-box}ul.wp-block-rss.alignleft{margin-right:2em}ul.wp-block-rss.alignright{margin-left:2em}ul.wp-block-rss.is-grid{display:flex;flex-wrap:wrap;list-style:none;padding:0}ul.wp-block-rss.is-grid li{margin:0 1em 1em 0;width:100%}@media (min-width:600px){ul.wp-block-rss.columns-2 li{width:calc(50% - 1em)}ul.wp-block-rss.columns-3 li{width:calc(33.33333% - 1em)}ul.wp-block-rss.columns-4 li{width:calc(25% - 1em)}ul.wp-block-rss.columns-5 li{width:calc(20% - 1em)}ul.wp-block-rss.columns-6 li{width:calc(16.66667% - 1em)}}.wp-block-rss__item-author,.wp-block-rss__item-publish-date{display:block;font-size:.8125em} \ No newline at end of file