DataObjects/core.sql
[Pman.Core] / DataObjects / Images.php
index 56285fc..6279e0c 100644 (file)
@@ -58,23 +58,29 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
     {
         if (isset($q['_remote_upload'])) {
             require_once 'System.php';
+            
             $tmpdir  = System::mktemp("-d remote_upload");
             
             $path = $tmpdir . '/' . basename($q['_remote_upload']);
+            
             if(!file_exists($path)){
                file_put_contents($path, file_get_contents($q['_remote_upload'])); 
             }
             
             $imageInfo = getimagesize($path);
+            
             require_once 'File/MimeType.php';
             $y = new File_MimeType();
             $ext = $y->toExt(trim((string) $imageInfo['mime'] ));
             
             if (!preg_match("/\." . $ext."$/", $path, $matches)) {
-                rename($path,$path.$ext);
+                rename($path,$path.".".$ext);
+                $path.= ".".$ext;
             }
             
-            $this->createFrom($path);
+            if (!$this->createFrom($path)) {
+                $roo->jerr("erro making image" . $q['_remote_upload']);
+            }
             
             $roo->addEvent("ADD", $this, $this->toEventString());
         
@@ -295,7 +301,15 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         require_once 'File/MimeType.php';
         $y = new File_MimeType();
         $this->mimetype = $_FILES['imageUpload']['type'];
-        if (in_array($this->mimetype, array('text/application', 'application/octet-stream'))) { // weird tyeps..
+        if (in_array($this->mimetype, array(
+                        'text/application',
+                        'application/octet-stream',
+                        'image/x-png',  // WTF does this?
+                        'image/pjpeg',  // WTF does this?
+                        'application/x-apple-msg-attachment', /// apple doing it's magic...
+                        'application/vnd.ms-excel',   /// sometimes windows reports csv as excel???
+                        'application/csv-tab-delimited-table', // windows again!!?
+                ))) { // weird tyeps..
             $inf = pathinfo($_FILES['imageUpload']['name']);
             $this->mimetype  = $y->fromExt($inf['extension']);
         }
@@ -431,6 +445,17 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         //-- max?
         //$size = max(100, (int) $size);
         //$size = min(1024, (int) $size);
+        // the size should 200x150 to convert
+        $sizear = preg_split('/(x|c)/', $size);
+        if(empty($sizear[1])){
+            $sizear[1] = 0;
+        }
+        $size = implode(strpos($size,'c') > -1 ? 'c' : 'x', $sizear);
+//        print_r($size);
+        $fc = $this->toFileConvert();
+//        print_r($size);
+//        exit;
+        $fc->convert($this->mimetype, $size);
         
         
         return $baseURL . $provider . "/$size/{$this->id}/{$this->filename}";