journal_path .= 'images/'; if (!file_exists($this->journal_path)) { mkdir($this->journal_path); } } public function deleteDir($path) { $path = $this->getPath($path); if ($path === false) return false; try { utils::recurseDelete($this->journal_path . $path); $path = dirname($path); if ($path == '.') return ''; else return $path; } catch (ErrorException $e) { throw new technicalException('Unable to delete dir ' . $this->journal_path . $path); } } public function getList($path = '') { $path = $this->getPath($path); $list = parent::getList($path); if ($list === false) return $list; foreach ($list as $key=>$value) { if ($value['type'] != self::FILE_TYPE_IMAGE && $value['type'] != self::FILE_TYPE_DIR) { unset($list[$key]); } } foreach ($list as &$value) { if ($value['type'] == self::FILE_TYPE_IMAGE) { $value['thumb'] = $this->getThumb($path, $value['filename']); } } return $list; } public function getThumb($path, $filename) { $protocol = !empty($_SERVER['HTTPS']) ? 'https' : 'http'; $thumb = utils::getThumbPath($this->journal_id, ($path ? $path . '/' : $path) . $filename, true); return file_exists(LENCRIER_DATA_ROOT . '/' . $thumb) ? $protocol . '://' . LENCRIER_ADMIN_HOST . '/datas/' . $thumb : false; } public function uploadFile($path, $file, $encoded = false) { if (empty($file['name']) || !($type = self::getFileType($file['name'])) || $type != self::FILE_TYPE_IMAGE) { throw new userException('Le fichier n\'est pas une image'); } $dest = parent::uploadFile($path, $file, $encoded); if (!$dest) { return false; } $im = new Image($this->journal_path . $dest); list($w, $h) = $im->getSize(); $format = $im->format(); if ($w > self::IMAGE_SIZE || $h > self::IMAGE_SIZE) { $im->resize(self::IMAGE_SIZE); $im->save($this->journal_path . $dest); } $thumb = false; $thumb_path = utils::getThumbPath($this->journal_id, $dest); if ($encoded && !empty($file['thumb'])) { if ($this->_processEncodedUpload($file['thumb'])) { unset($file['thumb']['content']); $t = new Image($file['thumb']['tmp_name']); list($tw, $th) = $t->getSize(); unset($t); if ($w <= self::THUMB_SIZE && $h <= self::THUMB_SIZE && rename($file['thumb']['tmp_name'], $thumb_path)) { $thumb = true; } else { unlink($file['thumb']['tmp_name']); } } } if (!$thumb) { $size = ($w < self::THUMB_SIZE && $h < self::THUMB_SIZE) ? ($w > $h ? (int)$w : (int)$h) : self::THUMB_SIZE; $im->resize($size); $im->save($thumb_path, 'jpeg'); } unset($im); return $dest; } } ?>