Update SmartyExtend set vars calls with parameter changes
Frontend: drop $cms, add $smarty_data array Backend: if $cms is set content_path options array entry must be set
This commit is contained in:
@@ -462,17 +462,19 @@ class SmartyExtend extends \Smarty
|
|||||||
* g_title :G_TITLE
|
* g_title :G_TITLE
|
||||||
* stylesheet :STYLESHEET
|
* stylesheet :STYLESHEET
|
||||||
* javascript :JAVASCRIPT
|
* javascript :JAVASCRIPT
|
||||||
* @param \CoreLibs\Admin\Backend|null $cms Optinal Admin Backend for
|
* @param array<string,mixed> $smarty_data array of three keys
|
||||||
* smarty variables merge
|
* that hold smarty set strings
|
||||||
|
* HEADER, DATA, DEBUG_DATA
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setSmartyVarsFrontend(
|
public function setSmartyVarsFrontend(
|
||||||
array $options,
|
array $options,
|
||||||
?\CoreLibs\Admin\Backend $cms = null
|
array $smarty_data
|
||||||
): void {
|
): void {
|
||||||
$this->setSmartyVars(
|
$this->setSmartyVars(
|
||||||
false,
|
false,
|
||||||
$cms,
|
$smarty_data,
|
||||||
|
null,
|
||||||
$options['compile_dir'] ?? null,
|
$options['compile_dir'] ?? null,
|
||||||
$options['cache_dir'] ?? null,
|
$options['cache_dir'] ?? null,
|
||||||
$options['js'] ?? null,
|
$options['js'] ?? null,
|
||||||
@@ -484,6 +486,7 @@ class SmartyExtend extends \Smarty
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
$options['stylesheet'] ?? null,
|
$options['stylesheet'] ?? null,
|
||||||
$options['javascript'] ?? null
|
$options['javascript'] ?? null
|
||||||
);
|
);
|
||||||
@@ -503,6 +506,7 @@ class SmartyExtend extends \Smarty
|
|||||||
* admin_stylesheet :ADMIN_STYLESHEET
|
* admin_stylesheet :ADMIN_STYLESHEET
|
||||||
* admin_javascript :ADMIN_JAVASCRIPT
|
* admin_javascript :ADMIN_JAVASCRIPT
|
||||||
* page_width :PAGE_WIDTH
|
* page_width :PAGE_WIDTH
|
||||||
|
* content_path :CONTENT_PATH
|
||||||
* user_name :_SESSION['USER_NAME']
|
* user_name :_SESSION['USER_NAME']
|
||||||
* @param \CoreLibs\Admin\Backend|null $cms Optinal Admin Backend for
|
* @param \CoreLibs\Admin\Backend|null $cms Optinal Admin Backend for
|
||||||
* smarty variables merge
|
* smarty variables merge
|
||||||
@@ -512,8 +516,18 @@ class SmartyExtend extends \Smarty
|
|||||||
array $options,
|
array $options,
|
||||||
?\CoreLibs\Admin\Backend $cms = null
|
?\CoreLibs\Admin\Backend $cms = null
|
||||||
): void {
|
): void {
|
||||||
|
// if we have cms data, check for array blocks and build
|
||||||
|
$smarty_data = [];
|
||||||
|
if ($cms !== null) {
|
||||||
|
$smarty_data = [
|
||||||
|
'HEADER' => $cms->HEADER,
|
||||||
|
'DATA' => $cms->DATA,
|
||||||
|
'DEBUG_DATA' => $cms->DEBUG_DATA
|
||||||
|
];
|
||||||
|
}
|
||||||
$this->setSmartyVars(
|
$this->setSmartyVars(
|
||||||
true,
|
true,
|
||||||
|
$smarty_data,
|
||||||
$cms,
|
$cms,
|
||||||
$options['compile_dir'] ?? null,
|
$options['compile_dir'] ?? null,
|
||||||
$options['cache_dir'] ?? null,
|
$options['cache_dir'] ?? null,
|
||||||
@@ -525,6 +539,7 @@ class SmartyExtend extends \Smarty
|
|||||||
$options['admin_stylesheet'] ?? null,
|
$options['admin_stylesheet'] ?? null,
|
||||||
$options['admin_javascript'] ?? null,
|
$options['admin_javascript'] ?? null,
|
||||||
$options['page_width'] ?? null,
|
$options['page_width'] ?? null,
|
||||||
|
$options['content_path'] ?? null,
|
||||||
$options['user_name'] ?? null,
|
$options['user_name'] ?? null,
|
||||||
null,
|
null,
|
||||||
null
|
null
|
||||||
@@ -537,6 +552,7 @@ class SmartyExtend extends \Smarty
|
|||||||
*
|
*
|
||||||
* @param bool $admin_call default false
|
* @param bool $admin_call default false
|
||||||
* will set admin only variables
|
* will set admin only variables
|
||||||
|
* @param array<string,mixed> $smarty_data smarty data to merge
|
||||||
* @param \CoreLibs\Admin\Backend|null $cms Optinal Admin Backend for
|
* @param \CoreLibs\Admin\Backend|null $cms Optinal Admin Backend for
|
||||||
* smarty variables merge
|
* smarty variables merge
|
||||||
* @param string|null $compile_dir BASE . TEMPLATES_C
|
* @param string|null $compile_dir BASE . TEMPLATES_C
|
||||||
@@ -549,6 +565,7 @@ class SmartyExtend extends \Smarty
|
|||||||
* @param string|null $set_admin_stylesheet ADMIN_STYLESHEET
|
* @param string|null $set_admin_stylesheet ADMIN_STYLESHEET
|
||||||
* @param string|null $set_admin_javascript ADMIN_JAVASCRIPT
|
* @param string|null $set_admin_javascript ADMIN_JAVASCRIPT
|
||||||
* @param string|null $set_page_width PAGE_WIDTH
|
* @param string|null $set_page_width PAGE_WIDTH
|
||||||
|
* @param string|null $set_content_path CONTENT_PATH (only if $cms set and admin)
|
||||||
* @param string|null $set_user_name _SESSION['USER_NAME']
|
* @param string|null $set_user_name _SESSION['USER_NAME']
|
||||||
* @param string|null $set_stylesheet STYLESHEET
|
* @param string|null $set_stylesheet STYLESHEET
|
||||||
* @param string|null $set_javascript JAVASCRIPT
|
* @param string|null $set_javascript JAVASCRIPT
|
||||||
@@ -556,6 +573,7 @@ class SmartyExtend extends \Smarty
|
|||||||
*/
|
*/
|
||||||
private function setSmartyVars(
|
private function setSmartyVars(
|
||||||
bool $admin_call,
|
bool $admin_call,
|
||||||
|
array $smarty_data = [],
|
||||||
?\CoreLibs\Admin\Backend $cms = null,
|
?\CoreLibs\Admin\Backend $cms = null,
|
||||||
?string $compile_dir = null,
|
?string $compile_dir = null,
|
||||||
?string $cache_dir = null,
|
?string $cache_dir = null,
|
||||||
@@ -567,6 +585,7 @@ class SmartyExtend extends \Smarty
|
|||||||
?string $set_admin_stylesheet = null,
|
?string $set_admin_stylesheet = null,
|
||||||
?string $set_admin_javascript = null,
|
?string $set_admin_javascript = null,
|
||||||
?string $set_page_width = null,
|
?string $set_page_width = null,
|
||||||
|
?string $set_content_path = null,
|
||||||
?string $set_user_name = null,
|
?string $set_user_name = null,
|
||||||
?string $set_stylesheet = null,
|
?string $set_stylesheet = null,
|
||||||
?string $set_javascript = null,
|
?string $set_javascript = null,
|
||||||
@@ -593,6 +612,9 @@ class SmartyExtend extends \Smarty
|
|||||||
$set_stylesheet === null ||
|
$set_stylesheet === null ||
|
||||||
$set_javascript === null
|
$set_javascript === null
|
||||||
)
|
)
|
||||||
|
) ||
|
||||||
|
(
|
||||||
|
$admin_call === true && $cms !== null && $set_content_path === null
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
/** @deprecated setSmartyVars call without parameters */
|
/** @deprecated setSmartyVars call without parameters */
|
||||||
@@ -612,25 +634,12 @@ class SmartyExtend extends \Smarty
|
|||||||
$set_admin_stylesheet = $set_admin_stylesheet ?? ADMIN_STYLESHEET;
|
$set_admin_stylesheet = $set_admin_stylesheet ?? ADMIN_STYLESHEET;
|
||||||
$set_admin_javascript = $set_admin_javascript ?? ADMIN_JAVASCRIPT;
|
$set_admin_javascript = $set_admin_javascript ?? ADMIN_JAVASCRIPT;
|
||||||
$set_page_width = $set_page_width ?? PAGE_WIDTH;
|
$set_page_width = $set_page_width ?? PAGE_WIDTH;
|
||||||
|
$set_content_path = $set_content_path ?? CONTENT_PATH;
|
||||||
$set_stylesheet = $set_stylesheet ?? STYLESHEET;
|
$set_stylesheet = $set_stylesheet ?? STYLESHEET;
|
||||||
$set_javascript = $set_javascript ?? JAVASCRIPT;
|
$set_javascript = $set_javascript ?? JAVASCRIPT;
|
||||||
$set_user_name = $set_user_name ?? $_SESSION['USER_NAME'] ?? '';
|
$set_user_name = $set_user_name ?? $_SESSION['USER_NAME'] ?? '';
|
||||||
// depreacte call globals cms on null 4mcs
|
// merge additional smarty data
|
||||||
if (
|
$this->mergeCmsSmartyVars($smarty_data);
|
||||||
$cms === null &&
|
|
||||||
isset($GLOBALS['cms'])
|
|
||||||
) {
|
|
||||||
/** @deprecated setSmartyVars globals cms is deprecated */
|
|
||||||
trigger_error(
|
|
||||||
'Calling setSmartyVars without cms parameter when needed is deprecated',
|
|
||||||
E_USER_DEPRECATED
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// this is ugly
|
|
||||||
$cms = $cms ?? $GLOBALS['cms'] ?? null;
|
|
||||||
if ($cms instanceof \CoreLibs\Admin\Backend) {
|
|
||||||
$this->mergeCmsSmartyVars($cms);
|
|
||||||
}
|
|
||||||
|
|
||||||
// trigger flags
|
// trigger flags
|
||||||
$this->HEADER['USE_PROTOTYPE'] = $this->USE_PROTOTYPE;
|
$this->HEADER['USE_PROTOTYPE'] = $this->USE_PROTOTYPE;
|
||||||
@@ -672,12 +681,27 @@ class SmartyExtend extends \Smarty
|
|||||||
$this->DATA['FORM_ACTION'] = $this->FORM_ACTION;
|
$this->DATA['FORM_ACTION'] = $this->FORM_ACTION;
|
||||||
// special for admin
|
// special for admin
|
||||||
if ($admin_call === true) {
|
if ($admin_call === true) {
|
||||||
|
// depreacte call globals cms on null 4mcs
|
||||||
|
if (
|
||||||
|
$cms === null &&
|
||||||
|
isset($GLOBALS['cms'])
|
||||||
|
) {
|
||||||
|
/** @deprecated setSmartyVars globals cms is deprecated */
|
||||||
|
trigger_error(
|
||||||
|
'Calling setSmartyVars without cms parameter when needed is deprecated',
|
||||||
|
E_USER_DEPRECATED
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// this is ugly
|
||||||
|
$cms = $cms ?? $GLOBALS['cms'] ?? null;
|
||||||
// set ACL extra show
|
// set ACL extra show
|
||||||
if ($cms instanceof \CoreLibs\Admin\Backend) {
|
if ($cms instanceof \CoreLibs\Admin\Backend) {
|
||||||
$this->DATA['show_ea_extra'] = $cms->acl['show_ea_extra'] ?? false;
|
$this->DATA['show_ea_extra'] = $cms->acl['show_ea_extra'] ?? false;
|
||||||
$this->DATA['ADMIN'] = $cms->acl['admin'] ?? 0;
|
$this->DATA['ADMIN'] = $cms->acl['admin'] ?? 0;
|
||||||
// top menu
|
// top menu
|
||||||
$this->DATA['nav_menu'] = $cms->adbTopMenu();
|
$this->DATA['nav_menu'] = $cms->adbTopMenu(
|
||||||
|
$set_content_path
|
||||||
|
);
|
||||||
$this->DATA['nav_menu_count'] = count($this->DATA['nav_menu']);
|
$this->DATA['nav_menu_count'] = count($this->DATA['nav_menu']);
|
||||||
// messages = ['msg' =>, 'class' => 'error/warning/...']
|
// messages = ['msg' =>, 'class' => 'error/warning/...']
|
||||||
$this->DATA['messages'] = $cms->messages;
|
$this->DATA['messages'] = $cms->messages;
|
||||||
@@ -737,18 +761,18 @@ class SmartyExtend extends \Smarty
|
|||||||
/**
|
/**
|
||||||
* merge outside object HEADER/DATA/DEBUG_DATA vars into the smarty class
|
* merge outside object HEADER/DATA/DEBUG_DATA vars into the smarty class
|
||||||
*
|
*
|
||||||
* @param \CoreLibs\Admin\Backend $cms object that has header/data/debug_data
|
* @param array<string,mixed> $smarty_data array that has header/data/debug_data
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function mergeCmsSmartyVars(\CoreLibs\Admin\Backend $cms): void
|
public function mergeCmsSmartyVars(array $smarty_data): void
|
||||||
{
|
{
|
||||||
// array merge HEADER, DATA, DEBUG DATA
|
// array merge HEADER, DATA, DEBUG DATA
|
||||||
foreach (['HEADER', 'DATA', 'DEBUG_DATA'] as $ext_smarty) {
|
foreach (['HEADER', 'DATA', 'DEBUG_DATA'] as $ext_smarty) {
|
||||||
if (
|
if (
|
||||||
isset($cms->{$ext_smarty}) &&
|
isset($smarty_data[$ext_smarty]) &&
|
||||||
is_array($cms->{$ext_smarty})
|
is_array($smarty_data[$ext_smarty])
|
||||||
) {
|
) {
|
||||||
$this->{$ext_smarty} = array_merge($this->{$ext_smarty}, $cms->{$ext_smarty});
|
$this->{$ext_smarty} = array_merge($this->{$ext_smarty}, $smarty_data[$ext_smarty]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user