일반페이지에서 스마트에디터 사용하기
관련링크
본문
일반페이지에서 스마트에디터를 사용하는 게시판 입력폼을 만들었습니다.
<?php
$sub_menu = 200100;
// board
$bo_table = 'notice';
$board = get_board_db($bo_table);
$is_dhtml_editor = $board['bo_use_dhtml_editor'];
$bo_select_editor = $board['bo_select_editor'];
if($is_dhtml_editor && $bo_select_editor){
include_once (G5_EDITOR_PATH."/{$bo_select_editor}/editor.lib.php");
}else{
include_once (G5_LIB_PATH."/editor.lib.php");
}
include_once(G5_PATH.'/head.php');
// token
$token = get_token();
set_session("ss_write_{$bo_table}_token", $token);
// file
$is_file = $board['bo_upload_count'] > 0;
$file_count = $board['bo_upload_count'] ?? 0;
?>
<a href="/bbs/write.php?bo_table=notice">그누보드 게시판으로</a>
<div class="container">
<h1>게시글 작성</h1>
<form method="post" action="/bbs/write_update.php" enctype="multipart/form-data" onsubmit="return fwrite_submit(this)">
<input type="hidden" name="bo_table" value="<?=$bo_table?>">
<input type="hidden" name="token" value="<?=$token?>">
<input type="hidden" name="return_url" value="/board/notice/?mode=list">
<label for="wr_name">작성자</label>
<input type="text" id="wr_name" name="wr_name" required>
<label for="wr_subject">제목</label>
<input type="text" id="wr_subject" name="wr_subject" required>
<label for="wr_content">내용</label>
<div class="wr_content cheditor5">
<?php $editor_html = editor_html('wr_content', '', false)?>
<?php echo $editor_html;?>
</div>
<?php for ($i=0; $is_file && $i<$file_count; $i++) : ?>
<input type="file" name="bf_file[]">
<?php endfor ;?>
<button type="submit">작성</button>
</form>
</div>
<script>
function fwrite_submit(f){
<?php echo get_editor_js('wr_content', $is_dhtml_editor);?>
<?php echo chk_editor_js('wr_content', $is_dhtml_editor);?>
return true;
}
</script>
<?php
// footer 파일 포함
include_once(G5_PATH.'/tail.php');
?>
호름을 이야기 하자면
에디터를 선택한 경우 $board의 정보를 가져와
에디터 플러그인을 include하고
include_once (G5_EDITOR_PATH."/{$bo_select_editor}/editor.lib.php");
그 다음 head.php를 불러오고
.wr_content 에 현재는 직접적으로 넣지만 에디터 이름을 클래스로 넣고
<div class="wr_content cheditor5">
현재 에디터 출력과는 관계없지만 내용을 wr_content에 넣거나
입력 검사를 위한 onsubmit과 자바스트립트
<form method="post" action="/bbs/write_update.php" enctype="multipart/form-data" onsubmit="return fwrite_submit(this)">
<script>
function fwrite_submit(f){
<?php echo get_editor_js('wr_content', $is_dhtml_editor);?>
<?php echo chk_editor_js('wr_content', $is_dhtml_editor);?>
return true;
}
</script>
출력을 봐서는 일반 textarea가 나오는데
이것은
include_once (G5_LIB_PATH."/editor.lib.php");
이게 include 된것 처럼 보여지는데
현재 get_include_file()를 보면
Array
(
[0] => /home/prepend/prepend.php
[1] => /home/prepend/reject_excute/reject_excute.php
[2] => /home/prepend/funcall_excute/funcall_excute.php
[3] => /home/prepend/upload_guard/upload_guard.php
[4] => /oocooc/www/board/notice/index.php
[5] => /oocooc/www/common.php
[6] => /oocooc/www/config.php
[7] => /oocooc/www/version.php
[8] => /oocooc/www/lib/hook.lib.php
[9] => /oocooc/www/lib/Hook/hook.class.php
[10] => /oocooc/www/lib/Hook/hook.extends.class.php
[11] => /oocooc/www/lib/get_data.lib.php
[12] => /oocooc/www/lib/cache.lib.php
[13] => /oocooc/www/lib/Cache/obj.class.php
[14] => /oocooc/www/lib/Cache/FileCache.class.php
[15] => /oocooc/www/lib/uri.lib.php
[16] => /oocooc/www/data/dbconfig.php
[17] => /oocooc/www/lib/common.lib.php
[18] => /oocooc/www/lib/pbkdf2.compat.php
[19] => /oocooc/www/bbs/visit_insert.inc.php
[20] => /oocooc/www/bbs/db_table.optimize.php
[21] => /oocooc/www/extend/debugbar.extend.php
[22] => /oocooc/www/extend/default.config.php
[23] => /oocooc/www/extend/g5_54version_update.extend.php
[24] => /oocooc/www/extend/shop.extend.php
[25] => /oocooc/www/extend/smarteditor_upload_extend.php
[26] => /oocooc/www/extend/sms5.extend.php
[27] => /oocooc/www/extend/social_login.extend.php
[28] => /oocooc/www/plugin/social/includes/functions.php
[29] => /oocooc/www/extend/version.extend.php
[30] => /oocooc/www/board/notice/form.php
[31] => /oocooc/www/plugin/editor/cheditor5/editor.lib.php
[32] => /oocooc/www/head.php
[33] => /oocooc/www/head.sub.php
[34] => /oocooc/www/lib/latest.lib.php
[35] => /oocooc/www/lib/thumbnail.lib.php
[36] => /oocooc/www/lib/outlogin.lib.php
[37] => /oocooc/www/lib/poll.lib.php
[38] => /oocooc/www/lib/visit.lib.php
[39] => /oocooc/www/lib/connect.lib.php
[40] => /oocooc/www/lib/popular.lib.php
)
이걸 보면 제대로 include된거 같은데
잘못된 부분이 뭘까요?
위 파일은 /board/notice/의 include파일인데
/board/notice/index.php 에서 common.php를 include하고
위 파일을 include하고 있습니다.
답변 1
가장 기본적인 구성으로 된 테스트/샘플 페이지부터 에디터가 정상적으로 뜨는 지 확인해 본 뒤,
실제 페이지의 요소를 하나씩 추가해가면서 원인을 찾아가 볼 수 있습니다.
정확한 원인 지점을 찾으면 해결이 훨씬 쉬워집니다.
* /board/notice/test.php
<?php
include_once('../../common.php');
$bo_table = 'notice';
$board = get_board_db($bo_table);
include_once(G5_LIB_PATH.'/editor.lib.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>에디터 테스트</title>
</head>
<body>
<h1>에디터 테스트</h1>
<form method="post" action="#" enctype="multipart/form-data">
<input type="hidden" name="bo_table" value="<?=$bo_table?>">
<div>
<label for="wr_subject">제목</label>
<input type="text" name="wr_subject" id="wr_subject" required>
</div>
<div>
<label for="wr_content">내용</label>
<?php echo editor_html('wr_content', ''); ?>
</div>
<div>
<button type="submit">작성</button>
</div>
</form>
</body>
</html>
G5_EDITOR_PATH."/{$bo_select_editor}/editor.lib.php"와 G5_LIB_PATH."/editor.lib.php"는 사실상 같은 작동을 합니다.
G5_LIB_PATH."/editor.lib.php"에서 게시판 환경설정에 따라 자동으로 G5_EDITOR_PATH."/{$bo_select_editor}/editor.lib.php"가 로드되는 구조이기 때문입니다.
따라서 현재 문제는 다음 중 하나일 가능성이 높습니다:
1. 게시판 설정에서 "DHTML 에디터 사용" □ 체크박스가 해제되어 있거나
2. "에디터 선택" 드롭다운에서 cheditor5가 선택되지 않았거나
3. cheditor5 플러그인 자체가 제대로 설치되지 않았을 가능성
관리자 → 게시판관리 → 해당 게시판 설정에서 이 부분들을 먼저 확인해보시는 것이 좋겠습니다.
!-->