3 * Create a website screenshot API
9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2014 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://cweiske.de/phancap.htm
16 header('HTTP/1.0 500 Internal Server Error');
18 if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
19 include_once __DIR__ . '/../src/phancap/Autoloader.php';
20 Autoloader::register();
22 include_once 'phancap/Autoloader.php';
25 $config = new Config();
28 $options = new Options();
30 $options->setConfig($config);
31 $options->parse($_GET);
32 } catch (\InvalidArgumentException $e) {
33 header('HTTP/1.0 400 Bad Request');
34 header('Content-type: text/plain');
35 echo $e->getMessage() . "\n";
39 $auth = new Authenticator();
41 $auth->authenticate($config);
42 } catch (\Exception $e) {
43 header('HTTP/1.0 401 Unauthorized');
44 header('Content-type: text/plain');
45 echo $e->getMessage() . "\n";
49 $rep = new Repository();
50 $rep->setConfig($config);
52 $img = $rep->getImage($options);
53 if ($config->redirect) {
54 header('HTTP/1.0 302 Found');
55 header('Expires: ' . date('r', $img->getExpiryDate($options)));
56 header('Location: ' . $img->getUrl());
58 header('Content-type: ' . $img->getMimeType());
59 readfile($img->getPath());
61 } catch (\Exception $e) {
62 //FIXME: handle 404s and so properly
63 //FIXME: send out error image if images are preferred
64 header('HTTP/1.0 500 Internal Server error');
65 header('Content-type: text/plain');
66 echo $e->getMessage() . "\n";