DataObjects/Images.php
authorEdward <edward@roojs.com>
Wed, 7 May 2014 06:32:29 +0000 (14:32 +0800)
committerEdward <edward@roojs.com>
Wed, 7 May 2014 06:32:29 +0000 (14:32 +0800)
DataObjects/Images.php

index 7687cfe..f3b99f7 100644 (file)
@@ -96,6 +96,46 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
             $roo->jok($r->URL(-1,'/Images') . '#attachment-'.  $r->id);
         }
         
+        if(isset($q['_auto_save'])){
+            require_once 'System.php';
+            
+            $tmpdir  = System::mktemp("-d auto_save");
+            
+            $path = $tmpdir . '/' . time() . '.json';
+            
+            if(!file_exists($path)){
+               file_put_contents($path, $q['_auto_save'])); 
+            }
+            
+            $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);
+                $path.= ".".$ext;
+            }
+            
+            if (!$this->createFrom($path)) {
+                $roo->jerr("error occour on auto save making image");
+            }
+            
+            if(!empty($q['_return_after_create'])){
+                return;
+            }
+            
+            $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);
+        }
+        
     }