2 require __DIR__ . '/../data/config.php';
3 require_once __DIR__ . '/../src/anoweco/autoload.php';
5 header("Access-Control-Allow-Origin: *");
7 \Twig_Autoloader::register();
9 $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../data/templates/');
10 $twig = new \Twig_Environment(
13 //'cache' => '/path/to/compilation_cache',
17 //$twig->addExtension(new Twig_Extension_Debug());
19 function verifyParameter($givenParams, $paramName)
21 if (!isset($givenParams[$paramName])) {
22 error('"' . $paramName . '" parameter missing');
24 return $givenParams[$paramName];
27 function verifyUrlParameter($givenParams, $paramName)
29 verifyParameter($givenParams, $paramName);
30 $url = parse_url($givenParams[$paramName]);
31 if (!isset($url['scheme'])) {
32 error('Invalid URL in "' . $paramName . '" parameter: scheme missing');
34 if (!isset($url['host'])) {
35 error('Invalid URL in "' . $paramName . '" parameter: host missing');
38 return $givenParams[$paramName];
41 function getOptionalParameter($givenParams, $paramName, $default)
43 if (!isset($givenParams[$paramName])) {
46 return $givenParams[$paramName];
52 * @param string $status HTTP status code line
53 * @param string $code One of the allowed status types:
55 * - insufficient_scope
58 * @param string $description
60 function error($description, $status = 'HTTP/1.0 400 Bad Request')
63 header('Content-Type: text/plain');
64 echo $description . "\n";
68 function render($tplname, $vars = array(), $return = false)
70 $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
73 return $template->render($vars);
75 echo $template->render($vars);