Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bitweaver/themes
Browse files Browse the repository at this point in the history
  • Loading branch information
spiderr committed Jun 3, 2013
2 parents 301c1b0 + 73c8671 commit 2172cf9
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
39 changes: 39 additions & 0 deletions BitSmarty.php
Expand Up @@ -106,6 +106,45 @@ function getModuleConfig( $pModuleRsrc ) {
return $moduleConfig;
}

/**
* THE method to invoke if you want to be sure a tpl's sibling php file gets included if it exists. This
* should not need to be invoked from anywhere except within this class
*
* @param string $pFile file to be included, should be of the form "bitpackage:<packagename>/<templatename>"
* @return TRUE if a sibling php file was included
* @access private
*/
function includeSiblingFile( $pFile, $pIncludeVars=NULL ) {
global $gBitThemes;
$ret = FALSE;
if( strpos( $pFile, ':' )) {
list( $resource, $location ) = explode( ':', $pFile );
if( $resource == 'bitpackage' ) {
list( $package, $modFile ) = explode( '/', $location );
$subdir = preg_match( '/mod_/', $modFile ) ? 'modules' : 'templates';
if( preg_match('/mod_/', $modFile ) || preg_match( '/center_/', $modFile ) ) {
global $gBitSystem;
$path = constant( strtoupper( $package )."_PKG_PATH" );
$includeFile = "$path$subdir/$modFile";
if( file_exists( $includeFile )) {
global $gBitSmarty, $gBitSystem, $gBitUser, $gQueryUserId, $moduleParams;
$moduleParams = array();
if( !empty( $pIncludeVars['module_params'] ) ) {
// module_params were passed through via the {include},
// e.g. {include file="bitpackage:foobar/mod_list_foo.tpl" module_params="user_id=`$gBitUser->mUserId`&sort_mode=created_desc"}
$moduleParams['module_params'] = $gBitThemes->parseString( $pIncludeVars['module_params'] );
} else {
// Module Params were passed in from the template, like kernel/dynamic.tpl
$moduleParams = $this->get_template_vars( 'moduleParams' );
}
include( $includeFile );
$ret = TRUE;
}
}
}
}
}

/**
* verifyCompileDir
*
Expand Down
52 changes: 52 additions & 0 deletions smartyplugins/resource._custom.php
@@ -0,0 +1,52 @@
<?php
/**
* 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, $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 )) {
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_by_ref( '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;
}

}


0 comments on commit 2172cf9

Please sign in to comment.