<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Fonts extends CI_controller {

    public function _remap($method, $params = array())
    {
        array_unshift($params,$method);
        $this->index($params);
    }
    
    /**
    * 
    *
    * @exemple "base_url" /img/ "nome do module de onte está a imagem" / nome da imagem dentro da pasta img do modulo
    */
    public function index($uri = null) 
    {
        if ($uri[0] != 'index') 
        {
            $local = 'assets/fonts';
            $arquivo = '';
            for ($i = 1;$i < count($uri);$i++) 
            {
                if ($i < count($uri) - 1) $local.= "/" . $uri[$i];
                else $arquivo = $uri[$i];
            }
            $font_file = module_file_path($uri[0], $local, $arquivo);
            if($font_file != NULL)
            {
                $extensao = pathinfo($arquivo, PATHINFO_EXTENSION);
                $this->output
                    ->set_content_type($extensao)
                    ->set_output(file_get_contents($font_file));
            }
        }
        
    }
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
    public function index_bk($uri=null)
    {
        /*$uri = "logo_homero.jpg";
        
       // $this->output->enable_profiler(false);
        $img_file = module_file_path("blog", "assets/img", $uri); 
        //var_dump($img_file);
        
        $new_file = 'assets/cache/'.$uri;
        
        //$assets	= $this->input->get('assets') ? $this->input->get('assets') : 'assets/images';
		//$size	= $this->input->get('size');
		$height;
		$width;
		$ratio;
		//$force	= $this->input->get('force');
		//$module = $this->input->get('module');
        
        
        $config = array(
				'image_library'		=> 'gd2',
				'source_image'		=> $img_file,
				'new_image'			=> $new_file,
				'create_thumb'		=> false,
				//'maintain_ratio'	=> $ratio == 'no' ? false : true,
				//'master_dim'		=> !empty($width) ? 'width' : 'height', 
				//'width'				=> !empty($width) ? $width : $height,
				//'height'			=> !empty($height) ? $height : $width,
			);

			$this->load->library('image_lib', $config);
			
			$this->image_lib->resize();
            
            //echo '<img src='.base_url().$new_file.'>';
		    
		    $this->load->library('easyphpthumbnail');
		    $thumb = new easyphpthumbnail;
		    //$thumb->Thumbwidth = 562;
		    $thumb->Createthumb($img_file);*/
		    

		//$this->output			->set_content_type($ext)			->set_output(file_get_contents($new_file));     
        
        
        
        if($uri[0] != 'index')
        {
            
            $local = 'assets/img';
            $arquivo = '';
            for ($i = 1; $i < count($uri); $i++) {
                if($i < count($uri)-1)
                     $local .= "/".$uri[$i];
                else
                    $arquivo = $uri[$i];
            }
            //var_dump($local);
            //var_dump($arquivo);
            $img_file = module_file_path($uri[0], $local, $arquivo); 
            $new_file = 'assets/cache/'.$arquivo;
            $config = array(
				'image_library'		=> 'gd2',
				'source_image'		=> $img_file,
				'new_image'			=> $new_file,
				'create_thumb'		=> false,
				//'maintain_ratio'	=> $ratio == 'no' ? false : true,
				//'master_dim'		=> !empty($width) ? 'width' : 'height', 
				//'width'				=> !empty($width) ? $width : $height,
				//'height'			=> !empty($height) ? $height : $width,
			);
            $this->load->library('image_lib', $config);
			$this->image_lib->resize();
            
            //$new_file = module_file_path($uri[0], 'assets/cache', $arquivo); 
           // echo '<img src='.base_url().$new_file.'>';
            //$file = 'modules/leadpg/img/infograph.pdf';
            //$filename = 'infografico-view-brasil-metodologia-de-sucesso.pdf';
          header('Content-type: image/jpg');
          header('Content-Disposition: inline; filename="' . $new_file . '"');
          header('Content-Transfer-Encoding: binary');
          header('Accept-Ranges: bytes');
          @readfile($new_file);
            
    	/*	$img_file = module_file_path($uri[0], $local, $arquivo); 
    	    
            $this->load->library('easyphpthumbnail');
		    $thumb = new easyphpthumbnail;
		    //$thumb->Thumbwidth = 562;
		    $thumb->Createthumb($img_file);
    		*/
            
            
        }
        
    }
    
    public function infografico()
    {
          $file = 'modules/leadpg/img/infograph.pdf';
          $filename = 'infografico-view-brasil-metodologia-de-sucesso.pdf';
          header('Content-type: application/pdf');
          header('Content-Disposition: inline; filename="' . $filename . '"');
          header('Content-Transfer-Encoding: binary');
          header('Accept-Ranges: bytes');
          @readfile($file);
    }
    
    
    //teste
    public function f79a705eac0b35b3860b0d661c769874()
    {
        $key = $this->uri->segment(4);
        $clique = $this->uri->segment(5);
        $url = $this->uri->segment(6)."/";
        
        for ($i = 7; $i <= $this->uri->total_segments(); $i++) {
             $url .= "/".$this->uri->segment($i);
        }
        echo "cq = $clique <br>";
        echo $url;
        $this->load->model('newsletter_model');
        $this->newsletter_model->clicou_email_campanha($key);
        //redirect($url);
    }
    
	/**
	 * Performs the image processing based on the parameters provided in the GET request
	 *
	 * @param string $file The name of the image to return.
	 */
	public function bk($file=null)
	{
	    var_dump($file);
        if (empty($file) || !is_string($file))
		{
			die('No image to process.');
		}

		$this->output->enable_profiler(false);

		// Get our params
		$assets	= $this->input->get('assets') ? $this->input->get('assets') : 'assets/images';
		$size	= $this->input->get('size');
		$height	= $this->input->get('height');
		$width	= $this->input->get('width');
		$ratio	= $this->input->get('ratio');
		$force	= $this->input->get('force');
		$module = $this->input->get('module');

		$ext = pathinfo($file, PATHINFO_EXTENSION);

		if (empty($ext))
		{
			die('Filename does not include a file extension.');
		}

		// Is it a square?
		if (!empty($size))
		{
			$height = (int)$size;
			$width	= (int)$size;
			$ratio 	= 'no';
		}
		
		if (!empty($module))
		{
			$img_file = module_file_path($module, $assets, $file); 
		} else {
			$img_file = FCPATH . $assets .'/'. $file;
		}

		if (!is_file($img_file))
		{
			die('Image could not be found.');
		}

		$new_file = FCPATH .'assets/cache/'. str_replace('.'. $ext, '', $file) ."_{$width}x{$height}.". $ext;

		if (!is_file($new_file) || $force != 'yes')
		{
			$config = array(
				'image_library'		=> 'gd2',
				'source_image'		=> $img_file,
				'new_image'			=> $new_file,
				'create_thumb'		=> false,
				'maintain_ratio'	=> $ratio == 'no' ? false : true,
				'master_dim'		=> !empty($width) ? 'width' : 'height', 
				'width'				=> !empty($width) ? $width : $height,
				'height'			=> !empty($height) ? $height : $width,
			);

			$this->load->library('image_lib', $config);

			$this->image_lib->resize();
		}

		$this->output
			->set_content_type($ext)
			->set_output(file_get_contents($new_file));
	}//end index()

	//--------------------------------------------------------------------

}//end class