diff --git a/site/plugins/admin/app/Controllers/EntriesController.php b/site/plugins/admin/app/Controllers/EntriesController.php index 2f9c0a9f..10e65c78 100644 --- a/site/plugins/admin/app/Controllers/EntriesController.php +++ b/site/plugins/admin/app/Controllers/EntriesController.php @@ -14,12 +14,12 @@ class EntriesController extends Controller protected function getEntriesQuery($entry) { if ($entry && $entry != '') { - $query = $entry; - } else { - $query = ''; - } + $query = $entry; + } else { + $query = ''; + } - return $query; + return $query; } public function index($request, $response, $args) @@ -34,8 +34,10 @@ class EntriesController extends Controller var_dump($id); - return $this->view->render($response, - 'plugins/admin/views/templates/content/entries/index.html', [ + return $this->view->render( + $response, + 'plugins/admin/views/templates/content/entries/index.html', + [ 'entries_list' => $this->entries->fetchAll($this->getEntriesQuery($request->getQueryParams()['id']), 'date', 'DESC'), 'entry_current' => $this->getEntriesQuery($request->getQueryParams()['id']), 'menu_item' => 'entries', @@ -56,7 +58,8 @@ class EntriesController extends Controller 'attributes' => ['class' => 'float-right btn'] ] ] - ]); + ] + ); } public function add($request, $response, $args) @@ -69,17 +72,19 @@ class EntriesController extends Controller // If there is any template file then go... if (count($_fieldsets) > 0) { foreach ($_fieldsets as $fieldset) { - if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'json') { - $fieldset_content = JsonParser::decode(Filesystem::read($fieldset['path'])); - if (isset($fieldset_content['sections']) && isset($fieldset_content['sections']['main']) && isset($fieldset_content['sections']['main']['fields'])) { - $fieldsets[$fieldset['basename']] = $fieldset_content['title']; - } - } + if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'json') { + $fieldset_content = JsonParser::decode(Filesystem::read($fieldset['path'])); + if (isset($fieldset_content['sections']) && isset($fieldset_content['sections']['main']) && isset($fieldset_content['sections']['main']['fields'])) { + $fieldsets[$fieldset['basename']] = $fieldset_content['title']; + } + } } } - return $this->view->render($response, - 'plugins/admin/views/templates/content/entries/add.html', [ + return $this->view->render( + $response, + 'plugins/admin/views/templates/content/entries/add.html', + [ 'entries_list' => $this->entries->fetchAll($this->getEntriesQuery($request->getQueryParams()['entry']), 'date', 'DESC'), 'menu_item' => 'entries', 'fieldsets' => $fieldsets, @@ -95,12 +100,12 @@ class EntriesController extends Controller 'attributes' => ['class' => 'navbar-item active'] ] ] - ]); + ] + ); } public function addProcess($request, $response, $args) { - $data = $request->getParsedBody(); // Set parent entry @@ -141,17 +146,14 @@ class EntriesController extends Controller // Predefine data values based on selected fieldset foreach ($fieldset['sections'] as $section) { - foreach ($section as $key => $field) { // Get values from default data if (isset($default_data[$key])) { - $_value = $default_data[$key]; // Get values from fieldsets predefined field values } elseif (isset($field['value'])) { - $_value = $field['value']; // or set empty value @@ -197,8 +199,10 @@ class EntriesController extends Controller } } - return $this->view->render($response, - 'plugins/admin/views/templates/content/entries/type.html', [ + return $this->view->render( + $response, + 'plugins/admin/views/templates/content/entries/type.html', + [ 'fieldset' => $entry['fieldset'], 'entry_name' => $this->getEntriesQuery($request->getQueryParams()['entry']), 'fieldsets' => $fieldsets, @@ -215,12 +219,12 @@ class EntriesController extends Controller 'attributes' => ['class' => 'navbar-item active'] ] ] - ]); + ] + ); } public function typeProcess($request, $response, $args) { - $data = []; $_data = $request->getParsedBody(); @@ -262,8 +266,10 @@ class EntriesController extends Controller } } - return $this->view->render($response, - 'plugins/admin/views/templates/content/entries/move.html', [ + return $this->view->render( + $response, + 'plugins/admin/views/templates/content/entries/move.html', + [ 'entry_path_current' => $entry_name, 'entries_list' => $entries_list, 'name_current' => Arr::last(explode("/", $entry_name)), @@ -281,12 +287,12 @@ class EntriesController extends Controller 'attributes' => ['class' => 'navbar-item active'] ] ] - ]); + ] + ); } public function moveProcess($request, $response, $args) { - $data = $request->getParsedBody(); if (!$this->entries->has($data['parent_entry'] . '/' . $data['name_current'])) { @@ -305,8 +311,10 @@ class EntriesController extends Controller public function rename($request, $response, $args) { - return $this->view->render($response, - 'plugins/admin/views/templates/content/entries/rename.html', [ + return $this->view->render( + $response, + 'plugins/admin/views/templates/content/entries/rename.html', + [ 'name_current' => Arr::last(explode("/", $this->getEntriesQuery($request->getQueryParams()['entry']))), 'entry_path_current' => $this->getEntriesQuery($request->getQueryParams()['entry']), 'entry_parent' => implode('/', array_slice(explode("/", $this->getEntriesQuery($request->getQueryParams()['entry'])), 0, -1)), @@ -323,7 +331,8 @@ class EntriesController extends Controller 'attributes' => ['class' => 'navbar-item active'] ] ] - ]); + ] + ); } public function renameProcess($request, $response, $args) @@ -378,8 +387,10 @@ class EntriesController extends Controller $fieldset = JsonParser::decode(Filesystem::read($fieldset_path)); is_null($fieldset) and $fieldset = []; - return $this->view->render($response, - 'plugins/admin/views/templates/content/entries/edit.html', [ + return $this->view->render( + $response, + 'plugins/admin/views/templates/content/entries/edit.html', + [ 'entry_name' => $entry_name, 'entry_body' => $entry, 'fieldset' => $fieldset, @@ -403,7 +414,8 @@ class EntriesController extends Controller 'attributes' => ['class' => 'navbar-item'] ], ] - ]); + ] + ); } public function getMediaList(string $entry, bool $path = false) : array diff --git a/site/plugins/admin/app/Controllers/FieldsetsController.php b/site/plugins/admin/app/Controllers/FieldsetsController.php index 6549b9a4..fc213c54 100644 --- a/site/plugins/admin/app/Controllers/FieldsetsController.php +++ b/site/plugins/admin/app/Controllers/FieldsetsController.php @@ -8,10 +8,12 @@ use function Flextype\Component\I18n\__; class FieldsetsController extends Controller { - public function index($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/fieldsets/index.html', [ + public function index($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/fieldsets/index.html', + [ 'menu_item' => 'fieldsets', 'fieldsets_list' => $this->fieldsets->fetchList(), 'links' => [ @@ -28,13 +30,16 @@ class FieldsetsController extends Controller 'attributes' => ['class' => 'float-right btn'] ] ] - ]); - } + ] + ); + } - public function add($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/fieldsets/add.html', [ + public function add($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/fieldsets/add.html', + [ 'menu_item' => 'fieldsets', 'fieldsets_list' => $this->fieldsets->fetchList(), 'links' => [ @@ -51,11 +56,12 @@ class FieldsetsController extends Controller 'attributes' => ['class' => 'float-right btn'] ] ] - ]); - } + ] + ); + } - public function addProcess($request, $response, $args) - { + public function addProcess($request, $response, $args) + { $data = $request->getParsedBody(); Arr::delete($data, 'csrf_name'); @@ -71,12 +77,14 @@ class FieldsetsController extends Controller } return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); - } + } - public function edit($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/fieldsets/edit.html', [ + public function edit($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/fieldsets/edit.html', + [ 'menu_item' => 'fieldsets', 'id' => $request->getQueryParams()['id'], 'data' => JsonParser::encode($this->fieldsets->fetch($request->getQueryParams()['id'])), @@ -94,24 +102,27 @@ class FieldsetsController extends Controller 'attributes' => ['class' => 'js-save-form-submit float-right btn'] ], ] - ]); - } + ] + ); + } - public function editProcess($request, $response, $args) - { - if ($this->fieldsets->update($request->getParsedBody()['id'], JsonParser::decode($request->getParsedBody()['data']))) { - $this->flash->addMessage('success', __('admin_message_fieldsets_saved')); - } else { - $this->flash->addMessage('error', __('admin_message_fieldsets_was_not_saved')); - } + public function editProcess($request, $response, $args) + { + if ($this->fieldsets->update($request->getParsedBody()['id'], JsonParser::decode($request->getParsedBody()['data']))) { + $this->flash->addMessage('success', __('admin_message_fieldsets_saved')); + } else { + $this->flash->addMessage('error', __('admin_message_fieldsets_was_not_saved')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); + } - public function rename($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/fieldsets/rename.html', [ + public function rename($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/fieldsets/rename.html', + [ 'menu_item' => 'fieldsets', 'id' => $request->getQueryParams()['id'], 'links' => [ @@ -126,39 +137,40 @@ class FieldsetsController extends Controller 'attributes' => ['class' => 'navbar-item active'] ], ], - ]); - } + ] + ); + } - public function renameProcess($request, $response, $args) - { - if ($this->fieldsets->rename($request->getParsedBody()['fieldset-id-current'], $request->getParsedBody()['id'])) { - $this->flash->addMessage('success', __('admin_message_fieldset_renamed')); - } else { - $this->flash->addMessage('error', __('admin_message_fieldset_was_not_renamed')); - } + public function renameProcess($request, $response, $args) + { + if ($this->fieldsets->rename($request->getParsedBody()['fieldset-id-current'], $request->getParsedBody()['id'])) { + $this->flash->addMessage('success', __('admin_message_fieldset_renamed')); + } else { + $this->flash->addMessage('error', __('admin_message_fieldset_was_not_renamed')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); + } - public function deleteProcess($request, $response, $args) - { - if ($this->fieldsets->delete($request->getParsedBody()['fieldset-id'])) { - $this->flash->addMessage('success', __('admin_message_fieldset_deleted')); - } else { - $this->flash->addMessage('error', __('admin_message_fieldset_was_not_deleted')); - } + public function deleteProcess($request, $response, $args) + { + if ($this->fieldsets->delete($request->getParsedBody()['fieldset-id'])) { + $this->flash->addMessage('success', __('admin_message_fieldset_deleted')); + } else { + $this->flash->addMessage('error', __('admin_message_fieldset_was_not_deleted')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); + } - public function duplicateProcess($request, $response, $args) - { - if ($this->fieldsets->copy($request->getParsedBody()['fieldset-id'], $request->getParsedBody()['fieldset-id'] . '-duplicate-' . date("Ymd_His"))) { - $this->flash->addMessage('success', __('admin_message_fieldset_duplicated')); - } else { - $this->flash->addMessage('error', __('admin_message_fieldset_was_not_duplicated')); - } + public function duplicateProcess($request, $response, $args) + { + if ($this->fieldsets->copy($request->getParsedBody()['fieldset-id'], $request->getParsedBody()['fieldset-id'] . '-duplicate-' . date("Ymd_His"))) { + $this->flash->addMessage('success', __('admin_message_fieldset_duplicated')); + } else { + $this->flash->addMessage('error', __('admin_message_fieldset_was_not_duplicated')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); + } } diff --git a/site/plugins/admin/app/Controllers/InformationController.php b/site/plugins/admin/app/Controllers/InformationController.php index 8f545192..63f5ddd2 100644 --- a/site/plugins/admin/app/Controllers/InformationController.php +++ b/site/plugins/admin/app/Controllers/InformationController.php @@ -7,32 +7,34 @@ use function Flextype\Component\I18n\__; class InformationController extends Controller { - public function index($request, $response, $args) - { - if (function_exists('apache_get_modules')) { - if (!in_array('mod_rewrite', apache_get_modules())) { - $apache_mod_rewrite_installed = false; - } else { - $apache_mod_rewrite_installed = true; - } - } else { - $apache_mod_rewrite_installed = true; - } + public function index($request, $response, $args) + { + if (function_exists('apache_get_modules')) { + if (!in_array('mod_rewrite', apache_get_modules())) { + $apache_mod_rewrite_installed = false; + } else { + $apache_mod_rewrite_installed = true; + } + } else { + $apache_mod_rewrite_installed = true; + } - if (!function_exists('password_hash')) { - $password_hash_installed = false; - } else { - $password_hash_installed = true; - } + if (!function_exists('password_hash')) { + $password_hash_installed = false; + } else { + $password_hash_installed = true; + } - if (!function_exists('password_verify')) { - $password_verify_installed = false; - } else { - $password_verify_installed = true; - } + if (!function_exists('password_verify')) { + $password_verify_installed = false; + } else { + $password_verify_installed = true; + } - return $this->view->render($response, - 'plugins/admin/views/templates/system/information/index.html', [ + return $this->view->render( + $response, + 'plugins/admin/views/templates/system/information/index.html', + [ 'menu_item' => 'information', 'php_uname' => php_uname(), 'webserver' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : @getenv('SERVER_SOFTWARE'), @@ -47,6 +49,7 @@ class InformationController extends Controller 'attributes' => ['class' => 'navbar-item active'] ], ] - ]); - } + ] + ); + } } diff --git a/site/plugins/admin/app/Controllers/PluginsController.php b/site/plugins/admin/app/Controllers/PluginsController.php index 5b2b55f8..15d63428 100644 --- a/site/plugins/admin/app/Controllers/PluginsController.php +++ b/site/plugins/admin/app/Controllers/PluginsController.php @@ -12,8 +12,10 @@ class PluginsController extends Controller { public function index($request, $response, $args) { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/plugins/index.html', [ + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/plugins/index.html', + [ 'plugins_list' => $this->registry->get('plugins'), 'menu_item' => 'plugins', 'links' => [ @@ -30,7 +32,8 @@ class PluginsController extends Controller 'attributes' => ['float-right btn' => 'navbar-item', 'target' => '_blank'] ], ] - ]); + ] + ); } public function pluginStatusProcess($request, $response, $args) @@ -41,5 +44,4 @@ class PluginsController extends Controller Filesystem::write(PATH['plugins'] . '/' . $data['plugin'] . '/' . 'settings.json', JsonParser::encode($plugin_settings)); $this->cache->clear(); } - } diff --git a/site/plugins/admin/app/Controllers/SettingsController.php b/site/plugins/admin/app/Controllers/SettingsController.php index cd89b27d..39939c7e 100644 --- a/site/plugins/admin/app/Controllers/SettingsController.php +++ b/site/plugins/admin/app/Controllers/SettingsController.php @@ -12,29 +12,28 @@ class SettingsController extends Controller { public function index($request, $response, $args) { + $entries = []; + foreach ($this->entries->fetchAll('', 'date', 'DESC') as $entry) { + $entries[$entry['slug']] = $entry['title']; + } - $entries = []; - foreach ($this->entries->fetchAll('', 'date', 'DESC') as $entry) { - $entries[$entry['slug']] = $entry['title']; - } + $themes = []; + foreach (Filesystem::listContents(PATH['themes']) as $theme) { + if ($theme['type'] == 'dir' && Filesystem::has($theme['path'] . '/' . $theme['dirname'] . '.json')) { + $themes[$theme['dirname']] = $theme['dirname']; + } + } - $themes = []; - foreach (Filesystem::listContents(PATH['themes']) as $theme) { - if ($theme['type'] == 'dir' && Filesystem::has($theme['path'] . '/' . $theme['dirname'] . '.json')) { - $themes[$theme['dirname']] = $theme['dirname']; - } - } + $available_locales = Filesystem::listContents(PATH['plugins'] . '/admin/languages/'); + $system_locales = $this->plugins->getLocales(); + $locales = []; + foreach ($available_locales as $locale) { + if ($locale['type'] == 'file' && $locale['extension'] == 'json') { + $locales[$locale['basename']] = $system_locales[$locale['basename']]['nativeName']; + } + } - $available_locales = Filesystem::listContents(PATH['plugins'] . '/admin/languages/'); - $system_locales = $this->plugins->getLocales(); - $locales = []; - foreach ($available_locales as $locale) { - if ($locale['type'] == 'file' && $locale['extension'] == 'json') { - $locales[$locale['basename']] = $system_locales[$locale['basename']]['nativeName']; - } - } - - $cache_driver = ['auto' => 'Auto Detect', + $cache_driver = ['auto' => 'Auto Detect', 'file' => 'File', 'apcu' => 'APCu', 'wincache' => 'WinCache', @@ -44,8 +43,10 @@ class SettingsController extends Controller 'zend' => 'Zend', 'array' => 'Array']; - return $this->view->render($response, - 'plugins/admin/views/templates/system/settings/index.html', [ + return $this->view->render( + $response, + 'plugins/admin/views/templates/system/settings/index.html', + [ 'timezones' => Date::timezones(), 'settings' => $this->registry->get('settings'), 'cache_driver' => $cache_driver, @@ -73,12 +74,12 @@ class SettingsController extends Controller 'attributes' => ['class' => 'float-right btn'] ] ] - ]); + ] + ); } public function update($request, $response, $args) { - $data = $request->getParsedBody(); Arr::delete($data, 'csrf_name'); diff --git a/site/plugins/admin/app/Controllers/SnippetsController.php b/site/plugins/admin/app/Controllers/SnippetsController.php index 2e2ba889..c2de31c6 100644 --- a/site/plugins/admin/app/Controllers/SnippetsController.php +++ b/site/plugins/admin/app/Controllers/SnippetsController.php @@ -8,10 +8,12 @@ use function Flextype\Component\I18n\__; class SnippetsController extends Controller { - public function index($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/snippets/index.html', [ + public function index($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/snippets/index.html', + [ 'menu_item' => 'snippets', 'snippets_list' => $this->snippets->fetchList(), 'links' => [ @@ -28,13 +30,16 @@ class SnippetsController extends Controller 'attributes' => ['class' => 'float-right btn'] ], ] - ]); - } + ] + ); + } - public function add($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/snippets/add.html', [ + public function add($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/snippets/add.html', + [ 'menu_item' => 'snippets', 'links' => [ 'snippets' => [ @@ -43,24 +48,27 @@ class SnippetsController extends Controller 'attributes' => ['class' => 'navbar-item active'] ], ] - ]); - } + ] + ); + } - public function addProcess($request, $response, $args) - { - if ($this->snippets->create($request->getParsedBody()['id'], "")) { - $this->flash->addMessage('success', __('admin_message_snippet_created')); - } else { - $this->flash->addMessage('error', __('admin_message_snippet_was_not_created')); - } + public function addProcess($request, $response, $args) + { + if ($this->snippets->create($request->getParsedBody()['id'], "")) { + $this->flash->addMessage('success', __('admin_message_snippet_created')); + } else { + $this->flash->addMessage('error', __('admin_message_snippet_was_not_created')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.snippets.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.snippets.index')); + } - public function edit($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/snippets/edit.html', [ + public function edit($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/snippets/edit.html', + [ 'menu_item' => 'snippets', 'id' => $request->getQueryParams()['id'], 'data' => $this->snippets->fetch($request->getQueryParams()['id']), @@ -78,24 +86,27 @@ class SnippetsController extends Controller 'attributes' => ['class' => 'js-save-form-submit float-right btn'] ] ] - ]); - } + ] + ); + } - public function editProcess($request, $response, $args) - { - if ($this->snippets->update($request->getParsedBody()['id'], $request->getParsedBody()['data'])) { - $this->flash->addMessage('success', __('admin_message_snippets_saved')); - } else { - $this->flash->addMessage('error', __('admin_message_snippets_was_not_saved')); - } + public function editProcess($request, $response, $args) + { + if ($this->snippets->update($request->getParsedBody()['id'], $request->getParsedBody()['data'])) { + $this->flash->addMessage('success', __('admin_message_snippets_saved')); + } else { + $this->flash->addMessage('error', __('admin_message_snippets_was_not_saved')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.snippets.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.snippets.index')); + } - public function rename($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/snippets/rename.html', [ + public function rename($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/snippets/rename.html', + [ 'menu_item' => 'snippets', 'id_current' => $request->getQueryParams()['id'], 'links' => [ @@ -105,42 +116,44 @@ class SnippetsController extends Controller 'attributes' => ['class' => 'navbar-item active'] ], ] - ]); - } + ] + ); + } - public function renameProcess($request, $response, $args) - { - if ($this->snippets->rename( - $request->getParsedBody()['id_current'], - $request->getParsedBody()['id']) + public function renameProcess($request, $response, $args) + { + if ($this->snippets->rename( + $request->getParsedBody()['id_current'], + $request->getParsedBody()['id'] + ) ) { - $this->flash->addMessage('success', __('admin_message_snippets_renamed')); - } else { + $this->flash->addMessage('success', __('admin_message_snippets_renamed')); + } else { $this->flash->addMessage('error', __('admin_message_snippets_was_not_renamed')); - } + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.snippets.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.snippets.index')); + } - public function deleteProcess($request, $response, $args) - { - if ($this->snippets->delete($request->getParsedBody()['snippet-id'])) { - $this->flash->addMessage('success', __('admin_message_snippets_deleted')); - } else { - $this->flash->addMessage('error', __('admin_message_snippets_was_not_deleted')); - } + public function deleteProcess($request, $response, $args) + { + if ($this->snippets->delete($request->getParsedBody()['snippet-id'])) { + $this->flash->addMessage('success', __('admin_message_snippets_deleted')); + } else { + $this->flash->addMessage('error', __('admin_message_snippets_was_not_deleted')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.snippets.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.snippets.index')); + } - public function duplicateProcess($request, $response, $args) - { - if ($this->snippets->copy($request->getParsedBody()['snippet-id'], $request->getParsedBody()['snippet-id'] . '-duplicate-' . date("Ymd_His"))) { - $this->flash->addMessage('success', __('admin_message_snippets_duplicated')); - } else { - $this->flash->addMessage('error', __('admin_message_snippets_was_not_duplicated')); - } + public function duplicateProcess($request, $response, $args) + { + if ($this->snippets->copy($request->getParsedBody()['snippet-id'], $request->getParsedBody()['snippet-id'] . '-duplicate-' . date("Ymd_His"))) { + $this->flash->addMessage('success', __('admin_message_snippets_duplicated')); + } else { + $this->flash->addMessage('error', __('admin_message_snippets_was_not_duplicated')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.snippets.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.snippets.index')); + } } diff --git a/site/plugins/admin/app/Controllers/TemplatesController.php b/site/plugins/admin/app/Controllers/TemplatesController.php index da303756..b61200d0 100644 --- a/site/plugins/admin/app/Controllers/TemplatesController.php +++ b/site/plugins/admin/app/Controllers/TemplatesController.php @@ -8,10 +8,12 @@ use function Flextype\Component\I18n\__; class TemplatesController extends Controller { - public function index($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/templates/index.html', [ + public function index($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/templates/index.html', + [ 'menu_item' => 'templates', 'templates_list' => $this->themes->getTemplates(), 'partials_list' => $this->themes->getPartials(), @@ -29,13 +31,16 @@ class TemplatesController extends Controller 'attributes' => ['class' => 'float-right btn'] ], ] - ]); - } + ] + ); + } - public function add($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/templates/add.html', [ + public function add($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/templates/add.html', + [ 'menu_item' => 'templates', 'links' => [ 'templates' => [ @@ -44,51 +49,54 @@ class TemplatesController extends Controller 'attributes' => ['class' => 'navbar-item active'] ], ] - ]); - } + ] + ); + } - public function addProcess($request, $response, $args) - { - $type = $request->getParsedBody()['type']; + public function addProcess($request, $response, $args) + { + $type = $request->getParsedBody()['type']; - if ($type == 'partial') { - $_type = '/templates/partials/'; - } else { - $_type = '/templates/'; - } + if ($type == 'partial') { + $_type = '/templates/partials/'; + } else { + $_type = '/templates/'; + } - $id = Text::safeString($request->getParsedBody()['id'], '-', true) . '.html'; + $id = Text::safeString($request->getParsedBody()['id'], '-', true) . '.html'; - $file = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $id; + $file = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $id; - if (!Filesystem::has($file)) { - if (Filesystem::write( - $file, - "" + if (!Filesystem::has($file)) { + if (Filesystem::write( + $file, + "" )) { - $this->flash->addMessage('success', __('admin_message_'.$type.'_created')); - } else { - $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_created')); - } - } else { - $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_created')); - } + $this->flash->addMessage('success', __('admin_message_'.$type.'_created')); + } else { + $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_created')); + } + } else { + $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_created')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index')); + } - public function edit($request, $response, $args) - { - $type = $request->getQueryParams()['type']; + public function edit($request, $response, $args) + { + $type = $request->getQueryParams()['type']; - if ($type == 'partial') { - $_type = '/templates/partials/'; - } else { - $_type = '/templates/'; - } + if ($type == 'partial') { + $_type = '/templates/partials/'; + } else { + $_type = '/templates/'; + } - return $this->view->render($response, - 'plugins/admin/views/templates/extends/templates/edit.html', [ + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/templates/edit.html', + [ 'menu_item' => 'templates', 'id' => $request->getQueryParams()['id'], 'data' => Filesystem::read(PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getQueryParams()['id'] . '.html'), @@ -107,32 +115,35 @@ class TemplatesController extends Controller 'attributes' => ['class' => 'js-save-form-submit float-right btn'] ] ] - ]); - } + ] + ); + } - public function editProcess($request, $response, $args) - { - $type = $request->getParsedBody()['type_current']; + public function editProcess($request, $response, $args) + { + $type = $request->getParsedBody()['type_current']; - if ($type == 'partial') { - $_type = '/templates/partials/'; - } else { - $_type = '/templates/'; - } + if ($type == 'partial') { + $_type = '/templates/partials/'; + } else { + $_type = '/templates/'; + } - if (Filesystem::write( PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()['id'] . '.html', $request->getParsedBody()['data'])) { - $this->flash->addMessage('success', __('admin_message_'.$type.'_saved')); - } else { - $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_saved')); - } + if (Filesystem::write(PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()['id'] . '.html', $request->getParsedBody()['data'])) { + $this->flash->addMessage('success', __('admin_message_'.$type.'_saved')); + } else { + $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_saved')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.fieldsets.index')); + } - public function rename($request, $response, $args) - { - return $this->view->render($response, - 'plugins/admin/views/templates/extends/templates/rename.html', [ + public function rename($request, $response, $args) + { + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/templates/rename.html', + [ 'menu_item' => 'templates', 'types' => ['partial' => __('admin_partial'), 'template' => __('admin_template')], 'id_current' => $request->getQueryParams()['id'], @@ -144,75 +155,77 @@ class TemplatesController extends Controller 'attributes' => ['class' => 'navbar-item active'] ], ] - ]); - } + ] + ); + } - public function renameProcess($request, $response, $args) - { - $type = $request->getParsedBody()['type_current']; + public function renameProcess($request, $response, $args) + { + $type = $request->getParsedBody()['type_current']; - if ($type == 'partial') { - $_type = '/templates/partials/'; - } else { - $_type = '/templates/'; - } + if ($type == 'partial') { + $_type = '/templates/partials/'; + } else { + $_type = '/templates/'; + } - if (!Filesystem::has(PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()['id'] . '.html')) { - if (Filesystem::rename( + if (!Filesystem::has(PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()['id'] . '.html')) { + if (Filesystem::rename( PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()['id_current'] . '.html', - PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()['id'] . '.html') + PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()['id'] . '.html' + ) ) { - $this->flash->addMessage('success', __('admin_message_'.$type.'_renamed')); - } else { + $this->flash->addMessage('success', __('admin_message_'.$type.'_renamed')); + } else { $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_renamed')); - } - } else { - $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_renamed')); - } + } + } else { + $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_renamed')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index')); + } - public function deleteProcess($request, $response, $args) - { - $type = $request->getParsedBody()['type']; + public function deleteProcess($request, $response, $args) + { + $type = $request->getParsedBody()['type']; - if ($type == 'partial') { - $_type = '/templates/partials/'; - } else { - $_type = '/templates/'; - } + if ($type == 'partial') { + $_type = '/templates/partials/'; + } else { + $_type = '/templates/'; + } - $file_path = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '.html'; + $file_path = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '.html'; - if (Filesystem::delete($file_path)) { - $this->flash->addMessage('success', __('admin_message_'.$type.'_deleted')); - } else { - $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_deleted')); - } + if (Filesystem::delete($file_path)) { + $this->flash->addMessage('success', __('admin_message_'.$type.'_deleted')); + } else { + $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_deleted')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index')); + } - public function duplicateProcess($request, $response, $args) - { - $type = $request->getParsedBody()['type']; + public function duplicateProcess($request, $response, $args) + { + $type = $request->getParsedBody()['type']; - if ($type == 'partial') { - $_type = '/templates/partials/'; - } else { - $_type = '/templates/'; - } + if ($type == 'partial') { + $_type = '/templates/partials/'; + } else { + $_type = '/templates/'; + } - $file_path = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '.html'; - $file_path_new = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '-duplicate-' . date("Ymd_His") . '.html'; + $file_path = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '.html'; + $file_path_new = PATH['themes'] . '/' . $this->registry->get('settings.theme') . $_type . $request->getParsedBody()[$type.'-id'] . '-duplicate-' . date("Ymd_His") . '.html'; - if (Filesystem::copy($file_path, $file_path_new)) { - $this->flash->addMessage('success', __('admin_message_'.$type.'_duplicated')); - } else { - $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_duplicated')); - } + if (Filesystem::copy($file_path, $file_path_new)) { + $this->flash->addMessage('success', __('admin_message_'.$type.'_duplicated')); + } else { + $this->flash->addMessage('error', __('admin_message_'.$type.'_was_not_duplicated')); + } - return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index')); - } + return $response->withRedirect($this->container->get('router')->pathFor('admin.templates.index')); + } } diff --git a/site/plugins/admin/app/Controllers/UsersConstroller.php b/site/plugins/admin/app/Controllers/UsersConstroller.php index fb0a55fa..3701943f 100644 --- a/site/plugins/admin/app/Controllers/UsersConstroller.php +++ b/site/plugins/admin/app/Controllers/UsersConstroller.php @@ -11,72 +11,77 @@ use Psr\Container\ContainerInterface; class UsersController extends Controller { - public function index($request, $response, $args) - { - - } + public function index($request, $response, $args) + { + } - public function login($request, $response, $args) - { - if (!Users::isLoggedIn()) { - return $this->container->get('view')->render($response, - 'plugins/admin/views/templates/users/login.html', [ - 'user_is_logged' => Users::isLoggedIn() - ]); - } else { - return $response->withRedirect($this->container->get('router')->urlFor('admin.users.registration')); - } - } - - public function loginProcess($request, $response, $args) - { - $data = $request->getParsedBody(); - - if (Filesystem::has($_user_file = PATH['site'] . '/accounts/' . $data['username'] . '.json')) { - $user_file = JsonParser::decode(Filesystem::read($_user_file)); - if (password_verify(trim($data['password']), $user_file['hashed_password'])) { - Session::set('username', $user_file['username']); - Session::set('role', $user_file['role']); - return $response->withRedirect('admin/entries'); - } else { - //Notification::set('error', __('admin_message_wrong_username_password')); - } - } else { - //Notification::set('error', __('admin_message_wrong_username_password')); - } - } - - public function registration($request, $response, $args) - { + public function login($request, $response, $args) + { if (!Users::isLoggedIn()) { - return $this->view->render($response, - 'plugins/admin/views/templates/users/registration.html'); + return $this->container->get('view')->render( + $response, + 'plugins/admin/views/templates/users/login.html', + [ + 'user_is_logged' => Users::isLoggedIn() + ] + ); + } else { + return $response->withRedirect($this->container->get('router')->urlFor('admin.users.registration')); + } + } + + public function loginProcess($request, $response, $args) + { + $data = $request->getParsedBody(); + + if (Filesystem::has($_user_file = PATH['site'] . '/accounts/' . $data['username'] . '.json')) { + $user_file = JsonParser::decode(Filesystem::read($_user_file)); + if (password_verify(trim($data['password']), $user_file['hashed_password'])) { + Session::set('username', $user_file['username']); + Session::set('role', $user_file['role']); + return $response->withRedirect('admin/entries'); + } else { + //Notification::set('error', __('admin_message_wrong_username_password')); + } + } else { + //Notification::set('error', __('admin_message_wrong_username_password')); + } + } + + public function registration($request, $response, $args) + { + if (!Users::isLoggedIn()) { + return $this->view->render( + $response, + 'plugins/admin/views/templates/users/registration.html' + ); } else { return $response->withRedirect($this->container->get('router')->urlFor('admin.entires.index')); } - } + } - public function registrationProcess($request, $response, $args) - { - $data = $request->getParsedBody(); + public function registrationProcess($request, $response, $args) + { + $data = $request->getParsedBody(); - if (!Filesystem::has($_user_file = PATH['site'] . '/accounts/' . Text::safeString($data['username']) . '.json')) { + if (!Filesystem::has($_user_file = PATH['site'] . '/accounts/' . Text::safeString($data['username']) . '.json')) { if (Filesystem::write( - PATH['site'] . '/accounts/' . $data['username'] . '.json', - JsonParser::encode(['username' => Text::safeString($data['username']), + PATH['site'] . '/accounts/' . $data['username'] . '.json', + JsonParser::encode(['username' => Text::safeString($data['username']), 'hashed_password' => password_hash($data['password'], PASSWORD_BCRYPT), 'email' => $data['email'], 'role' => 'admin', - 'state' => 'enabled']))) { - return $response->withRedirect($this->container->get('router')->urlFor('admin.entries.index')); - } else { - //return false; - } - } else { - //return false; - } - } + 'state' => 'enabled']) + )) { + return $response->withRedirect($this->container->get('router')->urlFor('admin.entries.index')); + } else { + //return false; + } + } else { + //return false; + } + } }