<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/local/bin/perl -Tw

# parser.pl v 1.5.11
# by wayne.myers@bbc.co.uk (et al)
# Enormous thanks to:
# Chay Palton, Damion Yates, Matt Blakemore,
# Dan Tagg, T.V. Raman, Mark Foster, Peter Burden,
# Jack Evans, Steve at wels.net, Gene D., Maurice Walshe
# and many others.

# parser.pl aka BETSIE is Copyright 1998 - 2001 BBC Digital Media
# See LICENCE for full licence details
# See README for more information
# See ChangeLog for version changes

# modules
use Socket;
use strict;

# variables

my $version = "1.5.11";	# version number
my @x = ();         	# all the lines of the html page we're parsing
my $contents = "";  	# @x concatenated
my $inpath = "";    	# path_info string from which we get the rest
my $qs;                 # query string, used for authorisation process
my $root = "";      	# domain of the page we are looking at
my $path = "";      	# path of the page we are looking at
my $file = "";      	# name of the file we are looking at
my $postdata = "";  	# POST method data
my $method = "GET"; 	# $method remains this way unless we get POST data
my $length = -1;    	# but is the length of content if any greater in a POST
my $count;		# counter for main request loop
my $httptype;		# http type of request
my $code;		# http return code
my $msg;		# http message
my $newurl;		# used to store redirect target
my $tag;		# used to store meta redirect tags
my $loop_flag;		# flag used to make sure we get the right page
my $script_flag;    	# flag used to see if we are in script tags or not
my $ws_flag;		# flag used to minimise unnecessary white space
my $set = 0;            # is 1 if we want the settings page
my $body; 		# the body tag
my $cookies;            # cookies we want to pass on to other server
my @setcookies;         # cookies server wants us to pass onto user
my $header;             # the http header we want to send the browser
my $extraheaders;       # extra headers to send the server on requests
my $nocontenttype = 1;  # flag unset when content type is printed
my $basic_realm;        # contains strin
my $set_auth = 0;       # flag set when required authorisation is provided


# VARIABLES YOU MIGHT WANT TO CHANGE:

my $pathtoparser = "http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}";
my $selfnuke = "(?:$pathtoparser|$ENV{'SCRIPT_NAME'})"; # used to eliminate textonly links to self
my $maxpost = 65536; # is maximum number of bytes in a POST
my $parsehome = "http://www.bbc.co.uk/education/betsie/";
my $name = $ENV{'SCRIPT_NAME'};		# name of this file
$name =~ s/^.*\/(\w\.+)$/$1/;
my $agent = $ENV{'HTTP_USER_AGENT'};	# pretend to be the calling browser

my $allowchars = '[a-zA-Z0-9_.\-\/\#\?\&amp;\=\%\~\+]'; # allowed characters
my $alarm = 10;  # number of seconds before we time out

# variables for colour/font settings etc
# be sure to amend make_body() if you amend them
my $setstr = "/0005";	# is default string for settings.
my $chsetstr = "/1005";  # string used for default change settings page
# next five arrays are for each set of colour options. feel free to add to or amend these.
my @bg    = ('#000000', '#FFFFFF', '#0000FF', '#FFFFCC');
my @text  = ('#FFFF00', '#000000', '#FFFFFF', '#000000');
my @link  = ('#00FFFF', '#0000FF', '#FFFFCC', '#0000FF');
my @vlink = ('#00CCFF', '#0000CC', '#FFFF99', '#0000CC');
my @alink = ('#FFFF00', '#000000', '#FFFFFF', '#000000');
# ten fonts. again, you can change these if you like
my @font_face = ("Verdana, Arial", "Times", "Courier", "Helvetica", "Arial",
		 "Bookman Old Style", "Geneva", "Chicago", "Courier New", "System");

# VARIABLES YOU MUST SUPPLY:

my $localhost = ""; #"www.bbc.co.uk";  # name of the actual machine which is localhost
                                  # (not necessarily same as server name if its virtual)

my $parsecontact = "wayne.myers\@bbc.co.uk";

my @safe = qw (	bbc.co.uk
		beeb.com
		bbcworldwide.com
		bbcresources.com
		bbcshop.com
		radiotimes.com
		open.ac.uk
		open2.net
		freebeeb.net
		);

# VARIABLES YOU (PROBABLY) DON'T WANT TO TOUCH:

my ($rec_test) = $pathtoparser =~ /^http:\/(.*)$/;	# var to solve recursion problem

# Set alarm handler (comment this out on systems that can't handle it)
alarm $alarm;
$SIG{ALRM} = \&amp;alarm;

# main loop

$|=1;

# handle POST requests

if ($ENV{'REQUEST_METHOD'} eq "POST") {
    
    $length = $ENV{'CONTENT_LENGTH'};
    
    if ($length &gt; $maxpost) {
	$x[0] = "Too much data for POST method.";
	error();
	exit;
    }
    
    if ($length) {
	
	read(STDIN, $postdata, $length, 0);
	$method = "POST";
	
    }
}

# take path info or referer allowing easy linking in...
$inpath = $ENV{'PATH_INFO'} || $ENV{'HTTP_REFERER'};
# strip http/ftp/gopher etc scheme if present (ie came from referer)
$inpath =~ s/^\w+:\///;
	       
# Uncomment the following ugly hack for servers that don't do PATH_INFO properly 
# (if you couldn't do alarm above, you probably need this too :( )
# $inpath =~ s/^.*?$name//;

# get query string
$qs = $ENV{'QUERY_STRING'} || "";

if (($inpath !~ /^$allowchars+$/) ||
    ($inpath =~ /\.\./) ||
    ($qs !~ /^$allowchars*$/) ||
    ($qs =~ /\.\./)) {
    $x[0] = "Unknown error";
    error();
    exit 0;
}



# beat recursive betsie bug #1
$inpath =~ s/^$rec_test//i;

# get optional settings string
$inpath =~ s!^(\/\d{4})\/!\/!;
$setstr = $1 || $setstr;  # is already initialised to '/0005'
if (length $setstr != 5) { $setstr = "/0005"; }
$chsetstr = $setstr;
$chsetstr =~ s/^\/(\d)/\/1/;
if ($1 eq "1") { $set = 1;};

($root, $path, $file) = urlcalc($inpath);

unless (safe("http:\/\/$root")) {
    $x[0] = "&lt;a href=\"http:\/\/$root$path$file\"&gt;http:\/\/$root$path$file&lt;\/a&gt; not on safe list. Sorry";
    error();
    exit;
}

$cookies = $ENV{'HTTP_COOKIE'} || $ENV{'COOKIE'} || "";

# turn any Betsie-auth cookie into an Authorization header
if ($cookies =~ s/Betsie-auth=([A-Za-z0-9\+\=\/]*?)\;//s) {

    $extraheaders = "Authorization: Basic $1\n";
    $set_auth = 1;

}

# if query string contains our betsie-pi parameter
# this is an attempt to authorise ourselves on a page
# if it isn't really, the following will simply fail...
if($qs =~ /betsie-pi=/) {

    # set a cookie with the auth string
    my ($authcook, $authloc) = make_auth_cookie_and_loc($file);
    # redirect to ourselves with the proper url

    print "Set-Cookie: Betsie-auth=$authcook;\n";
    print "Content-Type: text/html\n\n"; 
    print &lt;&lt;HTML;

&lt;html&gt;
&lt;head&gt;
&lt;meta HTTP-EQUIV="Refresh" CONTENT="0; URL=$pathtoparser/$authloc"&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;Logging in. Please follow &lt;a href="$pathtoparser/$authloc"&gt;this link&lt;/a&gt;.
&lt;/body&gt;
&lt;/html&gt;

HTML

    exit 0;

}


$loop_flag = 0;
$count = 0;

 LOOP: while ($loop_flag == 0) {
     
     $count++;
     if ($count == 9) {
	 $x[0] = "Too many times through the loop.";
	 error();
	 exit;
     }
     
     if ($ENV{'QUERY_STRING'} ne "") { $file .= "\?$ENV{'QUERY_STRING'}" }
     
     @x = graburl($root, $path . $file);

     $contents=join '', @x;
     
     # handle http codes
     # 3xx we follow the redirect
     # anything other than 200 is an error.
     
     ($httptype, $code, $msg) = split /\s+/, $x[0];
     
     if ($code =~ /^3\d\d/) {
	 $contents =~ s/^.*Location:\s+(\S+)\s.*$/$1/s;
	 $newurl = $contents;
	 redir();
	 next LOOP;
     }
     
     if ($code !~ /200|401/) {
	 error();
	 exit;
     }
     
     # check for autoredirects of all sorts
     
     if ($contents =~ /(&lt;meta[^&gt;]*?http-equiv[^&gt;]*?refresh[^&gt;]*?&gt;)/is) {
	 $tag = $1;
	 unless ($tag =~ /content=\"\d{3,}/is) {     # only deal with refreshes of 99 secs or less
	     if ($tag =~ /url=(.*?)\"/is) {            # don't refresh if no url given
		 $newurl = $1;
#		 unless ($file =~ /$newurl$/) {         # don't refresh to same page
		 unless (($file =~ /$newurl$/) || ($newurl =~ /$path$file$/)) {         # don't refresh to same page
		     redir();
		     next LOOP;
		 }
	     }
	 }
     }
     
     # if we got here we must have got something and can end the loop
     
     $loop_flag = 1;
     
 }

# lose HTTP OK line
if ($code =~ /200|401/) {
    $contents =~ s/^HTTP[^\n]*\n//s;
}

# ignore all files not reported as some kind of text in content-type
if ($contents !~ /Content-Type:\s+text/is) {
    # send contents on unchanged
    print $contents;
    exit 0;
}

# pass cookies on but rewrite path
while ($contents =~ s/(Set-Cookie:[^\n]*\n)//isg) {
    my $c = $1;
    if ($c =~ /path=/) {
	# arbitrarily rewrite path to '/' so both betsie and originator can see it
	$c =~ s/(path=\/)[^;]*;/$1;/is;
    } else {
	$c =~ s/\n$/ path=\/;\n/;
    }
    print $c;
}

# get header out of contents
# finding it hard to match \n\n for some reason
$contents =~ s/^(.*?\n\s*\n)//s;
$header = $1;
$header =~ s/Content-Length.*\n//i; # because the length is now wrong

# add content type to header if not present
if ($header !~ /Content-Type/s) {
    $header =~ s/\n\n$/\nContent-Type: text\/html\n\n/s;
}

# handle WWW-Authenticate requests
if (($set_auth == 0) &amp;&amp;
    ($header =~ /WWW-Authenticate:([^\n]*\n)/isg)) {

#    ($basic_realm) = $header =~ /Basic realm=\"([^\"]*?)\"/is;

    $contents = make_auth_page();
    print $header, $contents;
    exit 0;

}

# *now* print header content type
print $header;

# set nocontenttype flag to ensure it never gets printed again
$nocontenttype = 0;

# make the body tag
$body = make_body();

# if we're on the settings page, send that and exit
if ($set != 0) {
    print &lt;&lt;HTML;	
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Betsie Settings Page&lt;/title&gt;
&lt;meta name="ROBOTS" content="NOINDEX, NOFOLLOW"&gt;
&lt;/head&gt;
$body
&lt;/body&gt;
&lt;/html&gt;
HTML
					
    exit;
}

# we're not on the settings page. call parser routines
$contents = preparse($contents);

@x = split /\n/, $contents;

$contents = "";

# start sending
$script_flag = 0; # it will be 1 if we are in &lt;SCRIPT&gt; tags
$ws_flag = 0;   # it will be 2 if we just printed a second &lt;BR&gt; in a row

for (@x) {
    $contents = parse($_);
    unless ((!$contents) ||
	    ($script_flag == 1) ||
	    ($contents =~ /^\s+$/s) ||
	    (($ws_flag &gt; 1) &amp;&amp; ($contents =~ /^(\s*&lt;br[^&gt;]*?&gt;\s*)+$/is))) {
        print $contents;
        if ($contents !~ /&lt;br[^&gt;]*?&gt;\s*$/is) { $ws_flag = 0; }
        unless ($contents =~ /\n$/) { print "\n"; }
    }
    if ($contents =~ /&lt;br[^&gt;]*?&gt;\s*$/is) { $ws_flag++; }
}

exit 0;

# subroutines

# base64encode
# give it a string
# get a base64 encoded version back
# Modified from code from MIME:Base64 module by Gisle Aas
sub base64encode {

    my $in = shift;
    my $res = "";

    $res = join '', map( pack('u',$_)=~ /^.(\S*)/, ($in=~/(.{1,45})/gs));

    $res =~ tr|` -_|AA-Za-z0-9+/|;               # `# help emacs
    # fix padding at the end
    my $padding = (3 - length($in) % 3) % 3;
    $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
    return $res;

}

# urldecode
# urldecode a string
# Code from CGI.pm by Lincoln Stein
sub urldecode {

    my $str = shift;

    return "" unless $str;

    $str =~ tr/+/ /;       # pluses become spaces
    $str =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
    return $str;

}

# parse_parms
# give it a query string
# get a hash of parameters
# any url decoding will be done
sub parse_parms {

    my $qs = shift;
    my %parms;
    my $key;
    my $val;


    for (split '&amp;', $qs) {
	($key, $val) = $_ =~ /^([^=]+?)=(.*)$/;
	if ($val =~ /\%/) { $val = urldecode($val); }
	$parms{$key} = $val;
    }

    return %parms;

}

# make_auth_cookie_and_loc
# give it an auth_page query string
# it returns the cookie we want to set
# and the location to redirect to
sub make_auth_cookie_and_loc {

    my $file = shift;
    my $str;
    my %pa;

    %pa  = parse_parms($qs);

    $str = base64encode($pa{'betsie-u'}.":".$pa{'betsie-p'});

    return ($str, $pa{'betsie-pi'});

}

# make_auth_page
# returns a suitable authorisation page
sub make_auth_page {

    my $page;

    $body = make_body();

    $page = &lt;&lt;HTML;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Authorisation Required&lt;/title&gt;
&lt;/head&gt;
$body
&lt;h1&gt;Betsie Authorisation Request Page&lt;/h1&gt;

&lt;p&gt;You are trying to view a page which is password protected.
If you don't have a password for this page, please select the
browser's 'back' button to go back.

&lt;p&gt;$basic_realm

&lt;form action="$pathtoparser" method="GET"&gt;

&lt;input type="hidden" name="betsie-pi" value="$root$path$file"&gt;

&lt;h2&gt;User name&lt;/h2&gt;
&lt;input type="text" name="betsie-u"&gt;

&lt;h2&gt;Password&lt;/h2&gt;
&lt;input type="password" name="betsie-p"&gt;

&lt;p&gt;&lt;input type="submit" name="Submit"&gt;
&lt;p&gt;&lt;input type="reset" name="Reset"&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

HTML

    return $page;

}

# redir
# handles redirects.
# assumes $newurl contains the new url to redirect to...

sub redir {
    
    # case 1 - it begins with /
    
    if ($newurl =~ /^\//) {
	$newurl = "\/" . $root . $newurl;
	($root, $path, $file) = urlcalc($newurl);
	return;
    }
    
    # case 2 - it's the full path
    
    if ($newurl =~ /^http/) {
	$newurl =~ s/^http:\///;
	($root, $path, $file) = urlcalc($newurl);
	return;
    }
    
    # case 3 - it's a filename
    
    if ($newurl =~ /^(\w|-|_)+\.\w+$/) {
	$file = $newurl;
	return;
    }
    
    # case 4 - it's a relative path
    
    if ($newurl =~ /[(\w|-|_)+\/]*(\w|-|_)+\.\w+/) {
	$path .= $newurl;
	$path =~ s/\/((\w|-|_)+\.\w+)$/\//;
	$file = $1;
	$path =~ s#\/(\w|-|_)+\/\.\.##g;
	return;
    }
    
    # case 5 - the ones i haven't thought of...
    
    $x[0] = "Unknown redirect - $newurl";
    
    error();
    exit;
    
}

# error
# displays error page with message

sub error {

    my $error = shift || "";
    if($error ne "") {
	$x[0]=$error;
    }

    $root = "" unless $root;
    $path = "" unless $path;
    $file = "" unless $file;
    $contents = "" unless $contents;
    $body = "&lt;body&gt;" unless $body;

    # print contenttype if we haven't already
    if ($nocontenttype == 1) {
	print "Content-Type: text/html\n\n";
    }

print &lt;&lt;HTMLERR;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Betsie Error Page&lt;/title&gt;
&lt;/head&gt;
$body
&lt;h1&gt;Betsie Error Page&lt;/h1&gt;
&lt;p&gt;Sorry, but Betsie was unable to find the page at http://$root$path$file.

&lt;p&gt;The error was as follows: $x[0].

&lt;p&gt;If you have just found a bug in Betsie (it's possible), please email the details
to &lt;a href=\"mailto:$parsecontact\"&gt;$parsecontact&lt;/a&gt;

&lt;p&gt;&lt;a href=\"$parsehome\"&gt;Return to the Betsie
homepage&lt;/a&gt;, or select your browser's 'back' button (or equivalent) to return to the
page you just came from.

&lt;p&gt;Inpath: $inpath
&lt;p&gt;Root: $root
&lt;p&gt;Path: $path
&lt;p&gt;File: $file

&lt;/font&gt;
&lt;/body&gt;
&lt;/html&gt;

HTMLERR

}


# graburl
# homebrewed page grabber thing. gets remote page.
sub graburl {

    my ($host, $file) = @_;
    
    my ($remote,                        # the name of the server
	$port,                          # the port
	$iaddr, $paddr, $proto, $line); # these vars used internally
    
    #DMY + WM
    if ($host eq $localhost) {
	$host = "localhost";
    }
    
    $remote  = $host;
    $port    = 80;

    # support non standard port numbers
    if ($remote =~ s/:(\d+)$//) { $port = $1; }
    
    unless ($iaddr   = inet_aton($remote)) {
	warn "no host: $remote";
	error("Error: no host", "$!");
    }
    
    $paddr   = sockaddr_in($port, $iaddr);
    $proto   = getprotobyname('tcp');
    select(SOCK);
    $| = 1;
    
    unless (socket(SOCK, PF_INET, SOCK_STREAM, $proto)) {
	warn "socket: $!";
	error("Error: socket problem", "$!");
    }

    unless (connect(SOCK, $paddr)) {
	warn "connect: $!";
	error("Error: connection problem", "$!");
    }
    
    select(STDOUT);
    
    print SOCK "$method $file HTTP/1.0\n";
    print SOCK "Accept: */*\n";
    print SOCK "User-Agent: $agent\n";
    print SOCK "Host: $host\n";
    if ($cookies) {
	print SOCK "Cookie: $cookies\n";
    }

    # support arbitrary extra headers
    if($extraheaders) {
	print SOCK $extraheaders;
    }


    if ($length &gt; -1) { print SOCK "Content-Length: $length\n"; }
    print SOCK "\n";
    if ($length &gt; -1) {
	print SOCK "$postdata\n";
    }

    
    @x = &lt;SOCK&gt;;
    
    unless (close (SOCK)) {
	warn "close: $!";
	return ("Error: problem closing socket", "$!");
    }
    
    $method = "GET";
    $length = -1;
    $postdata = "";
    
    return @x;
    
}

# parser routines

# preparse
# preparses take the whole page and does the bits that need the whole of the page

sub preparse {

    my $page = shift;
    
    # preparsing:
    
    # remove http header lines and insert missing html/body tags
    
    if ($page !~ /&lt;html[^&gt;]*&gt;/is) {
	$page =~ s/^(.+?)\n\n/&lt;html&gt;/s;
    } else {
	$page =~ s/.*?&lt;html([^&gt;]*)&gt;/&lt;html$1&gt;/is;
    }
    
    if ($page !~ /&lt;\/html&gt;/is) {
	$page .= "&lt;\/html&gt;";
    }
    
    if ($page !~ /&lt;frameset/is) {    # don't do this to frames pages
	
	if ($page !~ /&lt;\/body&gt;/is) {
	    $page =~ s/&lt;\/html&gt;/&lt;\/body&gt;\n&lt;\/html&gt;/is;
	}
	
	if ($page !~ /&lt;body/is) { # if there's no body tag
	    if ($page =~ /&lt;\/head&gt;/is) {	# look for an end head tag
		$page =~ s/&lt;\/head&gt;/&lt;\/head&gt;\n&lt;body&gt;/is;   # put body tag there if we find it
	    } else {
		if ($page =~ /&lt;\/title&gt;/is) {	# if we don't find end head look for end title
		    $page =~ s/&lt;\/title&gt;/&lt;\/title&gt;&lt;\/head&gt;\n&lt;body&gt;/is;	# insert both end head and body start
		} else {
		    $page =~ s/&lt;html([^&gt;]*)&gt;/&lt;html$1&gt;&lt;head&gt;&lt;title&gt;$root$path$file&lt;\/title&gt;&lt;\/head&gt;&lt;body&gt;/is;
		    # this is clumsy, true, but so is the code it's trying to fix.
		}
	    }
	}
	
    }
    
    # now we have a head we can look out for and exclude robots.
    $page =~ s/(&lt;\/head&gt;)/&lt;meta name="ROBOTS" content="NOINDEX, NOFOLLOW"&gt;\n$1/is;
    
    # remove stylesheets part 1
    $page =~ s/&lt;style.+?&lt;\/style&gt;//gis;
    
    # remove java
    $page =~ s/&lt;applet.+?&lt;\/applet&gt;/&lt;p&gt;Java applet removed\.\n/gis;
    
    # put MAPs in body (later on AREAs become As...)
    while ($page =~ s/&lt;map[^&gt;]*?&gt;(.*?)&lt;\/map&gt;(.*)(&lt;\/body&gt;)/$2\n$1\n$3/is) {};
        
    # remove all extraneous whitespace and newlines in tags
    $page =~ s/\s+=/=/gs;
    $page =~ s/=\s+/=/gs;
    $page =~ s/&lt;\s+([^&gt;]+)&gt;/&lt;$1&gt;/gs;
    $page =~ s/&lt;([^&gt;]+)\s+&gt;/&lt;$1&gt;/gs;
    while ($page =~ s/&lt;([^&gt;\n]+?)\n([^&gt;]*)&gt;/&lt;$1 $2&gt;/gs) {}
    while ($page =~ s/&lt;([^&gt;]+?)\s{2,}([^&gt;]+)&gt;/&lt;$1 $2&gt;/gs) {}
    
    # remove empty links - mucho ta to Matt Blakemore for suggesting this one
    $page =~ s/&lt;a[^&gt;]*href\s*\=\s*[^&gt;]*&gt;\s*&lt;img[^&gt;]*alt\s*\=\s*\"\"[^&gt;]*&gt;\s*&lt;\/a&gt;//gis;

    # go to move_nav and move the nav
    $page = move_nav($page);  

    # go to move_extra and do any other fiddling
    $page = move_extra($page);
    
    # remove hidden javascript. and comments. (sorry).
    $page =~ s/&lt;!--.*?--&gt;//gs;
    
    # make sure no two tags are on same line
    $page =~ s/(&gt;)([^\n|=])/$1\n$2/gs;
    
    # remove blank lines
    $page =~ s/\s{2,}/\n/gs;

    # find and fix text-only links
    $page =~ s/&lt;a\s+href\s*=\s*\"$selfnuke[^\"]*\"[^&gt;]*&gt;.*?&lt;\/a&gt;//sig;

    return $page;
}

# move_extra
# moves arbitrary other blocks of code around the page
# block n is delimited by the following
# &lt;!-- BETSIEBLOCK n --&gt;
# ... code
# &lt;!-- ENDBETSIEBLOCK n --&gt;
# blocks end up in the order they were numbered
# at the bottom of the page
sub move_extra {

    my $page = shift;

    my $start = "(?:BETSIEBLOCK)";
    my $end = "(?:ENDBETSIEBLOCK)";

    my $count = 1;

    while ($page =~ /&lt;!--\s+$start/is) {
	# move the nth betsie block
	$page =~ s/(.*?)&lt;!--\s+$start\s+$count[^&gt;]+?--&gt;(.*?)&lt;!--\s+$end\s+$count[^&gt;]+?--&gt;(.*)&lt;\/body&gt;/$1$3$2&lt;\/body&gt;/is;
	$count++;
    }

    return $page;

}

# move_nav
# moves the nav bar around
# this one is for the BBC site. your site may need a whole different one...

sub move_nav {

    my $page = shift;
    
    my $start_nav = '(?:GLOBAL\s+NAVIGATION|GLOBALNAVBEGIN)';
    my $end_nav = '(?:End\s+of\s+GLOBAL\s+NAVIGATION|SERVICESNAVEND)';

    if ($root =~ /\.bbc\.co\.uk$/) {
	
	# first make sure all table widths have double quotes
	
	$page =~ s/(&lt;t[^&gt;]*?)width=(\d+)/$1width="$2"/gis;
	
	for ($root) {
	    
	    /^news/ and do {
		
		# news nav mangling - sits in a table width 90 pixels... Or 100 pixels. Depends on the template.
		
		$page =~ s/(.*?)&lt;table([^&gt;]*?)width=[\"|\']?(?:90|100)[\"|\']?.*?&gt;(.*?)&lt;\/table&gt;(.*)&lt;\/body&gt;/$1$4$3&lt;\/body&gt;/is;

		last;
		
	    };
	    
	    /^www/  and do {
		
		# normal or worldservice...
		
		if ($path =~ /worldservice|arabic|cantonese|mandarin|russian|spanish|ukrainian/) {
		    
		    # world service nav mangling - sits in a td width 98 pixels and followed by td width 1 pixel
		    # but mileage varies, hence all the \d's...
		    
		    $page =~ s/(.*?)&lt;td([^&gt;]*?)width=[\"|\'](?:9\d|1\d\d)[\"|\'].*?&gt;(.*?)&lt;td([^&gt;]*?)width=[\"|\']\d[\"|\'].*?&gt;(.*)&lt;\/body&gt;/$1$5$3&lt;\/body&gt;/is;

		} elsif ($path =~ /^\/news\//) {

		    # news nav mangling - sits in a table width 90 pixels... Or 100 pixels. Depends on the template.

		    $page =~ s/(.*?)&lt;table([^&gt;]*?)width=[\"|\'](?:90|100)[\"|\'].*?&gt;(.*?)&lt;\/table&gt;(.*)&lt;\/body&gt;/$1$4$3&lt;\/body&gt;/is;
		    
		} else {
		    
                    # deal with old education navbar
		    
                    last if ($page =~ s/(&lt;a href=\"\/education\/nav\/bbcedbar\.map\"&gt;).*?(&lt;\/a&gt;)/$1BBC Education$2/is);
                      
		    if ($page =~ /&lt;!--\s+$start_nav/is) {

                      	# code for commented stuff here
                      	$page =~ s/(.*?)&lt;!--\s+$start_nav[^&gt;]+?--&gt;(.*?)&lt;!--\s+$end_nav[^&gt;]+?--&gt;(.*)&lt;\/body&gt;/$1$3$2&lt;\/body&gt;/is;
 
                    } else {
                      
                      	# Old standard navs. Should be 107 and 3 pixels, but you never know...
                    	$page =~ s/(.*?)&lt;td([^&gt;]*?)width=[\"|\']1\d\d[\"|\'].*?&gt;(.*?)&lt;td([^&gt;]*?)width=[\"|\']\d[\"|\'].*?&gt;(.*)&lt;\/body&gt;/$1$5$3&lt;\/body&gt;/is;

		    }
						    
		}

		last;

	    };
 
	    # i don't know where we are, here, but lets try for standard nav bars anyway...
	    if ($page =~ /&lt;!--\s+$start_nav/is) {
		# code for commented stuff here&gt;
           	$page =~ s/(.*?)&lt;!--\s+$start_nav[^&gt;]+?--&gt;(.*?)&lt;!--\s+$end_nav[^&gt;]+?--&gt;(.*)&lt;\/body&gt;/$1$3$2&lt;\/body&gt;/is;
	    } else {

		# if in doubt, do nothing, to avoid sending back empty documents.

	    }
	}
    }
    
    
    return $page;	
	
}

# parse
# handles the line-by-line bits of betsification
sub parse {
    
    my ($line) = shift;
    my $link;
    my $alt;    # used in area tag handler
    my $target; # ditto
    
    $line =~ s/click here/select this link/gis;
    
    # nuke javascript event handlers
    while ($line =~ s/(&lt;[^&gt;]*?)(\s+on\S+?\s*=\s*\".*?\")+(.*?&gt;)/$1 $3/i) {}; # dbl quotes
    while ($line =~ s/(&lt;[^&gt;]*?)(\s+on\S+?\s*=\s*\'.*?\')+(.*?&gt;)/$1 $3/i) {}; # sgl quotes
    while ($line =~ s/(&lt;[^&gt;]*?)(\s+on\S+?\s*=\s*\S+?)(&gt;)/$1 $3/i) {};     # no quotes. naughty!
    
    # lose inline stylesheeting
    $line =~ s/(&lt;[^&gt;]*?)style\s*=\s*\".*?\"/$1/gis;
    
    # lose arbitrary justification arbitrarily
    $line =~ s/(&lt;[^&gt;]*?)align\s*=\s*\".*?\"/$1/gis;
    
    # S T O P   P E O P L E   L I K E   T H I S (thanx to T.V.Raman for the suggestion)
    if ($line =~ /(\w ){5,}/) {
    	$line =~ s/(\w) /$1/g;
    }
    
    my $tag;
    $line =~ /&lt;(\S+)[^&gt;]*?&gt;/;
    $tag = $1 || "";
    if ($tag eq "") { return $line; }
    $tag = lc $tag;
    
    for ($tag) {
	
	# handle javascript script
	/noscript/		 and do {
	    $line =~ s/&lt;(?:\/)?noscript[^&gt;]*?&gt;//gis;	 
	    last;
	};
	
	/script/ and do {
	    if ($line =~ /&lt;script/i) {
		$script_flag = 1;
		$line =~ s/&lt;script.*$//gis;
	    } elsif ($line =~ /&lt;\/script/i) {
		$line =~ s/^.*?&lt;\/script&gt;//i;
		$script_flag = 0;
	    }
	    last;
	};
	
	# lose nobr
	/nobr/   and do {
	    $line =~ s/&lt;(?:\/)?nobr&gt;//gis;
	    last;
	};
	
	# lose link rel=stylesheet *only*
	/link/   and do {
	    if ($line =~ /rel\s*=\s*\"?stylesheet\"?/gis) {
		$line =~ s/&lt;link[^&gt;]*?&gt;//gis;
	    }
	    last;
	};
	
	# lose center tag
	/center/		 and do {
	    $line =~ s/&lt;(?:\/)?center[^&gt;]*?&gt;//gis;	 
	    last;
	};
	
	
	# nuke all fonts
	/font/	 and do {
	    $line =~ s/&lt;(?:\/)?font[^&gt;]*?&gt;//gis;
	    $line =~ s/&lt;(?:\/)?basefont[^&gt;]*?&gt;//gis;
	    last;
	};
	
	/base/	 and do {
	    
	    if (($link) = $line =~ /&lt;base[^&gt;]+?href\s*=\s*(\S+)[^&gt;]*?&gt;/i) {
		$link =~ s/\"//g;
		$link =~ s#^http:\/##i;
		($root, $path) = urlcalc($link);
	    }
	    
	    last;
	};
	
	# lose layers
	/layer/	and do {
	    $line =~ s/&lt;(?:\/)?layer[^&gt;]*?&gt;//gis;
	    last;
	};
	
	# lose divs
	/div/	and do {
	    $line =~ s/&lt;(?:\/)?div[^&gt;]*?&gt;//gis;
	    last;
	};

	# detableiser
	/table/	and do {
	    $line =~ s/&lt;(?:\/)?table[^&gt;]*?&gt;//gis;
	    last;
	};
	/tr$/		 and do {
	    $line =~ s/&lt;(?:\/)?tr[^&gt;]*?&gt;//gis;	 
	    last;
	};
	# this is very rudimentary and could be improved
	# but not till i'm sure what the right way is
	/th$/ and do {
	    $line =~ s/&lt;\/th&gt;//gis;
	    $line =~ s/&lt;th.*?&gt;/&lt;br&gt;/gis;
	    last;
	};
	/td$/		 and do {
	    $line =~ s/&lt;\/td&gt;//gis;
	    $line =~ s/&lt;td.*?&gt;/&lt;br&gt;/gis;
	    last;
	};
	
	# link masher
	/^a$/		 and do {
	    
	    # get the link out and remove any quoting
	    $line =~ /&lt;a[^&gt;]+?href\s*=\s*(\S+)[^&gt;]*?&gt;/i;
	    $link = $1 || "";
	    $link =~ s/\"//g;
	    $link =~ s/\'//g;
	    last if ($link =~ /^\#/);	 # ignore anchors
	    
	    $line =~ s/\s*=\s*/=/;
	    
	    # check for URL passing scripts and make them external
	    # this should fix webguide and all other script based
	    # URL passers for whom a href is just too easy... :)

	    # note that URLs automatically end if an &amp; is present.
	    # note that this is a hack to get around an old bbc-specific
	    # problem, and should probably now be removed, since it surely
	    # breaks interoperability with other scripts.
	    
	    if ($link =~ m#\?.*?http(:|CHR\(58\))\/\/#i) {
		
		$link =~ s/CHR\(58\)/:/gi;
		$link =~ s/.*?(\?.*)/$1/;
		$link =~ s#^\?.*?(http:\/\/.*)$#$1#i;
		$link =~ s/&amp;.*$//;
		unless (safe($link)) {
		    $line =~ s#(&lt;a[^&gt;]+?href=)\S+([^&gt;]*?&gt;)#$1$link$2 (External)#i;
		    last;
		}
	    }
	    
	    # handle real audio
	    
	    if ($link =~ /\.(ram|rm|ra)$/i) {
		if ($link =~ /^http:/i) {
		    last;
		}
		if ($link =~ /^\//) {
		    $link = "http:\/\/" . $root . $link;
		    $line =~ s/(&lt;a[^&gt;]+?href=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
		    last;
		}
		$link = $root . $path . $link;
		$link =~ s#\/\w+\/\.\.\/#\/#g;
		$link = "http:\/\/" . $link;
		$line =~ s/(&lt;a[^&gt;]+?href=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
		last;
	    }
	    
	    # handle fully qualified links
	    
	    if ($link =~ /^\w+:/) {
		unless (safe($link)) {
		    $line =~ s/(&lt;a[^&gt;]+&gt;)/$1 (External)/i;
		    last;
		}
		if ($link =~ /^http/i) {
		    $link =~ s/^http:\/(\/.*)$/$pathtoparser$setstr$1/i;
		    $line =~ s/(&lt;a[^&gt;]+?href=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
		} elsif ($link =~ /javascript:/) {
		    $line =~ s/&lt;a[^&gt;]+&gt;/&lt;a href=""&gt;/i;
		}
		last;
	    }
	    
	    # now the slash led links
	    
	    if ($link =~ /^\//) {
		$link = $pathtoparser . "$setstr" ."\/". $root . $link;
		$line =~ s/(&lt;a[^&gt;]+?href=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
		last;
	    }
	    
	    # now the rest of them
	    
	    $link = "\/" . $root . $path . $link;
	    $link =~ s#\/\w+\/\.\.\/#\/#g;
	    $link = $pathtoparser. "$setstr" . $link;
	    $line =~ s/(&lt;a[^&gt;]+?href=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
	    last;
	};
	
	/^area$/			and do {
	    
	    # get the link out and remove any quoting
	    ($link) = $line =~ /&lt;area[^&gt;]+?href\s*=\s*(\S+)[^&gt;]*?&gt;/i;
	    $link =~ s/\"//g;
	    $link =~ s/\'//g;
	    last if ($link =~ /^\#/);	 # ignore anchors
	    
	    # get alt out
	    
	    ($alt) = $line =~ /&lt;area[^&gt;]+?alt\s*=\s*\"(.*?)\"[^&gt;]*?&gt;/i;
	    
	    $alt = $alt || $link;  # so non-alt tagged stuff sort of works...
	    
	    # get target out (if present) - we don't need to do this elsewhere
	    # because it's retained, but here we're rewriting the whole tag...
	    
	    ($target) = $line =~ /&lt;area[^&gt;]+?target\s*=\s*\"(.*?)\"[^&gt;]*?&gt;/i;
	    
	    $target = $target || "_top";  # so non-targeted stuff sort of works...
	    
	    # handle fully qualified links
	    
	    if ($link =~ /^\w+:/) {
		unless (safe($link)) {
		    $line = "&lt;a href=\"$link\" target=\"$target\"&gt;$alt (External)&lt;/a&gt;&amp;nbsp;";
		    last;
		}
		if ($link =~ /^http/i) {
		    $link =~ s/^http:\/(\/.*)$/$pathtoparser$setstr$1/i;
		    $line = "&lt;a href=\"$link\" target=\"$target\"&gt;$alt&lt;/a&gt;&amp;nbsp;"
		    } elsif ($link =~ /javascript:/) {
			$line = "&lt;a href=\"\"&gt;&amp;nbsp;";
		    }
		last;
	    }
	    
	    # now the slash led links
	    
	    if ($link =~ /^\//) {
		$link = $pathtoparser . "$setstr" ."\/". $root . $link;
		$line = "&lt;a href=\"$link\" target=\"$target\"&gt;$alt&lt;/a&gt;&amp;nbsp;";
		last;
	    }
	    
	    # now the rest of them
	    
	    $link = "\/" . $root . $path . $link;
	    $link =~ s#\/\w+\/\.\.\/#\/#g;
	    $link = $pathtoparser. "$setstr" . $link;
	    $line = "&lt;a href=\"$link\" target=\"$target\"&gt;$alt&lt;/a&gt;&amp;nbsp;";
	    last;
	    
	};
	
	
	/^frameset$/	and do {
	    $line =~ s/(&lt;frameset[^&gt;]*?) cols/$1 rows/i;
	    $line =~ s/(&lt;frameset[^&gt;]+)frameborder\s*=\s*[\'|\"]?[no|0][\'|\"]?([^&gt;]*)&gt;/$1 $2&gt;/i;
	    $line =~ s/(&lt;frameset[^&gt;]+)border\s*=\s*[\'|\"]?0[\'|\"]?([^&gt;]*)&gt;/$1 $2&gt;/i;
	    while ($line =~ s/(&lt;frameset[^&gt;]*?\=\s*[\"|\']?\s*)\d{1,2}\%?(,?)/$1\*$2/i) {};
	    last;
	};																	 
	
	/^frame$/		 and do {
	    
	    # make all frames resizeable...
	    
	    $line =~ s/(&lt;frame[^&gt;]+?)noresize[="noresize"]?([^&gt;]*&gt;)/$1 $2/ig;
	    $line =~ s/(&lt;frame[^&gt;]+)frameborder\s*=\s*[\'|\"]?[no|0][\'|\"]?([^&gt;]*)&gt;/$1 $2&gt;/i;
	    $line =~ s/(&lt;frame[^&gt;]+)border\s*=\s*[\'|\"]?0[\'|\"]?([^&gt;]*)&gt;/$1 $2&gt;/i;
	    
	    # get the link out and remove any quoting
	    
	    ($link) = $line =~ /&lt;frame[^&gt;]+?src\s*=\s*(\S+)[^&gt;]*?&gt;/i;
	    last if ($link eq "");
	    $link =~ s/\"//g;
	    $link =~ s/\'//g;
	    $line =~ s/\s*=\s*/=/;
	    if ($line !~ /scrolling/i) {
		
		$line =~ s/(&lt;frame[^&gt;]+)&gt;/$1 scrolling=yes&gt;/i;
		
	    } else {
		
		$line =~ s/(&lt;frame[^&gt;]+)scrolling\s*=\s*[\'|\"]?no[\'|\"]?([^&gt;]*)&gt;/$1 scrolling=\"yes\" $2&gt;/i;
		
	    }
	    # handle fully qualified links
	    
	    if ($link =~ /^\w+:/) {
		if ($link =~ /^http/i) {
		    $link =~ s/^http:\/(\/.*)$/$pathtoparser$setstr$1/i;
		    $line =~ s/(&lt;frame[^&gt;]+?src=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
		}
		last;
	    }
	    
	    # now the slash led links
	    
	    if ($link =~ /^\//) {
		$link = $pathtoparser . "$setstr" ."\/". $root . $link;
		$line =~ s/(&lt;frame[^&gt;]+?src=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
		last;
	    }
	    
	    # now the rest of them
	    
	    $link = "\/" . $root . $path . $link;
	    $link =~ s#\/\w+\/\.\.\/#\/#g;
	    $link = $pathtoparser . "$setstr". $link;
	    $line =~ s/(&lt;frame[^&gt;]+?src=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
	    last;
	};
	
	/^form$/		 and do {
	    
	    # get the link out and remove any quoting
	    
	    ($link) = $line =~ /&lt;form[^&gt;]+?action\s*=\s*(\S+)[^&gt;]*?&gt;/i;
	    last if ($link eq "");
	    $link =~ s/\"//g;
	    $link =~ s/\'//g;
	    $line =~ s/\s*=\s*/=/;
	    
	    # handle fully qualified links
	    
	    if ($link =~ /^\w+:/) {
		if ($link =~ /^http/i) {
		    $link =~ s/^http:\/(\/.*)$/$pathtoparser$setstr$1/i;
		    $line =~ s/(&lt;form[^&gt;]+?action=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
		}
		last;
	    }
	    
	    # now the slash led links
	    
	    if ($link =~ /^\//) {
		$link = $pathtoparser .$setstr. "\/".$root . $link;
		$line =~ s/(&lt;form[^&gt;]+?action=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
		last;
	    }
	    
	    # now the rest of them
	    
	    $link = "\/" . $root . $path . $link;
	    $link =~ s#\/\w+\/\.\.\/#\/#g;
	    $link = $pathtoparser .$setstr. $link;
	    $line =~ s/(&lt;form[^&gt;]+?action=)\S+([^&gt;]*?&gt;)/$1"$link"$2/i;
	    last;
	};
	
	/img/		 and do {
	    
	    # case 1 - image has empty alt tag
	    
	    $line =~ s/&lt;img[^&gt;]*?alt="".*?&gt;//i;
	    
	    # case 2 - image has non-empty alt tag
	    
	    $line =~ s/&lt;img[^&gt;]*?alt="(.+?)".*?&gt;/&lt;p&gt;$1/i;
	    
	    # case 3 - image has no alt tag at all
	    
	    $line =~ s/&lt;img.*?&gt;//i;
	    
	    last;
	    
	};
	
	/input/		 and do {
	    
	    # only screw with it if it's an image...
	    
	    if ($line =~ /(&lt;input[^&gt;]*?type=(\"|\')?)image/gis) {
		$line =~ s/($1)image/$1submit/gis;
		last;
	    }
	    
	    last;
	    
	};
	
	/embed/	 and do {
	    
	    # sort shockwave etc plus anything else embedded with src
	    
	    # currently attempts to make sure all src left after losing images has the right path
	    
	    $line =~ s/&lt;([^&gt;]+?)src=([\'|\"]?)(\/\S+?)([\'|\"]?)([^&gt;]*?)&gt;/&lt;$1SRQ=$2http:\/\/$root$3$4$5&gt;/i;
	    $line =~ s/&lt;([^&gt;]+?)src=([\'|\"]?)(http:\/\/\S+?)([\'|\"]?)([^&gt;]*?)&gt;/&lt;$1SRQ=$2$3$4$5&gt;/i;
	    $line =~ s/&lt;([^&gt;]+?)src=([\'|\"]?)(\S+?)([\'|\"]?)([^&gt;]*?)&gt;/&lt;$1src=$2http:\/\/$root$path$3$4$5&gt;/i;
	    $line =~ s#\/\w+\/\.\.\/#\/#g;
	    $line =~ s/&lt;([^&gt;]+?)SRQ/&lt;$1src/i;
	    
	};
	
	/body/		and do {
	    
	    if ($line =~ /&lt;body/i ) {
		$line =~ s/&lt;body[^&gt;]*?&gt;/$body/i;
		last;
	    }
	    
	    $line =~ s#&lt;\/body&gt;#\n&lt;p&gt;&lt;a href=\"$pathtoparser$chsetstr/$root$path$file\"&gt;Change Text Only Settings&lt;\/a&gt;\n&lt;p&gt;&lt;a href=\"http:\/\/$root$path$file\"&gt;Graphic version of this page&lt;\/a&gt;\n&lt;\/font&gt;\n&lt;!-- This page parsed by Betsie version $version--&gt;\n&lt;\/body&gt;#is;
	    
	};
	
    }
    
    return $line;
    
}

# url calc takes an inpath (is full url without http:/ at beginning
# ie it expects it to begin with a slash and then have the domain name,
# and then whatever else we have or have not got...
sub urlcalc {

    my $url = shift;
    my $root = "";
    my $path = "";
    my $file = "";
    
    $url =~ s#^\/([^\/]*)##;
    $root = $1;
    ($path, $file) = $url =~ /(.*\/)(.*?)$/;
    if ($path eq "") { $path = "\/"; }
    if ($file eq "/") { $file = ""; }
    
    return $root, $path, $file;
    
}

# alarm
# kills hanging Betsies. added by Damion Yates From BBC R&amp;D (Kingswood)
# doesn't work on machines that don't implement alarm
sub alarm {
    my $signame = shift;

    select(STDOUT); # in case we're timing out on a socket...

    warn "Betsie Alert: Timeout after $alarm seconds SIG$signame received\n";

    error("Attempt to load this page timed out. Please try again later.");

    exit 1;
}

# safe
# makes sure the url given is in the safe list

sub safe {
    
    my $url = shift;
    
    return 1 if ($url =~ /^(javascript|mailto):/is);
    
    for (@safe) {
	return 1 if ($url =~ /\w+:\/\/((\w|-)+\.)*$_/is);
    }
    return 0;
    
}

# make_body
# returns a suitable body tag
# including settings page if appropriate
sub make_body {
    
    my $b = "";
    my ($slash, $set, $code, $font, $font_size) = split '', $setstr;
    
    # brief sanity check - font size must be 1 to 7, code 0 to 3, font 0 to 9 (hence no check)
    # we don't really care about set or slash. in fact we don't even use slash.
    if ($font_size &gt; 7 || $font_size == 0) { $font_size = 5; }
    if ($code &gt; 3) { $code = 0; }
    
    if ($set == 1) {
	
	$b = "&lt;h1&gt;Text Only Settings Page:&lt;/h1&gt;
&lt;p&gt;You can change the text-only settings by selecting from the following links. Select the last link when you are done.
&lt;p&gt;Alternatively, &lt;a href=\"$pathtoparser/1005/$root$path$file\"&gt;select this link&lt;/a&gt; to return to the default settings.
&lt;h2&gt;Colours:&lt;/h2&gt;
&lt;p&gt;&lt;a href=\"$pathtoparser/10$font$font_size/$root$path$file\"&gt;Yellow On Black&lt;/a&gt;
, &lt;a href=\"$pathtoparser/11$font$font_size/$root$path$file\"&gt;Black On White&lt;/a&gt;
, &lt;a href=\"$pathtoparser/12$font$font_size/$root$path$file\"&gt;White On Blue&lt;/a&gt;
, &lt;a href=\"$pathtoparser/13$font$font_size/$root$path$file\"&gt;Black On Cream&lt;/a&gt;	
&lt;h2&gt;Font Size:&lt;/h2&gt;
&lt;p&gt;&lt;a href=\"$pathtoparser/1".$code.$font."1/$root$path$file\"&gt;Tiny&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code.$font."2/$root$path$file\"&gt;Small&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code.$font."3/$root$path$file\"&gt;Medium Small&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code.$font."4/$root$path$file\"&gt;Medium&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code.$font."5/$root$path$file\"&gt;Large&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code.$font."6/$root$path$file\"&gt;Extra Large&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code.$font."7/$root$path$file\"&gt;Extra Extra Large&lt;/a&gt;
&lt;h2&gt;Font:&lt;/h2&gt;
&lt;p&gt;&lt;a href=\"$pathtoparser/1".$code."0$font_size/$root$path$file\"&gt;Verdana&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code."1$font_size/$root$path$file\"&gt;Times&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code."2$font_size/$root$path$file\"&gt;Courier&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code."3$font_size/$root$path$file\"&gt;Helvetica&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code."4$font_size/$root$path$file\"&gt;Arial&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code."5$font_size/$root$path$file\"&gt;Bookman Old Style&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code."6$font_size/$root$path$file\"&gt;Geneva&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code."7$font_size/$root$path$file\"&gt;Chicago&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code."8$font_size/$root$path$file\"&gt;Courier New&lt;/a&gt;
, &lt;a href=\"$pathtoparser/1".$code."9$font_size/$root$path$file\"&gt;System&lt;/a&gt;
&lt;h2&gt;Notes:&lt;/h2&gt;
&lt;p&gt;Not all browsers support all possible font, size and colour combinations.
&lt;p&gt;Most browsers allow you to specify your own font, size and colour combinations, overriding any given 
by the current page. You may find that route more flexible than the options allowed here. Consult your browser
documentation for details.
&lt;hr&gt;
&lt;p&gt;&lt;b&gt;&lt;a href=\"$pathtoparser/0$code$font$font_size/$root$path$file\"&gt;Select this link when done&lt;/a&gt;&lt;/b&gt;";

    }
	
    $b = "&lt;body bgcolor=\"$bg[$code]\" text=\"$text[$code]\" link=\"$link[$code]\" alink=\"$alink[$code]\" vlink=\"$vlink[$code]\"&gt;\n&lt;font face=\"$font_face[$font]\" size=\"$font_size\"&gt;\n" . $b;
	
    return $b;
    
}
</pre></body></html>