fix #8131 - chinese translations
[Pman.Core] / Images.php
index 327fa8c..bcedb00 100644 (file)
@@ -78,6 +78,8 @@ class Pman_Core_Images extends Pman
     var $method = 'inline';
     var $page = false;
     var $is_local = false;
+    var $size;
+    
     
     function get($s, $opts=array()) // determin what to serve!!!!
     {
@@ -85,6 +87,8 @@ class Pman_Core_Images extends Pman
         //if (!empty($_GET['_post'])) {
         //   return $this->post();
         //}
+     
+        
         
         $this->is_local = (!empty($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'localhost') ? true : false;
         
@@ -126,7 +130,7 @@ class Pman_Core_Images extends Pman
         }
         
         if (strpos($id,':') > 0) {  // id format  tablename:id:-imgtype
-            
+            //DB_DataObject::debugLevel(1);
             if (!$this->authUser) {
                 $this->imgErr("not-authenticated-using-colon-format",$s);
                 
@@ -183,7 +187,8 @@ class Pman_Core_Images extends Pman
         
         $img = DB_DataObjecT::factory('Images');
          
-        if (!$id || !$img->get($id)) {
+        if (!$id || !$img->get($id) || !$img->exists()) {
+           //print_r($img);           die("HERE");
             $this->imgErr("image has been removed or deleted.",$s);
         }
         
@@ -217,8 +222,9 @@ class Pman_Core_Images extends Pman
     }
     
     function imgErr($reason,$path) {
-        header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
-            urlencode($reason) .'&path='.urlencode($path));
+        header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' . urlencode($reason) );
+        header('X-Error: ' . $reason . ':' . $path);
+        echo $reason . ':' . $path;
         exit;
     }
     
@@ -282,27 +288,27 @@ class Pman_Core_Images extends Pman
  
     function serve($img)
     {
-        $this->sessionState(0); // turn off session... - locking...
         
+        $this->sessionState(0); // turn off session... - locking...
         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()));
-    
+        if (!$img->exists()) {
+            $this->imgErr("serve = missing-image", $img->getStoreName());
+             
         }
 //        print_r($img);exit;
         $x = $img->toFileConvert();
         if (empty($this->as_mimetype) || $img->mimetype == 'image/gif') {
             $this->as_mimetype  = $img->mimetype;
         }
+        
+        
         if (!$this->thumb) {
             if ($x->mimetype == $this->as_mimetype) {
-                $x->serveOnly($this->method);
+                $x->serveOnly($this->method, $img->filename);
                 exit;
             }
             $x->convert( $this->as_mimetype);
-            $x->serve($this->method);
+            $x->serve($this->method, $img->filename);
             exit;
         }
         //echo "SKALING?  $this->size";
@@ -327,6 +333,7 @@ class Pman_Core_Images extends Pman
         if (!file_exists($fn)) {    
             $this->validateSize();
         }
+       
         
         if(!empty($this->page) && !is_nan($this->page * 1)){
             $x->convert( $this->as_mimetype, $this->size, 0, $this->page);
@@ -468,10 +475,10 @@ class Pman_Core_Images extends Pman
     {
         $url = $dom;
         if (!is_string($url)) {
-            $url = $dom->getAttribute($src);
+            $url = $dom->getAttribute('src');
         }
          $umatch  = false;
-        if(!preg_match('#/(Images|Images/Thumb/[a-z0-9]+|Images/Download)/([0-9]+)/(.*)$#', $attr_url, $umatch))  {
+        if(!preg_match('#/(Images|Images/Thumb/[a-z0-9]+|Images/Download)/([0-9]+)/(.*)$#', $url, $umatch))  {
             return $url;
         }
         $id = $umatch[2];
@@ -498,15 +505,15 @@ class Pman_Core_Images extends Pman
         }
         
         $w =  is_string($dom) ? false : $dom->getAttribute('width');
-        $h =  is_string($dom) ? false : $dom->getAttribute('width');
+        $h =  is_string($dom) ? false : $dom->getAttribute('height');
         
-        if (!is_string($dom) && (!empty($w) || !empty($h))
+        if (!is_string($dom) && (!empty($w) || !empty($h) ) && is_numeric($w) && is_numeric($h))
         {
             // no support for %...
             $thumbsize =
-                (empty($w) ? '0' : $w * 1) .
+                (empty($w) ? '0' : intval($w) * 1) .
                 'x' .
-                (empty($h) ? '0' : $h * 1);
+                (empty($h) ? '0' : intval($h) * 1);
              $provider = '/Images/Thumb';
             
         }
@@ -664,4 +671,8 @@ class Pman_Core_Images extends Pman
         }
     }
     
+     
+        
+        
+         
 }