<?php







class core_comparison extends white_label_themes {






	function _metabox(){ 
		add_meta_box( 'cm_extrastore',  "Store" , array($this, '_storeextra' ), THEME_TAXONOMY.'_type', 'side', 'high' );
	}	
	function _storeextra(){ global $post;
	
		$eSID = get_post_meta($post->ID, 'storeID', true);
	
		$categories = get_terms( 'store', array(
		'orderby'    => 'count',
		'hide_empty' => 0,
		 ) );
		
		echo "<select name='wlt_field[storeID]'>";
		foreach($categories as $store){
		echo "<option value='". $store->term_id ."' ".selected( $eSID, $store->term_id ).">". $store->name ."</option>";	
		}
		echo "</select>";
	
	}

	function __construct(){	 
	
		if(is_admin()){		 
  			
			
			add_action('admin_menu', array($this, '_metabox' ) );
			 
			add_action('hook_admin_1_pagesetup', array($this, '_hook_admin_1_pagesetup'  ) ); 
			
			// HOOK INTO THE EDIT PAGE AND ADD-ON STORE FIELDS
			add_action('hook_fieldlist_0', array($this, '_extra_fields' ) );
			// SAVE POST DATA
			add_action('save_post',  array( $this,'_save_post' ));	
		}
	  
	  	// COMPARED PRODUCTS POST TYPE		
		register_post_type( 'cproduct_type', 
			array(			
			'hierarchical' => true,	
			  'labels' 		=> array('name' => 'Compared Products'),
			  'public' 		=> false,
			  'query_var' 	=> true,
			  'show_ui' 	=> true,	
			  'menu_icon' 	=> get_template_directory_uri()."/framework/admin/img/icons/box.png", 		   
			  'rewrite' 	=> array('slug' => 'cproduct'),
			  'supports' 	=> array ( 'title', 'editor','author', 'post-formats', 'comments','excerpt', 'thumbnail', 'custom-fields', 'publicize', 'wpcom-markdown' ),			 
			
			) );	
		register_taxonomy( 'store', 'cproduct_type', array( 'hierarchical' => true, 'labels' => array('name' => 'Stores') , 'query_var' => true, 'rewrite' => true, 'rewrite' => array('slug' => 'store') ) );  
		 
		
		// MAMAGEMEN
		add_action( 'manage_cproduct_type_posts_custom_column', array( $this, '_admin_custom_column' ), 10, 2 );	
		add_filter( 'manage_cproduct_type_posts_columns', array( $this, '_admin_custom_columns' ), 10, 2 );	
		
		// ACTIVATED SHORTCODES	
		add_shortcode( 'STORE', array($this,'wlt_shortcode_store') );
		add_shortcode( 'COMPARISONTABLE', array($this,'wlt_shortcode_comparison_table') );
   	
		// ADD FIELDS TO SUBMISSION FORM
		add_action('hook_add_fieldlist',  array($this, '_hook_customfields' ) );
		
		// HOOK FIELD SWITCH TO INCLUDE CUSTOM TYPE
		add_action('hook_core_fields_switch', array($this, '_hook_core_fields_switch' ) );
	 
	 
		add_action('admin_menu', array($this, '_custom_metabox' ) );
		add_action( 'admin_head', array($this, '_admin_extra_css' ) );
	 	 
		 
		// STORES PAGE
		add_action( "pre_get_posts", array($this, "_pre_get_posts" ));
 
	}
	 	

// STORES PAGE QUERY FIX
function _query_where($q){ global $wpdb;
	$q = str_replace("$wpdb->term_relationships.term_taxonomy_id IN","$wpdb->postmeta.meta_value = ",$q);
	return $q;
}
function _pre_get_posts( $query ) {
 
	if($query->is_archive() && is_tax('store') ){
	
	//  ADJUST WHERE QUERY
 	add_filter('posts_where',  array($this, '_query_where' ) ); 
	
	// SET RELATIONSHIP AND QUERY
	set_query_var( 'meta_key', 'storeID' );
  
	} 
 
   return $query;
}







function _admin_extra_css(){
 
	if($_GET['post_type'] == 'cproduct_type' ){
		echo '<style type="text/css">';
		echo '.wlt_thumbnail { max-width:100px; max-height:80px; }';
		echo '.column-price { width:100px; text-align:center !important; border-right:1px solid #ddd !important; }';
		echo '</style>';
	}
}
function _admin_custom_column($column_name, $post_id) {
 
	global $wpdb, $CORE, $post; 

	switch($column_name){
	
		case "store": {
		
		// GET THE STORE
		$stores = get_the_term_list($post_id, 'store', '', ', ', '' );	
		echo $stores;
		
		} break;
	
		case "price": {
			$p = get_post_meta($post_id,"price",true);
			if($p == ""){
			echo "not set";
			}else{
			echo hook_price($p);
			}
		} break;
		
		case "image": {
			$img = hook_image_display(get_the_post_thumbnail($post_id, array(100,80), array('class'=> "img-polaroid")));
			if($img == ""){
				$img = hook_fallback_image_display($CORE->FALLBACK_IMAGE($post_id)); 
			}
			if($img != ""){			 
			echo "<a href='post.php?post=".$post_id."&action=edit'>".$img."</a>";
			} 
			 
		} break;
	
	}
	
}
function _admin_custom_columns($defaults) {
 
	global $wpdb, $CORE, $post; 

	$defaults['price'] 		= 'Price';
	$defaults['title'] 		= 'Title';	
	$defaults['date'] 		= 'Date';
	$defaults['store'] 		= 'Store';
	$defaults['image'] 		= 'Image';
	return $defaults;
}
 
	
	function _custom_metabox(){ 	
	// LISTING DATA META BOX
	add_meta_box( 'wlt_cproductdata', "Product Information", array($this, '_cproduct_details' ), 'cproduct_type', 'normal', 'high' ); 	
	}
	
	function _cproduct_details(){ global $post, $CORE; 
	
	?>
    
    <table style="width:100%;" border="0">
    
 
    
  <tr>
    <td>Product Price:</td>
    <td>
    <input type="text" name="wlt_field[price]"  value="<?php echo get_post_meta($post->ID,'price',true); ?>" style="width:80px;">
    </td>
  </tr>
  
  
  <tr>
    <td>Store/ Buy Link:</td>
    <td>
    <input type="text" name="wlt_field[buy_link]"  value="<?php echo get_post_meta($post->ID,'buy_link',true); ?>" style="width:400px;">
    </td>
  </tr>
  
 
</table>
 
     
     <?php  
    
    }
	
	
 
	
	//  HOOK INTO THE ADMIN MENU TO CREATE A NEW TAB
	function _hook_admin_1_pagesetup(){  global $wpdb, $CORE; $core_admin_values = get_option("core_admin_values");  ?>
	
	<div class="accordion-group">
    <div class="accordion-heading" style="background:#fff;">
        <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#pagesetup_according" href="#extra1">
         <h4 style="margin:0xp;font-weight:bold;">
         <img src="<?php echo get_template_directory_uri(); ?>/framework/admin/img/icons/set.png">
         Comparison Settings <span style="font-size:12px;">(view/hide)</span></h4> 
        </a>
    </div>
    
    <div id="extra1" class="accordion-body collapse">
    <div class="accordion-inner">
    <div class="innerwrap content">
    
    <div class="heading2">Comparison Matching Options</div>
    
    <p>Choose how you want the system to match products below;</p>
    
    
    <div class="row-fluid">
  
	
	 	 
		 <div class="form-row control-group row-fluid ">
                                <label class="control-label span7" data-placement="top">Exact Title Match</label>
                                <div class="controls span4">
                                  <div class="row-fluid">
                                    <div class="pull-left">
                                      <label class="radio off">
                                      <input type="radio" name="toggle" 
                                      value="off" onchange="document.getElementById('compare_title').value='0'">
                                      </label>
                                      <label class="radio on">
                                      <input type="radio" name="toggle"
                                      value="on" onchange="document.getElementById('compare_title').value='1'">
                                      </label>
                                      <div class="toggle <?php if($core_admin_values['compare_title'] == '1'){  ?>on<?php } ?>">
                                        <div class="yes">ON</div>
                                        <div class="switch"></div>
                                        <div class="no">OFF</div>
                                      </div>
                                    </div> 
                                   </div>
                                 </div>
                                 
                                 <input type="hidden" class="row-fluid" id="compare_title" name="admin_values[compare_title]" value="<?php echo $core_admin_values['compare_title']; ?>">
         </div> 
         
         <p>This option will try to match the title exactly with your compared products.</p>
         
         
         
		 <div class="form-row control-group row-fluid ">
                                <label class="control-label span7" data-placement="top">5 Character Match</label>
                                <div class="controls span4">
                                  <div class="row-fluid">
                                    <div class="pull-left">
                                      <label class="radio off">
                                      <input type="radio" name="toggle" 
                                      value="off" onchange="document.getElementById('compare_5char').value='0'">
                                      </label>
                                      <label class="radio on">
                                      <input type="radio" name="toggle"
                                      value="on" onchange="document.getElementById('compare_5char').value='1'">
                                      </label>
                                      <div class="toggle <?php if($core_admin_values['compare_5char'] == '1'){  ?>on<?php } ?>">
                                        <div class="yes">ON</div>
                                        <div class="switch"></div>
                                        <div class="no">OFF</div>
                                      </div>
                                    </div> 
                                   </div>
                                 </div>
                                 
                                 <input type="hidden" class="row-fluid" id="compare_5char" name="admin_values[compare_5char]" value="<?php echo $core_admin_values['compare_5char']; ?>">
         </div> 
         
         
         <p>This option will break down the title of the products and try to match any words with more than 5 characters.</p>
         
         
         <h4>Custom Field Match</h4>
         
         <p>This option lets you pick custom fields which will be used to match products.</p>
         
         <hr />
         
         <?php $i=0; while($i < 5){ 
		 
		 $meta_key = "";
		 if(isset($core_admin_values['compare_custom' . $i])){
			$meta_key = $core_admin_values['compare_custom' . $i];
		 }
		 ?>
         <div class="form-row control-group row-fluid ">
         <label class="control-label span7">Custom Field Match</label>
         <div class="controls span4">
             <div class="row-fluid">
             <select name="admin_values[compare_custom<?php echo $i; ?>]">
             <option></option>                
        	 <?php echo $CORE->CUSTOMFIELDLIST(esc_attr( $meta_key )); ?>    
             </select>                   
             </div>
         </div>
         </div>
         <?php $i++; } ?>
         
     
     </div></div>
     
     
     </div></div></div>
     
     <?php }
	
	// ADD A FLAG IF THE RELATED TOO FEATURE IS SET
	function _save_post(){
	
		global $wpdb, $post, $CORE;
 		
		// EXTRA FOR CUSTOM POST TYPE
		if(isset($_POST['post_type']) && ( $_POST['post_type'] == "cproduct_type"  ) && isset($_POST['wlt_field']) && !empty($_POST['wlt_field']) ){
			// SAVE CUSTOM META DATA
			foreach($_POST['wlt_field'] as $key=>$val){
				update_post_meta($post->ID,$key,$val);	
			}
		}
	
	}
	
 
	
 	function _hook_core_fields_switch($field){ global $CORE, $wpdb; $STRING = "";  $options = "";
	  
		if($field['type'] == "multi-product-select"){
		
			if(isset($_GET['eid'])){ $options = get_post_meta($_GET['eid'],$field['name'],true); }
				 
				$STRING .='<link rel="stylesheet" type="text/css" href="'.THEME_URI.'/framework/css/css.autocomplete.css" />
				<script type="text/javascript" src="'.THEME_URI.'/framework/js/jquery.autocomplete.js"></script>
				<script>
				jQuery(document).ready(function() { jQuery(\'#autocompleteme\').smartSuggest({ src: \''.get_home_url().'?boxid=reg_field_'.$field['name'].'&option=1\' }); });
				</script>    
				<input type="text" id="autocompleteme" style="width:300px;" placeholder="Enter product title or keyword.." /> ';
				 
						 
				$STRING .= '<select name="custom['.$field['name'].'][]" class="row-fluid" tabindex="'.$GLOBALS['TABORDER'].'" id="reg_field_'.$field['name'].'" multiple="multiple" style="width:100%;">';	
				
				if(is_array($options) && !empty($options)){				
					foreach($options as $val){
						$oldIds .= $val.",";
						$val = trim($val);
						if(strlen($val) > 0 && is_numeric($val)){
						 $STRING .= '<option value="'.$val.'" selected=selected>'.get_the_title($val).'</option>';	
						}				 
					}// end foreach
				}
					
				$STRING .= '<option value=""></option></select>';
				
				// KEEP OLD VALUES FOR SETTING THE FLAGS				
				$STRING .= '<input type="hidden" name="custom['.$field['name'].'_old]" value="'.$oldIds.'" />';
								
		}
		
		return $STRING;
	}
	
 

	
	function _hook_customfields($c){ global $CORE;
	
		$o = 50;
 				
		$c[$o]['title'] 	= "Price";
		$c[$o]['name'] 		= "price";
		$c[$o]['type'] 		= "price";
		$c[$o]['class'] 	= "form-control";
		$c[$o]['help'] 		= "Enter the price of your product here.";
		$o++;
		
		$c[$o]['title'] 	= "Website Link";
		$c[$o]['name'] 		= "buy_link";
		$c[$o]['type'] 		= "text";
		$c[$o]['class'] 	= "form-control";
		$c[$o]['help'] 		= "Enter the website link with more information about this product.";
		$o++;
 
		return $c;
	} 
	
	
 
	// HOOK INTO THE EDIT LISTING PAGE
	function _extra_fields($c){	
		$list1 = array ( 			
		"tab7" => array("tab" => true, "title" => "Comparison Settings"), 
			 
			"price" => array("label" => "Price", "desc" => "",  ),
			
			"buy_link" => array("label" => "Affiliate Link", "desc" => "",  ),
			 				
		); 	 
		
	return array_merge($c,$list1);
	}//
	
	function _get_product_titles(){ global $wpdb, $post;
		
		$products_array = array(); $ESTRING = "";
		
		// GET EXISTSING DATA
		if(isset($_GET['post'])){		
		$existing_data = get_post_meta($post->ID, 'related_to',true);
			if(is_array($existing_data) && !empty($existing_data)){
				$ESTRING .=  "WHERE ";
				foreach($existing_data as $k=>$gg){
				$ESTRING .= " ".$wpdb->posts.".ID = '".$gg."' OR";
				}
				$ESTRING = substr($ESTRING,0,-3);
			}
		}
		
		/*$SQL = "SELECT DISTINCT ".$wpdb->posts.".ID, ".$wpdb->posts.".post_title FROM ".$wpdb->posts." 
				INNER JOIN ".$wpdb->postmeta." 
				ON ( ".$wpdb->postmeta.".post_id = ".$wpdb->posts.".ID 
				AND ".$wpdb->posts.".post_status='publish' 
				AND ".$wpdb->posts.".post_type='cproducts_type' 
				AND ".$wpdb->posts.".ID != '".$_GET['post']."'  ) ".$ESTRING." LIMIT 0,100";
		*/	
		$SQL = "SELECT * FROM ".$wpdb->posts." WHERE ".$wpdb->posts.".post_type='cproduct_type'  ";
	 
		$rr = $wpdb->get_results($SQL);
		if(is_array($rr) && !empty($rr)){			
			foreach($rr as $kk){
				$products_array[$kk->ID] = $kk->post_title;			
			}
		}
				 
		 	 
		return $products_array;	
	}//
	
	function wlt_shortcode_store( $atts, $content = null ) {
	
			global $userdata, $CORE, $post, $shortcode_tags; $STRING = "";  $default_options = '';
		
			extract( shortcode_atts( array('text' => $default_options, 'post_id' => $post->ID  ), $atts ) );
			 
		 
			$store = "";
			$store_list = get_the_terms($post_id, "store" );
			if(is_array($store_list)){
				foreach($store_list as $st){
					$store .= "<span class='wlt_shortcode_store'><a href='".get_term_link($st->slug, "store")."'>".esc_attr($text)."".$st->name."</a></span>";
				}	
			return $store;
			}
	}	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
function COMPARISON($postID){ global $wpdb;

$found_identify = array(); 
$industry_identify = array('upc','mpn','isbn','ean');
// WE ALWAYS COMPARE ITEMS AGAINST INDUSTRY STANDARD IDENTIFIERS
foreach($industry_identify as $check){
	$vv = get_post_meta($postID, $check, true);
	if(strlen($vv) > 1){
		$found_identify[$check] = $vv;
	}
}

// GET LIST OF COMPARED TABLES
$compared_tables = get_option('wlt_comparedtables');
if(!is_array($compared_tables)){ $compared_tables = array(); }  

	// NOW LOOP THROUGH ALL COMPARED TABLES
	if(!empty($compared_tables) && !empty($found_identify)){
		foreach($compared_tables as $tablename){			
		
			// GET THE COLUMN NAMES
			$chkcol = mysql_query("SELECT * FROM `".$tablename."` LIMIT 1"); 
			if(!$chkcol){
			// should remove here
			continue;
			}
			$canContinue = false;
			$chcols = mysql_fetch_assoc($chkcol); 
			$sql = "SELECT * FROM ".$tablename." WHERE";		
			// NOW WE LOOP THROUGH ALL OF THE COMPARED VALUES (ISBN ETC)
			$industry_identify = array_merge($industry_identify,array('post_title'));
			//
			foreach($found_identify as $j => $jk){ if($jk == "" || strtolower($jk) == "none"){ continue; }
				if(array_key_exists($j,$chcols)){
				$sql .= " ".$j." =  '".$jk."' OR";
				$canContinue = true;
				}
			} // end foreach
			// NOW CHECK WE CAN CONTINUE
			if($canContinue){
			$sql = substr($sql,0,-2);
				// NOW RUN QUERY				
				$rr = $wpdb->get_results($sql, ARRAY_A);
				if(is_array($rr) && !empty($rr)){
					// SAVE AND STORE					
					$nn[] = $rr;					
				}// end if
			}// end if		
					
		} // end foreach
	}

// CHECK IF EMPTY, IF NOT CHECK FOR SIMILIAR ITEMS
if(!empty($found_identify)){
	$i=1; 
	
	foreach($found_identify as $j => $jk){ if($jk == ""){ continue; }
		$sql = "SELECT $wpdb->posts.ID FROM  $wpdb->posts";
		$sql .= " INNER JOIN $wpdb->postmeta AS wlt".$i." ON (  $wpdb->posts.ID = wlt".$i.".post_id AND wlt".$i.".meta_key = '".$j."' AND wlt".$i.".meta_value = '".$jk."' ) ";
		$sql .= "GROUP BY $wpdb->posts.ID";

		$rr = $wpdb->get_results($sql, ARRAY_A);
		if(is_array($rr) && !empty($rr)){			
			foreach($rr as $kk){
				$nn[] = $kk['ID'];
			}
		}
		$i++;
	}
 
	// RETURN
	return array_unique($nn);
}

return $nn;
}	
	
	
	
	
	
function wlt_shortcode_comparison_table(){ global $CORE, $post, $wpdb; $sql = ""; $foundproducts = array(); $setAnd = true;

// ADD ON THIS PRODUCT
$foundproducts[] = array( "ID" => $post->ID, "price" =>  get_post_meta($post->ID, 'price', true) );


$sql = "SELECT DISTINCT $wpdb->posts.ID FROM  $wpdb->posts ";

// CUSTOM FIELD MATCHING
$i=0; while($i < 5){		 

	if(isset($GLOBALS['CORE_THEME']['compare_custom' . $i]) && strlen($GLOBALS['CORE_THEME']['compare_custom' . $i]) > 1){ 
		
		$vv = get_post_meta($post->ID, $GLOBALS['CORE_THEME']['compare_custom' . $i], true);		
		
		if($vv != ""){   $setAnd = false;
	
		$sql .= "INNER JOIN $wpdb->postmeta AS t".$i." ON ($wpdb->posts.ID = t".$i.".post_id AND t".$i.".meta_key = '" . $GLOBALS['CORE_THEME']['compare_custom' . $i] . "' AND t".$i.".meta_value = '" . $vv . "' ) ";
		
		}
		
	}
	
	$i++;
		
}


//  BUILD QUERY
$sqlwhere.= " WHERE (";

// COMPARE BY 5 CHARACTERS
if(isset($GLOBALS['CORE_THEME']['compare_5char']) && $GLOBALS['CORE_THEME']['compare_5char'] == 1){ 
preg_match_all( "/[a-z0-9']{6,}/i", $post->post_title, $words );
if(is_array($words[0]) && !empty($words[0])){

	foreach($words[0] as $word){ $setAnd = false; 
		$sqlwhere .= "post_title LIKE ('%". $word ."%') OR ";
	}
}
}
 

// EXTACT TITLE MATCH
if(isset($GLOBALS['CORE_THEME']['compare_title']) && $GLOBALS['CORE_THEME']['compare_title'] == 1){ $setAnd = false;
	$sqlwhere .= "post_title LIKE ('%". $post->post_title ."%') OR ";
}

// CLEAN UP
$sqlwhere.= ")";
if($sqlwhere == " WHERE ()"){ $sqlwhere = "WHERE";  }else{ $sqlwhere = substr($sqlwhere, 0,-4)." )"; }
$sql .= $sqlwhere;

if(!$setAnd){ $sql .= " AND"; }

// COMPLETE
$sql .= " post_type ='cproduct_type' AND post_status = 'publish' LIMIT 30 ";

// DO THE SEARCH
$rr = $wpdb->get_results($sql, ARRAY_A);	
if(is_array($rr) && !empty($rr) ){			
	foreach($rr as $kk){			
	$foundproducts[] = array( "ID" => $kk['ID'], "price" =>  get_post_meta($kk['ID'], 'price', true) );

	}
}

//echo $sql;

if(array($foundproducts) && !empty($foundproducts) ){

// SORT THE ARRAY BY PRICE
$DATA = $CORE->multisort( $foundproducts , array('price') );	


ob_start();
?>
<div id="wlt_comparisontable">
<table class="table table-bordered table-striped">
      <colgroup>
        <col class="col-xs-2 hidden-xs">
       
        <col class="col-xs-7">
        <col class="col-xs-2">
        <col class="col-xs-1">
      </colgroup>
      <thead>
        <tr>
          <th class="hidden-xs "><?php echo $CORE->_e(array('checkout','49')); ?></th>
          <th class="hidden-xs"><?php echo $CORE->_e(array('checkout','1')); ?></th>
          <th class="text-center"><?php echo $CORE->_e(array('checkout','2')); ?></th>
          <th></th>
        </tr>
      </thead>
      <tbody>

<?php 
$STRING .= ob_get_clean(); 

$i=1;
foreach($DATA as $p){

ob_start();

// GET THE PRODUCT
$thisp = get_post($p['ID']);

// GET IMAGES
if($p['ID'] != $post->ID &&  has_post_thumbnail($p['ID']) ){
	$image = $CORE->GETIMAGE($p['ID']);
	if(strpos($image, "fallback") !== false){
	$image = "";
	}
}
 

// GET THE STORE
$store_name = "";
$store_img = "";
	
if($p['ID'] != $post->ID){
	$stores = get_the_terms($p['ID'], 'store');	

	if(isset($stores[0])){
	
		if(isset($GLOBALS['CORE_THEME']['category_icon_'.$stores[0]->term_id])){
			$store_img = "<img src='".$GLOBALS['CORE_THEME']['category_icon_'.$stores[0]->term_id]."' alt='".$stores[0]->name."' class='cstoreicon' >";
			if(isset($GLOBALS['CORE_THEME']['category_website_'.$stores[0]->term_id])){
			$store_img = "<a href='".$GLOBALS['CORE_THEME']['category_website_'.$stores[0]->term_id]."' rel='nofollow' target='_blank'>".$store_img."</a>";
			}
		}
		$store_name = "<div class='cstorename'>".$stores[0]->name."</div>";
	}
}else{

	// GET STORE ID FOR THIS POST
	$eSID = get_post_meta($post->ID, 'storeID', true); 

	if(is_numeric($eSID)){
		
		$thisStore = get_term_by( 'id', $eSID, 'store' );
		
		$store_name = "<div class='cstorename'>".$thisStore->name."</div>";
		if(isset($GLOBALS['CORE_THEME']['category_icon_'.$thisStore->term_id])){
			$store_img = "<img src='".$GLOBALS['CORE_THEME']['category_icon_'.$thisStore->term_id]."' alt='".$thisStore->name."' class='cstoreicon' >";
			if(isset($GLOBALS['CORE_THEME']['category_website_'.$thisStore->term_id])){
			$store_img = "<a href='".$GLOBALS['CORE_THEME']['category_website_'.$thisStore->term_id]."' rel='nofollow' target='_blank'>".$store_img."</a>";
			}
		}
	}
}

// AFFILIATE LINK
$link = home_url(). "/out/".$p['ID']."/buy_link/";

// DESCRIPTION
$desc = strip_tags($thisp->post_content);


?>

 <tr class="pos<?php echo $i; ?>">
          <th scope="row" class="hidden-xs text-center">
            <?php echo $store_img; ?>
            <?php echo $store_name; ?>
          </th>
          
          <td class="hidden-xs storetitle">
		  
          <?php echo $image; ?>
          
		  <div class="ctitle"><?php echo $thisp->post_title; ?></div>
          
          <?php if(strlen($desc) > 2){ ?>
          <div class="cdesc desc<?php echo $p['ID']; ?>"><?php echo $desc; ?></div>
          
          <script>
			jQuery(document).ready(function() {
			 
			  jQuery('.desc<?php echo $p['ID']; ?>').expander({
				slicePoint: 100,   
				expandSpeed: 0,
				userCollapseText: '<?php echo $CORE->_e(array('feedback','4')); ?>',
				expandText: '<?php echo $CORE->_e(array('feedback','3')); ?>',
			  });
			 
			  jQuery('div.expandDiv').expander();
			}); 
			</script>
            <?php } ?>
          
           </td>
          
          <td class="text-center"><div class="cprice"><?php echo hook_price($p['price']); ?></div></td>
          
          <td> <a  href="<?php echo $link; ?>" class="btn btn-success" target="_blank"> <?php echo $CORE->_e(array('checkout','51')); ?> </a> </td>
          
        </tr>
 

<?php 

$STRING .= ob_get_clean(); 
$i++;
}

ob_start();
?>
</tbody> </table></div>
<?php
$STRING .= ob_get_clean(); 

 }
 
	 
return $STRING;
	
}	
	
	
	
	
	
	
	
	
 
} // END CLASS


?>