<?php
/**
* Media functions
*
* @package GridMini 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 gridmini_media_content_grid() {
    global $post; ?>
    <?php if ( !(gridmini_get_option('hide_thumbnail_home')) ) { ?>
    <?php if ( has_post_thumbnail($post->ID) ) { ?>
    <div class="gridmini-grid-post-thumbnail gridmini-grid-post-block">
        <?php if ( gridmini_get_option('thumbnail_link_home') == 'no' ) { ?>
            <?php the_post_thumbnail('gridmini-360w-360h-image', array('class' => 'gridmini-grid-post-thumbnail-img', 'title' => the_title_attribute('echo=0'))); ?>
        <?php } else { ?>
            <a href="<?php echo esc_url( get_permalink() ); ?>" class="gridmini-grid-post-thumbnail-link" title="<?php /* translators: %s: post title. */ echo esc_attr( sprintf( __( 'Permanent Link to %s', 'gridmini' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_post_thumbnail('gridmini-360w-360h-image', array('class' => 'gridmini-grid-post-thumbnail-img', 'title' => the_title_attribute('echo=0'))); ?></a>
        <?php } ?>
        <?php gridmini_grid_media_bottom_data(); ?>
    </div>
    <?php } else { ?>
    <div class="gridmini-grid-post-thumbnail gridmini-grid-post-thumbnail-default gridmini-grid-post-block">
        <?php if ( gridmini_get_option('thumbnail_link_home') == 'no' ) { ?>
            <img src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/no-image-360-360.jpg' ); ?>" class="gridmini-grid-post-thumbnail-img"/>
        <?php } else { ?>
            <a href="<?php echo esc_url( get_permalink() ); ?>" class="gridmini-grid-post-thumbnail-link" title="<?php /* translators: %s: post title. */ echo esc_attr( sprintf( __( 'Permanent Link to %s', 'gridmini' ), the_title_attribute( 'echo=0' ) ) ); ?>"><img src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/no-image-360-360.jpg' ); ?>" class="gridmini-grid-post-thumbnail-img"/></a>
        <?php } ?>
        <?php gridmini_grid_media_bottom_data(); ?>
    </div>
    <?php } ?>
    <?php } ?>
<?php }

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

function gridmini_media_content_single_location() {
    global $post;
    if( gridmini_get_option('featured_media_under_post_title') ) {
        add_action('gridmini_after_single_post_title', 'gridmini_media_content_single', 10 );
    } else {
        add_action('gridmini_before_single_post_title', 'gridmini_media_content_single', 10 );
    }
}
add_action('template_redirect', 'gridmini_media_content_single_location', 100 );

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

function gridmini_media_content_page_location() {
    global $post;
    if( gridmini_get_option('featured_media_under_page_title') ) {
        add_action('gridmini_after_single_page_title', 'gridmini_media_content_page', 10 );
    } else {
        add_action('gridmini_before_single_page_title', 'gridmini_media_content_page', 10 );
    }
}
add_action('template_redirect', 'gridmini_media_content_page_location', 110 );