diff options
author | Ian C <ianc@noddybox.co.uk> | 2006-01-29 17:54:06 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2006-01-29 17:54:06 +0000 |
commit | 57f02306e09ee78802bab35f8dd599372c46a31a (patch) | |
tree | 0c84b800d4bda5e2155cc3a9b0d5459f34ed9fe9 /php | |
parent | a15a07a5797afd145348c29577b557c116228966 (diff) |
This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'php')
-rw-r--r-- | php/example.css | 79 | ||||
-rw-r--r-- | php/example1.php | 23 | ||||
-rw-r--r-- | php/example2.php | 23 | ||||
-rw-r--r-- | php/leftbar.php | 186 | ||||
-rw-r--r-- | php/leftbar.txt | 42 |
5 files changed, 353 insertions, 0 deletions
diff --git a/php/example.css b/php/example.css new file mode 100644 index 0000000..7fd715a --- /dev/null +++ b/php/example.css @@ -0,0 +1,79 @@ +.lb_toplink +{ + font-size: small; +} + +.lb_sublink +{ + font-size: x-small; +} + +body +{ + font-size: small; + font-family: sans-serif; + background: white; + color: black; +} + +a:link +{ + font-style: normal; + font-weight: bold; + text-decoration: none; + color: black; +} + +a:visited +{ + font-style: normal; + font-weight: bold; + text-decoration: none; + color: black; +} + +a:hover +{ + font-style: normal; + font-weight: bold; + text-decoration: underline; + color: black; +} + +a:active +{ + font-style: normal; + font-weight: bold; + text-decoration: underline; + color: black; +} + +div.leftbar +{ + width: 200px; + min-width: 200px; + border: 1px solid black; + padding: 0.25em; + float: left; + background-color: #aaaaff; +} + +h2.lb_header +{ + border: 1px none blue; + padding: 0.1em; + margin: 0em; + background-color: blue; + color: white; + font-size: medium; +} + +li.lb_linklist +{ + list-style-type: none; +} + +li.lb_sublist +{ + list-style-type: none; +} diff --git a/php/example1.php b/php/example1.php new file mode 100644 index 0000000..3b33e7e --- /dev/null +++ b/php/example1.php @@ -0,0 +1,23 @@ +<?php + include_once("leftbar.php"); +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<link rel="StyleSheet" href="example.css" type="text/css"/> +<title>Example 1</title> +<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> + +<h1>Example 1</h1> + +<div class="leftbar"> +<?php LeftBar('leftbar.txt','context_ex1'); ?> +</div> + +<p>Welcome to example page one.</p> + +</body> +</html> + diff --git a/php/example2.php b/php/example2.php new file mode 100644 index 0000000..7b36a5f --- /dev/null +++ b/php/example2.php @@ -0,0 +1,23 @@ +<?php + include_once("leftbar.php"); +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<link rel="StyleSheet" href="example.css" type="text/css"/> +<title>Example 2</title> +<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> +</head> +<body> + +<h1>Example 2</h1> + +<div class="leftbar"> +<?php LeftBar('leftbar.txt'); ?> +</div> + +<p>Welcome to example page two.</p> + +</body> +</html> + 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 @@ +<?php +/* + leftbar - Simple link manipulation. + + Copyright (C) 2006 Ian Cowburn (ianc@noddybox.co.uk) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ------------------------------------------------------------------------- + + $Id$ + +*/ + +class LB_LinkDef +{ + var $url; + var $text; + + function LB_LinkDef($u,$t) + { + $this->url=$u; + $this->text=$t; + } +} + +function LB_LeftHeader($hdr) +{ + printf('<h2 class="lb_header">%s</h2>',$hdr); +} + +function LB_TopLink($url,$txt) +{ + printf('<li class="lb_linklist"><a class="lb_toplink" href="%s">%s</a></li>',$url,$txt); +} + +function LB_SubLink($url,$txt) +{ + printf('<li class="lb_sublist"><a class="lb_sublink" href="%s">%s</a></li>',$url,$txt); +} + +function LB_OpenLink(&$is_open) +{ + if (!$is_open) + { + $is_open = TRUE; + echo '<ul class="lb_toplink">'; + } +} + +function LB_OpenSub(&$is_open) +{ + if (!$is_open) + { + $is_open = TRUE; + echo '<li class="lb_linklist">'; + echo '<ul class="lb_sublist">'; + } +} + +function LB_CloseLink(&$is_open) +{ + if ($is_open) + { + $is_open = FALSE; + echo '</ul>'; + } +} + +function LB_CloseSub(&$is_open) +{ + if ($is_open) + { + $is_open = FALSE; + echo '</ul>'; + echo '</li>'; + } +} + +function LeftBar($file, $context = '') +{ + $fp = fopen($file,'r'); + + if (!$fp) + { + printf('<p>Missing leftbar config %s!</p>',$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('<p>WARNING: Bad "def"</p>'); + } + break; + + case 'set': + if (count($tok)==2) + { + LB_CloseSub($in_sub); + LB_CloseLink($in_link); + LB_LeftHeader($tok[1]); + } + else + { + printf('<p>WARNING: Bad "set"</p>'); + } + 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('<p>WARNING: Bad "link"</p>'); + } + 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('<p>WARNING: Bad "sub"</p>'); + } + break; + + default: + printf('<p>WARNING: Bad line "%s"</p>',$line); + break; + } + } + } + + LB_CloseSub($in_sub); + LB_CloseLink($in_link); + + fclose($fp); +} +?> diff --git a/php/leftbar.txt b/php/leftbar.txt new file mode 100644 index 0000000..32fc683 --- /dev/null +++ b/php/leftbar.txt @@ -0,0 +1,42 @@ +# $Id$ +# +# * Blank lines and lines starting '#' are ignored. +# * Commands and arguments are tab seperated. +# + + +# The def command is: +# +# def link_id link_text url +# +def about About Noddybox /about.php +def google1 Google (com) http://www.google.com/ +def google2 Google (UK) http://www.google.co.uk/ +def bsd Free BSD http://www.freebsd.org/ +def micro Microsoft http://www.microsoft.com/ +def ex1 Example 1 example1.php +def ex2 Example 2 example2.php + +# A set and its links are defined as: +# +# set text +# link link_id context +# sub link_id +# +# For link use '-' is there is no context. +# +set Set 1 +link about - +link bsd - + +set Set 2 +link google1 - +link google2 - +link ex1 context_ex1 +sub ex2 +link bsd - + +set Set 3 +link google1 - +link google2 - +link micro - |