<?php
include "Snoopy.class.inc";

$a = 0;
$noOfLinks = 0;
$noOfCats = 0;
$updateList = "";

function checkReferer ($referer) {

        if (preg_match ('¤^http://www\.kor\.dk¤i', $referer)) {
                return 1;
        }
        if (preg_match ('¤^http://kor\.dk¤i', $referer)) {
                return 1;
        }
        return 0;
}

function readfirstsite ($URI, $levels, $listeditors) {

//        $URI = urlencode($URI);
//        $URI = preg_replace ("¤%2C¤", ",", $URI);
//        echo "read " . $URI . " - " . $levels . " - " . $listeditors . "<br>";
        if ($levels < 1) return;
        if (preg_match ('¤^/*(.*)/*$¤', $URI, $arr)) {
                $URI = "/" . $arr[1];
        }

        global $snoopyCache;

        $snoopy = new Snoopy;
        $snoopy->user = "wkn";
        $snoopy->pass = "werner3";
        $snoopy->expandlinks = false;
        $found = $snoopy->fetchlinks("http://musicmoz.org/" . $URI);

        if ($snoopy->status == 200)
        {
                $snoopyCache = $snoopy;
                return 1;
        } else {
                return 0;
        }
}

function readsite ($URI, $levels, $listeditors) {

//        $URI = urlencode($URI);
//        $URI = preg_replace ("¤%2C¤", ",", $URI);
//        echo "read " . $URI . " - " . $levels . " - " . $listeditors . "<br>";
        if ($levels < 1) return;
        if (preg_match ('¤^/*(.*)/*$¤', $URI, $arr)) {
                $URI = "/" . $arr[1];
        }

        global $snoopyCache;
        global $a;
        global $green;
        global $greens;
        global $reds;
        global $unrev;
        $a++;
        if ($snoopyCache) {
                $snoopy = $snoopyCache;
                $found = 1;
        } else {
                $snoopy = new Snoopy;
                $snoopy->expandlinks = false;
                $snoopy->user = "wkn";
                $snoopy->pass = "werner3";
                $found = $snoopy->fetchlinks("http://musicmoz.org/" . $URI);
        }
        $snoopyCache = '';
        if ($found)
        {
//                echo "response code: ".$snoopy->response_code."<br>\n";
//                while(list($key,$val) = each($snoopy->headers))
//                        echo $key.": ".$val."<br>\n";
//                echo "<p>\n";

                trimCat ($URI, $baseLevel);

                for($x=0;$x<count($snoopy->results);$x++)        {
                        $str = $snoopy->results[$x];
                        $mask = "¤^" . urldecode($URI) . "¤i";
                        $mask = preg_replace ('¤\+¤', '\\+', $mask);
                        $link = urldecode($str);
//                        echo $URI . "---" . $link . "---" . $mask . "<br>";
                        $dURI = str_replace ("¤", "_skildpadde_", urldecode($URI));
                        $dURI = str_replace ("|", "_lodretstreg_", $dURI);
                        $dmask = "¤" . $dURI . "¤i";
                        $dmask = preg_replace ('¤\+¤', '\\+', $dmask);
                        $dlink = str_replace ("¤", "_skildpadde_", $link);
                        $dlink = str_replace ("|", "_lodretstreg_", $dlink);
//                        if ((preg_match ($mask, $link))
                        if ((preg_match ($dmask, $dlink))
                        &&  (! strpos ($link, ".htm"))) {
                                if ($listeditors) {
                                        $editors = fetchEditors ($str, $desc);
                                }
                                trimCat ($str, $nextLevel);
                                if ($nextLevel == $baseLevel + 1) {
                                        printCat ($editors, $str, $a, $desc);
                                        if ((! $green)||($greens[$a] > 0)||($reds[$a] > 0)) {
                                                readsite ($str, $levels - 1, $listeditors);
                                        }
                                }
                        }
                }
        }
        else
                echo "error fetching document: ".$snoopy->error."\n";
        $a--;
}

function sendToSingle ($editors, $text) {
        global $target;
        if ($editors) while (list ($editor, $cats) = each ($editors)) {
//                if ($eds) $eds .= ",+" . $editor;
//                else $eds = $editor;
                if ($eds) $eds .= "+" . $editor;
                else $eds = $editor;
        }
        $str  = "<a href='http://musicmoz.org/editors/send.cgi?toeditor=" . $eds;
//        $str  = "<a href='http://www.primeline.com/~newwave/odp/sendtomany.mv?editor_list=" . $eds;
//        $str  = "<a href=http://newwave.primeline.com/dmoz/multi-feedback.kizml?toeditors=" . $eds;
        $str .= "' target='" . $target . "'>" . $text . "</a>";
        return $str;
}

function sendToForm ($editors, $text) {
        global $target;
        if ($editors) while (list ($editor, $cats) = each ($editors)) {
                if ($eds) $eds .= " " . $editor;
                else $eds = $editor;
        }
        $str  = "<form method='post' action='http://musicmoz.org/editors/send.cgi'";
        $str .= " target='" . $target . "'>";
        $str  .= "<input type=hidden name=toeditor value='" . $eds;
        $str .= "'>";
        $str .= "<input type=submit value='" . $text . "'>";
        $str .= "</form>";
        return $str;
}

function edSpiderLink ($editors, $text) {
        global $target;
        if ($editors) while (list ($editor, $cats) = each ($editors)) {
                if ($eds) $eds .= ",+" . $editor;
                else $eds = $editor;
        }
        $str  = "<a href='http://www.kor.dk/odp/edspider.php3?editors=" . $eds;
        $str .= "' target='" . $target . "'>" . $text . "</a>";
        return $str;
}

function edSpiderForm ($editors, $text) {
        global $target;
        if ($editors) while (list ($editor, $cats) = each ($editors)) {
                if ($eds) $eds .= " " . $editor;
                else $eds = $editor;
        }
        $str  = "<form method='post' action='http://www.kor.dk/odp/edspider.php3'";
        $str .= " target='" . $target . "'>";
        $str  .= "<input type=hidden name=editors value='" . $eds;
        $str .= "'>";
        $str .= "<input type=submit value='" . $text . "'>";
        $str .= "</form>";
        return $str;
}

function editorLink ($editor) {
        global $target;
        $str = "<a href='http://musicmoz.org/editors/profile.cgi?editor="
           . $editor . "' target='" . $target . "'>" . $editor . "</a>";
        return $str;
}

function trimCat ($cat, &$levels) {
        $prcat = $cat;
        if (preg_match ('¤^\s*(\S.*\S)\s*$¤', $prcat, $arr)) {
                $prcat = $arr[1];
        }
        if (preg_match ('¤\.org/(.*)$¤', $prcat, $arr)) {
                $prcat = $arr[1];
        }
        if (preg_match ('¤cat=(.*)$¤', $prcat, $arr)) {
                $prcat = $arr[1];
        }
//        $prcat = preg_replace ("¤%27¤", "'", $prcat);
        $prcat = preg_replace ('¤:\s*¤', '/', $prcat);
        $prcat = preg_replace ('¤\s¤', '_', $prcat);
        if (preg_match ('¤^/*(.*)$¤', $prcat, $arr)) {
                $prcat = $arr[1];
        }
        if (preg_match ('¤^/*(.*)/$¤', $prcat, $arr)) {
                $prcat = $arr[1];
        }
        $prcat = urldecode ($prcat);
        $part = split ('/', $prcat);
        $levels = count ($part);
        return $prcat;
}

function printCat ($editors, $str, $level, $desc) {
        global $depth;

        global $noOfCats;
        global $noOfLinks;
        global $startlevel;
        global $origcool;
        global $origlisteditors;
        global $localeditorlist;
        global $updateList;
        global $target;
        global $cool;
        global $coollist;
        global $noOfCooled;
        global $kiss;
        global $green;
        global $greens;
        global $red;
        global $reds;
        global $fetchedReds;
        global $unrev;
        global $session;
        global $HTTP_HOST;
        global $PHP_SELF;

        $greens[$level] = 0;
        $reds[$level] = 0;
        if ($unrev) {
                $greens[$level] = fetchGreens ($str);
                $reds[$level] = $fetchedReds;
        }
        if ($green) {
                if (($greens[$level] < 1)&&($reds[$level] < 1)) return;
        }

        $noOfCats++;
        $prcat = trimCat ($str, $levels);
        $part = split ('/', $prcat);
        if ($level > 0) {
                $subcat = $part [$startlevel + $level - 1];
        } else $subcat = $prcat;

        if ($updateList == "") {
                $updateList = $prcat;
        } else {
                $updateList = $updateList . ',' . $prcat;
        }

        if ($noOfCats % 2 == 1)
                $bg = "#eeeeee";
        else
                $bg = "#ffffff";

        echo "<table border=0 cellpadding=0 cellspacing=0 width=90%><tr><td valign=top bgcolor=" . $bg . " width=90%>";
        if (! $kiss ) {
                echo "<a href='http://$HTTP_HOST$PHP_SELF?upwards=1&listeditors=" . $origlisteditors . "&cool=" . $origcool . "&unrev=" . $unrev. "&session=" . $session . "&green=" . $green . "&red=" . $red . "&depth=" . $depth . "&cat=" . urlencode($prcat) . "'><img src=http://kor.dk/odp/up.gif border=0></A>";
                echo "<a href='http://$HTTP_HOST$PHP_SELF?upwards=&listeditors=" . $origlisteditors . "&cool=" . $origcool . "&unrev=" . $unrev . "&session=" . $session . "&green=" . $green . "&red=" . $red . "&depth=" . $depth . "&cat=" . urlencode($prcat) . "'><img src=http://kor.dk/odp/dn.gif border=0></A>&nbsp;";
        }
  $spacer = "";
        for($x=0;$x<$level;$x++) {
                $spacer = $spacer . ". . ";
        }
//        $spacer = "<img src='http://kor.dk/odp/1x1trans.gif' height=1 width="
//        .($level*10)
//        ." alt='s' align=middle>";
        echo $spacer;

//        echo "<a href='http://musicmoz.org/" . urlencode($prcat) . "/' target='" . $target . "'>" . urldecode($subcat) . "</a>";
        echo "<a href='http://musicmoz.org/" . urlencode($prcat) . "/' target='" . $target . "'>" . $subcat . "</a>";

        if ($greens[$level] > 0) echo " (<font color=green>$greens[$level]</font>";
        if ($reds[$level] > 0) {
                if ($greens[$level] < 1) echo " (<font color=green>0</font>";
                echo ", ";
                echo "<font color=red>$reds[$level]</font>";
        }
        if (($greens[$level] > 0)||($reds[$level] > 0)) echo ")";

        if (! $kiss ) {
                echo $desc;
          if(count($editors) == 1)        { echo " - Editor "; }
          if(count($editors) >  1)        { echo " - Editors "; }
          if(count($editors) >  0)        {
                  echo editorLink ($editors[0]);
                  for($y=1;$y<count($editors);$y++)        {
                          echo ", " . editorLink ($editors[$y]);
                  }
                  echo " <font size='-1'> ";
                  if(count($editors) >  0){
                          echo " " . sendToSingle ($localeditorlist, "[feedback]") . " ";
                  }
                  echo " " . edSpiderLink ($localeditorlist, "[more info]") . " ";
                  echo " </font> ";
          }
         }
        if (($cool) && (is_array($coollist))) {
                 foreach ($coollist as $coollink) {
                        $coollink = str_replace ("<b>", "", $coollink);
                        $coollink = str_replace ("</b>", "", $coollink);
                        echo " <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                        for($x=0;$x<$level;$x++) {
                                echo "&nbsp;&nbsp;&nbsp;&nbsp;";
                        }
                        echo "&nbsp;";
                        echo " <font size='-1'> ";
                        echo $coollink;
                        echo " </font> ";
                }
        }
//        echo " - " . $noOfLinks . " links";
        echo "</td>";

        if (! $kiss ) {
          echo "<td valign=top width=30 bgcolor=" . $bg . ">";
          echo "<font size='-1'>";
          echo "&nbsp;[<a href='http://musicmoz.org/editors/editcat.cgi?cat=" . urlencode($prcat) . "' target='" . $target . "'>edit</A>]";
          echo "&nbsp;[<a href='http://www.kor.dk/odp/linkspider.php3?keywords=sex,porn,xxx,adult&noMultiUrl=1&url=http://musicmoz.org/" . urlencode($prcat) . "/' target='" . $target . "'>check</A>]";
  //        echo "&nbsp;[<a href='http://himitsu.selfpromotion.com/demozulator.t?PAGE=http://musicmoz.org/" . urlencode($prcat) . "/' target='" . $target . "'>check</A>]";
//          echo "&nbsp;[<a href='http://musicmoz.org/editors/multilink.cgi?cat=" . urlencode($prcat) . "' target='" . $target . "'>add</A>]";
//          echo "&nbsp;[<a href='http://www.kor.dk/odp/category_logs.php3?name=" . urlencode($prcat) . "' target='" . $target . "'>logs</A>]";
//          echo "&nbsp;[<a href='http://musicmoz.org/Bookmarks/W/wkn/Pop/desc.html?cat=" . urlencode($prcat) . "' target='" . $target . "'>update</A>]";
  //        echo "&nbsp;[<a href='http://$HTTP_HOST$PHP_SELF?upwards=1&listeditors=" . $origlisteditors . "&depth=" . $depth . "&cat=" . urlencode($prcat) . "'>up</A>]";
  //        echo "&nbsp;[<a href='http://$HTTP_HOST$PHP_SELF?upwards=&listeditors=" . $origlisteditors . "&depth=" . $depth . "&cat=" . urlencode($prcat) . "'>down</A>]";
          echo "&nbsp;";
          echo "</font>";
          echo "</td>";
        }
        echo "</tr></table>";
//        echo "<br>";
        flush();
}

function fetchEditors ($URI, &$desc) {

        global $editorlist;
        global $cool;
        global $coollist;
        global $localeditorlist;
        global $noOfLinks;
        global $noOfCooled;
        global $target;
        global $snoopyCache;

        $noOfLinks = 0;
        $noOfCooled = 0;
        $localeditorlist = "";
        $coollist = "";
        $snoopy = new Snoopy;
        $snoopy->user = "wkn";
        $snoopy->pass = "werner3";
        $snoopy->expandlinks = false;

        if($snoopy->fetchlinks("http://musicmoz.org/" . $URI))
        {
                $snoopyCache = $snoopy;

                // Check for description
                $desc = " - <a href='http://musicmoz.org/editors/editcatdesc.cgi?cat="
                . $URI
                . "' target='" . $target . "'><FONT color=red>no description</FONT></a>";
                $descOK = " - <a href='http://musicmoz.org/editors/editcatdesc.cgi?cat="
                . $URI
                . "' target='" . $target . "'><FONT color=green>desc</FONT></a>";
                for($x=0;$x<count($snoopy->results);$x++)        {
                        $str = $snoopy->results[$x];
                        if (preg_match ("¤desc¤", $str, $arr)) {
                                $desc = $descOK;
                        }
                }
                // Find editors
                for($x=0;$x<count($snoopy->results);$x++)        {
                        $str = $snoopy->results[$x];
                        if (preg_match ('¤^/profiles/(.*)\.¤', $str, $arr)) {
                                $editors[] = $arr[1];
                                $editorlist[$arr[1]]++;
                                $localeditorlist[$arr[1]]++;
                        }
                        if (preg_match ("¤http://¤", $str)) {
                                $noOfLinks++;
                        }
                }
                // Find cooled sites
                if ($cool) {
                  preg_match_all ("/<li>(.*?)<img(.*?)star\.gif/im", $snoopy->fetched, $regs);
                  $i=0;
                  foreach ($regs[1] as $loop_result) {
                          $coollist[] = '<img src="http://www.kor.dk/odp/star.gif" align=middle width=15 height=16 alt="cool">&nbsp;' . $loop_result . '';
  //                        echo $coollist[$i];
                          $i++;
                  }
                        $noOfCooled = $i;
                }

                return $editors;
        }
        else
                echo "error fetching document: ".$snoopy->error."\n";
}

function fetchRedGreenBySymlink ($catg) {

$str = '';
$cat = urlencode($catg);
$cat = preg_replace ('¤%2F¤', '/', $cat);
$cat = preg_replace ('¤%5C%27¤', "%27", $cat);
$cat = preg_replace ('¤%E¤', '%e', $cat);
$cat = preg_replace ('¤%eA¤', '%ea', $cat);
$cat = preg_replace ('¤%eB¤', '%eb', $cat);
$cat = preg_replace ('¤%eC¤', '%ec', $cat);
$cat = preg_replace ('¤%eD¤', '%ed', $cat);
$cat = preg_replace ('¤%eE¤', '%ee', $cat);
$cat = preg_replace ('¤%eF¤', '%ef', $cat);
$cat = preg_replace ('¤%F¤', '%f', $cat);
$cat = preg_replace ('¤%FA¤', '%fa', $cat);
$cat = preg_replace ('¤%FB¤', '%fb', $cat);
$cat = preg_replace ('¤%FC¤', '%fc', $cat);
$cat = preg_replace ('¤%FD¤', '%fd', $cat);
$cat = preg_replace ('¤%FE¤', '%fe', $cat);
$cat = preg_replace ('¤%FF¤', '%ff', $cat);

srand((double)microtime()*1000000);
$title = rand(100000,999999);

        $snoopy = new Snoopy;
        $snoopy->expandlinks = false;
        $snoopy->user = "wkn";
        $snoopy->pass = "werner3";
        $snoopy->maxlength = 500;

          if($snoopy->fetch("http://musicmoz.org/editors/link2.cgi?cat=Bookmarks/W/wkn/Symlinks&linkcat=" . $cat . "&linkname=" . $title . ""))
          {
                        $snoopy->maxlength = 30000;
                        if($snoopy->fetch("http://musicmoz.org/editors/editcat.cgi?cat=Bookmarks/W/wkn/Symlinks"))
                  {
                                $symlinks = $snoopy->results;
                                $snoopy->maxlength = 500;
                                if($snoopy->fetch("http://musicmoz.org/editors/delink2.cgi?cat=Bookmarks/W/wkn/Symlinks&link=" . $title . "&locale=dan&submit=Bekræft"))
                          {
                                  if (preg_match ("/" . $title . "(.*)\)/im", $symlinks, $arr)) {
                                          $actual = $arr[1];
                                        } else {
                                          $actual = 'Not Found';
                                        }
                                  if (preg_match ("/color=\"green\">(\d*) /im", $actual, $arr)) {
                                          $greens = $arr[1];
                                        } else {
                                          $greens = 0;
                                        }
                                  if (preg_match ("/color=\"#cc0000\">(\d*) /im", $actual, $arr)) {
                                          $reds = $arr[1];
                                        } else {
                                          $reds = 0;
                                        }

                                $str  = urldecode($cat) . " has <B>" . $greens . "</B> unreviewed";
                                $str .= "<br>\n";
                                $str .= urldecode($cat) . " has <B>" . $reds . "</B> errors";
                                }
                        }
                }
        return $str;
}

function fetchRedGreenByService ($catg) {

  $snoopy = new Snoopy;
  $snoopy->expandlinks = false;

  $parmcat = utf8_encode(urldecode($catg));

//  if($snoopy->fetch("http://kor.dk/odp/redgreen.php3?cat=" . $catg))
  if($snoopy->fetch("http://dmoz.nurey.net/ViewUnrev.epl?cat=" . $parmcat))
  {
     $str = $snoopy->results;
  } else
  {
     echo "error fetching document: ".$snoopy->error."\n";
     $str = "";
  }
  return $str;
}

function fetchRedGreen ($catg) {

  global $red;

  if ($red) {
    $str = fetchRedGreenBySymlink ($catg);
  } else {
    $str = fetchRedGreenByService ($catg);
  }
  return $str;
}

function fetchGreens ($cat) {

        global $target;
        global $snoopyCache;
        global $fetchedReds;

        $fetchedReds = -1;
        $snoopy = new Snoopy;
        $snoopy->expandlinks = false;

        $parmcat = utf8_encode(urldecode($cat));
//        $parmcat = imap_utf8($cat);
//        $parmcat = urldecode($cat);
//        echo "[". $parmcat . "]";

        $rawheaders["Content-type"]="text/html;charset=UTF-8";
        $submit_vars["cat"] = urldecode($cat);

//        if($snoopy->submit("http://dmoz.nurey.net/ViewUnrev.epl", $submit_vars))
//        $str = implode("", file("http://dmoz.nurey.net/ViewUnrev.epl?cat=" . $parmcat));

//        if($snoopy->fetch("http://dmoz.nurey.net/ViewUnrev.epl?cat=" . $parmcat))
//        if($snoopy->fetch("http://kor.dk/odp/redgreen.php3?cat=" . $cat))
        if(true)
        {
//                $str = $snoopy->results;
                $str = fetchRedGreen ($cat);
                if (preg_match ("/has <B>(\d*)<\/B> unreviewed/im", $str, $matches)) {
                        $greens = $matches[1];
                } else {
                        $greens = -1;
                }
                if (preg_match ("/has <B>(\d*)<\/B> errors/im", $str, $matches)) {
                        $fetchedReds = $matches[1];
                } else {
                        $fetchedReds = -1;
                }
                return $greens;
        }
        else
                echo "error fetching document: ".$snoopy->error."\n";
}

function printFooter () {
        global $HTTP_HOST;
        global $PHP_SELF;

        print "
<p>
<A HREF='http://$HTTP_HOST$PHP_SELF'><img src='http://www.kor.dk/odp/catspider.gif' align=right border=0></A>
Spider tools by <A HREF=http://musicmoz.org/editors/profile.cgi?editor=wkn>wkn</A> since September 2000.
<br>
<A HREF='http://musicmoz.org/Test/Editors/W/wkn/Tools/'>Go to Spider Tools list and support</A>..
<br clear=all>
</blockquote>
<p>
<table border=0 bgcolor='#669933' cellpadding=2 cellspacing=0 width='100%'><tr><td valign=middle>
<font color='#ffffff' face='sans-serif, Arial, Helvetica' size='-2'>
&nbsp; &nbsp;
Copyright &copy; 2000-02 Werner Knudsen
</font>
</td></tr></table>
</body></html>
        ";
}

// Main program starts here //

if ($refresh == "yes") {
  srand ((double) microtime() * 10000000);
  $randval = rand();
  header ("Location: http://$HTTP_HOST$PHP_SELF?" . $randval);
  exit;
}

$cat = trimCat ($cat, $startlevel);
if ((! $cat) || (strlen($cat) < 4)) {
        // read input file into an array and print it out
        $fcontents = file ('musicspider.htm');
        while (list ($line_num, $line) = each ($fcontents)) {
                if ($catCookie) {
                        $line = preg_replace ('¤Write category\, or click the Spider image for your last crawl¤', $catCookie, $line);
                }
                echo $line . "\n";
        }
        exit;
}

if (! $target) {
        $target = "_blank";
}

$cat = urlencode($cat);
$cat = preg_replace ('¤%2F¤', '/', $cat);
$cat = preg_replace ('¤%5C%27¤', "%27", $cat);
$cat = preg_replace ('¤%E¤', '%e', $cat);
$cat = preg_replace ('¤%eA¤', '%ea', $cat);
$cat = preg_replace ('¤%eB¤', '%eb', $cat);
$cat = preg_replace ('¤%eC¤', '%ec', $cat);
$cat = preg_replace ('¤%eD¤', '%ed', $cat);
$cat = preg_replace ('¤%eE¤', '%ee', $cat);
$cat = preg_replace ('¤%eF¤', '%ef', $cat);
$cat = preg_replace ('¤%F¤', '%f', $cat);
$cat = preg_replace ('¤%FA¤', '%fa', $cat);
$cat = preg_replace ('¤%FB¤', '%fb', $cat);
$cat = preg_replace ('¤%FC¤', '%fc', $cat);
$cat = preg_replace ('¤%FD¤', '%fd', $cat);
$cat = preg_replace ('¤%FE¤', '%fe', $cat);
$cat = preg_replace ('¤%FF¤', '%ff', $cat);
//$cat = preg_replace ("/%(\w\w)/e", "'%'.strtolower('\\1')", $cat);

if ((! $depth) && ($depth != 0)) $depth = 1;
if ($cool) $listeditors = 1;
$origlisteditors = $listeditors;
$origcool = $cool;
if ($upwards) $listeditors = 1;

if ($catCookie) {
        $catCookie .= ";" . $cat;
} else {
        $catCookie = $cat;
}
$catCookie = $cat;
setcookie ("catCookie", $catCookie, time()+(1000*60*60*24*7));
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                      // always modified
header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
header ("Pragma: no-cache");                          // HTTP/1.0

echo "<html>";
echo "<head><title>MusicSpider " . $cat . "</title>";
//echo "$HTTP_REFERER\n";
//echo "$PHP_SELF\n";
?>

<base href="http://musicmoz.org/">
<script language="JavaScript" type="text/javascript">
<!--
<?php
echo "var thisSession = '$session';\n";
?>
function ran(limit) {
  num = Math.floor (1 + (limit-1)*Math.random());
  return num;
}
function doOnError() {
  alert('Please login to ODP to use this tool fully');
  thisSession = '';
}
function doOnAbort() {
  alert('ODP Login Aborted');
  thisSession = '';
}
function doOnLoad() {
  if (document.odp) {
    document.cat.src="http://www.kor.dk/odp/catspider4.gif";
  }
  if (thisSession == '') {
          thisSession = ran(100000);
  }
}
function doOnSubmit() {
  document.forms[0].session.value = thisSession;
}
function done() {
        document.cat.src='http://www.kor.dk/odp/catspider2.gif';
}

//-->
</script>

</head>
<body onLoad="done()" bgcolor="#ffffff" text="#000000" link="#003300" vlink="#660000"
alink="#FF0000"><p><center><table border=0 bgcolor="#669933" cellpadding=3
cellspacing=0 width="100%"><tr><td align=left valign=middle> &nbsp;
<a href="/"><!--img src="/img/odphead.gif" width=222 height=25 align=middle
border=0 alt="Open Directory Project"-->MusicMoz</a></td></tr><tr><td bgcolor="#cccccc"
align=right><font color="#666666" face="sans-serif, Arial, Helvetica"
size="-1"><a href="/">home</a> |
<a href="http://musicmoz.org/Test/Editors/W/wkn/Tools/">feedback</a></font></td></tr>
</table></center>

<blockquote>

<?php

srand ((double) microtime() * 10000000);
$randval = rand();

$urlcat = urldecode($cat);

if ($green) $unrev = 1;
if ($red) $unrev = 1;
if ($unrev) $red = 1;
$unrevchecked = "";

$editorchecked = "";
if ($origlisteditors) $editorchecked = "checked";
$coolchecked = "";
if ($origcool) $coolchecked = "checked";
$upwardschecked = "";
if ($upwards) $upwardschecked = "checked";
$greenchecked = "";
if ($green) $greenchecked = "checked";
$redchecked = "";
if ($red) $redchecked = "checked";
$unrevchecked = "";
if ($unrev) $unrevchecked = "checked";

print "
<table align=right cellspacing=4 border=1>
<FORM action='http://$HTTP_HOST$PHP_SELF' method='POST' onSubmit='doOnSubmit()'>
  <tr><td bgcolor=#cccccc>
                    <table cellspacing=4 border=0>
                    <tr><td>Category:
                                                                                    </td><td>
                        <INPUT TYPE=TEXT SIZE=40 NAME=cat value='$urlcat'></td></tr>
                    <tr><td>
                                                                                    Depth:
                                                                                    </td><td>
                        <INPUT TYPE=TEXT NAME=depth SIZE=2 VALUE='$depth'>
                        &nbsp; Target:
                        <SELECT name=target>
                        <OPTION value='_self'>Same window</OPTION>
                        <OPTION value='_blank' selected>New window</OPTION>
                        <OPTION value='_top'>Top frame</OPTION>
                        </SELECT>
                    </td></tr>
                    <tr><td>
                        Editors:
                                                                                    </td><td>
                        <input type=checkbox name=listeditors value='1' $editorchecked>
                        &nbsp; CoolSpider:
                        <input type=checkbox name=cool value='1' $coolchecked>
                        &nbsp; Crawl upwards:
                        <input type=checkbox name=upwards value='1' $upwardschecked>
                    </td></tr>
<script language='JavaScript' type='text/javascript'>
<!--
document.write('<tr><td>');
document.write('  Unrev: ');
document.write('</td><td> ');
document.write('  <input type=checkbox name=unrev value=1 $unrevchecked>');
document.write('  &nbsp; RoboErrors: ');
document.write('  <input type=checkbox name=red value=1 $redchecked>');
document.write('  &nbsp; GreenSpider: ');
document.write('  <input type=checkbox name=green value=1 $greenchecked>');
document.write('</td></tr>');
//-->
</script>
<noscript>
                    <tr><td colspan=2>
                    JavaScript needed to use GreenSpider options.
                    </td></tr>
</noscript>
                    <tr><td colspan=2 align=center>
                        <input type='hidden' name=session value='$session'>
                        <input type='submit' value='Start crawling'>
                        &nbsp;&nbsp;
                        <input name='kiss' type='submit' value='Keep It Simple'>
                        &nbsp;&nbsp;
                        <input name='rdfeditors' type='submit' value='All Editors'>
                    </td></tr>
                    </table>
  </td></tr>
</FORM>
  </table>
";

echo "<A HREF='http://$HTTP_HOST$PHP_SELF?" . $randval . "'><img name='cat' src='http://www.kor.dk/odp/catspider4.gif' align=left border=0></A>";
echo "<!--img name='odp' src='http://musicmoz.org/forum/open.gif' width=1 height=1 border=0 alt=' ' onLoad='doOnLoad()' onAbort='doOnAbort()' onError='doOnError()'-->";

echo "<h2>MusicSpider</h2>";
echo "<h3>Crawling MusicMoz Directory</h3>";
/*
echo "<h3>Crawling " . urldecode($cat);
if ($upwards)
        echo " Upwards</h3>";
else
        echo " to a depth of " . $depth . "</h3>";
echo "<p>";
*/

echo "<br clear=all><br>";

if ((! checkReferer($HTTP_REFERER)) && ($unrev) && ($session)) {
        echo "<h3>Unauthorized access.</h3>";
        echo "<p>You must submit MusicSpider from an authorized url.</p>";
        echo "<p>Please go to the <a href='http://kor.dk/odp/musicspider.php3'>MusicSpider home page</a>.</p>";
        printFooter();
        exit;
}

// Login check suspended
if ((1 == 2) && (! $session) && ($unrev)) {
        echo "<h3>Editor login check completed. Please resubmit.</h3>";
        echo "<p><font size='-1'>If you get stuck in the login check, click the spider image and try again - it usually helps.</font></p>";
        printFooter();
        exit;
}

if ($rdfeditors) {

$rdfed = "";
$snoopy = new Snoopy;
$snoopy->expandlinks = false;
$snoopy->user = "wkn";
$snoopy->pass = "werner3";

$snoopy->maxlength = 5000;
if($snoopy->fetch("http://odp.gizmotech.net/gizmos/editors/index.pl"))
{
         $symlinks = $snoopy->results;
         if (preg_match ("/week ending ([^<]*)</i", $symlinks, $regs)) {
				   $week = " RDF dump current as of week ending " . $regs[1];
				 } else {
				   $week = " RDF dump date not known";
				 }
}

echo "<h3>All editors in " . $cat . " and below - " . $week . "</h3>";
flush();

$snoopy->maxlength = 6000000;
if($snoopy->fetch("http://odp.gizmotech.net/gizmos/editors/index.pl?default=entered&for=all&cat=" . urlencode($cat) . "&selcat=&checkboxes=checked&command=Submit"))
{
         $symlinks = $snoopy->results;
         preg_match_all ("/feedback\d*\" value=\"([^\"]*)\"/im", $symlinks, $regs);
         $i=0;
         foreach ($regs[1] as $title) {
  //                        $coollist[] = '<img src="http://www.kor.dk/odp/star.gif" align=middle width=15 height=16 alt="cool">&nbsp;' . $loop_result . '';
  //                        echo $coollist[$i];
                          if ($i > 0) $eds .= ", ";
                                      $eds .=  $title;
                          $rdfed[$title]++;
													$i++;

         }
         echo "<form><textarea wrap=virtual cols=60 rows=5>";
         echo $eds;
         echo "</textarea></form>";
         echo "<p>Number of editors listed: " . $i . ".</p>";
				 echo "<table summary='Forms' cellpadding='3' border='0'><tr><td>" . sendToForm ($rdfed, "Send Feedback to all") . "</td><td>";
				 echo edSpiderForm ($rdfed, "Send all to EdSpider") . " </td></tr>";
				 echo "<tr><td colspan=2 align=center><font size='-1'>Note: corrections in the above field will be ignored when submitting.</font></td></tr></table>";
         echo "<p>The information is extracted from TheSeeker's <a href='http://odp.gizmotech.net/gizmos/editors/'>Editor Watch</a> tool, and may be a week or so out of date. " . $week . "</p>";
}
        printFooter();
        exit;
}

flush();

if ($upwards) {
        $startlevel = 1;
        $part = split ('/', $cat);
        $levels = count ($part);
        for ($x=$levels; $x>0; $x--) {
                $upcat = $part[0];
                for ($y=1; $y<$x; $y++) {
                        $upcat .= "/" . $part[$y];
                }
                $editors = fetchEditors ($upcat, $desc);
                printCat ($editors, $upcat, $x-1, $desc);
        }
} else {
        if ($listeditors) {
                $editors = fetchEditors ($cat, $desc);
        }
        if (readfirstsite ($cat, $depth, $listeditors)) {
                printCat ($editors, $cat, 0, $desc);
                readsite ($cat, $depth, $listeditors);
        }
}

if ($noOfCats < 1) {
        echo "<h3>No categories to display.</h3>";
        printFooter();
        exit;
}

if (! $kiss ) {
  if ($listeditors) {
          echo "<p><table border=1 cellpadding=5 width=90% align=center><tr><td><b>Editor Summary:</b><br>";
  }
  if ($editorlist) while (list ($editor, $cats) = each ($editorlist)) {
          if ($cats == 1) echo editorLink ($editor) . " (" . $cats . " cat).<br>";
          else echo editorLink ($editor) . " (" . $cats . " cats).<br>";
  }
  if ($listeditors) {
          echo "</td></tr>";
          echo "<tr><td>";
          if (count ($editorlist) > 0) {
                  echo sendToSingle ($editorlist, "Send editor list to Multiple Editors Feedback");
  //                echo sendToSingle ($editorlist, "Send editor list to NewWave's Multiple Editors Feedback");
                  echo "<br>";
                  echo edSpiderLink ($editorlist, "Send editor list to EdSpider for further information");
          } else {
                  echo "No editors found.";
          }
          if ((preg_match ('¤gruban¤i', $cat)) || (preg_match ('¤newwave¤i', $cat))) {
                  echo "<br>Three cheers for Gruban and NewWave:";
                  for($i=0;$i<3;++$i) echo " Hurrah!";
          }
          echo "</td></tr>";
          echo "</table>";
  }
}

if (! $kiss ) {
  echo '<form action="http://www.kor.dk/odp/catdemoz.php3"  target="' . $target . '" method="POST">';
  echo '<input type="hidden" name="cat" value="' . $updateList . '">';
  echo '&nbsp;<input type=submit value="DeMozulate All Categories" align=middle>';
  echo '</form>';

  echo '<hr>Public Interface Update is experimental; use at your own risk!<br>';
  echo '<form action="http://musicmoz.org/Bookmarks/W/wkn/Pop/desc.html"  target="' . $target . '">';
  echo '<textarea name="cat" rows=3 cols=40 wrap=virtual>' . $updateList . '</textarea>';
  echo '&nbsp;<input type=submit value="Update Public Interface" align=middle>';
  echo '</form>';
  echo 'Useful for instance if string translations have changed.<hr>';
}

//echo '<p><a href="http://musicmoz.org/Bookmarks/W/wkn/Pop/desc.html?cat=' . $updateList . '"  target="' . $target . '">Update public interface for all categories</a>';

//echo $catCookie;
//echo urlencode("æøåäöáàâñéèëê");

printFooter();
?>
