To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-14-2003, 09:22 PM   #1
rpanning
Tandem Web Works
 
rpanning's Avatar
 
Join Date: Dec 2002
Location: MN, USA
Posts: 444
AutoNav (Automated Navigation)

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.
Attached Files
File Type: txt autonav.txt (8.3 KB, 76 views)
__________________
Are you a mountain biker and live in Minnesota? Join MORC to help support our trials!

Last edited by rpanning; 11-14-2003 at 09:37 PM.
rpanning is offline   Reply With Quote
Old 11-18-2003, 04:20 PM   #2
jenni
Member
 
Join Date: Jan 2003
Posts: 91
To be honest, I am more interested in seeing your company's website...I can't imagine maintaining a site (especially a business site) where anyone and everyone can add pages on a whim without letting the webmaster (official or unofficial) know about it.
jenni is offline   Reply With Quote
Old 11-18-2003, 06:27 PM   #3
rpanning
Tandem Web Works
 
rpanning's Avatar
 
Join Date: Dec 2002
Location: MN, USA
Posts: 444
I work for a school district and my job is to fix the computers. The Website is done on my "free time" and since I don't have much of that my boss has decided to split up the work. Each building keeps their own site content up-to-date. There for I don't see every change, addition, etc. We are a growing district so I'm sure sometime in the future we'll have a full-time Webmaster but until then this script helps out a lot with navigation.

Also, I'm going to start working on version 2 of AutoNav. I've though of a few different ways to code it. Still looking for some input.

[UPDATE]Auto_Nav version 2 will be for PHP 5 and contain major new features. It will be completely rewritten so look for it sometime in spring 2005.[/UPDATE]
__________________
Are you a mountain biker and live in Minnesota? Join MORC to help support our trials!

Last edited by rpanning; 02-17-2005 at 02:24 AM.
rpanning is offline   Reply With Quote
Old 11-19-2003, 12:30 AM   #4
planetsim
code | beer > sleep
 
Join Date: Sep 2002
Location: aus
Posts: 4,826
I may just suggest that i got your script. however got the following errors with it.

Code:
Warning: asort() expects parameter 1 to be array, null given in D:\httpdocs\autonav.php on line 139

Warning: Invalid argument supplied for foreach() in D:\httpdocs\autonav.php on line 140

Warning: Invalid argument supplied for foreach() in D:\httpdocs\autonav.php on line 143
Now i didnt modify the script. But as a suggestion maybe make sure your script is portable. Now for all i know i may have not set it up correctly. But keep errors on this will allow you to see all errors, than when you wish to distribute it or use it on a different system there should be no bugs.

just me 2cents
__________________
Dont be lazy Search
And use the Manual
Webmobo - Open Source News Script | Portfolio / Blog | Against TCPA
planetsim is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 02:15 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.