Merge branch 'master' of http://git.roojs.com:8081/Pman.Core
[Pman.Core] / DataObjects / Images.php
index 325c410..446fda1 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,13 +34,16 @@ 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);
         if (method_exists($o, 'hasPerm')) {
             // edit permissions on related object needed...
             return $o->hasPerm( $perm == 'S' ? 'S' : 'E' , $au);
@@ -111,9 +113,12 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         $f = $this->getStoreName();
         $dest = dirname($f);
         if (!file_exists($dest)) {
-            
+            // currently this is 0775 due to problems using shared hosing (FTP)
+            // it makes all the files unaccessable..
+            // you can normally solve this by giving the storedirectory better perms
+            // if needed on a dedicated server..
             $oldumask = umask(0);
-            mkdir($dest, 0770, true);
+            mkdir($dest, 0775, true);
             umask($oldumask);  
         }
         
@@ -143,7 +148,6 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         ));
           
     }
-
      
     /**
      * deletes all the image instances of it...
@@ -221,6 +225,7 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
     }
     
     // direct via roo...
+    /// ctrl not used??
     function onUpload($ctrl)
     {
         
@@ -280,6 +285,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/%'
@@ -322,10 +329,15 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
     function object($obj=false)
     {
         if ($obj === false) {
+            if (empty($this->ontable) || empty($this->onid)) {
+                return false;
+            }
             $ret = DB_DataObject::factory($this->ontable);
             $ret->get($this->onid);
             return $ret;
         }
+        
+        
         $this->ontable = $obj->tableName();
         $this->onid = $obj->id; /// assumes our nice standard of using ids..
         return $obj;
@@ -336,7 +348,14 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
       //  echo '<PRE>';print_r($req);exit;
         $ret= $this->toArray();
       
-      
+        static $ff = false;
+        if (!$ff) {
+            $ff = HTML_FlexyFramework::get();
+        }
+        
+        $ret['public_baseURL'] = isset($ff->Pman_Images['public_baseURL']) ?
+                    $ff->Pman_Images['public_baseURL'] : $ff->baseURL;
+        
         if (!empty($req['query']['imagesize'])) {
              $baseURL = isset($req['query']['imageBaseURL']) ? $req['query']['imageBaseURL'] : false;
             
@@ -370,7 +389,13 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
 
         $ff = HTML_FlexyFramework::get();
         $baseURL = $baseURL ? $baseURL : $ff->baseURL ;
+        if (preg_match('#^http[s]*://#', $provider)) {
+            $baseURL = '';
+        }
+       
         if ($size < 0) {
+            $provider = preg_replace('#/Thumb$#', '', $provider);
+            
             return $baseURL . $provider . "/{$this->id}/{$this->filename}";
         }
         //-- max?
@@ -405,9 +430,32 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
             $sy = $sz[1];
         }
         // create it?
+         
+        return '<img src="' . $this->URL($size, $provider) . '" width="'. $sx . '" height="'. $sy . '">';
         
         
-        return '<img src="' . $this->URL($size, $provider) . '" width="'. $sx . '" height="'. $sy . '">';
+    }
+     
+    /**
+     * to Fileconvert object..
+     *
+     *
+     *
+     */
+    function toFileConvert()
+    {
+        require_once 'File/Convert.php';
+        $fc = new File_Convert($this->getStoreName(), $this->mimetype);
+        return $fc;
+        
+    }
+    
+    function fileExt()
+    {
+        require_once 'File/MimeType.php';
+        
+        $y = new File_MimeType();
+        return  $y->toExt($this->mimetype);
         
         
     }
@@ -438,6 +486,11 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
             
         
         if (!empty($ar['_copy_from'])) {
+            
+            if (!$this->checkPerm( 'A' , $roo->authUser))  {
+                $roo->jerr("IMAGE UPLOAD PERMISSION DENIED");
+            }
+            
             $copy = DB_DataObject::factory('Images');
             $copy->get($ar['_copy_from']);
             $this->setFrom($copy->toArray());
@@ -463,8 +516,8 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         // this should be doign update
         $this->setFrom($ar);
          
-        $this->checkPerm($this->id ? 'A' ? 'E', $this->authUser))  {
-            $this->jerr("IMAGE UPLOAD PERMISSION DENIED");
+        if (!$this->checkPerm($this->id ? 'A' : 'E', $roo->authUser))  {
+            $roo->jerr("IMAGE UPLOAD PERMISSION DENIED");
         }
         
         if (!isset($_FILES['imageUpload'])) {
@@ -474,6 +527,7 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         if ( !$this->onUpload($this)) {
             $roo->jerr("File upload failed : ". $this->err);
         }
+        
         $roo->addEvent("ADD", $this, $this->toEventString());
         
         $r = DB_DataObject::factory($this->tableName());