This is a guide to create a user/search engine friendly directory using Websight
http://websight.sourceforge.net/site/; Websight is a directory script written in php. I'd like to present a short tutorial/article on how to make it user/search engine friendly and share with you all today.
I saw many people asking how they can create a user/search engine friendly directory in many forums, so I wrote a guidance a short while ago and posted it in
some other forum, but what I suggested initially was not such a great solution. Recently I had chance to review it and present a much better solution; I wanted to start from scratch, so I am posing this short article here. Another reason I am posing this in IMR is that I want to get more feedback from different people.
Though this is an Ok solution, this is probably not the best and greatest; I think the performance can be improved 100% by optimizing the code. So, what I'm hoping to accomplish is
1) If anyone else out there trying to create a user/search engine friendly directory, then they can just look at this short tutorial and do it(Ok, you'd probably have questions, but I will help to the best of my knowledge and ability).
2) I might get some criticism; in specific, criticism with regard to routine efficiency. As I answer those criticism, I can improve my work.
Here we go.
1. First, you create pathinfo.php and place it in the root of the installation directory. The php file looks like this
[code:1:cf80c00e83]
<?php
$GetCategoryId=Array();
$MatchCategory=Array();
$query="SELECT id, name FROM ".DB_PREFIX."categories WHERE parent!='-1' ORDER BY id";
$result=mysql_query($query);
while($row=mysql_fetch_row($result))
{
$count=1;
$currentcat=$row[0];
while($currentcat!="0")
{
$cquery="SELECT id, name, parent FROM ".DB_PREFIX."categories WHERE id='$currentcat'";
$cresult=mysql_query($cquery);
if(mysql_num_rows($cresult)>0)
{
$crow=mysql_fetch_row($cresult);
$parray[0][$count]=$crow[0];
$parray[1][$count]=$crow[1];
$currentcat=$crow[2];
} else
{
$currentcat=0;
}
$count=$count+1;
}
$tree="";
while($count>1)
{
$count=$count-1;
if(($count!="0" && $count!="1")&&isset($parray[1][$count]))
{
$tree.=opmaak($parray[1][$count])."/";
}
}
$urlstring = str_replace(" ", "_", $tree.opmaak($row[1]));
$GetCategoryId["/".$urlstring."/"]="".$row[0];
$MatchCategory["".$row[0]]=$urlstring."/";
}
if ($cat == "0")
{
if (strlen($PATH_INFO) > 1
&& $PATH_INFO{strlen($PATH_INFO) - 1} != "/")
{
$cat = $GetCategoryId[$PATH_INFO."/"];
} else
{
$cat = $GetCategoryId[$PATH_INFO];
}
if ($cat == "")
{
$cat == "0";
}
}
?>[/code:1:cf80c00e83]
Note:
You probably need to have
[code:1:cf80c00e83]
$urlstring = str_replace(" ", "_", $tree.opmaak($row[1]));
$GetCategoryId["/".$urlstring."/"]="".$row[0];
$MatchCategory["".$row[0]]=urlencode($urlstring)."/";[/code:1:cf80c00e83]
instead of just
[code:1:cf80c00e83]
$urlstring = str_replace(" ", "_", $tree.opmaak($row[1]));
$GetCategoryId["/".$urlstring."/"]="".$row[0];
$MatchCategory["".$row[0]]=$urlstring."/";[/code:1:cf80c00e83]
for unicode. I haven't tested this extensively, but if you look at the code, you should get the idea.
Basically, this maps url strings to different categories and vice versa. As you can see, this routine maps url strings dynamically, so you do not need to mess with your server so much nor do you need to hard-code url strings.
2. Copy index.php and name it Top(no extension). This(leave a copy of index.php) is not absolutely necessary, BUT this is one quick and dirty way to make everything just work without making too many modifications to replace index.php with Top. Also if you are already running Websight, this is the easiest way to preserve backward compatibility.
3. Include the following line
[code:1:cf80c00e83]
include_once("./pathinfo.php");[/code:1:cf80c00e83]
in confirm.php, privacy.php, search.php, Top, newcat.php, contact.php, index.php, and newlink.php, right after
[code:1:cf80c00e83]
include_once("./includes/functions.php");[/code:1:cf80c00e83]
4. There are functions to check if the file called the function is index.php. Modify them so that both index.php and Top are recognized.
5. ?cat=xxx needs to be replaced with new directory path; you need to do two things to do this.
i) You need to reference $GetCategoryId and $MatchCategory, get new directory paths and save them in an array.
ii) You need to reference the array to get new directory path for each and every ?cat=xxx.
5.2. Paths need to be modified in order to adjust to this change; there are number of ways to fix paths and make the adjustment, but what worked for me was
Create 3 extra variables in websight_config table;
[code:1:cf80c00e83]
basepath
websightroot and
websighttop[/code:1:cf80c00e83]
and set them like the following
[code:1:cf80c00e83]
basepath http://www.yourSite.com
websightroot directory/
websighttop Top/[/code:1:cf80c00e83]
if your root address is
http://www.yourSite.com and have your websight installation on
http://www.yourSite.com/directory/ directory.
6. Add the following code wherever appropriate depending on your server configuration(.htaccess or vhost.conf).
[code:1:cf80c00e83]
<Files Top>
ForceType application/x-httpd-php
</Files>[/code:1:cf80c00e83]
That's it! Tutorial is rather brief(actually very brief), so there are a couple of things you need to figure out, but you should be able to figure it out. I barely know php, so if you know php just a little, you should be able to figure out details.
Again, I know that this is not the best or the greatest way to do it. A lot of improvements can be made(easily). Let me know and post comments, suggestions, and questions if you have any. Hopefully, we will have a better tutorial here so that people won't be struggling to make a user/search engine friendly directory from now on.
Last Note 1: This is one example of how it's done;
Education Website Directory.
Last Note 2: If there is someone who is pretty good at php and wants to rewrite this and publish a more complete article/tutorial, please do so. That would help me as well as other people.