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