소스 파일 : /navigation/naviFetch_utils.php (2022-08-11)     소스 설명 : (navi) 서버 db로부터 데이터 가져오기 유틸리티 함수 모음
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
<?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 링크 주소 변경
//	$abbr = str_replace('abbr_view.php?m_temp1=','/test/view/view.php?no=',$abbr);
  	$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='/test/view/view.php?no=","a target='_blank' href='/test/view/view.php?no=",$abbr);

	// 삽입 그림 또는 링크 또는 코드 또는 수식(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);
}

// 용어해설 내 번호 항목 영역 마다 분리 추출하여 배열화시키는 함수
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;
}
*/

?>


Copyrightⓒ written by 차재복 (Cha Jae Bok)
"본 웹사이트 내 모든 저작물은 원출처를 밝히는 한 자유롭게 사용(상업화포함) 가능합니다"