<?php
/*
Theme Designed By: S O R O U S H M A R K E T
Email: info@soroushmarket.ir
Demo Website: soroushmarket.ir
Author Website: soroushmarket.ir
*/
$store_page_setting = (is_front_page() && is_page_template('front-page.php') ? 'page' : 'paged' );
   $current_page = get_query_var($store_page_setting);
         $per_page = get_option('posts_per_page');
         $offset = $current_page > 0 ? $per_page * ($current_page-1) : 0;
         $product_args = array(
            'post_type' => 'download',
            'posts_per_page' => $per_page,
            'offset' => $offset
         );
   $products = new WP_Query( $product_args );
   get_header();?>
   <div role="complementary" class="col-lg-3 col-md-3 col-sm-12 hidden-sm hidden-xs side-bar">
   <?php get_template_part('right-sidebar'); ?>
   </div>
<?php if ($data['show_most_viewed'] == 1) { ?>
<!-- begin most viewed -->
<div class="col-lg-9 col-md-9 col-sm-12 rcon">
   <div class="product">
      <div class="row prod-name">
         <div class="col-lg-9 col-md-9 col-sm-9 col-lg-12">
            <h4 class="post-title"><span class="fa fa-shopping-bag"></span>محصولات پربازدید</h4>
         </div>
         <div class="col-lg-3 col-md-3 col-sm-3 hidden-xs">
            <!-- Controls -->
            <div class="controls pull-left">
               <a class="left fa fa-chevron-right btn btn-success btn-sm" href="#carousel-example"
                  data-slide="prev"></a><a class="right fa fa-chevron-left btn btn-success btn-sm" href="#carousel-example"
                  data-slide="next"></a>
            </div>
         </div>
      </div>
      <div id="carousel-example" class="carousel slide" data-ride="carousel">
         <!-- Wrapper for slides -->
         <div class="carousel-inner">
            <?php
               $popularpost = new WP_Query( array(
               'posts_per_page' => 8,
               'post_type' => 'download',
               'post_status' => 'publish',
               'meta_key' => 'post_views_count',
               'orderby' => 'meta_value',
               'order' => 'DESC'  ) );
               $i = 0;
               while ( $popularpost->have_posts() ) : $popularpost->the_post();
               if($i == 0){echo '<div class="item active">
                           <div class="row">';}
               elseif ($i == 4) {echo '<div class="item">
                          <div class="row">';}
               ?>
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 rcol">
               <div class="r-box r-box-view">
                  <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                     <div class="figure">
                        <?php if ( has_post_thumbnail()) :  ?>
                        <?php the_post_thumbnail('thumbnail');?>
                        <?php else: ?>
                        <img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/tumb.png" class="post-tumb" />
                        <?php endif; ?>
                        <div class="figcaption">
                           <?php the_title(); ?>
                           <div class="figprice"><?php if(edd_is_free_download(get_the_ID()) && $data['free_price'] == 1) { 
                                echo 'رایگان';
                           } else {edd_price(get_the_ID());}
                              ?></div>
                        </div>
                     </div>
                  </a>
               </div>
            </div>
            <?php
               $i++;
               if($i == 4){echo '</div>
                                 </div>';}
                     endwhile;
               if($i < 4 && $i != 0 || $i > 4 && $i <= 8 ){echo '</div>
                                 </div>';}
                     // Reset Post Data
                     wp_reset_postdata();
                     ?>
         </div>
      </div>
   </div>
</div>
<!-- end most viewed -->
<?php } ?>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12 pcol">
   <?php if ( $products->have_posts() ) : $i = 1; ?>
   <?php while ( $products->have_posts() ) : $products->the_post(); ?>
   <?php if ($data['view_type'] == 1) { ?>
   <div role="main" class="col-lg-6 col-md-6 col-sm-6 col-xs-12 pcon" id="post-<?php the_ID(); ?>">
      <div class="product">
         <div class="col-lg-4 col-md-5 col-sm-5 col-xs-12 prod-img fr-img">
            <?php if ( has_post_thumbnail()) :  ?>
            <a href="<?php the_permalink() ?>" class="vi-img-res-box"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
            <?php else: ?>
            <a href="<?php the_permalink() ?>" class="vi-img-res-box"><img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/tumb.png" class="post-tumb"/></a>
            <?php endif; ?>
         </div>
         <div class="col-lg-8 col-md-7 col-sm-7 col-xs-12 prod-det">
            <div class="row prod-name">
               <h2><?php the_title(); ?></h2>
            </div>
            <?php if(function_exists('edd_price')) { ?>
            <div class="row prod-price price">
               <i class="fa fa-database price-icon"></i>
                <?php if(edd_is_free_download(get_the_ID()) && $data['free_price'] == 1) { 
                                echo 'رایگان';
                           } else {edd_price(get_the_ID());}
                              ?>
            </div>
            <?php } ?>
            <div class="prod-links">
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                  <a href="<?php the_permalink() ?>" class="col-lg-11 col-md-11 col-sm-11 col-xs-12 btn btn-success btn-sm prod-btn">
                  <span class="fa fa-list"></span>&nbsp;&nbsp;توضیحات
                  </a>
               </div>
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                  <?php if(function_exists('edd_price')) { 
                   if(edd_is_free_download($post->ID) && is_plugin_active( 'easy-digital-downloads-free-link/easy-digital-downloads-free-link.php' )) { ?> 
                     <a href="<?php the_permalink() ?>" class="edd_free_link button blue col-lg-11 col-md-11 col-sm-11 col-xs-12 btn btn-primary btn-sm">
                     <span class="download-label">دانلود</span>
                  </a>
                 <?php } else {
                  echo edd_get_purchase_link(get_the_ID(), 'Add', 'button');
                  } }?>
               </div>
            </div>
         </div>
      </div>
   </div>
   <?php } else { ?>
   <div role="main" class="col-lg-4 col-md-4 col-sm-4 col-xs-12 pcon" id="post-<?php the_ID(); ?>">
      <div class="product">
         <div class="col-xs-12 prod-img fr-img">
            <?php if ( has_post_thumbnail()) :  ?>
            <a href="<?php the_permalink() ?>" class="vi-img-res-box"><?php the_post_thumbnail( 'single-download' ); ?>
            <?php else: ?>
            <a href="<?php the_permalink() ?>" class="vi-img-res-box"><img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/tumb.png" class="post-tumb"/>
            <?php endif; ?>
            <?php if(function_exists('edd_price')) { ?>
            <div class="row prod-price price pt-price">
               <i class="fa fa-database price-icon"></i>
               <?php if(edd_is_free_download(get_the_ID()) && $data['free_price'] == 1) { 
                                echo 'رایگان';
                           } else {edd_price(get_the_ID());}
                              ?>
            </div>
            <?php } ?>
            </a>
         </div>
         <div class="col-xs-12 prod-det">
            <div class="col-xs-10 prod-name pt-name">
               <h2 title="<?php the_title(); ?>"><?php the_title(); ?></h2>
            </div>
            <div class="col-xs-12 prod-links pt-link">
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                  <a href="<?php the_permalink() ?>" class="col-lg-11 col-md-11 col-sm-11 col-xs-12 btn btn-success btn-sm prod-btn">
                  <span class="fa fa-list"></span>&nbsp;&nbsp;توضیحات
                  </a>
               </div>
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                  <?php if(function_exists('edd_price')) { 
                   if(edd_is_free_download($post->ID) && is_plugin_active( 'easy-digital-downloads-free-link/easy-digital-downloads-free-link.php' )) { ?> 
                     <a href="<?php the_permalink() ?>" class="edd_free_link button blue col-lg-11 col-md-11 col-sm-11 col-xs-12 btn btn-primary btn-sm">
                     <span class="download-label">دانلود</span>
                  </a>
                 <?php } else {
                  echo edd_get_purchase_link(get_the_ID(), 'Add', 'button');
                  } }?>
               </div>
            </div>
         </div>
      </div>
   </div>
   <?php } ?>
   <?php $i+=1; ?>
   <?php endwhile; ?>
   <div class="col-lg-12 pagination">
      <?php wp_product_pagination(); ?>
   </div>
   <?php else : ?>
   <div class="col-lg-12">
      <div class="alert alert-warning alert-dismissible anote"><strong><span class="fa fa-bell" aria-hidden="true">
         </span> فایلی پیدا نشد.</strong>
      </div>
   </div>
   <?php endif; ?>

<?php if ($data['show_main_blog'] == 1 && is_front_page()) { ?>
<div class="col-lg-12 col-md-12 col-sm-12 rcon">
         <div class="row block-name">
            <h4 class="block-title"><span class="fa fa-file-text-o"></span><?php echo $data['main_blog_title']; ?></h4>
         </div>
</div>
   <?php $normalpost = new WP_Query( array(
               'posts_per_page' => $data['main_blog_count'],
               'post_type' => 'post',
               'post_status' => 'publish',
               'cat' => $data['main_blog_cat']) );
    if ( have_posts() ) : ?>
   <?php while ( $normalpost->have_posts() ) : $normalpost->the_post(); ?>
   <?php if ($data['view_type'] == 1) { ?>
   <div role="main" class="col-lg-6 col-md-6 col-sm-6 col-xs-12 pcon" id="post-<?php the_ID(); ?>">
      <div class="product">
        <div class="col-lg-4 col-md-5 col-sm-5 col-xs-12 prod-img fr-img">
            <?php if ( has_post_thumbnail()) :  ?>
            <a href="<?php the_permalink() ?>" class="vi-img-res-box post-img"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
            <?php else: ?>
            <a href="<?php the_permalink() ?>" class="vi-img-res-box post-img"><img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/tumb.png" class="post-tumb"/></a>
            <?php endif; ?>
         </div>
         <div class="col-lg-8 col-md-7 col-sm-7 col-xs-12 prod-det">
            <div class="row post-name">
               <h2><?php the_title(); ?></h2>
            </div>
            <div class="row excerpt"><?php the_excerpt(); ?></div>
            <div class="post-links">
               <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                  <a href="<?php the_permalink() ?>" class="col-lg-6 col-md-7 col-sm-7 col-xs-12 pull-left btn btn-primary btn-sm prod-btn">
                  <span class="fa fa-list"></span>&nbsp;&nbsp;&nbsp;ادامه مطلب
                  </a>
               </div>
            </div>
         </div>
      </div>
   </div>
   <?php } else { ?>
   <div role="main" class="col-lg-4 col-md-4 col-sm-4 col-xs-12 pcon" id="post-<?php the_ID(); ?>">
      <div class="product">
         <div class="col-xs-12 prod-img fr-img">
            <?php if ( has_post_thumbnail()) :  ?>
            <a href="<?php the_permalink() ?>" class="vi-img-res-box post-img"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
            <?php else: ?>
            <a href="<?php the_permalink() ?>" class="vi-img-res-box post-img"><img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/tumb.png" class="post-tumb"/></a>
            <?php endif; ?>
         </div>
         <div class="col-xs-12">
            <div class="col-xs-10 post-name pt-name">
               <h2 title="<?php the_title(); ?>"><?php the_title(); ?></h2>
            </div>
            <div class="prod-links col-xs-12">
               <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                  <a href="<?php the_permalink() ?>" class="col-lg-6 col-md-7 col-sm-7 col-xs-12 pull-left btn btn-primary btn-sm prod-btn">
                  <span class="fa fa-list"></span>&nbsp;&nbsp;&nbsp;ادامه مطلب
                  </a>
               </div>
            </div>
         </div>
      </div>
   </div>
   <?php } ?>
   <?php endwhile; ?>
   <?php else : ?>
   <div class="col-lg-12">
      <div class="alert alert-warning alert-dismissible anote" role="alert">
         <strong><span class="fa fa-bell" aria-hidden="true">
         </span> نوشته ای پیدا نشد.</strong>
      </div>
   </div>
   <?php endif; ?>
<?php } ?>

<?php if ($data['show_main_page'] == 1 && is_front_page()) { ?>
   <div class="col-lg-12 col-md-12 col-sm-12 rcon">
      <div class="product">
         <div class="row prod-name">
            <h4 class="post-title"><span class="fa fa-file-text-o"></span><?php echo $data['main_title']; ?></h4>
         </div>
         <div class="main-page">
            <?php echo $data['main_text']; ?>
         </div>
      </div>
   </div>
   <?php } ?>

</div>
</div>
<?php if ($data['show_side_mobile'] == 1) { ?>
 <div role="complementary" class="col-lg-3 col-md-3 col-sm-12 visible-sm visible-xs side-bar">
   <?php get_template_part('right-sidebar'); ?>
 </div>
 <?php } ?>
</div>
<?php get_footer(); ?>