\n";
else {
printgw();
}
}
function MkGW($pagename, $auth, $level)
{
global $LinkTargets, $gwStart, $links;
if (time() > $gwStart+10) { echo "."; $gwStart = time(); flush; }
#echo "MkGW($pagename, ...): Entering
\n";
$page = RetrieveAuthPage($pagename, $auth);
if (1) {
$text = $page['targets'];
$targets = explode(",", $text);
if (!$text) return(0); // indicates we've reached a node
} else {
$text = $page['text'];
if (!$text) return(0); // indicates we've reached a node
$LinkTargets = array();
$html = MarkupToHTML($pagename,$text); // calculate $LinkTargets as byproduct
# echo "MkGW: LinkTargets=".print_r($LinkTargets,true)."
\n";
$targets = array_keys((array)$LinkTargets);
}
if (!$targets) return(0); // indicates we've reached a node
$links[$pagename] = $targets;
foreach ($targets as $t) {
if (array_key_exists($t, $links)) {
} else {
# echo "MkGW($pagename): Calling MkGW($t)
\n";
MkGW($t, $auth, $level+1);
}
}
}
# See if there is a link from $from, to $to
# Delete it and return true if found (ie modifies the params it is passed!)
function findreverse($from, $to)
{
global $links;
if(array_key_exists($from, $links)) {
$nlinks = array();
$found = 0;
foreach ($links[$from] as $t) {
if (strcmp($t, $to) == 0) {
$found=1;
} else {
$nlinks[] = $t;
}
}
if ($found) {
$links[$from] = $nlinks;
return 1;
}
}
return 0;
}
function printgw()
{
global $links;
# Edit the next line as appropriate to format your graph notes
echo "
\ndigraph xyz {
\nsize=\"6,6\";
\nnode [color=lightblue2, style=filled];
\n";
foreach ($links as $k => $l)
echo "\"$k\" [URL=\"" . FmtPageName('$PageUrl', $k) . "\" target=\"_new\"];
\n";
foreach ($links as $k => $l) {
foreach ($l as $t) {
echo "\"$k\" -> \"$t\"";
# This section tries to avoid duplicate arrows in both directions and instead use a double headed arrow
# Personal preference really...
if (findreverse($t, $k))
echo " [dir=\"both\"]";
echo ";
\n";
}
}
echo "}
\n";
}