2 커밋 0ccab3e6b3 ... 14f4b7f8aa

작성자 SHA1 메시지 날짜
  igb 14f4b7f8aa fleat: update feedback 1 주 전
  igb 1c5d191c20 fleat: update feedback 1 주 전
3개의 변경된 파일178개의 추가작업 그리고 23개의 파일을 삭제
  1. 53 9
      usr/themes/beardocs/archive.php
  2. 66 0
      usr/themes/beardocs/feedback.php
  3. 59 14
      usr/themes/beardocs/footer.php

+ 53 - 9
usr/themes/beardocs/archive.php

@@ -1,6 +1,9 @@
 <?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
 
-
+if(!empty($_GET['feedback'])) {
+    require_once __DIR__ . '/feedback.php';
+    exit;
+}
 ?>
 <?php $this->need('header.php'); ?>
 
@@ -8,18 +11,14 @@
 
 
 
-
-
-
-
-
 // 示例调用
-$token = 'dataset-Emh5R5hCGorTuqG0dkQe7tMf';  // 传入实际的 token
+$token = 'dataset-Emh5R5hCGorTuqG0dkQe7tMf';  // 传入实际的 toke
 $datasets = 'c08ae7fa-c4e7-4fae-8138-2097ff19e1a6';  // 传入实际的 datasets ID
 $keyword =  '';//'how to cute';  // 传入实际的查询关键字
 $PathInfo = Typecho_Widget::widget('Widget_Options')->request->getPathInfo();;
 
 
+
 // 检查请求路径是否以 '/search' 开头
 if (strpos($PathInfo, '/search') === 0)
 {
@@ -32,9 +31,7 @@ if (strpos($PathInfo, '/search') === 0)
 
 
 if(!empty($_GET['category'])) {
-
     $category_id = $_GET['category'] * 1;
-
 }
 ?>
 
@@ -125,11 +122,15 @@ $thisChild["name"] ?></a></li> <?php }  ?>
       <script>
           function toggleAnswer(index) {
               var answerDiv = document.getElementById('answer-' + index);
+              var feedbackDiv = document.getElementById('feedback-' + index);
               var icon = document.getElementById('icon-' + index);
 
               if (answerDiv.style.display === 'none') {
            
                   answerDiv.style.display = 'block';
+                  feedbackDiv.style.display = 'block';
+
+
                   //icon.innerHTML = '▲'; // 展开时显示向上箭头
                   
                   // 找到当前答案中的视频并自动播放
@@ -139,6 +140,7 @@ $thisChild["name"] ?></a></li> <?php }  ?>
                   }
               } else {
                   answerDiv.style.display = 'none';
+                  feedbackDiv.style.display = 'none';
                   //icon.innerHTML = '▼'; // 收起时显示向下箭头
                   
                   // 如果答案被隐藏,暂停视频播放
@@ -183,6 +185,10 @@ $thisChild["name"] ?></a></li> <?php }  ?>
               padding-left: 20px; /* 答案缩进 */
 
           }
+
+          .feedback-btn {
+          border: 1px solid #ddd; background: #f8f8f8; border-radius: 4px; padding: 5px 15px; margin-right: 10px; cursor: pointer; height: 32px; line-height: 1; display: inline-flex; align-items: center;
+          }
           
           /* 在手机设备上将卡片padding设为0 */
           @media (max-width: 768px) {
@@ -347,6 +353,24 @@ if (!empty($keyword)&&(strpos($PathInfo, '/search') === 0))
                 <div id="answer-<?= $index ?>" class="answer" style="display: none;white-space: pre-line;">
                     <?= $answer ?>
                 </div>
+                <!-- 添加反馈按钮 -->
+                <div  id="feedback-<?= $index ?>" class="feedback-container " style="display: none; margin-top: 30px; padding: 0 15px 15px 15px; text-align: center">
+                    <div class="feedback-question" style="font-size: 14px; color: #666; margin-bottom: 5px;">Was this article helpful to you?</div>
+                    <div class="feedback-buttons">
+                        <button class="feedback-btn  feedback-btn-<?= $index ?> helpful-btn" onclick="recordFeedback(<?= $index ?>, '<?= htmlspecialchars(addslashes($question), ENT_QUOTES, 'UTF-8') ?>', 1)"  title="YES">
+                            <i class="ri-thumb-up-line"></i>
+                        </button>
+                        <button class="feedback-btn feedback-btn-<?= $index ?> not-helpful-btn" onclick="recordFeedback(<?= $index ?>, '<?= htmlspecialchars(addslashes($question), ENT_QUOTES, 'UTF-8') ?>', 0)"  title="NO">
+                            <i class="ri-thumb-down-line"></i>
+                        </button>
+                        <button onclick="window.open('https://wa.me/8617000161888?text=Hello!', '_blank')" class="feedback-btn" title="No result ? Contact us on WhatsApp." >
+                            <i class="ri-whatsapp-line"></i>
+                            feedback
+                        </button>
+                    </div>
+                    <div id="feedback-result-<?= $index ?>" class="feedback-result" style="display: none; color: #666; margin-top: 5px;"></div>
+                </div>
+
             </div>
 
 
@@ -494,6 +518,24 @@ if (!empty($keyword)&&(strpos($PathInfo, '/search') === 0))
                 <div id="answer-<?= $index ?>" class="answer" style="display: none;white-space: pre-line;">
                     <?= $answer ?>
                 </div>
+                <!-- 添加反馈按钮 -->
+                <div  id="feedback-<?= $index ?>" class="feedback-container " style="display: none; margin-top: 30px; padding: 0 15px 15px 15px; text-align: center">
+                    <div class="feedback-question" style="font-size: 14px; color: #666; margin-bottom: 5px;">Was this article helpful to you?</div>
+                    <div class="feedback-buttons">
+                        <button class="feedback-btn  feedback-btn-<?= $index ?> helpful-btn" onclick="recordFeedback(<?= $index ?>, '<?= htmlspecialchars(addslashes($question), ENT_QUOTES, 'UTF-8') ?>', 1)"  title="YES">
+                            <i class="ri-thumb-up-line"></i>
+                        </button>
+                        <button class="feedback-btn feedback-btn-<?= $index ?> not-helpful-btn" onclick="recordFeedback(<?= $index ?>, '<?= htmlspecialchars(addslashes($question), ENT_QUOTES, 'UTF-8') ?>', 0)"  title="NO">
+                            <i class="ri-thumb-down-line"></i>
+                        </button>
+                        <button onclick="window.open('https://wa.me/8617000161888?text=Hello!', '_blank')" class="feedback-btn" title="No result ? Contact us on WhatsApp." >
+                            <i class="ri-whatsapp-line"></i>
+                            feedback
+                        </button>
+                    </div>
+                    <div id="feedback-result-<?= $index ?>" class="feedback-result" style="display: none; color: #666; margin-top: 5px;"></div>
+                </div>
+
             </div>
 
 
@@ -552,4 +594,6 @@ if (!empty($keyword)&&(strpos($PathInfo, '/search') === 0))
 </div>
 
 
+
+
 <?php $this->need('footer.php'); ?>

+ 66 - 0
usr/themes/beardocs/feedback.php

@@ -0,0 +1,66 @@
+<?php
+/**
+ * 用户反馈处理接口
+ */
+if (!defined('__TYPECHO_ROOT_DIR__')) exit;
+
+// 检查是否是 POST 请求
+if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+    // 获取反馈数据
+    $questionId = isset($_POST['questionId']) ? (int)$_POST['questionId'] : 0;
+    $questionTitle = isset($_POST['questionTitle']) ? $_POST['questionTitle'] : '';
+    $isHelpful = isset($_POST['isHelpful']) ? (int)$_POST['isHelpful'] : 0;
+    $categoryId = isset($_POST['categoryId']) ? (int)$_POST['categoryId'] : 0;
+    
+    // 验证数据
+    if (empty($questionTitle)) {
+        echo json_encode(['status' => 'error', 'message' => 'The question cannot be empty.']);
+        exit;
+    }
+    
+    try {
+        // 获取数据库连接
+        $db = Typecho_Db::get();
+
+        $request = Typecho_Request::getInstance();
+
+        // 获取用户IP
+        $ip =  $request->getIp();
+        
+//        // 检查是否已经提交过反馈
+//        $exists = $db->fetchRow($db->select()
+//            ->from('table.article_feedbacks')
+//            ->where('question_id = ?', $questionId)
+//            ->where('ip = ?', $ip)
+//            ->limit(1));
+//
+//        if ($exists) {
+//            echo json_encode(['status' => 'error', 'message' => '您已经对此问题进行过评价']);
+//            exit;
+//        }
+        
+        // 准备插入数据
+        $data = [
+            'question_id' => $questionId,
+            'question_title' => $questionTitle,
+            'category_id' => $categoryId,
+            'is_helpful' => $isHelpful,
+            'ip' => $ip,
+            'created' => time()
+        ];
+        
+        // 插入数据到数据库
+        $db->query($db->insert('table.article_feedbacks')->rows($data));
+        
+        // 返回成功响应
+        echo json_encode(['status' => 'success', 'message' => 'Thank you for your feedback!']);
+    } catch (Exception $e) {
+        // 返回错误响应
+        echo json_encode(['status' => 'error', 'message' => 'An error occurred while saving feedback.']);
+    }
+    exit;
+}
+
+// 如果不是 POST 请求,返回错误
+echo json_encode(['status' => 'error', 'message' => 'Invalid request method.']);
+exit;

+ 59 - 14
usr/themes/beardocs/footer.php

@@ -18,20 +18,20 @@ $currentUrl = $_SERVER['REQUEST_URI'];
 <!--	</div>-->
 <!--</footer>-->
 
-    <footer class="uk-background-secondary uk-background-norepeat uk-background-cover uk-background-center-center uk-light uk-margin-large-top" >
-        <div class="uk-section uk-section-small uk-section-hero uk-position-relative" data-uk-scrollspy="cls: uk-animation-slide-bottom-medium; repeat: false">
-            <div class="uk-container">
-                <div class="hero-search">
-                    <div class="uk-position-relative" style="display: flex; justify-content: center; align-items: center; height: 40px;"> <!-- 设置固定高度 -->
-                <div class='lxdh'>
-                            <a href="https://wa.me/8617000161888?text=Hello!">No result ? Contact us on WhatsApp.</a>
-                   </div>
-                    </div>
-                </div>
-            </div>
-        </div>
-
-    </footer>
+<!--    <footer class="uk-background-secondary uk-background-norepeat uk-background-cover uk-background-center-center uk-light uk-margin-large-top" >-->
+<!--        <div class="uk-section uk-section-small uk-section-hero uk-position-relative" data-uk-scrollspy="cls: uk-animation-slide-bottom-medium; repeat: false">-->
+<!--            <div class="uk-container">-->
+<!--                <div class="hero-search">-->
+<!--                    <div class="uk-position-relative" style="display: flex; justify-content: center; align-items: center; height: 40px;"> <!-- 设置固定高度 -->-->
+<!--                <div class='lxdh'>-->
+<!--                            <a href="https://wa.me/8617000161888?text=Hello!">No result ? Contact us on WhatsApp.</a>-->
+<!--                   </div>-->
+<!--                    </div>-->
+<!--                </div>-->
+<!--            </div>-->
+<!--        </div>-->
+<!---->
+<!--    </footer>-->
 <?php
 }
 ?>
@@ -46,5 +46,50 @@ $currentUrl = $_SERVER['REQUEST_URI'];
 <?php echo General::Options('CustomizationFooterJsCode'); ?>
 <?php $this->footer(); ?>
 <script src="<?php $this->options->themeUrl('assets/plugins/instant.page/instantpage.min.js'); ?>"></script>
+
+<!-- 添加反馈功能的JavaScript代码 -->
+<script>
+  function recordFeedback(questionId, questionTitle, isHelpful) {
+      // 显示加载状态
+      var resultDiv = document.getElementById('feedback-result-' + questionId);
+      resultDiv.style.display = 'block';
+      resultDiv.innerHTML = 'Submitting your feedback...';
+      
+      // 准备发送的数据
+      var data = new FormData();
+      data.append('action', 'recordFeedback');
+      data.append('questionId', questionId);
+      data.append('questionTitle', questionTitle);
+      data.append('isHelpful', isHelpful);
+      
+      // 发送AJAX请求
+      fetch('/index.php/category/M288/?feedback=1', {
+          method: 'POST',
+          body: data
+      })
+      .then(response => response.json())
+      .then(data => {
+          resultDiv.innerHTML = data.message;
+          
+          // 如果提交成功,禁用按钮
+          if (data.status === 'success') {
+
+            
+              // 禁用按钮,避免重复提交
+              var buttons = document.querySelectorAll(".feedback-btn-"+questionId);
+              buttons.forEach(function(btn) {
+                  btn.disabled = true;
+                  btn.style.opacity = '0.5';
+                  btn.style.cursor = 'default';
+              });
+          }
+      })
+      .catch(error => {
+          resultDiv.innerHTML = 'Submission failed, please try again later.';
+          console.error('Error:', error);
+      });
+  }
+</script>
+
 </body>
 </html>