Changeset 1763
- Timestamp:
- 01/21/2008 05:19:34 AM (12 months ago)
- Files:
-
- 1 modified
-
trunk/modules/media/controllers/media.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/media/controllers/media.php
r1633 r1763 18 18 */ 19 19 class Media_Controller extends Controller { 20 protected $use_cache = false; 20 21 protected $use_cache = FALSE; 21 22 protected $cache_lifetime; 22 23 23 protected $pack_css = false;24 protected $pack_js = false;24 protected $pack_css = FALSE; 25 protected $pack_js = FALSE; 25 26 26 public function __construct() { 27 public function __construct() 28 { 27 29 parent::__construct(); 28 30 29 $cache = config::item('media.cache');31 $cache = Config::item('media.cache'); 30 32 $this->use_cache = ($cache > 0); 31 33 32 if (is_int($cache)) { 34 if (is_int($cache)) 35 { 33 36 $this->cache_lifetime = $cache; 34 } else { 37 } 38 else 39 { 35 40 $this->cache_lifetime = config::item('cache.lifetime') OR $this->cache_lifetime = 1800; 36 41 } 37 42 38 if ($this->use_cache AND ! isset($this->cache))43 if ($this->use_cache AND ! isset($this->cache)) 39 44 { 40 45 $this->load->library('cache'); 41 46 } 42 47 43 $this->pack_css = (bool)config::item('media.pack_css'); 48 $this->pack_css = (bool) Config::item('media.pack_css'); 49 $this->pack_js = Config::item('media.pack_js'); 44 50 45 $this->pack_js = config::item('media.pack_js'); 46 if ($this->pack_js === true) $this->pack_js = 'Normal'; 51 if ($this->pack_js === TRUE) 52 { 53 $this->pack_js = 'Normal'; 54 } 47 55 } 48 56 49 public function css() { 57 public function css() 58 { 50 59 $filename = $orig_filename = $this->uri->segment(3); 51 if (substr($filename, -4) == ".css") { 60 if (substr($filename, -4) == '.css') 61 { 52 62 $filename = substr($filename, 0, -4); 53 63 } 54 64 55 65 $mimetype = config::item('mimes.css'); 56 $mimetype = (isset($mimetype[0]) ? $mimetype[0] : 'text/stylesheet'); 57 66 $mimetype = (isset($mimetype[0])) ? $mimetype[0] : 'text/stylesheet'; 58 67 59 68 $this->use_cache AND $data = $this->cache->get('media.css.'.$filename); 60 69 61 if ( !isset($data) OR empty($data))70 if ( ! isset($data) OR empty($data)) 62 71 { 63 72 try 64 73 { 65 $view = new View('media/css/'.$filename, null, 'css');74 $view = new View('media/css/'.$filename, NULL, 'css'); 66 75 } 67 76 catch (Kohana_Exception $exception) 68 77 { 69 // try to load the file as a php view (eg,file.css.php)78 // Try to load the file as a php view (e.g. file.css.php) 70 79 try 71 80 { 72 81 $view = new View('media/css/'.$orig_filename); 73 74 82 } 75 83 catch (Kohana_Exception $exception) 76 84 { 77 // not found85 // Not found 78 86 unset($view); 79 87 } 80 88 } 81 89 82 if (isset($view)) { 90 if (isset($view)) 91 { 83 92 $data = $view->render(); 84 93 … … 103 112 } 104 113 105 public function js() { 114 public function js() 115 { 106 116 $filename = $orig_filename = $this->uri->segment(3); 107 if (substr($filename, -3) == ".js") { 117 if (substr($filename, -3) == '.js') 118 { 108 119 $filename = substr($filename, 0, -3); 109 120 } 110 121 111 $mimetype = config::item('mimes.js');112 $mimetype = (isset($mimetype[0]) ? $mimetype[0] : 'text/javascript');122 $mimetype = Config::item('mimes.js'); 123 $mimetype = (isset($mimetype[0])) ? $mimetype[0] : 'text/javascript'; 113 124 114 125 115 126 $this->use_cache AND $data = $this->cache->get('media.js.'.$filename); 116 127 117 if ( !isset($data) OR empty($data))128 if ( ! isset($data) OR empty($data)) 118 129 { 119 130 try 120 131 { 121 $view = new View('media/js/'.$filename, null, 'js');132 $view = new View('media/js/'.$filename, NULL, 'js'); 122 133 } 123 134 catch (Kohana_Exception $exception) 124 135 { 125 // try to load the file as a php view (eg, file.js.php)136 // Try to load the file as a php view (eg, file.js.php) 126 137 try 127 138 { … … 130 141 catch (Kohana_Exception $exception) 131 142 { 132 // not found143 // Not found 133 144 unset($view); 134 145 } … … 160 171 } 161 172 162 public function _default() { 173 public function _default() 174 { 163 175 $type = $this->uri->segment(2); 164 176 $filename = $this->uri->segment(3); 165 // TODO: finish this for generic types177 // TODO: finish this for generic types 166 178 /* issues: getting View to work with any types of files */ 167 179 } 168 169 function _css_compress($data) { 170 // from http://www.ibloomstudios.com/articles/php_css_compressor/ 180 181 // Based on http://www.ibloomstudios.com/articles/php_css_compressor/ 182 public function _css_compress($data) 183 { 184 // Remove comments 185 $data = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $data); 171 186 172 // remove comments 173 $data = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $data); 174 // remove tabs, spaces, newlines, etc. 175 $data = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $data); 187 // Remove tabs, spaces, newlines, etc. 188 $data = str_replace 189 ( 190 array("\r\n", "\r", "\n", "\t", ' ', ' {', '{ ', ' }', '} ', ' +', '+ ', ' >', '> ', ' :', ': ', ' ;', '; ', ' ,', ', ', ';}'), 191 array(' ', ' ', ' ', ' ', ' ', '{', '{', '}', '}', '+', '+', '>', '>', ':', ':', ';', ';', ',', ',', '}' ), 192 $data 193 ); 194 176 195 return $data; 177 196 } 197 178 198 } // End Media_Controller 179 180
