Merge branch 'autosave' of github.com:gnuboard/g4s into autosave
This commit is contained in:
24
bbs/ajax.autosave.php
Normal file
24
bbs/ajax.autosave.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
include_once('./_common.php');
|
||||||
|
|
||||||
|
if (!$is_member) die('0');
|
||||||
|
|
||||||
|
$uid = escape_trim($_REQUEST['uid']);
|
||||||
|
$subject = escape_trim($_REQUEST['subject']);
|
||||||
|
$content = escape_trim($_REQUEST['content']);
|
||||||
|
|
||||||
|
/*
|
||||||
|
$uid = get_session("ss_autosave_uid");
|
||||||
|
if (!$uid) {
|
||||||
|
$uid = get_uniqid();
|
||||||
|
set_session("ss_autosave_uid", $uid);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ($content) {
|
||||||
|
$sql = " insert into {$g4['autosave_table']} set mb_id = '{$member['mb_id']}', as_uid = '{$uid}', as_subject = '$subject', as_content = '$content', as_datetime = '".G4_TIME_YMDHIS."' on duplicate key update as_subject = '$subject', as_content = '$content', as_datetime = '".G4_TIME_YMDHIS."' ";
|
||||||
|
$result = sql_query($sql, false);
|
||||||
|
|
||||||
|
echo autosave_count($member['mb_id']);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@ -380,6 +380,9 @@ if (!G4_IS_MOBILE && $board['bo_use_dhtml_editor'] && $member['mb_level'] >= $bo
|
|||||||
}
|
}
|
||||||
$editor_html = editor_html('wr_content', $content, $is_dhtml_editor);
|
$editor_html = editor_html('wr_content', $content, $is_dhtml_editor);
|
||||||
|
|
||||||
|
// 임시 저장된 글 갯수
|
||||||
|
$autosave_count = autosave_count($member['mb_id']);
|
||||||
|
|
||||||
include_once(G4_PATH.'/head.sub.php');
|
include_once(G4_PATH.'/head.sub.php');
|
||||||
@include_once ($board_skin_path.'/write.head.skin.php');
|
@include_once ($board_skin_path.'/write.head.skin.php');
|
||||||
include_once('./board_head.php');
|
include_once('./board_head.php');
|
||||||
|
|||||||
@ -555,6 +555,9 @@ for ($i=(int)$row['max_bf_no']; $i>=0; $i--)
|
|||||||
// 파일의 갯수를 게시물에 업데이트 한다.
|
// 파일의 갯수를 게시물에 업데이트 한다.
|
||||||
$row = sql_fetch(" select count(*) as cnt from {$g4['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' ");
|
$row = sql_fetch(" select count(*) as cnt from {$g4['board_file_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' ");
|
||||||
sql_query(" update {$write_table} set wr_file = '{$row['cnt']}' where wr_id = '{$wr_id}' ");
|
sql_query(" update {$write_table} set wr_file = '{$row['cnt']}' where wr_id = '{$wr_id}' ");
|
||||||
|
|
||||||
|
// 자동저장된 레코드를 삭제한다.
|
||||||
|
sql_query(" delete from g4s_autosave where as_uid = '{$uid}' ");
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// 비밀글이라면 세션에 비밀글의 아이디를 저장한다. 자신의 글은 다시 패스워드를 묻지 않기 위함
|
// 비밀글이라면 세션에 비밀글의 아이디를 저장한다. 자신의 글은 다시 패스워드를 묻지 않기 위함
|
||||||
|
|||||||
@ -1722,7 +1722,7 @@ function get_uniqid()
|
|||||||
// 년월일시분초에 100분의 1초 두자리를 추가함 (1/100 초 앞에 자리가 모자르면 0으로 채움)
|
// 년월일시분초에 100분의 1초 두자리를 추가함 (1/100 초 앞에 자리가 모자르면 0으로 채움)
|
||||||
$key = date('ymdHis', time()) . str_pad((int)(microtime()*100), 2, "0", STR_PAD_LEFT);
|
$key = date('ymdHis', time()) . str_pad((int)(microtime()*100), 2, "0", STR_PAD_LEFT);
|
||||||
|
|
||||||
$result = sql_query(" insert into {$g4['uniqid_table']} values ('$key') ", false);
|
$result = sql_query(" insert into {$g4['uniqid_table']} set uq_id = '$key', uq_ip = '{$_SERVER['REMOTE_ADDR']}' ", false);
|
||||||
if ($result) break; // 쿼리가 정상이면 빠진다.
|
if ($result) break; // 쿼리가 정상이면 빠진다.
|
||||||
|
|
||||||
// insert 하지 못했으면 일정시간 쉰다음 다시 유일키를 만든다.
|
// insert 하지 못했으면 일정시간 쉰다음 다시 유일키를 만든다.
|
||||||
@ -2078,4 +2078,18 @@ function googl_short_url($longUrl)
|
|||||||
|
|
||||||
return $json->id;
|
return $json->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 임시 저장된 글 갯수
|
||||||
|
function autosave_count($mb_id)
|
||||||
|
{
|
||||||
|
global $g4;
|
||||||
|
|
||||||
|
if ($mb_id) {
|
||||||
|
$row = sql_fetch(" select count(*) as cnt from {$g4['autosave_table']} where mb_id = '$mb_id' ");
|
||||||
|
return (int)$row['cnt'];
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
@ -57,7 +57,7 @@ function get_editor_js($id, $ckeditor=true)
|
|||||||
function chk_editor_js($id, $ckeditor=true, $textarea_name="내용을")
|
function chk_editor_js($id, $ckeditor=true, $textarea_name="내용을")
|
||||||
{
|
{
|
||||||
if ( $ckeditor ) {
|
if ( $ckeditor ) {
|
||||||
return "if (!{$id}_editor_data) { alert(\"$textarea_name 입력해 주십시오.\"); CKEDITOR.instances.{$id}.focus(); return false; }\n";
|
return "if (!{$id}_editor_data) { alert(\"$textarea_name 입력해 주십시오.\"); CKEDITOR.instances.{$id}.focus(); return false; }\nif (typeof(f.wr_content)!=\"undefined\") f.wr_content.value = {$id}_editor_data;\n";
|
||||||
} else {
|
} else {
|
||||||
return "if (!{$id}_editor.value) { alert(\"$textarea_name 입력해 주십시오.\"); {$id}_editor.focus(); return false; }\n";
|
return "if (!{$id}_editor.value) { alert(\"$textarea_name 입력해 주십시오.\"); {$id}_editor.focus(); return false; }\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,8 @@ if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
|
|||||||
<h2 id="wrapper_title"><?php echo $g4['title'] ?></h2>
|
<h2 id="wrapper_title"><?php echo $g4['title'] ?></h2>
|
||||||
|
|
||||||
<!-- 게시물 작성/수정 시작 { -->
|
<!-- 게시물 작성/수정 시작 { -->
|
||||||
<form name="fwrite" id="fwrite" action="<?php echo $action_url ?>" onsubmit="return fwrite_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off" style="width:<?php echo $width; ?>">
|
<form name="fwrite" id="fwrite" class="autosave" action="<?php echo $action_url ?>" onsubmit="return fwrite_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off" style="width:<?php echo $width; ?>">
|
||||||
|
<input type="hidden" name="uid" value="<?php echo get_uniqid(); ?>">
|
||||||
<input type="hidden" name="w" value="<?php echo $w ?>">
|
<input type="hidden" name="w" value="<?php echo $w ?>">
|
||||||
<input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
|
<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="wr_id" value="<?php echo $wr_id ?>">
|
||||||
@ -102,7 +103,12 @@ echo $option_hidden;
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><label for="wr_subject">제목<strong class="sound_only">필수</strong></label></th>
|
<th scope="row"><label for="wr_subject">제목<strong class="sound_only">필수</strong></label></th>
|
||||||
<td><input type="text" name="wr_subject" value="<?php echo $subject ?>" id="wr_subject" required class="frm_input required" size="50" maxlength="255"></td>
|
<td>
|
||||||
|
<input type="text" name="wr_subject" value="<?php echo $subject ?>" id="wr_subject" required class="frm_input required" size="50" maxlength="255">
|
||||||
|
<?php if ($is_member) { ?>
|
||||||
|
임시 저장된 글 (<span id="autosave_count"><?php echo $autosave_count; ?></span>)
|
||||||
|
<?php } ?>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
@ -212,3 +218,30 @@ function fwrite_submit(f)
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<!-- } 게시물 작성/수정 끝 -->
|
<!-- } 게시물 작성/수정 끝 -->
|
||||||
|
|
||||||
|
<script>
|
||||||
|
<?php if ($is_member) { ?>
|
||||||
|
function autosave() {
|
||||||
|
jQuery("form.autosave").each(function() {
|
||||||
|
if (typeof(CKEDITOR.instances.wr_content)!="undefined")
|
||||||
|
this.wr_content.value = CKEDITOR.instances.wr_content.getData();
|
||||||
|
jQuery.ajax({
|
||||||
|
url: g4_bbs_url+"/ajax.autosave.php",
|
||||||
|
data: {
|
||||||
|
"uid" : this.uid.value,
|
||||||
|
"subject": this.wr_subject.value,
|
||||||
|
"content": this.wr_content.value
|
||||||
|
},
|
||||||
|
type: "POST",
|
||||||
|
success: function(data){
|
||||||
|
if (data) {
|
||||||
|
$("#autosave_count").html(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(autosave, 3 * 1000);
|
||||||
|
<?php } ?>
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user