forked from gnuboard/gnuboard5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.ajax.php
More file actions
69 lines (62 loc) · 2.46 KB
/
search.ajax.php
File metadata and controls
69 lines (62 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
// ===========================
// AJAX 검색 결과 전용 파일
// ===========================
include_once('./_common.php');
include_once(G5_PATH . '/search.lib.php');
include_once(G5_PATH . '/search.config.php');
// 파라미터 입력 받기
$page_jump = $is_mobile ? 3 : 10;
$page_display_count = $is_mobile ? 3 : 10;
$options = [
'stx' => $_GET['stx'] ?? '',
'bo_table' => $_GET['bo_table'] ?? '',
'page' => max(1, (int)($_GET['page'] ?? 1)),
'sort' => $_GET['sort'] ?? 'date_desc',
'search_type' => $_GET['search_type'] ?? 'subject_content',
'rows' => 15,
'page_jump' => $page_jump,
'page_display_count' => $page_display_count,
'excluded_bo_tables' => $excluded_bo_tables,
'excluded_ids' => $excluded_ids,
'excluded_names' => $excluded_names,
'exclude_words' => $exclude_words,
'use_external' => $use_external,
'external_db' => $external_db,
];
$options['offset'] = ($options['page'] - 1) * $options['rows'];
// 공통 검색 함수 호출
$res = get_search_results($options);
// --- 결과값 정리
$total_count = $res['count'];
$show_count = $total_count >= $max_result ? number_format($max_result).'+' : number_format($total_count);
$notice = '';
if ($total_count >= $max_result) {
$notice = "검색 결과가 많아, 최대 {$max_result}개까지만 표시됩니다. 더 정확한 검색어로 검색해 주세요.";
}
// 페이징 생성
parse_str($_SERVER['QUERY_STRING'], $params);
unset($params['page']);
$base_url = '?' . http_build_query($params) . '&';
$pagination = render_pagination($total_count, $options['page'], $options['rows'], $options['page_jump'], $base_url, $options['page_display_count']);
// 리스트 데이터
$items_arr = [];
foreach($res['items'] as $row){
$items_arr[] = [
'url' => G5_BBS_URL.'/board.php?bo_table='.urlencode($row['bo_table']).'&wr_id='.urlencode($row['wr_id']),
'is_comment' => $row['wr_id'] != $row['wr_parent'] ? 1 : 0,
'subject' => get_highlighted_text($row['wr_subject'] ?: '[댓글]', $options['stx']),
'preview' => $row['wr_content_preview'] . ' ' .$row['image_icons'],
'name' => htmlspecialchars($row['wr_name']),
'date' => substr($row['wr_datetime'],0,10)
];
}
// --- 최종 AJAX JSON 반환
header('Content-Type: application/json; charset=utf-8');
echo json_encode([
'items' => $items_arr,
'pagination' => $pagination,
'show_count' => $show_count,
'notice' => $notice,
'count' => $total_count,
]);