Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Apr 2005 21:39:55 +0200
From:      Max Laier <max@love2party.net>
To:        freebsd-www@freebsd.org
Subject:   Re: [CGI] (Bi-)Monthly XML-composer
Message-ID:  <200504082140.01725.max@love2party.net>
In-Reply-To: <4256C8CC.9060102@elischer.org>
References:  <200504081532.19834.max@love2party.net> <4256C8CC.9060102@elischer.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--nextPart2175418.iL6sv8IIRH
Content-Type: multipart/mixed;
  boundary="Boundary-01=_M4tVCcCa8Yi94Zf"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

--Boundary-01=_M4tVCcCa8Yi94Zf
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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 al=
so
> > 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-if=
y=20
the form.  Do we have Perl CGI on www or do we really need to do this with=
=20
cgi-lib.pl?  I'd really love to get this done.  Comments please.

Thanks.

=2D-=20
/"\  Best regards,                      | mlaier@freebsd.org
\ /  Max Laier                          | ICQ #67774661
 X   http://pf4freebsd.love2party.net/  | mlaier@EFnet
/ \  ASCII Ribbon Campaign              | Against HTML Mail and News

--Boundary-01=_M4tVCcCa8Yi94Zf
Content-Type: text/plain;
  charset="iso-8859-1";
  name="monthly.cgi"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="monthly.cgi"

#!/usr/bin/perl -w

require "./cgi-style.pl";

use CGI qw(:all);
use strict;


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

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

my @messages;

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

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

	my $Spaces =3D " " x ($Indent*3);
	if (!@Text)
	{
		# No text in the tag
		return ("$Spaces<$TagEtc >\n");
	}
	elsif (@Text =3D=3D 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) =3D @_;

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

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

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

	my @hidden;

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

	my @contacts;
	foreach my $Num (1..$NumDevelopers)
	{
		my $fname =3D param("FirstName$Num") || "";
		my $lname =3D param("LastName$Num")  || "";
		my $email =3D 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  =3D param("Url$Num")  || "";
		my $desc =3D 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=3D\"$url\"", $desc));
		}
		else
		{
			push(@links, xml(2, "url href=3D\"$url\""));
		}
	}

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

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

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

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

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

	my $title =3D "FreeBSD project submission output";

	my @contents =3D xml(0, "project cat=3D\'$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 =3D join('', @contents);

	$contents =3D "<!-- 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 =3D> "FirstName$Num", -size =3D> 20)),
			td(textfield(-name =3D> "LastName$Num",  -size =3D> 20)),
			td(textfield(-name =3D> "Email$Num",     -size =3D> 32))));
}

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

my @TaskTable;
foreach my $Num (1..$NumTasks)
{
	push(@TaskTable,
		 TR(td(textarea(-name =3D> "Task$Num", -rows =3D> 3, -cols =3D> 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 foll=
owing:",
   br,
   start_form(),
  =20
   h3("Project:"),
   textfield(-name =3D> "Project", -size =3D> "32"),

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

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


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

__END__

--Boundary-01=_M4tVCcCa8Yi94Zf--

--nextPart2175418.iL6sv8IIRH
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (FreeBSD)

iD8DBQBCVt4RXyyEoT62BG0RAiViAJ9aEj8b7//ZRQcqPXaV7Cvcn0oF9QCdFVVp
xFZ3B9wu1oHa+Y4g+FFRxs0=
=Zbuo
-----END PGP SIGNATURE-----

--nextPart2175418.iL6sv8IIRH--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200504082140.01725.max>