summaryrefslogtreecommitdiff
path: root/smartyplugins/resource.bitpackage.php
diff options
context:
space:
mode:
Diffstat (limited to 'smartyplugins/resource.bitpackage.php')
-rw-r--r--smartyplugins/resource.bitpackage.php113
1 files changed, 50 insertions, 63 deletions
diff --git a/smartyplugins/resource.bitpackage.php b/smartyplugins/resource.bitpackage.php
index faaf9c7..82711e1 100644
--- a/smartyplugins/resource.bitpackage.php
+++ b/smartyplugins/resource.bitpackage.php
@@ -1,88 +1,75 @@
<?php
/**
* Smarty plugin
- * @package Smarty
- * @subpackage plugins
- */
-
-/**
- * Smarty plugin
* -------------------------------------------------------------
* File: resource.bitpackage.php
* Type: resource
* Name: bitpackage
* Purpose: Fetches templates from the correct package
* -------------------------------------------------------------
+ * @package Smarty
+ * @subpackage plugins
*/
-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;
-}
+class Smarty_Resource_Bitpackage extends Smarty_Resource_Custom {
-// 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;
+ protected function fetch ( $pTplName, &$pTplSource, &$pTplTime ) {
+ $resources = $this->getTplLocations( $pTplName );
+ foreach( $resources as $resource ) {
+ if( file_exists( $resource )) {
+ $pTplSource = file_get_contents( $resource );
+ $pTplTime = filemtime( $resource );
+ }
}
}
- return FALSE;
-}
-function smarty_resource_bitpackage_secure( $pTplName, &$gBitSmarty ) {
- // assume all templates are secure
- return TRUE;
-}
+ protected function fetchTimestamp( $pTplName ) {
+ $ret = FALSE;
+ foreach( $this->getTplLocations( $pTplName ) as $resource ) {
+ if( file_exists( $resource )) {
+ $ret = filemtime( $resource );
+ }
+ }
+ return $ret;
+ }
-function smarty_resource_bitpackage_trusted( $pTplName, &$gBitSmarty ) {
- // not used for templates
-}
+ private function getTplLocations( $pTplName ) {
+ global $gBitThemes, $gNoForceStyle;
-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.'/';
+ }
- $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 config/themes/force/
+ $ret['force'] = CONFIG_PKG_PATH."themes/force/$package/$subdir$template";
+ $ret['force_simple'] = CONFIG_PKG_PATH."themes/force/$subdir$template";
+ }
- // 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 config/themes/force/
- $ret['force'] = CONFIG_PKG_PATH."themes/force/$package/$subdir$template";
- $ret['force_simple'] = CONFIG_PKG_PATH."themes/force/$subdir$template";
- }
+ // look in themes/style/<stylename>/
+ $ret['override'] = $gBitThemes->getStylePath()."$package/$subdir$template";
+ $ret['override_simple'] = $gBitThemes->getStylePath().$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;
- // 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";
+ }
- // look for default package template
- $ret['package_template'] = constant( strtoupper( $package ).'_PKG_PATH' )."$subdir$template";
+ return $ret;
}
-
- return $ret;
}
+
?>