X-Git-Url: https://git.cweiske.de/anoweco.git/blobdiff_plain/ccb7bb3c75555c01e7dbc78e0b971abc86f3a59d..0199ed68a4be8a55ec06212c466ed6a6f29b78e2:/www/www-header.php diff --git a/www/www-header.php b/www/www-header.php index a221ca5..1b4a685 100644 --- a/www/www-header.php +++ b/www/www-header.php @@ -13,6 +13,55 @@ $twig = new \Twig_Environment( ); //$twig->addExtension(new Twig_Extension_Debug()); +function verifyParameter($givenParams, $paramName) +{ + if (!isset($givenParams[$paramName])) { + error('"' . $paramName . '" parameter missing'); + } + return $givenParams[$paramName]; +} + +function verifyUrlParameter($givenParams, $paramName) +{ + verifyParameter($givenParams, $paramName); + $url = parse_url($givenParams[$paramName]); + if (!isset($url['scheme'])) { + error('Invalid URL in "' . $paramName . '" parameter: scheme missing'); + } + if (!isset($url['host'])) { + error('Invalid URL in "' . $paramName . '" parameter: host missing'); + } + + return $givenParams[$paramName]; +} + +function getOptionalParameter($givenParams, $paramName, $default) +{ + if (!isset($givenParams[$paramName])) { + return $default; + } + return $givenParams[$paramName]; +} + +/** + * Send out an error + * + * @param string $status HTTP status code line + * @param string $code One of the allowed status types: + * - forbidden + * - insufficient_scope + * - invalid_request + * - not_found + * @param string $description + */ +function error($description, $status = 'HTTP/1.0 400 Bad Request') +{ + header($status); + header('Content-Type: text/plain'); + echo $description . "\n"; + exit(1); +} + function render($tplname, $vars = array(), $return = false) { $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');