Source for file BitSmarty.php
Documentation is available at BitSmarty.php
* Smarty Library Inteface Class
* @version $Header: /cvsroot/bitweaver/_bit_kernel/BitSmarty.php,v 1.15 2006/10/13 09:22:47 lsces Exp $
* Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// set SMARTY_DIR that we have the absolute path
define( 'SMARTY_DIR', UTIL_PKG_PATH. 'smarty/libs/' );
// If we have smarty in our kernel, use that.
// assume it is in php's global include_path
// don't set SMARTY_DIR if we are not using the bw copy
$smartyIncFile = 'Smarty.class.php';
require_once($smartyIncFile);
function check( $perm ) {
return $gBitUser->hasPermission( $perm );
global $smarty_force_compile;
$this->mCompileRsrc = NULL;
$this->config_dir = "configs/";
// $this->caching = false;
$this->force_compile = $smarty_force_compile;
$this->assign('app_name', 'bitweaver');
$this->register_prefilter("add_link_ticket");
$this->register_object('perm', $permCheck, array(), true, array('autoComplete'));
$this->assign_by_ref( 'perm', $permCheck );
if( defined( 'TEMPLATE_DEBUG' ) && TEMPLATE_DEBUG == TRUE ) {
echo "\n<!-- - - - {$pParams['smarty_include_tpl_file']} - - - -->\n";
$this->includeSiblingPhp( $pParams['smarty_include_tpl_file'] );
return parent::_smarty_include ($pParams);
// this is used when auto-storing untranslated master strings
$this->mCompileRsrc = $resource_name;
return parent::_compile_resource($resource_name, $compile_path);
function fetch($_smarty_tpl_file, $_smarty_cache_id = null, $_smarty_compile_id = null, $_smarty_display = false)
$_smarty_cache_id = $_smarty_cache_id;
$_smarty_compile_id = $_smarty_compile_id;
if( strpos( $_smarty_tpl_file, ':' ) ) {
list ($resource, $location) = split(':', $_smarty_tpl_file);
if ($resource == 'bitpackage') {
list ($package, $template) = split('/', $location);
// exclude temp, as it contains nexus menus
if( !$gBitSystem->isPackageActive( $package ) && $package != 'temp' ) {
// the PHP sibling file needs to be included here, before the fetch so caching works properly
$this->includeSiblingPhp($_smarty_tpl_file);
if( defined( 'TEMPLATE_DEBUG' ) && TEMPLATE_DEBUG == TRUE ) {
echo "\n<!-- - - - {$_smarty_tpl_file} - - - -->\n";
return parent::fetch($_smarty_tpl_file, $_smarty_cache_id, $_smarty_compile_id, $_smarty_display);
* 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 $pRsrc resource of the template, should be of the form "bitpackage:<packagename>/<templatename>"
* @return TRUE if a sibling php file was included
function includeSiblingPhp($pRsrc)
list ($resource, $location) = split(':', $pRsrc);
if ($resource == 'bitpackage')
list ($package, $template) = split('/', $location);
// print "( $resource, $location ) ( $package, $template )<br/>";
$subdir = preg_match('/mod_/', $template) ? 'modules' : 'templates';
$path = $gBitSystem->mPackages[$package]['path'];
$modPhpFile = str_replace('.tpl', '.php', "$path$subdir/$template");
global $gBitSmarty, $gBitSystem, $gBitUser, $user, $smarty, $gQueryUserId, $module_rows, $module_params, $module_column;
// Module Params were passed in from the template, like kernel/dynamic.tpl
if( $moduleParams = $this->get_template_vars('moduleParams') ) {
if( strpos( trim( $moduleParams['params'] ), ' ' ) ) {
parse_str( $moduleParams["params"], $module_params );
$module_title = ( isset ( $moduleParams['title'] ) ? tra( $moduleParams['title'] ) : ( isset ( $module_params['title'] ) ? $module_params['title'] : NULL ) );
$module_rows = $moduleParams['module_rows'];
global $gBitSystem, $gBitLanguage, $bitdomain;
$temp = BIT_ROOT_PATH . "temp/";
$style = $gBitSystem->getStyle();
$endPath = "$bitdomain/$style/". $gBitLanguage->mLanguage;
$compDir = $temp . "templates_c/$endPath";
$this->compile_dir = $compDir;
$cacheDir = $temp . "cache/$endPath";
$this->cache_dir = $cacheDir;
// This will insert a ticket on all template URL's that have GET parameters.
if ( is_object( $gBitUser ) && $gBitUser->isValid() ) {
$from = '#href="(.*PKG_URL.*php)\?(.*)&(.*)"#i';
$to = 'href="\\1?\\2&tk={$gBitUser->mTicket}&\\3"';
$from = '#<form([^>]*)>#i';
$to = '<form\\1><input type="hidden" name="tk" value="{$gBitUser->mTicket}" />';
if( strpos( $tpl_source, '{form}' ) ) {
$tpl_source = str_replace( '{form}', '{form}<input type="hidden" name="tk" value="{$gBitUser->mTicket}" />', $tpl_source );
} elseif( strpos( $tpl_source, '{form ' ) ) {
$from = '#\{form(\}| [^\}]*)\}#i';
$to = '{form\\1}<input type="hidden" name="tk" value="{$gBitUser->mTicket}" />';
|