forked from laysense/laysense.cn
Scope article feeds and expand canvas editing
This commit is contained in:
@@ -255,6 +255,9 @@ class AdminController
|
||||
}
|
||||
$page = array_replace($page, $data, ['version' => $this->version($request)]);
|
||||
try {
|
||||
$data['alignments'] = $request->post('alignments') === null ? $page['alignments']
|
||||
: $this->alignmentMap(json_decode($this->input($request, 'alignments'), true), ['heading', 'lead', 'actions', 'image']);
|
||||
$page['alignments'] = $data['alignments'];
|
||||
$data['quicklinks'] = $request->post('quicklinks') === null ? $page['quicklinks'] : SiteDesign::parseLinks($this->input($request, 'quicklinks'));
|
||||
if ($data['name'] === '' || mb_strlen($data['name']) > 100 || !in_array($data['status'], ['draft', 'published'], true)
|
||||
|| $data['title'] === '' || mb_strlen($data['title']) > 160 ||
|
||||
@@ -334,8 +337,9 @@ class AdminController
|
||||
$key = $change['key'] ?? null;
|
||||
$version = $change['version'] ?? null;
|
||||
$fields = $change['fields'] ?? null;
|
||||
$alignments = $change['alignments'] ?? null;
|
||||
$isNew = is_array($change) && array_key_exists('version', $change) && $version === null;
|
||||
if (!is_string($key) || isset($updates[$key]) || !is_array($fields) || $fields === []
|
||||
if (!is_string($key) || isset($updates[$key]) || !is_array($fields) || ($fields === [] && $alignments === null)
|
||||
|| ($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('区块已变更或画布内容无效,请重新打开编辑页。');
|
||||
@@ -353,6 +357,9 @@ class AdminController
|
||||
}
|
||||
$section[$field] = trim($value);
|
||||
}
|
||||
if ($alignments !== null) {
|
||||
$section['alignments'] = Database::json($this->alignmentMap($alignments, ['title', 'lead']));
|
||||
}
|
||||
$this->checkSection($section, $section['style']);
|
||||
if (isset($fields['body'])) {
|
||||
$section['body'] = Html::sanitize($section['body']);
|
||||
@@ -367,6 +374,20 @@ class AdminController
|
||||
return $updates;
|
||||
}
|
||||
|
||||
private function alignmentMap(mixed $alignments, array $fields): array
|
||||
{
|
||||
if (!is_array($alignments) || array_diff(array_keys($alignments), $fields)) {
|
||||
throw new RuntimeException('画布对齐设置无效。');
|
||||
}
|
||||
foreach ($alignments as $value) {
|
||||
if (!in_array($value, Html::ALIGNMENTS, true)) {
|
||||
throw new RuntimeException('画布对齐设置无效。');
|
||||
}
|
||||
}
|
||||
|
||||
return $alignments;
|
||||
}
|
||||
|
||||
private function checkSection(array $section, string $savedStyle): void
|
||||
{
|
||||
if ($section['title'] === '' || mb_strlen($section['title']) > 100 || mb_strlen($section['lead']) > 500
|
||||
|
||||
Reference in New Issue
Block a user