mirror of
https://github.com/flextype/flextype.git
synced 2025-08-14 17:14:22 +02:00
Admin Panel: Fieldsets Manager - cleanup and refactoring
This commit is contained in:
@@ -18,116 +18,144 @@ class FieldsetsManager
|
||||
|
||||
switch (Http::getUriSegment(2)) {
|
||||
case 'add':
|
||||
$create_fieldset = Http::post('create_fieldset');
|
||||
|
||||
if (isset($create_fieldset)) {
|
||||
if (Token::check((Http::post('token')))) {
|
||||
|
||||
$file = PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Text::safeString(Http::post('name'), '-', true) . '.yaml';
|
||||
|
||||
if (!Filesystem::has($file)) {
|
||||
// Create a fieldset!
|
||||
if (Filesystem::write(
|
||||
$file,
|
||||
YamlParser::encode([
|
||||
'title' => Http::post('title'),
|
||||
'fields' => [
|
||||
'title' => [
|
||||
'title' => 'admin_title',
|
||||
'type' => 'text',
|
||||
'size' => 'col-12'
|
||||
]
|
||||
]
|
||||
])
|
||||
)) {
|
||||
Notification::set('success', __('admin_message_fieldset_created'));
|
||||
Http::redirect(Http::getBaseUrl() . '/admin/fieldsets');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new \RuntimeException("Request was denied because it contained an invalid security token. Please refresh the page and try again.");
|
||||
}
|
||||
}
|
||||
|
||||
Themes::view('admin/views/templates/extends/fieldsets/add')
|
||||
->display();
|
||||
FieldsetsManager::addFieldsets();
|
||||
break;
|
||||
case 'delete':
|
||||
if (Http::get('fieldset') != '') {
|
||||
if (Token::check((Http::get('token')))) {
|
||||
Filesystem::delete(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '.yaml');
|
||||
Notification::set('success', __('admin_message_fieldset_deleted'));
|
||||
Http::redirect(Http::getBaseUrl() . '/admin/fieldsets');
|
||||
} else {
|
||||
throw new \RuntimeException("Request was denied because it contained an invalid security token. Please refresh the page and try again.");
|
||||
}
|
||||
}
|
||||
FieldsetsManager::deleteFieldsets();
|
||||
break;
|
||||
case 'rename':
|
||||
$rename_fieldset = Http::post('rename_fieldset');
|
||||
|
||||
if (isset($rename_fieldset)) {
|
||||
if (Token::check((Http::post('token')))) {
|
||||
if (!Filesystem::has(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('name') . '.yaml')) {
|
||||
if (rename(
|
||||
PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('name_current') . '.yaml',
|
||||
PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('name') . '.yaml')
|
||||
) {
|
||||
Notification::set('success', __('admin_message_fieldset_renamed'));
|
||||
Http::redirect(Http::getBaseUrl() . '/admin/fieldsets');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new \RuntimeException("Request was denied because it contained an invalid security token. Please refresh the page and try again.");
|
||||
}
|
||||
}
|
||||
|
||||
Themes::view('admin/views/templates/extends/fieldsets/rename')
|
||||
->assign('name_current', Http::get('fieldset'))
|
||||
->display();
|
||||
FieldsetsManager::renameFieldsets();
|
||||
break;
|
||||
case 'duplicate':
|
||||
if (Http::get('fieldset') != '') {
|
||||
if (Token::check((Http::get('token')))) {
|
||||
Filesystem::copy(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '.yaml',
|
||||
PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '-duplicate-' . date("Ymd_His") . '.yaml');
|
||||
Notification::set('success', __('admin_message_fieldset_duplicated'));
|
||||
Http::redirect(Http::getBaseUrl() . '/admin/fieldsets');
|
||||
} else {
|
||||
throw new \RuntimeException("Request was denied because it contained an invalid security token. Please refresh the page and try again.");
|
||||
}
|
||||
}
|
||||
FieldsetsManager::duplicateFieldsets();
|
||||
break;
|
||||
case 'edit':
|
||||
$action = Http::post('action');
|
||||
|
||||
if (isset($action) && $action == 'save-form') {
|
||||
if (Token::check((Http::post('token')))) {
|
||||
|
||||
// Save a fieldset!
|
||||
if (Filesystem::write(
|
||||
PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('name') . '.yaml',
|
||||
Http::post('fieldset')
|
||||
)) {
|
||||
Notification::set('success', __('admin_message_fieldset_saved'));
|
||||
Http::redirect(Http::getBaseUrl() . '/admin/fieldsets/edit?fieldset=' . Http::post('name'));
|
||||
}
|
||||
} else {
|
||||
throw new \RuntimeException("Request was denied because it contained an invalid security token. Please refresh the page and try again.");
|
||||
}
|
||||
}
|
||||
|
||||
Themes::view('admin/views/templates/extends/fieldsets/edit')
|
||||
->assign('fieldset', Filesystem::read(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '.yaml'))
|
||||
->display();
|
||||
FieldsetsManager::editFieldsets();
|
||||
break;
|
||||
default:
|
||||
$fieldsets_list = Themes::getFieldsets();
|
||||
|
||||
Themes::view('admin/views/templates/extends/fieldsets/list')
|
||||
->assign('fieldsets_list', $fieldsets_list)
|
||||
->display();
|
||||
FieldsetsManager::listFieldsets();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected static function addFieldsets()
|
||||
{
|
||||
$create_fieldset = Http::post('create_fieldset');
|
||||
|
||||
if (isset($create_fieldset)) {
|
||||
if (Token::check((Http::post('token')))) {
|
||||
|
||||
$file = PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Text::safeString(Http::post('name'), '-', true) . '.yaml';
|
||||
|
||||
if (!Filesystem::has($file)) {
|
||||
// Create a fieldset!
|
||||
if (Filesystem::write(
|
||||
$file,
|
||||
YamlParser::encode([
|
||||
'title' => Http::post('title'),
|
||||
'fields' => [
|
||||
'title' => [
|
||||
'title' => 'admin_title',
|
||||
'type' => 'text',
|
||||
'size' => 'col-12'
|
||||
]
|
||||
]
|
||||
])
|
||||
)) {
|
||||
Notification::set('success', __('admin_message_fieldset_created'));
|
||||
Http::redirect(Http::getBaseUrl() . '/admin/fieldsets');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new \RuntimeException("Request was denied because it contained an invalid security token. Please refresh the page and try again.");
|
||||
}
|
||||
}
|
||||
|
||||
Themes::view('admin/views/templates/extends/fieldsets/add')
|
||||
->display();
|
||||
}
|
||||
|
||||
protected static function renameFieldsets()
|
||||
{
|
||||
$rename_fieldset = Http::post('rename_fieldset');
|
||||
|
||||
if (isset($rename_fieldset)) {
|
||||
if (Token::check((Http::post('token')))) {
|
||||
if (!Filesystem::has(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('name') . '.yaml')) {
|
||||
if (rename(
|
||||
PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('name_current') . '.yaml',
|
||||
PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('name') . '.yaml')
|
||||
) {
|
||||
Notification::set('success', __('admin_message_fieldset_renamed'));
|
||||
Http::redirect(Http::getBaseUrl() . '/admin/fieldsets');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new \RuntimeException("Request was denied because it contained an invalid security token. Please refresh the page and try again.");
|
||||
}
|
||||
}
|
||||
|
||||
Themes::view('admin/views/templates/extends/fieldsets/rename')
|
||||
->assign('name_current', Http::get('fieldset'))
|
||||
->display();
|
||||
}
|
||||
|
||||
protected static function duplicateFieldsets()
|
||||
{
|
||||
if (Http::get('fieldset') != '') {
|
||||
if (Token::check((Http::get('token')))) {
|
||||
Filesystem::copy(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '.yaml',
|
||||
PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '-duplicate-' . date("Ymd_His") . '.yaml');
|
||||
Notification::set('success', __('admin_message_fieldset_duplicated'));
|
||||
Http::redirect(Http::getBaseUrl() . '/admin/fieldsets');
|
||||
} else {
|
||||
throw new \RuntimeException("Request was denied because it contained an invalid security token. Please refresh the page and try again.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function deleteFieldsets()
|
||||
{
|
||||
if (Http::get('fieldset') != '') {
|
||||
if (Token::check((Http::get('token')))) {
|
||||
Filesystem::delete(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '.yaml');
|
||||
Notification::set('success', __('admin_message_fieldset_deleted'));
|
||||
Http::redirect(Http::getBaseUrl() . '/admin/fieldsets');
|
||||
} else {
|
||||
throw new \RuntimeException("Request was denied because it contained an invalid security token. Please refresh the page and try again.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function editFieldsets()
|
||||
{
|
||||
$action = Http::post('action');
|
||||
|
||||
if (isset($action) && $action == 'save-form') {
|
||||
if (Token::check((Http::post('token')))) {
|
||||
|
||||
// Save a fieldset!
|
||||
if (Filesystem::write(
|
||||
PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('name') . '.yaml',
|
||||
Http::post('fieldset')
|
||||
)) {
|
||||
Notification::set('success', __('admin_message_fieldset_saved'));
|
||||
Http::redirect(Http::getBaseUrl() . '/admin/fieldsets/edit?fieldset=' . Http::post('name'));
|
||||
}
|
||||
} else {
|
||||
throw new \RuntimeException("Request was denied because it contained an invalid security token. Please refresh the page and try again.");
|
||||
}
|
||||
}
|
||||
|
||||
Themes::view('admin/views/templates/extends/fieldsets/edit')
|
||||
->assign('fieldset', Filesystem::read(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '.yaml'))
|
||||
->display();
|
||||
}
|
||||
|
||||
protected static function listFieldsets()
|
||||
{
|
||||
Themes::view('admin/views/templates/extends/fieldsets/list')
|
||||
->assign('fieldsets_list', Themes::getFieldsets())
|
||||
->display();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user