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

Source for file function.include_js.php

Documentation is available at function.include_js.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * Smarty {include_js} function plugin
  10.  *
  11.  * Type:     function
  12.  * Name:     include_js
  13.  * Input:
  14.  *        - file      (required) - fully qualified file to a javascript file
  15.  *          - nopack      (optional) - do not pack
  16.  */
  17. function smarty_function_include_js$params,&$gBitSmarty {
  18.     global $gBitSystem;
  19.     $pack TRUE;
  20.     foreach($params as $key => $val{
  21.         switch$key {
  22.             case 'file':
  23.                 $file $val;
  24.                 break;
  25.             case 'nopack':
  26.                 $pack FALSE;
  27.             default:
  28.                 break;
  29.         }            
  30.     }
  31.     ifis_file$file )) {
  32.         // pack it
  33.         if$pack && $gBitSystem->isFeatureActive'themes_packed_js_css' && shell_exec'which java' ) ) {
  34.             // start up caching engine - pretend we are themes package
  35.             $BitCache new BitCache'themes'TRUE );
  36.  
  37.             // get a name for the cache file we're going to store
  38.             $cachefile md5$file ).'.js';
  39.  
  40.             // if the file hasn't been packed and cached yet, we do that now.
  41.             if!$BitCache->isCached$cachefilefilemtime$file ))) {
  42.                 // pack and cache it
  43.                 $cachedata shell_exec'java -jar '.UTIL_PKG_PATH.'yui/yuicompressor-2.4.2.jar --type js '.$file );
  44.                 $BitCache->writeCacheFile$cachefile$cachedata );
  45.             }
  46.  
  47.             // update the file path with new path
  48.             $file $BitCache->getCacheFile$cachefile );
  49.         }
  50.         // get file text
  51.         $text freadfopen($file,'r')filesize$file ) );
  52.     }else{
  53.         // dump a comment to the page
  54.         $text "if( typeof( console ) != undefined ){ console.log( 'There was an error trying to include js file: ".$file.", it could not be found. Please check the file path.' ); }";
  55.     }
  56.     return $text;
  57. }

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