Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 function cachedImages()
 {
     $ui = posix_getpwuid(posix_geteuid());
     $imageCache = session_save_path() . '/email-cache-' . $ui['name'] . '/mail/' . $this->tableName() . '-' . $this->id . '-images.txt';
     $ids = $this->attachmentIds();
     $fh = fopen($imageCache, 'w');
     $i = DB_DataObject::factory('Images');
     $i->onid = $this->id;
     $i->ontable = $this->tableName();
     $i->whereAddIn('id', $ids, 'int');
     $i->find();
     $images = array();
     require_once 'File/MimeType.php';
     $y = new File_MimeType();
     while ($i->fetch()) {
         if (!file_exists($i->getStoreName()) || !filesize($i->getStoreName())) {
             continue;
         }
         $images["attachment-{$i->id}"] = array('file' => $i->getStoreName(), 'mimetype' => $i->mimetype, 'ext' => $y->toExt($i->mimetype), 'contentid' => "attachment-{$i->id}");
     }
     file_put_contents($imageCache, json_encode($images));
 }
Exemplo n.º 3
0
 function onUploadFromData($data, $roo)
 {
     if (empty($data)) {
         $this->err = "Missing file details";
         return false;
     }
     if ($this->id) {
         $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()) {
             $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', 'image/pjpeg', 'application/x-apple-msg-attachment', 'application/vnd.ms-excel', 'application/csv-tab-delimited-table'))) {
         // 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;
 }
Exemplo n.º 4
0
 function fetchImage($url)
 {
     $this->log("FETCH : {$url}\n");
     if ($url[0] == '/') {
         $ff = HTML_FlexyFramework::get();
         $file = $ff->rootDir . $url;
         require_once 'File/MimeType.php';
         $m = new File_MimeType();
         $mt = $m->fromFilename($file);
         $ext = $m->toExt($mt);
         return array('mimetype' => $mt, 'ext' => $ext, 'contentid' => md5($file), 'file' => $file);
     }
     //print_R($url); exit;
     if (preg_match('#^file:///#', $url)) {
         $file = preg_replace('#^file://#', '', $url);
         require_once 'File/MimeType.php';
         $m = new File_MimeType();
         $mt = $m->fromFilename($file);
         $ext = $m->toExt($mt);
         return array('mimetype' => $mt, 'ext' => $ext, 'contentid' => md5($file), 'file' => $file);
     }
     // CACHE???
     // 2 files --- the info file.. and the actual file...
     // add user
     // unix only...
     $uinfo = posix_getpwuid(posix_getuid());
     $user = $uinfo['name'];
     $cache = ini_get('session.save_path') . "/Pman_Core_Mailer-{$user}/" . md5($url);
     if ($this->cache_images && file_exists($cache) && filemtime($cache) > strtotime('NOW - 1 WEEK')) {
         $ret = json_decode(file_get_contents($cache), true);
         $this->log("fetched from cache");
         $ret['file'] = $cache . '.data';
         return $ret;
     }
     if (!file_exists(dirname($cache))) {
         mkdir(dirname($cache), 0700, true);
     }
     require_once 'HTTP/Request.php';
     $a = new HTTP_Request($this->mapurl($url));
     $a->sendRequest();
     $data = $a->getResponseBody();
     $this->log("got file of size " . strlen($data));
     $this->log("save contentid " . md5($url));
     file_put_contents($cache . '.data', $data);
     $mt = $a->getResponseHeader('Content-Type');
     require_once 'File/MimeType.php';
     $m = new File_MimeType();
     $ext = $m->toExt($mt);
     $ret = array('mimetype' => $mt, 'ext' => $ext, 'contentid' => md5($url));
     file_put_contents($cache, json_encode($ret));
     $ret['file'] = $cache . '.data';
     return $ret;
 }
Exemplo n.º 5
0
 function abitodocx($fn)
 {
     require_once 'File/MimeType.php';
     $fmt = new File_MimeType();
     $fext = $fmt->toExt($this->from);
     $ext = $this->ext;
     $target = str_replace('.', '_', $fn) . '.' . $ext;
     if (file_exists($target) && filesize($target) && filemtime($target) > filemtime($fn)) {
         return $target;
     }
     require_once 'File/Convert/AbiToDocx.php';
     $conv = new File_Convert_AbiToDocx($fn);
     $conv->save($target);
     return file_exists($target) && filesize($target) ? $target : false;
 }