DataObjects/core.sql
[Pman.Core] / Images.php
index 7a32d67..fcae94e 100644 (file)
@@ -14,7 +14,7 @@
  *      ontable (req) tablename.
  *      filename
  *      (other table args)
- *      as (serve as a type) = eg. mimetype.
+ *      as (serve as a type) = eg. ?as=audio/mpeg 
  * 
  * args: generic
  *     as :(serve as a type) = eg. mimetype.
@@ -140,6 +140,57 @@ class Pman_Core_Images extends Pman
         $this->serve($img);
         exit;
     }
+    
+    
+    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'])) {
+           $this->jerr("missing target type");
+        }
+        if (empty($_REQUEST['mimetype'])) {
+            $this->jerr("missing mimetype");
+        }
+        if (empty($_REQUEST['data'])) {
+            $this->jerr("missing data");
+        }
+        
+        
+        $this->as_mimetype = $_REQUEST['as'];
+        $this->mimetype = $_REQUEST['mimetype'];
+        require_once 'File/MimeType.php';
+        $y = new File_MimeType();
+        $src_ext = $y->toExt( $this->mimetype );
+        
+        
+        $tmp = $this->tempName($src_ext);
+        file_put_contents($tmp, $_REQUEST['data']);
+        
+        require_once 'File/Convert.php';
+        $cv = new File_Convert($tmp, $this->mimetype);
+        
+        $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;
+        
+        
+        
+    }
+    
+    
  
     function serve($img)
     {
@@ -162,7 +213,14 @@ 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.!???
+      // var_dump($fn);
+        if (!file_exists($fn)) {
+            $this->validateSize();
+        }
         
         $x->convert( $this->as_mimetype, $this->size);
         $x->serve();
@@ -228,11 +286,11 @@ class Pman_Core_Images extends Pman
         if (!isset($ff->Pman_Images['public_baseURL'])) {
             return $html;
         }
-        var_dump($ff->Pman_Images['public_baseURL']);
+        //var_dump($ff->Pman_Images['public_baseURL']);
         $baseURL = $ff->Pman_Images['public_baseURL'];
         
         preg_match_all('/<img\s+[^>]+>/i',$html, $result); 
-        print_r($result);
+        //print_r($result);
         $matches = array_unique($result[0]);
         foreach($matches as $img) {
             $imatch = array();
@@ -273,7 +331,7 @@ class Pman_Core_Images extends Pman
     static function replaceImgUrl($html, $baseURL, $tag, $attr, $attr_name) 
     {
         
-        print_R($attr);
+        //print_R($attr);
         // see if it's an image url..
         // Images/{ID}/fullname.xxxx
         // Images/Thumb/200/{ID}/fullname.xxxx
@@ -306,7 +364,7 @@ class Pman_Core_Images extends Pman
                 (empty($attr['width']) ? '0' : $attr['width'] * 1) .
                 'x' .
                 (empty($attr['height']) ? '0' : $attr['height'] * 1);
-            
+             $provider = '/Images/Thumb';
             
         }