diff options
author | Andreas Gohr <andi@splitbrain.org> | 2007-05-13 14:32:30 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2007-05-13 14:32:30 +0200 |
commit | 176da19b9321f902effc171acbaef8416ba48be3 (patch) | |
tree | 8e8abc45c83d87d6d926eea15cdc05c4df58cf0c | |
parent | a8bd192a380e9ca2870cad0c9ee11ce6a598eadb (diff) | |
download | rpg-176da19b9321f902effc171acbaef8416ba48be3.tar.gz rpg-176da19b9321f902effc171acbaef8416ba48be3.tar.bz2 |
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
-rw-r--r-- | lib/exe/js.php | 25 |
1 files 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"; } } @@ -164,6 +164,27 @@ function js_out(){ } /** + * 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 * * @author Andreas Gohr <andi@splitbrain.org> |