diff --git a/site/plugins/admin/classes/EntriesManager.php b/site/plugins/admin/classes/EntriesManager.php index c9ccea9f..2ed34249 100644 --- a/site/plugins/admin/classes/EntriesManager.php +++ b/site/plugins/admin/classes/EntriesManager.php @@ -39,15 +39,15 @@ class EntriesManager if (Token::check((Http::post('token')))) { $file = PATH['entries'] . '/' . Http::post('parent_entry') . '/' . Text::safeString(Http::post('slug'), '-', true) . '/entry.html'; - if (!Filesystem::fileExists($file)) { + if (!Filesystem::has($file)) { // Get fieldset - $fieldset = YamlParser::decode(Filesystem::getFileContent(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('fieldset') . '.yaml')); + $fieldset = YamlParser::decode(Filesystem::read(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('fieldset') . '.yaml')); // We need to check if template for current fieldset is exists // if template is not exist then default template will be used! $template_path = PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/templates/' . Http::post('fieldset') . '.php'; - if (Filesystem::fileExists($template_path)) { + if (Filesystem::has($template_path)) { $template = Http::post('fieldset'); } else { $template = 'default'; @@ -81,7 +81,7 @@ class EntriesManager Arr::delete($frontmatter, 'content'); // Create a entry! - if (Filesystem::setFileContent( + if (Filesystem::write( $file, '---'."\n". YamlParser::encode(array_replace_recursive($frontmatter, $_frontmatter)). @@ -115,8 +115,9 @@ class EntriesManager case 'duplicate': if (Http::get('entry') != '') { if (Token::check((Http::get('token')))) { - Filesystem::recursiveCopy(PATH['entries'] . '/' . Http::get('entry'), - PATH['entries'] . '/' . Http::get('entry') . '-duplicate-' . date("Ymd_His")); + Filesystem::copy(PATH['entries'] . '/' . Http::get('entry'), + PATH['entries'] . '/' . Http::get('entry') . '-duplicate-' . date("Ymd_His"), + true); Notification::set('success', __('admin_message_entry_duplicated')); Http::redirect(Http::getBaseUrl().'/admin/entries/?entry='.implode('/', array_slice(explode("/", Http::get('entry')), 0, -1))); } else { @@ -173,7 +174,7 @@ class EntriesManager Arr::delete($frontmatter, 'entry'); $frontmatter = YamlParser::encode(array_merge($entry, $frontmatter)); - if (Filesystem::setFileContent( + if (Filesystem::write( PATH['entries'] . '/' . Http::post('entry') . '/entry.html', '---'."\n". $frontmatter."\n". @@ -251,7 +252,7 @@ class EntriesManager if (isset($action) && $action == 'save-form') { if (Token::check((Http::post('token')))) { - Filesystem::setFileContent( + Filesystem::write( PATH['entries'] . '/' . Http::post('entry_name') . '/entry.html', Http::post('entry_content') ); @@ -262,7 +263,7 @@ class EntriesManager } } - $entry_content = Filesystem::getFileContent(PATH['entries'] . '/' . Http::get('entry') . '/entry.html'); + $entry_content = Filesystem::read(PATH['entries'] . '/' . Http::get('entry') . '/entry.html'); Themes::view('admin/views/templates/content/entries/source') ->assign('entry_name', Http::get('entry')) @@ -291,7 +292,7 @@ class EntriesManager $content = Http::post('content'); $content = (isset($content)) ? $indenter->indent($content) : ''; - Filesystem::setFileContent( + Filesystem::write( PATH['entries'] . '/' . Http::get('entry') . '/entry.html', '---'."\n". $frontmatter."\n". @@ -305,7 +306,7 @@ class EntriesManager // Fieldset for current entry template $fieldset_path = PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . (isset($entry['fieldset']) ? $entry['fieldset'] : 'default') . '.yaml'; - $fieldset = YamlParser::decode(Filesystem::getFileContent($fieldset_path)); + $fieldset = YamlParser::decode(Filesystem::read($fieldset_path)); is_null($fieldset) and $fieldset = []; Themes::view('admin/views/templates/content/entries/content') @@ -456,7 +457,7 @@ class EntriesManager if (Http::get('delete_file') != '') { if (Token::check((Http::get('token')))) { - Filesystem::deleteFile($files_directory . Http::get('delete_file')); + Filesystem::delete($files_directory . Http::get('delete_file')); Notification::set('success', __('admin_message_entry_file_deleted')); Http::redirect(Http::getBaseUrl().'/admin/entries/edit?entry='.Http::get('entry').'&media=true'); } else { diff --git a/site/plugins/admin/classes/FieldsetsManager.php b/site/plugins/admin/classes/FieldsetsManager.php index e7053ed1..b472713b 100644 --- a/site/plugins/admin/classes/FieldsetsManager.php +++ b/site/plugins/admin/classes/FieldsetsManager.php @@ -25,9 +25,9 @@ class FieldsetsManager $file = PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Text::safeString(Http::post('name'), '-', true) . '.yaml'; - if (!Filesystem::fileExists($file)) { + if (!Filesystem::has($file)) { // Create a fieldset! - if (Filesystem::setFileContent( + if (Filesystem::write( $file, YamlParser::encode([ 'title' => Http::post('title'), @@ -55,7 +55,7 @@ class FieldsetsManager case 'delete': if (Http::get('fieldset') != '') { if (Token::check((Http::get('token')))) { - Filesystem::deleteFile(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '.yaml'); + 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 { @@ -68,7 +68,7 @@ class FieldsetsManager if (isset($rename_fieldset)) { if (Token::check((Http::post('token')))) { - if (!Filesystem::fileExists(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('name') . '.yaml')) { + 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') @@ -105,7 +105,7 @@ class FieldsetsManager if (Token::check((Http::post('token')))) { // Save a fieldset! - if (Filesystem::setFileContent( + if (Filesystem::write( PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::post('name') . '.yaml', Http::post('fieldset') )) { @@ -118,7 +118,7 @@ class FieldsetsManager } Themes::view('admin/views/templates/extends/fieldsets/edit') - ->assign('fieldset', Filesystem::getFileContent(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '.yaml')) + ->assign('fieldset', Filesystem::read(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . Http::get('fieldset') . '.yaml')) ->display(); break; default: diff --git a/site/plugins/admin/classes/MenusManager.php b/site/plugins/admin/classes/MenusManager.php index 3e38c28b..b5d6b2cc 100644 --- a/site/plugins/admin/classes/MenusManager.php +++ b/site/plugins/admin/classes/MenusManager.php @@ -17,7 +17,7 @@ class MenusManager Registry::set('sidebar_menu_item', 'menus'); // Create directory for menus - !Filesystem::fileExists(PATH['menus']) and Filesystem::createDir(PATH['menus']); + !Filesystem::has(PATH['menus']) and Filesystem::createDir(PATH['menus']); switch (Http::getUriSegment(2)) { case 'add': @@ -28,9 +28,9 @@ class MenusManager $file = PATH['menus'] . '/' . Text::safeString(Http::post('name'), '-', true) . '.yaml'; - if (!Filesystem::fileExists($file)) { + if (!Filesystem::has($file)) { // Create a menu! - if (Filesystem::setFileContent( + if (Filesystem::write( $file, YamlParser::encode(['title' => Http::post('title')]) )) { @@ -49,7 +49,7 @@ class MenusManager case 'delete': if (Http::get('menu') != '') { if (Token::check((Http::get('token')))) { - Filesystem::deleteFile(PATH['menus'] . '/' . Http::get('menu') . '.yaml'); + Filesystem::delete(PATH['menus'] . '/' . Http::get('menu') . '.yaml'); Notification::set('success', __('admin_message_menu_deleted')); Http::redirect(Http::getBaseUrl() . '/admin/menus'); } else { @@ -62,7 +62,7 @@ class MenusManager if (isset($rename_menu)) { if (Token::check((Http::post('token')))) { - if (!Filesystem::fileExists(PATH['menus'] . '/' . Http::post('name') . '.yaml')) { + if (!Filesystem::has(PATH['menus'] . '/' . Http::post('name') . '.yaml')) { if (rename( PATH['menus'] . '/' . Http::post('name_current') . '.yaml', PATH['menus'] . '/' . Http::post('name') . '.yaml') @@ -99,7 +99,7 @@ class MenusManager if (Token::check((Http::post('token')))) { // Save a menu! - if (Filesystem::setFileContent( + if (Filesystem::write( PATH['menus'] . '/' . Http::post('name') . '.yaml', Http::post('menu') )) { @@ -112,7 +112,7 @@ class MenusManager } Themes::view('admin/views/templates/extends/menus/edit') - ->assign('menu', Filesystem::getFileContent(PATH['menus'] . '/' . Http::get('menu') . '.yaml')) + ->assign('menu', Filesystem::read(PATH['menus'] . '/' . Http::get('menu') . '.yaml')) ->display(); break; default: @@ -123,7 +123,7 @@ class MenusManager if (count($menus) > 0) { foreach ($menus as $menu) { - $menus_list[basename($menu, '.yaml')] = YamlParser::decode(Filesystem::getFileContent($menu)); + $menus_list[basename($menu, '.yaml')] = YamlParser::decode(Filesystem::read($menu)); } } diff --git a/site/plugins/admin/classes/PluginsManager.php b/site/plugins/admin/classes/PluginsManager.php index 5b070b08..23a0f37b 100644 --- a/site/plugins/admin/classes/PluginsManager.php +++ b/site/plugins/admin/classes/PluginsManager.php @@ -20,9 +20,9 @@ class PluginsManager { if (Http::post('plugin_change_status')) { if (Token::check((Http::post('token')))) { - $plugin_settings = YamlParser::decode(Filesystem::getFileContent(PATH['plugins'] . '/' . Http::post('plugin') . '/' . 'settings.yaml')); + $plugin_settings = YamlParser::decode(Filesystem::read(PATH['plugins'] . '/' . Http::post('plugin') . '/' . 'settings.yaml')); Arr::set($plugin_settings, 'enabled', (Http::post('status') == 'true' ? true : false)); - Filesystem::setFileContent(PATH['plugins'] . '/' . Http::post('plugin') . '/' . 'settings.yaml', YamlParser::encode($plugin_settings)); + Filesystem::write(PATH['plugins'] . '/' . Http::post('plugin') . '/' . 'settings.yaml', YamlParser::encode($plugin_settings)); Cache::clear(); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); diff --git a/site/plugins/admin/classes/SettingsManager.php b/site/plugins/admin/classes/SettingsManager.php index f117ab48..f2f93257 100644 --- a/site/plugins/admin/classes/SettingsManager.php +++ b/site/plugins/admin/classes/SettingsManager.php @@ -50,7 +50,7 @@ class SettingsManager Arr::set($settings, 'entries.media.upload_images_width', (int) Http::post('entries.media.upload_images_width')); Arr::set($settings, 'entries.media.upload_images_height', (int) Http::post('entries.media.upload_images_height')); - if (Filesystem::setFileContent(PATH['config']['site'] . '/settings.yaml', YamlParser::encode(array_merge(Registry::get('settings'), $settings)))) { + if (Filesystem::write(PATH['config']['site'] . '/settings.yaml', YamlParser::encode(array_merge(Registry::get('settings'), $settings)))) { Notification::set('success', __('admin_message_settings_saved')); Http::redirect(Http::getBaseUrl().'/admin/settings'); } @@ -59,13 +59,15 @@ class SettingsManager } } - $available_locales = Filesystem::getFilesList(PATH['plugins'] . '/admin/languages/', 'yaml'); + $available_locales = Filesystem::listContents(PATH['plugins'] . '/admin/languages/'); $system_locales = Plugins::getLocales(); $locales = []; foreach ($available_locales as $locale) { - $locales[basename($locale, '.yaml')] = $system_locales[basename($locale, '.yaml')]['nativeName']; + if ($locale['type'] == 'file' && $locale['extension'] == 'yaml') { + $locales[$locale['basename']] = $system_locales[$locale['basename']]['nativeName']; + } } $entries = []; @@ -76,8 +78,10 @@ class SettingsManager $themes = []; - foreach (Filesystem::getDirList(PATH['themes']) as $theme) { - $themes[$theme] = $theme; + foreach (Filesystem::listContents(PATH['themes']) as $theme) { + if ($theme['type'] == 'dir' && Filesystem::has($theme['path'] . '/' . $theme['dirname'] . '.yaml')) { + $themes[$theme['dirname']] = $theme['dirname']; + } } $cache_driver = ['auto' => 'Auto Detect', diff --git a/site/plugins/admin/classes/SnippetsManager.php b/site/plugins/admin/classes/SnippetsManager.php index cddc062a..1791cdc1 100644 --- a/site/plugins/admin/classes/SnippetsManager.php +++ b/site/plugins/admin/classes/SnippetsManager.php @@ -17,7 +17,7 @@ class SnippetsManager Registry::set('sidebar_menu_item', 'snippets'); // Create directory for logs - !Filesystem::fileExists(PATH['snippets']) and Filesystem::createDir(PATH['snippets']); + !Filesystem::has(PATH['snippets']) and Filesystem::createDir(PATH['snippets']); switch (Http::getUriSegment(2)) { case 'add': @@ -28,9 +28,9 @@ class SnippetsManager $file = PATH['snippets'] . '/' . Text::safeString(Http::post('name'), '-', true) . '.php'; - if (!Filesystem::fileExists($file)) { + if (!Filesystem::has($file)) { // Create a snippet! - if (Filesystem::setFileContent( + if (Filesystem::write( $file, "" )) { @@ -49,7 +49,7 @@ class SnippetsManager case 'delete': if (Http::get('snippet') != '') { if (Token::check((Http::get('token')))) { - Filesystem::deleteFile(PATH['snippets'] . '/' . Http::get('snippet') . '.php'); + Filesystem::delete(PATH['snippets'] . '/' . Http::get('snippet') . '.php'); Notification::set('success', __('admin_message_snippet_deleted')); Http::redirect(Http::getBaseUrl() . '/admin/snippets'); } else { @@ -62,7 +62,7 @@ class SnippetsManager if (isset($rename_snippet)) { if (Token::check((Http::post('token')))) { - if (!Filesystem::fileExists(PATH['snippets'] . '/' . Http::post('name') . '.php')) { + if (!Filesystem::has(PATH['snippets'] . '/' . Http::post('name') . '.php')) { if (rename( PATH['snippets'] . '/' . Http::post('name_current') . '.php', PATH['snippets'] . '/' . Http::post('name') . '.php') @@ -99,7 +99,7 @@ class SnippetsManager if (Token::check((Http::post('token')))) { // Save a snippet! - if (Filesystem::setFileContent( + if (Filesystem::write( PATH['snippets'] . '/' . Http::post('name') . '.php', Http::post('snippet') )) { @@ -112,14 +112,20 @@ class SnippetsManager } Themes::view('admin/views/templates/extends/snippets/edit') - ->assign('snippet', Filesystem::getFileContent(PATH['snippets'] . '/' . Http::get('snippet') . '.php')) + ->assign('snippet', Filesystem::read(PATH['snippets'] . '/' . Http::get('snippet') . '.php')) ->display(); break; default: - $snippets_list = Filesystem::getFilesList(PATH['snippets'], 'php'); + $snippets = []; + + foreach (Filesystem::listContents(PATH['snippets']) as $snippet) { + if ($snippet['type'] == 'file' && $snippet['extension'] == 'php') { + $snippets[$snippet['basename']] = $snippet['basename']; + } + } Themes::view('admin/views/templates/extends/snippets/list') - ->assign('snippets_list', $snippets_list) + ->assign('snippets_list', $snippets) ->display(); break; } diff --git a/site/plugins/admin/classes/TemplatesManager.php b/site/plugins/admin/classes/TemplatesManager.php index bb6970cc..c3b17ed0 100644 --- a/site/plugins/admin/classes/TemplatesManager.php +++ b/site/plugins/admin/classes/TemplatesManager.php @@ -27,9 +27,9 @@ class TemplatesManager $file = PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $type . 's' . '/' . Text::safeString(Http::post('name'), '-', true) . '.php'; - if (!Filesystem::fileExists($file)) { + if (!Filesystem::has($file)) { // Create a template! - if (Filesystem::setFileContent( + if (Filesystem::write( $file, "" )) { @@ -49,7 +49,7 @@ class TemplatesManager if (Http::get('template') != '') { if (Token::check((Http::get('token')))) { $type = (Http::get('type') && Http::get('type') == 'partial') ? 'partial' : 'template'; - Filesystem::deleteFile(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $type . 's' . '/' . Http::get('template') . '.php'); + Filesystem::delete(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $type . 's' . '/' . Http::get('template') . '.php'); Notification::set('success', __('admin_message_template_deleted')); Http::redirect(Http::getBaseUrl() . '/admin/templates'); } else { @@ -64,7 +64,7 @@ class TemplatesManager if (Token::check((Http::post('token')))) { $type = (Http::post('type') && Http::post('type') == 'partial') ? 'partial' : 'template'; $type_current = (Http::post('type_current') && Http::post('type_current') == 'partial') ? 'partial' : 'template'; - if (!Filesystem::fileExists(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $type . 's' . '/' . Http::post('name') . '.php')) { + if (!Filesystem::has(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $type . 's' . '/' . Http::post('name') . '.php')) { if (rename( PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $type_current . 's' . '/' . Http::post('name_current') . '.php', PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $type . 's' . '/' . Http::post('name') . '.php') @@ -105,7 +105,7 @@ class TemplatesManager $type = (Http::post('type') && Http::post('type') == 'partial') ? 'partial' : 'template'; // Save a template! - if (Filesystem::setFileContent( + if (Filesystem::write( PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $type . 's' . '/' . Http::post('name') . '.php', Http::post('template') )) { @@ -120,7 +120,7 @@ class TemplatesManager $type = (Http::get('type') && Http::get('type') == 'partial') ? 'partials' : 'templates'; Themes::view('admin/views/templates/extends/templates/edit') - ->assign('template', Filesystem::getFileContent(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $type . '/' . Http::get('template') . '.php')) + ->assign('template', Filesystem::read(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $type . '/' . Http::get('template') . '.php')) ->assign('type', ((Http::get('type') && Http::get('type') == 'partial') ? 'partial' : 'template')) ->display(); break; diff --git a/site/plugins/admin/classes/UsersManager.php b/site/plugins/admin/classes/UsersManager.php index 021d1311..7c3fd595 100644 --- a/site/plugins/admin/classes/UsersManager.php +++ b/site/plugins/admin/classes/UsersManager.php @@ -40,9 +40,9 @@ class UsersManager if (isset($registration)) { if (Token::check((Http::post('token')))) { - if (Filesystem::fileExists($_user_file = PATH['site'] . '/accounts/' . Text::safeString(Http::post('username')) . '.yaml')) { + if (Filesystem::has($_user_file = PATH['site'] . '/accounts/' . Text::safeString(Http::post('username')) . '.yaml')) { } else { - Filesystem::setFileContent( + Filesystem::write( PATH['site'] . '/accounts/' . Http::post('username') . '.yaml', YamlParser::encode(['username' => Text::safeString(Http::post('username')), 'hashed_password' => password_hash(trim(Http::post('password')), PASSWORD_BCRYPT), @@ -65,7 +65,7 @@ class UsersManager public static function isUsersExists() { // Get Users Profiles - $users = Filesystem::getFilesList(PATH['site'] . '/accounts/', 'yaml'); + $users = Filesystem::listContents(PATH['site'] . '/accounts/'); // If any users exists then return true return ($users && count($users) > 0) ? true : false; @@ -84,8 +84,8 @@ class UsersManager if (isset($login)) { if (Token::check((Http::post('token')))) { - if (Filesystem::fileExists($_user_file = PATH['site'] . '/accounts/' . Http::post('username') . '.yaml')) { - $user_file = YamlParser::decode(Filesystem::getFileContent($_user_file)); + if (Filesystem::has($_user_file = PATH['site'] . '/accounts/' . Http::post('username') . '.yaml')) { + $user_file = YamlParser::decode(Filesystem::read($_user_file)); if (password_verify(trim(Http::post('password')), $user_file['hashed_password'])) { Session::set('username', $user_file['username']); Session::set('role', $user_file['role']);