Mercurial > SimpleWebPresenter
changeset 7:350a8c63bd14
Support for recursive includes.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Fri, 20 May 2011 23:34:33 +0200 |
| parents | 6c0162497d56 |
| children | 19dfa6f3e2be 1ac66bef193a |
| files | index.php |
| diffstat | 1 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/index.php Fri May 20 22:28:03 2011 +0200 +++ b/index.php Fri May 20 23:34:33 2011 +0200 @@ -1,5 +1,7 @@ <?php define(DEBUG,0); +define(MAX_RECURSE,50); + if (DEBUG) { error_reporting(E_ALL); ini_set("display_errors", 1); @@ -43,6 +45,29 @@ $doc = new DOMDocument(); $doc->load($confFile); +$includes=$doc->getElementsByTagName("include"); +$recurse=0; + +while($includes->length>0) { + if(++$recurse>MAX_RECURSE) { + errorPage('Recursion limit exceeded', 500); + } + foreach ($includes as $include) { + $src=$include->getAttribute("src"); + $subdoc = new DOMDocument(); + $subdoc->load("${lang}/${src}"); + $parent=$include->parentNode; + $xml=getElementByTagName($subdoc,"xml"); + foreach($xml->childNodes as $child) { + $text=$subdoc->saveXml($child); + $clonedChild=$doc->importNode($child,true); + $parent->insertBefore($clonedChild,$include); + } + $parent->removeChild($include); + } + $includes=$doc->getElementsByTagName("include"); +} + $head=getElementByTagName($doc,"head"); $title=$head->getAttribute("title");
