<?php // (2021.1.19, 차재복, Cha Jae Bok, cjbword@gmailcom)
//** '소스 파일을 웹페이지로 보기'의 함수 모음 **
# 소스 보기 함수 루틴 =======================
function src_view ($file_alias, $find) {
// 선택 파일 내용 출력
// 소스 라인 배열 선언
$source = array();
// 파일 오픈
$fp = fopen($file_alias, "r") or die("파일열기에 실패하였습니다");
while( !feof($fp) ){
// 소스를 한 줄씩 읽어들임
$line_source = htmlspecialchars( fgets($fp) );
// 라인 소스 배열화
$source[] = $line_source;
}
echo "<div style='margin-top:10px;overflow:auto;border:1px dotted gray;'>";
// 소스 라인
echo "<div id='source_line' class='opened_source'
style='float:left;box-sizing:border-box;width:5%;text-align:center;line-height:120%;border:1px dotted gray;'>";
echo "<pre>";
for ($i=1; $i<=count($source); $i++) {
$num_str = str_pad($i,3,"0",STR_PAD_LEFT);
echo "<span id='l{$i}'>".$num_str."</span>";
echo "<br>";
}
echo "</pre>";
echo "</div>";
// 소스 내용
echo "<div id='source_origin' class='opened_source'
style='float:left;box-sizing:border-box;width:95%;overflow:auto;line-height:120%;padding-left:15px;'>";
echo "<pre><source>";
foreach ($source as $key => $value) {
if (!empty($find) && strpos($value,$find) !== false) {
if (empty($line_no)) $line_no = $key + 1;
echo "<span style='color:red;'>".$value."</span>";
} else {
echo $value;
}
}
echo "</source></pre>";
echo "</div>";
echo "</div>";
// 파일 닫음
fclose($fp);
return $line_no; // $find 할 때, 찾은 해당 라인 번호를 리턴
}
# ======================= 소스 보기 함수 루틴 끝
# 소스 설명 함수 루틴 =======================
function src_desc ($dir, $file, $dbi) {
if (empty($dir) or empty($file)) return;
// 해킹 방어
$dir = mysqli_real_escape_string($dbi, $dir);
$file = mysqli_real_escape_string($dbi, $file);
// 쿼리 실행
$query = "select dir,filename,run,expr,date,code from src_files where dir='{$dir}' and filename='{$file}'";
$result = mysqli_query($dbi, $query);
if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
$matched = mysqli_fetch_assoc($result);
return $matched; // dir,filename,expr,date,code
}
# ======================= 소스 설명 함수 루틴 끝
# 소스 내용 중 언어 키워드 포함 여부 확인 =======================
function src_lang_keyword ($file_desc, $dbi) {
// 파일 확장자 추출
$file_ext = substr($file_desc['filename'], strrpos($file_desc['filename'], '.') + 1);
// HTML일 경우, PHP로도 가능토록 함
if ($file_ext=='html') $file_ext = 'PHP';
// 쿼리 실행
$query = "select keyword,lang,word_no from lang_keyword where lang='{$file_ext}' order by lang,keyword";
$result = mysqli_query($dbi, $query);
if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
$str = '';
$i = 1;
$rec_no = 1;
while ($matched = mysqli_fetch_assoc($result)) {
// 소스 내 포함된 키워드들 찾고 보여주기
if (strpos($file_desc['code'],$matched['keyword'])!==false) {
if($i != 1) $str .= ", ";
// 페이지 산출
$page_records = 10; // 페이지 당 출력 레코드 수
$page = ceil($rec_no/$page_records);
//
$str .= "<a href='/test/testing/testing.html?menu=t11&id=35&lang=".$matched['lang']."&p=$page'>".$matched['keyword']."</a>";
$i += 1;
}
$rec_no += 1;
}
/*
if (!empty($str)) {
// echo "<hr style='clear:both;'>";
echo "<br style='clear:both;'>";
echo strtoupper($file_ext)." 키워드 : ";
echo $str;
}
*/
}
# ======================= 소스 설명 함수 루틴 끝
?>
"본 웹사이트 내 모든 저작물은 원출처를 밝히는 한 자유롭게 사용(상업화포함) 가능합니다"