Hi, this script automaticly makes your navigation lists based on the files in the filesystem. I'm looking for any input to improve it, expecialy speed since it scans dirs, but any input is great. Note that I do have a cache system setup but it's not apart of AutoNav. I hope you find this script helpful, let me know if you use it! 😃 Below is kind of a Q&A section. The file is attached.
Why was it made?
I'm the "unofficial Webmaster" for our website at work and we have some people updating the content. Every once and a while they would make a new page. Sometimes they wouldn't tell me and sometime they would. So, I was getting sick of having to look for navigation changes, added pages. Also, it's a PAIN having to update almost every page. So I made this script/class so I would never have to update the navigation.
How does it list?
It will scan your webpages from the cwd back to the doc root. It's then sorted to get the proper sequense. All pages and folders starting with a underscore are hidden. The link title is based on the filename or foldername if it's an index file. All files with the link extenstion are used to get the link to another page. The root file is used to get the name of the root link (top link, '/').
How does it work?
When you make a new AutoNav instance it sets the default values. Next, when you make the nav list it will read through the dirs. (Note: All files and folders starting with _ are NOT listed.) When it reaches the .. folder it goes back and lists that, until the document root is reached. If it reaches a folder, the folder is checked for an index file and listed if one exists. Next, if it reaches a file that has the extension in the extension list or link extension the type is checked. If it's an index AND the current dir is the doc root it checks to see if the / url is already added, if so it returns. If not the root file is included to get the new name (output buffering is used to catch extra whitespace). It's then added to the list. If it's a link file, file is also included to get the URL. (Note: The name is set before the file is included so that you can change it before adding it to the list.) If it's a regular file its added to the list. Finaly, when you display the nav list it is sorted by URL to get the proper sequense and then printed.
What do I have to do to use it?
There are a few things that you might want to change so that it works with your site. First, make sure the default values are correct for your site (ext and index lists, link ext, and root file). Next, you'll want to change the output code, look in displayNav_List for this. Look at all of the $output variables, that's what will be printed. Change the indent size and style if you want. Finaly, make sure you do something with the errors. I have my own error handling I use that displays the errors on the page if there are any (not the one thats in the attached file 😉). Then make a new AutoNav and makeNav_List() then displayNav_List(). Other than that you should be set to go, unless you want to make some tweeks. Don't forget to make the root file and any links you want.