DataObjects/Core_notify.php
[Pman.Core] / Images.php
index 303777b..833a47d 100644 (file)
@@ -59,6 +59,7 @@ class Pman_Core_Images extends Pman
         
         $bits= explode('/', $s);
         $id = 0;
+        
         // without id as first part...
         if (!empty($bits[0]) && $bits[0] == 'Thumb') {
             $this->thumb = true;
@@ -76,7 +77,46 @@ class Pman_Core_Images extends Pman
             $this->size = empty($bits[2]) ? '0x0' : $bits[2];
             $id = empty($bits[3]) ? 0 :   $bits[3];
             
+        } else if (!empty($bits[0]) && $bits[0] == 'events') {
+            
+            $popts = PEAR::getStaticProperty('Pman','options');
+            $ev = DB_DAtaObject::Factory('events');
+            if (!$ev->get($bits[1])) {
+                die("could not find event id");
+            }
+            // technically same user only.. -- normally www-data..
+            if (function_exists('posix_getpwuid')) {
+                $uinfo = posix_getpwuid( posix_getuid () ); 
+                $user = $uinfo['name'];
+            } else {
+                $user = getenv('USERNAME'); // windows.
+            }
+            $ff = HTML_FlexyFramework::get();
+            $file = $ff->Pman['event_log_dir']. '/'. $user. date('/Y/m/d/',strtotime($ev->event_when)). $ev->id . ".json";
+            $filesJ = json_decode(file_get_contents($file));
+         
+            //print_r($filesJ);
+         
+            foreach($filesJ->FILES as $k=>$f){
+                if ($f->tmp_name != $bits[2]) {
+                    continue;
+                }
+                
+                $src = $ff->Pman['event_log_dir']. '/'. $user. date('/Y/m/d/', strtotime($ev->event_when)).  $f->tmp_name ;
+                if (!file_exists($src)) {
+                    die("file was not saved");
+                }
+                header ('Content-Type: ' . $f->type);
+            
+                header("Content-Disposition: attachment; filename=\"".basename($f->name)."\";" );
+                @ob_clean();
+                flush();
+                readfile($src);
+                exit;
+            }
+            die ("unknown file?"); 
         } else {
+        
             $id = empty($bits[0]) ? 0 :  $bits[0];
         }
         
@@ -144,6 +184,10 @@ class Pman_Core_Images extends Pman
     
     function post()
     {
+        
+        if (!$this->authUser) {
+            $this->jerr("image conversion only allowed by registered users");
+        }
         // converts a posted string (eg.svg)
         // into another type..
         if (empty($_REQUEST['as'])) {
@@ -161,7 +205,7 @@ class Pman_Core_Images extends Pman
         $this->mimetype = $_REQUEST['mimetype'];
         require_once 'File/MimeType.php';
         $y = new File_MimeType();
-        $src_ext = $y->toExt($filename);
+        $src_ext = $y->toExt( $this->mimetype );
         
         
         $tmp = $this->tempName($src_ext);
@@ -170,8 +214,16 @@ class Pman_Core_Images extends Pman
         require_once 'File/Convert.php';
         $cv = new File_Convert($tmp, $this->mimetype);
         
-        $cv->convert($this->as_mimetype);
-        $cv->serve();
+        $fn = $cv->convert(
+                $this->as_mimetype ,
+                empty($_REQUEST['width']) ? 0 : $_REQUEST['width'],
+                empty($_REQUEST['height']) ? 0 : $_REQUEST['height']
+        );
+        if (!empty($_REQUEST['as_data'])) {
+            $this->jok(base64_encode(file_get_contents($fn)));
+        }
+        
+        $cv->serve('attachment');
         exit;
         
         
@@ -182,6 +234,8 @@ class Pman_Core_Images extends Pman
  
     function serve($img)
     {
+        $this->sessionState(0); // turn off session... - locking...
+        
         require_once 'File/Convert.php';
         if (!file_exists($img->getStoreName())) {
             //print_r($img);exit;
@@ -201,7 +255,25 @@ class Pman_Core_Images extends Pman
         }
         //echo "SKALING?  $this->size";
         // acutally if we generated the image, then we do not need to validate the size..
-        $this->validateSize();
+        
+        
+        
+        // if the mimetype is not converted..
+        // then the filename should be original.{size}.jpeg
+        $fn = $img->getStoreName() . '.'. $this->size . '.jpeg'; // thumbs are currenly all jpeg.!???
+        
+        if (!file_exists($fn)) {
+            $fn = $img->getStoreName()  . '.'. $this->size . '.'. $img->fileExt();
+            // if it's an image, convert into the same type for thumbnail..
+            if (preg_match('#^image/#', $img->mimetype)) {
+               $this->as_mimetype = $img->mimetype;
+            }
+        }
+        
+        if (!file_exists($fn)) {            
+            
+            $this->validateSize();
+        }
         
         $x->convert( $this->as_mimetype, $this->size);
         $x->serve();
@@ -321,7 +393,7 @@ class Pman_Core_Images extends Pman
         $attr_url = $attr[$attr_name];
         $umatch  = false;
         if(!preg_match('#/(Images|Images/Thumb/[a-z0-9]+|Images/Download)/([0-9]+)/(.*)$#', $attr_url, $umatch))  {
-            continue;
+            return $html;
         }
         $id = $umatch[2];
         $img = DB_DataObject::factory('Images');