Changeset 2006
- Timestamp:
- 02/09/2008 12:23:27 AM (10 months ago)
- Location:
- trunk/modules/media
- Files:
-
- 4 modified
-
config/media.php (modified) (3 diffs)
-
controllers/media.php (modified) (12 diffs)
-
helpers/media.php (modified) (1 diff)
-
libraries/JavaScriptPacker.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/media/config/media.php
r1633 r2006 1 1 <?php defined('SYSPATH') or die('No direct script access.'); 2 2 /** 3 * @package Media Module 4 * 5 * $Id$ 6 * 3 7 * The media controller is a way of serving up various media content (JS, CSS, images, etc) 4 * 8 * 5 9 * The idea is that you have a subdirectory in your application views directory called "media", 6 10 * which contains all the files needed. For example: 7 * 11 * 8 12 * http://baseurl/media/css/style1.css -> views/media/css/style1.css or style1.css.php 9 * 10 * Additionally, CSS and Javascript files can be packed and cached. 13 * 14 * Additionally, CSS and Javascript files can be packed and cached. 11 15 */ 12 16 13 17 /** 14 * Enable media caching. 15 * 18 * Enable media caching. 19 * 16 20 * Set to false to disable, true to enable using default cache lifetimes, or number of seconds to cache for 17 * 21 * 18 22 * Strongly recommended if you are using packing. 19 23 */ … … 22 26 /** 23 27 * If CSS files should be packed (whitespace, comments, etc removed) 24 * 28 * 25 29 * Boolean 26 30 */ … … 29 33 /** 30 34 * If javascript files should be packed. 31 * 35 * 32 36 * Value should be one of: false, 0,10,62,95 or 'Numeric', 'Normal', 'High ASCII'. 33 * 37 * 34 38 * false or 0 disables packing 35 39 */ -
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 { -
trunk/modules/media/helpers/media.php
r1809 r2006 1 1 <?php defined('SYSPATH') or die('No direct script access.'); 2 2 /** 3 * Class: media 4 * Media helper class. 5 * 6 * Kohana Source Code: 7 * author - Kohana Team 8 * copyright - (c) 2007 Kohana Team 9 * license - <http://kohanaphp.com/license.html> 10 */ 3 * Media helper class. 4 * 5 * $Id$ 6 * 7 * @package Media Module 8 * @author Kohana Team 9 * @copyright (c) 2007-2008 Kohana Team 10 * @license http://kohanaphp.com/license.html 11 */ 11 12 class media_Core { 13 12 14 /** 13 * Method: stylesheet 14 * Creates a stylesheet link. 15 * 16 * Parameters: 17 * style - filename, or array of filenames (do not include path) 18 * media - media type of stylesheet 19 * index - include the index_page in the link 20 * 21 * Returns: 22 * An HTML stylesheet link. 23 */ 15 * Creates a stylesheet link. 16 * 17 * @param string|array filename, or array of filenames (do not include path) 18 * @param string media type of stylesheet 19 * @param boolean include the index_page in the link 20 * @return string 21 */ 24 22 public static function stylesheet($style, $media = FALSE, $index = TRUE) 25 23 { -
trunk/modules/media/libraries/JavaScriptPacker.php
r1766 r2006 1 1 <?php 2 /* 7 December 2006. version 1.0 3 * 2 /** 3 * @package Media Module 4 * 5 * $Id$ 6 * 7 * 7 December 2006. version 1.0 8 * 4 9 * This is the php version of the Dean Edwards JavaScript 's Packer, 5 10 * Based on : 6 * 11 * 7 12 * ParseMaster, version 1.0.2 (2005-08-19) Copyright 2005, Dean Edwards 8 13 * a multi-pattern parser. 9 14 * KNOWN BUG: erroneous behavior when using escapeChar with a replacement 10 15 * value that is a function 11 * 16 * 12 17 * packer, version 2.0.2 (2005-08-19) Copyright 2004-2005, Dean Edwards 13 * 18 * 14 19 * License: http://creativecommons.org/licenses/LGPL/2.1/ 15 * 20 * 16 21 * Ported to PHP by Nicolas Martin. 17 * 22 * 18 23 * ---------------------------------------------------------------------- 19 * 24 * 20 25 * examples of usage : 21 26 * $myPacker = new JavaScriptPacker($script, 62, true, false); 22 27 * $packed = $myPacker->pack(); 23 * 28 * 24 29 * or 25 * 30 * 26 31 * $myPacker = new JavaScriptPacker($script, 'Normal', true, false); 27 32 * $packed = $myPacker->pack(); 28 * 33 * 29 34 * or (default values) 30 * 35 * 31 36 * $myPacker = new JavaScriptPacker($script); 32 37 * $packed = $myPacker->pack(); 33 * 34 * 38 * 39 * 35 40 * params of the constructor : 36 41 * $script: the JavaScript to pack, string. … … 43 48 * in the script, boolean. 44 49 * default: false. 45 * 50 * 46 51 * The pack() method return the compressed JavasScript, as a string. 47 * 52 * 48 53 * see http://dean.edwards.name/packer/usage/ for more information. 49 * 54 * 50 55 * Notes : 51 56 * # need PHP 5 . Tested with PHP 5.1.2 52 * 57 * 53 58 * # The packed result may be different than with the Dean Edwards 54 59 * version, but with the same length. The reason is that the PHP … … 58 63 * ECMAScript standard). So the encoded keywords order can be 59 64 * different in the two results. 60 * 65 * 61 66 * # Be careful with the 'High ASCII' Level encoding if you use 62 * UTF-8 in your files... 67 * UTF-8 in your files... 63 68 */ 64 69 … … 87 92 $_encoding = $this->LITERAL_ENCODING[$_encoding]; 88 93 $this->_encoding = min((int)$_encoding, 95); 89 $this->_fastDecode = $_fastDecode; 94 $this->_fastDecode = $_fastDecode; 90 95 $this->_specialChars = $_specialChars; 91 96 } … … 253 258 // the ECMAscript standard does not guarantee this behaviour, 254 259 // and thus not all browsers (e.g. Mozilla versions dating back to at 255 // least 2003) respect this. 260 // least 2003) respect this. 256 261 usort($unsorted, array(&$this, '_sortWords')); 257 262 $j = 0; … … 434 439 if (defined('self::JSFUNCTION'.$aName)) 435 440 return constant('self::JSFUNCTION'.$aName); 436 else 441 else 437 442 return ''; 438 443 } … … 530 535 return ($charCode < _encoding ? \'\' : arguments.callee($charCode / _encoding)) + 531 536 String.fromCharCode($charCode % _encoding + 161); 532 }'; 537 }'; 533 538 534 539 }
