Changeset 2006 for trunk/modules/media/controllers/media.php
- Timestamp:
- 02/09/2008 12:23:27 AM (11 months ago)
- Files:
-
- 1 modified
-
trunk/modules/media/controllers/media.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/media/controllers/media.php
r2005 r2006 1 1 <?php defined('SYSPATH') or die('No direct script access.'); 2 /**3 * Kohana - The Swift PHP Framework4 *5 * License:6 * author - Kohana Team7 * copyright - (c) 2007 Kohana Team8 * license - <http://kohanaphp.com/license.html>9 */10 11 2 /** 12 3 * Handles loading of site resources (CSS, JS, images) using Views. … … 16 7 * Usage: 17 8 * `http://example.com/index.php/media/css/styles.css` 9 * 10 * $Id$ 11 * 12 * @package Media Module 13 * @author Kohana Team 14 * @copyright (c) 2007-2008 Kohana Team 15 * @license http://kohanaphp.com/license.html 18 16 */ 19 17 class Media_Controller extends Controller { … … 41 39 } 42 40 43 if ($this->use_cache AND ! isset($this->cache)) 41 if ($this->use_cache AND ! isset($this->cache)) 44 42 { 45 43 $this->cache = new Cache; … … 54 52 } 55 53 } 56 54 57 55 public function css($querystr) { 58 // find all the individual files 56 // find all the individual files 59 57 $files = explode("+", $querystr); 60 58 … … 69 67 foreach ($files as $orig_filename) { 70 68 $filename = $orig_filename; 71 if (substr($filename, -4) == ".css") 69 if (substr($filename, -4) == ".css") 72 70 { 73 71 $filename = substr($filename, 0, -4); 74 72 } 75 73 76 74 try 77 75 { … … 80 78 catch (Kohana_Exception $exception) 81 79 { 82 // try to load the file as a php view (eg, file.css.php) 80 // try to load the file as a php view (eg, file.css.php) 83 81 try 84 82 { 85 83 $view = new View('media/css/'.$orig_filename); 86 84 87 85 } 88 86 catch (Kohana_Exception $exception) … … 95 93 if (isset($view)) { 96 94 $filedata = $view->render(); 97 95 98 96 ($this->pack_css) and $filedata = $this->_css_compress($filedata); 99 97 100 98 $data .= $filedata; 101 99 } 102 100 else 103 { 101 { 104 102 $data .= "\n/**** stylesheet ".$filename." not found ****/\n\n\n"; 105 103 } 106 104 } 107 105 108 106 ($this->use_cache) and $this->cache->set('media.css.'.$querystr, $data, array('media'), $this->cache_lifetime); 109 107 } … … 126 124 $this->use_cache AND $data = $this->cache->get('media.js.'.$filename); 127 125 128 if ( ! isset($data) OR empty($data)) 126 if ( ! isset($data) OR empty($data)) 129 127 { 130 128 try … … 134 132 catch (Kohana_Exception $exception) 135 133 { 136 // Try to load the file as a php view (eg, file.js.php) 134 // Try to load the file as a php view (eg, file.js.php) 137 135 try 138 136 { … … 146 144 } 147 145 148 if (isset($view)) 146 if (isset($view)) 149 147 { 150 148 $data = $view->render(); 151 149 152 if ($this->pack_js) 150 if ($this->pack_js) 153 151 { 154 152 $packer = new JavaScriptPacker($data, $this->pack_js); … … 157 155 158 156 ($this->use_cache) and $this->cache->set('media.js.'.$filename, $data, array('media'), $this->cache_lifetime); 159 } 160 else 157 } 158 else 161 159 { 162 160 $data = '/* script not found */'; … … 174 172 // TODO: finish this for generic types 175 173 /* issues: getting View to work with any types of files */ 176 174 177 175 try 178 176 {
