Skip to content

Commit

Permalink
refactor: rename and move function to set $JSINFO
Browse files Browse the repository at this point in the history
This is a more consistent place relative to pageinfo()
  • Loading branch information
micgro42 committed Apr 5, 2018
1 parent 7bf3190 commit 0c39d46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
17 changes: 17 additions & 0 deletions inc/common.php
Expand Up @@ -300,6 +300,23 @@ function pageinfo() {
return $info;
}

/**
* Initialize and/or fill global $JSINFO with some basic info to be given to javascript
*/
function jsinfo() {
global $JSINFO, $ID, $INFO, $ACT;

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['useHeadingNavigation'] = (int) useHeading('navigation');
$JSINFO['useHeadingContent'] = (int) useHeading('content');
}

/**
* Return information about the current media item as an associative array.
*
Expand Down
16 changes: 1 addition & 15 deletions inc/template.php
Expand Up @@ -328,7 +328,7 @@ function tpl_metaheaders($alt = true) {
if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
$script .= "var SIG='".toolbar_signature()."';";
}
_tpl_ensureJSINFO();
jsinfo();
$script .= 'var JSINFO = ' . json_encode($JSINFO).';';
$head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);

Expand All @@ -351,20 +351,6 @@ function tpl_metaheaders($alt = true) {
return true;
}

function _tpl_ensureJSINFO() {
global $JSINFO, $ID, $INFO, $ACT;

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['useHeadingNavigation'] = (int) useHeading('navigation');
$JSINFO['useHeadingContent'] = (int) useHeading('content');
}

/**
* prints the array build by tpl_metaheaders
*
Expand Down

0 comments on commit 0c39d46

Please sign in to comment.