use central include file
[stapibas.git] / www / render.php
1 <?php
2 namespace stapibas;
3 /**
4  * Render the bookmarks/comments/links for a given URL
5  *
6  * @param string $url URL to get content for
7  */
8 require_once 'www-header.php';
9
10 if (!isset($_GET['url'])) {
11     header('HTTP/1.0 400 Bad Request');
12     echo "HTTP POST 'url' parameter missing\n";
13     exit(1);
14 }
15 $url = $_GET['url'];
16 if ($url === '') {
17     header('HTTP/1.0 400 Bad Request');
18     echo "'url' parameter is empty\n";
19     exit(1);
20 }
21 if (filter_var($url, FILTER_VALIDATE_URL) === false) {
22     header('HTTP/1.0 400 Bad Request');
23     echo "Invalid URL given\n";
24     exit(1);
25 }
26
27
28 $deps = new Dependencies();
29 $deps->db = new PDO($dbdsn, $dbuser, $dbpass);
30 $deps->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
31 $deps->options = array(
32     'template_dir' => __DIR__ . '/../data/templates/default/'
33 );
34
35 $r = new Renderer_Html($deps);
36 echo $r->render($url);
37 ?>