From 176da19b9321f902effc171acbaef8416ba48be3 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 13 May 2007 14:32:30 +0200 Subject: include support for JavaScript files This patch adds support for include calls in JavaScript files as discussed in [1] The syntax looks like this: /* !!include script.js */ All whitespaces are optional (except between !!include and script of course) [1] http://www.freelists.org/archives/dokuwiki/01-2007/msg00121.html darcs-hash:20070513123230-7ad00-71a1081aaef1e8f6bc909820927f17d0be71b74e.gz --- lib/exe/js.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/exe/js.php b/lib/exe/js.php index a55783a61..ca9fc68a8 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -91,7 +91,7 @@ function js_out(){ // load files foreach($files as $file){ echo "\n\n/* XXXXXXXXXX begin of $file XXXXXXXXXX */\n\n"; - @readfile($file); + js_load($file); echo "\n\n/* XXXXXXXXXX end of $file XXXXXXXXXX */\n\n"; } @@ -132,7 +132,7 @@ function js_out(){ foreach($plugins as $plugin){ if (@file_exists($plugin)) { echo "\n\n/* XXXXXXXXXX begin of $plugin XXXXXXXXXX */\n\n"; - @readfile($plugin); + js_load($plugin); echo "\n\n/* XXXXXXXXXX end of $plugin XXXXXXXXXX */\n\n"; } } @@ -163,6 +163,27 @@ function js_out(){ print $js; } +/** + * Load the given file, handle include calls and print it + */ +function js_load($file){ + if(!@file_exists($file)) return; + + $data = io_readFile($file); + while(preg_match('#/\*\s*!!include\s+([\w\./]+)\s*\*/#',$data,$match)){ + $ifile = $match[1]; + if($ifile{0} != '/') $ifile = dirname($file).'/'.$ifile; + + if(@file_exists($ifile)){ + $idata = io_readFile($ifile); + }else{ + $idata = ''; + } + $data = str_replace($match[0],$idata,$data); + } + echo $data; +} + /** * Checks if a JavaScript Cache file still is valid * -- cgit v1.2.3