[Bio] / Sprout / NmpdrPage.pm Repository:
ViewVC logotype

Annotation of /Sprout/NmpdrPage.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : parrello 1.1 #
2 :     # Module to render a page that looks like an NMPDR page.
3 :     #
4 :     #
5 :    
6 :     #### WARNING! THIS IS NOT A PACKAGE. IT'S A SET OF INCLUDED
7 :     #### SUBROUTINES! THIS IS NOT A PACKAGE.
8 :    
9 :     use FIG_Config;
10 :     use LWP::UserAgent;
11 :    
12 :     sub get_php_include
13 :     {
14 :     my($path) = @_;
15 :     my $base = "$FIG_Config::fig_disk/../html";
16 :     $path = "$base/$path";
17 :     local $/ = undef;
18 :     if (!open(F, "<$path"))
19 :     {
20 :     warn "get_php_include(): Cannot open $path: $!\n";
21 :     return;
22 :     }
23 :     my $out = <F>;
24 :     close(F);
25 :     return $out;
26 :     }
27 :    
28 :     sub expand_nmpdr_page
29 :     {
30 :     my($title, $content) = @_;
31 :    
32 :     my $header = get_php_include("includes/header-fig.inc");
33 :     my $left_nav = get_php_include("includes/left_nav-fig.inc");
34 :     my $footer = get_php_include("includes/footer.inc");
35 :    
36 :     my $out = <<'END';
37 :     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
38 :     <html xmlns="http://www.w3.org/1999/xhtml">
39 :     <head>
40 :     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
41 :     END
42 :     $out .= "<title>$title</title>\n";
43 :    
44 :     $out .= <<'END';
45 :     <link href="../content/NMPDR.css" rel="stylesheet" type="text/css" />
46 :     </head>
47 :    
48 :     <body>
49 :     <div id="header">
50 :     END
51 :     $out .= $header;
52 :     $out .= <<'END';
53 :     </div>
54 :     <div id="container">
55 :    
56 :     <div id="sidebar">
57 :     END
58 :     $out .= $left_nav;
59 :     $out .= <<'END';
60 :     </div>
61 :     <div id="content">
62 :     END
63 :     $out .= $content;
64 :    
65 :     $out .= <<'END';
66 :    
67 :     </div>
68 :     <div id="footer">
69 :     END
70 :     $out .= $footer;
71 :     $out .= <<'END';
72 :     </div>
73 :     </div>
74 :     </body>
75 :     </html>
76 :     END
77 :     return $out;
78 :     }
79 :    
80 :     sub print_template_header
81 :     {
82 :     my($title) = @_;
83 :    
84 :     my $header = get_php_include("includes/header-fig.inc");
85 :     my $left_nav = get_php_include("includes/left_nav-fig.inc");
86 :    
87 :     print <<'END';
88 :     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
89 :     <html xmlns="http://www.w3.org/1999/xhtml">
90 :     <head>
91 :     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
92 :     END
93 :     print "<title>$title</title>\n";
94 :     print <<'END';
95 :     <link href="../content/NMPDR.css" rel="stylesheet" type="text/css" />
96 :     </head>
97 :    
98 :     <body>
99 :     <div id="header">
100 :     END
101 :     print $header;
102 :     print <<'END';
103 :     </div>
104 :     <div id="container-cal">
105 :    
106 :     <div id="sidebar">
107 :     END
108 :     print $left_nav;
109 :     print <<'END';
110 :     </div>
111 :     <div id="content">
112 :     END
113 :     }
114 :    
115 :     sub print_template_footer
116 :     {
117 :     my $footer = get_php_include("includes/footer.inc");
118 :     print <<'END';
119 :    
120 :     </div>
121 :     <div id="footer">
122 :     END
123 :     print $footer;
124 :     print <<'END';
125 :     </div>
126 :     </div>
127 :     </body>
128 :     </html>
129 :     END
130 :     }
131 :    
132 :     # Look for relative URLs in the body of a template string and
133 :     # replace them with absolute URLs. On entry, the first parameter
134 :     # ($template) should be a giant HTML string representing the
135 :     # template, and the second parameter ($base) should be the
136 :     # proposed new base URL. The modified template will be returned.
137 :     sub fix_template_urls {
138 :     my ($template, $base) = @_;
139 :     # Strip any trailing slash off the base.
140 :     if ($base =~ m!/$!) {
141 :     substr $base, -1, 1, "";
142 :     }
143 :     # Create an output string.
144 :     my $retVal = "";
145 :     # Denote we're at the beginning of the template string.
146 :     my $pos = 0;
147 :     # Loop through the input template, looking for possible
148 :     # URLs.
149 :     while ($template =~ m/(href|src|action)="([^"]+)"/gi) {
150 :     # At this point, $1 should be a keyword that has a
151 :     # URL as its value and $2 will be the URL. We use the
152 :     # pos() function to find where we are in the template
153 :     # string. In particular, we want to know where the
154 :     # keyword starts. We begin by computing the length of
155 :     # the entire matched string.
156 :     my $matchLen = length($1) + 3 + length($2);
157 :     # Get the keyword and URL values.
158 :     my $keyword = $1;
159 :     my $url = $2;
160 :     # Compute the start position and copy the stuff we
161 :     # passed over on the way to finding this match.
162 :     my $startPos = pos($template) - $matchLen;
163 :     $retVal .= substr($template,$pos, $startPos - $pos);
164 :     # Append the keyword and the =".
165 :     $retVal .= "$keyword=\"";
166 :     # Find out if this is an absolute or relative URL.
167 :     if ($url =~ /^http:/i) {
168 :     # Absolute URL. Move it unmodified.
169 :     $retVal .= $url;
170 :     } elsif ($url =~ m!^/!i) {
171 :     # Here it's relative to the site root. We
172 :     # stuff the caller-specified bnase URL in
173 :     # front.
174 :     $retVal .= "$base$url";
175 :     } else {
176 :     # Here it's relative to the current location. Since
177 :     # it's a Typo3 web page, the curent location is
178 :     # the site root. We have to insert a slash between
179 :     # the base and the URL.
180 :     $retVal .= "$base/$url";
181 :     }
182 :     # Add the closing quote.
183 :     $retVal .= '"';
184 :     # Denote we've processed up through the end of the
185 :     # matched section.
186 :     $pos = $startPos + $matchLen;
187 :     }
188 :     # Check for a residual.
189 :     if ($pos < length($template)) {
190 :     # Here there's unmatched residual that needs to be
191 :     # added at the end of the return string.
192 :     $retVal .= substr($template, $pos);
193 :     }
194 :     # Return the result.
195 :     return $retVal;
196 :     }
197 :    
198 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3