Add blueprints and fake content
This commit is contained in:
parent
1ff19bf38f
commit
8235816462
592 changed files with 22385 additions and 31535 deletions
12
kirby/config/areas/account.php
Normal file
12
kirby/config/areas/account.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
return function () {
|
||||
return [
|
||||
'icon' => 'account',
|
||||
'label' => t('view.account'),
|
||||
'search' => 'users',
|
||||
'dialogs' => require __DIR__ . '/account/dialogs.php',
|
||||
'dropdowns' => require __DIR__ . '/account/dropdowns.php',
|
||||
'views' => require __DIR__ . '/account/views.php'
|
||||
];
|
||||
};
|
70
kirby/config/areas/account/dialogs.php
Normal file
70
kirby/config/areas/account/dialogs.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
$dialogs = require __DIR__ . '/../users/dialogs.php';
|
||||
|
||||
return [
|
||||
|
||||
// change email
|
||||
'account.changeEmail' => [
|
||||
'pattern' => '(account)/changeEmail',
|
||||
'load' => $dialogs['user.changeEmail']['load'],
|
||||
'submit' => $dialogs['user.changeEmail']['submit'],
|
||||
],
|
||||
|
||||
// change language
|
||||
'account.changeLanguage' => [
|
||||
'pattern' => '(account)/changeLanguage',
|
||||
'load' => $dialogs['user.changeLanguage']['load'],
|
||||
'submit' => $dialogs['user.changeLanguage']['submit'],
|
||||
],
|
||||
|
||||
// change name
|
||||
'account.changeName' => [
|
||||
'pattern' => '(account)/changeName',
|
||||
'load' => $dialogs['user.changeName']['load'],
|
||||
'submit' => $dialogs['user.changeName']['submit'],
|
||||
],
|
||||
|
||||
// change password
|
||||
'account.changePassword' => [
|
||||
'pattern' => '(account)/changePassword',
|
||||
'load' => $dialogs['user.changePassword']['load'],
|
||||
'submit' => $dialogs['user.changePassword']['submit'],
|
||||
],
|
||||
|
||||
// change role
|
||||
'account.changeRole' => [
|
||||
'pattern' => '(account)/changeRole',
|
||||
'load' => $dialogs['user.changeRole']['load'],
|
||||
'submit' => $dialogs['user.changeRole']['submit'],
|
||||
],
|
||||
|
||||
// delete
|
||||
'account.delete' => [
|
||||
'pattern' => '(account)/delete',
|
||||
'load' => $dialogs['user.delete']['load'],
|
||||
'submit' => $dialogs['user.delete']['submit'],
|
||||
],
|
||||
|
||||
// change file name
|
||||
'account.file.changeName' => [
|
||||
'pattern' => '(account)/files/(:any)/changeName',
|
||||
'load' => $dialogs['user.file.changeName']['load'],
|
||||
'submit' => $dialogs['user.file.changeName']['submit'],
|
||||
],
|
||||
|
||||
// change file sort
|
||||
'account.file.changeSort' => [
|
||||
'pattern' => '(account)/files/(:any)/changeSort',
|
||||
'load' => $dialogs['user.file.changeSort']['load'],
|
||||
'submit' => $dialogs['user.file.changeSort']['submit'],
|
||||
],
|
||||
|
||||
// delete
|
||||
'account.file.delete' => [
|
||||
'pattern' => '(account)/files/(:any)/delete',
|
||||
'load' => $dialogs['user.file.delete']['load'],
|
||||
'submit' => $dialogs['user.file.delete']['submit'],
|
||||
],
|
||||
|
||||
];
|
14
kirby/config/areas/account/dropdowns.php
Normal file
14
kirby/config/areas/account/dropdowns.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
$dropdowns = require __DIR__ . '/../users/dropdowns.php';
|
||||
|
||||
return [
|
||||
'account' => [
|
||||
'pattern' => '(account)',
|
||||
'options' => $dropdowns['user']['options']
|
||||
],
|
||||
'account.file' => [
|
||||
'pattern' => '(account)/files/(:any)',
|
||||
'options' => $dropdowns['user.file']['options']
|
||||
],
|
||||
];
|
40
kirby/config/areas/account/views.php
Normal file
40
kirby/config/areas/account/views.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Find;
|
||||
use Kirby\Panel\Panel;
|
||||
|
||||
return [
|
||||
'account' => [
|
||||
'pattern' => 'account',
|
||||
'action' => function () {
|
||||
return [
|
||||
'component' => 'k-account-view',
|
||||
'props' => kirby()->user()->panel()->props(),
|
||||
];
|
||||
},
|
||||
],
|
||||
'account.file' => [
|
||||
'pattern' => 'account/files/(:any)',
|
||||
'action' => function (string $filename) {
|
||||
return Find::file('account', $filename)->panel()->view();
|
||||
}
|
||||
],
|
||||
'account.logout' => [
|
||||
'pattern' => 'logout',
|
||||
'auth' => false,
|
||||
'action' => function () {
|
||||
if ($user = kirby()->user()) {
|
||||
$user->logout();
|
||||
}
|
||||
Panel::go('login');
|
||||
},
|
||||
],
|
||||
'account.password' => [
|
||||
'pattern' => 'reset-password',
|
||||
'action' => function () {
|
||||
return [
|
||||
'component' => 'k-reset-password-view',
|
||||
];
|
||||
}
|
||||
]
|
||||
];
|
131
kirby/config/areas/files/dialogs.php
Normal file
131
kirby/config/areas/files/dialogs.php
Normal file
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Find;
|
||||
use Kirby\Panel\Field;
|
||||
use Kirby\Panel\Panel;
|
||||
use Kirby\Toolkit\Escape;
|
||||
|
||||
/**
|
||||
* Shared file dialogs
|
||||
* They are included in the site and
|
||||
* users area to create dialogs there.
|
||||
* The array keys are replaced by
|
||||
* the appropriate routes in the areas.
|
||||
*/
|
||||
return [
|
||||
'changeName' => [
|
||||
'load' => function (string $path, string $filename) {
|
||||
$file = Find::file($path, $filename);
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'name' => [
|
||||
'label' => t('name'),
|
||||
'type' => 'slug',
|
||||
'required' => true,
|
||||
'icon' => 'title',
|
||||
'allow' => '@._-',
|
||||
'after' => '.' . $file->extension(),
|
||||
'preselect' => true
|
||||
]
|
||||
],
|
||||
'submitButton' => t('rename'),
|
||||
'value' => [
|
||||
'name' => $file->name(),
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $path, string $filename) {
|
||||
$file = Find::file($path, $filename);
|
||||
$renamed = $file->changeName(get('name'));
|
||||
$oldUrl = $file->panel()->url(true);
|
||||
$newUrl = $renamed->panel()->url(true);
|
||||
$response = [
|
||||
'event' => 'file.changeName',
|
||||
'dispatch' => [
|
||||
'content/move' => [
|
||||
$oldUrl,
|
||||
$newUrl
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
// check for a necessary redirect after the filename has changed
|
||||
if (Panel::referrer() === $oldUrl && $oldUrl !== $newUrl) {
|
||||
$response['redirect'] = $newUrl;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
],
|
||||
|
||||
'changeSort' => [
|
||||
'load' => function (string $path, string $filename) {
|
||||
$file = Find::file($path, $filename);
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'position' => Field::filePosition($file)
|
||||
],
|
||||
'submitButton' => t('change'),
|
||||
'value' => [
|
||||
'position' => $file->sort()->isEmpty() ? $file->siblings(false)->count() + 1 : $file->sort()->toInt(),
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $path, string $filename) {
|
||||
$file = Find::file($path, $filename);
|
||||
$files = $file->siblings()->sorted();
|
||||
$ids = $files->keys();
|
||||
$newIndex = (int)(get('position')) - 1;
|
||||
$oldIndex = $files->indexOf($file);
|
||||
|
||||
array_splice($ids, $oldIndex, 1);
|
||||
array_splice($ids, $newIndex, 0, $file->id());
|
||||
|
||||
$files->changeSort($ids);
|
||||
|
||||
return [
|
||||
'event' => 'file.sort',
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
'delete' => [
|
||||
'load' => function (string $path, string $filename) {
|
||||
$file = Find::file($path, $filename);
|
||||
return [
|
||||
'component' => 'k-remove-dialog',
|
||||
'props' => [
|
||||
'text' => tt('file.delete.confirm', [
|
||||
'filename' => Escape::html($file->filename())
|
||||
]),
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $path, string $filename) {
|
||||
$file = Find::file($path, $filename);
|
||||
$redirect = false;
|
||||
$referrer = Panel::referrer();
|
||||
$url = $file->panel()->url(true);
|
||||
|
||||
$file->delete();
|
||||
|
||||
// redirect to the parent model URL
|
||||
// if the dialog has been opened in the file view
|
||||
if ($referrer === $url) {
|
||||
$redirect = $file->parent()->panel()->url(true);
|
||||
}
|
||||
|
||||
return [
|
||||
'event' => 'file.delete',
|
||||
'dispatch' => ['content/remove' => [$url]],
|
||||
'redirect' => $redirect
|
||||
];
|
||||
}
|
||||
],
|
||||
];
|
9
kirby/config/areas/files/dropdowns.php
Normal file
9
kirby/config/areas/files/dropdowns.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Find;
|
||||
|
||||
return [
|
||||
'file' => function (string $parent, string $filename) {
|
||||
return Find::file($parent, $filename)->panel()->dropdown();
|
||||
}
|
||||
];
|
41
kirby/config/areas/installation.php
Normal file
41
kirby/config/areas/installation.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Panel\Panel;
|
||||
|
||||
return function ($kirby) {
|
||||
return [
|
||||
'icon' => 'settings',
|
||||
'label' => t('view.installation'),
|
||||
'views' => [
|
||||
'installation' => [
|
||||
'pattern' => 'installation',
|
||||
'auth' => false,
|
||||
'action' => function () use ($kirby) {
|
||||
$system = $kirby->system();
|
||||
return [
|
||||
'component' => 'k-installation-view',
|
||||
'props' => [
|
||||
'isInstallable' => $system->isInstallable(),
|
||||
'isInstalled' => $system->isInstalled(),
|
||||
'isOk' => $system->isOk(),
|
||||
'requirements' => $system->status(),
|
||||
'translations' => $kirby->translations()->values(function ($translation) {
|
||||
return [
|
||||
'text' => $translation->name(),
|
||||
'value' => $translation->code(),
|
||||
];
|
||||
}),
|
||||
]
|
||||
];
|
||||
}
|
||||
],
|
||||
'installation.fallback' => [
|
||||
'pattern' => '(:all)',
|
||||
'auth' => false,
|
||||
'action' => function () {
|
||||
Panel::go('installation');
|
||||
}
|
||||
]
|
||||
]
|
||||
];
|
||||
};
|
11
kirby/config/areas/languages.php
Normal file
11
kirby/config/areas/languages.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
return function ($kirby) {
|
||||
return [
|
||||
'icon' => 'globe',
|
||||
'label' => t('view.languages'),
|
||||
'menu' => true,
|
||||
'dialogs' => require __DIR__ . '/languages/dialogs.php',
|
||||
'views' => require __DIR__ . '/languages/views.php'
|
||||
];
|
||||
};
|
149
kirby/config/areas/languages/dialogs.php
Normal file
149
kirby/config/areas/languages/dialogs.php
Normal file
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Find;
|
||||
use Kirby\Panel\Field;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\Escape;
|
||||
|
||||
$languageDialogFields = [
|
||||
'name' => [
|
||||
'label' => t('language.name'),
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'icon' => 'title'
|
||||
],
|
||||
'code' => [
|
||||
'label' => t('language.code'),
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'counter' => false,
|
||||
'icon' => 'globe',
|
||||
'width' => '1/2'
|
||||
],
|
||||
'direction' => [
|
||||
'label' => t('language.direction'),
|
||||
'type' => 'select',
|
||||
'required' => true,
|
||||
'empty' => false,
|
||||
'options' => [
|
||||
['value' => 'ltr', 'text' => t('language.direction.ltr')],
|
||||
['value' => 'rtl', 'text' => t('language.direction.rtl')]
|
||||
],
|
||||
'width' => '1/2'
|
||||
],
|
||||
'locale' => [
|
||||
'label' => t('language.locale'),
|
||||
'type' => 'text',
|
||||
],
|
||||
];
|
||||
|
||||
return [
|
||||
|
||||
// create language
|
||||
'language.create' => [
|
||||
'pattern' => 'languages/create',
|
||||
'load' => function () use ($languageDialogFields) {
|
||||
return [
|
||||
'component' => 'k-language-dialog',
|
||||
'props' => [
|
||||
'fields' => $languageDialogFields,
|
||||
'submitButton' => t('language.create'),
|
||||
'value' => [
|
||||
'code' => '',
|
||||
'direction' => 'ltr',
|
||||
'locale' => '',
|
||||
'name' => '',
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function () {
|
||||
kirby()->languages()->create([
|
||||
'code' => get('code'),
|
||||
'direction' => get('direction'),
|
||||
'locale' => get('locale'),
|
||||
'name' => get('name'),
|
||||
]);
|
||||
return [
|
||||
'event' => 'language.create'
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// delete language
|
||||
'language.delete' => [
|
||||
'pattern' => 'languages/(:any)/delete',
|
||||
'load' => function (string $id) {
|
||||
$language = Find::language($id);
|
||||
return [
|
||||
'component' => 'k-remove-dialog',
|
||||
'props' => [
|
||||
'text' => tt('language.delete.confirm', [
|
||||
'name' => Escape::html($language->name())
|
||||
])
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
Find::language($id)->delete();
|
||||
return [
|
||||
'event' => 'language.delete',
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// update language
|
||||
'language.update' => [
|
||||
'pattern' => 'languages/(:any)/update',
|
||||
'load' => function (string $id) use ($languageDialogFields) {
|
||||
$language = Find::language($id);
|
||||
$fields = $languageDialogFields;
|
||||
$locale = $language->locale();
|
||||
|
||||
// use the first locale key if there's only one
|
||||
if (count($locale) === 1) {
|
||||
$locale = A::first($locale);
|
||||
}
|
||||
|
||||
// the code of an existing language cannot be changed
|
||||
$fields['code']['disabled'] = true;
|
||||
|
||||
// if the locale settings is more complex than just a
|
||||
// single string, the text field won't do it anymore.
|
||||
// Changes can only be made in the language file and
|
||||
// we display a warning box instead.
|
||||
if (is_array($locale) === true) {
|
||||
$fields['locale'] = [
|
||||
'label' => $fields['locale']['label'],
|
||||
'type' => 'info',
|
||||
'text' => t('language.locale.warning')
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'component' => 'k-language-dialog',
|
||||
'props' => [
|
||||
'fields' => $fields,
|
||||
'submitButton' => t('save'),
|
||||
'value' => [
|
||||
'code' => $language->code(),
|
||||
'direction' => $language->direction(),
|
||||
'locale' => $locale,
|
||||
'name' => $language->name(),
|
||||
'rules' => $language->rules(),
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
$language = Find::language($id)->update([
|
||||
'direction' => get('direction'),
|
||||
'locale' => get('locale'),
|
||||
'name' => get('name'),
|
||||
]);
|
||||
return [
|
||||
'event' => 'language.update'
|
||||
];
|
||||
}
|
||||
],
|
||||
];
|
26
kirby/config/areas/languages/views.php
Normal file
26
kirby/config/areas/languages/views.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Toolkit\Escape;
|
||||
|
||||
return [
|
||||
'languages' => [
|
||||
'pattern' => 'languages',
|
||||
'action' => function () {
|
||||
$kirby = kirby();
|
||||
|
||||
return [
|
||||
'component' => 'k-languages-view',
|
||||
'props' => [
|
||||
'languages' => $kirby->languages()->values(function ($language) {
|
||||
return [
|
||||
'default' => $language->isDefault(),
|
||||
'id' => $language->code(),
|
||||
'info' => Escape::html($language->code()),
|
||||
'text' => Escape::html($language->name()),
|
||||
];
|
||||
})
|
||||
]
|
||||
];
|
||||
}
|
||||
],
|
||||
];
|
43
kirby/config/areas/login.php
Normal file
43
kirby/config/areas/login.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Panel\Panel;
|
||||
|
||||
return function ($kirby) {
|
||||
return [
|
||||
'icon' => 'user',
|
||||
'label' => t('login'),
|
||||
'views' => [
|
||||
'login' => [
|
||||
'pattern' => 'login',
|
||||
'auth' => false,
|
||||
'action' => function () use ($kirby) {
|
||||
$system = $kirby->system();
|
||||
$status = $kirby->auth()->status();
|
||||
return [
|
||||
'component' => 'k-login-view',
|
||||
'props' => [
|
||||
'methods' => array_keys($system->loginMethods()),
|
||||
'pending' => [
|
||||
'email' => $status->email(),
|
||||
'challenge' => $status->challenge()
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
],
|
||||
'login.fallback' => [
|
||||
'pattern' => '(:all)',
|
||||
'auth' => false,
|
||||
'action' => function ($path) use ($kirby) {
|
||||
/**
|
||||
* Store the current path in the session
|
||||
* Once the user is logged in, the path will
|
||||
* be used to redirect to that view again
|
||||
*/
|
||||
$kirby->session()->set('panel.path', $path);
|
||||
Panel::go('login');
|
||||
}
|
||||
]
|
||||
]
|
||||
];
|
||||
};
|
17
kirby/config/areas/site.php
Normal file
17
kirby/config/areas/site.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
|
||||
return function ($kirby) {
|
||||
return [
|
||||
'breadcrumbLabel' => function () use ($kirby) {
|
||||
return $kirby->site()->title()->or(t('view.site'))->toString();
|
||||
},
|
||||
'icon' => 'home',
|
||||
'label' => $kirby->site()->blueprint()->title() ?? t('view.site'),
|
||||
'menu' => true,
|
||||
'dialogs' => require __DIR__ . '/site/dialogs.php',
|
||||
'dropdowns' => require __DIR__ . '/site/dropdowns.php',
|
||||
'searches' => require __DIR__ . '/site/searches.php',
|
||||
'views' => require __DIR__ . '/site/views.php',
|
||||
];
|
||||
};
|
547
kirby/config/areas/site/dialogs.php
Normal file
547
kirby/config/areas/site/dialogs.php
Normal file
|
@ -0,0 +1,547 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Find;
|
||||
use Kirby\Exception\Exception;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Exception\PermissionException;
|
||||
use Kirby\Panel\Field;
|
||||
use Kirby\Panel\Panel;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
$files = require __DIR__ . '/../files/dialogs.php';
|
||||
|
||||
return [
|
||||
|
||||
// change page position
|
||||
'page.changeSort' => [
|
||||
'pattern' => 'pages/(:any)/changeSort',
|
||||
'load' => function (string $id) {
|
||||
$page = Find::page($id);
|
||||
$position = null;
|
||||
|
||||
if ($page->blueprint()->num() !== 'default') {
|
||||
throw new PermissionException([
|
||||
'key' => 'page.sort.permission',
|
||||
'data' => [
|
||||
'slug' => $page->slug()
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'position' => Field::pagePosition($page),
|
||||
],
|
||||
'submitButton' => t('change'),
|
||||
'value' => [
|
||||
'position' => $page->panel()->position()
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
Find::page($id)->changeStatus('listed', get('position'));
|
||||
return [
|
||||
'event' => 'page.sort',
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change page status
|
||||
'page.changeStatus' => [
|
||||
'pattern' => 'pages/(:any)/changeStatus',
|
||||
'load' => function (string $id) {
|
||||
$page = Find::page($id);
|
||||
$blueprint = $page->blueprint();
|
||||
$status = $page->status();
|
||||
$states = [];
|
||||
$position = null;
|
||||
|
||||
foreach ($blueprint->status() as $key => $state) {
|
||||
$states[] = [
|
||||
'value' => $key,
|
||||
'text' => $state['label'],
|
||||
'info' => $state['text'],
|
||||
];
|
||||
}
|
||||
|
||||
if ($status === 'draft') {
|
||||
$errors = $page->errors();
|
||||
|
||||
// switch to the error dialog if there are
|
||||
// errors and the draft cannot be published
|
||||
if (count($errors) > 0) {
|
||||
return [
|
||||
'component' => 'k-error-dialog',
|
||||
'props' => [
|
||||
'message' => t('error.page.changeStatus.incomplete'),
|
||||
'details' => $errors,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$fields = [
|
||||
'status' => [
|
||||
'label' => t('page.changeStatus.select'),
|
||||
'type' => 'radio',
|
||||
'required' => true,
|
||||
'options' => $states
|
||||
]
|
||||
];
|
||||
|
||||
if ($blueprint->num() === 'default') {
|
||||
$fields['position'] = Field::pagePosition($page, [
|
||||
'when' => [
|
||||
'status' => 'listed'
|
||||
]
|
||||
]);
|
||||
|
||||
$position = $page->panel()->position();
|
||||
}
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => $fields,
|
||||
'submitButton' => t('change'),
|
||||
'value' => [
|
||||
'status' => $status,
|
||||
'position' => $position
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
Find::page($id)->changeStatus(get('status'), get('position'));
|
||||
return [
|
||||
'event' => 'page.changeStatus',
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change template
|
||||
'page.changeTemplate' => [
|
||||
'pattern' => 'pages/(:any)/changeTemplate',
|
||||
'load' => function (string $id) {
|
||||
$page = Find::page($id);
|
||||
$blueprints = $page->blueprints();
|
||||
|
||||
if (count($blueprints) <= 1) {
|
||||
throw new Exception([
|
||||
'key' => 'page.changeTemplate.invalid',
|
||||
'data' => [
|
||||
'slug' => $id
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'template' => Field::template($blueprints, [
|
||||
'required' => true
|
||||
])
|
||||
],
|
||||
'submitButton' => t('change'),
|
||||
'value' => [
|
||||
'template' => $page->intendedTemplate()->name()
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
Find::page($id)->changeTemplate(get('template'));
|
||||
return [
|
||||
'event' => 'page.changeTemplate',
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change title
|
||||
'page.changeTitle' => [
|
||||
'pattern' => 'pages/(:any)/changeTitle',
|
||||
'load' => function (string $id) {
|
||||
$page = Find::page($id);
|
||||
$permissions = $page->permissions();
|
||||
$select = get('select', 'title');
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'title' => Field::title([
|
||||
'required' => true,
|
||||
'preselect' => $select === 'title',
|
||||
'disabled' => $permissions->can('changeTitle') === false
|
||||
]),
|
||||
'slug' => Field::slug([
|
||||
'required' => true,
|
||||
'preselect' => $select === 'slug',
|
||||
'path' => $page->parent() ? '/' . $page->parent()->id() . '/' : '/',
|
||||
'disabled' => $permissions->can('changeSlug') === false,
|
||||
'wizard' => [
|
||||
'text' => t('page.changeSlug.fromTitle'),
|
||||
'field' => 'title'
|
||||
]
|
||||
])
|
||||
],
|
||||
'autofocus' => false,
|
||||
'submitButton' => t('change'),
|
||||
'value' => [
|
||||
'title' => $page->title()->value(),
|
||||
'slug' => $page->slug(),
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
$page = Find::page($id);
|
||||
$title = trim(get('title'));
|
||||
$slug = trim(get('slug'));
|
||||
|
||||
// basic input validation before we move on
|
||||
if (Str::length($title) === 0) {
|
||||
throw new InvalidArgumentException(['key' => 'page.changeTitle.empty']);
|
||||
}
|
||||
|
||||
if (Str::length($slug) === 0) {
|
||||
throw new InvalidArgumentException(['key' => 'page.slug.invalid']);
|
||||
}
|
||||
|
||||
// nothing changed
|
||||
if ($page->title()->value() === $title && $page->slug() === $slug) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// prepare the response
|
||||
$response = [
|
||||
'event' => []
|
||||
];
|
||||
|
||||
// the page title changed
|
||||
if ($page->title()->value() !== $title) {
|
||||
$page->changeTitle($title);
|
||||
$response['event'][] = 'page.changeTitle';
|
||||
}
|
||||
|
||||
// the slug changed
|
||||
if ($page->slug() !== $slug) {
|
||||
$newPage = $page->changeSlug($slug);
|
||||
$response['event'][] = 'page.changeSlug';
|
||||
$response['dispatch'] = [
|
||||
'content/move' => [
|
||||
$oldUrl = $page->panel()->url(true),
|
||||
$newUrl = $newPage->panel()->url(true)
|
||||
]
|
||||
];
|
||||
|
||||
// check for a necessary redirect after the slug has changed
|
||||
if (Panel::referrer() === $oldUrl && $oldUrl !== $newUrl) {
|
||||
$response['redirect'] = $newUrl;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
],
|
||||
|
||||
// create a new page
|
||||
'page.create' => [
|
||||
'pattern' => 'pages/create',
|
||||
'load' => function () {
|
||||
// the parent model for the new page
|
||||
$parent = get('parent', 'site');
|
||||
|
||||
// the view on which the add button is located
|
||||
// this is important to find the right section
|
||||
// and provide the correct templates for the new page
|
||||
$view = get('view', $parent);
|
||||
|
||||
// templates will be fetched depending on the
|
||||
// section settings in the blueprint
|
||||
$section = get('section');
|
||||
|
||||
// this is the parent model
|
||||
$model = Find::parent($parent);
|
||||
|
||||
// this is the view model
|
||||
// i.e. site if the add button is on
|
||||
// the dashboard
|
||||
$view = Find::parent($view);
|
||||
|
||||
// available blueprints/templates for the new page
|
||||
// are always loaded depending on the matching section
|
||||
// in the view model blueprint
|
||||
$blueprints = $view->blueprints($section);
|
||||
|
||||
// the pre-selected template
|
||||
$template = $blueprints[0]['name'] ?? $blueprints[0]['value'] ?? null;
|
||||
|
||||
$fields = [
|
||||
'parent' => Field::hidden(),
|
||||
'title' => Field::title([
|
||||
'required' => true,
|
||||
'preselect' => true
|
||||
]),
|
||||
'slug' => Field::slug([
|
||||
'required' => true,
|
||||
'sync' => 'title',
|
||||
'path' => empty($model->id()) === false ? '/' . $model->id() . '/' : '/'
|
||||
]),
|
||||
'template' => Field::hidden()
|
||||
];
|
||||
|
||||
// only show template field if > 1 templates available
|
||||
// or when in debug mode
|
||||
if (count($blueprints) > 1 || option('debug') === true) {
|
||||
$fields['template'] = Field::template($blueprints, [
|
||||
'required' => true
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => $fields,
|
||||
'submitButton' => t('page.draft.create'),
|
||||
'value' => [
|
||||
'parent' => $parent,
|
||||
'slug' => '',
|
||||
'template' => $template,
|
||||
'title' => '',
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function () {
|
||||
$title = trim(get('title'));
|
||||
|
||||
if (Str::length($title) === 0) {
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'page.changeTitle.empty'
|
||||
]);
|
||||
}
|
||||
|
||||
$page = Find::parent(get('parent', 'site'))->createChild([
|
||||
'content' => ['title' => $title],
|
||||
'slug' => get('slug'),
|
||||
'template' => get('template'),
|
||||
]);
|
||||
|
||||
return [
|
||||
'event' => 'page.create',
|
||||
'redirect' => $page->panel()->url(true)
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// delete page
|
||||
'page.delete' => [
|
||||
'pattern' => 'pages/(:any)/delete',
|
||||
'load' => function (string $id) {
|
||||
$page = Find::page($id);
|
||||
$text = tt('page.delete.confirm', [
|
||||
'title' => Escape::html($page->title()->value())
|
||||
]);
|
||||
|
||||
if ($page->childrenAndDrafts()->count() > 0) {
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'info' => [
|
||||
'type' => 'info',
|
||||
'theme' => 'negative',
|
||||
'text' => t('page.delete.confirm.subpages')
|
||||
],
|
||||
'check' => [
|
||||
'label' => t('page.delete.confirm.title'),
|
||||
'type' => 'text',
|
||||
'counter' => false
|
||||
]
|
||||
],
|
||||
'size' => 'medium',
|
||||
'submitButton' => t('delete'),
|
||||
'text' => $text,
|
||||
'theme' => 'negative',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'component' => 'k-remove-dialog',
|
||||
'props' => [
|
||||
'text' => $text
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
$page = Find::page($id);
|
||||
$redirect = false;
|
||||
$referrer = Panel::referrer();
|
||||
$url = $page->panel()->url(true);
|
||||
|
||||
if ($page->childrenAndDrafts()->count() > 0 && get('check') !== $page->title()->value()) {
|
||||
throw new InvalidArgumentException(['key' => 'page.delete.confirm']);
|
||||
}
|
||||
|
||||
$page->delete(true);
|
||||
|
||||
// redirect to the parent model URL
|
||||
// if the dialog has been opened in the page view
|
||||
if ($referrer === $url) {
|
||||
$redirect = $page->parentModel()->panel()->url(true);
|
||||
}
|
||||
|
||||
return [
|
||||
'event' => 'page.delete',
|
||||
'dispatch' => ['content/remove' => [$url]],
|
||||
'redirect' => $redirect
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// duplicate page
|
||||
'page.duplicate' => [
|
||||
'pattern' => 'pages/(:any)/duplicate',
|
||||
'load' => function (string $id) {
|
||||
$page = Find::page($id);
|
||||
$hasChildren = $page->hasChildren();
|
||||
$hasFiles = $page->hasFiles();
|
||||
$toggleWidth = '1/' . count(array_filter([$hasChildren, $hasFiles]));
|
||||
|
||||
$fields = [
|
||||
'title' => Field::title([
|
||||
'required' => true
|
||||
]),
|
||||
'slug' => Field::slug([
|
||||
'required' => true,
|
||||
'path' => $page->parent() ? '/' . $page->parent()->id() . '/' : '/',
|
||||
'wizard' => [
|
||||
'text' => t('page.changeSlug.fromTitle'),
|
||||
'field' => 'title'
|
||||
]
|
||||
])
|
||||
];
|
||||
|
||||
if ($hasFiles === true) {
|
||||
$fields['files'] = [
|
||||
'label' => t('page.duplicate.files'),
|
||||
'type' => 'toggle',
|
||||
'required' => true,
|
||||
'width' => $toggleWidth
|
||||
];
|
||||
}
|
||||
|
||||
if ($hasChildren === true) {
|
||||
$fields['children'] = [
|
||||
'label' => t('page.duplicate.pages'),
|
||||
'type' => 'toggle',
|
||||
'required' => true,
|
||||
'width' => $toggleWidth
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => $fields,
|
||||
'submitButton' => t('duplicate'),
|
||||
'value' => [
|
||||
'children' => false,
|
||||
'files' => false,
|
||||
'slug' => $page->slug() . '-' . Str::slug(t('page.duplicate.appendix')),
|
||||
'title' => $page->title() . ' ' . t('page.duplicate.appendix')
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
$newPage = Find::page($id)->duplicate(get('slug'), [
|
||||
'children' => (bool)get('children'),
|
||||
'files' => (bool)get('files'),
|
||||
'title' => (string)get('title'),
|
||||
]);
|
||||
|
||||
return [
|
||||
'event' => 'page.duplicate',
|
||||
'redirect' => $newPage->panel()->url(true)
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change filename
|
||||
'page.file.changeName' => [
|
||||
'pattern' => '(pages/.*?)/files/(:any)/changeName',
|
||||
'load' => $files['changeName']['load'],
|
||||
'submit' => $files['changeName']['submit'],
|
||||
],
|
||||
|
||||
// change sort
|
||||
'page.file.changeSort' => [
|
||||
'pattern' => '(pages/.*?)/files/(:any)/changeSort',
|
||||
'load' => $files['changeSort']['load'],
|
||||
'submit' => $files['changeSort']['submit'],
|
||||
],
|
||||
|
||||
// delete
|
||||
'page.file.delete' => [
|
||||
'pattern' => '(pages/.*?)/files/(:any)/delete',
|
||||
'load' => $files['delete']['load'],
|
||||
'submit' => $files['delete']['submit'],
|
||||
],
|
||||
|
||||
// change site title
|
||||
'site.changeTitle' => [
|
||||
'pattern' => 'site/changeTitle',
|
||||
'load' => function () {
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'title' => Field::title([
|
||||
'required' => true,
|
||||
'preselect' => true
|
||||
])
|
||||
],
|
||||
'submitButton' => t('rename'),
|
||||
'value' => [
|
||||
'title' => site()->title()->value()
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function () {
|
||||
site()->changeTitle(get('title'));
|
||||
return [
|
||||
'event' => 'site.changeTitle',
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change filename
|
||||
'site.file.changeName' => [
|
||||
'pattern' => '(site)/files/(:any)/changeName',
|
||||
'load' => $files['changeName']['load'],
|
||||
'submit' => $files['changeName']['submit'],
|
||||
],
|
||||
|
||||
// change sort
|
||||
'site.file.changeSort' => [
|
||||
'pattern' => '(site)/files/(:any)/changeSort',
|
||||
'load' => $files['changeSort']['load'],
|
||||
'submit' => $files['changeSort']['submit'],
|
||||
],
|
||||
|
||||
// delete
|
||||
'site.file.delete' => [
|
||||
'pattern' => '(site)/files/(:any)/delete',
|
||||
'load' => $files['delete']['load'],
|
||||
'submit' => $files['delete']['submit'],
|
||||
],
|
||||
|
||||
];
|
28
kirby/config/areas/site/dropdowns.php
Normal file
28
kirby/config/areas/site/dropdowns.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Panel\Dropdown;
|
||||
|
||||
$files = require __DIR__ . '/../files/dropdowns.php';
|
||||
|
||||
return [
|
||||
'changes' => [
|
||||
'pattern' => 'changes',
|
||||
'options' => function () {
|
||||
return Dropdown::changes();
|
||||
}
|
||||
],
|
||||
'page' => [
|
||||
'pattern' => 'pages/(:any)',
|
||||
'options' => function (string $path) {
|
||||
return Find::page($path)->panel()->dropdown();
|
||||
}
|
||||
],
|
||||
'page.file' => [
|
||||
'pattern' => '(pages/.*?)/files/(:any)',
|
||||
'options' => $files['file']
|
||||
],
|
||||
'site.file' => [
|
||||
'pattern' => '(site)/files/(:any)',
|
||||
'options' => $files['file']
|
||||
]
|
||||
];
|
55
kirby/config/areas/site/searches.php
Normal file
55
kirby/config/areas/site/searches.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Toolkit\Escape;
|
||||
|
||||
return [
|
||||
'pages' => [
|
||||
'label' => t('pages'),
|
||||
'icon' => 'page',
|
||||
'query' => function (string $query = null) {
|
||||
$pages = site()
|
||||
->index(true)
|
||||
->search($query)
|
||||
->filter('isReadable', true)
|
||||
->limit(10);
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach ($pages as $page) {
|
||||
$results[] = [
|
||||
'image' => $page->panel()->image(),
|
||||
'text' => Escape::html($page->title()->value()),
|
||||
'link' => $page->panel()->url(true),
|
||||
'info' => Escape::html($page->id())
|
||||
];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
],
|
||||
'files' => [
|
||||
'label' => t('files'),
|
||||
'icon' => 'image',
|
||||
'query' => function (string $query = null) {
|
||||
$files = site()
|
||||
->index(true)
|
||||
->filter('isReadable', true)
|
||||
->files()
|
||||
->search($query)
|
||||
->limit(10);
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$results[] = [
|
||||
'image' => $file->panel()->image(),
|
||||
'text' => Escape::html($file->filename()),
|
||||
'link' => $file->panel()->url(true),
|
||||
'info' => Escape::html($file->id())
|
||||
];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
]
|
||||
];
|
30
kirby/config/areas/site/views.php
Normal file
30
kirby/config/areas/site/views.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Find;
|
||||
|
||||
return [
|
||||
'page' => [
|
||||
'pattern' => 'pages/(:any)',
|
||||
'action' => function (string $path) {
|
||||
return Find::page($path)->panel()->view();
|
||||
}
|
||||
],
|
||||
'page.file' => [
|
||||
'pattern' => 'pages/(:any)/files/(:any)',
|
||||
'action' => function (string $id, string $filename) {
|
||||
return Find::file('pages/' . $id, $filename)->panel()->view();
|
||||
}
|
||||
],
|
||||
'site' => [
|
||||
'pattern' => 'site',
|
||||
'action' => function () {
|
||||
return site()->panel()->view();
|
||||
}
|
||||
],
|
||||
'site.file' => [
|
||||
'pattern' => 'site/files/(:any)',
|
||||
'action' => function (string $filename) {
|
||||
return Find::file('site', $filename)->panel()->view();
|
||||
}
|
||||
],
|
||||
];
|
11
kirby/config/areas/system.php
Normal file
11
kirby/config/areas/system.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
return function ($kirby) {
|
||||
return [
|
||||
'icon' => 'settings',
|
||||
'label' => t('view.system'),
|
||||
'menu' => true,
|
||||
'dialogs' => require __DIR__ . '/system/dialogs.php',
|
||||
'views' => require __DIR__ . '/system/views.php'
|
||||
];
|
||||
};
|
43
kirby/config/areas/system/dialogs.php
Normal file
43
kirby/config/areas/system/dialogs.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Panel\Field;
|
||||
|
||||
return [
|
||||
// license registration
|
||||
'registration' => [
|
||||
'load' => function () {
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'license' => [
|
||||
'label' => t('license.register.label'),
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'counter' => false,
|
||||
'placeholder' => 'K3-',
|
||||
'help' => t('license.register.help')
|
||||
],
|
||||
'email' => Field::email([
|
||||
'required' => true
|
||||
])
|
||||
],
|
||||
'submitButton' => t('license.register'),
|
||||
'value' => [
|
||||
'license' => null,
|
||||
'email' => null
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function () {
|
||||
// @codeCoverageIgnoreStart
|
||||
kirby()->system()->register(get('license'), get('email'));
|
||||
return [
|
||||
'event' => 'system.register',
|
||||
'message' => t('license.register.success')
|
||||
];
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
],
|
||||
];
|
46
kirby/config/areas/system/views.php
Normal file
46
kirby/config/areas/system/views.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
|
||||
return [
|
||||
'system' => [
|
||||
'pattern' => 'system',
|
||||
'action' => function () {
|
||||
$kirby = kirby();
|
||||
$system = $kirby->system();
|
||||
$license = $system->license();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($license === true) {
|
||||
// valid license, but user is not admin
|
||||
$license = 'Kirby 3';
|
||||
} elseif ($license === false) {
|
||||
// no valid license
|
||||
$license = null;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$plugins = $system->plugins()->values(function ($plugin) {
|
||||
return [
|
||||
'author' => $plugin->authorsNames(),
|
||||
'license' => $plugin->license(),
|
||||
'link' => $plugin->link(),
|
||||
'name' => $plugin->name(),
|
||||
'version' => $plugin->version(),
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
'component' => 'k-system-view',
|
||||
'props' => [
|
||||
'debug' => $kirby->option('debug', false),
|
||||
'license' => $license,
|
||||
'plugins' => $plugins,
|
||||
'php' => phpversion(),
|
||||
'server' => $system->serverSoftware(),
|
||||
'ssl' => Server::https(),
|
||||
'version' => $kirby->version(),
|
||||
]
|
||||
];
|
||||
}
|
||||
],
|
||||
];
|
14
kirby/config/areas/users.php
Normal file
14
kirby/config/areas/users.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
return function ($kirby) {
|
||||
return [
|
||||
'icon' => 'users',
|
||||
'label' => t('view.users'),
|
||||
'search' => 'users',
|
||||
'menu' => true,
|
||||
'dialogs' => require __DIR__ . '/users/dialogs.php',
|
||||
'dropdowns' => require __DIR__ . '/users/dropdowns.php',
|
||||
'searches' => require __DIR__ . '/users/searches.php',
|
||||
'views' => require __DIR__ . '/users/views.php'
|
||||
];
|
||||
};
|
295
kirby/config/areas/users/dialogs.php
Normal file
295
kirby/config/areas/users/dialogs.php
Normal file
|
@ -0,0 +1,295 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Find;
|
||||
use Kirby\Cms\UserRules;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Panel\Field;
|
||||
use Kirby\Panel\Panel;
|
||||
use Kirby\Toolkit\Escape;
|
||||
|
||||
$files = require __DIR__ . '/../files/dialogs.php';
|
||||
|
||||
return [
|
||||
|
||||
// create
|
||||
'user.create' => [
|
||||
'pattern' => 'users/create',
|
||||
'load' => function () {
|
||||
$kirby = kirby();
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'name' => Field::username(),
|
||||
'email' => Field::email([
|
||||
'link' => false,
|
||||
'required' => true
|
||||
]),
|
||||
'password' => Field::password(),
|
||||
'language' => Field::translation([
|
||||
'required' => true
|
||||
]),
|
||||
'role' => Field::role([
|
||||
'required' => true
|
||||
])
|
||||
],
|
||||
'submitButton' => t('create'),
|
||||
'value' => [
|
||||
'name' => '',
|
||||
'email' => '',
|
||||
'password' => '',
|
||||
'language' => $kirby->panelLanguage(),
|
||||
'role' => $kirby->user()->role()->name()
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function () {
|
||||
kirby()->users()->create([
|
||||
'name' => get('name'),
|
||||
'email' => get('email'),
|
||||
'password' => get('password'),
|
||||
'language' => get('language'),
|
||||
'role' => get('role')
|
||||
]);
|
||||
return [
|
||||
'event' => 'user.create'
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change email
|
||||
'user.changeEmail' => [
|
||||
'pattern' => 'users/(:any)/changeEmail',
|
||||
'load' => function (string $id) {
|
||||
$user = Find::user($id);
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'email' => [
|
||||
'label' => t('email'),
|
||||
'required' => true,
|
||||
'type' => 'email',
|
||||
'preselect' => true
|
||||
]
|
||||
],
|
||||
'submitButton' => t('change'),
|
||||
'value' => [
|
||||
'email' => $user->email()
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
Find::user($id)->changeEmail(get('email'));
|
||||
return [
|
||||
'event' => 'user.changeEmail'
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change language
|
||||
'user.changeLanguage' => [
|
||||
'pattern' => 'users/(:any)/changeLanguage',
|
||||
'load' => function (string $id) {
|
||||
$user = Find::user($id);
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'translation' => Field::translation(['required' => true])
|
||||
],
|
||||
'submitButton' => t('change'),
|
||||
'value' => [
|
||||
'translation' => $user->language()
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
Find::user($id)->changeLanguage(get('translation'));
|
||||
|
||||
return [
|
||||
'event' => 'user.changeLanguage',
|
||||
'reload' => [
|
||||
'globals' => '$translation'
|
||||
]
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change name
|
||||
'user.changeName' => [
|
||||
'pattern' => 'users/(:any)/changeName',
|
||||
'load' => function (string $id) {
|
||||
$user = Find::user($id);
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'name' => Field::username([
|
||||
'preselect' => true
|
||||
])
|
||||
],
|
||||
'submitButton' => t('rename'),
|
||||
'value' => [
|
||||
'name' => $user->name()->value()
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
Find::user($id)->changeName(get('name'));
|
||||
|
||||
return [
|
||||
'event' => 'user.changeName'
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change password
|
||||
'user.changePassword' => [
|
||||
'pattern' => 'users/(:any)/changePassword',
|
||||
'load' => function (string $id) {
|
||||
$user = Find::user($id);
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'password' => Field::password([
|
||||
'label' => t('user.changePassword.new'),
|
||||
]),
|
||||
'passwordConfirmation' => Field::password([
|
||||
'label' => t('user.changePassword.new.confirm'),
|
||||
])
|
||||
],
|
||||
'submitButton' => t('change'),
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
$user = Find::user($id);
|
||||
$password = get('password');
|
||||
$passwordConfirmation = get('passwordConfirmation');
|
||||
|
||||
// validate the password
|
||||
UserRules::validPassword($user, $password ?? '');
|
||||
|
||||
// compare passwords
|
||||
if ($password !== $passwordConfirmation) {
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'user.password.notSame'
|
||||
]);
|
||||
}
|
||||
|
||||
// change password if everything's fine
|
||||
$user->changePassword($password);
|
||||
|
||||
return [
|
||||
'event' => 'user.changePassword'
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change role
|
||||
'user.changeRole' => [
|
||||
'pattern' => 'users/(:any)/changeRole',
|
||||
'load' => function (string $id) {
|
||||
$user = Find::user($id);
|
||||
|
||||
return [
|
||||
'component' => 'k-form-dialog',
|
||||
'props' => [
|
||||
'fields' => [
|
||||
'role' => Field::role([
|
||||
'label' => t('user.changeRole.select'),
|
||||
'required' => true,
|
||||
])
|
||||
],
|
||||
'submitButton' => t('user.changeRole'),
|
||||
'value' => [
|
||||
'role' => $user->role()->name()
|
||||
]
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
$user = Find::user($id)->changeRole(get('role'));
|
||||
|
||||
return [
|
||||
'event' => 'user.changeRole',
|
||||
'user' => $user->toArray()
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// delete
|
||||
'user.delete' => [
|
||||
'pattern' => 'users/(:any)/delete',
|
||||
'load' => function (string $id) {
|
||||
$user = Find::user($id);
|
||||
$i18nPrefix = $user->isLoggedIn() ? 'account' : 'user';
|
||||
|
||||
return [
|
||||
'component' => 'k-remove-dialog',
|
||||
'props' => [
|
||||
'text' => tt($i18nPrefix . '.delete.confirm', [
|
||||
'email' => Escape::html($user->email())
|
||||
])
|
||||
]
|
||||
];
|
||||
},
|
||||
'submit' => function (string $id) {
|
||||
$user = Find::user($id);
|
||||
$redirect = false;
|
||||
$referrer = Panel::referrer();
|
||||
$url = $user->panel()->url(true);
|
||||
|
||||
$user->delete();
|
||||
|
||||
// redirect to the users view
|
||||
// if the dialog has been opened in the user view
|
||||
if ($referrer === $url) {
|
||||
$redirect = '/users';
|
||||
}
|
||||
|
||||
// logout the user if they deleted themselves
|
||||
if ($user->isLoggedIn()) {
|
||||
$redirect = '/logout';
|
||||
}
|
||||
|
||||
return [
|
||||
'event' => 'user.delete',
|
||||
'dispatch' => ['content/remove' => [$url]],
|
||||
'redirect' => $redirect
|
||||
];
|
||||
}
|
||||
],
|
||||
|
||||
// change file name
|
||||
'user.file.changeName' => [
|
||||
'pattern' => '(users/.*?)/files/(:any)/changeName',
|
||||
'load' => $files['changeName']['load'],
|
||||
'submit' => $files['changeName']['submit'],
|
||||
],
|
||||
|
||||
// change file sort
|
||||
'user.file.changeSort' => [
|
||||
'pattern' => '(users/.*?)/files/(:any)/changeSort',
|
||||
'load' => $files['changeSort']['load'],
|
||||
'submit' => $files['changeSort']['submit'],
|
||||
],
|
||||
|
||||
// delete file
|
||||
'user.file.delete' => [
|
||||
'pattern' => '(users/.*?)/files/(:any)/delete',
|
||||
'load' => $files['delete']['load'],
|
||||
'submit' => $files['delete']['submit'],
|
||||
]
|
||||
|
||||
];
|
18
kirby/config/areas/users/dropdowns.php
Normal file
18
kirby/config/areas/users/dropdowns.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Find;
|
||||
|
||||
$files = require __DIR__ . '/../files/dropdowns.php';
|
||||
|
||||
return [
|
||||
'user' => [
|
||||
'pattern' => 'users/(:any)',
|
||||
'options' => function (string $id) {
|
||||
return Find::user($id)->panel()->dropdown();
|
||||
}
|
||||
],
|
||||
'user.file' => [
|
||||
'pattern' => '(users/.*?)/files/(:any)',
|
||||
'options' => $files['file']
|
||||
]
|
||||
];
|
25
kirby/config/areas/users/searches.php
Normal file
25
kirby/config/areas/users/searches.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Toolkit\Escape;
|
||||
|
||||
return [
|
||||
'users' => [
|
||||
'label' => t('users'),
|
||||
'icon' => 'users',
|
||||
'query' => function (string $query = null) {
|
||||
$users = kirby()->users()->search($query)->limit(10);
|
||||
$results = [];
|
||||
|
||||
foreach ($users as $user) {
|
||||
$results[] = [
|
||||
'image' => $user->panel()->image(),
|
||||
'text' => Escape::html($user->username()),
|
||||
'link' => $user->panel()->url(true),
|
||||
'info' => Escape::html($user->role()->title())
|
||||
];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
]
|
||||
];
|
69
kirby/config/areas/users/views.php
Normal file
69
kirby/config/areas/users/views.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Find;
|
||||
use Kirby\Toolkit\Escape;
|
||||
|
||||
return [
|
||||
'users' => [
|
||||
'pattern' => 'users',
|
||||
'action' => function () {
|
||||
$kirby = kirby();
|
||||
$role = get('role');
|
||||
$roles = $kirby->roles()->toArray(function ($role) {
|
||||
return [
|
||||
'id' => $role->id(),
|
||||
'title' => $role->title(),
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
'component' => 'k-users-view',
|
||||
'props' => [
|
||||
'role' => function () use ($kirby, $roles, $role) {
|
||||
if ($role) {
|
||||
return $roles[$role] ?? null;
|
||||
}
|
||||
},
|
||||
'roles' => array_values($roles),
|
||||
'users' => function () use ($kirby, $role) {
|
||||
$users = $kirby->users();
|
||||
|
||||
if (empty($role) === false) {
|
||||
$users = $users->role($role);
|
||||
}
|
||||
|
||||
$users = $users->paginate([
|
||||
'limit' => 20,
|
||||
'page' => get('page')
|
||||
]);
|
||||
|
||||
return [
|
||||
'data' => $users->values(function ($user) {
|
||||
return [
|
||||
'id' => $user->id(),
|
||||
'image' => $user->panel()->image(),
|
||||
'info' => Escape::html($user->role()->title()),
|
||||
'link' => $user->panel()->url(true),
|
||||
'text' => Escape::html($user->username())
|
||||
];
|
||||
}),
|
||||
'pagination' => $users->pagination()->toArray()
|
||||
];
|
||||
},
|
||||
]
|
||||
];
|
||||
}
|
||||
],
|
||||
'user' => [
|
||||
'pattern' => 'users/(:any)',
|
||||
'action' => function (string $id) {
|
||||
return Find::user($id)->panel()->view();
|
||||
}
|
||||
],
|
||||
'user.file' => [
|
||||
'pattern' => 'users/(:any)/files/(:any)',
|
||||
'action' => function (string $id, string $filename) {
|
||||
return Find::file('users/' . $id, $filename)->panel()->view();
|
||||
}
|
||||
],
|
||||
];
|
Loading…
Add table
Add a link
Reference in a new issue