123 lines
5.8 KiB
PHP
123 lines
5.8 KiB
PHP
<?= $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?>
|
|
<?= $this->section('content') ?>
|
|
<div class="layout_top"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/top'); ?></div>
|
|
<div class="layout_middle">
|
|
<div class="layout_left"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?></div>
|
|
<div class="layout_right">
|
|
<?= $this->include("templates/{$viewDatas['layout']}/index_header"); ?>
|
|
<div id="container" class="layout_content">
|
|
<style>
|
|
.news-container {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.news-item {
|
|
width: 48%;
|
|
margin-bottom: 20px;
|
|
border: 1px solid #ddd;
|
|
padding: 10px;
|
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.news-item h3 {
|
|
font-size: 18px;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.news-item p {
|
|
font-size: 14px;
|
|
color: #666;
|
|
}
|
|
</style>
|
|
<div
|
|
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>
|
|
<small style="color: #6c757d; font-size: 14px;">최근 업데이트: <span id="lastUpdate"></span></small>
|
|
</div>
|
|
|
|
<script>
|
|
function updateLastUpdateTime() {
|
|
const now = new Date();
|
|
const options = {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
second: '2-digit',
|
|
hour12: false
|
|
};
|
|
document.getElementById('lastUpdate').textContent = now.toLocaleString('ko-KR', options);
|
|
}
|
|
|
|
// fetchRSS 함수 정의
|
|
function fetchRSS() {
|
|
fetch('/RSSFeed/getITWorld')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const newsContainer = document.getElementById('newsContainer');
|
|
newsContainer.innerHTML = '';
|
|
data.forEach(item => {
|
|
// console.log('RSS 항목:', item); // 디버깅을 위한 로그
|
|
const pubDate = new Date(item.pubDate);
|
|
const newsItem = document.createElement('div');
|
|
newsItem.className = 'news-item';
|
|
|
|
// 이미지 URL 추출 및 변환
|
|
let imageUrl = item.imageUrl || extractImageFromContent(item.content);
|
|
imageUrl = convertToAbsoluteUrl(imageUrl, item.link);
|
|
|
|
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>
|
|
<p>${item.description}</p>
|
|
<small>게시일: ${pubDate.toLocaleString()}</small>
|
|
`;
|
|
newsContainer.appendChild(newsItem);
|
|
});
|
|
updateLastUpdateTime(); // RSS 피드를 가져온 후 시간 업데이트
|
|
})
|
|
.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('/')) {
|
|
return `${base.protocol}//${base.hostname}${url}`;
|
|
}
|
|
return `${base.protocol}//${base.hostname}${base.pathname.substring(0, base.pathname.lastIndexOf('/') + 1)}${url}`;
|
|
}
|
|
|
|
// 페이지 로드 시 초기 시간 설정 및 RSS 피드 가져오기
|
|
updateLastUpdateTime();
|
|
fetchRSS();
|
|
|
|
// 1시간마다 RSS 피드 업데이트
|
|
setInterval(fetchRSS, 3600000);
|
|
</script>
|
|
<div class="news-container" id="newsContainer">
|
|
<!-- RSS 피드 항목들이 여기에 동적으로 추가됩니다 -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="layout_footer"><?= $this->include("templates/{$viewDatas['layout']}/index_footer"); ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="layout_bottom">
|
|
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?>
|
|
</div>
|
|
<?= $this->endSection() ?>
|