first working version
[phancap.git] / www / get.php
index 5212e99420a974c3d61b62dd9bca354a7ec8e061..6bb5c7f05cfdc9458e867c4403bf1e4f5b7d50b4 100644 (file)
@@ -3,6 +3,8 @@ namespace phancap;
 /**
  * Get a screenshot for a website.
  */
+header('HTTP/1.0 500 Internal Server Error');
+
 if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
     include_once __DIR__ . '/../src/phancap/Autoloader.php';
     Autoloader::register();
@@ -10,15 +12,30 @@ if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
     include_once 'phancap/Autoloader.php';
 }
 
+$config = new Config();
+$config->setupCheck();
+
 $options = new Options();
 try {
     $options->parse($_GET);
 } catch (\InvalidArgumentException $e) {
     header('HTTP/1.0 400 Bad Request');
     header('Content-type: text/plain');
-    echo $e->getMessage();
+    echo $e->getMessage() . "\n";
     exit(1);
 }
 
-var_dump($options->values);
+$rep = new Repository();
+$rep->setConfig($config);
+try {
+    $img = $rep->getImage($options);
+    header('HTTP/1.0 302 Found');
+    header('Location: ' . $img->getUrl());
+} catch (\Exception $e) {
+    //FIXME: handle 404s and so properly
+    header('HTTP/1.0 500 Internal Server error');
+    header('Content-type: text/plain');
+    echo $e->getMessage() . "\n";
+    exit(2);
+}
 ?>