<?php // (2022.8.21, 차재복, Cha Jae Bok, http://www.ktword.co.kr)
// no 일치하는 용어해설 db에서 가져와 번호 마다 분리 후 json 포멧 송출
function ajaxFetchDetailSeparate($no, $dbi, $err_msg='') {
$query = "select a.abbr,b.origin,b.in_no,b.type,b.text,b.code,c.yako,c.full_name,c.korean,c.extra_keyword,c.sujung
from dict_anchor a left join embed b on a.no=b.no left join cjb_dict c on a.no=c.no
where a.no=$no";
$result = mysqli_query($dbi,$query);
if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
// 내용 추출, 이미지 링크 삽입, mathjax 삽입 등
$i = 0;
while ( $matched = mysqli_fetch_assoc($result) ) {
// 초기값 설정
if ($i == 0) {
$abbr = $matched['abbr'];
include_once "../base_utils/common_utils.php";
$fullname = wordListComma($matched['yako'], $matched['korean'], $matched['full_name'],
$matched['extra_keyword']);
$name = mb_substr($fullname,0,30,'utf-8').' ... ';
$date = date("Y-m-d", strtotime($matched['sujung']));
}
// 내용 중, `{[(번호)]}`로써, 삽입된 그림, 링크, 코드, 수식(MathJax) 추출 후 배열화
$embed_arr[] = array('in_no'=>$matched['in_no'],'origin'=>$matched['origin'],'type'=>$matched['type'],
'text'=>$matched['text'],'code'=>$matched['code']);
$i = $i + 1;
}
// 만일, abbr 비었으면 리턴
if (empty($abbr)) return;
// a 링크 주소 변경
$query = "select a.no,a.in_no,a.no_related,b.titlename,b.tree_id,c.name,c.path2node_v2
from dict_related a left join book_idx b on a.no_related=b.no left join gubun_tree_v2 c on b.tree_id=c.id
where a.no=$no
order by a.in_no";
$result = mysqli_query($dbi,$query);
if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
while ( $matched = mysqli_fetch_assoc($result) ) {
$related[$matched['no_related']] = $matched['path2node_v2'];
}
/*
// $abbr = str_replace("a href='abbr_view.php?m_temp1=","a target='_blank' href='/test/view/view.php?no=",$abbr);
$abbr = str_replace("a href='abbr_view.php?m_temp1=","a target='one_more' href='/test/view/view.php?no=",$abbr);
// $abbr = str_replace("a href='/test/view/view.php?no=","a target='_blank' href='/test/view/view.php?no=",$abbr);
$abbr = str_replace("a href='/test/view/view.php?no=","a target='one_more' href='/test/view/view.php?no=",$abbr);
*/
// 전처리
$abbr = str_replace("<a href='abbr_view.php?m_temp1=","<a href='/test/view/view.php?no=",$abbr);
$abbr = pair_delimiter($abbr,"&id=","' >","'>");
$abbr = pair_delimiter($abbr," title=","'>",">");
// 본처리
$abbr = pair_delimiter($abbr,"<a href='/test/view/view.php?no=","</a>",'innerExtractDo',$related);
// $abbr = pair_delimiter($abbr,"<a href='/test/view/view.php?no=","</a>",'innerExtractDo',$related);
// 삽입 그림 또는 링크 또는 코드 또는 수식(MathJax) 교체, 끝하단에 추가 이미지 파일 보이기
include_once "../view/view_body_text.php";
$abbr = str_embed_display($abbr, $embed_arr, '', false);
/*
include_once "../base_utils/common_utils.php";
// mathjax 요소 있으면, display 경우에, div 감쌈
$abbr = mathjax_div_wrap_ajax($abbr);
*/
// 각 번호 항목 마다 분리 추출하여 배열화시키는 함수 호출
$return = array('separated' => seperate($abbr), 'name' => $name, 'fullname' => $fullname, 'date' => $date);
// 항목 섹션 마다 구분된채, json 포멧으로 송출
echo json_encode($return,JSON_UNESCAPED_UNICODE);
}
// 추출 내용 중 일부 조작처리 (abbr 내 no 추출 등)
function innerExtractDo($str,$para) {
// no
$delimeter['no']['start'] = "no=";
$delimeter['no']['end'] = "\'>";
// id
// $delimeter['id']['start'] = "&id=";
// $delimeter['id']['end'] = "' title=";
// name
$delimeter['name']['start'] = "\'>";
$delimeter['name']['end'] = "<\/a>";
foreach( $delimeter as $key=>$value) {
if(preg_match("/{$value['start']}(.*?){$value['end']}/", $str, $matches)) $keyword[] = $matches[1];
else return $str;
}
$path = $para[$keyword[0]];
$name = htmlspecialchars($keyword[1]);
return "<a href=\"javascript:idPathFocusDirect('{$path}','{$keyword[0]}','{$name}')\">{$name}</a>";
// return $path.", ".$keyword[0].", ".$keyword[1].", ".$keyword[2]; // $path
}
// 용어해설 내 번호 항목 영역 마다 분리 추출하여 배열화시키는 함수
function seperate($abbr) {
// 용어해설 설명 단위 구절(항) 마다 추출
$rest = $abbr;
$i = 0;
$first = 0;
while ( ( $pos = strpos($rest,"\n".($i+2).". ") // linux
or $pos = strpos($rest,"\r\n".($i+2).". ") // windows
or $pos = strpos($rest,"\r".($i+2).". ") // mac
) !== false ) {
$len = $pos - $first + 1;
$substr[$i] = trim(substr($rest, $first, $len));
$rest = substr($rest, $pos);
$i = $i + 1;
}
$substr[$i] = $rest;
return $substr;
}
/* javascript ajax 기능에서, div 내 표출시키려는 내부 div는 사라져버림
// 용어해설 내 mathjax 있는 경우에, div inline-block 요소로 감쌈
function mathjax_div_wrap_ajax($abbr) {
$right_bk = 0;
while (($left_bk=strpos($abbr,'[#',$right_bk)) and ($right_bk=strpos($abbr,'#]',$left_bk))) {
$left_str = substr($abbr,0,$left_bk);
$right_str = substr($abbr,$right_bk+strlen('#]'));
$math_word_len = $right_bk + strlen('#]') - $left_bk;
$math_word = substr($abbr, $left_bk, $math_word_len);
$replaced = "<div style='display:inline-block;'>"
.$math_word
."</div>"; // ."sp={$sp},ln={$ln}"
$abbr = $left_str . $replaced . $right_str;
$right_bk = $left_bk + strlen($replaced);
}
return $abbr;
}
*/
?>