<?php
/* 
* Theme: PREMIUMPRESS CORE FRAMEWORK FILE
* Url: www.premiumpress.com
* Author: Mark Fail
*
* THIS FILE WILL BE UPDATED WITH EVERY UPDATE
* IF YOU WANT TO MODIFY THIS FILE, CREATE A CHILD THEME
*
* http://codex.wordpress.org/Child_Themes
*/
if (!defined('THEME_VERSION')) {	header('HTTP/1.0 403 Forbidden'); exit; }

global $post, $CORE_UI, $userdata, $CORE, $settings;

   // ADMIN PREVIEW
    if(!isset($post->ID)){
		$post = new stdClass();
		$post->ID 			= 1;
		$post->post_title 	= "This is a sample title."; 
		$post->post_author 	= 1; 
		$post->post_excerpt = "";
		$post->post_content = "";
		$post->comment_count = 0;
		$post->thistheme = THEME_KEY;
		
		$post->showupgrades = 1;
	} 

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

	
	$title = $post->post_title;
	$store_image = "";
	$link = "#";
	$store_id = "";
	$name = "";
	$used = do_shortcode('[USED]');
  $hits = do_shortcode('[HITS]');  
  

  $up 	        = get_post_meta($post->ID, 'ratingup', true);
	$down 	      = get_post_meta($post->ID, 'ratingdown', true);
  $rating_total = get_post_meta($post->ID, 'rating_total', true);
 
 
	if(!is_numeric($used)){ $used = 0; }
	
	$found 	= wp_get_object_terms( $post->ID, 'store' );
	if(is_array($found) && !empty($found)){
		$link = get_term_link($found[0]->term_id, "store");	 
		$name = strip_tags(do_shortcode('[STORENAME]')); 		
		$store_image = do_shortcode('[STOREIMAGE sid='.$found[0]->term_id.']');		
		$store_id = $found[0]->term_id;

	}elseif( _ppt(array('lst', 'cppop')) == "1" ){ // next link goes to the actual listing page

    $link = get_permalink($post->ID)."?__sid=".$post->ID;
 
  } 

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

$show_qr = 0;
if(in_array(_ppt(array('searchcardvals','qr')),array("","1"))){
$show_qr = 1;
}

$show_comments = 0;
if(in_array(_ppt(array('searchcardvals','comments')),array("","1"))){
$show_comments = 1;
}

$show_views = 0;
if(in_array(_ppt(array('searchcardvals','views')),array("","1"))){
$show_views = 1;
}

$desc = do_shortcode("[EXCERPT limit=140]");
if(defined('WLT_DEMOMODE')){

$desc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus eleifend risus ut congue. Pellentesque nec lacus elit. Pellentesque"; 

}

	if(defined('WLT_DEMOMODE') && $store_image == ""){
		if(isset($_SESSION['design_preview'])){
			$store_image = DEMO_IMGS."?fw=text160&i=".rand(1,8)."&t=".THEME_KEY."&ct=".$_SESSION['design_preview'];
		}
	}

  // EXPIRY DISPLAY 
  $listdate = get_post_meta($post->ID,"listing_expiry_date",true);
  if($listdate !=""){
  $vv = $CORE->date_timediff($listdate);
  }

  
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

?>

<div ppt-box class="<?php if( $post->featured ){ ?>overflow-hidden <?php } ?>hide-mobile rounded mb-4 pid<?php echo $post->ID; ?>" data-pid='%postid%'>

 
  <div class="_content p-0 p-3 p-lg-4 py-4">

  <?php if( $post->featured ){ ?> 

    <span class="featuredribbion bg-danger"> <i class="fa fa-star"> </i> </span>

 


<?php } ?>

    <div class="d-lg-flex justify-content-between">
      <div class="position-relative w-100 _left">
        <div class="d-sm-flex flex-sm-column">
          <div class="d-flex align-items-center"> 
           
            <a href="javascript:void(0);" class="btn-gocoupon mr-3" data-nextlink="<?php echo $link; ?>" data-store="1" data-couponid="<?php echo $store_id; ?>">
            <div style="height:40px; width:80px; min-width:80px;" class="store-icon-small">
              <div ppt-border1 class="h-100 position-relative">
                <div class="bg-image" data-bg="<?php echo $store_image; ?>">
                  &nbsp;
                </div>
              </div>
            </div>
            </a>
            
            
            <div class="fs-md text-600 cursor " <?php if(!isset($settings['accountpage'])){ ?> onclick="jQuery('.coupon-btn-<?php echo $post->ID; ?>').trigger('click');"<?php } ?>>
              
            <?php if(isset($settings['accountpage'])){ ?><a href="<?php echo get_edit_listing_link($post->ID); ?>" class="text-dark"> <?php } ?>
            <?php echo $title; ?> 
            </div>
            <?php if(isset($settings['accountpage'])){ ?></a><?php } ?>
            
          </div>
          <div>
            <div class="fs-14 mt-3 pr-lg-4 opacity-5">
              <?php echo $desc; ?> <?php if(strlen($desc) > 10){ ?><a href="javascript:void(0);" onclick="processTerms('<?php echo $post->ID; ?>');">...</a><?php } ?>

              <?php if(function_exists('current_user_can') && current_user_can('administrator') ){ ?>
<span class="opacity-5"> <a target="_blank" href="<?php echo home_url(); ?>/wp-admin/admin.php?page=listings&eid=<?php echo $post->ID; ?>"><span class="fa fa-pencil"> <span></a></span>
<?php } ?>
            </div>
          </div>
        </div>
      </div>
      <div class="_right w-100 y-middle" style="min-width:250px;max-width:250px;">
        <div class="w-100 text-center">
          <div class=" fs-14 mb-3 <?php if($used > 0){ ?>d-inline-flex<?php } ?>">
            <div class="d-inline-flex verified text-success text-600">
              <div ppt-icon-16 data-ppt-icon-size="16">
                <?php echo $CORE_UI->icons_svg['check_circle']; ?>
              </div>
              <div class="ml-2">
                <?php echo __("Verified","premiumpress"); ?>
              </div>
            </div>
            <?php if($used > 0){ ?>
            <div>
              <div class="dot-sm mx-2">
                &nbsp;
              </div>
            </div>
            <div class="d-flex">
              <div ppt-icon-16 data-ppt-icon-size="16">
                <?php echo $CORE_UI->icons_svg['user']; ?>
              </div>
              <div class="ml-2">
                <span class="text-600"><?php echo $used; ?></span> <?php echo __("uses today","premiumpress"); ?>
              </div>
            </div>
            <?php } ?>
          </div>
          <?php echo do_shortcode('[CBUTTON]'); ?>
        </div>
      </div>
    </div>
  </div>
  <div class="_footer small  pl-3 pl-lg-4 fs-sm bg-light">
  
 
<div class="d-flex w-100">

<div>

<?php if(isset($settings['accountpage'])){ ?>
  <div>
  <a href="javascript:void(0);" onclick="ajax_delete_listing<?php echo $post->ID; ?>();" class="btn-danger btn-sm" data-ppt-btn="">

<span><?php echo __("Delete","premiumpress"); ?></span>

</a>
<script>
     function ajax_delete_listing<?php echo $post->ID; ?>(){
   
   if(confirm("<?php echo trim(__("Are you sure?","premiumpress")); ?>")){
   
       jQuery.ajax({
           type: "POST",
           url: '<?php echo home_url(); ?>/',	
   		dataType: 'json',	
   		data: {
               action: "listing_delete",
   			pid: <?php echo $post->ID; ?>,
           },
           success: function(response) {			
   			if(response.status == "ok"){	
   							
   	 
          jQuery('.pid<?php echo $post->ID; ?>').hide();
           
     		 	
   			}else{			
   				jQuery('#ajax_response_msg').html("error trying to delete");			
   			}			
           },
           error: function(e) {
               console.log(e)
           }
       });
   }// end are you sure
   
   }
</script>

</div>
  <?php }elseif($show_qr){ if(strlen($link) > 2){ ?>
<div class="badge_tooltip text-center" data-direction="top">
  <div class="badge_tooltip__initiator">
    <div ppt-icon-24 data-ppt-icon-size="24" style="cursor:pointer" class="qr-hover mr-3" data-qr-img="qrcode-image-%postid%" data-qr-link="<?php echo $link; ?>">
      <?php echo $CORE_UI->icons_svg['qr']; ?>
    </div>
  </div>
  <div class="badge_tooltip__item z-10">
    <div class="qrcode-image-%postid%">
    </div>
    <div class="fs-sm">
      <?php echo __("Scan QR code to view on mobile device.","premiumpress"); ?>
    </div>
  </div>
</div>
<?php } } ?>  

</div>


<div class="d-md-flex w-100 justify-content-between">

<div>

<?php if($show_views){ ?>
<span class="opacity-5"> <?php echo number_format($hits); ?> <?php echo __("Views","premiumpress"); ?> </span>
<?php } ?>

<?php if($show_comments){ ?>
<span class="opacity-5" onclick="showcomments(<?php echo $post->ID; ?>);" style="cursor:pointer"> &#8226; <?php echo $post->comment_count; ?> <?php echo __("Comments","premiumpress"); ?> </span>
<?php } ?>

<?php if($rating_total > 0){ ?>
<span class="opacity-5"> &#8226; <?php echo do_shortcode('[SUCCESSRATE]'); ?>% <?php echo __("success","premiumpress"); ?> </span>
<?php } ?>

<?php
	if(THEME_KEY == "cp" &&  _ppt(array('cashback', 'enable' )) == '1' && ( get_post_meta($post->ID, 'cashback',true) != "" || get_post_meta($post->ID, 'cashback_p',true) != ""   ) ){
	 
	?>
    
    <span class="opacity-5"> &#8226;
   
    <?php echo __("Cashback","premiumpress"); ?>: <?php if(!in_array(get_post_meta($post->ID, 'cashback',true),array("","0"))){ echo hook_currency_symbol('')."".get_post_meta($post->ID, 'cashback',true); } ?> 
	
	<?php if(!in_array(get_post_meta($post->ID, 'cashback_p',true),array("","0"))){ echo get_post_meta($post->ID, 'cashback_p',true); ?>% <?php } ?>
  
  </span>
    
    <?php } ?>
 


<?php 

$useddate = get_post_meta($post->ID,'lastused',true);			
if(!isset($GLOBALS['flag-single']) &&  $useddate != "" &&  ( strtotime(date("Y-m-d H:i:s", strtotime($useddate) ))  >  strtotime(date("Y-m-d H:i:s", strtotime( current_time( 'mysql' ) . " -1 day")))  )			
){ $da = $CORE->date_timediff($useddate,''); ?>
<span class="text-danger hide-ipad"><span class="fa fa-fire ml-2 mr-1"></span> <?php echo str_replace("%s",  $da['string-small'], __("last used %s","premiumpress")); ?> </span>
<?php } ?>



</div>

  
<div class="position-relative fs-6"><?php _ppt_template( 'cards/search_badges' ); ?></div> 

     
      
      <div class="text-muted y-middle">


      

        <?php if($listdate != "" && ( isset($vv['days-left']) && $vv['days-left'] < 60 && isset($vv['expired']) && $vv['expired'] == 0) ){ 
          ?>
          <span class="<?php if($vv['days-left'] < 4){ ?>text-danger text-600<?php } ?>">
                      <?php echo str_replace("%s", strtolower($vv['string']),__("Expires in %s","premiumpress")); ?> 
                      </span>


          <?php }elseif(isset($vv['expired']) && $vv['expired'] == 1){ ?>

        <span class="badge badge-danger p-2"><?php echo __("Expired","premiumpress"); ?></span>

       <?php  } ?>
        
         
      </div>
      
    </div>
</div> 
   

    
  </div>
</div> 

<div class="show-mobile">
  <div class="d-flex position-relative mb-3 border-bottom pb-3">
    <div class="w-100">

      <div class="fs-5 lh-30 text-700 cursor"  onclick="jQuery('.coupon-btn-<?php echo $post->ID; ?>').trigger('click');">
        <?php echo $title; ?>
      </div>

      <div class="d-flex mt-2 fs-sm align-items-center justify-content-between">
       
      <div>
      <?php if(is_array($found) && !empty($found)){ ?>
        <a href="javascript:void(0);" class="btn-gocoupon" data-nextlink="<?php echo $link; ?>" data-store="1" data-couponid="<?php echo $found[0]->term_id; ?>">
        <div style="height:25px; width:50px; min-width:50px;" class="store-icon-small  mr-3">
          <div ppt-border1 class="h-100 position-relative">
            <div class="bg-image" data-bg="<?php echo $store_image; ?>">
              &nbsp;
            </div> 
          </div>
        </div>
        </a>
        <?php }else{ ?>
       
          <div class="d-inline-flex verified text-success text-600 mr-2">
            <div ppt-icon-16 data-ppt-icon-size="16">
              <?php echo $CORE_UI->icons_svg['check_circle']; ?>
            </div>
            <div class="ml-1">
              <?php echo __("Verified","premiumpress"); ?>
            </div>
          </div>
       
        <?php } ?>
        </div>

        <div>
          

          <?php if(is_array($found) && !empty($found)){ ?>
          <div class="d-inline-flex verified text-success text-600 mr-2">
            <div ppt-icon-16 data-ppt-icon-size="16">
              <?php echo $CORE_UI->icons_svg['check_circle']; ?>
            </div>
            <div class="ml-1">
              <?php echo __("Verified","premiumpress"); ?>
            </div>
          </div>
          <?php } ?>

          <span class="btn-block"><?php echo do_shortcode('[TIMELEFT textonly=1]'); ?></span>
       

        </div>

        <div>
        <?php echo str_replace("btn-ppt-coupon","btn-ppt-coupon btn-xs",do_shortcode('[CBUTTON]')); ?>
      </div>

      
    </div>


  </div>
</div>
</div>
