From ccaa0663a2608b3b4c47c2df75154998896c4df6 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 7 Mar 2019 09:23:36 +0000 Subject: [PATCH] Block Editor: Include the missing blocks files These were missed from the previous commit. Refs #46429. git-svn-id: https://develop.svn.wordpress.org/trunk@44810 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks/calendar.php | 71 ++++++++++++++ src/wp-includes/blocks/rss.php | 137 +++++++++++++++++++++++++++ src/wp-includes/blocks/search.php | 82 ++++++++++++++++ src/wp-includes/blocks/tag-cloud.php | 71 ++++++++++++++ 4 files changed, 361 insertions(+) create mode 100644 src/wp-includes/blocks/calendar.php create mode 100644 src/wp-includes/blocks/rss.php create mode 100644 src/wp-includes/blocks/search.php create mode 100644 src/wp-includes/blocks/tag-cloud.php diff --git a/src/wp-includes/blocks/calendar.php b/src/wp-includes/blocks/calendar.php new file mode 100644 index 0000000000..9177997692 --- /dev/null +++ b/src/wp-includes/blocks/calendar.php @@ -0,0 +1,71 @@ +%2$s', + esc_attr( 'wp-block-calendar' . $custom_class_name . $align_class_name ), + get_calendar( true, false ) + ); + + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited + $monthnum = $previous_monthnum; + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited + $year = $previous_year; +} + +/** + * Registers the `core/calendar` block on server. + */ +function register_block_core_calendar() { + register_block_type( + 'core/calendar', + array( + 'attributes' => array( + 'align' => array( + 'type' => 'string', + ), + 'className' => array( + 'type' => 'string', + ), + 'month' => array( + 'type' => 'integer', + ), + 'year' => array( + 'type' => 'integer', + ), + ), + 'render_callback' => 'render_block_core_calendar', + ) + ); +} + +add_action( 'init', 'register_block_core_calendar' ); diff --git a/src/wp-includes/blocks/rss.php b/src/wp-includes/blocks/rss.php new file mode 100644 index 0000000000..b5fe3abaf5 --- /dev/null +++ b/src/wp-includes/blocks/rss.php @@ -0,0 +1,137 @@ +
' . __( 'RSS Error:' ) . ' ' . $rss->get_error_message() . '
'; + } + + if ( ! $rss->get_item_quantity() ) { + // PHP 5.2 compatibility. See: http://simplepie.org/wiki/faq/i_m_getting_memory_leaks. + $rss->__destruct(); + unset( $rss ); + + return '
' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '
'; + } + + $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 = __( '(Untitled)' ); + } + $link = $item->get_link(); + $link = esc_url( $link ); + if ( $link ) { + $title = "{$title}"; + } + $title = "
{$title}
"; + + $date = ''; + if ( $attributes['displayDate'] ) { + $date = $item->get_date( 'U' ); + + if ( $date ) { + $date = sprintf( + ' ', + date_i18n( get_option( 'c' ), $date ), + date_i18n( get_option( 'date_format' ), $date ) + ); + } + } + + $author = ''; + if ( $attributes['displayAuthor'] ) { + $author = $item->get_author(); + if ( is_object( $author ) ) { + $author = $author->get_name(); + $author = '' . __( 'by' ) . ' ' . esc_html( strip_tags( $author ) ) . ''; + } + } + + $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'], ' […]' ) ); + + // Change existing [...] to […]. + if ( '[...]' == substr( $excerpt, -5 ) ) { + $excerpt = substr( $excerpt, 0, -5 ) . '[…]'; + } + + $excerpt = '
' . esc_html( $excerpt ) . '
'; + } + + $list_items .= "
  • {$title}{$date}{$author}{$excerpt}
  • "; + } + + $classes = 'grid' === $attributes['blockLayout'] ? ' is-grid columns-' . $attributes['columns'] : ''; + $list_items_markup = ""; + + // PHP 5.2 compatibility. See: http://simplepie.org/wiki/faq/i_m_getting_memory_leaks. + $rss->__destruct(); + unset( $rss ); + + return $list_items_markup; +} + +/** + * Registers the `core/rss` block on server. + */ +function register_block_core_rss() { + register_block_type( 'core/rss', + array( + 'attributes' => array( + 'columns' => array( + 'type' => 'number', + 'default' => 2, + ), + 'blockLayout' => array( + 'type' => 'string', + 'default' => 'list', + ), + 'feedURL' => array( + 'type' => 'string', + 'default' => '', + ), + 'itemsToShow' => array( + 'type' => 'number', + 'default' => 5, + ), + 'displayExcerpt' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'displayAuthor' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'displayDate' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'excerptLength' => array( + 'type' => 'number', + 'default' => 55, + ), + ), + 'render_callback' => 'render_block_core_rss', + ) + ); +} + +add_action( 'init', 'register_block_core_rss' ); diff --git a/src/wp-includes/blocks/search.php b/src/wp-includes/blocks/search.php new file mode 100644 index 0000000000..ac7da463e9 --- /dev/null +++ b/src/wp-includes/blocks/search.php @@ -0,0 +1,82 @@ +%s', + $input_id, + $attributes['label'] + ); + } + + $input_markup = sprintf( + '', + $input_id, + esc_attr( get_search_query() ), + esc_attr( $attributes['placeholder'] ) + ); + + if ( ! empty( $attributes['buttonText'] ) ) { + $button_markup = sprintf( + '', + $attributes['buttonText'] + ); + } + + $class = 'wp-block-search'; + if ( isset( $attributes['className'] ) ) { + $class .= ' ' . $attributes['className']; + } + + return sprintf( + '', + $class, + esc_url( home_url( '/' ) ), + $label_markup . $input_markup . $button_markup + ); +} + +/** + * Registers the `core/search` block on the server. + */ +function register_block_core_search() { + register_block_type( + 'core/search', + array( + 'attributes' => array( + 'label' => array( + 'type' => 'string', + 'default' => __( 'Search' ), + ), + 'placeholder' => array( + 'type' => 'string', + 'default' => '', + ), + 'buttonText' => array( + 'type' => 'string', + 'default' => __( 'Search' ), + ), + ), + + 'render_callback' => 'render_block_core_search', + ) + ); +} + +add_action( 'init', 'register_block_core_search' ); diff --git a/src/wp-includes/blocks/tag-cloud.php b/src/wp-includes/blocks/tag-cloud.php new file mode 100644 index 0000000000..c60f8a1dd6 --- /dev/null +++ b/src/wp-includes/blocks/tag-cloud.php @@ -0,0 +1,71 @@ + false, + 'taxonomy' => $attributes['taxonomy'], + 'show_count' => $attributes['showTagCounts'], + ); + + $tag_cloud = wp_tag_cloud( $args ); + + if ( ! $tag_cloud ) { + $tag_cloud = esc_html( __( 'No terms to show.' ) ); + } + + return sprintf( + '

    %2$s

    ', + esc_attr( $class ), + $tag_cloud + ); +} + +/** + * Registers the `core/tag-cloud` block on server. + */ +function register_block_core_tag_cloud() { + register_block_type( + 'core/tag-cloud', + array( + 'attributes' => array( + 'taxonomy' => array( + 'type' => 'string', + 'default' => 'post_tag', + ), + 'className' => array( + 'type' => 'string', + ), + 'showTagCounts' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'align' => array( + 'type' => 'string', + ), + ), + 'render_callback' => 'render_block_core_tag_cloud', + ) + ); +} + +add_action( 'init', 'register_block_core_tag_cloud' );