head	1.10;
access;
symbols
	TIGRIS_1_1_0RC2:1.10
	TIGRIS_1_1_0RC1:1.10
	TIGRIS_1_1:1.10.0.12
	TIGRIS_1_0_8:1.10
	TIGRIS_1_0_8RC3:1.10
	TIGRIS_1_0_8RC2:1.10
	TIGRIS_1_0_8RC1:1.10
	TIGRIS_1_0_7:1.10
	TIGRIS_1_0_7RC3:1.10
	TIGRIS_1_0_7RC2:1.10
	TIGRIS_1_0_7RC1:1.10
	TIGRIS_1_0_6:1.10
	TIGRIS_1_0_6RC5:1.10
	TIGRIS_1_0_6RC4:1.10
	TIGRIS_1_0_6RC3:1.10
	TIGRIS_1_0_6RC2:1.10
	TIGRIS_1_0_6RC1:1.10
	TIGRIS_1_0_5:1.10
	TIGRIS_1_0_5RC6:1.10
	TIGRIS_1_0_5RC5:1.10
	TIGRIS_1_0_5RC4:1.10
	TIGRIS_1_0_5RC3:1.10
	TIGRIS_1_0_5RC2:1.10
	TIGRIS_1_0_5RC1:1.10
	TIGRIS_1_0_4:1.10
	TIGRIS_1_0_3:1.10
	TIGRIS_1_0_2:1.10
	TIGRIS_1_0_1:1.10
	TIGRIS_1_0:1.10.0.14
	TIGRIS_1_0_0:1.10
	TIGRIS_1_0_0_RC1:1.10.0.10
	HELM_PEER_PORT_BRANCH:1.10.0.8
	TIGRIS_0_9_2_4:1.10
	TIGRIS_0_9_2_3:1.10
	TIGRIS_0_9_2:1.10.0.6
	TIGRIS_0_9_0:1.10.0.4
	TIGRIS_0_8_4:1.10.0.2
	TIGRIS_710_FF:1.10
	TIGRIS_706:1.10
	TIGRIS_705:1.8
	TIGRIS_704:1.8
	TIGRIS_703:1.8
	TIGRIS_702:1.8
	TIGRIS_701:1.8
	TIGRIS_SEP_13_2000:1.2.0.2
	TIGRIS_BASELINE:1.8;
locks; strict;
comment	@# @;


1.10
date	2000.10.26.23.28.08;	author npm;	state Exp;
branches;
next	1.9;

1.9
date	2000.10.26.18.58.09;	author kmaples;	state Exp;
branches;
next	1.8;

1.8
date	2000.09.20.18.15.51;	author davidp;	state Exp;
branches;
next	1.7;

1.7
date	2000.09.19.20.50.57;	author ms;	state Exp;
branches;
next	1.6;

1.6
date	2000.09.14.22.53.10;	author kmaples;	state Exp;
branches;
next	1.5;

1.5
date	2000.09.14.20.48.42;	author kmaples;	state Exp;
branches;
next	1.4;

1.4
date	2000.09.14.16.54.20;	author kmaples;	state Exp;
branches;
next	1.3;

1.3
date	2000.09.14.05.42.35;	author kmaples;	state Exp;
branches;
next	1.2;

1.2
date	2000.07.20.22.40.54;	author kmaples;	state Exp;
branches;
next	1.1;

1.1
date	2000.05.06.00.49.41;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.10
log
@made search less greddy, now can deal with multiple links on one .wm line better
@
text
@#!/usr/bin/perl -i
# Copyright (c) 2000 Collab.Net, Inc.
# $Id: link-cooker,v 1.9 2000/10/26 18:58:09 kmaples Exp $

# Replaces href and action w/ $res.encodeUrl(url) so that
# the session ID gets inserted by Apache-JServ if cookies
# are disabled. Needs to be run on both templates and static
# html pages.

## what about: <LINK REL="stylesheet" TYPE="text/css" HREF="$res.encodeUrl("/sxc.css")"> ??
## It appears that this isn't a problem, but may become so in the future...

unless($ENV{DOMAIN}){
	print "WARNING: 'DOMAIN' environmental is not set!\n";
	print "WARNING: This may prevent links pointing to\n";
	print "WARNING: the current domain from being recognized\n";
	print "WARNING: and properly wrapped\n";
}
my $domain = $ENV{DOMAIN} || '--NONE SET--';

# print "\ndomain is set to $domain\n\n";

while(<>){
    ## Speed up the processing by skipping the irrelevant:
    unless(m/HREF|ACTION/i){
        print;
        next;
    }
    ## Strip out any previous calls to 'encodeUrl':
    ## $res.encodeUrl(foo)   -->   foo
#    s/\$res.encodeUrl\(([^)]*)\)/$1/gi; ## this munged urls w/ 
                                         ## func. calls						
    ## The assumption that I'm making is that a call to this
    ## function is either terminated by whitespace (separating
    ## html tokens) or '>' (terminating the tag): 
    s/\$res.encodeUrl\(([^\s\>]*)\)("?(\s+|\>))/$1$2/gi;

    ## capture the name/value pair the string represents:
    ## Note the placement of the quotation marks, as this is
    ## is _exactly_ what you get left with:
    ## href="foobar"   -->    href="$res.encodeUrl("foobar")"

	## The quoting can get touchy in this operation ... I've 
	## found it best NOT to comment inside the substitution
	## string, and to break up the string so that nothing 
	## tries to interpolate '$res.encodeUrl':
	
	s%\b((action|href)\s*=\s*)("?[^\s\>]+"?)%
		my ($n, $v) = ($1, $3);
		# It should be sufficient to remove all quotation
		# marks since they're being reintroduced:
		$v =~ s/"//g;

		# If the links are either 'mailto', or links
		# to external resources, don't wrap them in the
     		# encode function:
		if($v =~ m/^(mailto|https?:\/\/)/i){
			# wrap links inside of the current domain:
			if($v =~ m/^https?:\/\/([-\w.]*\.)?$domain/i){
				qq[$n"] . q[$res.encodeUrl] . qq[("$v")"];
			} else {
				qq[$n"$v"];
			}
		# Otherwise, wrap it up and send it out:
		} else {
			qq[$n"] . q[$res.encodeUrl] . qq[("$v")"];
		}
	%emgix;

    print;
}


__END__
## For posterity - previous version of same:

while (<>)
{
    # strip out any prior encodeUrl call
    s/\$res.encodeUrl\(([^)]*)\)/$1/gi;

    # non-quoted href
    s/(href\s*=\s*)([^\s\>]+)/${1}\$res.encodeUrl($2)/gi;

    # quoted href; WARNING: due to webmacro, there may be nested quotes!!
    #s/(href\s*=\s*)(\"[^\"]*\")/${1}\$res.encodeUrl($2)/gi;

    # non-quoted action
    s/(action\s*=\s*)([^\s\>]+)/${1}\$res.encodeUrl($2)/gi;

    # quoted action; WARNING: due to webmacro, there may be nested quotes!!
    #s/(action\s*=\s*)(\"[^\"]*\")/${1}\$res.encodeUrl($2)/gi;

    print;
}

@


1.9
log
@Fixed bug found by Ed which was causing hrefs w/ function calls in them
e.g. '()' - not to be 'cooked' correctly.
@
text
@d3 1
a3 1
# $Id: link-cooker,v 1.8 2000/09/20 18:15:51 davidp Exp $
d36 1
a36 1
    s/\$res.encodeUrl\((.*)\)("?(\s+|\>))/$1$2/gi;
@


1.8
log
@Backed out the change encodeUrl --> encodeURL.
We need "encodeUrl" until we can upgrade the jsdk.
@
text
@d3 1
a3 1
# $Id: link-cooker,v 1.6 2000/09/14 22:53:10 kmaples Exp $
d31 6
a36 1
    s/\$res.encodeUrl\(([^)]*)\)/$1/gi;
@


1.7
log
@Accidently added sandboxctl rather then sandboxctl.in.
Also made sandbox reloading faster
Submitted by:	Michael Salmon
Reviewed by:	Michael Stack
@
text
@d31 1
a31 1
    s/\$res.encodeURL\(([^)]*)\)/$1/gi;
d61 1
a61 1
			qq[$n"] . q[$res.encodeURL] . qq[("$v")"];
d75 1
a75 1
    s/\$res.encodeURL\(([^)]*)\)/$1/gi;
d78 1
a78 1
    s/(href\s*=\s*)([^\s\>]+)/${1}\$res.encodeURL($2)/gi;
d84 1
a84 1
    s/(action\s*=\s*)([^\s\>]+)/${1}\$res.encodeURL($2)/gi;
d91 1
a91 1
l
@


1.6
log
@Made the regex a little more discriminating about what constitutes a link
inside the current domain; fix bug so that if DOMAIN is not set, all links
starting 'http' are treated as outside the current domain.
@
text
@d3 1
a3 1
# $Id: link-cooker,v 1.5 2000/09/14 20:48:42 kmaples Exp $
d31 1
a31 1
    s/\$res.encodeUrl\(([^)]*)\)/$1/gi;
d61 1
a61 1
			qq[$n"] . q[$res.encodeUrl] . qq[("$v")"];
d75 1
a75 1
    s/\$res.encodeUrl\(([^)]*)\)/$1/gi;
d78 1
a78 1
    s/(href\s*=\s*)([^\s\>]+)/${1}\$res.encodeUrl($2)/gi;
d84 1
a84 1
    s/(action\s*=\s*)([^\s\>]+)/${1}\$res.encodeUrl($2)/gi;
d91 1
a91 1

@


1.5
log
@Added filter for links to domains in the current domain.
@
text
@d3 1
a3 1
# $Id: link-cooker,v 1.4 2000/09/14 16:54:20 kmaples Exp $
d19 3
a21 1
my $domain = $ENV{DOMAIN} || '';
d54 1
a54 1
			if($v =~ m/^http.*$domain/i){
@


1.4
log
@Modified regex to skip hrefs which (are presumed) to point to external
resources (i.e., begin with 'http')
@
text
@d3 1
a3 1
# $Id: $
d13 8
d50 7
a56 3
		if($v =~ m/^(mailto|https?:\/\/)/){
			qq[$n"$v"];
		
@


1.3
log
@Fixed bug which seemed to permit the creeping accumulation of quotation marks
if one was unfortunate enough to repeatedly run this script on the same files.
@
text
@d3 1
a3 1
# Last modified 07/20/2000 by kmaples@@collab.net
d24 2
d38 5
a42 1
		if($v =~ m/^mailto/){
d44 2
@


1.2
log
@Rewrote regex to skip 'mailto' tags, and treat quotation marks more sensibly
within and without HREFs and ACTIONs; skips lines irrelevant to processing.
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d33 3
a35 1
        $v =~ s/^"//; $v =~ s/"$//;
@


1.1
log
@Moved here from the sourcexchange/templates directory.  Changed the location of Perl from /usr/local/bin/perl to /usr/bin/perl.  Minor tweaks to the output of template-cooker.
@
text
@d3 1
d10 38
d50 2
a51 2
	# strip out any prior encodeUrl call
	s/\$res.encodeUrl\(([^)]*)\)/$1/gi;
d53 2
a54 2
	# non-quoted href
	s/(href\s*=\s*)([^\s\>]+)/${1}\$res.encodeUrl($2)/gi;
d56 2
a57 2
	# quoted href; WARNING: due to webmacro, there may be nested quotes!!
	#s/(href\s*=\s*)(\"[^\"]*\")/${1}\$res.encodeUrl($2)/gi;
d59 2
a60 2
	# non-quoted action
	s/(action\s*=\s*)([^\s\>]+)/${1}\$res.encodeUrl($2)/gi;
d62 2
a63 2
	# quoted action; WARNING: due to webmacro, there may be nested quotes!!
	#s/(action\s*=\s*)(\"[^\"]*\")/${1}\$res.encodeUrl($2)/gi;
d65 1
a65 1
	print;
d67 1
@

