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

93 lines
3.7 KiB
PHP

<?php
if (!defined('_GNUBOARD_')) exit;
/**
* 💡 [핵심] 서버 측 디버깅을 위한 커스텀 로그 함수.
* 테마의 어느 곳에서든 호출할 수 있습니다.
*
* @param mixed $data 로그로 남길 데이터 (문자열, 배열, 객체 등)
*/
if (!function_exists('rb_log')) {
function rb_log($data) {
$log_path = G5_DATA_PATH . '/log'; // 로그 저장 폴더
if (!is_dir($log_path)) {
@mkdir($log_path, G5_DIR_PERMISSION, true);
@chmod($log_path, G5_DIR_PERMISSION);
}
$log_file = $log_path . '/debug.log'; // 로그 파일명
// 로그를 호출한 파일과 라인 정보를 가져옵니다.
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
$caller = isset($backtrace[0]) ? "{$backtrace[0]['file']}:{$backtrace[0]['line']}" : 'unknown';
// 현재 시간과 함께 로그 메시지를 포맷팅합니다.
$log_message = "[" . date("Y-m-d H:i:s") . "] (" . $caller . ")\n";
// 데이터가 배열이나 객체이면 print_r로, 아니면 그대로 기록합니다.
if (is_array($data) || is_object($data)) {
$log_message .= print_r($data, true);
} else {
$log_message .= $data;
}
// 파일 끝에 로그를 추가합니다.
file_put_contents($log_file, $log_message . "\n\n", FILE_APPEND | LOCK_EX);
}
}
/**
* 💡 [핵심] 최신글 데이터를 배열로 반환하는 함수
* latest() 함수와 거의 동일하지만, echo로 출력하는 대신 배열로 반환합니다.
*
* @param string $bo_table 게시판 테이블명
* @param int $rows 가져올 게시물 수
* @param int $subject_len 제목 글자 수 제한
* @return array 최신글 데이터 배열
*/
if (!function_exists('get_latest')) {
function get_latest($bo_table, $rows, $subject_len) {
global $g5;
if (!$bo_table) {
return array();
}
$sql = " select * from {$g5['write_prefix']}{$bo_table} where wr_is_comment = 0 order by wr_num, wr_reply limit 0, {$rows} ";
$result = sql_query($sql);
$list = array();
for ($i=0; $row=sql_fetch_array($result); $i++) {
$list[$i] = $row;
$list[$i]['href'] = get_pretty_url($bo_table, $row['wr_id']);
$list[$i]['subject'] = cut_str(get_text($row['wr_subject']), $subject_len);
$list[$i]['summary'] = cut_str(strip_tags($row['wr_1'] ?: $row['wr_content']), 120);
$thumb = get_list_thumbnail($bo_table, $row['wr_id'], 200, 150, false, true);
// 💡 [최종 수정] 썸네일이 없을 경우 기본 이미지 경로 사용
$list[$i]['thumb_src'] = $thumb['src'] ?: G5_THEME_URL . '/rb.img/no_image.png';
$list[$i]['thumb_alt'] = $thumb['alt'] ?: get_text($row['wr_subject']);
$list[$i]['datetime2'] = substr($row['wr_datetime'], 5, 5);
}
return $list;
}
}
// 💡 [핵심 추가] 이미지 주소를 현재 도메인에 맞게 동적으로 변경하는 함수
if (!function_exists('g5_dynamic_img_url')) {
function g5_dynamic_img_url($content) {
if (!$content) return $content;
$base = G5_URL; // 현재 접속 도메인 (예: http://localhost)
// 정규식을 사용하여 이미지 URL을 동적으로 변경합니다.
// http(s)://도메인/data/editor/ 경로를 현재 G5_URL/data/editor/ 경로로 변경
$content = preg_replace(
'#https?://[^/]+(/data/editor/)#i',
$base . '$1',
$content
);
return $content;
}
}
// 앞으로 테마 전역에서 사용할 다른 헬퍼 함수들을 이곳에 추가할 수 있습니다.