Skip to content

Commit

Permalink
PRS-12 코드 포맷
Browse files Browse the repository at this point in the history
  • Loading branch information
kkigomi committed Jun 30, 2023
1 parent 4eba618 commit af64737
Showing 1 changed file with 48 additions and 44 deletions.
92 changes: 48 additions & 44 deletions plugin/editor/cheditor5/imageUpload/upload.php
@@ -1,35 +1,35 @@
<?php
require_once("config.php");

if(!function_exists('ft_nonce_is_valid')){
if (!function_exists('ft_nonce_is_valid')) {
include_once('../editor.lib.php');
}

if( !function_exists('che_reprocessImage') ){
function che_reprocessImage($file_path, $callback){

if (!function_exists('che_reprocessImage')) {
function che_reprocessImage($file_path, $callback)
{
$MIME_TYPES_PROCESSORS = array(
"image/gif" => array("imagecreatefromgif", "imagegif"),
"image/jpg" => array("imagecreatefromjpeg", "imagejpeg"),
"image/jpeg" => array("imagecreatefromjpeg", "imagejpeg"),
"image/png" => array("imagecreatefrompng", "imagepng"),
"image/webp" => array("imagecreatefromwebp", "imagewebp"),
"image/bmp" => array("imagecreatefromwbmp", "imagewbmp")
"image/gif" => array("imagecreatefromgif", "imagegif"),
"image/jpg" => array("imagecreatefromjpeg", "imagejpeg"),
"image/jpeg" => array("imagecreatefromjpeg", "imagejpeg"),
"image/png" => array("imagecreatefrompng", "imagepng"),
"image/webp" => array("imagecreatefromwebp", "imagewebp"),
"image/bmp" => array("imagecreatefromwbmp", "imagewbmp")
);

// Extracting mime type using getimagesize
try {
$image_info = getimagesize($file_path);
if ($image_info === null) {
//throw new Exception("Invalid image type");
return false;
//throw new Exception("Invalid image type");
return false;
}

$mime_type = $image_info["mime"];

if (!array_key_exists($mime_type, $MIME_TYPES_PROCESSORS)) {
//throw new Exception("Invalid image MIME type");
return false;
//throw new Exception("Invalid image MIME type");
return false;
}

$image_from_file = $MIME_TYPES_PROCESSORS[$mime_type][0];
Expand All @@ -38,13 +38,13 @@ function che_reprocessImage($file_path, $callback){
$reprocessed_image = @$image_from_file($file_path);

if (!$reprocessed_image) {
//throw new Exception("Unable to create reprocessed image from file");
return false;
//throw new Exception("Unable to create reprocessed image from file");
return false;
}

// Calling callback(if set) with path of image as a parameter
if ($callback !== null) {
$callback($reprocessed_image);
$callback($reprocessed_image);
}

// Freeing up memory
Expand All @@ -60,13 +60,13 @@ function che_reprocessImage($file_path, $callback){

$is_editor_upload = false;

$get_nonce = get_session('nonce_'.FT_NONCE_SESSION_KEY);
$get_nonce = get_session('nonce_' . FT_NONCE_SESSION_KEY);

if( $get_nonce && ft_nonce_is_valid( $get_nonce, 'cheditor' ) ){
if ($get_nonce && ft_nonce_is_valid($get_nonce, 'cheditor')) {
$is_editor_upload = true;
}

if( !$is_editor_upload ){
if (!$is_editor_upload) {
exit;
}

Expand All @@ -78,19 +78,19 @@ function che_reprocessImage($file_path, $callback){
$tempfile = $_FILES['file']['tmp_name'];
$filename = $_FILES['file']['name'];
$filename_len = strrpos($filename, ".");
$type = substr($filename, strrpos($filename, ".")+1);
$type = substr($filename, strrpos($filename, ".") + 1);
$found = false;
switch ($type) {
case "jpg":
case "jpeg":
case "gif":
case "png":
case "jpg":
case "jpeg":
case "gif":
case "png":
case "webp":
$found = true;
$found = true;
}

if ($found != true || $filename_len != 23) {
exit;
exit;
}

// 저장 파일 이름: 년월일시분초_렌덤문자8자
Expand All @@ -105,32 +105,36 @@ function che_reprocessImage($file_path, $callback){
$filesize = filesize($savefile);

if (!$imgsize) {
$filesize = 0;
$random_name = '-ERR';
unlink($savefile);
};

if ( CHE_UPLOAD_IMG_CHECK && ! che_reprocessImage($savefile, null) ){
$filesize = 0;
$random_name = '-ERR';
unlink($savefile);
$filesize = 0;
$random_name = '-ERR';
unlink($savefile);
}

if (CHE_UPLOAD_IMG_CHECK && !che_reprocessImage($savefile, null)) {
$filesize = 0;
$random_name = '-ERR';
unlink($savefile);
}

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;
$file_url = SAVE_URL . '/' . $filename;

if( function_exists('run_replace') ){
if (function_exists('run_replace')) {
$file_url = run_replace('get_editor_upload_url', $file_url, $savefile, array());
}

$rdata = sprintf('{"fileUrl": "%s", "filePath": "%s", "fileName": "%s", "fileSize": "%d" }',
$file_url,
$savefile,
$filename,
$filesize );
$rdata = sprintf(
'{"fileUrl": "%s", "filePath": "%s", "fileName": "%s", "fileSize": "%d" }',
$file_url,
$savefile,
$filename,
$filesize
);

echo $rdata;

0 comments on commit af64737

Please sign in to comment.