AIPT/cn/contact.php

396 lines
20 KiB
PHP
Raw Normal View History

2024-10-29 11:42:53 +08:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<?php
// 设置博客首页的SEO信息
$title = "给我们提交AI工具 - AI Tool Path";
$description = "加入我们一起推动AI工具的发展与创新。提交您的AI工具帮助更多用户发现和使用您的产品。";
$keywords = "加入我们, AI工具, 人工智能, AI发展, AI创新, AI行业动态AI Tool Path";
include('container/links.php');
?>
<?php
// Check if form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Check if required fields are set and not empty
if (
isset($_POST['product_name'], $_POST['domain'], $_POST['keywords'], $_POST['description'], $_POST['ai_description']) &&
!empty($_POST['product_name']) && !empty($_POST['domain']) && !empty($_POST['keywords']) &&
!empty($_POST['description']) && !empty($_POST['ai_description'])
) {
// Database connection setup (ensure $conn is defined)
// $conn = new mysqli('host', 'username', 'password', 'database');
// Get form inputs with strict filtering
$product_name = htmlspecialchars(mysqli_real_escape_string($conn, $_POST['product_name']), ENT_QUOTES, 'UTF-8');
$domain = filter_var(mysqli_real_escape_string($conn, $_POST['domain']), FILTER_SANITIZE_URL);
$logo_url = isset($_POST['logo_url']) ? htmlspecialchars(mysqli_real_escape_string($conn, $_POST['logo_url']), ENT_QUOTES, 'UTF-8') : null;
$screenshot_url = isset($_POST['screenshot_url']) ? htmlspecialchars(mysqli_real_escape_string($conn, $_POST['screenshot_url']), ENT_QUOTES, 'UTF-8') : null;
$keywords = htmlspecialchars(mysqli_real_escape_string($conn, $_POST['keywords']), ENT_QUOTES, 'UTF-8');
$description = htmlspecialchars(mysqli_real_escape_string($conn, $_POST['description']), ENT_QUOTES, 'UTF-8');
$ai_description = htmlspecialchars(mysqli_real_escape_string($conn, $_POST['ai_description']), ENT_QUOTES, 'UTF-8');
// Get user's IP address
$submitted_ip = $_SERVER['REMOTE_ADDR'];
$language = 'zh'; // Specify the language as Chinese ('zh')
// Check for existing submission with the same domain or IP address
$parsed_domain = parse_url($domain, PHP_URL_HOST);
$check_query = "SELECT * FROM tools_submission WHERE domain LIKE '%$parsed_domain%' OR submitted_ip = '$submitted_ip'";
$check_result = mysqli_query($conn, $check_query);
if (mysqli_num_rows($check_result) > 0) {
// Set custom header to indicate duplicate submission
header("X-Response-Status: duplicate");
echo "<script>layui.layer.msg('您已提交过此域名或 IP 地址,请勿重复提交', {icon: 5});</script>";
} else {
// Insert query
$qry = "INSERT INTO tools_submission (product_name, domain, logo_url, screenshot_url, keywords, description, features_description, submitted_ip, language) VALUES ('$product_name', '$domain', '$logo_url', '$screenshot_url', '$keywords', '$description', '$ai_description', '$submitted_ip', '$language')";
// Execute the query
$run = mysqli_query($conn, $qry);
if ($run) {
// Set custom header to indicate successful submission
header("X-Response-Status: success");
echo "<script>layui.layer.msg('提交成功,审核通过后展示', {icon: 1});</script>";
echo "<script>window.location.reload();</script>"; // Reload page after submission
} else {
// Set custom header to indicate submission failure
header("X-Response-Status: error");
echo "<script>layui.layer.msg('表单提交失败,错误信息: " . addslashes($conn->error) . "', {icon: 5});</script>";
}
}
} else {
// Set custom header to indicate missing fields
header("X-Response-Status: missing_fields");
echo "<script>layui.layer.msg('请填写所有必填字段', {icon: 5});</script>";
}
}
?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/layui-src/dist/layui.all.js"></script> <!-- 加载 layui.js -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui-src/dist/css/layui.css" /> <!-- 加载 layui.css -->
<style>
body {
color: var(--thm-gray) !important;
}
.loading-mask {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 9999;
text-align: center;
}
.loading-mask .loading-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
font-size: 1.5em;
}
.thumbnail {
max-width: 120px;
margin-top: 10px;
}
.contact-one__form-box {
max-width: 800px; /* 控制表单整体大小 */
margin: 0 auto; /* 居中 */
}
.form-group {
margin-bottom: 20px;
}
textarea {
max-height: 200px;
overflow: auto; /* 允许内容超出时滚动 */
resize: vertical; /* 允许用户垂直调整文本框大小 */
}
.file-input {
display: none; /* 隐藏文件选择按钮 */
}
</style>
</head>
<body class="body-bg-color">
<!-- Header -->
<?php include 'container/header.php' ?>
<!-- Page Title Start -->
<section class="page-title">
<div class="container">
<div class="page-title__inner">
<div class="page-title__shape-1" style="background-image: url(images/shapes/page-title-shape-1.png);"></div>
<div class="page-title__title-box">
<p class="page-title__sub-title">提交AI工具</p>
<h3 class="page-title__title">提交您的AI工具让更多用户发现和使用。</h3>
</div>
<p class="page-title__text">掌握 AI 工具的艺术:释放自动化创造力的力量,借助 AI Tool Path</p>
<p class="page-title__text">商务合作admin@aitoolpath.com</p>
<p class="page-title__text">工具审核a1726850085@outlook.com</p>
</div>
</div>
</section>
<!-- Page Title End -->
<!-- Contact One Start -->
<section class="contact-one">
<div class="container">
<div class="row">
<div class="col-xl-12 col-lg-12">
<div class="contact-one__right">
<div class="contact-one__form-box">
<h3 class="contact-one__form-title">提交AI工具</h3>
<form method="POST" action="" id="tool-form">
<div class="form-group">
<p class="contact-one__form-label">产品名称 *</p>
<input type="text" name="product_name" id="product_name" placeholder="产品名称" maxlength="20" required="">
</div>
<div class="form-group">
<p class="contact-one__form-label">域名 *</p>
<input type="text" name="domain" id="domain" placeholder="请输入域名例如https://www.aitoolpath.com" maxlength="30" required="">
</div>
<div class="form-group">
<button type="button" class="thm-btn" id="ai-fill-button">AI智能填充</button>
</div>
<div class="form-group">
<p class="contact-one__form-label">LOGO URL</p>
<input type="text" name="logo_url" id="logo_url" maxlength="300">
<input type="file" id="logo_file" class="file-input">
<button type="button" class="thm-btn" id="upload-logo">上传LOGO</button>
<img id="logo_thumbnail" class="thumbnail" style="display:none;">
</div>
<div class="form-group">
<p class="contact-one__form-label">截图 URL</p>
<input type="text" name="screenshot_url" id="screenshot_url" maxlength="300">
<input type="file" id="screenshot_file" class="file-input">
<button type="button" class="thm-btn" id="upload-screenshot">上传截图</button>
<img id="screenshot_thumbnail" class="thumbnail" style="display:none;">
</div>
<div class="form-group">
<p class="contact-one__form-label">关键词 *</p>
<input type="text" name="keywords" placeholder='AI视频,AI聊天' id="keywords" maxlength="120" required="">
</div>
<div class="form-group text-message-box">
<p class="contact-one__form-label">简介 *</p>
<textarea name="description" id="description" placeholder='一句话介绍' maxlength="160" required=""></textarea>
</div>
<div class="form-group text-message-box">
<p class="contact-one__form-label">功能描述 *</p>
<textarea name="ai_description" id="ai_description" placeholder='使用功能介绍,越详细越好' maxlength="1000" required=""></textarea>
</div>
<div class="form-group">
<div class="button-box">
<button type="submit" class="thm-btn contact-one__btn" data-loading-text="请稍等...">提交工具</button>
</div>
</div>
</form>
<p class="ajax-response mb-0"></p>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Contact One End -->
<!-- Loading Mask -->
<div class="loading-mask" id="loading-mask">
<div class="loading-text">正在处理,请耐心等待... ... ...</div>
</div>
<!-- Free Trail Start -->
<?php include 'container/free_trail.php' ?>
<!-- Free Trail End -->
<!-- Main Footer Start -->
<?php include 'container/footer.php' ?>
<!-- Main Footer End -->
<?php include 'container/footer_links.php' ?>
<script>
$('#tool-form').on('submit', function(e) {
e.preventDefault(); // 阻止默认表单提交行为
// 检查必填字段是否填写
if (!$('#product_name').val() || !$('#domain').val() || !$('#keywords').val() || !$('#description').val() || !$('#ai_description').val()) {
layui.layer.msg("请填写所有必填字段", { icon: 5 });
return;
}
// 检查域名格式是否正确
var domain = $('#domain').val();
var domainRegex = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w-]*)*$/; // 简单的域名验证正则表达式
if (!domainRegex.test(domain)) {
layui.layer.msg("请输入正确的域名例如https://www.example.com", { icon: 5 });
return;
}
// 显示蒙版加载动画
$('#loading-mask').show();
$('.contact-one__btn').attr('disabled', true);
// 提交表单
$.ajax({
url: '', // 当前页面,提交至 PHP 处理部分
type: 'POST',
data: $(this).serialize(),
success: function(response, textStatus, request) {
$('#loading-mask').hide();
$('.contact-one__btn').attr('disabled', false);
// 根据响应头的 X-Response-Status 显示不同提示信息
var responseStatus = request.getResponseHeader('X-Response-Status');
switch (responseStatus) {
case 'success':
layui.layer.msg('提交成功,审核通过后展示', { icon: 1 }, function() {
// 成功提示后重定向到指定页面
window.location.href = 'contact';
});
break;
case 'duplicate':
layui.layer.msg('您已提交过此域名或 IP 地址,请勿重复提交', { icon: 5 });
break;
case 'error':
layui.layer.msg('表单提交失败,请重试', { icon: 5 });
break;
case 'missing_fields':
layui.layer.msg('请填写所有必填字段', { icon: 5 });
break;
default:
layui.layer.msg('提交遇到未知错误,请重试', { icon: 5 });
}
},
error: function(xhr, status, error) {
$('#loading-mask').hide();
$('.contact-one__btn').attr('disabled', false);
layui.layer.msg('请求失败,请重试', { icon: 5 });
}
});
});
</script>
<script>
$('#ai-fill-button').click(function() {
var domain = $('#domain').val();
var productName = $('#product_name').val();
var language = '中文'; // 默认语言为中文
if (!domain || !productName) {
layui.layer.msg("请输入产品名称和域名", {icon: 5});
return;
}
// 显示蒙版加载动画,禁用按钮
$('#loading-mask').show();
$('#ai-fill-button').attr('disabled', true);
$.ajax({
url: 'https://api.aitoolpath.com/fetch_website_info',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ domain: domain, language: language }),
success: function(data) {
// 隐藏加载动画,启用按钮
$('#loading-mask').hide();
$('#ai-fill-button').attr('disabled', false);
console.log('API响应:', data); // 打印API响应
if (data.code === 200) {
var responseData = data.data;
$('#logo_url').val(responseData.logo_filename || "获取失败,请手动填写");
$('#logo_thumbnail').attr('src', responseData.logo_filename).toggle(!!responseData.logo_filename);
$('#screenshot_url').val(responseData.screenshot_filename || "获取失败,请手动填写");
$('#screenshot_thumbnail').attr('src', responseData.screenshot_filename).toggle(!!responseData.screenshot_filename);
$('#keywords').val(responseData.keywords || "获取失败,请手动填写");
$('#description').val(responseData.description || "获取失败,请手动填写");
$('#ai_description').val(responseData.ai_description || "获取失败,请手动填写");
layui.layer.msg('AI 填写完成', {icon: 1});
} else {
layui.layer.msg(data.message, {icon: 5});
}
},
error: function(xhr, status, error) {
// 隐藏加载动画,启用按钮
$('#loading-mask').hide();
$('#ai-fill-button').attr('disabled', false);
console.error('请求错误:', error);
layui.layer.msg('请求失败,请重试', {icon: 5});
}
});
});
// 上传LOGO
$('#upload-logo').click(function() {
$('#logo_file').click();
});
$('#logo_file').change(function() {
var formData = new FormData();
formData.append('file', $('#logo_file')[0].files[0]);
$.ajax({
url: 'https://api.aitoolpath.com/upload_image', // 替换为你的上传API
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data) {
if (data.code === 200) {
console.log(data.data.file_url) // 打印上传图片的URL
$('#logo_url').val(data.data.file_url);
$('#logo_thumbnail').attr('src', data.data.file_url).show();
layui.layer.msg('LOGO上传成功', {icon: 1});
} else {
layui.layer.msg('LOGO上传失败请重试', {icon: 5});
}
},
error: function(xhr, status, error) {
layui.layer.msg('LOGO上传失败请重试', {icon: 5});
}
});
});
// 上传截图
$('#upload-screenshot').click(function() {
$('#screenshot_file').click();
});
$('#screenshot_file').change(function() {
var formData = new FormData();
formData.append('file', $('#screenshot_file')[0].files[0]);
$.ajax({
url: 'https://api.aitoolpath.com/upload_image', // 替换为你的上传API
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data) {
if (data.code === 200) {
console.log(data.data.file_url)
$('#screenshot_url').val(data.data.file_url);
$('#screenshot_thumbnail').attr('src', data.data.file_url).show();
layui.layer.msg('图片上传成功', {icon: 1});
} else {
layui.layer.msg('图片上传失败,请重试', {icon: 5});
}
},
error: function(xhr, status, error) {
layui.layer.msg('图片上传失败,请重试', {icon: 5});
}
});
});
</script>
</body>
</html>