| @@ -16,7 +16,7 @@ require_once(DEDEINC.'/userlogin.class.php'); | |||
| @set_time_limit(0); | |||
| AjaxHead(); | |||
| helper('cache'); | |||
| $action = isset($action) && in_array($action, array('is_need_check_code', 'has_new_version', 'get_changed_files', 'update_backup', 'get_update_versions', 'update', 'upload_image')) ? $action : ''; | |||
| $action = isset($action) && in_array($action, array('is_need_check_code', 'has_new_version', 'get_changed_files', 'update_backup', 'get_update_versions', 'update', 'upload_image','get_ai_server')) ? $action : ''; | |||
| $curDir = dirname(GetCurUrl());//当前目录 | |||
| /** | |||
| * 登录鉴权 | |||
| @@ -376,6 +376,14 @@ if ($action === 'is_need_check_code') { | |||
| )); | |||
| exit; | |||
| } | |||
| if (empty($uploadedFile)) { | |||
| echo json_encode(array( | |||
| "code" => -1, | |||
| "msg" => "文件为空", | |||
| "data" => null, | |||
| )); | |||
| exit; | |||
| } | |||
| $fileType = mime_content_type($uploadedFile); | |||
| $imgSize = getimagesize($uploadedFile); | |||
| if (!in_array($fileType, $allowedTypes) || !$imgSize) { | |||
| @@ -434,5 +442,22 @@ if ($action === 'is_need_check_code') { | |||
| "msg" => "上传成功", | |||
| "data" => $activepath."/".$filename, | |||
| )); | |||
| } else if($action === 'get_ai_server') { | |||
| $params = $_GET; | |||
| unset($params['action']); | |||
| checkLogin(); | |||
| $params['timestamp'] = time(); // 加入时间戳 | |||
| $cuserLogin = new userLogin(); | |||
| $params['adminid'] = $cuserLogin->getUserID(); // 加入时间戳 | |||
| $params['ip'] = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1'; // 获取客户端IP | |||
| ksort($params); // 按字典序排序 | |||
| $queryString = http_build_query($params); // 生成查询字符串 | |||
| $params['sign'] = md5($queryString . $cfg_ai_apikey); // 计算MD5签名 | |||
| $url = $cfg_ai_server . '/ai?' . http_build_query($params); | |||
| echo json_encode(array( | |||
| "code" => 0, | |||
| "data" => $url, | |||
| )); | |||
| } | |||
| ?> | |||
| @@ -26,7 +26,7 @@ | |||
| <li class="breadcrumb-item active">发布文档</li> | |||
| </ol> | |||
| <div class="card shadow-sm"> | |||
| <div class="card-header d-flex justify-content-between align-items-center">发布文档 <button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">AI发布文档</button></div> | |||
| <div class="card-header d-flex justify-content-between align-items-center">发布文档 <?php if($cfg_ai_enabled == 'Y'){ ;?><button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">AI发布文档</button><?php } ;?></div> | |||
| <div class="card-body"> | |||
| <form name="form1" action="article_add.php" method="post" enctype="multipart/form-data"> | |||
| <input type="hidden" name="channelid" value="<?php echo $channelid?>"> | |||
| @@ -262,10 +262,16 @@ | |||
| function showAI() { | |||
| $("#mdlAI").modal('show'); | |||
| } | |||
| $("#btnAIAction").click(function() { | |||
| $("#btnAIAction").click(async function() { | |||
| let prompt = document.getElementById("prompt").value; | |||
| let modelid = document.getElementById("modelid").value; | |||
| let eventSource = new EventSource(`<?php echo $cfg_ai_server;?>/ai/article_add?modelid=${modelid}&prompt=${prompt}`); | |||
| let req = await fetch(`api.php?action=get_ai_server&pname=article_add&modelid=${modelid}&prompt=${prompt}`); | |||
| let resp = await req.json(); | |||
| if (resp.code !== 0) { | |||
| ShowMsg("获取服务器地址失败"); | |||
| return | |||
| } | |||
| let eventSource = new EventSource(resp.data); | |||
| // 新增状态跟踪变量 | |||
| let currentKey = null; | |||
| @@ -26,7 +26,7 @@ | |||
| <li class="breadcrumb-item active">修改文档</li> | |||
| </ol> | |||
| <div class="card shadow-sm"> | |||
| <div class="card-header d-flex justify-content-between align-items-center">修改<?php echo $arcRow['title'];?>文档 <button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">AI修改文档</button></div> | |||
| <div class="card-header d-flex justify-content-between align-items-center">修改<?php echo $arcRow['title'];?>文档 <?php if($cfg_ai_enabled == 'Y'){ ;?><button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">AI修改文档</button><?php } ;?></div> | |||
| <div class="card-body"> | |||
| <form name="form1" action="article_edit.php" method="post" enctype="multipart/form-data"> | |||
| <input type="hidden" name="dopost" value="save"> | |||
| @@ -266,11 +266,17 @@ | |||
| function showAI() { | |||
| $("#mdlAI").modal('show'); | |||
| } | |||
| $("#btnAIAction").click(function() { | |||
| $("#btnAIAction").click(async function() { | |||
| let prompt = document.getElementById("prompt").value; | |||
| let modelid = document.getElementById("modelid").value; | |||
| let eventSource = new EventSource(`<?php echo $cfg_ai_server;?>/ai/article_edit?aid=<?php echo $aid?>&modelid=${modelid}&prompt=${prompt}`); | |||
| let req = await fetch(`api.php?action=get_ai_server&pname=article_edit&aid=<?php echo $aid?>&modelid=${modelid}&prompt=${prompt}`); | |||
| let resp = await req.json(); | |||
| if (resp.code !== 0) { | |||
| ShowMsg("获取服务器地址失败"); | |||
| return | |||
| } | |||
| let eventSource = new EventSource(resp.data); | |||
| // 新增状态跟踪变量 | |||
| let currentKey = null; | |||
| let tagBuffer = ""; | |||
| @@ -308,10 +314,7 @@ | |||
| CKEDITOR.instances["body"].setReadOnly(false); | |||
| bodyHtml = ""; | |||
| } else if(currentKey == "typeid"){ | |||
| typeid += tagBuffer; | |||
| } else if(currentKey == "typeid"){ | |||
| const input = document.querySelector(`[name="${currentKey}"]`); | |||
| console.log("typeid=",typeid); | |||
| if (input) { | |||
| $(input).val(typeid); | |||
| $(input).prop("disabled", false).removeClass("disabled"); // 恢复输入状态 | |||
| @@ -345,6 +348,8 @@ | |||
| // CKEDITOR.instances["body"].insertHtml(char); | |||
| bodyHtml += char; | |||
| CKEDITOR.instances["body"].setData(bodyHtml) | |||
| } else if(currentKey == "typeid"){ | |||
| typeid += char; | |||
| } else { | |||
| const input = document.querySelector(`[name="${currentKey}"]`); | |||
| if (input) { | |||
| @@ -19,7 +19,7 @@ | |||
| <li class="breadcrumb-item active">添加栏目</li> | |||
| </ol> | |||
| <div class="card shadow-sm"> | |||
| <div class="card-header d-flex justify-content-between align-items-center">添加栏目 <button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">AI创建栏目</button></div> | |||
| <div class="card-header d-flex justify-content-between align-items-center">添加栏目 <?php if($cfg_ai_enabled == 'Y'){ ;?><button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">AI创建栏目</button><?php } ;?></div> | |||
| <div class="card-body"> | |||
| <form name="form1" action="catalog_add.php" method="post"> | |||
| <input type="hidden" name="dopost" value="save"> | |||
| @@ -412,10 +412,17 @@ | |||
| function showAI() { | |||
| $("#mdlAI").modal('show'); | |||
| } | |||
| $("#btnAIAction").click(function() { | |||
| $("#btnAIAction").click(async function() { | |||
| let prompt = document.getElementById("prompt").value; | |||
| let modelid = document.getElementById("modelid").value; | |||
| let eventSource = new EventSource(`<?php echo $cfg_ai_server;?>/ai/catalog_add?modelid=${modelid}&prompt=${prompt}`); | |||
| let req = await fetch(`api.php?action=get_ai_server&pname=catalog_add&modelid=${modelid}&prompt=${prompt}`); | |||
| let resp = await req.json(); | |||
| if (resp.code !== 0) { | |||
| ShowMsg("获取服务器地址失败"); | |||
| return | |||
| } | |||
| let eventSource = new EventSource(resp.data); | |||
| // 新增状态跟踪变量 | |||
| let currentKey = null; | |||
| @@ -19,7 +19,7 @@ | |||
| <li class="breadcrumb-item active">批量添加栏目</li> | |||
| </ol> | |||
| <div class="card shadow-sm"> | |||
| <div class="card-header d-flex justify-content-between align-items-center">批量添加栏目<button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">AI批量创建</button></div> | |||
| <div class="card-header d-flex justify-content-between align-items-center">批量添加栏目 <?php if($cfg_ai_enabled == 'Y'){ ;?><button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">AI批量创建</button><?php } ;?></div> | |||
| <div class="card-body"> | |||
| <form name="form1" action="catalog_add.php" method="post"> | |||
| <input type="hidden" name="dopost" value="savequick"> | |||
| @@ -287,7 +287,7 @@ | |||
| $("#btnAIAction").click(function() { | |||
| let prompt = document.getElementById("prompt").value; | |||
| let modelid = document.getElementById("modelid").value; | |||
| let eventSource = new EventSource(`<?php echo $cfg_ai_server;?>/ai/catalog_add_quick?modelid=${modelid}&prompt=${prompt}`); | |||
| let eventSource = new EventSource(`<?php echo $cfg_ai_server;?>/ai/catalog_add_quick?pname=catalog_add_quick&modelid=${modelid}&prompt=${prompt}`); | |||
| // 新增状态跟踪变量 | |||
| let currentKey = null; | |||
| @@ -19,7 +19,7 @@ | |||
| <li class="breadcrumb-item active">修改栏目</li> | |||
| </ol> | |||
| <div class="card shadow-sm"> | |||
| <div class="card-header d-flex justify-content-between align-items-center">修改栏目 <button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">AI修改栏目</button></div> | |||
| <div class="card-header d-flex justify-content-between align-items-center">修改栏目 <?php if($cfg_ai_enabled == 'Y'){ ;?><button type="button" id="btnAI" onclick="showAI();" class="btn btn-success btn-sm">AI修改栏目</button><?php } ;?></div> | |||
| <div class="card-body"> | |||
| <form name="form1" action="catalog_edit.php" method="post"> | |||
| <input type="hidden" name="dopost" value="save"> | |||
| @@ -444,10 +444,16 @@ | |||
| $("#mdlAI").modal('show'); | |||
| } | |||
| let bodyHtml = ""; | |||
| $("#btnAIAction").click(function() { | |||
| $("#btnAIAction").click(async function() { | |||
| let prompt = document.getElementById("prompt").value; | |||
| let modelid = document.getElementById("modelid").value; | |||
| let eventSource = new EventSource(`<?php echo $cfg_ai_server;?>/ai/catalog_edit?tid=<?php echo $id;?>&modelid=${modelid}&prompt=${prompt}`); | |||
| let req = await fetch(`api.php?action=get_ai_server&pname=catalog_edit&tid=<?php echo $id?>&modelid=${modelid}&prompt=${prompt}`); | |||
| let resp = await req.json(); | |||
| if (resp.code !== 0) { | |||
| ShowMsg("获取服务器地址失败"); | |||
| return | |||
| } | |||
| let eventSource = new EventSource(resp.data); | |||
| // 新增状态跟踪变量 | |||
| let currentKey = null; | |||
| @@ -60,7 +60,7 @@ foreach ($_FILES as $_key => $_value) { | |||
| $imgtypes = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp", "image/webp"); | |||
| if (is_array(${$_key.'_type'}) && count(${$_key.'_type'}) > 0) { | |||
| foreach (${$_key.'_type'} as $key => $value) { | |||
| if (in_array(strtolower(trim($value)), $imtypes)) { | |||
| if (in_array(strtolower(trim($value)), $imgtypes)) { | |||
| $image_dd = @getimagesize($$_key); | |||
| if ($image_dd == false) { | |||
| continue; | |||
| @@ -71,7 +71,7 @@ foreach ($_FILES as $_key => $_value) { | |||
| } | |||
| } | |||
| $imgtypes = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp", "image/webp"); | |||
| if (in_array(strtolower(trim($value)), $imtypes)) { | |||
| if (in_array(strtolower(trim($value)), $imgtypes)) { | |||
| $image_dd = @getimagesize($$_key); | |||
| if ($image_dd == false) { | |||
| continue; | |||