| | 68 | $data = ''; |
| | 69 | foreach ($files as $orig_filename) { |
| | 70 | $filename = $orig_filename; |
| | 71 | if (substr($filename, -4) == ".css") |
| | 72 | { |
| | 73 | $filename = substr($filename, 0, -4); |
| | 74 | } |
| | 75 | |
| | 76 | try |
| | 77 | { |
| | 78 | $view = new View('media/css/'.$filename, null, 'css'); |
| | 79 | } |
| | 80 | catch (Kohana_Exception $exception) |
| | 81 | { |
| | 82 | // try to load the file as a php view (eg, file.css.php) |
| | 83 | try |
| | 84 | { |
| | 85 | $view = new View('media/css/'.$orig_filename); |
| | 86 | |
| | 87 | } |
| | 88 | catch (Kohana_Exception $exception) |
| | 89 | { |
| | 90 | // not found |
| | 91 | unset($view); |
| | 92 | } |
| | 93 | } |
| | 94 | |
| | 95 | if (isset($view)) { |
| | 96 | $filedata = $view->render(); |
| | 97 | |
| | 98 | ($this->pack_css) and $filedata = $this->_css_compress($filedata); |
| | 99 | |
| | 100 | $data .= $filedata; |
| | 101 | } |
| | 102 | else |
| | 103 | { |
| | 104 | $data .= "\n/**** stylesheet ".$filename." not found ****/\n\n\n"; |
| | 105 | } |
| | 106 | } |
| | 107 | |
| | 108 | ($this->use_cache) and $this->cache->set('media.css.'.$querystr, $data, array('media'), $this->cache_lifetime); |
| | 109 | } |
| | 110 | |
| | 111 | $mimetype AND header('Content-type: '.$mimetype); |
| | 112 | echo $data; |
| | 113 | } |
| | 114 | |
| | 115 | public function js($orig_filename) { |
| | 116 | $filename = $orig_filename; |
| | 117 | if (substr($filename, -3) == '.js') |
| | 118 | { |
| | 119 | $filename = substr($filename, 0, -3); |
| | 120 | } |
| | 121 | |
| | 122 | $mimetype = Config::item('mimes.js'); |
| | 123 | $mimetype = (isset($mimetype[0])) ? $mimetype[0] : 'text/javascript'; |
| | 124 | |
| | 125 | |
| | 126 | $this->use_cache AND $data = $this->cache->get('media.js.'.$filename); |
| | 127 | |
| | 128 | if ( ! isset($data) OR empty($data)) |
| | 129 | { |
| 90 | | if (isset($view)) |
| 91 | | { |
| 92 | | $data = $view->render(); |
| 93 | | |
| 94 | | if ($this->pack_css) |
| 95 | | { |
| 96 | | $data = $this->_css_compress($data); |
| 97 | | } |
| 98 | | |
| 99 | | if ($this->use_cache) |
| 100 | | { |
| 101 | | $this->cache->set('media.css.'.$filename, $data, array('media'), $this->cache_lifetime); |
| 102 | | } |
| 103 | | } |
| 104 | | else |
| 105 | | { |
| 106 | | $data = '/* stylesheet not found */'; |
| 107 | | } |
| 108 | | } |
| 109 | | |
| 110 | | $mimetype AND header('Content-type: '.$mimetype); |
| 111 | | echo $data; |
| 112 | | } |
| 113 | | |
| 114 | | public function js() |
| 115 | | { |
| 116 | | $filename = $orig_filename = $this->uri->segment(3); |
| 117 | | if (substr($filename, -3) == '.js') |
| 118 | | { |
| 119 | | $filename = substr($filename, 0, -3); |
| 120 | | } |
| 121 | | |
| 122 | | $mimetype = Config::item('mimes.js'); |
| 123 | | $mimetype = (isset($mimetype[0])) ? $mimetype[0] : 'text/javascript'; |
| 124 | | |
| 125 | | |
| 126 | | $this->use_cache AND $data = $this->cache->get('media.js.'.$filename); |
| 127 | | |
| 128 | | if ( ! isset($data) OR empty($data)) |
| 129 | | { |
| 130 | | try |
| 131 | | { |
| 132 | | $view = new View('media/js/'.$filename, NULL, 'js'); |
| 133 | | } |
| 134 | | catch (Kohana_Exception $exception) |
| 135 | | { |
| 136 | | // Try to load the file as a php view (eg, file.js.php) |
| 137 | | try |
| 138 | | { |
| 139 | | $view = new View('media/js/'.$orig_filename); |
| 140 | | } |
| 141 | | catch (Kohana_Exception $exception) |
| 142 | | { |
| 143 | | // Not found |
| 144 | | unset($view); |
| 145 | | } |
| 146 | | } |
| 147 | | |