Path : /home/vishqocm/vishalwebtech.in/blog/wp-content/themes/katerio/functions/
File Upload :
Current File : /home/vishqocm/vishalwebtech.in///blog/wp-content/themes/katerio/functions/post-info.php

<?php
/**
 * Get post meta info functions
 *
 * @package Katerio
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

if ( ! function_exists( 'th90_get_post_info' ) ) {

	function th90_get_post_info( $args = '', $before = false, $after = false ) {

		// For Posts only ----------
		if ( get_post_type() != 'post' ) {
			return;
		}

		// Defaults ----------
		$args = wp_parse_args( $args, array(
			'first_cat'       => false,
			'cats'            => false,
			'cats_style'      => 'text',
			'author'          => false,
			'date'            => false,
			'views'           => false,
			'comments'        => false,
			'reading_time'    => false,
			'prefix_text'     => true,
			'addclass'        => '',
			'avatar'          => false,
			'avatar_size'     => 25,
			'edit'            => false,
			'time_format'     => false,
			'first_cat_style' => 'text',
			'sticky'          => false,
			'style'           => 'info-div-' . th90_opt( 'post_info_div' ),
		));

		extract( $args );

		if ( th90_is_amp() ) {
			$avatar = false;
		}

		$post_meta = $before . '<div class="entry-meta ' . $style . ( $addclass ? ' ' . $addclass : '' ) . '">';

		// First Category or Categories ----------
		if ( ! empty( $first_cat ) ) {
			$post_meta .= '<div class="meta-firstcat">';
			$post_meta .= false !== strpos( $first_cat_style, 'text' ) && ( 'info-div-icon' == $style || 'info-div-icon_color' == $style ) ? '<span class="info-icon">' . th90_get_svg_icon( 'cats' ) . '</span>' : '';
			$post_meta .= th90_get_category( $first_cat_style, th90_opt( 'post_first_cat_only' ) );
			$post_meta .= '</div>';
		}

		// Cats  ----------
		if ( ! empty( $cats ) ) {
			$post_meta .= '<div class="meta-cats">';
			$post_meta .= th90_get_category( $cats_style );
			$post_meta .= '</div>';
		}

		// Author ----------
		if ( ! empty( $author ) ) {
			if ( TH90_COAUTHORS_IS_ACTIVE ) {
				$post_meta .= '<div class="meta-author meta-color">';

				if ( $avatar && 'no' !== $avatar ) {
					$author_ids = explode( ',', coauthors_ids( ',', ',', null, null, false ) );
					$post_meta .= '<div class="avatar-list">';
					foreach ( $author_ids as $author_id) {
						$post_meta .= '<div class="avatar-item">';
						$post_meta .= get_avatar( $author_id, $avatar_size );
						$post_meta .= '</div>';
					}
					$post_meta .= '</div>';
				}

				$post_meta .= coauthors_posts_links( ',&nbsp;', '&nbsp;&amp;&nbsp;', esc_html__( 'By', 'katerio' ) . '&nbsp;', null, false );

				$post_meta .= '</div>';
			} else {
				$post_meta .= '<div class="meta-author author vcard meta-color">';
				if ( $avatar && 'no' !== $avatar ) {
					$post_meta .= get_avatar( get_the_author_meta( 'ID' ), $avatar_size );
				}
				$post_meta .= $prefix_text ? '<span class="meta-before">' . esc_html__( 'By', 'katerio' ) . '&nbsp;' . '</span>' : '';
				$post_meta .= '<a href="' . get_author_posts_url( get_the_author_meta( 'ID' ) ) . '" class="author-name url fn" rel="author" title="' . esc_attr( sprintf( __( 'Posts by %s', 'katerio' ), get_the_author() ) ) . '">'  . get_the_author() . '</a>';
				$post_meta .= '</div>';
			}

		}

		// Date  ----------
		if ( ! empty( $date ) ) {
			$post_meta .= '<div class="meta-date">';
			$post_meta .= '<a class="meta-color" href="' . get_permalink() . '">';
			$post_meta .= 'info-div-icon' == $style || 'info-div-icon_color' == $style ? '<span class="info-icon">' . th90_get_svg_icon( 'date' ) . '</span>' : '';
			$post_meta .= '<span>' . th90_get_time( $time_format ) . '</span>';
			$post_meta .= '</a>';
			$post_meta .= '</div>';
		}

		// Reading Time ----------
		if ( ! empty( $reading_time ) ) {
			$post_meta .= '<div class="meta-readtime meta-color">';
			$post_meta .= '<span>' . th90_reading_time() . '</span>';
			$post_meta .= '</div>';
		}

		// Number of views ----------
		if ( ! empty( $views ) && TH90_POSTVIEWS_IS_ACTIVE ) {
			$count  = pvc_get_post_views( get_the_ID() );
			$post_meta .= '<div class="meta-color meta-views">';
			$post_meta .= '<a class="meta-color" href="' . get_permalink() . '">';
			$post_meta .=  'info-div-icon' == $style || 'info-div-icon_color' == $style ? '<span class="info-icon">' . th90_get_svg_icon( 'view' ) . '</span>' : '';
			$post_meta .= '<span>' . th90_number_format_short( $count ) . ' ' . esc_html__( 'Views', 'katerio' ) . '</span>';
			$post_meta .= '</a>';
			$post_meta .= '</div>';
		}

		// Comments ----------
		if ( ! empty( $comments ) && th90_opt( 'post_comment' ) && ( comments_open() || get_comments_number() ) ) {

			$post_meta .= '<div class="meta-comments">';
			$post_meta .= '<a href="' . get_comments_link() . '" class="meta-color">';
			$comments_number = get_comments_number();
			if ( 'info-div-icon' == $style || 'info-div-icon_color' == $style ) {
				$post_meta .= 'info-div-icon' == $style || 'info-div-icon_color' == $style ? '<span class="info-icon">' . th90_get_svg_icon( 'comment' ) . '</span>' : '';
				$post_meta .= '<span>' . number_format_i18n( $comments_number ) . '</span>';
			} else {
				if ( $comments_number > 1 ) {
					$post_meta .= '<span>' . str_replace( '%', number_format_i18n( $comments_number ), esc_html__( '% Comments', 'katerio' ) ) . '</span>';
				} elseif ( $comments_number == 0 ) {
					$post_meta .= '<span>' . esc_html__( '0 Comments', 'katerio' ) . '</span>';
				} else {
					$post_meta .= '<span>' . esc_html__( '1 Comment', 'katerio' ) . '</span>';
				}
			}
			$post_meta .= '</a>';
			$post_meta .= '</div>';
		}

		// Edit ----------
		if ( ! empty( $edit ) && is_user_logged_in() ) {
			ob_start();
            edit_post_link( esc_html__( 'Edit', 'katerio' ), '<div class="edit-link meta-color">', '</div>' );
			$post_meta .= ob_get_clean();
		}

		$post_meta .= '</div>' . $after;

		if ( ! empty( $first_cat ) || ! empty( $cats ) || ! empty( $author ) || ! empty( $date ) || ( ! empty( $views ) && TH90_POSTVIEWS_IS_ACTIVE ) || ! empty( $reading_time ) || ( ! empty( $comments ) && th90_opt( 'post_comment' ) && ( comments_open() || get_comments_number() ) ) || ( ! empty( $edit ) && is_user_logged_in() ) ) {
			return $post_meta;
		}
	}
}

/*
--------------------------------------------------------------------------------
* Print the Post info
* ------------------------------------------------------------------------------
*/
if ( ! function_exists( 'th90_the_post_info' ) ) {

	function th90_the_post_info( $args = '', $before = false, $after = false ) {
		echo th90_get_post_info( $args, $before, $after );
	}
}

/*
--------------------------------------------------------------------------------
* Get the post time
* ------------------------------------------------------------------------------
*/
if ( ! function_exists( 'th90_get_time' ) ) {

	function th90_get_time( $format = false ) {

		if ( 'modern' == $format ) {

			// Human Readable Post Dates ----------
			$time_now  = current_time( 'timestamp' );
			$post_time = get_the_time( 'U' );

			$since = sprintf( esc_html__( '%s ago', 'katerio' ), human_time_diff( $post_time, $time_now ) );
		} else {

			// Default date format ----------
			$since = get_the_date();

		}

		return $since;
	}
}

/*
--------------------------------------------------------------------------------
* Display number of views
* ------------------------------------------------------------------------------
*/
if( ! function_exists( 'th90_views' )){

	function th90_views( $post_id = 0 ) {

		if( empty( $post_id )){
			$post_id = get_the_ID();
		}

		$output = '';

		if ( TH90_POSTVIEWS_IS_ACTIVE ) {
			$count  = pvc_get_post_views( $post_id );
			$output .= '<div class="meta-color meta-views">';
			$output .= '<span>' . th90_number_format_short( $count ) . ' ' . esc_html__( 'Views', 'katerio' ) . '</span>';
			$output .= '</div>';
		}

		return $output;
	}

}

/*
--------------------------------------------------------------------------------
* Get Post reading time
* ------------------------------------------------------------------------------
*/
if( ! function_exists( 'th90_reading_time' )){

	function th90_reading_time(){

		$content = get_post_field( 'post_content', get_the_ID() );
		$number_of_images = substr_count( strtolower( $content ), '<img ' );

		$content = strip_shortcodes( $content );
		$content = wp_strip_all_tags( $content );
		$word_count = count( preg_split( '/\s+/', $content ) );

		// Calculate additional time added to post by images.
		$additional_time = 0;
		// For the first image add 12 seconds, second image add 11, ..., for image 10+ add 3 seconds.
		for ( $i = 1; $i <= $number_of_images; $i++ ) {
			if ( $i >= 10 ) {
				$additional_time += 3 * (int) 300 / 60;
			} else {
				$additional_time += ( 12 - ( $i - 1 ) ) * (int) 300 / 60;
			}
		}

		$word_count += $additional_time;

		$word_count = apply_filters( 'th90_filter_wordcount', $word_count );

		$reading_time = $word_count / 300;

		if( $reading_time < 1){
			$result = esc_html__( 'Less 1 min read', 'katerio' );
		}
		elseif( $reading_time > 60 ){
			$result = sprintf( esc_html__( '%s hours read', 'katerio' ), number_format_i18n( floor( $reading_time / 60 ) ) );
		}
		else if ( $reading_time == 1 ){
			$result = esc_html__( '1 min read', 'katerio' );
		}
		else {
			$result = sprintf( esc_html__( '%s mins read', 'katerio' ), number_format_i18n( $reading_time ) );
		}

		return $result;
	}
}

/**
 * -----------------------------------------------------------------------------
 * Post Format Icon
 * -----------------------------------------------------------------------------
 */
if ( ! function_exists( 'th90_post_format_icon' ) ) {
	function th90_post_format_icon( $position = 'center' ) {
		$position = ' f-icon-' . $position;
		if ( has_post_format( 'video' ) ) {
			$video = th90_field_single( 'video_embed' );
			if ( $video && th90_check_youtube_vimeo( $video ) ) {
				$url_iframe = th90_get_url_embed( $video );
				$url_result = false;
				if ( strpos( $url_iframe, 'yout' ) !== false ) {
					$url_result = th90_build_youtube_url( $url_iframe );
				} elseif ( strpos( $url_iframe, 'vim' ) !== false ) {
					$url_result = th90_build_vimeo_url( $url_iframe );
				}
				if ( $url_result ) {
					echo '<a href="' . esc_url( $url_result ) . '" title="' . esc_attr( get_the_title() ) . '" class="f-icon f-video venobox' . esc_attr( $position ) . '" data-vbtype="video">' . th90_get_svg_icon( 'video' ) . '</a>';
				} else {
					echo '<div class="f-icon f-video' . esc_attr( $position ) . '">' . th90_get_svg_icon( 'video' ) . '</div>';
				}
		    } else {
		       echo '<div class="f-icon f-video' . esc_attr( $position ) . '">' . th90_get_svg_icon( 'video' ) . '</div>';
		    }

		} elseif ( has_post_format( 'audio' ) ) {
			echo '<div class="f-icon f-audio' . esc_attr( $position ) . '">' . th90_get_svg_icon( 'audio' ) . '</div>';
		} elseif ( has_post_format( 'gallery' ) ) {
			echo '<div class="f-icon f-gallery' . esc_attr( $position ) . '">' . th90_get_svg_icon( 'gallery' ) . '</div>';
		}
	}
}

/*
--------------------------------------------------------------------------------
* The Read More
* ------------------------------------------------------------------------------
*/
if ( ! function_exists( 'th90_the_readmore' ) ) {

	function th90_the_readmore( $style = 'text' ) {
		?>
		<div class="read-more">
			<a href="<?php the_permalink(); ?>" class="post-more button btn-small btn-<?php echo esc_attr( $style ); ?>">
				<span>
					<?php esc_html_e( 'Read More ...', 'katerio' ); ?>
				</span>
			</a>
		</div>
		<?php
	}
}