<commit_before>/**
 * @author zero (<EMAIL>)
 * @version 0.1.1
 * @brief 파일 업로드 관련
 **/
var uploadedFiles = new Array();
var uploaderSettings = new Array();
var loaded_images = new Array();
var swfUploadObjs = new Array();
var uploadSettingObj = new Object();

/**
 * 업로드를 하기 위한 준비 시작
 * 이 함수는 editor.html 에서 파일 업로드 가능할 경우 호출됨
 **/
// window.load 이벤트일 경우 && 문서 번호가 가상의 번호가 아니면 기존에 저장되어 있을지도 모르는 파일 목록을 가져옴
function editorUploadInit(obj, exe) {
    if(typeof(obj["editorSequence"])=="undefined") return;
    if(typeof(obj["sessionName"])=="undefined") obj["sessionName"]= "PHPSESSID";
    if(typeof(obj["allowedFileSize"])=="undefined") obj["allowedFileSize"]= 2*1024*1024;
    if(typeof(obj["allowedFileTypes"])=="undefined") obj["allowedFileTypes"]= "*.*";
    if(typeof(obj["allowedFileTypesDescription"])=="undefined") obj["allowedFileTypesDescription"]= "All Files";
    if(typeof(obj["replaceButtonID"])=="undefined") obj["replaceButtonID"] = "swfUploadButton"+obj["editorSequence"];
    if(typeof(obj["insertedFiles"])=="undefined") obj["insertedFiles"] = 0;
    uploadSettingObj = obj;
    xAddEventListener(window,"load",function() { XEUploaderStart(obj) });
    if(exe) XEUploaderStart(obj);
}

// 파일 업로드를 위한 기본 준비를 함
function XEUploaderStart(obj) {
    try { document.execCommand('BackgroundImageCache',false,true); } catch(e) { }

    var btnObj = xGetElementById(obj["replaceButtonID"]);
    var btnWidth = xWidth(btnObj);
    var btnHeight = xHeight(btnObj);
    btnObj.style.position = "relative";

    var dummy = xCreateElement("span");
    dummy.id = "dummy"+obj["replaceButtonID"];
    btnObj.appendChild(dummy);

    var settings = {
        flash_url : request_uri+"modules/editor/tpl/images/SWFUpload.swf",
        upload_url: request_uri,
        post_params: {
            "mid" : current_mid,
            "act" : "procFileUpload",
            "editor_sequence" : obj["editorSequence"],
            "uploadTargetSrl" : editorRelKeys[obj["editorSequence"]]["primary"].value
        },
        file_size_limit : parseInt(parseInt(obj["allowedFileSize"],10)/1024,10),
        file_queue_limit : 0,
        file_upload_limit : 0,
        file_types : obj["allowedFileTypes"],
        file_types_description : obj["allowedFileTypesDescription"],
        custom_settings : {
            progressTarget : null,
            cancelButtonId : null
        },
        debug: false,

        // Button settings
        button_window_mode: 'transparent',
        button_placeholder_id: dummy.id,
        button_text: null,
        button_image_url: "",
        button_width: btnWidth,
        button_height: btnHeight,
        button_text_style: null,
        button_text_left_padding: 0,
        button_text_top_padding: 0,
        button_cursor:-2,

        // The event handler functions are defined in handlers.js
        file_queued_handler : fileQueued,
        file_queue_error_handler : fileQueueError,
        file_dialog_complete_handler : fileDialogComplete,
        upload_start_handler : uploadStart,
        upload_progress_handler : uploadProgress,
        upload_error_handler : uploadError,
        upload_success_handler : uploadSuccess,
        upload_complete_handler : uploadComplete,
        queue_complete_handler :queueComplete
    };
    if(typeof(xeVid)!='undefined') settings["post_params"]["vid"] = xeVid;
    settings["post_params"][obj["sessionName"]] = xGetCookie(obj["sessionName"]);
    settings["editorSequence"] = obj["editorSequence"];
    settings["uploadTargetSrl"] = editorRelKeys[obj["editorSequence"]]["primary"].value;
    settings["fileListAreaID"] = obj["fileListAreaID"];
    settings["previewAreaID"] = obj["previewAreaID"];
    settings["uploaderStatusID"] = obj["uploaderStatusID"];

    uploaderSettings[obj["editorSequence"]] = settings;

    var swfu = new SWFUpload(settings);
    var swfObj = xGetElementById(swfu.movieName);
    swfUploadObjs[obj["editorSequence"]] = swfu.movieName;
    if(!swfObj) return;

    swfObj.style.display = "block";
    swfObj.style.cursor = "pointer";
    swfObj.style.position = "absolute";
    swfObj.style.left = 0;
    swfObj.style.top = "-3px";
    swfObj.style.width = btnWidth+"px";
    swfObj.style.height = btnHeight+"px";

    if(obj["insertedFiles"]>0 || editorRelKeys[obj["editorSequence"]]["primary"].value > 0) reloadFileList(settings);
}

function fileQueued(file) {
}

function fileQueueError(file, errorCode, message) {
    try {
        switch(errorCode) {
            case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED :
                alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
                break;
            case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                alert("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                break;
            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:<commit_msg>첨부파일 불러오는 스크립트 중복된 작업 안 하도록 수정<commit_after>/**
 * @author zero (<EMAIL>)
 * @version 0.1.1
 * @brief 파일 업로드 관련
 **/
var uploadedFiles = new Array();
var uploaderSettings = new Array();
var loaded_images = new Array();
var swfUploadObjs = new Array();
var uploadSettingObj = new Object();

/**
 * 업로드를 하기 위한 준비 시작
 * 이 함수는 editor.html 에서 파일 업로드 가능할 경우 호출됨
 **/
// window.load 이벤트일 경우 && 문서 번호가 가상의 번호가 아니면 기존에 저장되어 있을지도 모르는 파일 목록을 가져옴
function editorUploadInit(obj, exe) {
    if(typeof(obj["editorSequence"])=="undefined") return;
    if(typeof(obj["sessionName"])=="undefined") obj["sessionName"]= "PHPSESSID";
    if(typeof(obj["allowedFileSize"])=="undefined") obj["allowedFileSize"]= 2*1024*1024;
    if(typeof(obj["allowedFileTypes"])=="undefined") obj["allowedFileTypes"]= "*.*";
    if(typeof(obj["allowedFileTypesDescription"])=="undefined") obj["allowedFileTypesDescription"]= "All Files";
    if(typeof(obj["replaceButtonID"])=="undefined") obj["replaceButtonID"] = "swfUploadButton"+obj["editorSequence"];
    if(typeof(obj["insertedFiles"])=="undefined") obj["insertedFiles"] = 0;
    if(exe && uploadSettingObj != obj) XEUploaderStart(obj);
    if(typeof(uploaderSettings[obj["editorSequence"]]) != "undefined") {
        uploaderSettings[obj["editorSequence"]]["uploadTargetSrl"] = uploaderSettings[obj["editorSequence"]].post_params.uploadTargetSrl = editorRelKeys[obj["editorSequence"]]["primary"].value;
        reloadFileList(uploaderSettings[obj["editorSequence"]]);
    }
    uploadSettingObj = obj;
    xAddEventListener(window,"load",function() { XEUploaderStart(obj) });
}

// 파일 업로드를 위한 기본 준비를 함
function XEUploaderStart(obj) {
    try { document.execCommand('BackgroundImageCache',false,true); } catch(e) { }

    var btnObj = xGetElementById(obj["replaceButtonID"]);
    var btnWidth = xWidth(btnObj);
    var btnHeight = xHeight(btnObj);
    btnObj.style.position = "relative";

    var dummy = xCreateElement("span");
    dummy.id = "dummy"+obj["replaceButtonID"];
    btnObj.appendChild(dummy);

    var settings = {
        flash_url : request_uri+"modules/editor/tpl/images/SWFUpload.swf",
        upload_url: request_uri,
        post_params: {
            "mid" : current_mid,
            "act" : "procFileUpload",
            "editor_sequence" : obj["editorSequence"],
            "uploadTargetSrl" : editorRelKeys[obj["editorSequence"]]["primary"].value
        },
        file_size_limit : parseInt(parseInt(obj["allowedFileSize"],10)/1024,10),
        file_queue_limit : 0,
        file_upload_limit : 0,
        file_types : obj["allowedFileTypes"],
        file_types_description : obj["allowedFileTypesDescription"],
        custom_settings : {
            progressTarget : null,
            cancelButtonId : null
        },
        debug: false,

        // Button settings
        button_window_mode: 'transparent',
        button_placeholder_id: dummy.id,
        button_text: null,
        button_image_url: "",
        button_width: btnWidth,
        button_height: btnHeight,
        button_text_style: null,
        button_text_left_padding: 0,
        button_text_top_padding: 0,
        button_cursor:-2,

        // The event handler functions are defined in handlers.js
        file_queued_handler : fileQueued,
        file_queue_error_handler : fileQueueError,
        file_dialog_complete_handler : fileDialogComplete,
        upload_start_handler : uploadStart,
        upload_progress_handler : uploadProgress,
        upload_error_handler : uploadError,
        upload_success_handler : uploadSuccess,
        upload_complete_handler : uploadComplete,
        queue_complete_handler :queueComplete
    };
    if(typeof(xeVid)!='undefined') settings["post_params"]["vid"] = xeVid;
    settings["post_params"][obj["sessionName"]] = xGetCookie(obj["sessionName"]);
    settings["editorSequence"] = obj["editorSequence"];
    settings["uploadTargetSrl"] = editorRelKeys[obj["editorSequence"]]["primary"].value;
    settings["fileListAreaID"] = obj["fileListAreaID"];
    settings["previewAreaID"] = obj["previewAreaID"];
    settings["uploaderStatusID"] = obj["uploaderStatusID"];

    uploaderSettings[obj["editorSequence"]] = settings;

    var swfu = new SWFUpload(settings);
    var swfObj = xGetElementById(swfu.movieName);
    swfUploadObjs[obj["editorSequence"]] = swfu.movieName;
    if(!swfObj) return;

    swfObj.style.display = "block";
    swfObj.style.cursor = "pointer";
    swfObj.style.position = "absolute";
    swfObj.style.left = 0;
    swfObj.style.top = "-3px";
    swfObj.style.width = btnWidth+"px";
    swfObj.style.height = btnHeight+"px";

    if(obj["insertedFiles"]>0) reloadFileList(settings);
}

function fileQueued(file) {
}

function fileQueueError(file, errorCode, message) {
    try {
        switch(errorCode) {
            case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED :
                alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
                break;
            case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                alert("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                break;
            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
{'fraction_non_alphanumeric': 0.1372925261441044, 'fraction_numerical': 0.006044325050369375, 'mean_word_length': 3.6308307418924923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7228221', 'n_tokens_mistral': 3390, 'n_tokens_neox': 3473, 'n_words': 604}