Optimized get_filenames().

* Reduced number of large arrays it generates.
* Turned off glob()'s own sorting.
* Keeps current working directory intact.
* Checks read permissions.

Fixes issue #367

git-svn-id: http://textpattern.googlecode.com/svn/development/4.x@5319 2fea6a4d-a838-0410-917b-93a53c48e9d2