Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
enh(smarty/tpl): simplify the initSmartyTplForPopup function & compat…
Browse files Browse the repository at this point in the history
…ibility

When you are in a "widget" type element (custom view), the initialization of the Smarty template is not the same so you need to check this when calling to avoid errors.

Refs: STUDIO-2228
  • Loading branch information
jdelpierre committed Dec 12, 2019
1 parent 4c87741 commit e7972a5
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions www/include/common/common-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,36 +161,37 @@ function tidySearchKey($search, $advanced_search)

#

/**
* Allows to load Smarty's configuration in relation to a path
*
* @param {string} [$path=null] Path to the default template directory
* @param {object} [$tpl=null] A Smarty instance
* @param {string} [$subDir=null] A subdirectory of path
*
* @return {empty|object} A Smarty instance with configuration parameters
*/
function initSmartyTpl($path = null, $tpl = null, $subDir = null)
{
if (!$tpl) {
return;
}
$tpl->template_dir = $path . $subDir;
$tpl->compile_dir = "../GPL_LIB/SmartyCache/compile";
$tpl->config_dir = "../GPL_LIB/SmartyCache/config";
$tpl->cache_dir = "../GPL_LIB/SmartyCache/cache";
$tpl->plugins_dir[] = "../GPL_LIB/smarty-plugins";
$tpl->compile_dir = __DIR__ . "/../../../GPL_LIB/SmartyCache/compile";
$tpl->config_dir = __DIR__ . "/../../../GPL_LIB/SmartyCache/config";
$tpl->cache_dir = __DIR__ . "/../../../GPL_LIB/SmartyCache/cache";
$tpl->plugins_dir[] = __DIR__ . "/../../../GPL_LIB/smarty-plugins";
$tpl->caching = 0;
$tpl->compile_check = true;
$tpl->force_compile = true;
return $tpl;
}

function initSmartyTplForPopup($path = null, $tpl = null, $subDir = null, $centreon_path = null)
/**
* This function is mainly used in widgets
*/
function initSmartyTplForPopup($path = null, $tpl = null, $subDir = null, $centreonPath = null)
{
if (!$tpl) {
return;
}
$tpl->template_dir = $path . $subDir;
$tpl->compile_dir = _CENTREON_PATH_ . "/GPL_LIB/SmartyCache/compile";
$tpl->config_dir = _CENTREON_PATH_ . "/GPL_LIB/SmartyCache/config";
$tpl->cache_dir = _CENTREON_PATH_ . "/GPL_LIB/SmartyCache/cache";
$tpl->plugins_dir[] = _CENTREON_PATH_ . "/GPL_LIB/smarty-plugins";
$tpl->caching = 0;
$tpl->compile_check = true;
$tpl->force_compile = true;
return $tpl;
return initSmartyTpl($path, $tpl, $subDir);
}

/*
Expand Down

0 comments on commit e7972a5

Please sign in to comment.