4 * Get a screenshot for a website.
6 header('HTTP/1.0 500 Internal Server Error');
8 if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
9 include_once __DIR__ . '/../src/phancap/Autoloader.php';
10 Autoloader::register();
12 include_once 'phancap/Autoloader.php';
15 $config = new Config();
18 $options = new Options();
20 $options->setConfig($config);
21 $options->parse($_GET);
22 } catch (\InvalidArgumentException $e) {
23 header('HTTP/1.0 400 Bad Request');
24 header('Content-type: text/plain');
25 echo $e->getMessage() . "\n";
29 $auth = new Authenticator();
31 $auth->authenticate($config);
32 } catch (\Exception $e) {
33 header('HTTP/1.0 401 Unauthorized');
34 header('Content-type: text/plain');
35 echo $e->getMessage() . "\n";
39 $rep = new Repository();
40 $rep->setConfig($config);
42 $img = $rep->getImage($options);
43 if ($config->redirect) {
44 header('HTTP/1.0 302 Found');
45 header('Location: ' . $img->getUrl());
47 header('Content-type: ' . $img->getMimeType());
48 readfile($img->getPath());
50 } catch (\Exception $e) {
51 //FIXME: handle 404s and so properly
52 header('HTTP/1.0 500 Internal Server error');
53 header('Content-type: text/plain');
54 echo $e->getMessage() . "\n";