<?php
/**
* Media functions
*
* @package GridFeel WordPress Theme
* @copyright Copyright (C) 2025 ThemesDNA
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
* @author ThemesDNA <themesdna@gmail.com>
*/

function gridfeel_media_content_grid() {
    global $post; ?>
    <?php if ( has_post_thumbnail($post->ID) ) { ?>
    <div class="gridfeel-grid-post-thumbnail gridfeel-grid-post-block">
        <?php if ( gridfeel_get_option('thumbnail_link_home') == 'no' ) { ?>
            <?php the_post_thumbnail('gridfeel-360w-270h-image', array('class' => 'gridfeel-grid-post-thumbnail-img', 'title' => the_title_attribute('echo=0'))); ?>
        <?php } else { ?>
            <a href="<?php echo esc_url( get_permalink() ); ?>" class="gridfeel-grid-post-thumbnail-link" title="<?php /* translators: %s: post title. */ echo esc_attr( sprintf( __( 'Permanent Link to %s', 'gridfeel' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_post_thumbnail('gridfeel-360w-270h-image', array('class' => 'gridfeel-grid-post-thumbnail-img', 'title' => the_title_attribute('echo=0'))); ?></a>
        <?php } ?>
        <?php gridfeel_grid_media_bottom_data(); ?>
    </div>
    <?php } else { ?>
    <div class="gridfeel-grid-post-thumbnail gridfeel-grid-post-thumbnail-default gridfeel-grid-post-block">
        <?php if ( gridfeel_get_option('thumbnail_link_home') == 'no' ) { ?>
            <img src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/no-image-360-270.jpg' ); ?>" class="gridfeel-grid-post-thumbnail-img"/>
        <?php } else { ?>
            <a href="<?php echo esc_url( get_permalink() ); ?>" class="gridfeel-grid-post-thumbnail-link" title="<?php /* translators: %s: post title. */ echo esc_attr( sprintf( __( 'Permanent Link to %s', 'gridfeel' ), the_title_attribute( 'echo=0' ) ) ); ?>"><img src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/no-image-360-270.jpg' ); ?>" class="gridfeel-grid-post-thumbnail-img"/></a>
        <?php } ?>
        <?php gridfeel_grid_media_bottom_data(); ?>
    </div>
    <?php } ?>
<?php }


function gridfeel_media_content_single() {
    global $post;
    if ( has_post_thumbnail() ) {
        if ( !(gridfeel_get_option('hide_thumbnail')) ) {
            if ( gridfeel_get_option('thumbnail_link') == 'no' ) { ?>
                <div class="gridfeel-post-thumbnail-single">
                <?php
                if ( is_page_template( array( 'template-full-width-post.php', 'template-full-width-post-sidebar.php' ) ) ) {
                    the_post_thumbnail('gridfeel-1200w-autoh-image', array('class' => 'gridfeel-post-thumbnail-single-img', 'title' => the_title_attribute('echo=0')));
                } else {
                    the_post_thumbnail('gridfeel-685w-autoh-image', array('class' => 'gridfeel-post-thumbnail-single-img', 'title' => the_title_attribute('echo=0')));
                }
                ?>
                </div>
            <?php } else { ?>
                <div class="gridfeel-post-thumbnail-single">
                <?php if ( is_page_template( array( 'template-full-width-post.php', 'template-full-width-post-sidebar.php' ) ) ) { ?>
                    <a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php /* translators: %s: post title. */ echo esc_attr( sprintf( __( 'Permanent Link to %s', 'gridfeel' ), the_title_attribute( 'echo=0' ) ) ); ?>" class="gridfeel-post-thumbnail-single-link"><?php the_post_thumbnail('gridfeel-1200w-autoh-image', array('class' => 'gridfeel-post-thumbnail-single-img', 'title' => the_title_attribute('echo=0'))); ?></a>
                <?php } else { ?>
                    <a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php /* translators: %s: post title. */ echo esc_attr( sprintf( __( 'Permanent Link to %s', 'gridfeel' ), the_title_attribute( 'echo=0' ) ) ); ?>" class="gridfeel-post-thumbnail-single-link"><?php the_post_thumbnail('gridfeel-685w-autoh-image', array('class' => 'gridfeel-post-thumbnail-single-img', 'title' => the_title_attribute('echo=0'))); ?></a>
                <?php } ?>
                </div>
    <?php   }
        }
    }
}


function gridfeel_media_content_single_location() {
    global $post;
    if( gridfeel_get_option('featured_media_under_post_title') ) {
        add_action('gridfeel_after_single_post_title', 'gridfeel_media_content_single', 10 );
    } else {
        add_action('gridfeel_before_single_post_title', 'gridfeel_media_content_single', 10 );
    }
}
add_action('template_redirect', 'gridfeel_media_content_single_location', 100 );


function gridfeel_media_content_page() {
    global $post; ?>
    <?php
    if ( has_post_thumbnail() ) {
        if ( !(gridfeel_get_option('hide_page_thumbnail')) ) {
            if ( gridfeel_get_option('thumbnail_link_page') == 'no' ) { ?>
                <div class="gridfeel-post-thumbnail-single">
                <?php
                if ( is_page_template( array( 'template-full-width-page.php', 'template-full-width-page-sidebar.php' ) ) ) {
                    the_post_thumbnail('gridfeel-1200w-autoh-image', array('class' => 'gridfeel-post-thumbnail-single-img', 'title' => the_title_attribute('echo=0')));
                } else {
                    the_post_thumbnail('gridfeel-685w-autoh-image', array('class' => 'gridfeel-post-thumbnail-single-img', 'title' => the_title_attribute('echo=0')));
                }
                ?>
                </div>
            <?php } else { ?>
                <div class="gridfeel-post-thumbnail-single">
                <?php if ( is_page_template( array( 'template-full-width-page.php', 'template-full-width-page-sidebar.php' ) ) ) { ?>
                    <a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php /* translators: %s: post title. */ echo esc_attr( sprintf( __( 'Permanent Link to %s', 'gridfeel' ), the_title_attribute( 'echo=0' ) ) ); ?>" class="gridfeel-post-thumbnail-single-link"><?php the_post_thumbnail('gridfeel-1200w-autoh-image', array('class' => 'gridfeel-post-thumbnail-single-img', 'title' => the_title_attribute('echo=0'))); ?></a>
                <?php } else { ?>
                    <a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php /* translators: %s: post title. */ echo esc_attr( sprintf( __( 'Permanent Link to %s', 'gridfeel' ), the_title_attribute( 'echo=0' ) ) ); ?>" class="gridfeel-post-thumbnail-single-link"><?php the_post_thumbnail('gridfeel-685w-autoh-image', array('class' => 'gridfeel-post-thumbnail-single-img', 'title' => the_title_attribute('echo=0'))); ?></a>
                <?php } ?>
                </div>
    <?php   }
        }
    }
    ?>
<?php }


function gridfeel_media_content_page_location() {
    global $post;
    if( gridfeel_get_option('featured_media_under_page_title') ) {
        add_action('gridfeel_after_single_page_title', 'gridfeel_media_content_page', 10 );
    } else {
        add_action('gridfeel_before_single_page_title', 'gridfeel_media_content_page', 10 );
    }
}
add_action('template_redirect', 'gridfeel_media_content_page_location', 110 );