From 7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 7 Jan 2020 13:06:14 +0100 Subject: Added wordpress --- srcs/wordpress/wp-includes/blocks/archives.php | 143 +++++++++++++++ srcs/wordpress/wp-includes/blocks/block.php | 48 +++++ srcs/wordpress/wp-includes/blocks/calendar.php | 78 ++++++++ srcs/wordpress/wp-includes/blocks/categories.php | 120 +++++++++++++ .../wp-includes/blocks/latest-comments.php | 196 +++++++++++++++++++++ srcs/wordpress/wp-includes/blocks/latest-posts.php | 177 +++++++++++++++++++ srcs/wordpress/wp-includes/blocks/rss.php | 160 +++++++++++++++++ srcs/wordpress/wp-includes/blocks/search.php | 93 ++++++++++ srcs/wordpress/wp-includes/blocks/shortcode.php | 37 ++++ srcs/wordpress/wp-includes/blocks/tag-cloud.php | 78 ++++++++ 10 files changed, 1130 insertions(+) create mode 100644 srcs/wordpress/wp-includes/blocks/archives.php create mode 100644 srcs/wordpress/wp-includes/blocks/block.php create mode 100644 srcs/wordpress/wp-includes/blocks/calendar.php create mode 100644 srcs/wordpress/wp-includes/blocks/categories.php create mode 100644 srcs/wordpress/wp-includes/blocks/latest-comments.php create mode 100644 srcs/wordpress/wp-includes/blocks/latest-posts.php create mode 100644 srcs/wordpress/wp-includes/blocks/rss.php create mode 100644 srcs/wordpress/wp-includes/blocks/search.php create mode 100644 srcs/wordpress/wp-includes/blocks/shortcode.php create mode 100644 srcs/wordpress/wp-includes/blocks/tag-cloud.php (limited to 'srcs/wordpress/wp-includes/blocks') diff --git a/srcs/wordpress/wp-includes/blocks/archives.php b/srcs/wordpress/wp-includes/blocks/archives.php new file mode 100644 index 0000000..172b1c7 --- /dev/null +++ b/srcs/wordpress/wp-includes/blocks/archives.php @@ -0,0 +1,143 @@ + 'monthly', + 'format' => 'option', + 'show_post_count' => $show_post_count, + ) + ); + + $dropdown_args['echo'] = 0; + + $archives = wp_get_archives( $dropdown_args ); + + switch ( $dropdown_args['type'] ) { + case 'yearly': + $label = __( 'Select Year' ); + break; + case 'monthly': + $label = __( 'Select Month' ); + break; + case 'daily': + $label = __( 'Select Day' ); + break; + case 'weekly': + $label = __( 'Select Week' ); + break; + default: + $label = __( 'Select Post' ); + break; + } + + $label = esc_attr( $label ); + + $block_content = ' + '; + + return sprintf( + '
%2$s
', + esc_attr( $class ), + $block_content + ); + } + + $class .= ' wp-block-archives-list'; + + /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ + $archives_args = apply_filters( + 'widget_archives_args', + array( + 'type' => 'monthly', + 'show_post_count' => $show_post_count, + ) + ); + + $archives_args['echo'] = 0; + + $archives = wp_get_archives( $archives_args ); + + $classnames = esc_attr( $class ); + + if ( empty( $archives ) ) { + + return sprintf( + '
%2$s
', + $classnames, + __( 'No archives to show.' ) + ); + } + + return sprintf( + '', + $classnames, + $archives + ); +} + +/** + * Register archives block. + */ +function register_block_core_archives() { + register_block_type( + 'core/archives', + array( + 'attributes' => array( + 'align' => array( + 'type' => 'string', + 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ), + ), + 'className' => array( + 'type' => 'string', + ), + 'displayAsDropdown' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'showPostCounts' => array( + 'type' => 'boolean', + 'default' => false, + ), + ), + 'render_callback' => 'render_block_core_archives', + ) + ); +} +add_action( 'init', 'register_block_core_archives' ); diff --git a/srcs/wordpress/wp-includes/blocks/block.php b/srcs/wordpress/wp-includes/blocks/block.php new file mode 100644 index 0000000..24d2ab5 --- /dev/null +++ b/srcs/wordpress/wp-includes/blocks/block.php @@ -0,0 +1,48 @@ +post_type ) { + return ''; + } + + if ( 'publish' !== $reusable_block->post_status || ! empty( $reusable_block->post_password ) ) { + return ''; + } + + return do_blocks( $reusable_block->post_content ); +} + +/** + * Registers the `core/block` block. + */ +function register_block_core_block() { + register_block_type( + 'core/block', + array( + 'attributes' => array( + 'ref' => array( + 'type' => 'number', + ), + ), + 'render_callback' => 'render_block_core_block', + ) + ); +} +add_action( 'init', 'register_block_core_block' ); diff --git a/srcs/wordpress/wp-includes/blocks/calendar.php b/srcs/wordpress/wp-includes/blocks/calendar.php new file mode 100644 index 0000000..3d2e806 --- /dev/null +++ b/srcs/wordpress/wp-includes/blocks/calendar.php @@ -0,0 +1,78 @@ +%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; + + return $output; +} + +/** + * Registers the `core/calendar` block on server. + */ +function register_block_core_calendar() { + register_block_type( + 'core/calendar', + array( + 'attributes' => array( + 'align' => array( + 'type' => 'string', + 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ), + ), + '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/srcs/wordpress/wp-includes/blocks/categories.php b/srcs/wordpress/wp-includes/blocks/categories.php new file mode 100644 index 0000000..159bb8b --- /dev/null +++ b/srcs/wordpress/wp-includes/blocks/categories.php @@ -0,0 +1,120 @@ + false, + 'hierarchical' => ! empty( $attributes['showHierarchy'] ), + 'orderby' => 'name', + 'show_count' => ! empty( $attributes['showPostCounts'] ), + 'title_li' => '', + ); + + if ( ! empty( $attributes['displayAsDropdown'] ) ) { + $id = 'wp-block-categories-' . $block_id; + $args['id'] = $id; + $args['show_option_none'] = __( 'Select Category' ); + $wrapper_markup = '
%2$s
'; + $items_markup = wp_dropdown_categories( $args ); + $type = 'dropdown'; + + if ( ! is_admin() ) { + $wrapper_markup .= build_dropdown_script_block_core_categories( $id ); + } + } else { + $wrapper_markup = ''; + $items_markup = wp_list_categories( $args ); + $type = 'list'; + } + + $class = "wp-block-categories wp-block-categories-{$type}"; + + if ( isset( $attributes['align'] ) ) { + $class .= " align{$attributes['align']}"; + } + + if ( isset( $attributes['className'] ) ) { + $class .= " {$attributes['className']}"; + } + + return sprintf( + $wrapper_markup, + esc_attr( $class ), + $items_markup + ); +} + +/** + * Generates the inline script for a categories dropdown field. + * + * @param string $dropdown_id ID of the dropdown field. + * + * @return string Returns the dropdown onChange redirection script. + */ +function build_dropdown_script_block_core_categories( $dropdown_id ) { + ob_start(); + ?> + + array( + 'align' => array( + 'type' => 'string', + 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ), + ), + 'className' => array( + 'type' => 'string', + ), + 'displayAsDropdown' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'showHierarchy' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'showPostCounts' => array( + 'type' => 'boolean', + 'default' => false, + ), + ), + 'render_callback' => 'render_block_core_categories', + ) + ); +} +add_action( 'init', 'register_block_core_categories' ); diff --git a/srcs/wordpress/wp-includes/blocks/latest-comments.php b/srcs/wordpress/wp-includes/blocks/latest-comments.php new file mode 100644 index 0000000..d68e89a --- /dev/null +++ b/srcs/wordpress/wp-includes/blocks/latest-comments.php @@ -0,0 +1,196 @@ + $attributes['commentsToShow'], + 'status' => 'approve', + 'post_status' => 'publish', + ) + ) + ); + + $list_items_markup = ''; + if ( ! empty( $comments ) ) { + // Prime the cache for associated posts. This is copied from \WP_Widget_Recent_Comments::widget(). + $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) ); + _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false ); + + foreach ( $comments as $comment ) { + $list_items_markup .= '
  • '; + if ( $attributes['displayAvatar'] ) { + $avatar = get_avatar( + $comment, + 48, + '', + '', + array( + 'class' => 'wp-block-latest-comments__comment-avatar', + ) + ); + if ( $avatar ) { + $list_items_markup .= $avatar; + } + } + + $list_items_markup .= '
    '; + $list_items_markup .= ''; + if ( $attributes['displayExcerpt'] ) { + $list_items_markup .= '
    ' . wpautop( get_comment_excerpt( $comment ) ) . '
    '; + } + $list_items_markup .= '
  • '; + } + } + + $class = 'wp-block-latest-comments'; + if ( ! empty( $attributes['className'] ) ) { + $class .= ' ' . $attributes['className']; + } + if ( isset( $attributes['align'] ) ) { + $class .= " align{$attributes['align']}"; + } + if ( $attributes['displayAvatar'] ) { + $class .= ' has-avatars'; + } + if ( $attributes['displayDate'] ) { + $class .= ' has-dates'; + } + if ( $attributes['displayExcerpt'] ) { + $class .= ' has-excerpts'; + } + if ( empty( $comments ) ) { + $class .= ' no-comments'; + } + $classnames = esc_attr( $class ); + + return ! empty( $comments ) ? sprintf( + '
      %2$s
    ', + $classnames, + $list_items_markup + ) : sprintf( + '
    %2$s
    ', + $classnames, + __( 'No comments to show.' ) + ); +} + +/** + * Registers the `core/latest-comments` block. + */ +function register_block_core_latest_comments() { + register_block_type( + 'core/latest-comments', + array( + 'attributes' => array( + 'align' => array( + 'type' => 'string', + 'enum' => array( + 'left', + 'center', + 'right', + 'wide', + 'full', + ), + ), + 'className' => array( + 'type' => 'string', + ), + 'commentsToShow' => array( + 'type' => 'number', + 'default' => 5, + 'minimum' => 1, + 'maximum' => 100, + ), + 'displayAvatar' => array( + 'type' => 'boolean', + 'default' => true, + ), + 'displayDate' => array( + 'type' => 'boolean', + 'default' => true, + ), + 'displayExcerpt' => array( + 'type' => 'boolean', + 'default' => true, + ), + ), + 'render_callback' => 'render_block_core_latest_comments', + ) + ); +} + +add_action( 'init', 'register_block_core_latest_comments' ); diff --git a/srcs/wordpress/wp-includes/blocks/latest-posts.php b/srcs/wordpress/wp-includes/blocks/latest-posts.php new file mode 100644 index 0000000..b8fc02c --- /dev/null +++ b/srcs/wordpress/wp-includes/blocks/latest-posts.php @@ -0,0 +1,177 @@ + $attributes['postsToShow'], + 'post_status' => 'publish', + 'order' => $attributes['order'], + 'orderby' => $attributes['orderBy'], + 'suppress_filters' => false, + ); + + if ( isset( $attributes['categories'] ) ) { + $args['category'] = $attributes['categories']; + } + + $recent_posts = get_posts( $args ); + + $list_items_markup = ''; + + $excerpt_length = $attributes['excerptLength']; + + foreach ( $recent_posts as $post ) { + $title = get_the_title( $post ); + if ( ! $title ) { + $title = __( '(no title)' ); + } + $list_items_markup .= sprintf( + '
  • %2$s', + esc_url( get_permalink( $post ) ), + $title + ); + + if ( isset( $attributes['displayPostDate'] ) && $attributes['displayPostDate'] ) { + $list_items_markup .= sprintf( + '', + esc_attr( get_the_date( 'c', $post ) ), + esc_html( get_the_date( '', $post ) ) + ); + } + + if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent'] + && isset( $attributes['displayPostContentRadio'] ) && 'excerpt' === $attributes['displayPostContentRadio'] ) { + $post_excerpt = $post->post_excerpt; + if ( ! ( $post_excerpt ) ) { + $post_excerpt = $post->post_content; + } + $trimmed_excerpt = esc_html( wp_trim_words( $post_excerpt, $excerpt_length, ' … ' ) ); + + $list_items_markup .= sprintf( + '
    %1$s', + $trimmed_excerpt + ); + + if ( strpos( $trimmed_excerpt, ' … ' ) !== false ) { + $list_items_markup .= sprintf( + '%2$s
    ', + esc_url( get_permalink( $post ) ), + __( 'Read more' ) + ); + } else { + $list_items_markup .= sprintf( + '' + ); + } + } + + if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent'] + && isset( $attributes['displayPostContentRadio'] ) && 'full_post' === $attributes['displayPostContentRadio'] ) { + $list_items_markup .= sprintf( + '
    %1$s
    ', + wp_kses_post( html_entity_decode( $post->post_content, ENT_QUOTES, get_option( 'blog_charset' ) ) ) + ); + } + + $list_items_markup .= "
  • \n"; + } + + $class = 'wp-block-latest-posts wp-block-latest-posts__list'; + if ( isset( $attributes['align'] ) ) { + $class .= ' align' . $attributes['align']; + } + + if ( isset( $attributes['postLayout'] ) && 'grid' === $attributes['postLayout'] ) { + $class .= ' is-grid'; + } + + if ( isset( $attributes['columns'] ) && 'grid' === $attributes['postLayout'] ) { + $class .= ' columns-' . $attributes['columns']; + } + + if ( isset( $attributes['displayPostDate'] ) && $attributes['displayPostDate'] ) { + $class .= ' has-dates'; + } + + if ( isset( $attributes['className'] ) ) { + $class .= ' ' . $attributes['className']; + } + + return sprintf( + '', + esc_attr( $class ), + $list_items_markup + ); +} + +/** + * Registers the `core/latest-posts` block on server. + */ +function register_block_core_latest_posts() { + register_block_type( + 'core/latest-posts', + array( + 'attributes' => array( + 'align' => array( + 'type' => 'string', + 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ), + ), + 'className' => array( + 'type' => 'string', + ), + 'categories' => array( + 'type' => 'string', + ), + 'postsToShow' => array( + 'type' => 'number', + 'default' => 5, + ), + 'displayPostContent' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'displayPostContentRadio' => array( + 'type' => 'string', + 'default' => 'excerpt', + ), + 'excerptLength' => array( + 'type' => 'number', + 'default' => 55, + ), + 'displayPostDate' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'postLayout' => array( + 'type' => 'string', + 'default' => 'list', + ), + 'columns' => array( + 'type' => 'number', + 'default' => 3, + ), + 'order' => array( + 'type' => 'string', + 'default' => 'desc', + ), + 'orderBy' => array( + 'type' => 'string', + 'default' => 'date', + ), + ), + 'render_callback' => 'render_block_core_latest_posts', + ) + ); +} +add_action( 'init', 'register_block_core_latest_posts' ); diff --git a/srcs/wordpress/wp-includes/blocks/rss.php b/srcs/wordpress/wp-includes/blocks/rss.php new file mode 100644 index 0000000..0300585 --- /dev/null +++ b/srcs/wordpress/wp-includes/blocks/rss.php @@ -0,0 +1,160 @@ +
    ' . __( '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 = __( '(no title)' ); + } + $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}
  • "; + } + + $class = 'wp-block-rss'; + if ( isset( $attributes['align'] ) ) { + $class .= ' align' . $attributes['align']; + } + + if ( isset( $attributes['blockLayout'] ) && 'grid' === $attributes['blockLayout'] ) { + $class .= ' is-grid'; + } + + if ( isset( $attributes['columns'] ) && 'grid' === $attributes['blockLayout'] ) { + $class .= ' columns-' . $attributes['columns']; + } + + if ( isset( $attributes['className'] ) ) { + $class .= ' ' . $attributes['className']; + } + + $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( + 'align' => array( + 'type' => 'string', + 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ), + ), + 'className' => array( + 'type' => 'string', + ), + '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/srcs/wordpress/wp-includes/blocks/search.php b/srcs/wordpress/wp-includes/blocks/search.php new file mode 100644 index 0000000..6cd909f --- /dev/null +++ b/srcs/wordpress/wp-includes/blocks/search.php @@ -0,0 +1,93 @@ +%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']; + } + + if ( isset( $attributes['align'] ) ) { + $class .= ' align' . $attributes['align']; + } + + 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( + 'align' => array( + 'type' => 'string', + 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ), + ), + 'className' => array( + 'type' => 'string', + ), + '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/srcs/wordpress/wp-includes/blocks/shortcode.php b/srcs/wordpress/wp-includes/blocks/shortcode.php new file mode 100644 index 0000000..79df091 --- /dev/null +++ b/srcs/wordpress/wp-includes/blocks/shortcode.php @@ -0,0 +1,37 @@ + array( + 'text' => array( + 'type' => 'string', + 'source' => 'html', + ), + ), + 'render_callback' => 'render_block_core_shortcode', + ) + ); +} +add_action( 'init', 'register_block_core_shortcode' ); diff --git a/srcs/wordpress/wp-includes/blocks/tag-cloud.php b/srcs/wordpress/wp-includes/blocks/tag-cloud.php new file mode 100644 index 0000000..cf9c4d2 --- /dev/null +++ b/srcs/wordpress/wp-includes/blocks/tag-cloud.php @@ -0,0 +1,78 @@ + false, + 'taxonomy' => $attributes['taxonomy'], + 'show_count' => $attributes['showTagCounts'], + ); + + $tag_cloud = wp_tag_cloud( $args ); + + if ( ! $tag_cloud ) { + $labels = get_taxonomy_labels( get_taxonomy( $attributes['taxonomy'] ) ); + $tag_cloud = esc_html( + sprintf( + /* translators: %s: taxonomy name */ + __( 'Your site doesn’t have any %s, so there’s nothing to display here at the moment.' ), + strtolower( $labels->name ) + ) + ); + } + + 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( + 'align' => array( + 'type' => 'string', + 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ), + ), + 'className' => array( + 'type' => 'string', + ), + 'taxonomy' => array( + 'type' => 'string', + 'default' => 'post_tag', + ), + 'showTagCounts' => array( + 'type' => 'boolean', + 'default' => false, + ), + ), + 'render_callback' => 'render_block_core_tag_cloud', + ) + ); +} +add_action( 'init', 'register_block_core_tag_cloud' ); -- cgit