taskd/clone.sh: Syntax error fix
[girocco/testingthisout.git] / Girocco / CGI.pm
blobd3e5185676df377cc32aa54eca84a32aecd689e7
1 package Girocco::CGI;
3 use strict;
4 use warnings;
6 use Girocco::Config;
8 BEGIN {
9 our $VERSION = '0.1';
10 our @ISA = qw(Exporter);
11 our @EXPORT = qw(html_esc);
13 use CGI qw(:standard :escapeHTML -nosticky);
14 use CGI::Util qw(unescape);
15 use CGI::Carp qw(fatalsToBrowser);
19 sub new {
20 my $class = shift;
21 my ($heading, $section) = @_;
22 my $gcgi = {};
24 $section ||= 'administration';
26 $gcgi->{cgi} = CGI->new;
28 my $cgiurl = $gcgi->{cgi}->url(-absolute => 1);
29 ($gcgi->{srcname}) = ($cgiurl =~ m#^.*/\([a-zA-Z0-9_.\/-]+?\.cgi\)$#); #
30 $gcgi->{srcname} = "cgi/".$gcgi->{srcname} if $gcgi->{srcname};
32 print $gcgi->{cgi}->header(-type=>'text/html', -charset => 'utf-8');
34 print <<EOT;
35 <?xml version="1.0" encoding="utf-8"?>
36 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
37 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
39 <head>
40 <title>$Girocco::Config::name :: $heading</title>
41 <link rel="stylesheet" type="text/css" href="$Girocco::Config::gitwebfiles/gitweb.css"/>
42 <link rel="stylesheet" type="text/css" href="$Girocco::Config::gitwebfiles/girocco.css"/>
43 <link rel="shortcut icon" href="$Girocco::Config::gitwebfiles/git-favicon.png" type="image/png"/>
44 <script src="$Girocco::Config::gitwebfiles/mootools.js" type="text/javascript"></script>
45 <script src="$Girocco::Config::gitwebfiles/girocco.js" type="text/javascript"></script>
46 </head>
48 <body>
50 <div class="page_header">
51 <a href="http://git.or.cz/" title="Git homepage"><img src="$Girocco::Config::gitwebfiles/git-logo.png" width="72" height="27" alt="git" style="float:right; border-width:0px;"/></a>
52 <a href="$Girocco::Config::gitweburl">$Girocco::Config::name</a> / $section / $heading
53 </div>
55 EOT
57 bless $gcgi, $class;
60 sub DESTROY {
61 my $self = shift;
62 if ($self->{srcname} and $Girocco::Config::giroccourl) {
63 print <<EOT;
64 <div align="right">
65 <a href="$Girocco::Config::giroccourl?a=blob;f=$self->{srcname}">(view source)</a>
66 </div>
67 EOT
69 print <<EOT;
70 </body>
71 </html>
72 EOT
75 sub cgi {
76 my $self = shift;
77 $self->{cgi};
80 sub err {
81 my $self = shift;
82 print "<p style=\"color: red\">@_</p>\n";
83 $self->{err}++;
86 sub err_check {
87 my $self = shift;
88 my $err = $self->{err};
89 $err and print "<p style=\"font-weight: bold\">Operation aborted due to $err errors.</p>\n";
90 $err;
93 sub wparam {
94 my $self = shift;
95 my ($param) = @_;
96 my $val = $self->{cgi}->param($param);
97 defined $val and $val =~ s/^\s*(.*?)\s*$/$1/;
98 $val;
101 sub srcname {
102 my $self = shift;
103 my ($srcname) = @_;
104 $self->{srcname} = $srcname if $srcname;
105 $self->{srcname};
108 sub html_esc {
109 my ($str) = @_;
110 $str =~ s/&/&amp;/g;
111 $str =~ s/</&lt;/g; $str =~ s/>/&gt;/g;
112 $str =~ s/"/&quot;/g;
113 $str;
116 sub print_form_fields {
117 my $self = shift;
118 my ($fieldmap, $valuemap, @fields) = @_;
120 foreach my $field (map { $fieldmap->{$_} } @fields) {
121 print '<tr><td class="formlabel">'.$field->[0].':</td><td>';
122 if ($field->[2] eq 'text') {
123 print '<input type="text" name="'.$field->[1].'" size="80"';
124 print ' value="'.$valuemap->{$field->[1]}.'"' if $valuemap;
125 print ' />';
126 } else {
127 print '<textarea name="'.$field->[1].'" rows="5" cols="80">';
128 print $valuemap->{$field->[1]} if $valuemap;
129 print '</textarea>';
131 print "</td></tr>\n";