Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file function.jspack.php

Documentation is available at function.jspack.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * this function will output the URL to a given compressed and cached js file.
  10.  * NOTE: if you use the util package, it will automatically insert the javascript/ subdir
  11.  * 
  12.  * @param string $pParams[ipackage] package the javascript file is in. this will default to: 'util'. e.g.: wiki
  13.  * @param string $pParams[ifile] subdir and filename of the file you wish to pack and cache. e.g.: libs/jsfile.js
  14.  * @param string $pParams[defer] includes defer='defer'
  15.  * @param object $gBitSmarty 
  16.  * @access public
  17.  * @return URL to cached javascript file
  18.  */
  19. function smarty_function_jspack$pParams&$gBitSmarty {
  20.     // make sure we have a file to pack
  21.     ifempty$pParams['ifile')) {
  22.         die();
  23.     }
  24.  
  25.     ifempty$pParams['ipackage')) {
  26.         $pParams['ipackage''util';
  27.     }
  28.  
  29.     // get the full path to the file we want to pack - insert javasscript/ into path when we're getting stuff in util
  30.     $jsfile constantstrtoupper$pParams['ipackage').'_PKG_PATH' ).(( $pParams['ipackage'== 'util' 'javascript/' '' ).$pParams['ifile'];
  31.  
  32.     ifis_file$jsfile )) {
  33.         // get a name for the cache file we're going to store
  34.         $cachefile $pParams['ipackage'].'_'.str_replace'/''_'$pParams['ifile');
  35.  
  36.         require_onceKERNEL_PKG_PATH.'BitCache.php' );
  37.         $bitCache new BitCache'javascript'TRUE );
  38.  
  39.         // if the file hasn't been packed and cached yet, we do that now.
  40.         if!$bitCache->isCached$cachefilefilemtime$jsfile ))) {
  41.             /*
  42.              * params of the constructor :
  43.              * $script:       the JavaScript to pack, string.
  44.              * $encoding:     level of encoding, int or string :
  45.              *                0,10,62,95 or 'None', 'Numeric', 'Normal', 'High ASCII'.
  46.              *                default: 62.
  47.              * $fastDecode:   include the fast decoder in the packed result, boolean.
  48.              *                default : true.
  49.              * $specialChars: if you have flagged your private and local variables
  50.              *                in the script, boolean.
  51.              *                default: false.
  52.              */
  53.             require_onceUTIL_PKG_PATH.'javascript/class.JavaScriptPacker.php' );
  54.             $packer new JavaScriptPackerfile_get_contents$jsfile )'Normal'TRUEFALSE );
  55.             $bitCache->writeCacheFile$cachefile$packer->pack() );
  56.         }
  57.  
  58.         $defer !empty$pParams['defer'" defer='".$pParams['defer']."'" "";
  59.         return '<script'.$defer.' type="text/javascript" src="'.$bitCache->getCacheUrl$cachefile ).'"></script>';
  60.     else {
  61.         return "<!-- ".tra'not a valid file: ' ).$pParams['ifile']." -->";
  62.     }
  63. }
  64. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:39 +0000 by phpDocumentor 1.5.0-lsces