[CGI] (Bi-)Monthly XML-composer

Max Laier max at love2party.net
Fri Apr 8 12:40:35 PDT 2005


On Friday 08 April 2005 20:09, Julian Elischer wrote:
> Max Laier wrote:
> >Hi,
> >
> >as discussed here briefly after the last round of the status reports,
> > Julian has come up with a CGI-script that helps to fill the bi-monthly
> > status report xml-template.  I extended it slightly to take care of the
> > newer features.  In contrast to Julian's original approach, this one also
> > sets "Content-Type: text/plain" so that you get a download of the
> > resulting xml, rather than a html to copy and paste from.  I found that
> > easier to handle esp. in cli-environments.
>
> sure..  I'm not fussed on how this is done.. as long as it's easier than
> hand formatiting it :-)
>
> >In preparation on the next round of status-reports, we'd like to get
> > something along those lines on the FreeBSD website ASAP.  Hence I really
> > appreciate review and especially style nits ("cooperate identity" etc.).
> >
> >Thanks in advance, and many thanks to Julian for coming up with the
> > prototype.
>
> probably a better name.. :-) monthly_formatter.cgi or something.
>
> also, the reason we ask you to cut-n-paste the result into your mail
> program is that just adding a button
> "submit" is asking for 10,000 trolls to spam the monthly list with crap.

That's understood.  Hence the download.

Here is a slightly cleaned up version, that uses cgi-style.pl to FreeBSD-ify 
the form.  Do we have Perl CGI on www or do we really need to do this with 
cgi-lib.pl?  I'd really love to get this done.  Comments please.

Thanks.

-- 
/"\  Best regards,                      | mlaier at freebsd.org
\ /  Max Laier                          | ICQ #67774661
 X   http://pf4freebsd.love2party.net/  | mlaier at EFnet
/ \  ASCII Ribbon Campaign              | Against HTML Mail and News
-------------- next part --------------
#!/usr/bin/perl -w

require "./cgi-style.pl";

use CGI qw(:all);
use strict;


my $Submit = param("Submit");
my $debug  = param("debug") || "";

my $NumDevelopers = 3;
my $NumLinks      = 4;
my $NumTasks      = 5;

my @messages;

#
# Routine to format some xml nicely
#
sub xml
{
	my($Indent, $TagEtc, @Text) = @_;

	my($Tag, $Etc) = split(' ', $TagEtc, 2);

	my $Spaces = " " x ($Indent*3);
	if (!@Text)
	{
		# No text in the tag
		return ("$Spaces<$TagEtc >\n");
	}
	elsif (@Text == 1)
	{
		# Bottom level tag - output on one line
		return ("$Spaces<$TagEtc>@Text</$Tag>\n");
	}
	else
	{
		# This is not a bottom level tag - output a new line after
		# starting tag
		return ("$Spaces<$TagEtc>\n",
				@Text,
				"$Spaces</$Tag>\n");
	}
}

#
# As above to format indented text but no tag
#
sub xmltext
{
	my($Indent, @Text) = @_;

	my $Spaces = " " x ($Indent*3);

	return map { "$Spaces$_\n" } @Text;
}

if ($Submit)
{
	my $errors = 0;

	my @hidden;

	my $Project = param("Project") || "";
	my $Category = param("Category") || "misc";
	push(@hidden, hidden("Project"));

	my @contacts;
	foreach my $Num (1..$NumDevelopers)
	{
		my $fname = param("FirstName$Num") || "";
		my $lname = param("LastName$Num")  || "";
		my $email = param("Email$Num")     || "";

		push(@hidden, hidden("FirstName$Num"));
		push(@hidden, hidden("LastName$Num"));
		push(@hidden, hidden("Email$Num"));

		next unless $fname || $lname || $email;

		my @name;
		push(@name, xml(4, 'given',  $fname)) if $fname;
		push(@name, xml(4, 'common', $lname)) if $lname;

		my @person;
		push(@person, xml(3, 'name',  "", @name))  if @name;
		push(@person, xml(3, 'email', $email)) if $email;

		push(@contacts, xml(2, 'person', "", @person));
	}

	if (!@contacts)
	{
		++$errors;
		push(@messages, b("Please specify at least one contact"));
	}

	my @links;
	foreach my $Num (1..$NumLinks)
	{
		my $url  = param("Url$Num")  || "";
		my $desc = param("Desc$Num") || "";

		push(@hidden, hidden("Url$Num"));
		push(@hidden, hidden("Desc$Num"));

		next unless $url;
		my @link;
		if ($desc)
		{
			push(@links, xml(2, "url href=\"$url\"", $desc));
		}
		else
		{
			push(@links, xml(2, "url href=\"$url\""));
		}
	}

	my @tasks;
	foreach my $Num (1..$NumTasks)
	{
		my $desc = param("Task$Num") || "";
		$desc =~ s/\r//g;
		my @desc = split("\n", $desc);

		push(@hidden, hidden("Task$Num"));

		next unless $desc;
                push(@tasks, xml(2, "task", "",xmltext(3, @desc)));
	}

	my $info = param("SubmittedInfo") || "";
	push(@hidden, hidden("SubmittedInfo"));

	$info =~ s/\r//g;
	my @info = split("\n", $info);

	my $title = "FreeBSD project submission output";

	my @contents = xml(0, "project cat=\'$Category\'",
	    xml(1, "title", $Project),
	    "\n",
	    xml(1, "contact", "", @contacts),
	    "\n",
            xml(1, "links", "", @links),
            "\n",
            xml(1, "body",
                xml(2, "p", "", xmltext(3, @info))),
            "\n",
            xml(1, "help", "", @tasks),
        );
	my $contents = join('', @contents);

	$contents = "<!-- Mail to: monthly\@freebsd.org -->\n$contents";

	if (!$errors)
	{
                print "Content-Type: text/plain\n\n";
                print $contents;
                exit;
	}
}

my @DeveloperTable;
foreach my $Num (1..$NumDevelopers)
{
	push(@DeveloperTable,
		 TR(td(textfield(-name => "FirstName$Num", -size => 20)),
			td(textfield(-name => "LastName$Num",  -size => 20)),
			td(textfield(-name => "Email$Num",     -size => 32))));
}

my @LinksTable;
foreach my $Num (1..$NumLinks)
{
	push(@LinksTable,
		 TR(td(textfield(-name => "Url$Num",      -size => 55)),
			td(textfield(-name => "Desc$Num",     -size => 20))));
}

my @TaskTable;
foreach my $Num (1..$NumTasks)
{
	push(@TaskTable,
		 TR(td(textarea(-name => "Task$Num", -rows => 3, -cols => 60))));
}

print
  (html_header("Submitting a FreeBSD Project Status Report"),
   hr,
   join("<BR>\n", @messages, ""),
   p,
   "To submit status information about a FreeBSD project, fill out the following:",
   br,
   start_form(),
   
   h3("Project:"),
   textfield(-name => "Project", -size => "32"),

   h3("Category:"),
   scrolling_list(-name => "Category", -values => ['proj', 'docs', 'kern',
       'arch', 'ports', 'vendor', 'misc'], -default => ['proj'], -size => 7,
       -multiple => 'false', -lables => {'proj'=> 'Projects (non-specific)',
       'docs' => 'Documentation', 'kern' => 'Kernel', 'arch' => 'Architectures',
       'ports' => 'Ports', 'vendor' => 'Vendor / 3rd party software',
       'misc' => 'Miscellaneous' }),
   
   h3("Developers:"),
   blockquote(table({"BORDER" => 0,
					 "COLS"   => 3,
					 "NOSAVE" => 1},
					TR(td("First Name"),
					   td("Family Name"),
					   td("Email address")),
					@DeveloperTable)),
   
   h3("Links:"),
   blockquote(table({"BORDER" => 0,
					 "COLS"   => 2,
					 "NOSAVE" => 1},
					TR(td("Url"),
					   td("Description (optional)")),
					@LinksTable)),
   
   h3("Present status:"),
   blockquote(textarea(-name => "SubmittedInfo",
					   -rows => 7,
					   -cols => 60)),

   h3("Open tasks (optional):"),
   blockquote(table({"BORDER" => 0,
					 "COLS"   => 5,
					 "NOSAVE" => 1},
					TR(td("Description")),
					@TaskTable)),


   submit(-name => "Submit", -label => "Download XML"),
   reset(-value => "Reset"),
   br,
   end_form(),
   html_footer());

__END__
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-www/attachments/20050408/b0ec5969/attachment.bin


More information about the freebsd-www mailing list