Error: categories file cannot be loaded"; exit; } } else { $parmCat = $parmSearch; } // Cat vars $sortedCats = array_keys($cats); if (SORT_CATS) {sort($sortedCats);} $parmCat = strtolower(preg_replace('/[_+]/', ' ', $parmCat)); $category = ''; foreach ($sortedCats as $cat) { if ($parmCat == strtolower($cat)) { $category = $cat; break; } } if ($parmCat <> '' && $category == '') { $category = $parmCat; } $subcats = array(); $slashCount = substr_count($category, '/') + 1; foreach ($sortedCats as $cat) { if ($category == '') { if (substr_count($cat, '/') < 2) $subcats[$cat] = catLink($cat); } else if (preg_match("#^$category#", $cat) && substr_count($cat, '/') == $slashCount) { $subcats[$cat] = catLink($cat); } } // Landing Page if ($category == '') { // Vars $htmlCats = ''; $htmlCat = ''; $htmlSubcats = ''; $templateCat = loadTemplate(TEMPLATE_LANDING_CAT); $templateSubcat = trim(loadTemplate(TEMPLATE_LANDING_SUBCAT)); $cellWidth = intval(100 / NUM_CATS_PER_ROW); $catRowCount = 0; $subcatCount = 0; // Loop through cats foreach ($subcats as $subcat => $subcatLink) { // Top level category if (substr_count($subcat, '/') == 0) { // Finish previous cat if ($htmlCat <> '') { $htmlCat = preg_replace('//', $htmlSubcats, $htmlCat); $htmlCats .= $htmlCat; } // Check if need to start new row if ($catRowCount == NUM_CATS_PER_ROW) { $htmlCats .= HTML_CAT_NEWROW; $catRowCount = 0; } // Build category $catRowCount++; $htmlCat = $templateCat; $htmlCat = preg_replace('//', $cellWidth, $htmlCat); $htmlCat = preg_replace('//', $subcatLink, $htmlCat); $htmlCat = preg_replace('//', catTitle($subcat), $htmlCat); // Init subcat vars $htmlSubcats = ''; $subcatCount = 0; } // Sub-category else { // Build subcat output up to max subcats $subcatCount++; if ($subcatCount <= NUM_SUBCATS) { if ($htmlSubcats <> '') { $htmlSubcats .= HTML_SUBCAT_SEP; } $template = $templateSubcat; $template = preg_replace('//', $subcatLink, $template); $template = preg_replace('//', catTitle($subcat), $template); $htmlSubcats .= $template; } // More subcats... else if ($subcatCount - 1 == NUM_SUBCATS) { $htmlSubcats .= HTML_SUBCAT_SEP . HTML_SUBCAT_MORE; } } } // Finish last cat if ($htmlCat <> '') { $htmlCat = preg_replace('//', $htmlSubcats, $htmlCat); $htmlCats .= $htmlCat; } // Build Header/Footer $htmlHeader = loadTemplate(TEMPLATE_HEADER); $htmlHeader = preg_replace('//', '', $htmlHeader); $htmlHeader = preg_replace('//', HTML_LANDING_TITLE, $htmlHeader); $htmlHeader = preg_replace('//', HTML_LANDING_TITLE, $htmlHeader); $htmlHeader = preg_replace('//', '', $htmlHeader); $htmlHeader = preg_replace('//', $queryParams, $htmlHeader); $htmlHeader = preg_replace('//', $parmChannel, $htmlHeader); $htmlHeader = preg_replace('//', $parmLanguage, $htmlHeader); $htmlHeader = preg_replace('//', $parmEncoding, $htmlHeader); $htmlHeader = preg_replace('//', '', $htmlHeader); $htmlHeader = preg_replace("/=\"c\"\svalue=\"$parmCountry\"\s\/>/", "=\"c\" value=\"$parmCountry\" checked=checked />", $htmlHeader); $htmlFooter = loadTemplate(TEMPLATE_FOOTER); $htmlFooter = preg_replace('//', $queryParams, $htmlFooter); $htmlFooter = preg_replace('//', $parmChannel, $htmlFooter); $htmlFooter = preg_replace('//', $parmLanguage, $htmlFooter); $htmlFooter = preg_replace('//', $parmEncoding, $htmlFooter); $htmlFooter = preg_replace('//', '', $htmlFooter); $htmlFooter = preg_replace("/=\"c\"\svalue=\"$parmCountry\"\s\/>/", "=\"c\" value=\"$parmCountry\" checked=checked />", $htmlFooter); // Build page $html = loadTemplate(TEMPLATE_LANDING); $html = preg_replace('//', $htmlCats, $html); $html = preg_replace('//', '', $html); $html = $htmlHeader.$html.$htmlFooter; } // Category Page else { // Vars $catTitle = catTitle($category); $keywords = $cats[$category]; if ($keywords == '') { $keywords = $parmCat; } // HACK for premium $yahooPartner = PLANETWN_FEED_PARTNER; $yahooCat = strtolower($category); $yahooCat = preg_replace('/[_\/\s].+/', '', $yahooCat); if ($yahooCat == 'real') { $yahooCat = 'realestate'; } $yahooPartner = preg_replace('/_directory/', "_directory_$yahooCat", $yahooPartner); # $yahooType = $yahooCat !== '' ? YAHOO_FEED_TYPE.'_'.($parmSearch != '' ? 'search' : $parmCat) : YAHOO_FEED_TYPE; # $yahooType = preg_replace('/\/.*/', '', $yahooType); // !!! replace anything that is after the slash, we are only interested in main category !!! # $yahooType = preg_replace('/[\s]+/', '_', $yahooType); $yahooType = PLANETWN_FEED_TYPE; // Build breadcrumb $htmlBreadcrumb = ''; if ($parmType == 'dir') { $templateBreadcrumbLink = trim(loadTemplate(TEMPLATE_CAT_BREADCRUMB_LINK)); $sep = HTML_CAT_BREADCRUMB_SEP; $catPath = ''; foreach (explode('/', $category) as $thisCat) { // HACK for premium $htmlBreadcrumb = preg_replace('/dirlinksact/','dirlinks', $htmlBreadcrumb); if ($catPath == '') { $catPath = $thisCat; $template = $templateBreadcrumbLink; } else { $catPath .= "/$thisCat"; $template = $sep . $templateBreadcrumbLink; } $template = preg_replace('//', catLink($catPath), $template); $template = preg_replace('//', catTitle($thisCat), $template); $htmlBreadcrumb .= $template; } if ($htmlBreadcrumb <> '') { $template = loadTemplate(TEMPLATE_CAT_BREADCRUMB); $htmlBreadcrumb = preg_replace('//', $htmlBreadcrumb, $template); } } // Build subcats $htmlSubcats = ''; $templateSubcat = loadTemplate(TEMPLATE_CAT_SUBCAT_LISTING); foreach ($subcats as $subcat => $subcatLink) { $template = $templateSubcat; $template = preg_replace('//', $subcatLink, $template); $template = preg_replace('//', catTitle($subcat), $template); $htmlSubcats .= $template; } if ($htmlSubcats <> '') { $template = loadTemplate(TEMPLATE_CAT_SUBCATS); $htmlSubcats = preg_replace('//', $htmlSubcats, $template); } // Build site listings $htmlSites = ''; if (NUM_SITES <> 0) { $htmlSites = getFeed(FEED_SITES, $keywords, STARTNUM_SITES, NUM_SITES, TEMPLATE_CAT_SITE_LISTING, $yahooPartner, $yahooType); if ($htmlSites <> '') { $template = loadTemplate(TEMPLATE_CAT_SITES); $htmlSites = preg_replace('//', $htmlSites, $template); } } // Build ads $htmlAdsTop = ''; if (NUM_ADS_TOP <> 0) { $htmlAdsTop = getFeed(FEED_ADS_TOP, $keywords, STARTNUM_ADS_TOP, NUM_ADS_TOP, TEMPLATE_CAT_ADS_TOP_LISTING, $yahooPartner, $yahooType); if ($htmlAdsTop <> '') { $template = loadTemplate(TEMPLATE_CAT_ADS_TOP); $htmlAdsTop = preg_replace('//', $htmlAdsTop, $template); } else { $ucsearch = ucfirst($keywords); $ucsearch = preg_replace("/\+/", ' ',$ucsearch); $urlsearch = strtolower($keywords); $urlsearch = preg_replace("/\s+/",'+',$urlsearch); $htmlAdsTop = loadTemplate(TEMPLATE_CAT_ADS_TOP_LISTING); $htmlAdsTop = preg_replace('//', '', $htmlAdsTop); $htmlAdsTop = preg_replace('//', "$ucsearch Search", $htmlAdsTop); $htmlAdsTop = preg_replace('//', "Find results for $ucsearch on Spider.com.au", $htmlAdsTop); $htmlAdsTop = preg_replace('//', 'www.spider.com.au', $htmlAdsTop); $htmlAdsTop = preg_replace('//', "http://www.spider.com.au/search?q=$urlsearch", $htmlAdsTop); $template = loadTemplate(TEMPLATE_CAT_ADS_TOP); $htmlAdsTop = preg_replace('//', $htmlAdsTop, $template); } } $htmlAdsSide = ''; if (NUM_ADS_SIDE <> 0) { $htmlAdsSide = getFeed(FEED_ADS_SIDE, $keywords, STARTNUM_ADS_SIDE, NUM_ADS_SIDE, TEMPLATE_CAT_ADS_SIDE_LISTING, $yahooPartner, $yahooType); if ($htmlAdsSide <> '') { $template = loadTemplate(TEMPLATE_CAT_ADS_SIDE); $htmlAdsSide = preg_replace('//', $htmlAdsSide, $template); } } $htmlAdsBot = ''; if (NUM_ADS_BOT <> 0) { $htmlAdsBot = getFeed(FEED_ADS_BOT, $keywords, STARTNUM_ADS_BOT, NUM_ADS_BOT, TEMPLATE_CAT_ADS_BOT_LISTING, $yahooPartner, $yahooType); if ($htmlAdsBot <> '') { $template = loadTemplate(TEMPLATE_CAT_ADS_BOT); $htmlAdsBot = preg_replace('//', $htmlAdsBot, $template); } } // Build info section $htmlInfo = ''; //""; // Build Header/Footer $htmlHeader = ($category == '') ? loadTemplate(TEMPLATE_HEADER) : loadTemplate(TEMPLATE_HEADER_CATEGORY); $htmlHeader = preg_replace('//', $catTitle, $htmlHeader); $htmlHeader = preg_replace('//', $catTitle, $htmlHeader); $htmlHeader = preg_replace('//', HTML_CAT_TITLE, $htmlHeader); $htmlHeader = preg_replace('//', $htmlBreadcrumb, $htmlHeader); $htmlHeader = preg_replace('//', $queryParams, $htmlHeader); $htmlHeader = preg_replace('//', $parmChannel, $htmlHeader); $htmlHeader = preg_replace('//', $parmLanguage, $htmlHeader); $htmlHeader = preg_replace('//', $parmEncoding, $htmlHeader); $htmlHeader = preg_replace("/=\"c\"\svalue=\"$parmCountry\"\s\/>/", "=\"c\" value=\"$parmCountry\" checked=checked />", $htmlHeader); if ($parmType == 'dir' && $parmSearch == '') { $htmlHeader = preg_replace('//', '', $htmlHeader); } else { $htmlHeader = preg_replace('//', $category, $htmlHeader); } $htmlFooter = loadTemplate(TEMPLATE_FOOTER_CATEGORY); $htmlFooter = preg_replace('//', $queryParams, $htmlFooter); $htmlFooter = preg_replace('//', $parmChannel, $htmlFooter); $htmlFooter = preg_replace('//', $parmLanguage, $htmlFooter); $htmlFooter = preg_replace('//', $parmEncoding, $htmlFooter); $htmlFooter = preg_replace("/=\"c\"\svalue=\"$parmCountry\"\s\/>/", "=\"c\" value=\"$parmCountry\" checked=checked />", $htmlFooter); if ($parmType == 'dir') { $htmlFooter = preg_replace('//', '', $htmlFooter); } else { $htmlFooter = preg_replace('//', $category, $htmlFooter); } // Build page $html = loadTemplate(TEMPLATE_CAT); $html = preg_replace('//', $htmlInfo, $html); $html = preg_replace('//', $catTitle, $html); $html = preg_replace('//', $htmlBreadcrumb, $html); $html = preg_replace('//', $htmlSubcats, $html); $html = preg_replace('//', $htmlSites, $html); $html = preg_replace('//', $htmlAdsTop, $html); $html = preg_replace('//', $htmlAdsSide, $html); $html = preg_replace('//', $htmlAdsBot, $html); if ($parmType == 'dir' && $parmSearch == '') { $html = preg_replace('//', '', $html); } else { $html = preg_replace('//', $category, $html); } $html = $htmlHeader.$html.$htmlFooter; } print $html; ?>