add feed/list command, show help when no feed command given
[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 header('HTTP/1.0 500 Internal Server Error');
9 header('Content-type: text/plain');
10
11 require_once __DIR__ . '/../data/config.php';
12 require_once 'stapibas/autoloader.php';
13
14 if (!isset($_GET['url'])) {
15     header('HTTP/1.0 400 Bad Request');
16     echo "HTTP POST 'url' parameter missing\n";
17     exit(1);
18 }
19 $url = $_GET['url'];
20 if ($url === '') {
21     header('HTTP/1.0 400 Bad Request');
22     echo "'url' parameter is empty\n";
23     exit(1);
24 }
25 if (filter_var($url, FILTER_VALIDATE_URL) === false) {
26     header('HTTP/1.0 400 Bad Request');
27     echo "Invalid URL given\n";
28     exit(1);
29 }
30
31
32 $deps = new Dependencies();
33 $deps->db = new PDO($dbdsn, $dbuser, $dbpass);
34 $deps->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
35 $deps->options = array(
36     'template_dir' => __DIR__ . '/../data/templates/default/'
37 );
38
39 $r = new Renderer_Html($deps);
40 echo $r->render($url);
41 ?>