Wiki Tree

<?php

function crawlWiki($node_title,$depth){

$query = "select n.nid,nr.body,n.title from node as n left join node_revisions as nr on n.vid = nr.vid where type='wiki' and n.title like '$node_title' limit 1";
$result = mysql_query($query);

if($result){
$wiki_entry = mysql_fetch_object($result);

$regex = '/\[\[(.*)\]\]/Ui';
$link_array = array();
preg_match_all($regex,$wiki_entry->body,$link_array);

if ($wiki_entry){
$encoded_title = urlencode($wiki_entry->title);
if (count($link_array) > 0){
print "

  • $wiki_entry->title  nid'>[view]
  • \n";
    } else {
    print "$wiki_entry->title  nid'>[view]

    \n";
    }

    } else {
    print "

  • $node_title [create]
  • "; return;
    }

    if ($depth < 2 && count($link_array) > 0){
    print "

      \n";
      foreach(array_unique($link_array[1]) as $value){
      $value = preg_replace("/\|.+/","",$value);
      $exceptions = "Indices,Designers,Foundries,Typefaces,Publications,Blogs,Writers,Font Retailers,Books";
      if (!stristr($exceptions,$value)){
      crawlWiki($value,$depth+1);
      }
      }
      print "

    \n";
    }
    }

    }
    print "

      \n";
      $start = "Indices";
      if (isset($_GET['s'])) {
      $start = $_GET['s'];
      }
      crawlWiki($start,0);
      print "
        \n";
        ?>