Mercurial > SimpleWebPresenter
comparison inputParser.inc @ 60:63ea1cfd387d
Branch merge
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 11 Oct 2012 17:05:25 +0200 |
| parents | 0e157721bbad |
| children | b7efe2ecbc11 |
comparison
equal
deleted
inserted
replaced
| 57:fd3dd497eba6 | 60:63ea1cfd387d |
|---|---|
| 31 } | 31 } |
| 32 } | 32 } |
| 33 return $param_value; | 33 return $param_value; |
| 34 } | 34 } |
| 35 | 35 |
| 36 function getFiles($doc, $options) { | |
| 37 $lang = $options->getLang(); | |
| 38 $conf = $options->getName(); | |
| 39 | |
| 40 $toRemove = array(); | |
| 41 | |
| 42 $topLevelTags = $doc->getElementsByTagName("toplevel"); | |
| 43 foreach ($topLevelTags as $topLevel) { | |
| 44 $topLevel->parentNode->removeChild($topLevel); | |
| 45 } | |
| 46 | |
| 47 $valueDict = array(); | |
| 48 $fragments = array(); | |
| 49 $setters = $doc->getElementsByTagName("set"); | |
| 50 foreach ($setters as $setTag) { | |
| 51 $key = $setTag->getAttribute("id"); | |
| 52 $type = $setTag->getAttribute("type"); | |
| 53 if ($type == "fragment") { | |
| 54 $fragments[$key] = $setTag; | |
| 55 } | |
| 56 else { | |
| 57 $value = $setTag->getAttribute("value"); | |
| 58 if ($key && $value) { | |
| 59 $valueDict[$key] = $value; | |
| 60 } | |
| 61 } | |
| 62 //We need to iterate in the opposite direction when removing, | |
| 63 //so best shifting. | |
| 64 array_unshift($toRemove, $setTag); | |
| 65 } | |
| 66 | |
| 67 $params = $doc->getElementsByTagName("param"); | |
| 68 foreach ($params as $param) { | |
| 69 if ($param->getAttribute("type")=="input_config") { | |
| 70 $id = $param->getAttribute("id"); | |
| 71 if (array_key_exists($id, $valueDict)) { | |
| 72 $value = $valueDict[$id]; | |
| 73 $tmp = new DOMDocument(); | |
| 74 | |
| 75 $tmp->loadXml("<xml>${value}</xml>"); | |
| 76 $parent = $param->parentNode; | |
| 77 $parent->insertBefore(new DOMText($tmp->textContent), $param); | |
| 78 //We need to iterate in the opposite direction when removing, | |
| 79 //so best shifting. | |
| 80 array_unshift($toRemove, $param); | |
| 81 } | |
| 82 elseif (array_key_exists($id, $fragments)) { | |
| 83 $fragment = $fragments[$id]; | |
| 84 | |
| 85 $cloneFragment = $fragment->cloneNode(true); | |
| 86 $insNode = $param; | |
| 87 for ($i = $cloneFragment->childNodes->length - 1; $i >= 0; $i--) { | |
| 88 $child = $cloneFragment->childNodes->item($i); | |
| 89 $child = $child->parentNode->removeChild($child); | |
| 90 $insNode = $insNode->parentNode->insertBefore($child, $insNode); | |
| 91 } | |
| 92 | |
| 93 //We need to iterate in the opposite direction when removing, | |
| 94 //so best shifting. | |
| 95 array_unshift($toRemove, $param); | |
| 96 } | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 foreach($toRemove as $param) { | |
| 101 $parent = $param->parentNode; | |
| 102 $parent->removeChild($param); | |
| 103 } | |
| 104 | |
| 105 $body = getElementByTagName($doc,"body"); | |
| 106 $files = $body->getElementsByTagName("file"); | |
| 107 | |
| 108 $toRemove = array(); | |
| 109 | |
| 110 foreach ($files as $file) { | |
| 111 $script=$file->getAttribute("script"); | |
| 112 if ($script) { | |
| 113 $cacheable = false; | |
| 114 $src=""; | |
| 115 $cwd = getcwd(); | |
| 116 | |
| 117 $matches=array(); | |
| 118 preg_match('/(.*\/)/', $script, $matches); | |
| 119 $dirname=$matches[0]; | |
| 120 preg_match('/([^\/]*)$/', $script, $matches); | |
| 121 $filename=$matches[0]; | |
| 122 chdir("${lang}/${dirname}"); | |
| 123 $pipe=popen("php ${filename}","r"); | |
| 124 $file_content = stream_get_contents($pipe); | |
| 125 chdir("${cwd}"); | |
| 126 } | |
| 127 else { | |
| 128 $src = $file->getAttribute("src"); | |
| 129 $fname = $options->getBasePath() . "/${lang}/${src}"; | |
| 130 $file_content = $options->getCache()->loadFile($fname); | |
| 131 } | |
| 132 if(floatval($file_content)<0) { | |
| 133 errorPage("Resource not found '${lang}/${src}'"); | |
| 134 } | |
| 135 | |
| 136 $filters = $file->getElementsByTagName("filter"); | |
| 137 foreach($filters as $filter) { | |
| 138 $func = $filter->getAttribute("function"); | |
| 139 $params = $filter->getElementsByTagName("param"); | |
| 140 $callString = "\$file_content = ${func}(\$file_content, \$options"; | |
| 141 $param_values = array(); | |
| 142 $i = 0; | |
| 143 foreach ($filter->childNodes as $param) { | |
| 144 if ($param->nodeType == XML_ELEMENT_NODE) | |
| 145 { | |
| 146 $param_value[$i] = getParam($param); | |
| 147 $callString .= ",\$param_value[$i]"; | |
| 148 $i++; | |
| 149 } | |
| 150 } | |
| 151 $callString .= ");"; | |
| 152 eval($callString); | |
| 153 } | |
| 154 $ndoc = new DOMDocument(); | |
| 155 | |
| 156 $ndoc->loadXml("<xml>${file_content}</xml>"); | |
| 157 | |
| 158 $parent = $file->parentNode; | |
| 159 foreach ($ndoc->firstChild->childNodes as $child) { | |
| 160 $clonedChild = $doc->importNode($child, true); | |
| 161 $parent->insertBefore($clonedChild, $file); | |
| 162 } | |
| 163 //We need to iterate in the opposite direction when removing, | |
| 164 //so best shifting. | |
| 165 array_unshift($toRemove, $file); | |
| 166 } | |
| 167 foreach($toRemove as $param) { | |
| 168 $parent = $param->parentNode; | |
| 169 $parent->removeChild($param); | |
| 170 } | |
| 171 | |
| 172 return $doc; | |
| 173 } | |
| 174 | |
| 36 function getInput($master, $param, $options) | 175 function getInput($master, $param, $options) |
| 37 { | 176 { |
| 38 $out = ''; | |
| 39 | |
| 40 $lang = $options->getLang(); | 177 $lang = $options->getLang(); |
| 41 $name = $param->getAttribute("id"); | 178 $name = $param->getAttribute("id"); |
| 42 $conf = $options->getName(); | 179 $conf = $options->getName(); |
| 43 if (!$conf) | 180 if (!$conf) |
| 44 $conf = $param->getAttribute("default"); | 181 $conf = $param->getAttribute("default"); |
| 55 } | 192 } |
| 56 | 193 |
| 57 $includes = $doc->getElementsByTagName("include"); | 194 $includes = $doc->getElementsByTagName("include"); |
| 58 $recurse = 0; | 195 $recurse = 0; |
| 59 | 196 |
| 60 while($includes->length>0) { | 197 while($includes->length > 0) { |
| 61 if(++$recurse > MAX_RECURSE) { | 198 if(++$recurse > MAX_RECURSE) { |
| 62 errorPage('Recursion limit exceeded', 500); | 199 errorPage('Recursion limit exceeded', 500); |
| 63 } | 200 } |
| 64 foreach ($includes as $include) { | 201 foreach ($includes as $include) { |
| 65 $src = $include->getAttribute("src"); | 202 $src = $include->getAttribute("src"); |
| 77 $parent->removeChild($include); | 214 $parent->removeChild($include); |
| 78 } | 215 } |
| 79 $includes = $doc->getElementsByTagName("include"); | 216 $includes = $doc->getElementsByTagName("include"); |
| 80 } | 217 } |
| 81 | 218 |
| 82 $head = getElementByTagName($doc, "head"); | |
| 83 $title = $head->getAttribute("title"); | |
| 84 | |
| 85 if($title) { | |
| 86 $values=$master->getElementsByTagName("param"); | |
| 87 foreach ($values as $value) { | |
| 88 if ($value->getAttribute("type")=="input_config") { | |
| 89 if ($value->getAttribute("id")=="title") { | |
| 90 $tmp = new DOMDocument(); | |
| 91 $tmp->loadXml("<xml>${title}</xml>"); | |
| 92 $parent=$value->parentNode; | |
| 93 $parent->removeChild($value); | |
| 94 $parent->appendChild(new DOMText($tmp->textContent)); | |
| 95 } | |
| 96 } | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 $css = getElementByTagName($head,"css"); | |
| 101 $css = $doc->saveXML($css); | |
| 102 $css = preg_replace('/\s*<\/?\s*css\s*>\s*/s', '', $css); | |
| 103 | |
| 104 if($css) { | |
| 105 $values = $master->getElementsByTagName("param"); | |
| 106 foreach ($values as $value) { | |
| 107 if ($value->getAttribute("type") == "input_config") { | |
| 108 if ($value->getAttribute("id") == "css") { | |
| 109 $tmp = new DOMDocument(); | |
| 110 $tmp->loadXml("<xml>${css}</xml>"); | |
| 111 $parent=$value->parentNode; | |
| 112 foreach($tmp->firstChild->childNodes as $node) { | |
| 113 $clonedChild=$master->importNode($node,true); | |
| 114 $parent->insertBefore($clonedChild,$value); | |
| 115 } | |
| 116 $parent->removeChild($value); | |
| 117 } | |
| 118 } | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 | |
| 123 $body=getElementByTagName($doc,"body"); | |
| 124 $files=$body->getElementsByTagName("file"); | |
| 125 | |
| 126 foreach ($files as $file) { | |
| 127 $script=$file->getAttribute("script"); | |
| 128 if ($script) { | |
| 129 $cacheable = false; | |
| 130 $src=""; | |
| 131 $cwd = getcwd(); | |
| 132 | |
| 133 $matches=array(); | |
| 134 preg_match('/(.*\/)/', $script, $matches); | |
| 135 $dirname=$matches[0]; | |
| 136 preg_match('/([^\/]*)$/', $script, $matches); | |
| 137 $filename=$matches[0]; | |
| 138 chdir("${lang}/${dirname}"); | |
| 139 $pipe=popen("php ${filename}","r"); | |
| 140 $file_content = stream_get_contents($pipe); | |
| 141 chdir("${cwd}"); | |
| 142 } | |
| 143 else { | |
| 144 $src = $file->getAttribute("src"); | |
| 145 $fname = $options->getBasePath() . "/${lang}/${src}"; | |
| 146 $file_content = $options->getCache()->loadFile($fname); | |
| 147 } | |
| 148 if(floatval($file_content)<0) { | |
| 149 errorPage("Resource not found '${lang}/${src}'"); | |
| 150 } | |
| 151 | |
| 152 $filters=$file->getElementsByTagName("filter"); | |
| 153 foreach($filters as $filter) { | |
| 154 $func = $filter->getAttribute("function"); | |
| 155 $params = $filter->getElementsByTagName("param"); | |
| 156 $callString = "\$file_content = ${func}(\$file_content, \$options"; | |
| 157 $param_values = array(); | |
| 158 $i = 0; | |
| 159 foreach ($filter->childNodes as $param) { | |
| 160 if ($param->nodeType == XML_ELEMENT_NODE) | |
| 161 { | |
| 162 $param_value[$i] = getParam($param); | |
| 163 $callString .= ",\$param_value[$i]"; | |
| 164 $i++; | |
| 165 } | |
| 166 } | |
| 167 $callString .= ");"; | |
| 168 eval($callString); | |
| 169 } | |
| 170 $out.= $file_content; | |
| 171 } | |
| 172 | |
| 173 $doc = new DOMDocument(); | |
| 174 $doc->loadXml("<xml>${out}</xml>"); | |
| 175 | |
| 176 return $doc; | 219 return $doc; |
| 177 } | 220 } |
| 178 | |
| 179 ?> | 221 ?> |
