blob: 2a802f84171376bcfa67c89e3fdf75c52246afd2 (
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
|
<?php
namespace Bitweaver\Plugins;
use Smarty\Resource\Smarty_Resource_Custom;
use Bitweaver\KernelTools;
/**
* Smarty plugin
* -------------------------------------------------------------
* File: resource._custom.php
* Type: resource
* Name: _custom
* Purpose: Fetches templates from the correct package
* -------------------------------------------------------------
* @package Smarty
* @subpackage plugins
*/
class Smarty_Resource__Custom extends Smarty_Resource_Custom {
protected function fetch ( $pTplName, &$pTplSource, &$pTplTime ) {
global $gBitLanguage, $gBitThemes, $gBitSystem, $gBitSmarty;
$ret = '';
// We're gonna run our own cache mechanism for user_modules
// the cache is here to avoid calls to consumming queries,
// each module is different for each language because of the strings
$cacheDir = TEMP_PKG_PATH.'modules/cache/';
if( !is_dir( $cacheDir )) {
KernelTools::mkdir_p( $cacheDir );
}
list( $package, $template ) = explode( '/', $pTplName );
$cacheFile = $cacheDir.'_custom.'.$gBitLanguage->mLanguage.'.'.$template.'.tpl.cache';
if( !empty( $r["cache_time"] ) && file_exists( $cacheFile ) && !(( $gBitSystem->getUTCTime() - filemtime( $cacheFile )) > $r["cache_time"] )) {
$pTplSource = file_get_contents( $cacheFile );
} else {
global $moduleParams;
if( $moduleParams = $gBitThemes->getCustomModule( $template )) {
$gBitSmarty->assign( 'moduleParams', $moduleParams );
$pTplSource = $gBitSmarty->fetch( 'bitpackage:themes/custom_module.tpl' );
// write to chache file
$fp = fopen( $cacheFile, "w+" );
fwrite( $fp, $data, strlen( $data ));
fclose( $fp );
}
}
$pTplTime = filemtime( $cacheFile );
}
protected function fetchTimestamp( $pTplName ) {
return null;
}
}
|