Improve performance of inventory

`is_dir` is the most time-intensive function, so it would be worth delaying until it's absolutely necessary. This patch got my response-time down to 1.25s from previously 3.5s on a shared host. I also tried `glob`, `opendir` and `directory_iterator`, but on my environments `scandir` was indeed the fastest solution.

I suspect other performance improvements can be made here and there:
- leveraging `glob` as a way to find pages a few levels down, instead of inventoring every folder in-between
- using `readfile` instead of `file_get_contents`, and perhaps only scan the text files 'lazily' until the required field is found (such as title), resuming further ahead whenever another as yet unfetched field is required

Other ideas welcome, might work further on this when time frees up