<?php
defined('xcode_path') or defined('ABSPATH') or die('No script Cuddies');
defined('xcode_path') or define('xcode_assets_uri',get_stylesheet_directory_uri().'/img');
defined('xcode_path') or define('xcode_assets_path',get_stylesheet_directory().'/img');
global $xcode;
//xcode_assets_uri
class files{
	function get_file_icon($extension,$src=false){
		$uri='';
		$path=xcode_assets_path.'/icons/'.$extension.'.png';
		$default_src=xcode_assets_uri.'/icons/blank.png';
		if(@file_exists($path))
		{
			$uri=xcode_assets_uri.'/icons/'.$extension.'.png';
		}
		else{
			$uri=$default_src;
		}
		if($src==false)
		{
			$block='<img src="'.$uri.'" width="100%" class="xcode_file_icon"/>';
			
			return $block;
		}
		return $uri;
	}
	function build_files($files,$echo=false,$additional_info='')
	{
		$file_list='<div class="row file_listing">';
		if(!empty($files)):
		foreach($files as $file)
		{
			$file_title=$file['file_name'];
			$file_extension = pathinfo($file['file']['url'], PATHINFO_EXTENSION);
			$file_src=$file['file']['url'];
			ob_start();
			if($additional_info==''):
			?>
				<a href="<?=$file_src;?>" download="<?=$file_title;?>.<?=$file_extension;?>" target="_new">
					<div class="row single_resource_file">
						<div class="small-9 medium-10 large-11 columns">
							<?=$file_title;?>
						</div>
						<div class="small-3 medium-2 large-1 columns">
							<?=$this->get_file_icon($file_extension);?>
						</div>
					</div>
				</a>
			<?php
			else:
			?>
					<div class="row single_resource_file">
						<div class="small-4 medium-6 large-7 columns">
							<?=$file_title;?>
						</div>
						<div class="small-5 medium-4 large-4 columns">
							<a href="<?=$file_src;?>" download="<?=$file_title;?>.<?=$file_extension;?>" target="_new">
								<?=$additional_info;?>
							</a>
						</div>
						<div class="small-3 medium-2 large-1 columns">
							<?=$this->get_file_icon($file_extension);?>
						</div>
					</div>
			<?php
			endif;
			$file_list.=ob_get_clean();
		}
		endif;
		$file_list.='</div>';
		if($echo==true){
			echo $file_list;
		}
		return $file_list;
	}
	function build_files2($files,$echo=false,$additional_info='')
	{
		$file_list='<div class="row file_listing">';
		if(!empty($files)):
		foreach($files as $file)
		{
			$file_title=$file['file_name'];
			$file_extension = pathinfo($file['file']['url'], PATHINFO_EXTENSION);
			$file_src=$file['file']['url'];
			ob_start();
			if($additional_info==''):
			?>
				<a href="<?=$file_src;?>" download="<?=$file_title;?>.<?=$file_extension;?>" target="_new">
					<?=$this->get_file_icon($file_extension);?>
				</a>
			<?php
			endif;
			$file_list.=ob_get_clean();
		}
		endif;
		$file_list.='</div>';
		if($echo==true){
			echo $file_list;
		}
		return $file_list;
	}
}