<!-- 
// 功能：搜索页面默认模板
// 作者：启肯科技
// Q Q：328493711
// 微信：13738373177（同手机）
// 官网：http://www.qiken.com
// 说明：QKCMS-轻量级AI智能内容管理建站系统
// 版权：© 2025 温州启肯网络有限公司 保留所有权利，盗版必究。
-->

<?php
$search = isset($_GET['keyword']) ? htmlspecialchars(trim($_GET['keyword'])) : '';
$page_title = $search . '_相关文章搜索结果 - {qkcms:site_name}';
$page_keywords = $search . ',' . $search . '相关文章,' . $search . '原创内容,' . $search . '最新资讯';
$page_description = '{qkcms:site_name}为你找到所有包含【' . $search . '】的优质原创文章，涵盖' . $search . '最新资讯、实用攻略、深度解读等内容，精准匹配你的搜索需求。';
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title><?=$page_title?></title>
<meta name="keywords" content="<?=$page_keywords?>">
<meta name="description" content="<?=$page_description?>">
</head>

<body>
{qkcms:head.html}
<main class="main-content">
  <div class="container">
    <div class="content-layout">
      <div class="main-column">
        <section class="topics-section">
          <div class="topics-header">
            <h1 class="topics-title">搜索词【<?=$search?>】</h1>
            <div class="topics-filter"> <span class="tag-count-label">已匹配（{qkcms:total_search}）个相关 </span> </div>
          </div>
          <div class="topics-content">
            <div id="latest" class="tab-content active"> {qkcms:articles row=12 col=1 property=0 order=latest titlelen=30 description_len=90 page=1 tag="1,<?=$search?>"}
              <div class="topic-item fade-in"> <a href="{url}" class="topic-title"><div class="article-thumbnail-container"> <img src="{thumbnail}" alt="{title}" class="article-thumbnail"> </div></a>
                <div class="topic-content">
                  <div class="topic-header-row">
                    <div class="topic-meta"> <a href="#" class="topic-author">{author}</a> <span class="topic-time">{date_only}</span> </div>
                    <div class="article-tags">
                      <span class="article-tags-wrapper">{keywords_links}</span>
                    </div>
                  </div>
                  <a href="{url}" class="topic-title">{title}</a>
                  <p>描述: {description}</p>
                  <div class="topic-footer">
                    <div class="topic-stats"> <span class="topic-stat"> <span class="icon view"></span> {views}</span> <span class="topic-stat"> <span class="icon message"></span> {comments} </span> <span class="topic-stat"> <span class="icon like"></span> {like_count} </span> </div>
                  </div>
                </div>
              </div>
              {/qkcms:articles} </div>
          </div>
        </section>
        <section class="topics-section">
          <div class="pagination"> {qkcms:page type=1 page=1} {first_page} {prev_page} {page_numbers} {jump_to_page} {next_page} {last_page} <span class="page-status">{page_status}</span> {/qkcms:page} </div>
        </section>
      </div>
      <aside class="sidebar">
        <div class="tags-cloud-section">
          <h3 class="tags-header">大家都在搜什么？</h3>
          <div class="tags-cloud"> {qkcms:search row=20 order=1} <span class="tag">{search_term} （{count}）</span> {/qkcms:search} </div>
        </div>
        <div class="events-section fade-in">
          <h3 class="events-header">全站公告</h3>
          {qkcms:articles row=3 property=4 category_id=-1 titlelen=40} <a href="{url}" class="event-item">
          <div class="event-date">
            <div class="event-month">{date_mo}月</div>
            <div class="event-day">{date_dy}</div>
          </div>
          <div class="event-info">
            <div class="event-title">{title}</div>
            <div class="event-location">{keywords}</div>
          </div>
          </a> {/qkcms:articles} </div>
      </aside>
    </div>
  </div>
</main>
{qkcms:footer.html} 
<script>
    // 搜索词高亮显示
    function highlightSearchTerms() {
      // 从PHP变量直接获取搜索词，最可靠
      var keyword = '<?=htmlspecialchars($search)?>';

      if (!keyword || keyword.trim() === '') {
        return;
      }

      keyword = keyword.trim();

      // 转义正则表达式特殊字符
      var escapedKeyword = keyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
      var regex = new RegExp('(' + escapedKeyword + ')', 'gi');

      // 高亮文本函数
      function highlightText(element) {
        if (element && element.innerHTML) {
          element.innerHTML = element.innerHTML.replace(regex, '<span style="color: red; font-weight: bold;">$1</span>');
        }
      }

      // 高亮标题
      var titles = document.querySelectorAll('.topic-title');
      titles.forEach(highlightText);

      // 高亮描述
      var descriptions = document.querySelectorAll('.topic-content p');
      descriptions.forEach(highlightText);
    }

    // DOM完全加载后执行
    document.addEventListener('DOMContentLoaded', highlightSearchTerms);
  </script>
</body>
</html>
