Pman/Images.php
[Pman.Base] / Pman / Images.php
index 4a72b39..634c275 100644 (file)
@@ -69,15 +69,21 @@ class Pman_Images extends Pman
             if ((count($onbits) < 2)   || empty($onbits[1]) || !is_numeric($onbits[1]) || !strlen($onbits[0])) {
                 die("Bad url");
             }
+            //DB_DataObject::debugLevel(1);
             $img = DB_DataObjecT::factory('Images');
             $img->ontable = $onbits[0];
             $img->onid = $onbits[1];
+            if (empty($_REQUEST['anytype'])) {
+                $img->whereAdd("mimetype like 'image/%'");
+            }
+            
             if (isset($onbits[2])) {
                 $img->imgtype = $onbits[2];
             }
             $img->limit(1);
             if (!$img->find(true)) {
-                die("no image");
+                header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
+                urlencode("no images for that item: " . htmlspecialchars($id)));
             }
             
             $id = $img->id;
@@ -100,7 +106,8 @@ class Pman_Images extends Pman
             
             $img->limit(1);
             if (!$img->find(true)) {
-                die("No file exists");
+                header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason='. 
+                    urlencode("No file exists"));
             } 
             $id = $img->id;
             
@@ -110,7 +117,9 @@ class Pman_Images extends Pman
        
         $img = DB_DataObjecT::factory('Images');
         if (!$id || !$img->get($id)) {
-            die("image has been removed or deleted.");
+             
+            header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
+                urlencode("image has been removed or deleted."));
         }
         $this->serve($img);
         exit;
@@ -121,6 +130,13 @@ class Pman_Images extends Pman
     function serve($img)
     {
         require_once 'File/Convert.php';
+        if (!file_exists($img->getStoreName())) {
+            //print_r($img);exit;
+            header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
+                urlencode("Original file was missing : " . $img->getStoreName()));
+    
+        }
+        
         $x = new File_Convert($img->getStoreName(), $img->mimetype);
         if (empty($this->as_mimetype)) {
             $this->as_mimetype  = $img->mimetype;
@@ -143,7 +159,9 @@ class Pman_Images extends Pman
     function validateSize()
     {
         if (!in_array($this->size, array(
+               
                 '100', 
+                '100x100', 
                 '150', 
                 '150x150', 
                 '200', 
@@ -151,7 +169,7 @@ class Pman_Images extends Pman
                 '200x200',  
                 '400x0'
             ))) {
-            die("invalid scale");
+            die("invalid scale - ".$this->size);
         }
     }
 }
\ No newline at end of file