/**
* 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
{
/* 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);
}
$roo->jerr("erro making image" . $q['_remote_upload']);
}
+ if(!empty($q['_return_after_create'])){
+ return;
+ }
+
$roo->addEvent("ADD", $this, $this->toEventString());
$r = DB_DataObject::factory($this->tableName());
}
-
+
/**
* create an email from file.
* these must have been set first.
{
// 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;
}
mkdir($dest, 0775, true);
umask($oldumask);
}
- print_r($file);exit;
+
copy($file,$f);
// fill in details..
return false;
}
if ($tbl->$fld) {
+ HTML_FlexyFramework::get()->page->jerr("updating images is disabled");
+ exit;
$image = DB_DataObject::factory('Images');
$image->get($tbl->$fld);
$image->beforeDelete();
/// 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;
}
if ($this->id) {
+ HTML_FlexyFramework::get()->page->jerr("updating images is disabled");
+ exit;
$this->beforeDelete();
}
if ( empty($this->ontable)) {
$img->find();
while ($img->fetch()) {
+ HTML_FlexyFramework::get()->page->jerr("updating images is disabled");
+ exit;
$img->beforeDelete();
$img->delete();
}
if (!$this->createFrom($_FILES['imageUpload']['tmp_name'])) {
+ $this->err = isset($this->err) ? $this->err : "createFrom Image failed";
return false;
}
return true;
}
$c = clone($this);
- $c->ontable = $obj->tableName();
+ $c->whereAddIn($this->tableName() . '.ontable', array( $obj->tableName(), $obj->__table) , 'string');
$c->onid = $obj->id;
$c->autoJoin();
if (!empty($mime_like)) {
$c->whereAdd("Images.mimetype LIKE '". $c->escape($mime_like) ."'");
}
+ $c->orderBy('created DESC');
return $c->fetchAll();
}
}
- function toRooArray($req = array()) {
- // echo '<PRE>';print_r($req);exit;
+ function toRooArray($req) {
+
$ret= $this->toArray();
static $ff = false;
$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);
$fc = $this->toFileConvert();
// print_r($size);
// exit;
- $fc->convert($this->mimetype, $size);
+ $mt = $this->mimetype;
+ if (!preg_match('#^image/#i',$mt)) {
+ $mt = 'image/jpeg';
+ }
+ $fc->convert($mt, $size);
return $baseURL . $provider . "/$size/{$this->id}/{$this->filename}";
}
}
-
+
+ /**
+ *
+ * #2142 [new] CMS - image link urls
+ *
+ *
+ *
+ */
+ function toLinkHTML($size, $provider = '/Images/Thumb')
+ {
+ if(empty($this->linkurl)){
+ return $this->toHTML($size, $provider = '/Images/Thumb');
+ }
+
+ return '<a href="'.$this->linkurl.'" target="_blank">'.$this->toHTML($size, $provider = '/Images/Thumb').'</a>';
+
+ }
+
+
/**
* to Fileconvert object..
*
// 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());
+ $this->addEvent($ar, $roo);
$r = DB_DataObject::factory($this->tableName());
$r->id = $this->id;
}
+ function addEvent($ar, $roo)
+ {
+ $roo->addEvent("ADD", $this, $this->toEventString());
+ }
+
function toEventString()
{
//$p->toEventString();
}
+ function onUploadFromData($data, $roo)
+ {
+ if (empty($data)) {
+ $this->err = "Missing file details";
+ return false;
+ }
+
+ if ($this->id) {
+ HTML_FlexyFramework::get()->page->jerr("updating images is disabled");
+ exit;
+ $this->beforeDelete();
+ }
+
+ if (empty($this->ontable)) {
+ $this->err = "Missing ontable";
+ 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()) {
+ HTML_FlexyFramework::get()->page->jerr("updating images is disabled");
+ exit;
+ $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;
+ }
+
+ return true;
+
+ }
+
+ function createFromData($data)
+ {
+
+ $this->mimetype= strtolower($this->mimetype);
+
+ if (array_shift(explode('/', $this->mimetype)) == 'image') {
+
+ $imgs = @getimagesize($data);
+
+ if (!empty($imgs) && !empty($imgs[0]) && !empty($imgs[1])) {
+ list($this->width , $this->height) = $imgs;
+ }
+ }
+
+ $this->created = date('Y-m-d H:i:s');
+
+ if (!$this->id) {
+ $this->insert();
+ } else {
+ $this->update();
+ }
+
+ $f = $this->getStoreName();
+ $dest = dirname($f);
+ if (!file_exists($dest)) {
+ $oldumask = umask(0);
+ mkdir($dest, 0775, true);
+ umask($oldumask);
+ }
+
+ file_put_contents($f, file_get_contents("data://" . $data));
+
+ $o = clone($this);
+
+ $this->filesize = filesize($f);
+
+ $this->update($o);
+
+ return true;
+
+ }
+
+ function toBase64()
+ {
+ if(!preg_match('/^image\//', $this->mimetype)){
+ return false;
+ }
+
+ $file = $this->getStoreName();
+
+ if(!file_exists($file)){
+ return false;
+ }
+
+ $data = file_get_contents($file);
+
+ $base64 = 'data:' . $this->mimetype . ';base64,' . base64_encode($data);
+
+ return $base64;
+ }
+
+ function getNumberOfPages()
+ {
+ $ret = false;
+
+ require_once 'System.php';
+
+ switch ($this->mimetype) {
+
+ case 'application/pdf' :
+
+ $file = $this->getStoreName();
+
+ if(!file_exists($file)){
+ return false;
+ }
+
+ $pdftk = System::which('pdftk');
+
+ if (empty($pdftk)) {
+ return false;
+ }
+
+ $cmd = "{$pdftk} dump_data";
+
+ $test = `$cmd`;
+
+ print_R($test);exit;
+
+ break;
+ default :
+ break;
+ }
+
+ return $ret;
+ }
+
}