Files
dnssash/theme/rd.dnssash/skin/board/rb.board.core/write.skin.php
T
2026-06-11 18:47:38 +09:00

175 lines
9.7 KiB
PHP

<?php
if (!defined('_GNUBOARD_')) exit;
/**
* rb.board.core :: write.skin.php
* 💡 [최종판] '스마트 코어' 글쓰기 폼 - 에디터 전환 기능 및 wr_option 연동 오류 해결
*/
$field_map = array(
'summary' => 'wr_1',
'featured' => 'wr_10',
);
$ebook_link_field = 'wr_link1';
$cfg_write = isset($board_config['write']) ? $board_config['write'] : array();
?>
<div class="board-write-container">
<form name="fwrite" id="fwrite" action="<?php echo $action_url ?>" onsubmit="return fwrite_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off" novalidate>
<input type="hidden" name="uid" value="<?php echo get_uniqid(); ?>">
<input type="hidden" name="w" value="<?php echo $w ?>"><input type="hidden" name="bo_table" value="<?php echo $bo_table ?>"><input type="hidden" name="wr_id" value="<?php echo $wr_id ?>"><input type="hidden" name="sca" value="<?php echo $sca ?>"><input type="hidden" name="sfl" value="<?php echo $sfl ?>"><input type="hidden" name="stx" value="<?php echo $stx ?>"><input type="hidden" name="spt" value="<?php echo $spt ?>"><input type="hidden" name="sst" value="<?php echo $sst ?>"><input type="hidden" name="sod" value="<?php echo $sod ?>"><input type="hidden" name="page" value="<?php echo $page ?>">
<div class="write-form-group">
<label for="wr_subject" class="form-label">제목<span class="required">*</span></label>
<input type="text" name="wr_subject" value="<?php echo $subject ?>" id="wr_subject" required class="form-control" placeholder="제목을 입력하세요">
</div>
<?php if ($is_category): ?>
<div class="write-form-group">
<label for="ca_name" class="form-label">카테고리<span class="required">*</span></label>
<select name="ca_name" id="ca_name" required class="form-control"><option value="">선택하세요</option><?php echo $category_option ?></select>
</div>
<?php endif; ?>
<?php if (!empty($cfg_write['use_summary'])): ?>
<div class="write-form-group">
<label for="<?php echo $field_map['summary']; ?>" class="form-label"><?php echo $cfg_write['summary_label'] ?: '요약'; ?></label>
<textarea name="<?php echo $field_map['summary']; ?>" id="<?php echo $field_map['summary']; ?>" class="form-control" rows="3" placeholder="<?php echo $cfg_write['summary_placeholder']; ?>"><?php echo $write[$field_map['summary']]; ?></textarea>
</div>
<?php endif; ?>
<div class="write-form-group">
<label for="wr_content" class="form-label">내용<span class="required">*</span></label>
<div class="editor-toggle-buttons">
<button type="button" class="btn btn-sm btn-editor-toggle <?php echo $is_dhtml_editor ? 'active' : ''; ?>" data-editor-type="dhtml">HTML 에디터</button>
<button type="button" class="btn btn-sm btn-editor-toggle <?php echo $is_dhtml_editor ? '' : 'active'; ?>" data-editor-type="text">텍스트 에디터</button>
</div>
<div id="dhtml-editor-area" style="display: <?php echo $is_dhtml_editor ? 'block' : 'none'; ?>;">
<?php if ($is_dhtml_editor) { echo $editor_html; } ?>
</div>
<div id="text-editor-area" style="display: <?php echo $is_dhtml_editor ? 'none' : 'block'; ?>;">
<textarea id="wr_content_text" class="form-control" rows="10"><?php echo $content ?></textarea>
</div>
</div>
<!-- 💡 [핵심] 그누보드와 연동하기 위한 숨겨진 HTML 체크박스 -->
<div style="display:none;">
<?php if ($is_html) { ?>
<input type="checkbox" id="html" name="html" value="html2" <?php echo ($html_value) ? "checked" : ""; ?>>
<label for="html">html</label>
<?php } ?>
</div>
<hr class="form-divider">
<?php for ($i=1; $is_file && $i<=$board['bo_upload_count']; $i++):
$file_label = isset($cfg_write['file_labels'][$i]) ? $cfg_write['file_labels'][$i] : '첨부파일 #'.$i;
$file_text = isset($cfg_write['file_texts'][$i]) ? $cfg_write['file_texts'][$i] : '';
?>
<div class="write-form-group file-upload-group">
<label for="bf_file_<?php echo $i ?>" class="form-label"><?php echo $file_label; ?><?php if($i==1) echo '<span class="required">*</span>'; ?></label>
<div class="file-input-wrapper">
<input type="file" name="bf_file[]" id="bf_file_<?php echo $i ?>" title="파일첨부 <?php echo $i ?> : 용량 <?php echo $upload_max_filesize ?> 이하만 업로드 가능" class="form-control" <?php if ($w=='' && $i==1) echo 'required'; ?>>
<?php if ($w == 'u' && $file[$i-1]['file']): ?>
<span class="file-delete-wrap"><input type="checkbox" id="bf_file_del_<?php echo $i-1 ?>" name="bf_file_del[<?php echo $i-1; ?>]" value="1"><label for="bf_file_del_<?php echo $i-1 ?>"><?php echo $file[$i-1]['source'].'('.$file[$i-1]['size'].')'; ?> 파일 삭제</label></span>
<?php endif; ?>
</div>
<?php if($file_text): ?><p class="form-text"><?php echo $file_text; ?></p><?php endif; ?>
</div>
<?php endfor; ?>
<hr class="form-divider">
<?php if ($is_admin): ?>
<div class="admin-options-group">
<h3 class="form-section-title">관리자 전용 설정</h3>
<div class="write-form-group">
<label class="form-check-label"><input type="checkbox" name="<?php echo $field_map['featured']; ?>" value="Y" id="is_featured" <?php echo ($write[$field_map['featured']] == 'Y') ? 'checked' : ''; ?>> 이 글을 '지정 최신글'로 설정합니다. (최대 6개)</label>
</div>
<div class="write-form-group" id="ebook-link-group" style="display: <?php echo ($write[$field_map['featured']] == 'Y') ? 'block' : 'none'; ?>;">
<label for="<?php echo $ebook_link_field; ?>" class="form-label">E-book 링크</label>
<input type="url" name="<?php echo $ebook_link_field; ?>" value="<?php echo $write[$ebook_link_field]; ?>" id="<?php echo $ebook_link_field; ?>" class="form-control" placeholder="https://example.com/ebook/123">
<p class="form-text">'지정 최신글'로 설정했을 경우, 클릭 시 이동할 이북 주소를 입력하세요.</p>
</div>
</div>
<?php endif; ?>
<div class="write-form-footer">
<a href="<?php echo get_pretty_url($bo_table); ?>" class="btn btn-secondary">취소</a>
<button type="submit" id="btn_submit" accesskey="s" class="btn btn-primary">작성완료</button>
</div>
</form>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const isFeaturedCheckbox = document.getElementById('is_featured');
const ebookLinkGroup = document.getElementById('ebook-link-group');
if (isFeaturedCheckbox && ebookLinkGroup) {
isFeaturedCheckbox.addEventListener('change', function() {
ebookLinkGroup.style.display = this.checked ? 'block' : 'none';
});
}
const dhtmlEditorArea = document.getElementById('dhtml-editor-area');
const textEditorArea = document.getElementById('text-editor-area');
const editorToggleButtons = document.querySelectorAll('.btn-editor-toggle');
const wrContentTextarea = document.getElementById('wr_content_text');
const htmlCheckbox = document.getElementById('html'); // 💡 [핵심] 숨겨진 html 체크박스
function setEditorMode(isDhtml) {
if (isDhtml) {
dhtmlEditorArea.style.display = 'block';
textEditorArea.style.display = 'none';
if (htmlCheckbox) htmlCheckbox.checked = true; // 💡 [핵심] HTML 모드일 때 체크
} else {
dhtmlEditorArea.style.display = 'none';
textEditorArea.style.display = 'block';
if (htmlCheckbox) htmlCheckbox.checked = false; // 💡 [핵심] 텍스트 모드일 때 체크 해제
}
editorToggleButtons.forEach(btn => {
if ((btn.dataset.editorType === 'dhtml' && isDhtml) || (btn.dataset.editorType === 'text' && !isDhtml)) {
btn.classList.add('active');
} else {
btn.classList.remove('active');
}
});
}
// 초기 에디터 모드 설정
setEditorMode(<?php echo $is_dhtml_editor ? 'true' : 'false'; ?>);
editorToggleButtons.forEach(button => {
button.addEventListener('click', function() {
const type = this.dataset.editorType;
setEditorMode(type === 'dhtml');
});
});
});
function fwrite_submit(f) {
// 💡 [핵심] 그누보드 에디터의 제출 로직을 항상 호출하여 wr_content 필드를 업데이트합니다.
<?php echo $editor_js; ?>
// 텍스트 에디터가 활성화된 경우, 그 내용을 wr_content 필드로 옮겨줍니다.
const textEditorArea = document.getElementById('text-editor-area');
if (textEditorArea.style.display === 'block') {
f.wr_content.value = document.getElementById('wr_content_text').value;
}
// 최종적으로 wr_content 필드의 내용이 비어있는지 확인합니다.
if (f.wr_content.value.trim() === '') {
alert('내용을 입력해주세요.');
// 활성화된 에디터에 포커스
if (document.getElementById('dhtml-editor-area').style.display === 'block' && typeof CKEDITOR !== 'undefined' && CKEDITOR.instances.wr_content) {
CKEDITOR.instances.wr_content.focus();
} else {
document.getElementById('wr_content_text').focus();
}
return false;
}
return true;
}
</script>