# HG changeset patch # User Tom Fredrik "BFG" Klaussen # Date 1349967925 -7200 # Node ID 63ea1cfd387d9f8006373e9dbb75ea8b18ebff91 # Parent fd3dd497eba6c49af9f8ebfaba31b9bfe6eec94d# Parent 0e157721bbadcc7933f0981de5b0a8ecf995474f Branch merge diff -r fd3dd497eba6 -r 63ea1cfd387d StatusCodes.inc --- /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 @@ +HTTP_CONTINUE + */ + const HTTP_CONTINUE = 100; + /** + * HTTP_SWITCHING_PROTOCOLS + */ + const HTTP_SWITCHING_PROTOCOLS = 101; + + // [Successful 2xx] + /** + * HTTP_OK + */ + const HTTP_OK = 200; + /** + * HTTP_CREATED + */ + const HTTP_CREATED = 201; + /** + * HTTP_ACCEPTED + */ + const HTTP_ACCEPTED = 202; + /** + * HTTP_ACCEPTED + */ + const HTTP_NONAUTHORITATIVE_INFORMATION = 203; + /** + * HTTP_NO_CONTENT + */ + const HTTP_NO_CONTENT = 204; + /** + * HTTP_RESET_CONTENT + */ + const HTTP_RESET_CONTENT = 205; + /** + * HTTP_PARTIAL_CONTENT + */ + const HTTP_PARTIAL_CONTENT = 206; + + // [Redirection 3xx] + /** + * HTTP_MULTIPLE_CHOICES + */ + const HTTP_MULTIPLE_CHOICES = 300; + /** + * HTTP_MOVED_PERMANENTLY + */ + const HTTP_MOVED_PERMANENTLY = 301; + /** + * HTTP_FOUND + */ + const HTTP_FOUND = 302; + /** + * HTTP_SEE_OTHER + */ + const HTTP_SEE_OTHER = 303; + /** + * HTTP_NOT_MODIFIED + */ + const HTTP_NOT_MODIFIED = 304; + /** + * HTTP_USE_PROXY + */ + const HTTP_USE_PROXY = 305; + /** + * HTTP_UNUSED + */ + const HTTP_UNUSED = 306; + /** + * HTTP_TEMPORARY_REDIRECT + */ + const HTTP_TEMPORARY_REDIRECT = 307; + + // [Client Error 4xx] + /** + * Defines the beginning of errorCodes + * @private + */ + const errorCodesBeginAt = 400; + /** + * HTTP_BAD_REQUEST + */ + const HTTP_BAD_REQUEST = 400; + /** + * HTTP_UNAUTHORIZED + */ + const HTTP_UNAUTHORIZED = 401; + /** + * HTTP_PAYMENT_REQUIRED + */ + const HTTP_PAYMENT_REQUIRED = 402; + /** + * HTTP_FORBIDDEN + */ + const HTTP_FORBIDDEN = 403; + /** + * HTTP_NOT_FOUND + */ + const HTTP_NOT_FOUND = 404; + /** + * HTTP_METHOD_NOT_ALLOWED + */ + const HTTP_METHOD_NOT_ALLOWED = 405; + /** + * HTTP_NOT_ACCEPTABLE + */ + const HTTP_NOT_ACCEPTABLE = 406; + /** + * HTTP_PROXY_AUTHENTICATION_REQUIRED + */ + const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; + /** + * HTTP_REQUEST_TIMEOUT + */ + const HTTP_REQUEST_TIMEOUT = 408; + /** + * HTTP_CONFLICT + */ + const HTTP_CONFLICT = 409; + /** + * HTTP_GONE + */ + const HTTP_GONE = 410; + /** + * HTTP_LENGTH_REQUIRED + */ + const HTTP_LENGTH_REQUIRED = 411; + /** + * HTTP_PRECONDITION_FAILED + */ + const HTTP_PRECONDITION_FAILED = 412; + /** + * HTTP_REQUEST_ENTITY_TOO_LARGE + */ + const HTTP_REQUEST_ENTITY_TOO_LARGE = 413; + /** + * HTTP_REQUEST_URI_TOO_LONG + */ + const HTTP_REQUEST_URI_TOO_LONG = 414; + /** + * HTTP_UNSUPPORTED_MEDIA_TYPE + */ + const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; + /** + * HTTP_REQUESTED_RANGE_NOT_SATISFIABLE + */ + const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; + /** + * HTTP_EXPECTATION_FAILED + */ + const HTTP_EXPECTATION_FAILED = 417; + + // [Server Error 5xx] + /** + * HTTP_INTERNAL_SERVER_ERROR + */ + const HTTP_INTERNAL_SERVER_ERROR = 500; + /** + * HTTP_NOT_IMPLEMENTED + */ + const HTTP_NOT_IMPLEMENTED = 501; + /** + * HTTP_BAD_GATEWAY + */ + const HTTP_BAD_GATEWAY = 502; + /** + * HTTP_SERVICE_UNAVAILABLE + */ + const HTTP_SERVICE_UNAVAILABLE = 503; + /** + * HTTP_GATEWAY_TIMEOUT + */ + const HTTP_GATEWAY_TIMEOUT = 504; + /** + * HTTP_VERSION_NOT_SUPPORTED + */ + 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 diff -r fd3dd497eba6 -r 63ea1cfd387d common-functions.inc --- 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) { diff -r fd3dd497eba6 -r 63ea1cfd387d http-response-status-codes.inc --- 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 @@ -HTTP_CONTINUE - */ - const HTTP_CONTINUE = 100; - /** - * HTTP_SWITCHING_PROTOCOLS - */ - const HTTP_SWITCHING_PROTOCOLS = 101; - - // [Successful 2xx] - /** - * HTTP_OK - */ - const HTTP_OK = 200; - /** - * HTTP_CREATED - */ - const HTTP_CREATED = 201; - /** - * HTTP_ACCEPTED - */ - const HTTP_ACCEPTED = 202; - /** - * HTTP_ACCEPTED - */ - const HTTP_NONAUTHORITATIVE_INFORMATION = 203; - /** - * HTTP_NO_CONTENT - */ - const HTTP_NO_CONTENT = 204; - /** - * HTTP_RESET_CONTENT - */ - const HTTP_RESET_CONTENT = 205; - /** - * HTTP_PARTIAL_CONTENT - */ - const HTTP_PARTIAL_CONTENT = 206; - - // [Redirection 3xx] - /** - * HTTP_MULTIPLE_CHOICES - */ - const HTTP_MULTIPLE_CHOICES = 300; - /** - * HTTP_MOVED_PERMANENTLY - */ - const HTTP_MOVED_PERMANENTLY = 301; - /** - * HTTP_FOUND - */ - const HTTP_FOUND = 302; - /** - * HTTP_SEE_OTHER - */ - const HTTP_SEE_OTHER = 303; - /** - * HTTP_NOT_MODIFIED - */ - const HTTP_NOT_MODIFIED = 304; - /** - * HTTP_USE_PROXY - */ - const HTTP_USE_PROXY = 305; - /** - * HTTP_UNUSED - */ - const HTTP_UNUSED = 306; - /** - * HTTP_TEMPORARY_REDIRECT - */ - const HTTP_TEMPORARY_REDIRECT = 307; - - // [Client Error 4xx] - /** - * Defines the beginning of errorCodes - * @private - */ - const errorCodesBeginAt = 400; - /** - * HTTP_BAD_REQUEST - */ - const HTTP_BAD_REQUEST = 400; - /** - * HTTP_UNAUTHORIZED - */ - const HTTP_UNAUTHORIZED = 401; - /** - * HTTP_PAYMENT_REQUIRED - */ - const HTTP_PAYMENT_REQUIRED = 402; - /** - * HTTP_FORBIDDEN - */ - const HTTP_FORBIDDEN = 403; - /** - * HTTP_NOT_FOUND - */ - const HTTP_NOT_FOUND = 404; - /** - * HTTP_METHOD_NOT_ALLOWED - */ - const HTTP_METHOD_NOT_ALLOWED = 405; - /** - * HTTP_NOT_ACCEPTABLE - */ - const HTTP_NOT_ACCEPTABLE = 406; - /** - * HTTP_PROXY_AUTHENTICATION_REQUIRED - */ - const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; - /** - * HTTP_REQUEST_TIMEOUT - */ - const HTTP_REQUEST_TIMEOUT = 408; - /** - * HTTP_CONFLICT - */ - const HTTP_CONFLICT = 409; - /** - * HTTP_GONE - */ - const HTTP_GONE = 410; - /** - * HTTP_LENGTH_REQUIRED - */ - const HTTP_LENGTH_REQUIRED = 411; - /** - * HTTP_PRECONDITION_FAILED - */ - const HTTP_PRECONDITION_FAILED = 412; - /** - * HTTP_REQUEST_ENTITY_TOO_LARGE - */ - const HTTP_REQUEST_ENTITY_TOO_LARGE = 413; - /** - * HTTP_REQUEST_URI_TOO_LONG - */ - const HTTP_REQUEST_URI_TOO_LONG = 414; - /** - * HTTP_UNSUPPORTED_MEDIA_TYPE - */ - const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; - /** - * HTTP_REQUESTED_RANGE_NOT_SATISFIABLE - */ - const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; - /** - * HTTP_EXPECTATION_FAILED - */ - const HTTP_EXPECTATION_FAILED = 417; - - // [Server Error 5xx] - /** - * HTTP_INTERNAL_SERVER_ERROR - */ - const HTTP_INTERNAL_SERVER_ERROR = 500; - /** - * HTTP_NOT_IMPLEMENTED - */ - const HTTP_NOT_IMPLEMENTED = 501; - /** - * HTTP_BAD_GATEWAY - */ - const HTTP_BAD_GATEWAY = 502; - /** - * HTTP_SERVICE_UNAVAILABLE - */ - const HTTP_SERVICE_UNAVAILABLE = 503; - /** - * HTTP_GATEWAY_TIMEOUT - */ - const HTTP_GATEWAY_TIMEOUT = 504; - /** - * HTTP_VERSION_NOT_SUPPORTED - */ - 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 diff -r fd3dd497eba6 -r 63ea1cfd387d index.php --- 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(); diff -r fd3dd497eba6 -r 63ea1cfd387d inputParser.inc --- 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("${title}"); - $parent=$value->parentNode; - $parent->removeChild($value); - $parent->appendChild(new DOMText($tmp->textContent)); - } + $tmp->loadXml("${value}"); + $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("${css}"); - $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("${file_content}"); - $doc = new DOMDocument(); - $doc->loadXml("${out}"); + $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