diff --git a/trunk/functions.pl b/trunk/functions.pl index 941a70c..b6242e6 100644 --- a/trunk/functions.pl +++ b/trunk/functions.pl @@ -339,3 +339,16 @@ sub output_page #$stylesheet->output_as_bytes($output); <= for future use with XML::LibXSLT (>= 1.62) } } + +sub message +{ + my ($type, $text, $value) = @_; + my $message = XML::LibXML::Element->new( "message" ); + $message->setAttribute("type", $type); + $message->setAttribute("text", $text); + if ($value) + { + $message->setAttribute("value", $value); + } + return $message; +} diff --git a/trunk/index.pl b/trunk/index.pl index 4a2440b..52a0756 100644 --- a/trunk/index.pl +++ b/trunk/index.pl @@ -15,27 +15,15 @@ $page->appendChild(XML::LibXML::Element->new( "frontpage" )); if($query->param('information')) { - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "information"); - $message->setAttribute("text", $query->param('information')); - $message->setAttribute("value",$query->param('value')); - $page->appendChild($message); + $page->appendChild(message("information", $query->param('information'), $query->param('value'))); } elsif($query->param('error')) { - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "error"); - $message->setAttribute("text", $query->param('error')); - $message->setAttribute("value",$query->param('value')); - $page->appendChild($message); + $page->appendChild(message("error", $query->param('error'), $query->param('value'))); } elsif($query->param('warning')) { - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "warning"); - $message->setAttribute("text", $query->param('warning')); - $message->setAttribute("value",$query->param('value')); - $page->appendChild($message); + $page->appendChild(message("warning", $query->param('warning'), $query->param('value'))); } my $tagcloud = XML::LibXML::Element->new( "tagcloud" ); diff --git a/trunk/register.pl b/trunk/register.pl index 7dc3d32..4a26599 100644 --- a/trunk/register.pl +++ b/trunk/register.pl @@ -14,10 +14,7 @@ my $page = get_page_array(@userinfo); #check if user is logged in if($username) { - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "error"); - $message->setAttribute("text", "error_already_registered"); - $page->appendChild($message); + $page->appendChild(message("error", "error_already_registered")); $doc->setDocumentElement($page); @@ -38,10 +35,7 @@ elsif($query->param('user') and $query->param('pass') and $query->param('pass_re { $page->appendChild(XML::LibXML::Element->new( "registerform" )); - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "error"); - $message->setAttribute("text", "error_username_already_registered"); - $page->appendChild($message); + $page->appendChild(message("error", "error_username_already_registered")); $doc->setDocumentElement($page); @@ -60,10 +54,7 @@ elsif($query->param('user') and $query->param('pass') and $query->param('pass_re { $page->appendChild(XML::LibXML::Element->new( "registerform" )); - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "error"); - $message->setAttribute("text", "error_passwords_do_not_match"); - $page->appendChild($message); + $page->appendChild(message("error", "error_passwords_do_not_match")); $doc->setDocumentElement($page); @@ -74,10 +65,7 @@ elsif(not $query->param('user') and ($query->param('pass') or $query->param('pas { $page->appendChild(XML::LibXML::Element->new( "registerform" )); - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "error"); - $message->setAttribute("text", "error_insert_username"); - $page->appendChild($message); + $page->appendChild(message("error", "error_insert_username")); $doc->setDocumentElement($page); @@ -87,10 +75,7 @@ elsif(not $query->param('pass') and ($query->param('user') or $query->param('pas { $page->appendChild(XML::LibXML::Element->new( "registerform" )); - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "error"); - $message->setAttribute("text", "error_insert_password"); - $page->appendChild($message); + $page->appendChild(message("error", "error_insert_password")); $doc->setDocumentElement($page); @@ -100,10 +85,7 @@ elsif(not $query->param('pass_repeat') and ($query->param('user') or $query->par { $page->appendChild(XML::LibXML::Element->new( "registerform" )); - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "error"); - $message->setAttribute("text", "error_repeat_password"); - $page->appendChild($message); + $page->appendChild(message("error", "error_repeat_password")); $doc->setDocumentElement($page); diff --git a/trunk/settings.pl b/trunk/settings.pl index 1972990..191a9cc 100644 --- a/trunk/settings.pl +++ b/trunk/settings.pl @@ -21,10 +21,7 @@ if($userinfo->{'username'}) $page = get_page_array(@userinfo); - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "information"); - $message->setAttribute("text", "information_settings_changed"); - $page->appendChild($message); + $page->appendChild(message("information", "information_settings_changed")); } } @@ -37,10 +34,7 @@ if($userinfo->{'username'}) } else { - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "error"); - $message->setAttribute("text", "error_202c"); - $page->appendChild($message); + $page->appendChild(message("error", "error_202c")); } $doc->setDocumentElement($page); diff --git a/trunk/video.pl b/trunk/video.pl index 64189ed..44cf2db 100644 --- a/trunk/video.pl +++ b/trunk/video.pl @@ -93,10 +93,7 @@ if($query->url_param('id')) else { #output infobox - my $message = XML::LibXML::Element->new( "message" ); - $message->setAttribute("type", "information"); - $message->setAttribute("text", "information_comment_created"); - $page->appendChild($message); + $page->appendChild(message("information", "information_comment_created")); #add to database $dbh->do(qq{insert into comments (userid, videoid, text, timestamp) values (?, ?, ?, unix_timestamp())}, undef,