* Created on: 26/07/2018 * * @soundtrack Into the Sun (EP Version) - Sons Of The East * @package Hestia */ /** * Class Hestia_Blog_Post_Layout */ class Hestia_Blog_Post_Layout { /** * Initialize the post layout manager. */ public function init() { add_action( 'hestia_blog_post_template_part', array( $this, 'render' ), 2 ); } /** * Main render function. * * @param string $layout post layout. */ public function render( $layout ) { $pid = get_the_ID(); $article_class = $this->get_article_class( $layout ); $wrapper_class = $this->get_wrapper_class( $layout ); $row_class = 'row '; if ( $layout === 'alt-1' ) { $row_class = 'row alternative-blog-row '; } $settings = array( 'pid' => $pid, 'article_class' => $article_class, 'wrapper_class' => $wrapper_class, 'row_class' => $row_class, 'layout' => $layout, ); if ( is_search() ) { do_action( 'hestia_before_search_content' ); } echo $this->get_article( $settings ); } /** * Get an article. * * @param array $args Article arguments. */ public function get_article( $args = array() ) { $article_template = ''; $article_template .= '
'; $article_template .= '
'; if ( $args['layout'] === 'default' ) { $article_template .= $this->render_post_thumbnail(); } if ( $args['layout'] !== 'alt-2' ) { $article_template .= '
'; $article_template .= $this->render_post_body(); $article_template .= '
'; } if ( $args['layout'] === 'alt-1' ) { $article_template .= $this->render_post_thumbnail(); } if ( $args['layout'] === 'alt-2' ) { $article_template .= '
'; $article_template .= $this->render_post_thumbnail( $args['layout'] ); $article_template .= $this->render_post_body( $args['layout'] ); $article_template .= '
'; } $article_template .= '
'; $article_template .= '
'; return $article_template; } /** * Render alternative post thumbnail * * @param string $type layout type [default | alt-2 ]. */ private function render_post_thumbnail( $type = 'default' ) { if ( ! $this->is_valid_layout_type( $type ) ) { return ''; } if ( ! has_post_thumbnail() ) { return ''; } $post_thumbnail_content = ''; $size = 'hestia-blog'; $wrap_class = 'col-ms-5 col-sm-5'; if ( $type === 'alt-2' ) { $size = 'medium_large'; $wrap_class = 'card-header card-header-image'; } $post_thumbnail_content .= '
'; $post_thumbnail_content .= '
'; $post_thumbnail_content .= ''; $post_thumbnail_content .= get_the_post_thumbnail( null, $size ); $post_thumbnail_content .= ''; $post_thumbnail_content .= '
'; $post_thumbnail_content .= '
'; return $post_thumbnail_content; } /** * Get article class names. * * @return string */ private function get_article_class( $layout ) { $classes = ''; switch ( $layout ) { case 'default': case 'alt-1': $classes = 'card card-blog'; $classes .= ( is_sticky() && is_home() && ! is_paged() ? ' card-raised' : ' card-plain' ); break; case 'alt-2': $grid_layout = get_theme_mod( 'hestia_grid_layout', 1 ); $card_type = 'card-no-width'; if ( $grid_layout === 1 ) { $card_type = 'card'; } $classes = $card_type . ' card-plain card-blog'; if ( ! $this->is_full_content() ) { $classes .= ' text-center'; } $blog_layout = get_theme_mod( 'hestia_alternative_blog_layout', 'blog_normal_layout' ); if ( $blog_layout !== 'blog_alternative_layout2' ) { return $classes; } if ( $grid_layout === 1 ) { return $classes . ' layout-alternative2 '; } $classes .= ' layout-alternative2 col-sm-12 col-md-' . ( 12 / $grid_layout ); break; } return $classes; } /** * Wrapper classes for alternative layout */ private function get_wrapper_class( $layout ) { $classes = ''; switch ( $layout ) { case 'default': case 'alt-1': $classes = has_post_thumbnail() ? 'col-ms-7 col-sm-7' : 'col-sm-12'; break; case 'alt-2': $classes = 'col-md-12'; if ( is_sticky() && is_home() && ! is_paged() ) { $classes .= ' card featured-alt-2'; } break; } return $classes; } /** * Render post body. * * @param string $type the type of post. */ private function render_post_body( $type = 'default' ) { if ( ! $this->is_valid_layout_type( $type ) ) { return ''; } $post_body_content = ''; if ( $type === 'alt-2' ) { $post_body_content .= '
'; } $post_body_content .= '
'; $post_body_content .= hestia_category(); $post_body_content .= '
'; $post_body_content .= the_title( sprintf( '

', esc_url( get_permalink() ), the_title_attribute( array( 'echo' => false, ) ) ), '

', false ); $excerpt_class = $this->is_full_content() ? 'entry-content' : 'entry-summary'; $post_body_content .= '
'; $post_body_content .= $this->get_theme_excerpt( $type ); $post_body_content .= '
'; if ( $type === 'default' ) { $post_body_content .= $this->render_post_meta(); } if ( $type === 'alt-2' ) { $post_body_content .= $this->render_read_more_button(); $post_body_content .= '
'; } return $post_body_content; } /** * Get post excerpt. * * @param string $type Blog post layout type. * * @return string */ private function get_theme_excerpt( $type ) { global $post; $content = $this->get_post_content(); /** * Return full content if the option is set in customizer */ if ( $this->is_full_content() ) { return $content; } /** * Check for excerpt */ if ( has_excerpt( $post->ID ) ) { return apply_filters( 'the_excerpt', get_the_excerpt() ); } /** * Check for more tag */ $hestia_more = strpos( $post->post_content, '