Files
Gnuboard5/bbs/qawrite.php
T
thisgun a612e69d3e [perf]for 루프 조건의 count() 호출을 루프 밖으로 추출 (핵심 파일)
for ($i=0; $i<count(\$arr); $i++) 패턴은 매 반복마다 count()를 호출하여
불필요한 CPU 오버헤드를 발생시킴. 루프 전에 한 번만 count()를 계산하여
변수에 저장하는 고전적인 최적화.

적용 파일 (19개, 41곳):
- lib/common.lib.php (8)
- common.php (2)
- lib/shop.lib.php (5)
- lib/naverpay.lib.php (1)
- lib/thumbnail.lib.php (2)
- bbs/list.php (1), bbs/search.php (4), bbs/qalist.php (1), bbs/qawrite.php (1)
- bbs/ajax.filter.php (1), bbs/write_update.php (4)
- bbs/write_comment_update.php (1), bbs/memo_form_update.php (2)
- bbs/new_delete.php (1), bbs/move_update.php (4)
- shop/search.php (1), shop/orderform.sub.php (1)
- mobile/shop/search.php (1), mobile/shop/orderform.sub.php (1)

부수 효과:
- lib/shop.lib.php line 2115: 동일 루프 내 strstr($dlcomp, $company)를
  strpos($dlcomp, $company) !== false 로 변경 (strstr 최적화의 일부)

제외:
- theme/, skin/, plugin/ (사용자 커스터마이징/서드파티)
- lib/PHPExcel/ (서드파티 라이브러리)
- adm/ 및 shop/mail/ (관리자/드문 경로, 별도 후속 작업 여지)
- 주석 처리된 코드 (bbs/delete.php:127, bbs/delete_all.php:143)
2026-04-16 02:26:59 +00:00

148 lines
4.6 KiB
PHP

<?php
include_once('./_common.php');
include_once(G5_EDITOR_LIB);
if($w != '' && $w != 'u' && $w != 'r') {
alert('올바른 방법으로 이용해 주십시오.');
}
$qa_id = isset($_REQUEST['qa_id']) ? (int) $_REQUEST['qa_id'] : 0;
$write = array('qa_email_recv'=>'', 'qa_subject'=>'', 'qa_category'=>'');
if($is_guest)
alert('회원이시라면 로그인 후 이용해 보십시오.', './login.php?url='.urlencode(G5_BBS_URL.'/qalist.php'));
$qaconfig = get_qa_config();
$token = _token();
set_session('ss_qa_write_token', $token);
$g5['title'] = $qaconfig['qa_title'];
include_once('./qahead.php');
$skin_file = $qa_skin_path.'/write.skin.php';
if(is_file($skin_file)) {
/*==========================
$w == a : 답변
$w == r : 추가질문
$w == u : 수정
==========================*/
if($w == 'u' || $w == 'r') {
$sql = " select * from {$g5['qa_content_table']} where qa_id = '$qa_id' ";
if(!$is_admin) {
$sql .= " and mb_id = '{$member['mb_id']}' ";
}
$write = sql_fetch($sql);
if($w == 'u') {
if(!$write['qa_id'])
alert('게시글이 존재하지 않습니다.\\n삭제되었거나 자신의 글이 아닌 경우입니다.');
if(!$is_admin) {
if($write['qa_type'] == 0 && $write['qa_status'] == 1)
alert('답변이 등록된 문의글은 수정할 수 없습니다.');
if($write['mb_id'] != $member['mb_id'])
alert('게시글을 수정할 권한이 없습니다.\\n\\n올바른 방법으로 이용해 주십시오.', G5_URL);
}
}
}
// 분류
$category_option = '';
if(trim($qaconfig['qa_category'])) {
$category = explode('|', $qaconfig['qa_category']);
$category_cnt = count($category);
for($i=0; $i<$category_cnt; $i++) {
$category_option .= option_selected($category[$i], $write['qa_category']);
}
} else {
alert('1:1문의 설정에서 분류를 설정해 주십시오');
}
$is_dhtml_editor = false;
if ($config['cf_editor'] && $qaconfig['qa_use_editor'] && (!is_mobile() || defined('G5_IS_MOBILE_DHTML_USE') && G5_IS_MOBILE_DHTML_USE)) {
$is_dhtml_editor = true;
}
// 추가질문에서는 제목을 공백으로
if($w == 'r')
$write['qa_subject'] = '';
$content = '';
if ($w == '') {
$content = html_purifier($qaconfig['qa_insert_content']);
} else if($w == 'r') {
if($is_dhtml_editor)
$content = '<div><br><br><br>====== 이전 답변내용 =======<br></div>';
else
$content = "\n\n\n\n====== 이전 답변내용 =======\n";
// KISA 취약점 권고사항 Stored XSS (210624)
$content .= get_text(html_purifier($write['qa_content']), 0);
} else {
//$content = get_text($write['qa_content'], 0);
// KISA 취약점 권고사항 Stored XSS
$content = get_text(html_purifier($write['qa_content']), 0);
}
$editor_html = editor_html('qa_content', $content, $is_dhtml_editor);
$editor_js = '';
$editor_js .= get_editor_js('qa_content', $is_dhtml_editor);
$editor_js .= chk_editor_js('qa_content', $is_dhtml_editor);
$upload_max_filesize = number_format($qaconfig['qa_upload_size']) . ' 바이트';
$html_value = '';
$html_checked = '';
if (isset($write['qa_html']) && $write['qa_html']) {
$html_checked = 'checked';
$html_value = $write['qa_html'];
if($w == 'r' && $write['qa_html'] == 1 && !$is_dhtml_editor)
$html_value = 2;
}
$is_email = false;
$req_email = '';
if($qaconfig['qa_use_email']) {
$is_email = true;
if($qaconfig['qa_req_email'])
$req_email = 'required';
if($w == '' || $w == 'r')
$write['qa_email'] = $member['mb_email'];
if($w == 'u' && $is_admin && $write['qa_type'])
$is_email = false;
}
$is_hp = false;
$req_hp = '';
if($qaconfig['qa_use_hp']) {
$is_hp = true;
if($qaconfig['qa_req_hp'])
$req_hp = 'required';
if($w == '' || $w == 'r')
$write['qa_hp'] = $member['mb_hp'];
if($w == 'u' && $is_admin && $write['qa_type'])
$is_hp = false;
}
$list_href = G5_BBS_URL.'/qalist.php'.preg_replace('/^&amp;/', '?', $qstr);
$action_url = https_url(G5_BBS_DIR).'/qawrite_update.php';
include_once($skin_file);
} else {
echo '<div>'.str_replace(G5_PATH.'/', '', $skin_file).'이 존재하지 않습니다.</div>';
}
include_once('./qatail.php');