<?php defined( 'ABSPATH' ) or die;

/**
 * Custom thumbnail sizes
 */
function tech360_custom_thumbnail_size() {
	add_image_size( 'tiny-thumbnail', 96 );
	add_image_size( 'tiny-thumbnail-square', 96, 96, true );
	add_image_size( 'micro-thumbnail', 48 );
	add_image_size( 'micro-thumbnail-square', 48, 48, true );
}
add_action( 'after_setup_theme', 'tech360_custom_thumbnail_size' );

/**
 * Custom excerpt function
 */
function tech360_excerpt( $post_id, $length = 25, $display_link = false, $echo = true ) {

	$content = strip_tags( get_post( $post_id )->post_content );
	$output = [];

	$excerpt_array = explode( ' ', $content );
	if( count( $excerpt_array ) <= $length ) { // No need to trim
		$excerpt = implode( ' ', $excerpt_array );
	} else { // Trim needed
		$excerpt = implode( ' ', array_slice( $excerpt_array, 0, $length ) ) . '...';
	}

	$output[] = sprintf( '<p class="excerpt">%s</p>', $excerpt );

	if( $display_link ) {
		$link = '<p><a href="' . get_permalink( $post_id ) . '">Read more</a></p>';
		$output[] = $link;
	}

	if( $echo )
		echo implode( '', $output );
	else
		return implode( '', $output );

}

/**
 * Include required files
 */
require_once get_template_directory() . '/theme-code/constants.php';
require_once CODE_PATH . 'require/classes.php';
require_once CODE_PATH . 'require/custom_post_types.php';
require_once CODE_PATH . 'require/shortcodes.php';
