first commit 2
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
/**
|
||||
* rb.board.core.journal :: view.skin.php
|
||||
* '저널' 타입 전용 뷰어 - PDF 뷰어 기능만 담당
|
||||
*/
|
||||
|
||||
// 스킨 CSS 로드
|
||||
$_skin_url = G5_THEME_URL . '/skin/board/rb.board.core.journal';
|
||||
add_stylesheet('<link rel="stylesheet" href="' . $_skin_url . '/style.css?ver=' . G5_SERVER_TIME . '">', 0);
|
||||
|
||||
if (!function_exists('get_extension')) {
|
||||
function get_extension($filename) {
|
||||
$filename = basename($filename);
|
||||
return substr(strrchr($filename, "."), 1);
|
||||
}
|
||||
}
|
||||
|
||||
$pdfjs_url = G5_THEME_URL . '/js/pdfjs';
|
||||
$pdf_file_url = '';
|
||||
$pdf_download_url = ''; // 💡 [추가] 다운로드 URL을 저장할 변수
|
||||
|
||||
if ($view['file']['count'] > 0) { // 💡 [수정] 1이 아닌 0부터 시작하여 모든 첨부파일을 확인
|
||||
for ($i = 0; $i < $view['file']['count']; $i++) { // 💡 [수정]
|
||||
if (isset($view['file'][$i]) && strtolower(get_extension($view['file'][$i]['source'])) == 'pdf') {
|
||||
$pdf_file_url = $view['file'][$i]['path'].'/'.urlencode($view['file'][$i]['file']);
|
||||
$pdf_download_url = $view['file'][$i]['href']; // 💡 [추가] 다운로드 링크 저장
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- 💡 [핵심] 본문 내용은 전문 코어 파일에서 처리합니다. -->
|
||||
<div class="view-detail-content">
|
||||
<?php
|
||||
// HTML 에디터 사용 여부에 따라 conv_content 처리
|
||||
$html = 1;
|
||||
if (strstr($view['wr_option'], 'html1')) {
|
||||
$html = 1;
|
||||
} else if (strstr($view['wr_option'], 'html2')) {
|
||||
$html = 2;
|
||||
}
|
||||
// 💡 [핵심] g5_dynamic_img_url 함수를 적용하여 이미지 경로를 동적으로 변경합니다.
|
||||
echo g5_dynamic_img_url(conv_content($view['wr_content'], $html));
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php if ($pdf_file_url): ?>
|
||||
<div id="pdf-viewer-container">
|
||||
<!-- <?php /*if ($is_admin && $view['wr_8'] == 'Y'): */?>
|
||||
<div class="admin-option-item">
|
||||
<span class="option-text">💡 이 글은 메인 화면 포트폴리오 영역에 노출되고 있습니다.</span>
|
||||
</div>
|
||||
--><?php /*endif; */?>
|
||||
<div id="pdf-viewer-header">
|
||||
<button id="prev-page" class="btn btn-secondary"><i class="fa fa-arrow-left"></i> 이전</button>
|
||||
<div class="page-indicator">Page: <input type="number" id="page-num-input" value="1" min="1"> / <span id="page-count"></span></div>
|
||||
<button id="next-page" class="btn btn-secondary">다음 <i class="fa fa-arrow-right"></i></button>
|
||||
<?php if ($pdf_download_url): // 💡 [추가] 다운로드 버튼 ?>
|
||||
<a href="<?php echo $pdf_download_url; ?>" class="btn btn-primary" download>다운로드 <i class="fa fa-download"></i></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div id="canvas-wrapper"><canvas id="pdf-canvas"></canvas></div>
|
||||
<div id="pdf-loading"><div class="spinner"></div><p>PDF 파일을 불러오는 중입니다...</p></div>
|
||||
</div>
|
||||
<script src="<?php echo $pdfjs_url; ?>/pdf.min.js"></script>
|
||||
<script>
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
||||
'<?php echo $pdfjs_url; ?>/pdf.worker.min.js';
|
||||
|
||||
const url = '<?php echo $pdf_file_url; ?>';
|
||||
const canvas = document.getElementById('pdf-canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const loadingIndicator = document.getElementById('pdf-loading');
|
||||
const pageNumInput = document.getElementById('page-num-input');
|
||||
const pageCountSpan = document.getElementById('page-count');
|
||||
const prevButton = document.getElementById('prev-page');
|
||||
const nextButton = document.getElementById('next-page');
|
||||
const canvasWrapper = document.getElementById('canvas-wrapper');
|
||||
|
||||
let pdfDoc = null;
|
||||
let pageNum = 1;
|
||||
let pageRendering = false;
|
||||
let pageNumPending = null;
|
||||
|
||||
function hideLoadingIndicator() {
|
||||
loadingIndicator.style.display = 'none';
|
||||
}
|
||||
|
||||
function renderPage(num) {
|
||||
pageRendering = true;
|
||||
loadingIndicator.style.display = 'flex';
|
||||
|
||||
pdfDoc.getPage(num).then(function(page) {
|
||||
const desiredWidth = canvasWrapper.clientWidth;
|
||||
const viewport = page.getViewport({ scale: 1 });
|
||||
const scale = desiredWidth / viewport.width;
|
||||
const scaledViewport = page.getViewport({ scale });
|
||||
|
||||
canvas.height = scaledViewport.height;
|
||||
canvas.width = scaledViewport.width;
|
||||
|
||||
page.render({
|
||||
canvasContext: ctx,
|
||||
viewport: scaledViewport
|
||||
}).promise.then(function() {
|
||||
pageRendering = false;
|
||||
hideLoadingIndicator();
|
||||
if (pageNumPending !== null) {
|
||||
renderPage(pageNumPending);
|
||||
pageNumPending = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
pageNumInput.value = num;
|
||||
}
|
||||
|
||||
function queueRenderPage(num) {
|
||||
if (pageRendering) pageNumPending = num;
|
||||
else renderPage(num);
|
||||
}
|
||||
|
||||
function onPrevPage() {
|
||||
if (pageNum <= 1) return;
|
||||
pageNum--;
|
||||
queueRenderPage(pageNum);
|
||||
}
|
||||
|
||||
function onNextPage() {
|
||||
if (pageNum >= pdfDoc.numPages) return;
|
||||
pageNum++;
|
||||
queueRenderPage(pageNum);
|
||||
}
|
||||
|
||||
prevButton.addEventListener('click', onPrevPage);
|
||||
nextButton.addEventListener('click', onNextPage);
|
||||
|
||||
pageNumInput.addEventListener('change', function() {
|
||||
const n = parseInt(this.value, 10);
|
||||
if (n > 0 && n <= pdfDoc.numPages) {
|
||||
pageNum = n;
|
||||
queueRenderPage(pageNum);
|
||||
} else {
|
||||
this.value = pageNum;
|
||||
}
|
||||
});
|
||||
|
||||
pdfjsLib.getDocument(url).promise.then(function(pdf) {
|
||||
pdfDoc = pdf;
|
||||
pageCountSpan.textContent = pdfDoc.numPages;
|
||||
pageNumInput.max = pdfDoc.numPages;
|
||||
renderPage(pageNum);
|
||||
}).catch(function(err) {
|
||||
console.error(err);
|
||||
loadingIndicator.innerHTML =
|
||||
'<p style="color:red;">PDF 로드 실패</p>';
|
||||
hideLoadingIndicator();
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
<div class="view-footer">
|
||||
<div class="btn-group-left">
|
||||
<?php if ($prev_href): ?><a href="<?php echo $prev_href ?>" class="btn btn-secondary">이전글</a><?php endif; ?>
|
||||
<?php if ($next_href): ?><a href="<?php echo $next_href ?>" class="btn btn-secondary">다음글</a><?php endif; ?>
|
||||
</div>
|
||||
<div class="btn-group-right">
|
||||
<a href="<?php echo $list_href ?>" class="btn btn-primary">목록</a>
|
||||
<?php if ($update_href): ?><a href="<?php echo $update_href ?>" class="btn btn-secondary">수정</a><?php endif; ?>
|
||||
<?php if ($delete_href): ?><a href="<?php echo $delete_href ?>" onclick="del(this.href); return false;" class="btn btn-secondary">삭제</a><?php endif; ?>
|
||||
<?php if ($write_href): ?><a href="<?php echo $write_href ?>" class="btn btn-primary">글쓰기</a><?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user