Mercurial > SimpleWebPresenter
comparison index.php @ 23:814296ea84a9
Move functionality into inputParser.inc
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Wed, 19 Sep 2012 18:23:10 +0200 |
| parents | ccfddd7fba1b |
| children | 5c4d7c758fda |
comparison
equal
deleted
inserted
replaced
| 22:ccfddd7fba1b | 23:814296ea84a9 |
|---|---|
| 19 | 19 |
| 20 include 'php/cache_check.inc'; | 20 include 'php/cache_check.inc'; |
| 21 include_with_mtime('php/accept-language.inc'); | 21 include_with_mtime('php/accept-language.inc'); |
| 22 include_with_mtime('php/filters.inc'); | 22 include_with_mtime('php/filters.inc'); |
| 23 include_with_mtime('php/common-functions.inc'); | 23 include_with_mtime('php/common-functions.inc'); |
| 24 include_with_mtime('php/inputParser.inc'); | |
| 24 | 25 |
| 25 $URL_PARAMS=array('name','lang'); | 26 $URL_PARAMS=array('name','lang'); |
| 26 | 27 |
| 27 #Globals | 28 #Globals |
| 28 $name = $_GET['name']; | 29 $name = $_GET['name']; |
| 43 } | 44 } |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 48 function getParam($param) | |
| 49 { | |
| 50 $param_type=$param->getAttribute("type"); | |
| 51 $param_value; | |
| 52 if (!$param_type) | |
| 53 $param_type="scalar"; | |
| 54 | |
| 55 if($param_type == "scalar") { | |
| 56 $param_subst=$param->getAttribute("subst"); | |
| 57 $param_value=$param->getAttribute("value"); | |
| 58 if ($param_subst) { | |
| 59 /* | |
| 60 $param_value=preg_replace("/name/", $name, $param_subst); | |
| 61 $param_value=preg_replace('/lang/', $lang, $param_value); | |
| 62 */ | |
| 63 } | |
| 64 } | |
| 65 elseif($param_type == "array") { | |
| 66 $params=$param->getElementsByTagName("param"); | |
| 67 $param_value=array(); | |
| 68 foreach ($param->childNodes as $param) { | |
| 69 if ($param->nodeType == XML_ELEMENT_NODE) | |
| 70 { | |
| 71 array_push($param_value, getParam($param)); | |
| 72 } | |
| 73 } | |
| 74 } | |
| 75 return $param_value; | |
| 76 } | |
| 77 | |
| 78 function getInput($master, $param) | |
| 79 { | |
| 80 $out=''; | |
| 81 | |
| 82 $lang=$GLOBALS['lang']; | |
| 83 $name=$param->getAttribute("id"); | |
| 84 $conf=$_GET[$name]; | |
| 85 $GLOBALS[$name]=$conf; | |
| 86 if (!$conf) | |
| 87 $conf=$param->getAttribute("default"); | |
| 88 | |
| 89 $fname = "${lang}/${conf}.xml"; | |
| 90 cache_time($fname); | |
| 91 $config = loadFile($fname); | |
| 92 | |
| 93 $confFile="${lang}/${conf}.xml"; | |
| 94 if (!file_exists($confFile)) { | |
| 95 errorPage("Resource not available"); | |
| 96 } | |
| 97 $doc = new DOMDocument(); | |
| 98 $doc->load($confFile); | |
| 99 | |
| 100 $includes=$doc->getElementsByTagName("include"); | |
| 101 $recurse=0; | |
| 102 | |
| 103 while($includes->length>0) { | |
| 104 if(++$recurse>MAX_RECURSE) { | |
| 105 errorPage('Recursion limit exceeded', 500); | |
| 106 } | |
| 107 foreach ($includes as $include) { | |
| 108 $src=$include->getAttribute("src"); | |
| 109 $subdoc = new DOMDocument(); | |
| 110 $subdoc->load("${lang}/${src}"); | |
| 111 $parent=$include->parentNode; | |
| 112 $xml=getElementByTagName($subdoc,"xml"); | |
| 113 foreach($xml->childNodes as $child) { | |
| 114 $text=$subdoc->saveXml($child); | |
| 115 $clonedChild=$doc->importNode($child,true); | |
| 116 $parent->insertBefore($clonedChild,$include); | |
| 117 } | |
| 118 $parent->removeChild($include); | |
| 119 } | |
| 120 $includes=$doc->getElementsByTagName("include"); | |
| 121 } | |
| 122 | |
| 123 $head=getElementByTagName($doc,"head"); | |
| 124 $title=$head->getAttribute("title"); | |
| 125 | |
| 126 if($title) { | |
| 127 $values=$master->getElementsByTagName("param"); | |
| 128 foreach ($values as $value) { | |
| 129 if ($value->getAttribute("type")=="input_config") { | |
| 130 if ($value->getAttribute("id")=="title") { | |
| 131 $tmp = new DOMDocument(); | |
| 132 $tmp->loadXml("<xml>${title}</xml>"); | |
| 133 $parent=$value->parentNode; | |
| 134 $parent->removeChild($value); | |
| 135 $parent->appendChild(new DOMText($tmp->textContent)); | |
| 136 } | |
| 137 } | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 $css=getElementByTagName($head,"css"); | |
| 142 $css=$doc->saveXML($css); | |
| 143 $css=preg_replace('/\s*<\/?\s*css\s*>\s*/s', '', $css); | |
| 144 | |
| 145 if($css) { | |
| 146 $values=$master->getElementsByTagName("param"); | |
| 147 foreach ($values as $value) { | |
| 148 if ($value->getAttribute("type")=="input_config") { | |
| 149 if ($value->getAttribute("id")=="css") { | |
| 150 $tmp = new DOMDocument(); | |
| 151 $tmp->loadXml("<xml>${css}</xml>"); | |
| 152 $parent=$value->parentNode; | |
| 153 foreach($tmp->firstChild->childNodes as $node) { | |
| 154 $clonedChild=$master->importNode($node,true); | |
| 155 $parent->insertBefore($clonedChild,$value); | |
| 156 } | |
| 157 $parent->removeChild($value); | |
| 158 } | |
| 159 } | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 | |
| 164 $body=getElementByTagName($doc,"body"); | |
| 165 $files=$body->getElementsByTagName("file"); | |
| 166 | |
| 167 foreach ($files as $file) { | |
| 168 $script=$file->getAttribute("script"); | |
| 169 if ($script) { | |
| 170 $cacheable = false; | |
| 171 $src=""; | |
| 172 $cwd=getcwd(); | |
| 173 | |
| 174 $matches=array(); | |
| 175 preg_match('/(.*\/)/', $script, $matches); | |
| 176 $dirname=$matches[0]; | |
| 177 preg_match('/([^\/]*)$/', $script, $matches); | |
| 178 $filename=$matches[0]; | |
| 179 chdir("${lang}/${dirname}"); | |
| 180 $pipe=popen("php ${filename}","r"); | |
| 181 $file_content = stream_get_contents($pipe); | |
| 182 chdir("${cwd}"); | |
| 183 } | |
| 184 else { | |
| 185 $src = $file->getAttribute("src"); | |
| 186 $fname = "${lang}/${src}"; | |
| 187 cache_time($fname); | |
| 188 $file_content = loadFile($fname); | |
| 189 } | |
| 190 if(floatval($file_content)<0) { | |
| 191 errorPage("Resource not found '${lang}/${src}'"); | |
| 192 } | |
| 193 | |
| 194 $filters=$file->getElementsByTagName("filter"); | |
| 195 foreach($filters as $filter) { | |
| 196 $func=$filter->getAttribute("function"); | |
| 197 $params=$filter->getElementsByTagName("param"); | |
| 198 $callString="\$file_content=${func}(\$file_content"; | |
| 199 $param_values=array(); | |
| 200 $i=0; | |
| 201 foreach ($filter->childNodes as $param) { | |
| 202 if ($param->nodeType == XML_ELEMENT_NODE) | |
| 203 { | |
| 204 $param_value[$i]=getParam($param); | |
| 205 $callString.=",\$param_value[$i]"; | |
| 206 $i++; | |
| 207 } | |
| 208 } | |
| 209 $callString.=");"; | |
| 210 eval($callString); | |
| 211 } | |
| 212 $out.= $file_content; | |
| 213 } | |
| 214 | |
| 215 $doc = new DOMDocument(); | |
| 216 $doc->loadXml("<xml>${out}</xml>"); | |
| 217 | |
| 218 return $doc; | |
| 219 } | |
| 220 | |
| 221 $master = new DOMDocument(); | 49 $master = new DOMDocument(); |
| 222 $master->load("master.xml"); | 50 $master->load("master.xml"); |
| 223 | 51 |
| 224 $params=$master->getElementsByTagName("param"); | 52 $params = $master->getElementsByTagName("param"); |
| 225 foreach ($params as $param) { | 53 foreach ($params as $param) { |
| 226 if ($param->getAttribute("type") == "input") { | 54 if ($param->getAttribute("type") == "input") { |
| 227 $doc=getInput($master,$param); | 55 $doc = getInput($master, $param); |
| 228 | 56 |
| 229 $parent=$param->parentNode; | 57 $parent = $param->parentNode; |
| 230 foreach ($doc->firstChild->childNodes as $child) { | 58 foreach ($doc->firstChild->childNodes as $child) { |
| 231 $clonedChild=$master->importNode($child,true); | 59 $clonedChild = $master->importNode($child, true); |
| 232 $parent->insertBefore($clonedChild,$param); | 60 $parent->insertBefore($clonedChild, $param); |
| 233 } | 61 } |
| 234 $parent->removeChild($param); | 62 $parent->removeChild($param); |
| 235 | 63 |
| 236 } | 64 } |
| 237 } | 65 } |
