Merge pull request #246 from kkigomi/feature/cheditor-hook-get_editor_upload_url

CHEditor에서 이미지 업로드시 get_editor_upload_url Hook에 파일의 정보 추가
This commit is contained in:
thisgun
2023-07-17 11:47:37 +09:00
committed by GitHub

View File

@ -6,8 +6,8 @@ if(!function_exists('ft_nonce_is_valid')){
}
if (!function_exists('che_reprocessImage')) {
function che_reprocessImage($file_path, $callback){
function che_reprocessImage($file_path, $callback)
{
$MIME_TYPES_PROCESSORS = array(
"image/gif" => array("imagecreatefromgif", "imagegif"),
"image/jpg" => array("imagecreatefromjpeg", "imagejpeg"),
@ -108,7 +108,7 @@ if (!$imgsize) {
$filesize = 0;
$random_name = '-ERR';
unlink($savefile);
};
}
if (CHE_UPLOAD_IMG_CHECK && !che_reprocessImage($savefile, null)) {
$filesize = 0;
@ -117,20 +117,39 @@ if ( CHE_UPLOAD_IMG_CHECK && ! che_reprocessImage($savefile, null) ){
}
try {
if(defined('G5_FILE_PERMISSION')) chmod($savefile, G5_FILE_PERMISSION);
if (defined('G5_FILE_PERMISSION')) {
chmod($savefile, G5_FILE_PERMISSION);
}
} catch (Exception $e) {
}
$file_url = SAVE_URL . '/' . $filename;
if (function_exists('run_replace')) {
$file_url = run_replace('get_editor_upload_url', $file_url, $savefile, array());
$fileInfo = new \stdClass();
$fileInfo->name = (string) $filename;
$fileInfo->size = (int) $filesize;
$fileInfo->url = (string) $file_url;
if (isset($_POST['origname'])) {
$fileInfo->oriname = (string) $_POST['origname'];
}
$rdata = sprintf('{"fileUrl": "%s", "filePath": "%s", "fileName": "%s", "fileSize": "%d" }',
if ($imgsize) {
$fileInfo->width = (int) $imgsize[0];
$fileInfo->height = (int) $imgsize[1];
$fileInfo->type = (string) $imgsize['mime'];
}
$file_url = run_replace('get_editor_upload_url', $file_url, $savefile, $fileInfo);
}
$rdata = sprintf(
'{"fileUrl": "%s", "filePath": "%s", "fileName": "%s", "fileSize": "%d" }',
$file_url,
$savefile,
$filename,
$filesize );
$filesize
);
echo $rdata;