= max_pagination_pages()) $has_next = false; if (!$has_prev && !$has_next) return ''; $button = static function (int $target, string $label) use ($query, $field): string { return '
' . form_token() . hidden_inputs(['q' => $query, 'field' => $field, 'p' => $target]) . '
'; }; return '
'; } public static function page(): void { if (!uid()) err('请登录后操作'); $submitted = is_post_request(); $query = $submitted ? post('q', length_limit('search', 'max')) : ''; $field = topic_search_field($submitted ? (string)($_POST['field'] ?? 'title') : 'title'); $page = $submitted ? min(max_pagination_pages(), max(1, (int)($_POST['p'] ?? 1))) : 1; if ($query !== '') require_search_min_chars($query); $options = ['title' => '标题', 'body' => '内容', 'reply' => '回帖']; $radios = ''; foreach ($options as $value => $label) $radios .= ''; $form = '
' . form_token() . '
' . $radios . '
'; $main = '

搜索

' . $form . '
'; if ($submitted && $query === '') $main .= '
请输入搜索关键词
'; if ($query !== '') { if ($page === 1) { $seconds = post_interval_seconds(); if ($seconds > 0) { $user = row('app_users', 'id', uid()); $wait = $seconds - (time() - (int)($user['last_post_at'] ?? 0)); if ($wait > 0) err('搜索太频繁,请 ' . $wait . ' 秒后再试'); q('UPDATE app_users SET last_post_at=? WHERE id=?', [time(), uid()]); } } $size = max(1, (int)setting('topics_per_page', '30')); $data = topic_index_data(0, null, 'topics', $query, $field, 'comment', $page, $size); $main .= '
搜索“' . h($query) . '” · ' . $options[$field] . '
' . self::pagination($page > 1, (bool)$data['has_next_page'], $page, $query, $field); } page('搜索', shell_html($main, '', 'search-page')); } }