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; } loadLib('image'); $infos = image::identify($this->journal_path . $dest); if ($infos['width'] > self::IMAGE_SIZE || $infos['height'] > self::IMAGE_SIZE) { image::resize($this->journal_path . $dest, $this->journal_path . $dest, self::IMAGE_SIZE); } $thumb = false; $thumb_path = utils::getThumbPath($this->journal_id, $dest); if ($encoded && !empty($file['thumb'])) { if ($this->_processEncodedUpload($file['thumb'])) { unset($file['thumb']['content']); $infos = image::identify($file['thumb']['tmp_name']); if ($infos['format'] && $infos['width'] <= self::THUMB_SIZE && $infos['height'] <= self::THUMB_SIZE && rename($file['thumb']['tmp_name'], $thumb_path)) { $thumb = true; } else { unlink($file['thumb']['tmp_name']); } } } if (!$thumb && $infos['format']) { $size = ($infos['width'] < self::THUMB_SIZE && $infos['height'] < self::THUMB_SIZE) ? ($infos['width'] > $infos['height'] ? (int)$infos['width'] : (int)$infos['height']) : self::THUMB_SIZE; image::resize( $this->journal_path . $dest, $thumb_path, $size, null, array( image::FORCE_OUTPUT_FORMAT => 'JPEG' ) ); } return $dest; } } ?>