Files
dnssash/theme/rd.laser/rb.custom/_base_module/module.php
T
2026-06-11 18:47:38 +09:00

102 lines
4.3 KiB
PHP

<?php
if (!defined('_GNUBOARD_')) exit;
// =================================================================================
// 💡 [사용법] 이 파일을 복사하여 새 모듈을 만들 때 아래 TODO 항목들을 수정하세요.
// =================================================================================
// TODO: 'board_name'을 실제 게시판 테이블명으로 변경하세요. (예: 'gallery', 'news' 등)
$bo_table_name = 'board_name';
// TODO: 가져올 게시물 수를 변경할 수 있습니다.
$limit = 3;
// --- 데이터 처리 ---
$module_data = array();
$sql = " SELECT wr_id, wr_subject, wr_content FROM {$g5['write_prefix']}{$bo_table_name} WHERE wr_is_comment = 0 ORDER BY wr_num, wr_reply LIMIT {$limit} ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {
$files = get_file($bo_table_name, $row['wr_id']);
$image_url = (isset($files[0]['path']) && isset($files[0]['file'])) ? $files[0]['path'].'/'.$files[0]['file'] : G5_THEME_URL.'/img/no_image.png';
$module_data[] = array(
'id' => $row['wr_id'],
'title' => get_text($row['wr_subject']),
'description' => get_text(cut_str(strip_tags($row['wr_content']), 100)),
'image' => $image_url
);
}
$module_json = json_encode($module_data, JSON_UNESCAPED_UNICODE);
// CSS와 JS 파일의 버전을 파일 수정 시간으로 자동 갱신
$module_css_path = G5_THEME_PATH.'/rb.custom/_base_module/module.css';
$module_js_path = G5_THEME_PATH.'/rb.custom/_base_module/module.js';
$module_css_ver = file_exists($module_css_path) ? filemtime($module_css_path) : G5_CSS_VER;
$module_js_ver = file_exists($module_js_path) ? filemtime($module_js_path) : G5_JS_VER;
// 이 모듈만의 고유 ID를 생성합니다.
$module_id = 'base_module_'.uniqid();
?>
<!-- 모듈의 가장 바깥 요소에 고유 ID를 부여합니다. -->
<div id="<?php echo $module_id; ?>" class="base-module">
<section class="item-section" data-items='<?php echo htmlspecialchars($module_json, ENT_QUOTES, 'UTF-8'); ?>'>
<div class="container">
<div class="section-header">
<!-- TODO: 모듈의 제목과 설명을 수정하세요. -->
<span class="subtitle">Module Subtitle</span>
<h2>모듈 제목</h2>
<p>이곳에 모듈에 대한 간단한 설명을 입력하세요.</p>
</div>
<div class="item-grid">
<!-- JS로 아이템 카드가 생성될 영역 -->
</div>
</div>
</section>
<!-- 모듈 내부에 모달 HTML을 포함시킵니다. -->
<div class="image-modal">
<div class="modal-content">
<span class="close-btn">&times;</span>
<img class="modal-image" src="" alt="이미지">
<div class="modal-info">
<h3 class="modal-title"></h3>
<p class="modal-desc"></p>
</div>
</div>
</div>
</div>
<!-- 이 모듈에 필요한 CSS 파일을 불러옵니다. -->
<link rel="stylesheet" href="<?php echo G5_THEME_URL; ?>/rb.custom/_item_module/module.css?ver=<?php echo $module_css_ver; ?>">
<script>
(function() {
const currentModuleId = '<?php echo $module_id; ?>';
// TODO: 'inititemModule'을 고유한 함수 이름으로 변경하세요. (예: initNewsModule)
const initFunctionName = 'inititemModule';
// TODO: 'item-module-script'를 고유한 스크립트 ID로 변경하세요. (예: news-module-script)
const scriptId = 'item-module-script';
if (document.getElementById(scriptId)) {
if (typeof window[initFunctionName] === 'function') {
window[initFunctionName](currentModuleId);
}
return;
}
const script = document.createElement('script');
script.id = scriptId;
// TODO: JS 파일 경로를 실제 모듈 경로로 수정하세요.
script.src = '<?php echo G5_THEME_URL; ?>/rb.custom/_base_module/module.js?ver=<?php echo $module_js_ver; ?>';
script.async = true;
script.onload = () => {
if (typeof window[initFunctionName] === 'function') {
window[initFunctionName](currentModuleId);
}
};
document.head.appendChild(script);
})();
</script>