<?php
/*
  Template Name: Home page
 */

get_header();
?>


<!-- *************** - Tabs Container - *************** -->
<div class="tabs-1">

    <ul class="tabs-nav clearfix">
        <li><a href="#tab_latest"><?php _e('Latest', THEMEMAKERS_THEME_FOLDER_NAME); ?></a></li>
        <li><a href="#tab_popular"><?php _e('Popular', THEMEMAKERS_THEME_FOLDER_NAME); ?></a></li>
        <li><a href="#tab_features"><?php _e('Features', THEMEMAKERS_THEME_FOLDER_NAME); ?></a></li>
    </ul><!--/ .tabs-nav -->

    <div class="tabs-container">

        <div class="tab-content" id="tab_latest">
            <div class="gamelist">
                <ul class="clearfix">


                    <?php
                    $args = array(
                        'numberposts' => 5,
                        'orderby' => 'post_date',
                        'order' => 'DESC',
                        'post_type' => 'games',
                        'post_status' => 'publish',
                        'suppress_filters' => false);

                    $recent_games = wp_get_recent_posts($args);
                    ?>




                    <?php if (!empty($recent_games)): ?>
                        <?php foreach ($recent_games as $key => $game) : ?>
                            <?php
                            $terms = wp_get_post_terms($game['ID'], 'cons');
                            $permalink = get_permalink($game['ID']);
                            $featured_image = THEMEMAKERS_THEME_URI . '/images/no-image.jpg';

                            $featured_image_width = 313;
                            $featured_image_height = 220;

                            if ($key >= 2) {
                                $featured_image_width = 159;
                                $featured_image_height = 100;
                            }
							
							$image_alias='gallery_thumb';

                            if ($key >= 2) {
                                $image_alias='single_thumb';
                            }


                           if (has_post_thumbnail($game['ID'])) {
                                $featured_image = ThemeMakersHelper::get_post_featured_image($game['ID'], $image_alias);
                            }
							
                            ?>
                            <li>
                                <a href="<?php echo $permalink ?>">
                                  <img width="<?php echo $featured_image_width ?>" height="<?php echo $featured_image_height ?>" src="<?php echo $featured_image ?>" alt="" />
                                </a>

                                <div class="caption">
                                    <span class="date"><?php echo $game['post_date'] ?></span>
                                    <h5 class="title"><a href="<?php echo $permalink ?>"><?php echo $game['post_title'] ?></a></h5>
									
                                    <div class="description">
									 <?php
										if ($_REQUEST['excerpt_symbols_count']) {
												echo substr($game['post_content'], 0, $_REQUEST['excerpt_symbols_count']) . " ...";
										} else {
												the_excerpt();
										}
									?>
									
									</div>
                                    <?php if (!$_REQUEST['disable_blog_comments']): ?>
                                    <a href="<?php echo $permalink ?>#comments" class="comments-icon"><?php echo wp_count_comments($game['ID'])->total_comments ?> <?php _e('comments', THEMEMAKERS_THEME_FOLDER_NAME); ?></a>
                                    <?php endif; ?>
                                    <div class="platform-teaser">
                                        <?php if (!empty($terms)): ?>
                                            <?php foreach ($terms as $term) : ?>
                                                <?php $cons_color = get_taxonomy_term_type('cons', $term->term_id); ?>
                                                <a style="background-color: <?php echo $cons_color ?>" class="game_console" href="<?php bloginfo('url') ?>/?cons=<?php echo $term->slug ?>"><?php echo $term->name ?></a>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                    </div><!--/ .platform-teaser-->
									<?php if (!$_REQUEST['disable_blog_comments']): ?>
										<?php echo Thememakers_Entity_Rating::draw_rating($game['ID']) ?>
									<?php endif; ?>
                                </div><!--/ .caption-->
                                <div class="clear"></div>
                            </li>
                        <?php endforeach; ?>
                    <?php endif; ?>





                </ul>
                <div class="clearfix"></div>
                <br />
                <br />
                <a href="/games" class="button small yellow align-btn-right"><?php _e('More Latest', THEMEMAKERS_THEME_FOLDER_NAME); ?></a>
            </div><!--/ .gamelist-->

        </div><!--/ #tab1-->

        <div class="tab-content" id="tab_popular">

            <div class="gamelist">
                <ul class="clearfix">


                    <?php
                    $args = array(
                        'numberposts' => 5,
                        'orderby' => 'post_date',
                        'order' => 'DESC',
                        'post_type' => 'games',
                        'post_status' => 'publish',
                        'meta_key' => 'post_rating',
                        'orderby' => 'meta_value_num',
                        'order' => 'DESC',
                    );

                    $recent_games = wp_get_recent_posts($args);
                    ?>

                    <?php if (!empty($recent_games)): ?>
                        <?php foreach ($recent_games as $key => $game) : ?>
                            <?php
                            $terms = wp_get_post_terms($game['ID'], 'cons');
                            $permalink = get_permalink($game['ID']);
                            $featured_image = THEMEMAKERS_THEME_URI . '/images/no-image.jpg';

                            $image_alias='gallery_thumb';

                            if ($key >= 2) {
                                $image_alias='single_thumb';
                            }


                            if (has_post_thumbnail($game['ID'])) {
                                $featured_image = ThemeMakersHelper::get_post_featured_image($game['ID'], $image_alias);
                            }
                            ?>
                            <li>
                                <a href="<?php echo $permalink ?>">
                                    <img src="<?php echo $featured_image ?>" alt="" />
                                </a>

                                <div class="caption">
                                    <span class="date"><?php echo $game['post_date'] ?></span>
                                    <h5 class="title"><a href="<?php echo $permalink ?>"><?php echo $game['post_title'] ?></a></h5>
									
                                    <div class="description">
									<?php
										if ($_REQUEST['excerpt_symbols_count']) {
												echo substr($game['post_content'], 0, $_REQUEST['excerpt_symbols_count']) . " ...";
										} else {
												the_excerpt();
										}
									?>
									</div>
                                    <?php if (!$_REQUEST['disable_blog_comments']): ?>
                                    <a href="<?php echo $permalink ?>#comments" class="comments-icon"><?php echo wp_count_comments($game['ID'])->total_comments ?> <?php _e('comments', THEMEMAKERS_THEME_FOLDER_NAME); ?></a>
                                    <?php endif; ?>
                                    <div class="platform-teaser">
                                        <?php if (!empty($terms)): ?>
                                            <?php foreach ($terms as $term) : ?>
                                                <?php $cons_color = get_taxonomy_term_type('cons', $term->term_id); ?>
                                                <a style="background-color: <?php echo $cons_color ?>" class="game_console" href="<?php bloginfo('url') ?>/?cons=<?php echo $term->slug ?>"><?php echo $term->name ?></a>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                    </div><!--/ .platform-teaser-->
									 <?php if (!$_REQUEST['disable_blog_comments']): ?>
										<?php echo Thememakers_Entity_Rating::draw_rating($game['ID']) ?>
									 <?php endif; ?>
                                </div><!--/ .caption-->
                                <div class="clear"></div>
                            </li>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </ul>
                <a href="/games" class="button small yellow align-btn-right"><?php _e('More Latest', THEMEMAKERS_THEME_FOLDER_NAME); ?></a>
            </div><!--/ .gamelist-->

        </div><!--/ #tab1-->

        <div class="tab-content" id="tab_features">

            <div class="gamelist">
                <ul class="clearfix">


                    <?php
                    $featured_games_ids = Thememakers_Entity_Game::get_featured_games();
                    ?>
                    <?php if (!empty($featured_games_ids)): ?>
                        <?php foreach ($featured_games_ids as $key => $post_id) : ?>
                            <?php
                            $game = get_post($post_id);
                            $terms = wp_get_post_terms($game->ID, 'cons');
                            $permalink = get_permalink($game->ID);
                            $featured_image = THEMEMAKERS_THEME_URI . '/images/no-image.jpg';

                            $image_alias='gallery_thumb';

                            if ($key >= 2) {
                                $image_alias='single_thumb';
                            }

                            if (has_post_thumbnail($game->ID)) {
                                $featured_image = ThemeMakersHelper::get_post_featured_image($game->ID, $image_alias);
                            }
                            ?>
                            <li>
                                <a href="<?php echo $permalink ?>">
                                    <img src="<?php echo $featured_image ?>" alt="" />
                                </a>

                                <div class="caption">
                                    <span class="date"><?php echo $game->post_date ?></span>
                                    <h5 class="title"><a href="<?php echo $permalink ?>"><?php echo $game->post_title ?></a></h5>
									
                                    <div class="description">
									<?php
										if ($_REQUEST['excerpt_symbols_count']) {
												echo substr($game['post_content'], 0, $_REQUEST['excerpt_symbols_count']) . " ...";
										} else {
												the_excerpt();
										}
									?>
									</div>
                                    <?php if (!$_REQUEST['disable_blog_comments']): ?>
                                    <a href="<?php echo $permalink ?>#comments" class="comments-icon"><?php echo wp_count_comments($game->ID)->total_comments ?> <?php _e('comments', THEMEMAKERS_THEME_FOLDER_NAME); ?></a>
                                    <?php endif; ?>
                                    <div class="platform-teaser">
                                        <?php if (!empty($terms)): ?>
                                            <?php foreach ($terms as $term) : ?>
                                                <?php $cons_color = get_taxonomy_term_type('cons', $term->term_id); ?>
                                                <a style="background-color: <?php echo $cons_color ?>" class="game_console" href="<?php bloginfo('url') ?>/?cons=<?php echo $term->slug ?>"><?php echo $term->name ?></a>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                    </div><!--/ .platform-teaser-->
									 <?php if (!$_REQUEST['disable_blog_comments']): ?>
										<?php echo Thememakers_Entity_Rating::draw_rating($game->ID) ?>
									<?php endif; ?>
                                </div><!--/ .caption-->
                                <div class="clear"></div>
                            </li>
                        <?php endforeach; ?>
                    <?php endif; ?>





                </ul>
            </div><!--/ .gamelist-->

        </div><!--/ #tab1-->
    </div><!--/ .tabs-container-->
</div><!--/ .tabs-1-->
<!-- *************** - END Tabs Container - *************** -->


<!-- *************** - Reviews - *************** -->
<?php
$reviews_count = ThemeMakersThemeModel::get_option('reviews_count');
if(!$reviews_count){
    $reviews_count=5;
}
if ($reviews_count):
    ?>
    <div class="one-third">
        <div class="reviews">

            <div class="title-caption">
                <h3><?php _e('Reviews', THEMEMAKERS_THEME_FOLDER_NAME); ?></h3>
                
            </div><!--/ .title-->

            <div class="gamelist">
                <ul class="clearfix">

                    <?php
                    $args = array(
                        'numberposts' => $reviews_count,
                        'orderby' => 'post_date',
                        'order' => 'DESC',
                        'post_type' => 'review',
                        'post_status' => 'publish',
                        'suppress_filters' => false);

                    $recent_reviews = wp_get_recent_posts($args);
                    ?>




                    <?php if (!empty($recent_reviews)): ?>
                        <?php foreach ($recent_reviews as $key => $review) : ?>
                            <?php
                            $terms = wp_get_post_terms($review['ID'], 'cons');
                            $permalink = get_permalink($review['ID']);
                            $featured_image = THEMEMAKERS_THEME_URI . '/images/no-image.jpg';

                            $image_alias='gallery_thumb';

                            if ($key >= 2) {
                                $image_alias='single_thumb';
                            }


                            if (has_post_thumbnail($review['ID'])) {
                                $featured_image = ThemeMakersHelper::get_post_featured_image($review['ID'], $image_alias);
                            }
                            ?>
                            <li>
                                <a href="<?php echo $permalink ?>">
                                 <?php 
								echo wp_get_attachment_image(get_post_thumbnail_id($review['ID']), array(313,220)); 
								$featured_image=get_post_thumbnail_id($review['ID']);
								if (empty($featured_image)) {
									$featured_image = THEMEMAKERS_THEME_URI . '/images/no-image.jpg';			
							 		$featured_image_width='313px';
									$featured_image_height='220px';
									?>
									<img src="<?php echo $featured_image ?>" width="<?php echo $featured_image_width ?>" height="<?php echo $featured_image_height ?>" alt="<?php echo $review->post_title ?>" />
								<?php } ?>
                                </a>

                                <div class="caption">
                                    <span class="date"><?php echo $review['post_date'] ?></span>
                                    <h5 class="title"><a href="<?php echo $permalink ?>"><?php echo $review['post_title'] ?></a></h5>
									
                                    <div class="description">
									<?php
										if ($_REQUEST['excerpt_symbols_count']) {
												echo substr($review['post_content'], 0, $_REQUEST['excerpt_symbols_count']) . " ...";
										} else {
												the_excerpt();
										}
									?>
									</div>
                                    <?php if (!$_REQUEST['disable_blog_comments']): ?>
                                    <a href="<?php echo $permalink ?>#comments" class="comments-icon"><?php echo wp_count_comments($review['ID'])->total_comments ?> <?php _e('comments', THEMEMAKERS_THEME_FOLDER_NAME); ?></a>
                                    <?php endif; ?>
                                    <div class="platform-teaser">
                                        <?php if (!empty($terms)): ?>
                                            <?php foreach ($terms as $term) : ?>
                                                <?php $cons_color = get_taxonomy_term_type('cons', $term->term_id); ?>
                                                <a style="background-color: <?php echo $cons_color ?>" class="game_console" href="<?php bloginfo('url') ?>/?cons=<?php echo $term->slug ?>"><?php echo $term->name ?></a>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                    </div><!--/ .platform-teaser-->
									 <?php if (!$_REQUEST['disable_blog_comments']): ?>
										<?php echo Thememakers_Entity_Rating::draw_rating($review['ID']) ?>
									<?php endif; ?>
                                </div><!--/ .caption-->
                                <div class="clear"></div>
                            </li>
                        <?php endforeach; ?>
                    <?php endif; ?>



                </ul>
                <a href="<?php bloginfo('url') ?>/?post_type=review" class="see-all"><?php _e('See all', THEMEMAKERS_THEME_FOLDER_NAME); ?> &raquo;</a>
            </div><!--/ .gamelist-->
        </div><!--/ .reviews-->
    </div><!--/ .one-third-->
<?php endif; ?>
<!-- *************** - END Reviews - *************** -->


<!-- *************** - Previews - *************** -->
<?php
$releases_count = ThemeMakersThemeModel::get_option('releases_count');
if(!$releases_count){
    $releases_count=5;
}
if ($releases_count):
    ?>
    <div class="one-third last">
        <div class="reviews">

            <div class="title-caption">
                <h3><?php _e('Releases', THEMEMAKERS_THEME_FOLDER_NAME); ?></h3>
               
            </div><!--/ .title-->

            <div class="gamelist">
                <ul class="clearfix">

                    <?php
                    $args = array(
                        'numberposts' => $releases_count,
                        'orderby' => 'post_date',
                        'order' => 'DESC',
                        'post_type' => 'release',
                        'post_status' => 'publish',
                        'suppress_filters' => false);

                    $recent_releases = wp_get_recent_posts($args);
                    ?>




                    <?php if (!empty($recent_releases)): ?>
                        <?php foreach ($recent_releases as $key => $release) : ?>
                            <?php
                            $terms = wp_get_post_terms($release['ID'], 'cons');
                            $permalink = get_permalink($release['ID']);
                            $featured_image = THEMEMAKERS_THEME_URI . '/images/no-image.jpg';

                            $image_alias='gallery_thumb';

                            if ($key >= 2) {
                                $image_alias='single_thumb';
                            }


                            if (has_post_thumbnail($release['ID'])) {
                                $featured_image = ThemeMakersHelper::get_post_featured_image($release['ID'], $image_alias);
                            }
                            ?>
                            <li>
                                <a href="<?php echo $permalink ?>">
                                 <?php 
								echo wp_get_attachment_image(get_post_thumbnail_id($release['ID']), array(313,220)); 
								$featured_image=get_post_thumbnail_id($release['ID']);
								if (empty($featured_image)) {
									$featured_image = THEMEMAKERS_THEME_URI . '/images/no-image.jpg';			
							 		$featured_image_width='313px';
									$featured_image_height='220px';
									?>
									<img src="<?php echo $featured_image ?>" width="<?php echo $featured_image_width ?>" height="<?php echo $featured_image_height ?>" alt="<?php echo $release->post_title ?>" />
								<?php } ?>
                                </a>

                                <div class="caption">
                                    <span class="date"><?php echo $release['post_date'] ?></span>
                                    <h5 class="title"><a href="<?php echo $permalink ?>"><?php echo $release['post_title'] ?></a></h5>
									
                                    <div class="description">
									<?php
										if ($_REQUEST['excerpt_symbols_count']) {
												echo substr($release['post_content'], 0, $_REQUEST['excerpt_symbols_count']) . " ...";
										} else {
												the_excerpt();
										}
									?>											
									</div>
                                    <?php if (!$_REQUEST['disable_blog_comments']): ?>
                                    <a href="<?php echo $permalink ?>#comments" class="comments-icon"><?php echo wp_count_comments($release['ID'])->total_comments ?> <?php _e('comments', THEMEMAKERS_THEME_FOLDER_NAME); ?></a>
                                    <?php endif; ?>
                                    <div class="platform-teaser">
                                        <?php if (!empty($terms)): ?>
                                            <?php foreach ($terms as $term) : ?>
                                                <?php $cons_color = get_taxonomy_term_type('cons', $term->term_id); ?>
                                                <a style="background-color: <?php echo $cons_color ?>" class="game_console" href="<?php bloginfo('url') ?>/?cons=<?php echo $term->slug ?>"><?php echo $term->name ?></a>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                    </div><!--/ .platform-teaser-->
									 <?php if (!$_REQUEST['disable_blog_comments']): ?>
										<?php echo Thememakers_Entity_Rating::draw_rating($release['ID']) ?>
									 <?php endif; ?>
                                </div><!--/ .caption-->
                                <div class="clear"></div>
                            </li>
                        <?php endforeach; ?>
                    <?php endif; ?>



                </ul>
                <a href="<?php bloginfo('url') ?>/?post_type=release" class="see-all"><?php _e('See all', THEMEMAKERS_THEME_FOLDER_NAME); ?> &raquo;</a>
            </div><!--/ .gamelist-->
        </div><!--/ .reviews-->
    </div><!--/ .one-third .last-->
<?php endif; ?>
<!-- *************** - END Previews - *************** -->







<?php get_footer(); ?>
