2 require __DIR__ . '/../data/config.php';
3 require_once __DIR__ . '/../src/anoweco/autoload.php';
5 header("Access-Control-Allow-Origin: *");
7 $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../data/templates/');
8 $twig = new \Twig_Environment(
11 //'cache' => '/path/to/compilation_cache',
15 //$twig->addExtension(new Twig_Extension_Debug());
17 function verifyParameter($givenParams, $paramName)
19 if (!isset($givenParams[$paramName])) {
20 error('"' . $paramName . '" parameter missing');
22 return $givenParams[$paramName];
25 function verifyUrlParameter($givenParams, $paramName)
27 verifyParameter($givenParams, $paramName);
28 $url = parse_url($givenParams[$paramName]);
29 if (!isset($url['scheme'])) {
30 error('Invalid URL in "' . $paramName . '" parameter: scheme missing');
32 if (!isset($url['host'])) {
33 error('Invalid URL in "' . $paramName . '" parameter: host missing');
36 return $givenParams[$paramName];
39 function getOptionalParameter($givenParams, $paramName, $default)
41 if (!isset($givenParams[$paramName])) {
44 return $givenParams[$paramName];
50 * @param string $status HTTP status code line
51 * @param string $code One of the allowed status types:
53 * - insufficient_scope
56 * @param string $description
58 function error($description, $status = 'HTTP/1.0 400 Bad Request')
61 header('Content-Type: text/plain');
62 echo $description . "\n";
66 function render($tplname, $vars = array(), $return = false)
68 $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm');
71 return $template->render($vars);
73 echo $template->render($vars);