Mercurial > SimpleWebPresenter
comparison index.php @ 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 |
comparison
equal
deleted
inserted
replaced
| 6:6c0162497d56 | 7:350a8c63bd14 |
|---|---|
| 1 <?php | 1 <?php |
| 2 define(DEBUG,0); | 2 define(DEBUG,0); |
| 3 define(MAX_RECURSE,50); | |
| 4 | |
| 3 if (DEBUG) { | 5 if (DEBUG) { |
| 4 error_reporting(E_ALL); | 6 error_reporting(E_ALL); |
| 5 ini_set("display_errors", 1); | 7 ini_set("display_errors", 1); |
| 6 } | 8 } |
| 7 | 9 |
| 41 errorPage("Resource not available"); | 43 errorPage("Resource not available"); |
| 42 } | 44 } |
| 43 $doc = new DOMDocument(); | 45 $doc = new DOMDocument(); |
| 44 $doc->load($confFile); | 46 $doc->load($confFile); |
| 45 | 47 |
| 48 $includes=$doc->getElementsByTagName("include"); | |
| 49 $recurse=0; | |
| 50 | |
| 51 while($includes->length>0) { | |
| 52 if(++$recurse>MAX_RECURSE) { | |
| 53 errorPage('Recursion limit exceeded', 500); | |
| 54 } | |
| 55 foreach ($includes as $include) { | |
| 56 $src=$include->getAttribute("src"); | |
| 57 $subdoc = new DOMDocument(); | |
| 58 $subdoc->load("${lang}/${src}"); | |
| 59 $parent=$include->parentNode; | |
| 60 $xml=getElementByTagName($subdoc,"xml"); | |
| 61 foreach($xml->childNodes as $child) { | |
| 62 $text=$subdoc->saveXml($child); | |
| 63 $clonedChild=$doc->importNode($child,true); | |
| 64 $parent->insertBefore($clonedChild,$include); | |
| 65 } | |
| 66 $parent->removeChild($include); | |
| 67 } | |
| 68 $includes=$doc->getElementsByTagName("include"); | |
| 69 } | |
| 70 | |
| 46 $head=getElementByTagName($doc,"head"); | 71 $head=getElementByTagName($doc,"head"); |
| 47 $title=$head->getAttribute("title"); | 72 $title=$head->getAttribute("title"); |
| 48 | 73 |
| 49 $css=getElementByTagName($head,"css"); | 74 $css=getElementByTagName($head,"css"); |
| 50 $css=$doc->saveXML($css); | 75 $css=$doc->saveXML($css); |
