<?php

// DO NOT EDIT THIS FILE

function getSearchContents()
{
  global $file;
  global $i;
  global $scriptName;
  global $search;
  global $jstart;
  global $scriptSearchName;

  $begGroup = "Groups of reviewed web sites related to your search term";
  $endGroup = "</ul>";
  $oldURL = "http://directory.netscape.com/";
  $newURL = $scriptName."?dir=";
  $catRegex = "<LI><a href=\"(.*)\">(.*)</a> <FONT SIZE=1>- found in: (.*) </FONT>.*";

  $begSite = "Web sites reviewed and categorized by a team of editors";
  $endSite = "</ul>";
  $siteRegex = "<a href=\"(.*)\">(.*)</a>.*<BR>(.*)<FONT size=1>.*found in: (.*) <a href=\"(.*)\">(.*)</a>.*";

  $nextlink = $scriptSearchName."?search=$search&cp=srpnext10&jstart=$jstart";

  $m = 0;
  $j = 0;
  do
  {
    // find $begGroup which starts the category hits
    $found = 0;
    while ((!$found) && ($i <= sizeof($file)))
    {
       if (eregi($begGroup,$file[$i]))
       {
         $line[$j] = $file[$i];
         $found = 1;
       }
       $i++;
    }
    // grab everything from here til the $endGroup
    $found = 0;
    $j++;

    while ((!$found) && ($i <= sizeof($file)))
    {
       $line[$j] = $file[$i];
       if (eregi($endGroup,$file[$i]))
       {
         $found = 1;
         $lastline = $i;
       }
       $i++;
       $j++;
    }
    $j++;
    $m++;
  }
  while ($i <= sizeof($file));

  for ($i = 0 ; $i < sizeof ($line) ; $i++)
  {
    $line2 = eregi_replace($oldURL, $newURL, $line[$i]);
    unset($regs);
    eregi($catRegex,$line2, $regs);
    if (sizeof ($regs) > 1)
    {
        $caturl[] = $regs[1];
        $catname[] = $regs[2];
        $foundin[] = $regs[3];
    }
  }

  do
  {
    // find $begSite which starts the categroy hits
    $found = 0;
    while ((!$found) && ($i <= sizeof($file)))
    {
       if (eregi($begSite,$file[$i]))
       {
         $line3 = $line3.$file[$i];
         $found = 1;
       }
       $i++;
    }
    // grab everything from here til the next $endSite
    $found = 0;
    $j++;

    while ((!$found) && ($i <= sizeof($file)))
    {
       $line3 = $line3.$file[$i];
       if (eregi($endSite,$file[$i]))
       {
         $found = 1;
         $lastline = $i;
       }
       $i++;
       $j++;
    }

    $j++;
    $m++;
  }
  while ($i <= sizeof($file));

  // split line3
  $linkbits = explode ("<li>",$line3);

  // now print the stuff to see what we've got
  for ($i = 0 ; $i < sizeof ($linkbits) ; $i++)
  {
    $line4 = eregi_replace($oldURL, $newURL, $linkbits[$i]);
    unset($regs2);
    eregi($siteRegex,$line4, $regs2);
    if (sizeof ($regs2) > 1)
    {
        $linkurl[] = $regs2[1];
        $linkname[] = $regs2[2];
        $description[] = $regs2[3];
        $category[] = $regs2[4]." ".$regs2[6];
        $categoryurl[] = $regs2[5];
    }
  }

  return array ($caturl, $catname, $foundin, $linkurl, $linkname, $description, $category, $categoryurl, $nextlink);
}

function outputSearchTemplates ()
{
   global $caturl;      // category url
   global $catname;     // name of category
   global $foundin;     // higher level category name
   global $linkurl;     // url of outside site link
   global $linkname;    // name of outside site link
   global $description; // description of outside site link
   global $category;    // category outside site link is in
   global $categoryurl; // url of category of link
   global $search;      // search term
   global $nextlink;    // link to next x hits
   global $nocats;
   global $nolinks;
   global $templateDir; // directory containing the templates


   $tpl = new FastTemplate($templateDir);

   $tpl->define(
   	array(
   		main    => "search.tpl",
   		cat     => "searchcats.tpl",
     link     => "searchlinks.tpl"
   	)
   );

   $tpl->define_dynamic("catrow", "cat");
   $tpl->define_dynamic("linkrow", "link");

   $tpl->assign(array(SEARCHTERM => rawurldecode($search),
                      SEARCHBOX => getSearchBox (),
                      NEXT => $nextlink,
                      BECOMEANEDITOR => becomeAnEditor()
                      ));

   if (sizeof($catname) == 0)
   {
      $tpl->assign(array(CATEGORYROWS => $nocats
                      ));
   }
   else
   {
      for ($i = 0 ; $i < sizeof($catname) ; $i++)
      {
      	$tpl->assign(
      		array(
      			CATURL		=>	$caturl[$i],
      			CATEGORY	=>	$catname[$i],
         FOUNDIN	=>	$foundin[$i]
      		)
      	);

      	$tpl->parse(CATEGORYROWS,".catrow");
      }
      $tpl->parse(CATEGORYROWS, array ("cat")); // 1
   }

   if (sizeof($linkname) == 0)
   {
      $tpl->assign(array(LINKROWS => $nolinks
                      ));
   }
   else
   {
      for ($i = 0 ; $i < sizeof($linkname) ; $i++)
      {
      	$tpl->assign(
      		array(
      			LINKURL		=>	$linkurl[$i],
      			LINKNAME	=>	$linkname[$i],
         DESCRIPTION => $description[$i],
         LINKCAT => $category[$i],
         LINKCATURL => $categoryurl[$i]
      		)
      	);

   	   $tpl->parse(LINKROWS,".linkrow");
      }
      $tpl->parse(LINKROWS, array ("link"));
   }


   $tpl->parse(MAIN, array ("main"));

   $tpl->FastPrint();
}


?>
