Mercurial > SimpleWebPresenter
changeset 60:63ea1cfd387d
Branch merge
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 11 Oct 2012 17:05:25 +0200 |
| parents | fd3dd497eba6 (current diff) 0e157721bbad (diff) |
| children | 13d899b748b7 |
| files | http-response-status-codes.inc |
| diffstat | 5 files changed, 416 insertions(+), 373 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/StatusCodes.inc Thu Oct 11 17:05:25 2012 +0200 @@ -0,0 +1,296 @@ +<?php +/** + * StatusCodes provides named constants for + * HTTP protocol status codes. Written for the + * Recess Framework (http://www.recessframework.com/) + * + * @author Kris Jordan + * @author Tom Fredrik Blenning Klaussen + * @copyright MIT + */ +class StatusCodes +{ + // [Informational 1xx] + /** + * <a href="http://httpstatus.es/100">HTTP_CONTINUE</a> + */ + const HTTP_CONTINUE = 100; + /** + * <a href="http://httpstatus.es/101">HTTP_SWITCHING_PROTOCOLS</a> + */ + const HTTP_SWITCHING_PROTOCOLS = 101; + + // [Successful 2xx] + /** + * <a href="http://httpstatus.es/200">HTTP_OK</a> + */ + const HTTP_OK = 200; + /** + * <a href="http://httpstatus.es/201">HTTP_CREATED</a> + */ + const HTTP_CREATED = 201; + /** + * <a href="http://httpstatus.es/202">HTTP_ACCEPTED</a> + */ + const HTTP_ACCEPTED = 202; + /** + * <a href="http://httpstatus.es/203">HTTP_ACCEPTED</a> + */ + const HTTP_NONAUTHORITATIVE_INFORMATION = 203; + /** + * <a href="http://httpstatus.es/204">HTTP_NO_CONTENT</a> + */ + const HTTP_NO_CONTENT = 204; + /** + * <a href="http://httpstatus.es/205">HTTP_RESET_CONTENT</a> + */ + const HTTP_RESET_CONTENT = 205; + /** + * <a href="http://httpstatus.es/206">HTTP_PARTIAL_CONTENT</a> + */ + const HTTP_PARTIAL_CONTENT = 206; + + // [Redirection 3xx] + /** + * <a href="http://httpstatus.es/300">HTTP_MULTIPLE_CHOICES</a> + */ + const HTTP_MULTIPLE_CHOICES = 300; + /** + * <a href="http://httpstatus.es/301">HTTP_MOVED_PERMANENTLY</a> + */ + const HTTP_MOVED_PERMANENTLY = 301; + /** + * <a href="http://httpstatus.es/302">HTTP_FOUND</a> + */ + const HTTP_FOUND = 302; + /** + * <a href="http://httpstatus.es/303">HTTP_SEE_OTHER</a> + */ + const HTTP_SEE_OTHER = 303; + /** + * <a href="http://httpstatus.es/304">HTTP_NOT_MODIFIED</a> + */ + const HTTP_NOT_MODIFIED = 304; + /** + * <a href="http://httpstatus.es/305">HTTP_USE_PROXY</a> + */ + const HTTP_USE_PROXY = 305; + /** + * <a href="http://httpstatus.es/306">HTTP_UNUSED</a> + */ + const HTTP_UNUSED = 306; + /** + * <a href="http://httpstatus.es/307">HTTP_TEMPORARY_REDIRECT</a> + */ + const HTTP_TEMPORARY_REDIRECT = 307; + + // [Client Error 4xx] + /** + * Defines the beginning of errorCodes + * @private + */ + const errorCodesBeginAt = 400; + /** + * <a href="http://httpstatus.es/400">HTTP_BAD_REQUEST</a> + */ + const HTTP_BAD_REQUEST = 400; + /** + * <a href="http://httpstatus.es/401">HTTP_UNAUTHORIZED</a> + */ + const HTTP_UNAUTHORIZED = 401; + /** + * <a href="http://httpstatus.es/402">HTTP_PAYMENT_REQUIRED</a> + */ + const HTTP_PAYMENT_REQUIRED = 402; + /** + * <a href="http://httpstatus.es/403">HTTP_FORBIDDEN</a> + */ + const HTTP_FORBIDDEN = 403; + /** + * <a href="http://httpstatus.es/404">HTTP_NOT_FOUND</a> + */ + const HTTP_NOT_FOUND = 404; + /** + * <a href="http://httpstatus.es/405">HTTP_METHOD_NOT_ALLOWED</a> + */ + const HTTP_METHOD_NOT_ALLOWED = 405; + /** + * <a href="http://httpstatus.es/406">HTTP_NOT_ACCEPTABLE</a> + */ + const HTTP_NOT_ACCEPTABLE = 406; + /** + * <a href="http://httpstatus.es/407">HTTP_PROXY_AUTHENTICATION_REQUIRED</a> + */ + const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; + /** + * <a href="http://httpstatus.es/408">HTTP_REQUEST_TIMEOUT</a> + */ + const HTTP_REQUEST_TIMEOUT = 408; + /** + * <a href="http://httpstatus.es/409">HTTP_CONFLICT</a> + */ + const HTTP_CONFLICT = 409; + /** + * <a href="http://httpstatus.es/410">HTTP_GONE</a> + */ + const HTTP_GONE = 410; + /** + * <a href="http://httpstatus.es/411">HTTP_LENGTH_REQUIRED</a> + */ + const HTTP_LENGTH_REQUIRED = 411; + /** + * <a href="http://httpstatus.es/412">HTTP_PRECONDITION_FAILED</a> + */ + const HTTP_PRECONDITION_FAILED = 412; + /** + * <a href="http://httpstatus.es/413">HTTP_REQUEST_ENTITY_TOO_LARGE</a> + */ + const HTTP_REQUEST_ENTITY_TOO_LARGE = 413; + /** + * <a href="http://httpstatus.es/414">HTTP_REQUEST_URI_TOO_LONG</a> + */ + const HTTP_REQUEST_URI_TOO_LONG = 414; + /** + * <a href="http://httpstatus.es/415">HTTP_UNSUPPORTED_MEDIA_TYPE</a> + */ + const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; + /** + * <a href="http://httpstatus.es/416">HTTP_REQUESTED_RANGE_NOT_SATISFIABLE</a> + */ + const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; + /** + * <a href="http://httpstatus.es/417">HTTP_EXPECTATION_FAILED</a> + */ + const HTTP_EXPECTATION_FAILED = 417; + + // [Server Error 5xx] + /** + * <a href="http://httpstatus.es/500">HTTP_INTERNAL_SERVER_ERROR</a> + */ + const HTTP_INTERNAL_SERVER_ERROR = 500; + /** + * <a href="http://httpstatus.es/501">HTTP_NOT_IMPLEMENTED</a> + */ + const HTTP_NOT_IMPLEMENTED = 501; + /** + * <a href="http://httpstatus.es/502">HTTP_BAD_GATEWAY</a> + */ + const HTTP_BAD_GATEWAY = 502; + /** + * <a href="http://httpstatus.es/503">HTTP_SERVICE_UNAVAILABLE</a> + */ + const HTTP_SERVICE_UNAVAILABLE = 503; + /** + * <a href="http://httpstatus.es/504">HTTP_GATEWAY_TIMEOUT</a> + */ + const HTTP_GATEWAY_TIMEOUT = 504; + /** + * <a href="http://httpstatus.es/505">HTTP_VERSION_NOT_SUPPORTED</a> + */ + const HTTP_VERSION_NOT_SUPPORTED = 505; + + private static $messages = + array( + // [Informational 1xx] + 100=>'100 Continue', + 101=>'101 Switching Protocols', + + // [Successful 2xx] + 200=>'200 OK', + 201=>'201 Created', + 202=>'202 Accepted', + 203=>'203 Non-Authoritative Information', + 204=>'204 No Content', + 205=>'205 Reset Content', + 206=>'206 Partial Content', + + // [Redirection 3xx] + 300=>'300 Multiple Choices', + 301=>'301 Moved Permanently', + 302=>'302 Found', + 303=>'303 See Other', + 304=>'304 Not Modified', + 305=>'305 Use Proxy', + 306=>'306 (Unused)', + 307=>'307 Temporary Redirect', + + // [Client Error 4xx] + 400=>'400 Bad Request', + 401=>'401 Unauthorized', + 402=>'402 Payment Required', + 403=>'403 Forbidden', + 404=>'404 Not Found', + 405=>'405 Method Not Allowed', + 406=>'406 Not Acceptable', + 407=>'407 Proxy Authentication Required', + 408=>'408 Request Timeout', + 409=>'409 Conflict', + 410=>'410 Gone', + 411=>'411 Length Required', + 412=>'412 Precondition Failed', + 413=>'413 Request Entity Too Large', + 414=>'414 Request-URI Too Long', + 415=>'415 Unsupported Media Type', + 416=>'416 Requested Range Not Satisfiable', + 417=>'417 Expectation Failed', + + // [Server Error 5xx] + 500=>'500 Internal Server Error', + 501=>'501 Not Implemented', + 502=>'502 Bad Gateway', + 503=>'503 Service Unavailable', + 504=>'504 Gateway Timeout', + 505=>'505 HTTP Version Not Supported' + ); + + /** + * Get the header for the specified code. + * + * @param $code Http status code + * @return A textual representation of the header + */ + public static function httpHeaderFor($code) + { + return 'HTTP/1.1 ' . self::$messages[$code]; + } + + /** + * Get a canonical status message for the specified code + * + * @param $code Http status code + * @return Text for the specified code + */ + public static function getMessageForCode($code) + { + return self::$messages[$code]; + } + + /** + * Checks if the specified code is an error code. + * + * @param $code Http status code + * @return bool Answer + */ + public static function isError($code) + { + return is_numeric($code) && $code >= self::HTTP_BAD_REQUEST; + } + + /** + * Can the specified status code have a body? + * + * @param $code Http status code + * @return bool Answer + */ + public static function canHaveBody($code) + { + return + // True if not in 100s + ($code < self::HTTP_CONTINUE || $code >= self::HTTP_OK) + && // and not 204 NO CONTENT + $code != self::HTTP_NO_CONTENT + && // and not 304 NOT MODIFIED + $code != self::HTTP_NOT_MODIFIED; + } +} +?> \ No newline at end of file
--- a/common-functions.inc Thu Oct 11 02:05:09 2012 +0200 +++ b/common-functions.inc Thu Oct 11 17:05:25 2012 +0200 @@ -8,7 +8,7 @@ $baseDir = dirname(__FILE__); $cache = CacheTimeCheck::instance(__FILE__); -$cache->includeOnce('http-response-status-codes.inc', $baseDir); +$cache->includeOnce('StatusCodes.inc', $baseDir); function repMapString($map) {
--- a/http-response-status-codes.inc Thu Oct 11 02:05:09 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,296 +0,0 @@ -<?php -/** - * StatusCodes provides named constants for - * HTTP protocol status codes. Written for the - * Recess Framework (http://www.recessframework.com/) - * - * @author Kris Jordan - * @author Tom Fredrik Blenning Klaussen - * @copyright MIT - */ -class StatusCodes -{ - // [Informational 1xx] - /** - * <a href="http://httpstatus.es/100">HTTP_CONTINUE</a> - */ - const HTTP_CONTINUE = 100; - /** - * <a href="http://httpstatus.es/101">HTTP_SWITCHING_PROTOCOLS</a> - */ - const HTTP_SWITCHING_PROTOCOLS = 101; - - // [Successful 2xx] - /** - * <a href="http://httpstatus.es/200">HTTP_OK</a> - */ - const HTTP_OK = 200; - /** - * <a href="http://httpstatus.es/201">HTTP_CREATED</a> - */ - const HTTP_CREATED = 201; - /** - * <a href="http://httpstatus.es/202">HTTP_ACCEPTED</a> - */ - const HTTP_ACCEPTED = 202; - /** - * <a href="http://httpstatus.es/203">HTTP_ACCEPTED</a> - */ - const HTTP_NONAUTHORITATIVE_INFORMATION = 203; - /** - * <a href="http://httpstatus.es/204">HTTP_NO_CONTENT</a> - */ - const HTTP_NO_CONTENT = 204; - /** - * <a href="http://httpstatus.es/205">HTTP_RESET_CONTENT</a> - */ - const HTTP_RESET_CONTENT = 205; - /** - * <a href="http://httpstatus.es/206">HTTP_PARTIAL_CONTENT</a> - */ - const HTTP_PARTIAL_CONTENT = 206; - - // [Redirection 3xx] - /** - * <a href="http://httpstatus.es/300">HTTP_MULTIPLE_CHOICES</a> - */ - const HTTP_MULTIPLE_CHOICES = 300; - /** - * <a href="http://httpstatus.es/301">HTTP_MOVED_PERMANENTLY</a> - */ - const HTTP_MOVED_PERMANENTLY = 301; - /** - * <a href="http://httpstatus.es/302">HTTP_FOUND</a> - */ - const HTTP_FOUND = 302; - /** - * <a href="http://httpstatus.es/303">HTTP_SEE_OTHER</a> - */ - const HTTP_SEE_OTHER = 303; - /** - * <a href="http://httpstatus.es/304">HTTP_NOT_MODIFIED</a> - */ - const HTTP_NOT_MODIFIED = 304; - /** - * <a href="http://httpstatus.es/305">HTTP_USE_PROXY</a> - */ - const HTTP_USE_PROXY = 305; - /** - * <a href="http://httpstatus.es/306">HTTP_UNUSED</a> - */ - const HTTP_UNUSED = 306; - /** - * <a href="http://httpstatus.es/307">HTTP_TEMPORARY_REDIRECT</a> - */ - const HTTP_TEMPORARY_REDIRECT = 307; - - // [Client Error 4xx] - /** - * Defines the beginning of errorCodes - * @private - */ - const errorCodesBeginAt = 400; - /** - * <a href="http://httpstatus.es/400">HTTP_BAD_REQUEST</a> - */ - const HTTP_BAD_REQUEST = 400; - /** - * <a href="http://httpstatus.es/401">HTTP_UNAUTHORIZED</a> - */ - const HTTP_UNAUTHORIZED = 401; - /** - * <a href="http://httpstatus.es/402">HTTP_PAYMENT_REQUIRED</a> - */ - const HTTP_PAYMENT_REQUIRED = 402; - /** - * <a href="http://httpstatus.es/403">HTTP_FORBIDDEN</a> - */ - const HTTP_FORBIDDEN = 403; - /** - * <a href="http://httpstatus.es/404">HTTP_NOT_FOUND</a> - */ - const HTTP_NOT_FOUND = 404; - /** - * <a href="http://httpstatus.es/405">HTTP_METHOD_NOT_ALLOWED</a> - */ - const HTTP_METHOD_NOT_ALLOWED = 405; - /** - * <a href="http://httpstatus.es/406">HTTP_NOT_ACCEPTABLE</a> - */ - const HTTP_NOT_ACCEPTABLE = 406; - /** - * <a href="http://httpstatus.es/407">HTTP_PROXY_AUTHENTICATION_REQUIRED</a> - */ - const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; - /** - * <a href="http://httpstatus.es/408">HTTP_REQUEST_TIMEOUT</a> - */ - const HTTP_REQUEST_TIMEOUT = 408; - /** - * <a href="http://httpstatus.es/409">HTTP_CONFLICT</a> - */ - const HTTP_CONFLICT = 409; - /** - * <a href="http://httpstatus.es/410">HTTP_GONE</a> - */ - const HTTP_GONE = 410; - /** - * <a href="http://httpstatus.es/411">HTTP_LENGTH_REQUIRED</a> - */ - const HTTP_LENGTH_REQUIRED = 411; - /** - * <a href="http://httpstatus.es/412">HTTP_PRECONDITION_FAILED</a> - */ - const HTTP_PRECONDITION_FAILED = 412; - /** - * <a href="http://httpstatus.es/413">HTTP_REQUEST_ENTITY_TOO_LARGE</a> - */ - const HTTP_REQUEST_ENTITY_TOO_LARGE = 413; - /** - * <a href="http://httpstatus.es/414">HTTP_REQUEST_URI_TOO_LONG</a> - */ - const HTTP_REQUEST_URI_TOO_LONG = 414; - /** - * <a href="http://httpstatus.es/415">HTTP_UNSUPPORTED_MEDIA_TYPE</a> - */ - const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; - /** - * <a href="http://httpstatus.es/416">HTTP_REQUESTED_RANGE_NOT_SATISFIABLE</a> - */ - const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; - /** - * <a href="http://httpstatus.es/417">HTTP_EXPECTATION_FAILED</a> - */ - const HTTP_EXPECTATION_FAILED = 417; - - // [Server Error 5xx] - /** - * <a href="http://httpstatus.es/500">HTTP_INTERNAL_SERVER_ERROR</a> - */ - const HTTP_INTERNAL_SERVER_ERROR = 500; - /** - * <a href="http://httpstatus.es/501">HTTP_NOT_IMPLEMENTED</a> - */ - const HTTP_NOT_IMPLEMENTED = 501; - /** - * <a href="http://httpstatus.es/502">HTTP_BAD_GATEWAY</a> - */ - const HTTP_BAD_GATEWAY = 502; - /** - * <a href="http://httpstatus.es/503">HTTP_SERVICE_UNAVAILABLE</a> - */ - const HTTP_SERVICE_UNAVAILABLE = 503; - /** - * <a href="http://httpstatus.es/504">HTTP_GATEWAY_TIMEOUT</a> - */ - const HTTP_GATEWAY_TIMEOUT = 504; - /** - * <a href="http://httpstatus.es/505">HTTP_VERSION_NOT_SUPPORTED</a> - */ - const HTTP_VERSION_NOT_SUPPORTED = 505; - - private static $messages = - array( - // [Informational 1xx] - 100=>'100 Continue', - 101=>'101 Switching Protocols', - - // [Successful 2xx] - 200=>'200 OK', - 201=>'201 Created', - 202=>'202 Accepted', - 203=>'203 Non-Authoritative Information', - 204=>'204 No Content', - 205=>'205 Reset Content', - 206=>'206 Partial Content', - - // [Redirection 3xx] - 300=>'300 Multiple Choices', - 301=>'301 Moved Permanently', - 302=>'302 Found', - 303=>'303 See Other', - 304=>'304 Not Modified', - 305=>'305 Use Proxy', - 306=>'306 (Unused)', - 307=>'307 Temporary Redirect', - - // [Client Error 4xx] - 400=>'400 Bad Request', - 401=>'401 Unauthorized', - 402=>'402 Payment Required', - 403=>'403 Forbidden', - 404=>'404 Not Found', - 405=>'405 Method Not Allowed', - 406=>'406 Not Acceptable', - 407=>'407 Proxy Authentication Required', - 408=>'408 Request Timeout', - 409=>'409 Conflict', - 410=>'410 Gone', - 411=>'411 Length Required', - 412=>'412 Precondition Failed', - 413=>'413 Request Entity Too Large', - 414=>'414 Request-URI Too Long', - 415=>'415 Unsupported Media Type', - 416=>'416 Requested Range Not Satisfiable', - 417=>'417 Expectation Failed', - - // [Server Error 5xx] - 500=>'500 Internal Server Error', - 501=>'501 Not Implemented', - 502=>'502 Bad Gateway', - 503=>'503 Service Unavailable', - 504=>'504 Gateway Timeout', - 505=>'505 HTTP Version Not Supported' - ); - - /** - * Get the header for the specified code. - * - * @param $code Http status code - * @return A textual representation of the header - */ - public static function httpHeaderFor($code) - { - return 'HTTP/1.1 ' . self::$messages[$code]; - } - - /** - * Get a canonical status message for the specified code - * - * @param $code Http status code - * @return Text for the specified code - */ - public static function getMessageForCode($code) - { - return self::$messages[$code]; - } - - /** - * Checks if the specified code is an error code. - * - * @param $code Http status code - * @return bool Answer - */ - public static function isError($code) - { - return is_numeric($code) && $code >= self::HTTP_BAD_REQUEST; - } - - /** - * Can the specified status code have a body? - * - * @param $code Http status code - * @return bool Answer - */ - public static function canHaveBody($code) - { - return - // True if not in 100s - ($code < self::HTTP_CONTINUE || $code >= self::HTTP_OK) - && // and not 204 NO CONTENT - $code != self::HTTP_NO_CONTENT - && // and not 304 NOT MODIFIED - $code != self::HTTP_NOT_MODIFIED; - } -} -?> \ No newline at end of file
--- a/index.php Thu Oct 11 02:05:09 2012 +0200 +++ b/index.php Thu Oct 11 17:05:25 2012 +0200 @@ -59,6 +59,7 @@ $parent->removeChild($param); } } +$master = getFiles($master, $options); if (CACHING && $cacheable) $options->getCache()->CheckHttpModified();
--- a/inputParser.inc Thu Oct 11 02:05:09 2012 +0200 +++ b/inputParser.inc Thu Oct 11 17:05:25 2012 +0200 @@ -33,95 +33,79 @@ return $param_value; } -function getInput($master, $param, $options) -{ - $out = ''; - +function getFiles($doc, $options) { $lang = $options->getLang(); - $name = $param->getAttribute("id"); $conf = $options->getName(); - if (!$conf) - $conf = $param->getAttribute("default"); - $confFile = $options->getBasePath() . "/${lang}/${conf}.xml"; - $options->getCache()->cache_time($confFile); - $doc = new DOMDocument(); - $doc->load($confFile); + $toRemove = array(); - $toplevel = $doc->getElementsByTagName("toplevel"); - - if(! $toplevel->length) { - errorPage("Resource '${conf}' is not available", 500); + $topLevelTags = $doc->getElementsByTagName("toplevel"); + foreach ($topLevelTags as $topLevel) { + $topLevel->parentNode->removeChild($topLevel); } - $includes = $doc->getElementsByTagName("include"); - $recurse = 0; - - while($includes->length>0) { - if(++$recurse > MAX_RECURSE) { - errorPage('Recursion limit exceeded', 500); + $valueDict = array(); + $fragments = array(); + $setters = $doc->getElementsByTagName("set"); + foreach ($setters as $setTag) { + $key = $setTag->getAttribute("id"); + $type = $setTag->getAttribute("type"); + if ($type == "fragment") { + $fragments[$key] = $setTag; } - foreach ($includes as $include) { - $src = $include->getAttribute("src"); - $subdoc = new DOMDocument(); - $subfile = $options->getBasePath() . "/${lang}/${src}"; - $subdoc->load("$subfile"); - $options->getCache()->cache_time($subfile); - $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); + else { + $value = $setTag->getAttribute("value"); + if ($key && $value) { + $valueDict[$key] = $value; + } } - $includes = $doc->getElementsByTagName("include"); + //We need to iterate in the opposite direction when removing, + //so best shifting. + array_unshift($toRemove, $setTag); } - $head = getElementByTagName($doc, "head"); - $title = $head->getAttribute("title"); + $params = $doc->getElementsByTagName("param"); + foreach ($params as $param) { + if ($param->getAttribute("type")=="input_config") { + $id = $param->getAttribute("id"); + if (array_key_exists($id, $valueDict)) { + $value = $valueDict[$id]; + $tmp = new DOMDocument(); - if($title) { - $values=$master->getElementsByTagName("param"); - foreach ($values as $value) { - if ($value->getAttribute("type")=="input_config") { - if ($value->getAttribute("id")=="title") { - $tmp = new DOMDocument(); - $tmp->loadXml("<xml>${title}</xml>"); - $parent=$value->parentNode; - $parent->removeChild($value); - $parent->appendChild(new DOMText($tmp->textContent)); - } + $tmp->loadXml("<xml>${value}</xml>"); + $parent = $param->parentNode; + $parent->insertBefore(new DOMText($tmp->textContent), $param); + //We need to iterate in the opposite direction when removing, + //so best shifting. + array_unshift($toRemove, $param); + } + elseif (array_key_exists($id, $fragments)) { + $fragment = $fragments[$id]; + + $cloneFragment = $fragment->cloneNode(true); + $insNode = $param; + for ($i = $cloneFragment->childNodes->length - 1; $i >= 0; $i--) { + $child = $cloneFragment->childNodes->item($i); + $child = $child->parentNode->removeChild($child); + $insNode = $insNode->parentNode->insertBefore($child, $insNode); + } + + //We need to iterate in the opposite direction when removing, + //so best shifting. + array_unshift($toRemove, $param); } } } - $css = getElementByTagName($head,"css"); - $css = $doc->saveXML($css); - $css = preg_replace('/\s*<\/?\s*css\s*>\s*/s', '', $css); - - if($css) { - $values = $master->getElementsByTagName("param"); - foreach ($values as $value) { - if ($value->getAttribute("type") == "input_config") { - if ($value->getAttribute("id") == "css") { - $tmp = new DOMDocument(); - $tmp->loadXml("<xml>${css}</xml>"); - $parent=$value->parentNode; - foreach($tmp->firstChild->childNodes as $node) { - $clonedChild=$master->importNode($node,true); - $parent->insertBefore($clonedChild,$value); - } - $parent->removeChild($value); - } - } - } + foreach($toRemove as $param) { + $parent = $param->parentNode; + $parent->removeChild($param); } + $body = getElementByTagName($doc,"body"); + $files = $body->getElementsByTagName("file"); - $body=getElementByTagName($doc,"body"); - $files=$body->getElementsByTagName("file"); + $toRemove = array(); foreach ($files as $file) { $script=$file->getAttribute("script"); @@ -149,7 +133,7 @@ errorPage("Resource not found '${lang}/${src}'"); } - $filters=$file->getElementsByTagName("filter"); + $filters = $file->getElementsByTagName("filter"); foreach($filters as $filter) { $func = $filter->getAttribute("function"); $params = $filter->getElementsByTagName("param"); @@ -167,13 +151,71 @@ $callString .= ");"; eval($callString); } - $out.= $file_content; - } + $ndoc = new DOMDocument(); + + $ndoc->loadXml("<xml>${file_content}</xml>"); - $doc = new DOMDocument(); - $doc->loadXml("<xml>${out}</xml>"); + $parent = $file->parentNode; + foreach ($ndoc->firstChild->childNodes as $child) { + $clonedChild = $doc->importNode($child, true); + $parent->insertBefore($clonedChild, $file); + } + //We need to iterate in the opposite direction when removing, + //so best shifting. + array_unshift($toRemove, $file); + } + foreach($toRemove as $param) { + $parent = $param->parentNode; + $parent->removeChild($param); + } return $doc; } +function getInput($master, $param, $options) +{ + $lang = $options->getLang(); + $name = $param->getAttribute("id"); + $conf = $options->getName(); + if (!$conf) + $conf = $param->getAttribute("default"); + + $confFile = $options->getBasePath() . "/${lang}/${conf}.xml"; + $options->getCache()->cache_time($confFile); + $doc = new DOMDocument(); + $doc->load($confFile); + + $toplevel = $doc->getElementsByTagName("toplevel"); + + if(! $toplevel->length) { + errorPage("Resource '${conf}' is not available", 500); + } + + $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(); + $subfile = $options->getBasePath() . "/${lang}/${src}"; + $subdoc->load("$subfile"); + $options->getCache()->cache_time($subfile); + $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"); + } + + return $doc; +} ?> \ No newline at end of file
