DataObjects/core.sql
[Pman.Core] / DataObjects / Images.php
index c596f1e..56285fc 100644 (file)
@@ -26,7 +26,6 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
     public $linkurl;                         // string(254)  not_null
     public $descript;                        // blob(65535)  not_null blob
     public $title;                           // string(128)  not_null
-
     
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
@@ -35,14 +34,13 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
     {
         // default permissons are to
         // allow create / edit / if the user has
+        
         if (!$au) {
             
           
             
             return false;
         }
-         
-        
         
         $o = $this->object();
         //print_r($o);
@@ -56,9 +54,39 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         
     }
     
-    
-    
-    
+    function beforeInsert($q, $roo) 
+    {
+        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);
+            }
+            
+            $this->createFrom($path);
+            
+            $roo->addEvent("ADD", $this, $this->toEventString());
+        
+            $r = DB_DataObject::factory($this->tableName());
+            $r->id = $this->id;
+            $roo->loadMap($r);
+            $r->limit(1);
+            $r->find(true);
+            $roo->jok($r->URL(-1,'/Images') . '#attachment-'.  $r->id);
+        }
+        
+    }
     
     
     /**
@@ -150,7 +178,6 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         ));
           
     }
-
      
     /**
      * deletes all the image instances of it...
@@ -228,6 +255,7 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
     }
     
     // direct via roo...
+    /// ctrl not used??
     function onUpload($ctrl)
     {
         
@@ -287,6 +315,8 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
          
     }
      
+    
+    
     /**
      * return a list of images for an object, optionally with a mime regex.
      * eg. '%/pdf' or 'image/%'
@@ -392,8 +422,10 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         if (preg_match('#^http[s]*://#', $provider)) {
             $baseURL = '';
         }
-         var_dump($size < 0);
+       
         if ($size < 0) {
+            $provider = preg_replace('#/Thumb$#', '', $provider);
+            
             return $baseURL . $provider . "/{$this->id}/{$this->filename}";
         }
         //-- max?
@@ -447,6 +479,17 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         return $fc;
         
     }
+    
+    function fileExt()
+    {
+        require_once 'File/MimeType.php';
+        
+        $y = new File_MimeType();
+        return  $y->toExt($this->mimetype);
+        
+        
+    }
+    
     /**
      *
      *
@@ -507,6 +550,8 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
             $roo->jerr("IMAGE UPLOAD PERMISSION DENIED");
         }
         
+        
+        
         if (!isset($_FILES['imageUpload'])) {
             return; // standard update...
         }