Build a full-width CMS canvas and restore featured home products
This commit is contained in:
@@ -192,6 +192,9 @@ class AdminController
|
||||
}
|
||||
$data['name'] = $request->post('name') === null ? $page['name'] : $this->input($request, 'name');
|
||||
$data['status'] = $request->post('status') === null || $slug === 'home' ? $page['status'] : $this->input($request, 'status');
|
||||
$scale = $this->input($request, 'image_scale');
|
||||
$data['image_scale'] = $request->post('image_scale') === null ? (int) $page['image_scale']
|
||||
: (ctype_digit($scale) ? (int) $scale : -1);
|
||||
$data['actions'] = [];
|
||||
$validButtons = true;
|
||||
foreach ([1, 2] as $index) {
|
||||
@@ -211,6 +214,7 @@ class AdminController
|
||||
($data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 ||
|
||||
$data['heading'] === '' || mb_strlen($data['heading'] . $data['accent']) > 110 ||
|
||||
mb_strlen($data['lead']) > 600 || mb_strlen($data['alt']) > 200 ||
|
||||
!in_array($data['image_scale'], [0, 25, 40, 50, 60, 75, 85, 100], true) ||
|
||||
strlen($data['image']) > 1000 || ($data['image'] !== '' && !Html::url($data['image'], true)) || !$validButtons) {
|
||||
throw new RuntimeException('请检查页面标题、说明、图片地址和按钮链接。');
|
||||
}
|
||||
@@ -224,7 +228,7 @@ class AdminController
|
||||
}
|
||||
|
||||
return $this->render($request, 'admin-page', [
|
||||
'title' => '编辑 ' . $page['name'], 'page' => $page, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
'title' => '编辑 ' . $page['name'], 'page' => $page, 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
], $error !== '' ? 422 : 200);
|
||||
}
|
||||
|
||||
@@ -269,7 +273,7 @@ class AdminController
|
||||
return [];
|
||||
}
|
||||
$changes = is_string($payload) ? json_decode($payload, true) : null;
|
||||
if (!is_array($changes) || !array_is_list($changes) || count($changes) > count($sections)) {
|
||||
if (!is_array($changes) || !array_is_list($changes) || count($changes) > count($sections) + 50) {
|
||||
throw new RuntimeException('区块已变更或画布内容无效,请重新打开编辑页。');
|
||||
}
|
||||
$available = array_column($sections, null, 'key');
|
||||
@@ -278,13 +282,21 @@ class AdminController
|
||||
$key = $change['key'] ?? null;
|
||||
$version = $change['version'] ?? null;
|
||||
$fields = $change['fields'] ?? null;
|
||||
if (!is_string($key) || !isset($available[$key]) || !is_int($version) || !is_array($fields) || $fields === []) {
|
||||
$isNew = is_array($change) && array_key_exists('version', $change) && $version === null;
|
||||
if (!is_string($key) || isset($updates[$key]) || !is_array($fields) || $fields === []
|
||||
|| ($isNew ? (isset($available[$key]) || !preg_match('/^block-[a-f0-9]{32}$/D', $key))
|
||||
: (!isset($available[$key]) || !is_int($version) || $version !== (int) $available[$key]['version']))) {
|
||||
throw new RuntimeException('区块已变更或画布内容无效,请重新打开编辑页。');
|
||||
}
|
||||
$section = $available[$key];
|
||||
unset($available[$key]);
|
||||
$section = $available[$key] ?? ['key' => $key, 'title' => '', 'lead' => '', 'body' => '', 'style' => 'plain'];
|
||||
foreach ($fields as $field => $value) {
|
||||
if (!in_array($field, ['title', 'lead', 'body'], true) || !is_string($value)) {
|
||||
if (!in_array($field, ['title', 'lead', 'body'], true)) {
|
||||
throw new RuntimeException('画布内容无效。');
|
||||
}
|
||||
if ($field === 'body' && is_array($value)) {
|
||||
$value = Html::applyCanvasEdits($section['body'], $value);
|
||||
}
|
||||
if (!is_string($value)) {
|
||||
throw new RuntimeException('画布内容无效。');
|
||||
}
|
||||
$section[$field] = trim($value);
|
||||
@@ -294,7 +306,7 @@ class AdminController
|
||||
$section['body'] = Html::sanitize($section['body']);
|
||||
}
|
||||
$section['version'] = $version;
|
||||
$updates[] = $section;
|
||||
$updates[$key] = $section;
|
||||
}
|
||||
|
||||
return $updates;
|
||||
|
||||
Reference in New Issue
Block a user