X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FImages.php;h=98a6f8159abad63d32f73ea99fe83d382eec2a07;hp=154067bd7b5b24f8a99f93442f9177727e46a1ec;hb=5d4ac076dc4f620fbb91944eead3e0af66216a03;hpb=d69705b2e30a36610b5680afac4c26e3b3b8f6ae diff --git a/DataObjects/Images.php b/DataObjects/Images.php index 154067bd..98a6f815 100644 --- a/DataObjects/Images.php +++ b/DataObjects/Images.php @@ -2,7 +2,7 @@ /** * Table Definition for Images */ -require_once 'DB/DataObject.php'; +class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php'; class Pman_Core_DataObjects_Images extends DB_DataObject { @@ -30,23 +30,20 @@ class Pman_Core_DataObjects_Images extends DB_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - function checkPerm($perm, $au) + function checkPerm($lvl, $au) { // 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')) { + if (method_exists($o, 'checkPerm')) { // edit permissions on related object needed... - return $o->hasPerm( $perm == 'S' ? 'S' : 'E' , $au); + return $o->checkPerm( $lvl == 'S' ? 'S' : 'E' , $au); } @@ -109,6 +106,7 @@ class Pman_Core_DataObjects_Images extends DB_DataObject { // copy the file into the storage area.. if (!file_exists($file) || !filesize($file)) { + $this->err = "File $file did not exist or is 0 size"; return false; } @@ -268,12 +266,22 @@ class Pman_Core_DataObjects_Images extends DB_DataObject /// ctrl not used?? function onUpload($roo) { -// echo $_FILES['imageUpload']['type'];exit; + //print_r($_FILES); echo $_FILES['imageUpload']['type'];exit; if (empty($_FILES['imageUpload']['tmp_name']) || empty($_FILES['imageUpload']['name']) || empty($_FILES['imageUpload']['type']) ) { - $this->err = "Missing file details"; + + $emap = array( + 0=>"There is no error, the file uploaded with success", + 1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", + 2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form" , + 3=>"The uploaded file was only partially uploaded", + 4=>"No file was uploaded", + 6=>"Missing a temporary folder" + ); + $estr = (empty($_FILES['imageUpload']['error']) ? '?': $emap[$_FILES['imageUpload']['error']]); + $this->err = "Missing file details : Error=". $estr; return false; } @@ -327,6 +335,7 @@ class Pman_Core_DataObjects_Images extends DB_DataObject if (!$this->createFrom($_FILES['imageUpload']['tmp_name'])) { + $this->err = isset($this->err) ? $this->err : "createFrom Image failed"; return false; } return true; @@ -393,8 +402,8 @@ class Pman_Core_DataObjects_Images extends DB_DataObject } - function toRooArray($req = array()) { - // echo '
';print_r($req);exit; + function toRooArray($req) { + $ret= $this->toArray(); static $ff = false; @@ -406,7 +415,9 @@ class Pman_Core_DataObjects_Images extends DB_DataObject $ff->Pman_Images['public_baseURL'] : $ff->baseURL; if (!empty($req['query']['imagesize'])) { - $baseURL = isset($req['query']['imageBaseURL']) ? $req['query']['imageBaseURL'] : false; + // query/imageBaseURL ... depricated...? -- set it in config? + + $baseURL = isset($req['query']['imageBaseURL']) ? $req['query']['imageBaseURL'] : $ret['public_baseURL']; $ret['url'] = $this->URL(-1, '/Images/Download',$baseURL); @@ -615,7 +626,7 @@ class Pman_Core_DataObjects_Images extends DB_DataObject // print_r(!$this->onUpload($this)); if ( !$this->onUpload($this)) { - $roo->jerr("File upload failed : ". (!empty($this->err) ? $this->err : '')); + $roo->jerr("File upload failed : error = ". (!empty($this->err) ? $this->err : '')); } $roo->addEvent("ADD", $this, $this->toEventString()); @@ -658,6 +669,43 @@ class Pman_Core_DataObjects_Images extends DB_DataObject return false; } + if (!empty($this->imgtype) && $this->imgtype[0] == '-' && !empty($this->onid)) { + // then its an upload + $img = DB_DataObject::factory('Images'); + $img->onid = $this->onid; + $img->ontable = $this->ontable; + $img->imgtype = $this->imgtype; + + $img->find(); + while ($img->fetch()) { + $img->beforeDelete(); + $img->delete(); + } + + } + + require_once 'File/MimeType.php'; + $y = new File_MimeType(); + + if (in_array($this->mimetype, array( + 'text/application', + 'application/octet-stream', + 'image/x-png', // WTF does this? + 'image/pjpeg', // WTF does this? + 'application/x-apple-msg-attachment', /// apple doing it's magic... + 'application/vnd.ms-excel', /// sometimes windows reports csv as excel??? + 'application/csv-tab-delimited-table', // windows again!!? + ))) { // weird tyeps.. + $inf = pathinfo($this->filename); + $this->mimetype = $y->fromExt($inf['extension']); + } + + $ext = $y->toExt(trim((string) $this->mimetype )); + + if(array_pop(explode('.', $this->filename)) != $ext){ + $this->filename = $this->filename .'.'. $ext; + } + if (!$this->createFromData($data)) { return false; }