From 10cf78c4ce248cccc029815ed2ced19d64b9920c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= <grosse@cosmocode.de> Date: Thu, 29 Mar 2018 16:27:10 +0200 Subject: [PATCH] refactor: extract $JSINFO initialization into tpl_ function --- doku.php | 4 ---- inc/template.php | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doku.php b/doku.php index d02a43200..0b486e9ed 100644 --- a/doku.php +++ b/doku.php @@ -90,10 +90,6 @@ if($DATE_AT) { //make infos about the selected page available $INFO = pageinfo(); -//export minimal info to JS, plugins can add more -$JSINFO['id'] = $ID; -$JSINFO['namespace'] = (string) $INFO['namespace']; - // handle debugging if($conf['allowdebug'] && $ACT == 'debug') { html_debug(); diff --git a/inc/template.php b/inc/template.php index 7eef41aad..720513b0f 100644 --- a/inc/template.php +++ b/inc/template.php @@ -330,9 +330,7 @@ function tpl_metaheaders($alt = true) { if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { $script .= "var SIG='".toolbar_signature()."';"; } - $JSINFO['ACT'] = act_clean($ACT); - $JSINFO['DOKU_UHN'] = (int) useHeading('navigation'); - $JSINFO['DOKU_UHC'] = (int) useHeading('content'); + _tpl_ensureJSINFO(); $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); @@ -355,6 +353,20 @@ function tpl_metaheaders($alt = true) { return true; } +function _tpl_ensureJSINFO() { + global $JSINFO, $ID, $INFO; + + if (!is_array($JSINFO)) { + $JSINFO = []; + } + //export minimal info to JS, plugins can add more + $JSINFO['id'] = $ID; + $JSINFO['namespace'] = (string) $INFO['namespace']; + $JSINFO['ACT'] = act_clean($ACT); + $JSINFO['DOKU_UHN'] = (int) useHeading('navigation'); + $JSINFO['DOKU_UHC'] = (int) useHeading('content'); +} + /** * prints the array build by tpl_metaheaders * -- GitLab