/\n\n/gi;
$data =~ s/
/\n/gi;
$data =~ s/<[^>]+>//g;
if ($data =~ /\Q$re\E/i) {
return ($title, $data);
}
return ( );
}
# cgi_page_title(module, cgi)
# Given a CGI, return the text for its page title, if possible
sub cgi_page_title
{
local ($m, $cgi) = @_;
local $data = &read_file_contents(&module_root_directory($m)."/".$cgi);
local $rv;
if ($data =~ /(ui_print_header|ui_print_unbuffered_header)\([^,]+,[^,]*(\$text\{'([^']+)'|\$text\{"([^"]+)"|\&text\('([^']+)'|\&text\("([^"]+)")/) {
# New header function, with arg before title
local $msg = $3 || $4 || $5 || $6;
local %mtext = &load_language($m);
$rv = $mtext{$msg};
}
elsif ($data =~ /(^|\s|mail_page_)header\(\s*(\$text\{'([^']+)'|\$text\{"([^"]+)"|\&text\('([^']+)'|\&text\("([^"]+)")/) {
# Old header function
local $msg = $3 || $4 || $5 || $6;
local %mtext = &load_language($m);
$rv = $mtext{$msg};
}
if ($cgi eq "index.cgi" && !$rv) {
# If no title was found for an index.cgi, use module title
local %minfo = &get_module_info($m);
$rv = $minfo{'desc'};
}
return $rv;
}
# cgi_page_args(module, cgi)
# Given a module and CGI name, returns a string of URL parameters that can be
# used for linking to it. Returns "none" if parameters are needed, but cannot
# be determined.
sub cgi_page_args
{
local ($m, $cgi) = @_;
local $mroot = &module_root_directory($m);
if (-r "$mroot/cgi_args.pl") {
# Module can tell us what args to use
&foreign_require($m, "cgi_args.pl");
$args = &foreign_call($m, "cgi_args", $cgi);
if (defined($args)) {
return $args;
}
}
if ($cgi eq "index.cgi") {
# Index page is always safe to link to
return undef;
}
# Otherwise check if it appears to parse any args
local $data = &read_file_contents($mroot."/".$cgi);
if ($data =~ /(ReadParse|ReadParseMime)\(/) {
return "none";
}
return undef;
}
1;