1
0
mirror of https://github.com/typecho/typecho.git synced 2025-03-20 09:59:41 +01:00

Merge commit 'e143be0036b91a6ec4bfc5e8d3ad7c19edbfa6e8' into dev

This commit is contained in:
joyqi 2023-09-22 11:08:55 +08:00
commit f206d852bd
7 changed files with 49 additions and 18 deletions

@ -30,7 +30,7 @@ $(document).ready(function () {
});
$('#custom-field button.operate-add').click(function () {
var html = '<tr><td><input type="text" name="fieldNames[]" placeholder="<?php _e('字段名称'); ?>" class="text-s w-100"></td>'
var html = '<tr><td><input type="text" name="fieldNames[]" placeholder="<?php _e('字段名称'); ?>" pattern="^[_a-zA-Z][_a-zA-Z0-9]*$" oninput="this.reportValidity()" class="text-s w-100"></td>'
+ '<td><select name="fieldTypes[]" id="">'
+ '<option value="str"><?php _e('字符'); ?></option>'
+ '<option value="int"><?php _e('整数'); ?></option>'

@ -26,7 +26,7 @@ $defaultFields = isset($post) ? $post->getDefaultFieldItems() : $page->getDefaul
<td>
<label for="fieldname" class="sr-only"><?php _e('字段名称'); ?></label>
<input type="text" name="fieldNames[]" value="<?php echo htmlspecialchars($field['name']); ?>"
id="fieldname" class="text-s w-100">
id="fieldname" pattern="^[_a-zA-Z][_a-zA-Z0-9]*$" oninput="this.reportValidity()" class="text-s w-100">
</td>
<td>
<label for="fieldtype" class="sr-only"><?php _e('字段类型'); ?></label>
@ -56,7 +56,7 @@ $defaultFields = isset($post) ? $post->getDefaultFieldItems() : $page->getDefaul
<td>
<label for="fieldname" class="sr-only"><?php _e('字段名称'); ?></label>
<input type="text" name="fieldNames[]" placeholder="<?php _e('字段名称'); ?>" id="fieldname"
class="text-s w-100">
class="text-s w-100" pattern="^[_a-zA-Z][_a-zA-Z0-9]*$" oninput="this.reportValidity()">
</td>
<td>
<label for="fieldtype" class="sr-only"><?php _e('字段类型'); ?></label>

@ -17,7 +17,7 @@ if (preg_match("/^([0-9]+)([a-z]{1,2})$/i", $phpMaxFilesize, $matches)) {
<script src="<?php $options->adminStaticUrl('js', 'plupload.js'); ?>"></script>
<script>
$(document).ready(function() {
function updateAttacmentNumber () {
function updateAttachmentNumber () {
var btn = $('#tab-files-btn'),
balloon = $('.balloon', btn),
count = $('#file-list li .insert').length;
@ -56,7 +56,7 @@ $(document).ready(function() {
}
});
updateAttacmentNumber();
updateAttachmentNumber();
function fileUploadStart (file) {
$('<li id="' + file.id + '" class="loading">'
@ -113,7 +113,7 @@ $(document).ready(function() {
attachInsertEvent(li);
attachDeleteEvent(li);
updateAttacmentNumber();
updateAttachmentNumber();
if (!completeFile) {
completeFile = data;
@ -211,7 +211,7 @@ $(document).ready(function() {
function () {
$(el).fadeOut(function () {
$(this).remove();
updateAttacmentNumber();
updateAttachmentNumber();
});
});
}

@ -353,7 +353,7 @@ class Client
* 获取回执的头部信息
*
* @param string $key 头信息名称
* @return string
* @return ?string
*/
public function getResponseHeader(string $key): ?string
{

@ -351,6 +351,19 @@ class Request
return ($this->pathInfo = '/' . ltrim(urldecode($pathInfo), '/'));
}
/**
* 获取请求的内容类型
*
* @return string|null
*/
public function getContentType(): ?string
{
return $this->getServer(
'CONTENT_TYPE',
$this->getServer('HTTP_CONTENT_TYPE')
);
}
/**
* 获取环境变量
*
@ -492,7 +505,10 @@ class Request
*/
public function isJson(): bool
{
return !!preg_match("/^\s*application\/json(;|$)/i", $this->getHeader('Content-Type', ''));
return !!preg_match(
"/^\s*application\/json(;|$)/i",
$this->getContentType() ?? ''
);
}
/**

@ -213,6 +213,16 @@ class Request
return $this->request->makeUriByRequest($parameter);
}
/**
* 获取请求的内容类型
*
* @return string|null
*/
public function getContentType(): ?string
{
return $this->request->getContentType();
}
/**
* 获取环境变量
*
@ -317,6 +327,16 @@ class Request
return $this->request->isAjax();
}
/**
* 判断是否为json
*
* @return boolean
*/
public function isJson(): bool
{
return $this->request->isJson();
}
/**
* 判断输入是否满足要求
*

@ -41,10 +41,10 @@ class Ajax extends BaseOptions implements ActionInterface
{
$this->user->pass('editor');
$client = Client::get();
$result = ['available' => 0];
if ($client) {
$client->setHeader('User-Agent', $this->options->generator)
->setTimeout(10);
$result = ['available' => 0];
try {
$client->send('https://typecho.org/version.json');
@ -72,11 +72,9 @@ class Ajax extends BaseOptions implements ActionInterface
} catch (\Exception $e) {
// do nothing
}
$this->response->throwJson($result);
}
throw new Exception(_t('禁止访问'), 403);
$this->response->throwJson($result);
}
/**
@ -89,6 +87,7 @@ class Ajax extends BaseOptions implements ActionInterface
{
$this->user->pass('subscriber');
$client = Client::get();
$data = [];
if ($client) {
$client->setHeader('User-Agent', $this->options->generator)
->setTimeout(10)
@ -102,8 +101,6 @@ class Ajax extends BaseOptions implements ActionInterface
$matches
);
$data = [];
if ($matches) {
foreach ($matches[0] as $key => $val) {
$data[] = [
@ -117,11 +114,9 @@ class Ajax extends BaseOptions implements ActionInterface
}
}
}
$this->response->throwJson($data);
}
throw new Exception(_t('禁止访问'), 403);
$this->response->throwJson($data);
}
/**