diff --git a/.theme/.gitignore b/.theme/.gitignore new file mode 100644 index 0000000..aac8f5d --- /dev/null +++ b/.theme/.gitignore @@ -0,0 +1 @@ +lib/cache* diff --git a/.theme/js/functions.js b/.theme/js/functions.js index e6c2a9b..ff40bf7 100644 --- a/.theme/js/functions.js +++ b/.theme/js/functions.js @@ -19,7 +19,7 @@ jQuery(function($) { var html_class = settings.color + ' ' + settings.font; var current_path = document.location.pathname.substring(settings.root.length); - function typeAheadInit() { + function typeAheadInit( cache = false ) { var search_data = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.nonword('name'), queryTokenizer: Bloodhound.tokenizers.nonword, @@ -39,7 +39,8 @@ jQuery(function($) { data: { root_path : settings.root, current_path : document.location.pathname, - depth : settings.depth + depth : settings.depth, + cache: cache }, success: function() { $search.removeClass('loading'); @@ -307,6 +308,8 @@ jQuery(function($) { initTheme(); updateTheme(); + typeAheadInit('true'); + typeAheadEvents(); typeAheadInit(); typeAheadEvents(); serverLinksGenerator(); diff --git a/.theme/lib/directory-crawler.php b/.theme/lib/directory-crawler.php index e4bb072..0dcbb00 100644 --- a/.theme/lib/directory-crawler.php +++ b/.theme/lib/directory-crawler.php @@ -121,9 +121,23 @@ function remove_root_path( $directory ) { $root_path = !empty( $_GET[ 'root_path' ] ) ? $_GET[ 'root_path' ] : null; $current_path = !empty( $_GET[ 'current_path' ] ) ? $_GET[ 'current_path' ] : null; $depth = !empty( $_GET[ 'depth' ] ) ? $_GET[ 'depth' ] : 0; +$use_cache = !empty( $_GET['cache'] ) ? $_GET['cache'] : '/'; -$crawler = new DirectoryCrawler( $root_path, $current_path, $depth ); -$directories = $crawler->get_directories(); -$directories_json = json_encode( $directories ); +$cache_filename = 'cache-' . urlencode( $root ) . '-' . urlencode( $path ) . '-' . urlencode( $depth ) . '.txt'; -die( $directories_json ); +if ( $use_cache ) { + $cache = file_get_contents( $cache_filename ); + if ( empty( $cache ) ) { + $cache = ''; + } + + die( $cache ); +} else { + $crawler = new DirectoryCrawler( $root_path, $current_path, $depth ); + $directories = $crawler->get_directories(); + $directories_json = json_encode( $directories ); + + file_put_contents( $cache_filename, $directories_json ); + + die( $directories_json ); +}