<?php

/****************************************
// ######### WordPress Menus ######### //
****************************************/

function boot23_list_child_pages() {
  global $post;
  $children = get_pages( array( 'child_of' => $post->ID ) );
  $haschild = (count( $children ) > 0 );
  $page_id = ($haschild) ? $post->ID : wp_get_post_parent_id( $post->ID );
  wp_list_pages( array(
    'title_li'    => '',
    'depth'       => 0,
    'sort_order'  => 'asc',
    'sort_column' => 'menu_order',
    'child_of'    => $page_id,
  ));
}
add_shortcode('boot23_childpages', 'boot23_list_child_pages');

function boot23_list_pages_filter($output) {
  $output = str_replace('page_item', 'nav-item list-group-item py-1 p-0', $output);
  return $output;
}
add_filter('wp_list_pages', 'boot23_list_pages_filter');


/****************************************
// ######### WordPress Posts ######### //
****************************************/

function boot23_posted_on() {
	$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
        $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
	}
	$time_string = sprintf( $time_string,
		esc_attr( get_the_date( 'c' ) ),
		esc_html( get_the_date() )
	);
	$posted_on = sprintf(
		esc_html_x( 'Posted on %s', 'post date' ),
		'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
	);
	$byline = sprintf(
		esc_html_x( 'by %s', 'post author' ),
		'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
	);
	echo '<span class="posted-on">' . $posted_on . '</span> | <span class="byline"> ' . $byline . '</span>'; //
    if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
        echo ' | <span class="comments-link"><i class="fa fa-comments" aria-hidden="true"></i> ';
        comments_popup_link( sprintf( wp_kses( __( 'Leave a Comment<span class="screen-reader-text"> on %s</span>' ), array( 'span' => array( 'class' => array() ) ) ), get_the_title() ) );
        echo '</span>';
    }
}

function boot23_entry_footer() {
	if ( 'post' === get_post_type() ) {
		$categories_list = get_the_category_list( esc_html__( ', ' ) );
		if ( $categories_list ) {
			printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s') . '</span>', $categories_list );
		}
		$tags_list = get_the_tag_list( '', esc_html__( ', ') );
		if ( $tags_list ) {
			printf( ' | <span class="tags-links">' . esc_html__( 'Tagged %1$s' ) . '</span>', $tags_list );
		}
	}
	edit_post_link(
		sprintf(
			esc_html__( 'Edit %s' ),
			the_title( '<span class="screen-reader-text">"', '"</span>', false )
		),
		' | <span class="edit-link">',
		'</span>'
	);
}