Load(); require_once 'response.php'; header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); header('Content-Type: application/json; charset=utf-8'); $act = strtolower(trim($_GET['act'] ?? '')); $format = ApiResponse::getFormat(); $allowedActs = array( 'recipe_title', 'ingredient_name', 'nutrition_name', 'recipe_content', 'ingredient_content' ); if (!in_array($act, $allowedActs)) { $result = array( 'code' => 400, 'message' => 'โŒ ๆ— ๆ•ˆ็š„ๆŸฅ้‡็ฑปๅž‹', 'data' => null, '_query_time' => round((microtime(true) - $startTime) * 1000, 2) . 'ms' ); ApiResponse::output($result, $format); exit; } $result = call_user_func('check_' . $act); $result['_query_time'] = round((microtime(true) - $startTime) * 1000, 2) . 'ms'; ApiResponse::output($result, $format); exit; // ==================== ๆŸฅ้‡ๅ‡ฝๆ•ฐ ==================== /** * ่œๅ“ๆ ‡้ข˜ๆŸฅ้‡ * ๅ‚ๆ•ฐ: title - ่œๅ“ๆ ‡้ข˜ * ่ฟ”ๅ›ž: ้‡ๅค็އ็™พๅˆ†ๆฏ” */ function check_recipe_title() { global $zbp; $title = trim($_GET['title'] ?? $_POST['title'] ?? ''); if (empty($title)) { return array( 'code' => 400, 'message' => 'โŒ ็ผบๅฐ‘่œๅ“ๆ ‡้ข˜ๅ‚ๆ•ฐ', 'data' => null ); } $tablePost = $zbp->db->dbpre . 'post'; $sql = "SELECT log_Title FROM {$tablePost} WHERE log_Type = 0"; $rows = $zbp->db->Query($sql); $maxSimilarity = 0; $titleLimited = mb_substr($title, 0, 100); foreach ($rows as $row) { $existingTitle = mb_substr($row['log_Title'], 0, 100); similar_text($titleLimited, $existingTitle, $similarity); if ($similarity > $maxSimilarity) { $maxSimilarity = $similarity; } if ($maxSimilarity >= 100) { break; } } return array( 'code' => 200, 'message' => 'success', 'data' => array( 'duplicate_rate' => round($maxSimilarity, 2) ) ); } /** * ้ฃŸๆๅ็งฐๆŸฅ้‡ * ๅ‚ๆ•ฐ: name - ้ฃŸๆๅ็งฐ * ่ฟ”ๅ›ž: ้‡ๅค็އ็™พๅˆ†ๆฏ” */ function check_ingredient_name() { global $zbp; $name = trim($_GET['name'] ?? $_POST['name'] ?? ''); if (empty($name)) { return array( 'code' => 400, 'message' => 'โŒ ็ผบๅฐ‘้ฃŸๆๅ็งฐๅ‚ๆ•ฐ', 'data' => null ); } $tableIngredient = $zbp->db->dbpre . 'ingredient_detail'; $sql = "SELECT name FROM {$tableIngredient}"; $rows = $zbp->db->Query($sql); $maxSimilarity = 0; $nameLimited = mb_substr($name, 0, 100); foreach ($rows as $row) { $existingName = mb_substr($row['name'], 0, 100); similar_text($nameLimited, $existingName, $similarity); if ($similarity > $maxSimilarity) { $maxSimilarity = $similarity; } if ($maxSimilarity >= 100) { break; } } return array( 'code' => 200, 'message' => 'success', 'data' => array( 'duplicate_rate' => round($maxSimilarity, 2) ) ); } /** * ่ฅๅ…ปๆˆๅˆ†ๆŸฅ้‡ * ๅ‚ๆ•ฐ: name - ่ฅๅ…ปๆˆๅˆ†ๅ็งฐ * ่ฟ”ๅ›ž: ้‡ๅค็އ็™พๅˆ†ๆฏ” */ function check_nutrition_name() { global $zbp; $name = trim($_GET['name'] ?? $_POST['name'] ?? ''); if (empty($name)) { return array( 'code' => 400, 'message' => 'โŒ ็ผบๅฐ‘่ฅๅ…ปๆˆๅˆ†ๅ็งฐๅ‚ๆ•ฐ', 'data' => null ); } $tableNutrition = $zbp->db->dbpre . 'recipe_nutrition'; $sql = "SELECT DISTINCT name FROM {$tableNutrition}"; $rows = $zbp->db->Query($sql); $maxSimilarity = 0; $nameLimited = mb_substr($name, 0, 100); foreach ($rows as $row) { $existingName = mb_substr($row['name'], 0, 100); similar_text($nameLimited, $existingName, $similarity); if ($similarity > $maxSimilarity) { $maxSimilarity = $similarity; } if ($maxSimilarity >= 100) { break; } } return array( 'code' => 200, 'message' => 'success', 'data' => array( 'duplicate_rate' => round($maxSimilarity, 2) ) ); } /** * ่œๅ“ๅ†…ๅฎนๆŸฅ้‡ * ๅ‚ๆ•ฐ: content - ่œๅ“ๅ†…ๅฎน๏ผˆๅˆถไฝœๆญฅ้ชค็ญ‰๏ผ‰ * ่ฟ”ๅ›ž: ้‡ๅค็އ็™พๅˆ†ๆฏ” */ function check_recipe_content() { global $zbp; $content = trim($_GET['content'] ?? $_POST['content'] ?? ''); if (empty($content)) { return array( 'code' => 400, 'message' => 'โŒ ็ผบๅฐ‘่œๅ“ๅ†…ๅฎนๅ‚ๆ•ฐ', 'data' => null ); } $tablePost = $zbp->db->dbpre . 'post'; $sql = "SELECT log_Content FROM {$tablePost} WHERE log_Type = 0 LIMIT 1000"; $rows = $zbp->db->Query($sql); $maxSimilarity = 0; $contentLimited = mb_substr($content, 0, 100); $contentLength = mb_strlen($contentLimited); foreach ($rows as $row) { $existingContent = mb_substr(strip_tags($row['log_Content']), 0, 100); $existingLength = mb_strlen($existingContent); if ($existingLength > 0 && $contentLength > 0) { similar_text($contentLimited, $existingContent, $similarity); if ($similarity > $maxSimilarity) { $maxSimilarity = $similarity; } if ($maxSimilarity >= 100) { break; } } } return array( 'code' => 200, 'message' => 'success', 'data' => array( 'duplicate_rate' => round($maxSimilarity, 2) ) ); } /** * ้ฃŸๆๅ†…ๅฎนๆŸฅ้‡ * ๅ‚ๆ•ฐ: content - ้ฃŸๆๅ†…ๅฎน๏ผˆๅŠŸๆ•ˆใ€่ฅๅ…ปใ€ไฝฟ็”จๆ็คบ็ญ‰๏ผ‰ * ่ฟ”ๅ›ž: ้‡ๅค็އ็™พๅˆ†ๆฏ” */ function check_ingredient_content() { global $zbp; $content = trim($_GET['content'] ?? $_POST['content'] ?? ''); if (empty($content)) { return array( 'code' => 400, 'message' => 'โŒ ็ผบๅฐ‘้ฃŸๆๅ†…ๅฎนๅ‚ๆ•ฐ', 'data' => null ); } $tableIngredientDetail = $zbp->db->dbpre . 'ingredient_detail'; $sql = "SELECT effect, nutrition, usage_tip FROM {$tableIngredientDetail} LIMIT 1000"; $rows = $zbp->db->Query($sql); $maxSimilarity = 0; $contentLimited = mb_substr($content, 0, 100); $contentLength = mb_strlen($contentLimited); foreach ($rows as $row) { $existingContent = ''; if (!empty($row['effect'])) { $existingContent .= $row['effect'] . ' '; } if (!empty($row['nutrition'])) { $existingContent .= $row['nutrition'] . ' '; } if (!empty($row['usage_tip'])) { $existingContent .= $row['usage_tip']; } $existingContent = mb_substr(trim($existingContent), 0, 100); $existingLength = mb_strlen($existingContent); if ($existingLength > 0 && $contentLength > 0) { similar_text($contentLimited, $existingContent, $similarity); if ($similarity > $maxSimilarity) { $maxSimilarity = $similarity; } if ($maxSimilarity >= 100) { break; } } } return array( 'code' => 200, 'message' => 'success', 'data' => array( 'duplicate_rate' => round($maxSimilarity, 2) ) ); }