diff --git a/flextype/Cache.php b/flextype/Cache.php index e1049ae5..9664a24a 100755 --- a/flextype/Cache.php +++ b/flextype/Cache.php @@ -91,7 +91,7 @@ class Cache protected static function init() : void { // Create Cache Directory - !Filesystem::dirExists(PATH['cache']) and Filesystem::createDir(PATH['cache']); + !Filesystem::has(PATH['cache']) and Filesystem::createDir(PATH['cache']); // Set current time Cache::$now = time(); @@ -183,7 +183,7 @@ class Cache // http://php.net/manual/en/book.sqlite3.php case 'sqlite3': // Create doctrine cache directory if its not exists - !Filesystem::fileExists($cache_directory) and Filesystem::createDir($cache_directory); + !Filesystem::has($cache_directory) and Filesystem::createDir($cache_directory); $db = new \SQLite3($cache_directory . Registry::get('settings.cache.sqlite3.database', 'flextype') . '.db'); $driver = new DoctrineCache\SQLite3Cache($db, Registry::get('settings.cache.sqlite3.table', 'flextype')); @@ -218,7 +218,7 @@ class Cache break; default: // Create doctrine cache directory if its not exists - !Filesystem::fileExists($cache_directory) and Filesystem::createDir($cache_directory); + !Filesystem::has($cache_directory) and Filesystem::createDir($cache_directory); $driver = new DoctrineCache\FilesystemCache($cache_directory); break; } diff --git a/flextype/Entries.php b/flextype/Entries.php index 036dc660..4db50948 100755 --- a/flextype/Entries.php +++ b/flextype/Entries.php @@ -162,7 +162,7 @@ class Entries } // If entry exist - if (Filesystem::fileExists($file_path)) { + if (Filesystem::has($file_path)) { $entry_cache_id = md5('entry' . $file_path . filemtime($file_path) . (($raw === true) ? 'true' : 'false') . (($hidden === true) ? 'true' : 'false')); // Try to get the entry from cache @@ -233,19 +233,23 @@ class Entries if ($url === '') { // Get entries list - $entries_list = Filesystem::getFilesList($file_path, 'html', true, $multilevel); + $entries_list = Filesystem::listContents($file_path); // Create entries cached id - foreach ($entries_list as $key => $entry) { - $entry_cache_id .= md5('entries' . $entry . filemtime($entry) . (($raw === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length); + foreach ($entries_list as $entry) { + if ($entry['type'] == 'dir' && Filesystem::has($entry['path'] . '/entry.html')) { + $entry_cache_id .= md5('entries' . $entry['path'] . $entry['timestamp'] . (($raw === true) ? 'true' : 'false') . (($multilevel === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length); + } } if (Cache::contains($entry_cache_id)) { $entries = Cache::fetch($entry_cache_id); } else { // Create entries array from entries list - foreach ($entries_list as $key => $entry) { - $entries[$key] = Entries::processEntry($entry, $raw); + foreach ($entries_list as $entry) { + if ($entry['type'] == 'dir' && Filesystem::has($entry['path'] . '/entry.html')) { + $entries[$entry['dirname']] = Entries::processEntry($entry['path'] . '/entry.html', $raw); + } } Cache::save($entry_cache_id, $entries); @@ -253,14 +257,16 @@ class Entries } else { // Get entries list - $entries_list = Filesystem::getFilesList($file_path, 'html', true, $multilevel); + $entries_list = Filesystem::listContents($file_path); // Create entries cached id - foreach ($entries_list as $key => $entry) { - if (strpos($entry, $url . '/entry.html') !== false) { + foreach ($entries_list as $entry) { + if (strpos($entry['path'], $url . '/entry.html') !== false) { // ignore ... } else { - $entry_cache_id .= md5('entries' . $entry . filemtime($entry) . (($raw === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length); + if ($entry['type'] == 'dir' && Filesystem::has($entry['path'] . '/entry.html')) { + $entry_cache_id .= md5('entries' . $entry['path'] . $entry['timestamp'] . (($raw === true) ? 'true' : 'false') . $order_by . $order_type . $offset . $length); + } } } @@ -268,11 +274,13 @@ class Entries $entries = Cache::fetch($entry_cache_id); } else { // Create entries array from entries list and ignore current requested entry - foreach ($entries_list as $key => $entry) { - if (strpos($entry, $url . '/entry.html') !== false) { + foreach ($entries_list as $entry) { + if (strpos($entry['path'], $url . '/entry.html') !== false) { // ignore ... } else { - $entries[$key] = Entries::processEntry($entry, $raw); + if ($entry['type'] == 'dir' && Filesystem::has($entry['path'] . '/entry.html')) { + $entries[$entry['dirname']] = Entries::processEntry($entry['path'] . '/entry.html', $raw); + } } } @@ -326,7 +334,7 @@ class Entries public static function processEntry(string $file_path, bool $raw = false, bool $ignore_content = false) { // Get entry from file - $entry = trim(Filesystem::getFileContent($file_path)); + $entry = trim(Filesystem::read($file_path)); // Return raw entry if $raw is true if ($raw) { diff --git a/flextype/Flextype.php b/flextype/Flextype.php index c5ae892c..563524c0 100755 --- a/flextype/Flextype.php +++ b/flextype/Flextype.php @@ -129,7 +129,7 @@ class Flextype } // Create directory for logs - !Filesystem::fileExists(LOGS_PATH) and Filesystem::createDir(LOGS_PATH); + !Filesystem::has(LOGS_PATH) and Filesystem::createDir(LOGS_PATH); // Set Error handler set_error_handler('Flextype\Component\ErrorHandler\ErrorHandler::error'); @@ -152,11 +152,11 @@ class Flextype $site_settings_file_path = PATH['config']['site'] . '/settings.yaml'; // Set settings if Flextype settings and Site settings config files exist - if (Filesystem::fileExists($default_settings_file_path) && Filesystem::fileExists($site_settings_file_path)) { + if (Filesystem::has($default_settings_file_path) && Filesystem::has($site_settings_file_path)) { // Get Flextype settings and Site settings - $default_settings = YamlParser::decode(Filesystem::getFileContent($default_settings_file_path)); - $site_settings = YamlParser::decode(Filesystem::getFileContent($site_settings_file_path)); + $default_settings = YamlParser::decode(Filesystem::read($default_settings_file_path)); + $site_settings = YamlParser::decode(Filesystem::read($site_settings_file_path)); // Merge settings $settings = array_replace_recursive($default_settings, $site_settings); diff --git a/flextype/Menus.php b/flextype/Menus.php index b860574c..51e876fb 100644 --- a/flextype/Menus.php +++ b/flextype/Menus.php @@ -29,8 +29,8 @@ class Menus { $menu_path = PATH['menus'] . '/' . $menu_name . '.yaml'; - if (Filesystem::fileExists($menu_path)) { - return YamlParser::decode(Filesystem::getFileContent($menu_path)); + if (Filesystem::has($menu_path)) { + return YamlParser::decode(Filesystem::read($menu_path)); } else { throw new \RuntimeException("Menu {$menu_name} does not exist."); } diff --git a/flextype/Plugins.php b/flextype/Plugins.php index 04c2c64f..103552b8 100755 --- a/flextype/Plugins.php +++ b/flextype/Plugins.php @@ -236,15 +236,15 @@ class Plugins Registry::set('plugins', []); // Get Plugins List - $plugins_list = Filesystem::getDirList(PATH['plugins']); + $plugins_list = Filesystem::listContents(PATH['plugins']); // If Plugins List isnt empty then create plugin cache ID if (is_array($plugins_list) && count($plugins_list) > 0) { // Go through... foreach ($plugins_list as $plugin) { - if (Filesystem::fileExists($_plugin_settings = PATH['plugins'] . '/' . $plugin . '/settings.yaml') and - Filesystem::fileExists($_plugin_config = PATH['plugins'] . '/' . $plugin . '/'. $plugin .'.yaml')) { + if (Filesystem::has($_plugin_settings = PATH['plugins'] . '/' . $plugin['dirname'] . '/settings.yaml') and + Filesystem::has($_plugin_config = PATH['plugins'] . '/' . $plugin['dirname'] . '/'. $plugin['dirname'] .'.yaml')) { $_plugins_cache_id .= filemtime($_plugin_settings) . filemtime($_plugin_config); } } @@ -262,12 +262,12 @@ class Plugins // Go through... foreach ($plugins_list as $plugin) { - if (Filesystem::fileExists($_plugin_settings = PATH['plugins'] . '/' . $plugin . '/settings.yaml')) { - $plugin_settings = YamlParser::decode(Filesystem::getFileContent($_plugin_settings)); + if (Filesystem::has($_plugin_settings = PATH['plugins'] . '/' . $plugin['dirname'] . '/settings.yaml')) { + $plugin_settings = YamlParser::decode(Filesystem::read($_plugin_settings)); } - if (Filesystem::fileExists($_plugin_config = PATH['plugins'] . '/' . $plugin . '/'. $plugin. '.yaml')) { - $plugin_config = YamlParser::decode(Filesystem::getFileContent($_plugin_config)); + if (Filesystem::has($_plugin_config = PATH['plugins'] . '/' . $plugin['dirname'] . '/'. $plugin['dirname']. '.yaml')) { + $plugin_config = YamlParser::decode(Filesystem::read($_plugin_config)); } $_plugins_config[basename($_plugin_config, '.yaml')] = array_merge($plugin_settings, $plugin_config); @@ -282,9 +282,9 @@ class Plugins if (is_array($plugins_list) && count($plugins_list) > 0) { foreach (Plugins::$locales as $locale => $locale_title) { foreach ($plugins_list as $plugin) { - $language_file = PATH['plugins'] . '/' . $plugin . '/languages/' . $locale . '.yaml'; - if (Filesystem::fileExists($language_file)) { - I18n::add(YamlParser::decode(Filesystem::getFileContent($language_file)), $locale); + $language_file = PATH['plugins'] . '/' . $plugin['dirname'] . '/languages/' . $locale . '.yaml'; + if (Filesystem::has($language_file)) { + I18n::add(YamlParser::decode(Filesystem::read($language_file)), $locale); } } } diff --git a/flextype/Snippets.php b/flextype/Snippets.php index f78d974f..78dc5ebb 100644 --- a/flextype/Snippets.php +++ b/flextype/Snippets.php @@ -57,7 +57,7 @@ class Snippets $snippet_path = PATH['snippets'] . '/' . $name . '.php'; // Process snippet - if (Filesystem::fileExists($snippet_path)) { + if (Filesystem::has($snippet_path)) { // Turn on output buffering ob_start(); diff --git a/flextype/Themes.php b/flextype/Themes.php index f59414e1..3d8c0b23 100644 --- a/flextype/Themes.php +++ b/flextype/Themes.php @@ -81,10 +81,10 @@ class Themes if (Cache::contains($theme_cache_id)) { Registry::set('themes.'.Registry::get('settings.theme'), Cache::fetch($theme_cache_id)); } else { - if (Filesystem::fileExists($theme_settings = PATH['themes'] . '/' . $theme . '/' . 'settings.yaml') and - Filesystem::fileExists($theme_config = PATH['themes'] . '/' . $theme . '/' . $theme . '.yaml')) { - $theme_settings = YamlParser::decode(Filesystem::getFileContent($theme_settings)); - $theme_config = YamlParser::decode(Filesystem::getFileContent($theme_config)); + if (Filesystem::has($theme_settings = PATH['themes'] . '/' . $theme . '/' . 'settings.yaml') and + Filesystem::has($theme_config = PATH['themes'] . '/' . $theme . '/' . $theme . '.yaml')) { + $theme_settings = YamlParser::decode(Filesystem::read($theme_settings)); + $theme_config = YamlParser::decode(Filesystem::read($theme_config)); $_theme = array_merge($theme_settings, $theme_config); Registry::set('themes.'.Registry::get('settings.theme'), $_theme); Cache::save($theme_cache_id, $_theme); @@ -104,7 +104,7 @@ class Themes { // Set view file // From current theme folder or from plugin folder - if (Filesystem::fileExists(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $template . View::$view_ext)) { + if (Filesystem::has(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $template . View::$view_ext)) { $template = PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/' . $template; } else { $template = PATH['plugins'] . '/' . $template; @@ -124,15 +124,14 @@ class Themes { $partials = []; - // Get templates files - $_partials = Filesystem::getFilesList(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/partials/', 'php'); + // Get partials files + $_partials = Filesystem::listContents(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/partials/'); - // If there is any template file then go... + // If there is any partials file then go... if (count($_partials) > 0) { foreach ($_partials as $partial) { - if (!is_bool(Themes::_strrevpos($partial, '/partials' . DIRECTORY_SEPARATOR))) { - $partial_name = str_replace('.php', '', substr($partial, Themes::_strrevpos($partial, '/partials' . DIRECTORY_SEPARATOR)+strlen('/partials' . DIRECTORY_SEPARATOR))); - $partials[$partial_name] = $partial_name; + if ($partial['type'] == 'file' && $partial['extension'] == 'php') { + $partials[$partial['basename']] = $partial['basename']; } } } @@ -152,14 +151,13 @@ class Themes $templates = []; // Get templates files - $_templates = Filesystem::getFilesList(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/templates/', 'php'); + $_templates = Filesystem::listContents(PATH['themes'] . '/' . Registry::get('settings.theme') . '/views/templates/'); // If there is any template file then go... if (count($_templates) > 0) { foreach ($_templates as $template) { - if (!is_bool(Themes::_strrevpos($template, '/templates' . DIRECTORY_SEPARATOR))) { - $template_name = str_replace('.php', '', substr($template, Themes::_strrevpos($template, '/templates' . DIRECTORY_SEPARATOR)+strlen('/templates' . DIRECTORY_SEPARATOR))); - $templates[$template_name] = $template_name; + if ($template['type'] == 'file' && $template['extension'] == 'php') { + $templates[$template['basename']] = $template['basename']; } } } @@ -179,15 +177,14 @@ class Themes $fieldsets = []; // Get fieldsets files - $_fieldsets = Filesystem::getFilesList(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/', 'yaml'); + $_fieldsets = Filesystem::listContents(PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/'); // If there is any template file then go... if (count($_fieldsets) > 0) { foreach ($_fieldsets as $fieldset) { - if (!is_bool(Themes::_strrevpos($fieldset, '/fieldsets' . DIRECTORY_SEPARATOR))) { - $fieldset_name = str_replace('.yaml', '', substr($fieldset, Themes::_strrevpos($fieldset, '/fieldsets' . DIRECTORY_SEPARATOR)+strlen('/fieldsets' . DIRECTORY_SEPARATOR))); - $fieldset = YamlParser::decode(Filesystem::getFileContent($fieldset)); - $fieldsets[$fieldset_name] = $fieldset['title']; + if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'yaml') { + $fieldset_content = YamlParser::decode(Filesystem::read($fieldset['path'])); + $fieldsets[$fieldset['basename']] = $fieldset_content['title']; } } } @@ -196,24 +193,6 @@ class Themes return $fieldsets; } - /** - * _strrevpos - * - * @param string $instr instr - * @param string $needle needle - * - * @return bool - */ - private static function _strrevpos($instr, $needle) - { - $rev_pos = strpos(strrev($instr), strrev($needle)); - if ($rev_pos === false) { - return false; - } else { - return strlen($instr) - $rev_pos - strlen($needle); - } - } - /** * Get the Themes instance. *