Changeset 1515

Show
Ignore:
Timestamp:
12/13/2007 10:59:03 AM (10 months ago)
Author:
Shadowhand
Message:

Merged in changes to fix #222

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/View.php

    r1499 r1515  
    2828         * @param   array   pre-load data 
    2929         */ 
    30         public function __construct($name, $data = NULL) 
     30        public function __construct($name, $data = NULL, $type = NULL) 
    3131        { 
    32                 if (preg_match('/\.(?:html?|gif|jpe?g|png|css|js|tiff?|swf|pdf)$/Di', $name, $type)) 
     32                if (empty($type)) 
    3333                { 
    34                         // Removes the period from the beginning of the type 
    35                         $type = substr($type[0], 1); 
    36  
    37                         $this->kohana_filename = Kohana::find_file('views', $name, TRUE, $type); 
    38                         $this->kohana_filetype = current(Config::item('mimes.'.$type)); 
    39  
    40                         // Clear output Events to be safe 
    41                         Event::clear('system.display'); 
     34                        // Load the filename and set the content type 
     35                        $this->kohana_filename = Kohana::find_file('views', $name, TRUE); 
     36                        $this->kohana_filetype = EXT; 
    4237                } 
    4338                else 
    4439                { 
    45                         $this->kohana_filename = Kohana::find_file('views', $name, TRUE); 
    46                         $this->kohana_filetype = EXT; 
     40                        // Check if the filetype is allowed by the configuration 
     41                        if ( ! in_array($type, Config::item('view.allowed_filetypes'))) 
     42                                throw new Kohana_Exception('core.invalid_filetype', $type); 
     43 
     44                        // Load the filename and set the content type 
     45                        $this->kohana_filename = Kohana::find_file('views', $name.'.'.$type, TRUE, $type); 
     46                        $this->kohana_filetype = Config::item('mimes.'.$type); 
    4747                } 
    4848 
     
    174174                else 
    175175                { 
    176                         // Overwrite the content-type header 
    177                         header('Content-type: '.$this->kohana_filetype); 
     176                        // Set the content type and size 
     177                        header('Content-Type: '.$this->kohana_filetype[0]); 
     178                        header('Content-Length: '.filesize($this->kohana_filename)); 
    178179 
    179180                        if ($print == TRUE)