From 3825ddd38bc5af4afc3ae1a1aea832dde69b21d1 Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Mon, 14 May 2007 00:24:21 +0200 Subject: [PATCH] include_once support for javascript The include syntax was changed and enhanced by a include_once statement. Syntax: /* DOKUWIKI:include somefile.js */ /* DOKUWIKI:include_once someotherfile.js */ Note: include_once uses the basename of the inlcuded file to determine if it was previously loaded. You need to use something unique for it to make sure it is correctly loaded. Note: included files are not checked for updates by the cache logic. You need to touch the master file for updating the cache Note: includes are *not* supported inside included files to avoid any circular references darcs-hash:20070513222421-7ad00-d99d717ba8a428d0af2b3f7d593897e0467cb9c9.gz --- lib/exe/js.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/exe/js.php b/lib/exe/js.php index ca9fc68a8..4b78ade4b 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -165,13 +165,24 @@ function js_out(){ /** * Load the given file, handle include calls and print it + * + * @author Andreas Gohr <andi@splitbrain.org> */ function js_load($file){ if(!@file_exists($file)) return; + static $loaded = array(); $data = io_readFile($file); - while(preg_match('#/\*\s*!!include\s+([\w\./]+)\s*\*/#',$data,$match)){ - $ifile = $match[1]; + while(preg_match('#/\*\s*DOKUWIKI:include(_once)\s+([\w\./]+)\s*\*/#',$data,$match)){ + $ifile = $match[2]; + + // is it a include_once? + if($match[1]){ + $base = basename($ifile); + if($loaded[$base]) continue; + $loaded[$base] = true; + } + if($ifile{0} != '/') $ifile = dirname($file).'/'.$ifile; if(@file_exists($ifile)){ -- GitLab