cheditor5 추가
This commit is contained in:
3
plugin/editor/cheditor5/imageUpload/_common.php
Normal file
3
plugin/editor/cheditor5/imageUpload/_common.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
include_once("../../../../common.php");
|
||||
?>
|
||||
71
plugin/editor/cheditor5/imageUpload/config.php
Normal file
71
plugin/editor/cheditor5/imageUpload/config.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
include_once("_common.php");
|
||||
|
||||
if( strpos($config['cf_editor'], 'cheditor5') === false ){
|
||||
exit;
|
||||
}
|
||||
|
||||
define("CHE_UPLOAD_IMG_CHECK", 1); // <20>̹<EFBFBD><CCB9><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ҽ<EFBFBD> <20>ִ<EFBFBD><D6B4><EFBFBD> <20><><EFBFBD>θ<EFBFBD> üũ<C3BC>մϴ<D5B4>. ( <20>ش<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̹<EFBFBD><CCB9><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> üũ<C3BC>մϴ<D5B4>. 1<≯<EFBFBD> <20><><EFBFBD><EFBFBD>, 0<≯<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> )
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
# <20>̹<EFBFBD><CCB9><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>丮<EFBFBD><E4B8AE> <20><>ü <20><><EFBFBD>θ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
|
||||
# <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(/)<29><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>.
|
||||
# <20><><EFBFBD><EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20>бⰡ <20><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ֽʽÿ<CABD>.
|
||||
|
||||
# data/editor <20><><EFBFBD><EFBFBD><EFBFBD>丮<EFBFBD><E4B8AE> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>찡 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>丮<EFBFBD><E4B8AE> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20>ڵ带 <20>߰<EFBFBD><DFB0><EFBFBD>. kagla 140305
|
||||
|
||||
@mkdir(G5_DATA_PATH.'/'.G5_EDITOR_DIR, G5_DIR_PERMISSION);
|
||||
@chmod(G5_DATA_PATH.'/'.G5_EDITOR_DIR, G5_DIR_PERMISSION);
|
||||
|
||||
$ym = date('ym', G5_SERVER_TIME);
|
||||
|
||||
$data_dir = G5_DATA_PATH.'/'.G5_EDITOR_DIR.'/'.$ym;
|
||||
$data_url = G5_DATA_URL.'/'.G5_EDITOR_DIR.'/'.$ym;
|
||||
|
||||
define("SAVE_DIR", $data_dir);
|
||||
|
||||
@mkdir(SAVE_DIR, G5_DIR_PERMISSION);
|
||||
@chmod(SAVE_DIR, G5_DIR_PERMISSION);
|
||||
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 'SAVE_DIR'<27><> URL<52><4C> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
|
||||
# <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(/)<29><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>.
|
||||
|
||||
define("SAVE_URL", $data_url);
|
||||
|
||||
function che_get_user_id() {
|
||||
@session_start();
|
||||
return session_id();
|
||||
}
|
||||
|
||||
function che_get_file_passname(){
|
||||
$tmp_name = che_get_user_id().$_SERVER['REMOTE_ADDR'];
|
||||
$tmp_name = md5(sha1($tmp_name));
|
||||
return $tmp_name;
|
||||
}
|
||||
|
||||
function che_generateRandomString($length = 4) {
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
function che_replace_filename($filename){
|
||||
|
||||
$ext = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
|
||||
$random_str = che_generateRandomString(4);
|
||||
|
||||
$passname = che_get_file_passname();
|
||||
|
||||
$file_arr = explode('_', $filename);
|
||||
|
||||
return $file_arr[0].'_'.$passname.'_'.$random_str.'.'.$ext;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
?>
|
||||
49
plugin/editor/cheditor5/imageUpload/delete.php
Normal file
49
plugin/editor/cheditor5/imageUpload/delete.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
require_once("config.php");
|
||||
|
||||
if(!function_exists('ft_nonce_is_valid')){
|
||||
include_once('../editor.lib.php');
|
||||
}
|
||||
|
||||
$filesrc = isset($_POST["filesrc"]) ? $_POST["filesrc"] : '';
|
||||
|
||||
if( !$filesrc ){
|
||||
die( false );
|
||||
}
|
||||
|
||||
$is_editor_upload = false;
|
||||
|
||||
$get_nonce = get_session('nonce_'.FT_NONCE_SESSION_KEY);
|
||||
|
||||
if( $get_nonce && ft_nonce_is_valid( $get_nonce, 'cheditor' ) ){
|
||||
$is_editor_upload = true;
|
||||
}
|
||||
|
||||
if( !$is_editor_upload ){
|
||||
die( false );
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
$file_arr = explode('_', $filesrc );
|
||||
|
||||
if( $file_arr[1] !== che_get_file_passname() ){
|
||||
die( false );
|
||||
}
|
||||
|
||||
$filepath = SAVE_DIR . '/' . $filesrc;
|
||||
$r = false;
|
||||
|
||||
if (file_exists($filepath)) {
|
||||
$r = unlink($filepath);
|
||||
if ($r) {
|
||||
$thumbPath = dirname($filepath) . DIRECTORY_SEPARATOR . "thumb_" . basename($filepath);
|
||||
if (file_exists($thumbPath)) {
|
||||
unlink($thumbPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $r ? true : false;
|
||||
|
||||
?>
|
||||
128
plugin/editor/cheditor5/imageUpload/upload.php
Normal file
128
plugin/editor/cheditor5/imageUpload/upload.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
require_once("config.php");
|
||||
|
||||
if(!function_exists('ft_nonce_is_valid')){
|
||||
include_once('../editor.lib.php');
|
||||
}
|
||||
|
||||
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/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;
|
||||
}
|
||||
|
||||
$mime_type = $image_info["mime"];
|
||||
|
||||
if (!array_key_exists($mime_type, $MIME_TYPES_PROCESSORS)) {
|
||||
//throw new Exception("Invalid image MIME type");
|
||||
return false;
|
||||
}
|
||||
|
||||
$image_from_file = $MIME_TYPES_PROCESSORS[$mime_type][0];
|
||||
$image_to_file = $MIME_TYPES_PROCESSORS[$mime_type][1];
|
||||
|
||||
$reprocessed_image = @$image_from_file($file_path);
|
||||
|
||||
if (!$reprocessed_image) {
|
||||
//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);
|
||||
}
|
||||
|
||||
// Freeing up memory
|
||||
imagedestroy($reprocessed_image);
|
||||
} catch (Exception $e) {
|
||||
unlink($file_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$is_editor_upload = false;
|
||||
|
||||
$get_nonce = get_session('nonce_'.FT_NONCE_SESSION_KEY);
|
||||
|
||||
if( $get_nonce && ft_nonce_is_valid( $get_nonce, 'cheditor' ) ){
|
||||
$is_editor_upload = true;
|
||||
}
|
||||
|
||||
if( !$is_editor_upload ){
|
||||
exit;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
$tempfile = $_FILES['file']['tmp_name'];
|
||||
$filename = $_FILES['file']['name'];
|
||||
|
||||
$type = substr($filename, strrpos($filename, ".")+1);
|
||||
$found = false;
|
||||
switch ($type) {
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
case "gif":
|
||||
case "png":
|
||||
$found = true;
|
||||
}
|
||||
|
||||
if ($found != true) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20≯<EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD>Ͻú<CFBD><C3BA><EFBFBD>_<EFBFBD><5F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38>
|
||||
// 20140327125959_abcdefghi.jpg
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20≯<EFBFBD>: $_POST["origname"]
|
||||
|
||||
$filename = che_replace_filename($filename);
|
||||
$savefile = SAVE_DIR . '/' . $filename;
|
||||
|
||||
move_uploaded_file($tempfile, $savefile);
|
||||
$imgsize = getimagesize($savefile);
|
||||
$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);
|
||||
}
|
||||
|
||||
try {
|
||||
if(defined('G5_FILE_PERMISSION')) chmod($savefile, G5_FILE_PERMISSION);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
$rdata = sprintf('{"fileUrl": "%s/%s", "filePath": "%s", "fileName": "%s", "fileSize": "%d" }',
|
||||
SAVE_URL,
|
||||
$filename,
|
||||
$savefile,
|
||||
$filename,
|
||||
$filesize );
|
||||
|
||||
echo $rdata;
|
||||
?>
|
||||
Reference in New Issue
Block a user