cfmgrv4 init...3

This commit is contained in:
최준흠 2024-10-16 16:15:45 +09:00
parent fc3135b2e7
commit 6e3e41d0b9
2 changed files with 27 additions and 41 deletions

View File

@ -1,10 +1,16 @@
<?= $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?>
<?= $this->section('content') ?>
<div class="layout_top"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/top'); ?></div>
<!-- Layout Middle Start -->
<table class="layout_middle">
<tr>
<td class="layout_left"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?></td>
<td class="layout_left">
<!-- Layout Left Start -->
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?>
<!-- Layout Left End -->
</td>
<td class="layout_right">
<!-- Layout Right Start -->
<?= $this->include("templates/{$viewDatas['layout']}/index_header"); ?>
<div id="container" class="layout_content">
<link href="/css/<?= $viewDatas['layout'] ?>/index.css" media="screen" rel="stylesheet" type="text/css" />
@ -50,9 +56,11 @@
<script type="text/javascript" src="/js/<?= $viewDatas['layout'] ?>/index.js"></script>
</div>
<div class="layout_footer"><?= $this->include("templates/{$viewDatas['layout']}/index_footer"); ?></div>
<!-- Layout Right End -->
</td>
</tr>
</table>
<!-- Layout Middle End -->
<div class="layout_bottom">
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?>
</div>

View File

@ -1,12 +1,19 @@
<?= $this->extend(LAYOUTS[$viewDatas['layout']]['path']) ?>
<?= $this->section('content') ?>
<div class="layout_top"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/top'); ?></div>
<!-- Layout Middle Start -->
<table class="layout_middle">
<tr>
<td class="layout_left"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?></td>
<td class="layout_left">
<!-- Layout Left Start -->
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?>
<!-- Layout Left End -->
</td>
<td class="layout_right">
<!-- Layout Right Start -->
<?= $this->include("templates/{$viewDatas['layout']}/index_header"); ?>
<div id="container" class="layout_content">
<!-- RSS Feed Start -->
<style>
.news-container {
display: flex;
@ -32,27 +39,8 @@
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>
<div class="news-container" id="newsContainer"><!-- RSS 피드 항목들이 여기에 동적으로 추가됩니다 --></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')
@ -61,12 +49,10 @@
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);
@ -77,12 +63,10 @@
`;
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');
@ -90,11 +74,10 @@
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인 경우
return url;
}
const base = new URL(baseUrl);
if (url.startsWith('/')) {
@ -103,23 +86,18 @@
return `${base.protocol}//${base.hostname}${base.pathname.substring(0, base.pathname.lastIndexOf('/') + 1)}${url}`;
}
// 페이지 로드 시 초기 시간 설정 및 RSS 피드 가져오기
updateLastUpdateTime();
fetchRSS();
// 1시간마다 RSS 피드 업데이트
setInterval(fetchRSS, 3600000);
document.addEventListener('DOMContentLoaded', function() {
fetchRSS();
setInterval(fetchRSS, 3600000);
});
</script>
<div class="news-container" id="newsContainer">
<!-- RSS 피드 항목들이 여기에 동적으로 추가됩니다 -->
</div>
</div>
<!-- RSS Feed End -->
</div>
<div class="layout_footer"><?= $this->include("templates/{$viewDatas['layout']}/index_footer"); ?></div>
<!-- Layout Right End -->
</td>
</tr>
</table>
<div class="layout_bottom">
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?>
</div>
<!-- Layout Middle End -->
<div class="layout_bottom"><?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?></div>
<?= $this->endSection() ?>