talk about features
[phancap.git] / www / get.php
index 1da3e8a9de4b77722101196ff4a6d719972205a5..f78c3b5fef988653694e4c88d517d663f5e48b84 100644 (file)
@@ -1,8 +1,18 @@
 <?php
-namespace phancap;
 /**
- * Get a screenshot for a website.
+ * Create a website screenshot API
+ *
+ * PHP version 5
+ *
+ * @category  Tools
+ * @package   Phancap
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link      http://cweiske.de/phancap.htm
  */
+namespace phancap;
+
 header('HTTP/1.0 500 Internal Server Error');
 
 if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
@@ -40,10 +50,17 @@ $rep = new Repository();
 $rep->setConfig($config);
 try {
     $img = $rep->getImage($options);
-    header('HTTP/1.0 302 Found');
-    header('Location: ' . $img->getUrl());
+    if ($config->redirect) {
+        header('HTTP/1.0 302 Found');
+        header('Expires: ' . date('r', $img->getExpiryDate($options)));
+        header('Location: ' . $img->getUrl());
+    } else {
+        header('Content-type: ' . $img->getMimeType());
+        readfile($img->getPath());
+    }
 } catch (\Exception $e) {
     //FIXME: handle 404s and so properly
+    //FIXME: send out error image if images are preferred
     header('HTTP/1.0 500 Internal Server error');
     header('Content-type: text/plain');
     echo $e->getMessage() . "\n";