<?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
*/
 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>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
   <?php if ( have_posts() ) : ?>
   <?php while ( have_posts() ) : the_post(); ?>
   <div role="main" class="col-lg-12 col-md-12 col-sm-12 col-xs-12 scon" id="post-<?php the_ID(); ?>">
      <div class="product">
         <div class="row post-row">
            <h2 class="post-title"><span class="fa fa-pencil-square-o" style="width:25px"></span>
               <?php the_title(); ?>
            </h2>
         </div>
         <div class="col-lg-4 col-md-5 col-sm-5 col-xs-12 prod-img si-img">
            <div class="sp-loading"><img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/sp-loading.gif" alt=""><br>در حال بارگذاری</div>
            <div class="sp-wrap">
               <?php if ( has_post_thumbnail()) :  ?>
               <a href="<?php the_post_thumbnail_url( 'full' ); ?>">
               <img src="<?php the_post_thumbnail_url( 'single-download' ); ?>" class="post-tumb" alt="<?php the_title_attribute(); ?>"/>
               </a>
               <?php else: ?>
               <a href="<?php echo esc_url( get_template_directory_uri() ); ?>/images/tumb.png">
               <img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/tumb.png" class="post-tumb" alt="<?php the_title_attribute(); ?>"/>
               </a>
               <?php endif; 
                  $images = ( function_exists('edd_di_get_images') ) ? edd_di_get_images() : '';
                          if ( $images ) {
                              foreach ( $images as $image ) {                                    
                                 $att_id = get_attachment_id_from_src( $image['image'] );
                                  $html = ' <a href="' . wp_get_attachment_image_url($att_id, 'full') . '">
                                      <img src="' . wp_get_attachment_image_url($att_id, 'single-download') . '" alt="'.get_post_meta($att_id, '_wp_attachment_image_alt', true).'" /></a>';
                                  echo $html;
                              }
                          }?>
            </div>
         </div>
         <div class="col-lg-8 col-md-7 col-sm-7 col-xs-12 prod-det">
            <div class="row prod-row">
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 prod-col">
                  <div class="attr">
                     <span class="fa fa-calendar picon"></span>
                  </div>
                  <div class="attr-value">
                     <span><?php echo get_the_date('j F Y'); ?></span>
                  </div>
               </div>
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 prod-col">
                  <div class="attr">
                     <span class="fa fa-file-text-o picon"></span>
                  </div>
                  <div class="attr-value">
                     <span><?php echo get_post_meta($post->ID, "download_file_type", true); ?></span>
                  </div>
               </div>
            </div>
            <div class="row prod-row">
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 prod-col">
                  <div class="attr">
                     <span class="fa fa-floppy-o picon"></span>
                  </div>
                  <div class="attr-value">
                     <span><?php echo get_post_meta($post->ID, "download_file_size", true); ?></span>
                  </div>
               </div>
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 prod-col">
                  <div class="attr">
                     <span class="fa fa-files-o picon">
                  </div>
                  <div class="attr-value">
                     <span><?php echo get_post_meta($post->ID, "download_page_count", true); ?></span>
                  </div>
               </div>
            </div>
            <div class="row prod-row">
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 prod-col">
                  <div class="attr">
                     <span class="fa fa-folder-open-o picon"></span>
                  </div>
                  <div class="attr-value">
                     <span><?php the_terms( $post->ID, 'download_category', '', '، ', '' ); ?></span>
                  </div>
               </div>
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 prod-col">
                  <div class="attr">
                     <span class="fa fa-eye picon"></span>
                  </div>
                  <div class="attr-value">
                     <span><?php setPostViews(get_the_ID()); ?><?php echo getPostViews(get_the_ID()); ?></span>
                  </div>
               </div>
            </div>
            <?php if(edd_is_free_download(get_the_ID()) && $data['free_price'] == 1) { ?>
                           <div class="row prod-add sprice">رایگان</div>
                           <?php } else { ?>
                           <div class="row prod-add sprice"> <?php edd_price($post->ID); ?></div>
                           <?php } ?>
            <div class="row prod-add">
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 add-col">
                  <?php 
                     function edd_texts_args( $args ) {
                             $args['class'] = 'btn btn-success';
                         return $args;
                     }
                     add_filter( 'edd_purchase_link_args', 'edd_texts_args' );
                     if(function_exists('edd_price')) { ?>
                  <?php if(!edd_has_variable_prices(get_the_ID())) { ?>
                  <?php echo edd_get_purchase_link(get_the_ID(), 'Add', 'button');}} ?>
               </div>
               <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 add-col">
                  <?php
                     $preview_link = get_post_meta($post->ID, "download_preview_link", true);
                     if ($preview_link != '') {
                     ?>
                  <a href="<?php echo get_post_meta($post->ID, "download_preview_link", true); ?>" class="btn btn-warning">
                  <span class="fa fa-picture-o"></span>
                  <span>دانلود پیش نمایش</span>
                  </a>
                  <?php } ?>    
               </div>
            </div>
         </div>
         <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 down-con">
            <?php the_content();?>
            <?php if ($data['social_share'] == 1) { ?>
            <div class="alert alert-success share-box">
            <strong><span class="fa fa-bullhorn"></span>&nbsp;اشتراک گذاری در شبکه های اجتماعی، به دوستانتان معرفی کنید.</strong>
               <ul class="social">
                        <li><a aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="فیسبوک" href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>" target="_blank" class="fa fa-facebook"></a></li>
                        <li><a aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="گوگل پلاس" href="https://plus.google.com/share?url=<?php the_permalink(); ?>" target="_blank" class="fa fa-google-plus"></a></li>
                        <li><a aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="توئیتر" href="http://www.twitter.com/share?url=<?php the_permalink(); ?>" target="_blank" class="fa fa-twitter"></a></li>
                        <li><a aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="لینکداین" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink(); ?>" target="_blank" class="fa fa-linkedin"></a></li>
                        <li><a aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="کلوب" href="http://www.cloob.com/share/link/add?url=<?php the_permalink(); ?>" target="_blank" class="ico-cloob"></a></li>
                        <li><a aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="تلگرام" href="https://telegram.me/share/url?url=<?php the_permalink(); ?>" target="_blank" class="ico-telegram"></a></li>
               </ul>
            </div>
            <?php } ?>
            <?php if ($data['show_msg_help'] == 1) { ?>
            <div class="alert alert-info msg-help">
            <strong><span class="fa fa-info-circle"></span>&nbsp;راهنمای خرید:</strong>
               <?php echo $data['msg_help']; ?>
            </div>
            <?php } ?>
         </div>
         <?php if ($data['show_post_tags'] == 1) { ?>
         <div class="col-xs-12 p-tags">
            <p><?php the_terms( $post->ID, 'download_tag', '<span class="fa fa-tags"></span>&nbsp;برچسب ها:&nbsp;', '&nbsp;', '' ); ?></p>
         </div>
         <?php } ?>
      </div>
   </div>
   <?php if ($data['show_related'] == 1) { ?>
   <!-- begin custom related loop, isa -->
         <?php
            // arguments
            $custom_taxterms = wp_get_object_terms( $post->ID, $data['related_by'], array('fields' => 'ids') );
            $args = array(
            'post_type' => 'download',
            'post_status' => 'publish',
            'posts_per_page' => 4,
            'orderby' => 'rand',
            'tax_query' => array(
                array(
                    'taxonomy' => $data['related_by'],
                    'field' => 'id',
                    'terms' => $custom_taxterms
                )
            ),
            'post__not_in' => array ($post->ID),
            );
            $related_items = new WP_Query( $args );
            // loop over query
            if ($related_items->have_posts()) {
               ?>
             <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-shopping-bag" style="width:30px"></span>محصولات مشابه</h4>
         </div>
            <?php while ( $related_items->have_posts() ) : $related_items->the_post();
            ?>
         <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
            endwhile;
            // Reset Post Data
            wp_reset_postdata();
            ?>
      </div>
   </div>
   <!-- end custom related loop, isa --><?php }} ?>
   <?php endwhile; ?>
   <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 comments-list">
      <?php comments_template(); ?>
   </div>
   <?php endif; ?>
</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(); ?>