From 83a482b68691087fcfd636e6b093fd41f52b759a Mon Sep 17 00:00:00 2001
From: Andreas Gohr <gohr@cosmocode.de>
Date: Mon, 26 Oct 2009 12:40:46 +0100
Subject: [PATCH] make $INFO available to JavaScripts

Ignore-this: 372ed5dafd33b16d910edc164dc69fb9

$INFO is now exported as JavaScript variable INFO in the HTML
meta headers. This makes it easier for plugin authors to access
important info about the current page and user from JavaScript.

darcs-hash:20091026114046-6e07b-340f009428322105a5dda72933a66a3719de544d.gz
---
 inc/template.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/inc/template.php b/inc/template.php
index e26c5202a..837b06eb4 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -352,6 +352,14 @@ function tpl_metaheaders($alt=true){
   $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
                              'src'=>DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write);
 
+  // make $INFO available to JavaScripts
+  require_once(DOKU_INC.'inc/JSON.php');
+  $json = new JSON();
+  $infocpy = $INFO;
+  $infocpy['userinfo']['pass'] = '';
+  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=> 'var INFO = '.$json->encode($infocpy).';');
+
+
   // trigger event here
   trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
   return true;
-- 
GitLab