cfmgrv4 init...3

This commit is contained in:
최준흠 2024-10-16 15:25:29 +09:00
parent f887fc169a
commit 34bff1c58b

View File

@ -1,122 +1,124 @@
<?= $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?> <?= $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?>
<?= $this->section('content') ?> <?= $this->section('content') ?>
<div class="layout_top"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/top'); ?></div> <div class="layout_top"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/top'); ?></div>
<div class="layout_middle"> <table class="layout_middle">
<div class="layout_left"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?></div> <tr>
<div class="layout_right"> <td class="layout_left"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?></td>
<?= $this->include("templates/{$viewDatas['layout']}/index_header"); ?> <td class="layout_right">
<div id="container" class="layout_content"> <?= $this->include("templates/{$viewDatas['layout']}/index_header"); ?>
<style> <div id="container" class="layout_content">
.news-container { <style>
display: flex; .news-container {
flex-wrap: wrap; display: flex;
justify-content: space-between; flex-wrap: wrap;
} justify-content: space-between;
}
.news-item { .news-item {
width: 48%; width: 48%;
margin-bottom: 20px; margin-bottom: 20px;
border: 1px solid #ddd; border: 1px solid #ddd;
padding: 10px; padding: 10px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
} }
.news-item h3 { .news-item h3 {
font-size: 18px; font-size: 18px;
margin-bottom: 5px; margin-bottom: 5px;
} }
.news-item p { .news-item p {
font-size: 14px; font-size: 14px;
color: #666; color: #666;
} }
</style> </style>
<div <div
style="display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 20px; border-bottom: 2px solid #007bff; padding-bottom: 10px;"> style="display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 20px; border-bottom: 2px solid #007bff; padding-bottom: 10px;">
<h2 style="color: #007bff; font-size: 24px; margin: 0;">최신 뉴스</h2> <h2 style="color: #007bff; font-size: 24px; margin: 0;">최신 뉴스</h2>
<small style="color: #6c757d; font-size: 14px;">최근 업데이트: <span id="lastUpdate"></span></small> <small style="color: #6c757d; font-size: 14px;">최근 업데이트: <span id="lastUpdate"></span></small>
</div> </div>
<script> <script>
function updateLastUpdateTime() { function updateLastUpdateTime() {
const now = new Date(); const now = new Date();
const options = { const options = {
year: 'numeric', year: 'numeric',
month: '2-digit', month: '2-digit',
day: '2-digit', day: '2-digit',
hour: '2-digit', hour: '2-digit',
minute: '2-digit', minute: '2-digit',
second: '2-digit', second: '2-digit',
hour12: false hour12: false
}; };
document.getElementById('lastUpdate').textContent = now.toLocaleString('ko-KR', options); document.getElementById('lastUpdate').textContent = now.toLocaleString('ko-KR', options);
} }
// fetchRSS 함수 정의 // fetchRSS 함수 정의
function fetchRSS() { function fetchRSS() {
fetch('/RSSFeed/getITWorld') fetch('/RSSFeed/getITWorld')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
const newsContainer = document.getElementById('newsContainer'); const newsContainer = document.getElementById('newsContainer');
newsContainer.innerHTML = ''; newsContainer.innerHTML = '';
data.forEach(item => { data.forEach(item => {
// console.log('RSS 항목:', item); // 디버깅을 위한 로그 // console.log('RSS 항목:', item); // 디버깅을 위한 로그
const pubDate = new Date(item.pubDate); const pubDate = new Date(item.pubDate);
const newsItem = document.createElement('div'); const newsItem = document.createElement('div');
newsItem.className = 'news-item'; newsItem.className = 'news-item';
// 이미지 URL 추출 및 변환 // 이미지 URL 추출 및 변환
let imageUrl = item.imageUrl || extractImageFromContent(item.content); let imageUrl = item.imageUrl || extractImageFromContent(item.content);
imageUrl = convertToAbsoluteUrl(imageUrl, item.link); imageUrl = convertToAbsoluteUrl(imageUrl, item.link);
newsItem.innerHTML = ` newsItem.innerHTML = `
<h3><img src="${imageUrl || '/images/common/news.png'}" alt="${item.title}" style="width: 30px; height: 30px; object-fit: cover; margin-bottom: 10px;" onerror="this.onerror=null; this.src='/images/common/news.png';"><a href="${item.link}" target="_blank">${item.title}</a></h3> <h3><img src="${imageUrl || '/images/common/news.png'}" alt="${item.title}" style="width: 30px; height: 30px; object-fit: cover; margin-bottom: 10px;" onerror="this.onerror=null; this.src='/images/common/news.png';"><a href="${item.link}" target="_blank">${item.title}</a></h3>
<p>${item.description}</p> <p>${item.description}</p>
<small>게시일: ${pubDate.toLocaleString()}</small> <small>게시일: ${pubDate.toLocaleString()}</small>
`; `;
newsContainer.appendChild(newsItem); newsContainer.appendChild(newsItem);
}); });
updateLastUpdateTime(); // RSS 피드를 가져온 후 시간 업데이트 updateLastUpdateTime(); // RSS 피드를 가져온 후 시간 업데이트
}) })
.catch(error => console.error('RSS 피드를 가져오는 중 오류 발생:', error)); .catch(error => console.error('RSS 피드를 가져오는 중 오류 발생:', error));
}
// RSS 내용에서 이미지 URL 추출
function extractImageFromContent(content) {
const parser = new DOMParser();
const doc = parser.parseFromString(content, 'text/html');
const img = doc.querySelector('img');
return img ? img.src : null;
}
// 상대 URL을 절대 URL로 변환
function convertToAbsoluteUrl(url, baseUrl) {
if (!url) return null;
if (url.startsWith('http://') || url.startsWith('https://')) {
return url; // 이미 절대 URL인 경우
} }
const base = new URL(baseUrl);
if (url.startsWith('/')) { // RSS 내용에서 이미지 URL 추출
return `${base.protocol}//${base.hostname}${url}`; function extractImageFromContent(content) {
const parser = new DOMParser();
const doc = parser.parseFromString(content, 'text/html');
const img = doc.querySelector('img');
return img ? img.src : null;
} }
return `${base.protocol}//${base.hostname}${base.pathname.substring(0, base.pathname.lastIndexOf('/') + 1)}${url}`;
}
// 페이지 로드 시 초기 시간 설정 및 RSS 피드 가져오기 // 상대 URL을 절대 URL로 변환
updateLastUpdateTime(); function convertToAbsoluteUrl(url, baseUrl) {
fetchRSS(); if (!url) return null;
if (url.startsWith('http://') || url.startsWith('https://')) {
return url; // 이미 절대 URL인 경우
}
const base = new URL(baseUrl);
if (url.startsWith('/')) {
return `${base.protocol}//${base.hostname}${url}`;
}
return `${base.protocol}//${base.hostname}${base.pathname.substring(0, base.pathname.lastIndexOf('/') + 1)}${url}`;
}
// 1시간마다 RSS 피드 업데이트 // 페이지 로드 시 초기 시간 설정 및 RSS 피드 가져오기
setInterval(fetchRSS, 3600000); updateLastUpdateTime();
</script> fetchRSS();
<div class="news-container" id="newsContainer">
<!-- RSS 피드 항목들이 여기에 동적으로 추가됩니다 --> // 1시간마다 RSS 피드 업데이트
setInterval(fetchRSS, 3600000);
</script>
<div class="news-container" id="newsContainer">
<!-- RSS 피드 항목들이 여기에 동적으로 추가됩니다 -->
</div>
</div> </div>
</div> </div>
</div> <div class="layout_footer"><?= $this->include("templates/{$viewDatas['layout']}/index_footer"); ?></div>
<div class="layout_footer"><?= $this->include("templates/{$viewDatas['layout']}/index_footer"); ?></div> </td>
</div> </tr>
</div> </table>
<div class="layout_bottom"> <div class="layout_bottom">
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?> <?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?>
</div> </div>