blob: 5b6e6c577000348cc284489965e8ba8654df751f (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty plugin
* -------------------------------------------------------------
* File: resource.bitpackage.php
* Type: resource
* Name: bitpackage
* Purpose: Fetches templates from the correct package
* -------------------------------------------------------------
*/
function smarty_resource_bitpackage_source( $pTplName, &$pTplSource, &$gBitSmarty ) {
$resources = smarty_get_bitweaver_resources( $pTplName );
foreach( $resources as $resource ) {
if( file_exists( $resource )) {
$pTplSource = file_get_contents( $resource );
return TRUE;
}
}
vd( "Missing template:" );
vd( $resources );
return FALSE;
}
// the PHP sibling file needs to be included in modules_inc before this fetch so caching works properly
function smarty_resource_bitpackage_timestamp( $pTplName, &$pTplTimestamp, &$gBitSmarty ) {
foreach( smarty_get_bitweaver_resources( $pTplName ) as $resource ) {
if( file_exists( $resource )) {
$pTplTimestamp = filemtime( $resource );
return TRUE;
}
}
return FALSE;
}
function smarty_resource_bitpackage_secure( $pTplName, &$gBitSmarty ) {
// assume all templates are secure
return TRUE;
}
function smarty_resource_bitpackage_trusted( $pTplName, &$gBitSmarty ) {
// not used for templates
}
function smarty_get_bitweaver_resources( $pTplName ) {
global $gBitThemes, $gNoForceStyle;
$path = explode( '/', $pTplName );
$package = array_shift( $path );
$template = array_pop( $path );
$subdir = '';
foreach( $path as $p ) {
$subdir .= $p.'/';
}
// files found in temp are special - these are stored in temp/<pkg>/(templates|modules)/<template.tpl>
if( $package == 'temp' ) {
// if it's a module, we need to look in the correct place
$subdir .= ( preg_match( '/\b(help_)?mod_/', $template ) ? 'modules' : 'templates' );
// we can't override these templates - they only exist in temp
$ret['package_template'] = constant( strtoupper( $package ).'_PKG_PATH' )."$subdir/$template";
} else {
if( empty( $gNoForceStyle )) {
// look in themes/force/
$ret['force'] = THEMES_PKG_PATH."force/$package/$subdir$template";
$ret['force_simple'] = THEMES_PKG_PATH."force/$subdir$template";
}
// look in themes/style/<stylename>/
$ret['override'] = $gBitThemes->getStylePath()."$package/$subdir$template";
$ret['override_simple'] = $gBitThemes->getStylePath().$subdir.$template;
// if it's a module, we need to look in the correct place
$subdir = ( preg_match( '/\b(help_)?mod_/', $template ) ? 'modules' : 'templates' )."/".$subdir;
// look for default package template
$ret['package_template'] = constant( strtoupper( $package ).'_PKG_PATH' )."$subdir$template";
}
return $ret;
}
?>
|