add deployment instructions
[phancap.git] / www / get.php
index 4cd2b3a83c994666ae9012b30a1f6f09d36e0bdf..d4b70d3b3d593edf096f5e2beacdbdad768cead0 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')) {
@@ -36,16 +46,29 @@ try {
     exit(1);
 }
 
+if (strpos($_SERVER['HTTP_USER_AGENT'], ' cutycapt ') !== false) {
+    //phancap is trying to render a page with an image that
+    // is being fetched from phancap itself, leading to an
+    // infinite loop
+    header('HTTP/1.0 500 Infinite Loop');
+    header('Location: ' . $config->getCurrentUrlDir() . '/infinite.png');
+    exit(3);
+}
+
 $rep = new Repository();
 $rep->setConfig($config);
 try {
     $img = $rep->getImage($options);
     if ($config->redirect) {
         header('HTTP/1.0 302 Found');
+        header('phancap-file: ' . $img->name);
         header('Expires: ' . date('r', $img->getExpiryDate($options)));
         header('Location: ' . $img->getUrl());
     } else {
-        header('Content-type: ' . $img->getMimeType());
+        header('HTTP/1.0 200 OK');
+        header('phancap-file: ' . $img->name);
+        header('Content-Type: ' . $img->getMimeType());
+        header('Content-Length: ' . filesize($img->getPath()));
         readfile($img->getPath());
     }
 } catch (\Exception $e) {