From 57f02306e09ee78802bab35f8dd599372c46a31a Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 29 Jan 2006 17:54:06 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2, which included commits to RCS files with non-trunk default branches. --- php/leftbar.php | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 php/leftbar.php (limited to 'php/leftbar.php') diff --git a/php/leftbar.php b/php/leftbar.php new file mode 100644 index 0000000..05e3213 --- /dev/null +++ b/php/leftbar.php @@ -0,0 +1,186 @@ +url=$u; + $this->text=$t; + } +} + +function LB_LeftHeader($hdr) +{ + printf('

%s

',$hdr); +} + +function LB_TopLink($url,$txt) +{ + printf('',$url,$txt); +} + +function LB_SubLink($url,$txt) +{ + printf('
  • %s
  • ',$url,$txt); +} + +function LB_OpenLink(&$is_open) +{ + if (!$is_open) + { + $is_open = TRUE; + echo ''; + echo ''; + } +} + +function LeftBar($file, $context = '') +{ + $fp = fopen($file,'r'); + + if (!$fp) + { + printf('

    Missing leftbar config %s!

    ',$file); + return; + } + + $links = array(); + $curcontext = ''; + $in_link = FALSE; + $in_sub = FALSE; + + while (!feof($fp)) + { + $line = fgets($fp,1024); + + $line = rtrim($line); + + if (strlen($line)>0 && substr($line,0,1)!='#') + { + $tok = explode("\t",$line); + + switch($tok[0]) + { + case 'def': + if (count($tok)==4) + { + $links[$tok[1]] = new LB_LinkDef($tok[3],$tok[2]); + } + else + { + printf('

    WARNING: Bad "def"

    '); + } + break; + + case 'set': + if (count($tok)==2) + { + LB_CloseSub($in_sub); + LB_CloseLink($in_link); + LB_LeftHeader($tok[1]); + } + else + { + printf('

    WARNING: Bad "set"

    '); + } + break; + + case 'link': + if (count($tok)==3) + { + LB_CloseSub($in_sub); + LB_OpenLink($in_link); + $ldef = $links[$tok[1]]; + $curcontext = $tok[2]; + LB_TopLink($ldef->url,$ldef->text); + } + else + { + printf('

    WARNING: Bad "link"

    '); + } + break; + + case 'sub': + if (count($tok)==2) + { + if ($curcontext == $context) + { + LB_OpenSub($in_sub); + $ldef = $links[$tok[1]]; + LB_SubLink($ldef->url,$ldef->text); + } + } + else + { + printf('

    WARNING: Bad "sub"

    '); + } + break; + + default: + printf('

    WARNING: Bad line "%s"

    ',$line); + break; + } + } + } + + LB_CloseSub($in_sub); + LB_CloseLink($in_link); + + fclose($fp); +} +?> -- cgit v1.2.3