<?php
global $allowedposttags, $cactus_section_key;;
$service = cactus_option('service');
$columns = absint(cactus_option('columns_'.$cactus_section_key));
$section_title = cactus_option('section_title_'.$cactus_section_key);
$section_subtitle = cactus_option('section_subtitle_'.$cactus_section_key);

function cactus_get_service( $service ){
	global $allowedposttags;
	  $html  = '';
	  if(is_array($service)):
  		 foreach($service as $item):
       
		$icon  = str_replace('fa-','',$item['icon']);
		$icon  = str_replace('fa ','',$icon);
		
		$title = '<h4>'.esc_attr($item['title']).'</h4>';
		if($item['title_link'] !='' )
			$title = '<a href="'.esc_url($item['title_link']).'" target="_blank">'.$title.'</a>';
		$image     = isset($item['image'])?$item['image']:'';
		$icon_type = isset($item['icon_type'])?$item['icon_type']:'icon';
		
		if (is_numeric($image)) {
			$image_attributes = wp_get_attachment_image_src($image, 'full');
			$image   = $image_attributes[0];
		  }
		
      		$html .= '<li><div class="cactus-feature-item">';
            
             if($icon_type == 'image'){
             if($image !='' ){
         	 $html .= '<div class="cactus-feature-figure">
            <img src="'.esc_url($image).'" alt="'.esc_attr($item['title']).'">
            </div>';
             }
			 }else{
           $html .= '<div class="cactus-feature-figure">
            <i class="fa fa-'.esc_attr($icon).'" style="font-size: 50px;"></i>
            </div>';
			 }
            
            $html .= '<div class="cactus-feature-caption">
              '.$title.'
              <p>'.wp_kses( $item['text'] , $allowedposttags ).'</p>
            </div>
          </div>
        </li>';
         endforeach;
  		 endif;
		 return $html;
        
}
?>
  <div class="cactus-section-content">
    <div class="cactus-container">
      <h2 class="cactus-section-title text-center <?php echo 'section_title_'.$cactus_section_key.'_selective';?>"><?php echo wp_kses( $section_title , $allowedposttags );?></h2>
      <p class="cactus-section-desc text-center <?php echo 'section_subtitle_'.$cactus_section_key.'_selective';?>"><?php echo wp_kses( $section_subtitle , $allowedposttags );?></p>
      <ul class="cactus-services cactus-list-md-<?php echo $columns;?> <?php echo 'service_selective';?>">
     <?php echo cactus_get_service($service);?>
      </ul>
    </div>
  </div>
