File: //home/madepabj/gamepointpk.com/wp-content/themes/groovy/functions/post-formats.php
<?php
function epcl_display_post_format($format = '', $post_id = ''){
if( !$format ) // If not custom metaboxes, always uses format image
$format = 'image';
$prefix = EPCL_THEMEPREFIX.'_';
switch($format){
default: // Standard and Image post format
case 'image':
return epcl_get_image_format($post_id);
break;
case 'video':
return epcl_get_video_format($post_id);
break;
case 'gallery':
return epcl_get_gallery_format($post_id);
break;
case 'audio':
return epcl_get_audio_format($post_id);
break;
}
}
function epcl_get_image_format($post_id){
$index = get_query_var('index');
$epcl_theme = epcl_get_theme_options();
$module_style = get_query_var('epcl_module_style'); // Grid or Classic
$epcl_module = epcl_get_module_options();
$post_meta = get_post_meta( $post_id, 'epcl_post', true );
$class = $image_alt = $thumb_url = '';
$loop_post_style = 'small-image';
// Pendiente: mejorar estilo si no hay post_meta
if( !empty($post_meta) && !isset($post_meta['loop_style']) ){
$loop_post_style = 'small-image'; // text-only
if( $module_style == 'grid' && epcl_get_option('grid_loop_style', 'inherit') !== 'inherit' ){
$loop_post_style = epcl_get_option('grid_loop_style', 'inherit');
}
if( $module_style == 'classic' && epcl_get_option('classic_loop_style', 'inherit') !== 'inherit' ){
$loop_post_style = epcl_get_option('classic_loop_style', 'inherit');
}
$class = 'post-style-'.$loop_post_style;
}
// Loop
if( !is_single() ){
$optimized_image = '';
$size = 'epcl_vertical';
if( !empty( $epcl_module) && $epcl_module['layout'] == 'grid_posts' ){
$size = 'thumbnail';
}
// If is AMP loop, always force small-image layout for better speed results
if( epcl_is_amp() ){
$size = 'epcl_vertical';
if( !empty($post_meta) && isset($post_meta['loop_style']) && $post_meta['loop_style'] == 'classic-image' ){
$post_meta['loop_style'] = 'small-image';
}
}else{
if( !empty($post_meta) && isset($post_meta['loop_style']) ){
if( $module_style == 'grid' && epcl_get_option('grid_loop_style', 'inherit') !== 'inherit' ){
$post_meta['loop_style'] = epcl_get_option('grid_loop_style', 'inherit');
}
if( $module_style == 'classic' && epcl_get_option('classic_loop_style', 'inherit') !== 'inherit' ){
$post_meta['loop_style'] = epcl_get_option('classic_loop_style', 'inherit');
}
}
}
// Get optimized image if is assigned one
if( defined('EPCL_PLUGIN_PATH') && !empty($post_meta) && isset($post_meta['optimized_image']) ){
$optimized_image = $post_meta['optimized_image'];
if( !empty($optimized_image) && isset($optimized_image['alt']) ){
$image_alt = $optimized_image['alt'];
}
}
// Get loop style (small image or standard)
if( !empty($post_meta) && isset($post_meta['loop_style']) && $post_meta['loop_style'] != '' ){
$loop_post_style = $post_meta['loop_style'];
if( get_post_format() == 'audio' || get_post_format() == 'video' ){
$loop_post_style = 'classic-image';
}
$class .= 'post-style-'.$post_meta['loop_style'];
}
// Change size if the image is larger
if( $loop_post_style == 'classic-image' ){
$size = 'epcl_classic';
}
if( $module_style == 'grid' ){
$size = 'epcl_vertical';
}
$thumb_url = get_the_post_thumbnail_url($post_id, $size);
// Overwrite default img if there is any optimized image
if( !empty($optimized_image) && $optimized_image['url'] ){
$thumb_url = $optimized_image['url'];
}
// Single Post
}else{
$single_size = 'epcl_classic';
if( isset($post_meta['style']) && $post_meta['style'] == 'fullcover' ){
$single_size = 'epcl_fullcover';
}
$image_id = get_post_thumbnail_id( get_the_ID() );
$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true);
// On mobile always force Classic image size (even on fullcover style)
if( wp_is_mobile() ){
$single_size = 'epcl_classic';
}
}
if( !$image_alt ){
$image_alt = get_the_title();
}
if( is_single() && !has_post_thumbnail() ) return;
if( $index == 0 && isset($epcl_theme['enable_lazyload']) ){
$epcl_theme['enable_lazyload'] = false;
}
?>
<!-- start: .post-format-image -->
<div class="post-format-image <?php echo esc_attr($class); ?>">
<?php if( is_single() ): // Single Post ?>
<?php if( has_post_thumbnail() ): ?>
<div class="featured-image">
<div class="epcl-loader bg-box">
<?php the_post_thumbnail( $single_size, array('class' => 'fullwidth', 'data-lazy' => 'false') ); ?>
</div>
</div>
<?php endif; ?>
<?php else: // Loops ?>
<!-- start: .featured-image -->
<div class="featured-image epcl-flex">
<?php
$loop_class = '';
if( !empty($epcl_theme) && $epcl_theme['enable_lazyload'] == 1 && !epcl_is_amp() ){
$loop_class .= ' epcl-loader';
}
if( !empty($epcl_theme) && $epcl_theme['enable_lazyload'] == 0){
$loop_class .= 'loaded';
}
if( empty($epcl_theme) ){
$loop_class .= 'loaded';
}
?>
<!-- start: Classic module -->
<?php if( $module_style == 'classic'): ?>
<!-- Loop: Small/Vertical Image Style -->
<?php if( $thumb_url && $loop_post_style == 'small-image' ): ?>
<a href="<?php the_permalink(); ?>" class="thumb main-effect medium-shadow epcl-loader <?php echo esc_attr($loop_class); ?>">
<?php if( epcl_is_amp() ): ?>
<amp-img class="cover" layout="fill" src="<?php echo esc_url($thumb_url); ?>" alt="<?php echo esc_attr($image_alt); ?>"></amp-img>
<?php else: ?>
<?php if( !empty($epcl_theme) && $epcl_theme['enable_lazyload'] == '1' ): ?>
<img class="post-image fullimage lazy" alt="<?php echo esc_attr($image_alt); ?>" data-src="<?php echo esc_url($thumb_url); ?>" src="<?php echo EPCL_THEMEPATH; ?>/assets/images/transparent.gif" width="300" height="380">
<?php else: ?>
<img class="post-image fullimage" alt="<?php echo esc_attr($image_alt); ?>" src="<?php echo esc_url($thumb_url); ?>">
<?php endif; ?>
<?php endif; ?>
</a>
<?php endif; ?>
<!-- Loop: Classic Image Style -->
<?php if( $thumb_url && $loop_post_style == 'classic-image' ): ?>
<a href="<?php the_permalink(); ?>" class="thumb medium-shadow epcl-loader <?php echo esc_attr($loop_class); ?>">
<?php if( epcl_is_amp() ): ?>
<amp-img class="cover" layout="fill" src="<?php echo esc_url($thumb_url); ?>" alt="<?php echo esc_attr($image_alt); ?>"></amp-img>
<?php else: ?>
<?php if( !empty($epcl_theme) && $epcl_theme['enable_lazyload'] == '1' ): ?>
<img class="post-image fullimage lazy" alt="<?php echo esc_attr($image_alt); ?>" data-src="<?php echo esc_url($thumb_url); ?>" src="<?php echo EPCL_THEMEPATH; ?>/assets/images/transparent.gif" width="100%" height="380">
<?php else: ?>
<img class="post-image fullimage" alt="<?php echo esc_attr($image_alt); ?>" src="<?php echo esc_url($thumb_url); ?>" width="100%" height="380">
<?php endif; ?>
<?php endif; ?>
</a>
<?php if( get_the_category() ): ?>
<div class="absolute tags">
<?php echo epcl_render_categories(2); ?>
</div>
<?php endif; ?>
<div class="info">
<h1 class="main-title title inline main-effect"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</div>
<?php endif; ?>
<?php if($thumb_url): ?>
<div class="meta absolute">
<?php get_template_part('partials/meta-info/comments'); ?>
</div>
<?php elseif( !$thumb_url && $loop_post_style == 'classic-image'): ?>
<h1 class="main-title title large underline-effect"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php endif; ?>
<?php endif; ?>
<!-- end: Classic module -->
<!-- start: Grid module -->
<?php if( $module_style == 'grid'): ?>
<?php if( $thumb_url ): ?>
<a href="<?php the_permalink(); ?>" class="thumb fullwidth epcl-loader <?php echo esc_attr($loop_class); ?>">
<?php if( epcl_is_amp() ): ?>
<amp-img class="cover" layout="fill" src="<?php echo esc_url($thumb_url); ?>" alt="<?php echo esc_attr($image_alt); ?>"></amp-img>
<?php else: ?>
<?php if( !empty($epcl_theme) && $epcl_theme['enable_lazyload'] == '1' ): ?>
<img class="post-image fullimage lazy" alt="<?php echo esc_attr($image_alt); ?>" data-src="<?php echo esc_url($thumb_url); ?>" src="<?php echo EPCL_THEMEPATH; ?>/assets/images/transparent.gif" width="100%" height="380">
<?php else: ?>
<img class="post-image fullimage" alt="<?php echo esc_attr($image_alt); ?>" src="<?php echo esc_url($thumb_url); ?>" width="100%" height="380">
<?php endif; ?>
<?php endif; ?>
</a>
<?php endif; ?>
<div class="info textleft">
<h1 class="main-title title large inline shadow-effect"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</div>
<?php if( get_the_category() ): ?>
<div class="tags">
<?php echo epcl_get_primary_category_link( $post_meta, $post_id ); ?>
</div>
<?php endif; ?>
<div class="meta absolute">
<?php get_template_part('partials/meta-info/comments'); ?>
</div>
<?php endif; ?>
<!-- end: Grid module -->
</div>
<!-- end: .featured-image -->
<div class="clear"></div>
<?php endif; ?>
</div>
<!-- end: .post-format-image -->
<?php
}
function epcl_get_video_format($post_id){
$type = 'youtube';
$height = 225;
$url = '';
$epcl_theme = epcl_get_theme_options();
$post_meta = get_post_meta( $post_id, 'epcl_post_video', true );
$width = '100%';
$video_id = $video_url = '';
$show_featured_image = '';
if( !empty($post_meta) ){
$show_featured_image = $post_meta['show_featured_image'];
$type = $post_meta['video_type'];
$url = $post_meta['video_url'];
}
if( !is_single() && $show_featured_image ){
return epcl_get_image_format($post_id);
}
$class = '';
if ($type == 'youtube') {
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $matches);
if( !$url ) return;
$video_url ='https://www.youtube.com/embed/'.$matches[0].'?rel=0&showinfo=0';
} elseif ($type == 'vimeo') {
$result = preg_match('/(\d+)/', $url, $matches);
if( !$url ) return;
if($result){
$video_id = $matches[0];
}else{
$video_id = $url;
}
$video_url = 'https://player.vimeo.com/video/'.$video_id;
} elseif ($type == 'custom') {
$custom_embed = $post_meta['custom_embed'];
if( !$custom_embed ) return;
preg_match('/src="([^"]+)"/', $custom_embed, $match);
$video_url = $match[1];
}
?>
<div class="post-format-wrapper epcl-loader <?php echo esc_attr($class); ?>">
<div class="post-format-video">
<?php if( epcl_is_amp() ): ?>
<amp-iframe layout="responsive" width="480" height="250" sandbox="allow-scripts allow-same-origin allow-popups" title="<?php the_title(); ?>" src="<?php echo esc_url($video_url); ?>" allowfullscreen>
<amp-img layout="fill" src="<?php echo EPCL_THEMEPATH; ?>/assets/images/transparent.gif" placeholder></amp-img>
</amp-iframe>
<?php else: ?>
<?php if( epcl_get_option('enable_lazyload_embed', true) ): ?>
<iframe title="<?php the_title(); ?>" data-lazy="true" data-src="<?php echo esc_url($video_url); ?>" allowfullscreen height="<?php echo esc_attr($height); ?>" style="width: <?php echo esc_attr($width); ?>"></iframe>
<?php else: ?>
<iframe title="<?php the_title(); ?>" src="<?php echo esc_url($video_url); ?>" allowfullscreen height="<?php echo esc_attr($height); ?>" style="width: <?php echo esc_attr($width); ?>"></iframe>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
<?php if( !is_single() ): ?>
<div class="info below-image textcenter">
<h1 class="main-title title underline-effect large"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</div>
<?php endif; ?>
<?php
}
function epcl_get_gallery_format($post_id){
$post_gallery = $post_meta = array();
if( defined('EPCL_PLUGIN_PATH') ){
$post_meta = get_post_meta( $post_id, 'epcl_post', true );
$post_gallery = get_post_meta( $post_id, 'epcl_post_gallery', true );
}
// If no images and is Single Post, just return nothing
if( empty($post_gallery['gallery']) && is_single() ) return;
$gallery_images = explode(',', $post_gallery['gallery'] );
$epcl_theme = epcl_get_theme_options();
$module_style = get_query_var('epcl_module_style'); // Grid or Classic
$class = $post_style = '';
if( !empty($post_meta) ){
$post_style = $post_meta['style'];
}
$size = 'epcl_classic_post';
if( is_single() && $post_style == 'fullcover' ){
$size = 'epcl_fullcover';
}
$height = 225;
if( !wp_is_mobile() ){
$height = 400;
}
?>
<!-- In case of loop return just the title and meta info -->
<?php if( empty($post_gallery['gallery']) && !is_single() ): ?>
<div class="info below-image textcenter">
<h1 class="main-title title underline-effect large"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php get_template_part('partials/meta-info'); ?>
</div>
<?php return; endif; ?>
<div class="post-format-gallery <?php echo esc_attr($class); ?>">
<?php if( epcl_is_amp() ): ?>
<amp-carousel height="<?php echo absint($height); ?>" layout="fill" type="slides">
<?php foreach($gallery_images as $id): ?>
<?php
$image_url = wp_get_attachment_image_src($id, $size);
$image_alt = get_post_meta($id, '_wp_attachment_image_alt', TRUE);
?>
<amp-img class="cover" src="<?php echo esc_url( $image_url[0] ); ?>" layout="fill" alt="<?php echo esc_attr( $image_alt ); ?>">
<?php if( !is_single() ): ?>
<a href="<?php the_permalink(); ?>" class="full-link"></a>
<?php endif; ?>
</amp-img>
<?php endforeach; ?>
</amp-carousel>
<?php else: ?>
<div class="slick-slider" data-rtl="<?php echo is_rtl(); ?>">
<?php foreach($gallery_images as $id): ?>
<?php
$image_url = wp_get_attachment_image_src($id, $size);
?>
<div class="item epcl-loader">
<?php if( !empty($epcl_theme) && $epcl_theme['enable_lazyload'] == '1' ): ?>
<span class="thumb fullimage cover lazy" data-src="<?php echo esc_url( $image_url[0] ); ?>"></span>
<?php else: ?>
<span class="thumb fullimage cover" style="background-image: url(<?php echo esc_url( $image_url[0] ); ?>);"></span>
<?php endif; ?>
<a href="<?php the_permalink(); ?>" class="full-link"></a>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if( is_single() && $post_style == 'classic' ): ?>
<?php if( epcl_get_option( 'enable_single_category', true ) ): ?>
<div class="tags absolute">
<?php echo epcl_get_primary_category_link( $post_meta, $post_id ); ?>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php if( !is_single() ): ?>
<div class="info below-image textcenter">
<h1 class="main-title title underline-effect large"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</div>
<?php if( get_the_category() ): ?>
<div class="tags <?php if( $module_style == 'classic' ) echo 'absolute'; ?>">
<?php echo epcl_get_primary_category_link( $post_meta, $post_id ); ?>
</div>
<?php endif; ?>
<div class="meta absolute">
<?php get_template_part('partials/meta-info/comments'); ?>
</div>
<?php endif; ?>
<?php
}
/* To do: self hosted audio */
function epcl_get_audio_format($post_id){
$post_meta_audio = get_post_meta( $post_id, 'epcl_post_audio', true );
if( empty($post_meta_audio) ) return;
$show_featured_image = $post_meta_audio['show_featured_image'];
$url = $post_meta_audio['soundcloud_url'];
if( !is_single() && $show_featured_image ){
return epcl_get_image_format($post_id);
}
if( !is_single() && !$show_featured_image && !$url ){
return;
}
if( is_single() && !$url ){
return epcl_get_image_format($post_id);
}
$class = '';
$width = '100%';
$embed_code = wp_oembed_get( $url );
preg_match('/src="([^"]+)"/', $embed_code, $match);
$url = $match[1];
$url = str_replace('&', '&', $url);
$height = 225;
?>
<div class="post-format-audio post-format-wrapper epcl-loader <?php echo esc_attr($class); ?>">
<?php if( epcl_is_amp() ): ?>
<amp-iframe layout="responsive" width="480" height="150" sandbox="allow-scripts allow-same-origin allow-popups" title="<?php the_title(); ?>" src="<?php echo esc_url($url); ?>" allowfullscreen>
<amp-img layout="fill" src="<?php echo EPCL_THEMEPATH; ?>/assets/images/transparent.gif" placeholder></amp-img>
</amp-iframe>
<?php else: ?>
<?php if( epcl_get_option('enable_lazyload_embed', true) && !epcl_is_amp() ): ?>
<iframe title="<?php the_title(); ?>" data-lazy="true" data-src="<?php echo esc_url($url); ?>" allowfullscreen height="<?php echo absint($height); ?>" style="width: <?php echo esc_attr($width); ?>"></iframe>
<?php else: ?>
<iframe src="<?php echo esc_url($url); ?>" layout="fill" allowFullScreen height="<?php echo absint($height); ?>" style="width: <?php echo esc_attr($width); ?>"></iframe>
<?php endif; ?>
<?php endif; ?>
</div>
<?php if( !is_single() ): ?>
<div class="info below-image textcenter">
<h1 class="main-title title underline-effect large"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</div>
<?php endif; ?>
<?php
}