001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071072073074075076077078079080081082083084085086087088089090091092093094095096097098099100101
<?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; } */ ?>