topic. seperate the list into countries. /miscellaneous/florists/county.html return a list of towns in the county where we have vendors for the category->topic /miscellaneous/florists/county/town.html return a list of vendors in the town for the category->topic */ $request_url = strip_tags($_SERVER['REQUEST_URI']); # get the requested URL $request_url = substr($request_url,1); # remove the leading forwardslash $request_url = str_replace(".html","",$request_url); # remove the .html part $request_url = str_replace("%27","'",$request_url); $temp=explode("/","$request_url"); # split the URL into its components $vars["category"] = str_replace("%20"," ",$temp[0]); # the category is always the first element $numelements=count($temp); # number of parts if($numelements > 1){ # if there are at least 2 elements (0 and 1) $vars["topic"] = str_replace("%20"," ",$temp[1]); # the topic is always the second element } if($numelements > 2){ # the country is next $vars["county"] = str_replace("%20"," ",$temp[2]); } if($numelements > 3){ # the town is the last $vars["town"] = str_replace("%20"," ",$temp[3]); } #==================================================================================================== // MAKE VARIOUS VERSIONS $vars["county url"] = str_replace(" ","%20",$vars["county"]); $vars["county ucw"] = ucwords($vars["county"]); $vars["town url"] = str_replace(" ","%20",$vars["town"]); $vars["town ucw"] = ucwords($vars["town"]); $vars["category url"] = str_replace(" ","%20",$vars["category"]); $vars["category ucw"] = ucwords($vars["category"]); $vars["category ucf"] = ucwords($vars["category"]); $vars["topic url"] = str_replace(" ","%20",$vars["topic"]); $vars["topic ucw"] = ucwords($vars["topic"]); // FIX SOME ODDITIES FOR THE DISPLAY if($vars["topic"] == "buildings and fences"){ $vars["topic ucw"] = "Garden Buildings and Fences"; } if(($vars["topic"]=="photographers") && ($vars["category"]=="weddings")){ $vars["extra"] = "wedding "; } // MAKE THE ACCOMMODATION TOPICS if($vars["category"] == "accommodation"){ switch($vars["topic"]){ case "bed and breakfast": $vars["accommtype"] = "BB"; break; case "campsites": $vars["accommtype"] = "CS"; break; case "caravan parks": $vars["accommtype"] = "CP"; break; case "farm holidays": $vars["accommtype"] = "FH"; break; case "guest houses": $vars["accommtype"] = "GH"; break; case "holiday cottages": $vars["accommtype"] = "HC"; break; case "holiday parks": $vars["accommtype"] = "HP"; break; case "hostels": $vars["accommtype"] = "HS"; break; case "hotels": $vars["accommtype"] = "HO"; break; case "self catering": $vars["accommtype"] = "SC"; break; } } #==================================================================================================== // CREATE THE IMAGE CODE FOR THE CATEGORY if($vars["topic"] != ""){ if(($vars["topic"] == "photographers") && ($vars["category"] == "weddings")){ $image = "images/wedding photographers.jpg"; }else{ $image = "images/" . $vars["topic"] . ".jpg"; } // // if we don't have an image for the topic, use the category image instead // if(!file_exists($image)){ // $image = "images/" . $vars["category"] . ".jpg"; // } }else{ $image = "images/" . $vars["category"] . ".jpg"; } if(file_exists($image)){ $vars["header image"] = str_replace("images/","",$image); } #==================================================================================================== // DIRECT ACCORDING TO WHICH ELEMENTS EXIST if($vars["category"] == "about"){ # send the about page $content = join('',file('_about.txt')); $vars["title"] = "About In-Britain (local services and facilities in Britain (UK))."; $vars["description"] = "About the In-Britain local services and facilities finder."; $vars["keywords"] = "Britain, UK, local facilities, local services"; $return_page = make_substitutions($vars,$content,$template); }else if(($vars["town"] != "") && ($vars["county"] != "") && ($vars["topic"] != "") && ($vars["category"] != "")){ # it's a town's listings for the topic $return_page = town_listings($vars,$template,$link); }elseif(($vars["county"] != "") && ($vars["topic"] != "") && ($vars["category"] != "")){ # list the county's towns listing for the topic $return_page = county_towns($vars,$template,$link); }elseif(($vars["topic"] != "") && ($vars["category"] != "")){ # list the countries/counties for the topic $return_page = country_counties($vars,$template,$link); }elseif($vars["category"] != ""){ # list the sub-cat and topic links that are in all the fly-outs for the category $return_page = category_page($vars,$template,$link); }elseif(($request_url == "index") || ($request_url == "")){ # send the home page $content = join('',file('_homepage.txt')); $return_page = make_substitutions($vars,$content,$template); }elseif(($request_url == "newcategory") || ($request_url == "")){ # send new category page $content = join('',file('_newcategory.txt')); $return_page = make_substitutions($vars,$content,$template); } else{ header("HTTP/1.0 410 Gone"); # send the home page $content = join('',file('_homepage.txt')); $return_page = make_substitutions($vars,$content,$template); } #==================================================================================================== // RETURN THE PAGE print $return_page; exit; //################################################################################################### // LIST LINKS TO ALL THE SUB-CATEGORIES AND TOPICS THAT ARE IN ALL THE FLY-OUT function category_page($vars,$template,$link){ $UFcategory=ucfirst($vars["category"]); $content = "« Back\n"; $content .= "
\n"; $content .= "

" . $vars["category ucw"] . "


\n"; $content .= "
\n"; if($vars["category"] == "accommodation"){ $temp="types"; }else{ $temp="topics"; } $content .= "
\n"; $content .= "
\n"; $content .= " We have listings for these \"" . $vars["category"] . "\" $temp:-\n"; $content .= "
\n"; $content .= "
\n"; $content .= "
\n"; $startpos=strpos($vars["left column"],""); if(!($startpos === false)){ $endpos=strpos($vars["left column"],"",$startpos); if(!($endpos === false)){ $content .= substr($vars["left column"],$startpos,$endpos - $startpos); $content .= "
\n"; $content .= "

\n"; } } $return_page = make_substitutions($vars,$content,$template); return $return_page; } #==================================================================================================== // LIST THE VENDORS FOR THE TOPIC IN THE TOWN function town_listings($vars,$template,$link){ # create the image code for the town $image = "images/" . $vars["town"] . ".jpg"; if(file_exists($image)){ $vars["right column"] = "
"; } $qry = "SELECT * FROM " . $vars["table vendors"] . " "; $qry .= "WHERE category = '" . $vars["category"] . "' "; if($vars["category"] == "accommodation"){ $qry .= "AND topic LIKE '%" . $vars["accommtype"] . "%' "; }else{ $qry .= "AND topic = '" . $vars["topic"] . "' "; } $qry .= "AND county = '" . $vars["county"] . "' "; $qry .= "AND town = '" . str_replace("'","''",$vars["town"]) . "' "; # this is for when there's an apostrophe in the town name $qry .= "AND status != 'suspended' "; $qry .= "AND status != 'unreviewed' "; $qry .= "AND status != 'spam' "; $qry .= "ORDER BY url DESC, name ASC"; $results = mysql_query($qry,$link); $numresults = mysql_num_rows($results); if($numresults > 0){ $content="\n"; # vendor listings cell $content .= "\n"; # # town image cell # $content .= "\n"; $content .= "
\n"; $townProper = ""; $countyProper = ""; while($row = mysql_fetch_object($results)){ # save the proper capitalisation of the town and county if($townProper == ""){ $townProper = $row->town; $countyProper = $row->county; } if($row->url != ""){ $content .= "$row->name
\n"; }else{ $content .= "$row->name
\n"; } $address=""; if($row->address1 != ""){$address .= $row->address1;} if($row->address2 != ""){$address .= ", " . $row->address2;} if($row->address3 != ""){$address .= ", " . $row->address3;} if($row->town != ""){$address .= ", " . $row->town;} if($row->county != ""){$address .= ", " . $row->county;} if($row->postcode != ""){$address .= ", " . $row->postcode;} if($address != ""){$content .= "$address
";} if($row->description != ""){$content .= $row->description . "
\n";} $email="";$phone=""; if($row->email != ""){$email = $row->email;} if($row->phone != ""){$phone = $row->phone;} if($phone != ""){$content .= "Phone: $phone ";} if($email != ""){$content .= " : Email
\n";} if($email == ""){$content .= "
\n";} # if it's the admin IP, add the admin options if($_SERVER["REMOTE_ADDR"] == $vars["admin ip"]){ $referrer = $_SERVER['HTTP_REFERER']; $referrer = urlencode($referrer); $content .= "[ \n"; $content .= "edit  • \n"; $content .= " put in unreviewed  • \n"; $content .= " delete\n"; $content .= " ]\n"; $content .= "
\n"; } $content .= "
\n"; } $content .= "
\n"; $content .= "
$image
\n"; $county=ucwords($county); $town=ucwords($town); $listings="listings"; if($numresults == 1){$listings="listing";} $heading = "« Back\n"; $heading .= "
\n"; $heading .= "

" . ucwords($vars["extra"]) . $vars["topic ucw"] . " in " . $townProper . ", " . $countyProper . "

\n"; $heading .= "We have $numresults $listings for " . $vars["extra"] . $vars["topic"] . " in " . $townProper . ", " . $countyProper . "

\n"; $ad = adsense(); $heading .= "$ad
\n"; $heading .= "
\n"; $heading .= "
\n"; $heading .= " " . $vars["category ucw"] . ""; $heading .= " : " . $vars["topic ucw"] . ""; $heading .= " : " . $countyProper . ""; $heading .= " : " . $townProper . "\n"; $heading .= "
\n"; $vars["heading"] = $heading; } $vars["title"] = ucwords($vars["extra"]) . $vars["topic ucw"] . " in " . $townProper . ", " . $countyProper . ", Britain (UK)."; $vars["description"] = "Find your local " . $vars["extra"] . $vars["topic"] . " in " . $vars["town ucw"] . ", " . $vars["county ucw"] . ", Britain (UK)."; $vars["keywords"] = ucwords($vars["extra"]) . $vars["topic ucw"] . ", " . $vars["town ucw"] . ", " . $vars["county ucw"] . ", Britain, UK, local"; $vars["param1"] = $vars["topic"]; $vars["param2"] = $vars["county ucw"]; $vars["also links"] = also_links($vars,$template,$link); $return_page = make_substitutions($vars,$content,$template); return $return_page; } #==================================================================================================== // LIST THE TOWNS IN THE COUNTY WHERE WE HAVE VENDORS FOR THE TOPIC function county_towns($vars,$template,$link){ $qry = "SELECT DISTINCT town FROM " . $vars["table vendors"] . " "; $qry .= "WHERE category = '" . $vars["category"] . "' "; if($vars["category"] == "accommodation"){ $qry .= "AND topic LIKE '%" . $vars["accommtype"] . "%' "; }else{ $qry .= "AND topic = '" . $vars["topic"] . "' "; } $qry .= "AND county = '" . $vars["county"] . "' "; $qry .= "AND status != 'suspended' "; $qry .= "AND status != 'unreviewed' "; $qry .= "AND status != 'spam' "; $qry .= "ORDER BY town ASC"; $results = mysql_query($qry,$link); $numresults = mysql_num_rows($results); #find the number of rows needed $numcolumns=4; $numrows=floor($numresults / $numcolumns); if($numresults / $numcolumns > 0){$numrows++;} if($numresults > 0){ $content = "\n\n
\n"; $count=0; while($row = mysql_fetch_object($results)){ $town=$row->town; $townurl=trim(strtolower(str_replace(" ","%20",$town))); $townurl=str_replace("'","%27",$townurl); $content .= "$town
\n"; $count++; if($count >= $numrows){ $content .= "\n
 \n"; $count=0; } } $content .= "
\n"; $content .= "
\n"; $heading = "« Back\n"; $heading .= "
\n"; $heading .= "

" . ucwords($vars["extra"]) . $vars["topic ucw"] . " in " . $vars["county ucw"] . "

\n"; $heading .= "We have listings for " . $vars["extra"] . $vars["topic"] . " in " . $vars["county ucw"] . " in the following places


\n"; $ad = adsense(); $heading .= "$ad
\n"; $heading .= "
\n"; $heading .= "
\n"; $heading .= " " . $vars["category ucw"] . ""; $heading .= " : " . $vars["topic ucw"] . ""; $heading .= " : " . $vars["county ucw"] . "\n"; $heading .= "
\n"; $vars["heading"] = $heading; } $vars["title"] = ucwords($vars["extra"]) . $vars["topic ucw"] . " in " . $vars["county ucw"] . ", Britain (UK)."; $vars["description"] = "Find your local " . $vars["extra"] . $vars["topic"] . " in " . $vars["county ucw"] . ", Britain (UK)."; $vars["keywords"] = $vars["extra"] . $vars["topic"] . ", " . $vars["county ucw"] . ", Britain, UK, local"; $return_page = make_substitutions($vars,$content,$template); return $return_page; } #==================================================================================================== // LIST THE COUNTIES WHERE WE HAVE VENDORS FOR THE TOPIC, SEPERATED INTO COUNTRY LISTS function country_counties($vars,$template,$link){ $qry = "SELECT DISTINCT country, county FROM " . $vars["table vendors"] . " "; $qry .= "WHERE category = '" . $vars["category"] . "' "; if($vars["category"] == "accommodation"){ $qry .= "AND topic LIKE '%" . $vars["accommtype"] . "%' "; }else{ $qry .= "AND topic = '" . $vars["topic"] . "' "; } $qry .= "AND status != 'suspended' "; $qry .= "AND status != 'unreviewed' "; $qry .= "ORDER BY country ASC, county ASC"; $results = mysql_query($qry,$link); $numresults = mysql_num_rows($results); if($numresults > 0){ $england=""; $ireland=""; $scotland=""; $wales=""; while($row = mysql_fetch_object($results)){ if($row->country != $thiscountry){ $thiscountry = strtolower($row->country); $county = $row->county; if($county != ""){ $countyurl=trim(strtolower(str_replace(" ","%20",$county))); $a=":$county\n"; if($thiscountry == "england"){ $england .= $a; }elseif($thiscountry == "n.ireland"){ $ireland .= $a; }elseif($thiscountry == "scotland"){ $scotland .= $a; }elseif($thiscountry == "wales"){ $wales .= $a; } } } } // compile the lists code $numcolumns=4; $content = "\n"; # England if($england != ""){ $found=true; $content .= "\n"; $content .= "\n"; $temp=explode(":",$england); $num=count($temp)-1; $numrows=floor($num / $numcolumns); # round the result down to the integer if($numresults / $numcolumns > 0){$numrows++;} $count=0; $content .= "\n"; $content .= "\n"; $content .= "\n"; $content .= "\n"; $content .= "\n"; } # Scotland if($scotland != ""){ $found=true; $content .= "\n"; $content .= "\n"; $temp=explode(":",$scotland); $num=count($temp); $numrows=floor($num / $numcolumns); if($numresults / $numcolumns > 0){$numrows++;} $count=0; $content .= "\n"; $content .= "\n"; $content .= "\n"; $content .= "\n"; } # Wales if($wales != ""){ $found=true; $content .= "\n"; $content .= "\n"; $temp=explode(":",$wales); $num=count($temp); $numrows=floor($num / $numcolumns); if($numresults / $numcolumns > 0){$numrows++;} $count=0; $content .= "\n"; $content .= "\n"; $content .= "\n"; $content .= "\n"; } # N.Ireland if($ireland != ""){ $found=true; $content .= "\n"; $content .= "\n"; $temp=explode(":",$ireland); $num=count($temp); $numrows=floor($num / $numcolumns); if($numresults / $numcolumns > 0){$numrows++;} $count=0; $content .= "\n"; $content .= "\n"; $content .= "\n"; $content .= "\n"; } if($found === false){ $content .= "\n"; } $content .= "
England
\n"; for($i=1;$i <= $num;$i++){ # the 0 element is always empty due to the leading delimiter $content .= $temp[$i] . "
\n"; $count++; if($count >= $numrows){ $content .= "\n
 \n"; $count=0; } } $content .= "

Scotland
\n"; for($i=1;$i <= $num;$i++){ $content .= $temp[$i] . "
\n"; $count++; if($count >= $numrows){ $content .= "\n
 \n"; $count=0; } } $content .= "

Wales
\n"; for($i=1;$i <= $num;$i++){ $content .= $temp[$i] . "
\n"; $count++; if($count >= $numrows){ $content .= "\n
 \n"; $count=0; } } $content .= "

Northern Ireland
\n"; for($i=1;$i <= $num;$i++){ $content .= $temp[$i] . "
\n"; $count++; if($count >= $numrows){ $content .= "\n
 \n"; $count=0; } } $content .= "
\n"; $content .= "Sorry but we have no listings for " . $vars["topic"] . " in the UK.\n"; $content .= "
\n"; $content .= "
\n"; $content .= "
\n"; // compile the heading $heading = "« Back\n"; $heading .= "
\n"; $heading .= "

" . ucwords($vars["extra"]) . $vars["topic ucw"] . " in Britain (UK)

\n"; $heading .= "
\n"; $heading .= "We have listings for " . $vars["extra"] . $vars["topic"] . " in the UK for these counties and places

\n"; $heading .= "
\n"; $heading .= "
\n"; $heading .= "" . $vars["category ucw"] . ""; $heading .= " : " . $vars["topic ucw"] . "\n"; $heading .= "

\n"; $vars["heading"] = $heading; } $vars["title"] = $vars["topic ucw"] . " in Britain (UK)."; $vars["description"] = "Find your local " . $vars["topic"] . " in Britain (UK)."; $vars["keywords"] = $vars["topic"] . ", Britain, UK, local"; $return_page = make_substitutions($vars,$content,$template); return $return_page; } #==================================================================================================== // MAKE THE "ALSO" LINKS FOR THE BOTTOM OF THE LISTINGS // strings are passed as param1 and param2; e.g. a topic and a town function also_links($vars,$template,$link){ # query the database for $topic in $county $qry = "SELECT DISTINCT town FROM " . $vars["table vendors"] . " "; $qry .= "WHERE category = '" . $vars["category"] . "' "; if($vars["category"] == "accommodation"){ $qry .= "AND topic LIKE '%" . $vars["accommtype"] . "%' "; }else{ $qry .= "AND topic = '" . $vars["topic"] . "' "; } $qry .= "AND county = '" . $vars["county"] . "' "; $qry .= "AND status != 'suspended' "; $qry .= "AND status != 'unreviewed' "; $qry .= "ORDER BY town ASC"; $results = mysql_query($qry,$link); $numresults = mysql_num_rows($results); if($numresults > 0){ $alsolinks = "
\n"; $alsolinks .= "
We have " . $vars["extra"] . $vars["param1"] . " listed for these places in " . $vars["param2"] . "\n"; $alsolinks .= "
\n"; # find the number of rows needed $numcolumns=2; $numrows=floor($numresults / $numcolumns); if($numresults % $numcolumns > 0){$numrows++;} $alsolinks .= "\n\n
\n"; $count=0; $found=false; while($row = mysql_fetch_object($results)){ $thistown=$row->town; if($thistown != $vars["town"]){ $townurl=strtolower($thistown); $townurl=str_replace(" ","%20",$townurl); $townurl=str_replace("'","%27",$townurl); $found=true; $alsolinks .= "" . $thistown . " " . $vars["extra"] . $vars["topic"] . "
\n"; $count++; if($count >= $numrows){ $alsolinks .= "\n
 \n"; $count=0; } } } $alsolinks .= "
\n"; $alsolinks .= "
\n"; $alsolinks .= "
\n"; # if no other locations were found, scrap the string if($found === false){$alsolinks="";} } return $alsolinks; } ?>