summaryrefslogtreecommitdiff
path: root/lib/VNDB/Util/LayoutHTML.pm
blob: 7b908ee1f968ad57559b0219936b5656365f5def (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

package VNDB::Util::LayoutHTML;

use strict;
use warnings;
use YAWF ':html';
use Exporter 'import';
use VNDB::Func;

our @EXPORT = qw|htmlHeader htmlFooter|;


sub htmlHeader { # %options->{ title, js, noindex, search }
  my($self, %o) = @_;
  my $skin = $self->reqParam('skin') || $self->authInfo->{skin} || $self->{skin_default};
  $skin = $self->{skin_default} if !$self->{skins}{$skin} || !-d "$VNDB::ROOT/static/s/$skin";

  # heading
  html;
   head;
    title $o{title};
    Link rel => 'shortcut icon', href => '/favicon.ico', type => 'image/x-icon';
    Link rel => 'stylesheet', href => $self->{url_static}.'/s/'.$skin.'/style.css?'.$self->{version}, type => 'text/css', media => 'all';
    Link rel => 'search', type => 'application/opensearchdescription+xml', title => 'VNDB VN Search', href => $self->{url}.'/opensearch.xml';
    if($o{js}) {
      script type => 'text/javascript', src => $self->{url_static}.'/f/forms.js?'.$self->{version}; end;
    }
    script type => 'text/javascript', src => $self->{url_static}.'/f/script.js?'.$self->{version};
     # most browsers don't like a self-closing <script> tag...
    end;
    if($self->authInfo->{customcss}) {
      (my $css = $self->authInfo->{customcss}) =~ s/\n/ /g;
      style type => 'text/css', $css;
    }
    meta name => 'robots', content => 'noindex, follow', undef if $o{noindex};
   end;
   body;
    div id => 'bgright', ' ';
    div id => 'header';
     h1;
      a href => '/', lc mt 'The Visual Novel Database';
     end;
    end;

    _menu($self, %o);

    div id => 'maincontent';
}


sub _menu {
  my($self, %o) = @_;

  div id => 'menulist';

   div class => 'menubox';
    h2;
     span;
      for (grep $self->{l10n}->language_tag() ne $_, $self->{l10n}->languages()) {
        a href => "?l10n=$_";
         cssicon "lang $_", $self->{languages}{$_};
        end;
      }
     end;
     txt mt 'Menu';
    end;
    div;
     a href => '/',      mt 'Home'; br;
     a href => '/v/all', mt 'Visual novels'; br;
     a href => '/r',     mt 'Releases'; br;
     a href => '/p/all', mt 'Producers'; br;
     a href => '/g',     mt 'Tags'; br;
     a href => '/u/all', mt 'Users'; br;
     a href => '/hist',  mt 'Recent changes'; br;
     a href => '/t',     mt 'Discussion board'; br;
     a href => '/d6',    mt 'FAQ'; br;
     a href => 'irc://irc.synirc.net/vndb', '#vndb';
      lit ' (<a href="http://cgiirc.synirc.net/?chan=%23vndb">'.mt('webchat').'</a>)';
    end;
    form action => '/v/all', method => 'get', id => 'search';
     fieldset;
      legend 'Search';
      input type => 'text', class => 'text', id => 'sq', name => 'sq', value => $o{search}||'search';
      input type => 'submit', class => 'submit', value => 'Search';
     end;
    end;
   end;

   div class => 'menubox';
    if($self->authInfo->{id}) {
      my $uid = sprintf '/u%d', $self->authInfo->{id};
      h2;
       a href => $uid, ucfirst $self->authInfo->{username};
       txt ' ('.$self->{user_ranks}[$self->authInfo->{rank}][0].')';
      end;
      div;
       a href => "$uid/edit", 'My Profile'; br;
       a href => "$uid/list", 'My Visual Novel List'; br;
       a href => "$uid/wish", 'My Wishlist'; br;
       a href => "/t$uid",    sprintf 'My Messages (%d)', $self->authInfo->{mymessages}; br;
       a href => "$uid/hist", 'My Recent Changes'; br;
       a href => "$uid/tags", 'My Tags'; br;
       br;
       a href => '/v/new',    'Add Visual Novel'; br;
       a href => '/p/new',    'Add Producer'; br;
       br;
       a href => '/u/logout', 'Logout';
      end;
    } else {
      h2;
       a href => '/u/login', 'Login';
      end;
      div;
       form action => '/nospam?/u/login', id => 'loginform', method => 'post';
        fieldset;
         legend 'Login';
         input type => 'text', class => 'text', id => 'username', name => 'usrname';
         input type => 'password', class => 'text', id => 'userpass', name => 'usrpass';
         input type => 'submit', class => 'submit', value => 'Login';
        end;
       end;
       p;
        lit 'Need to <a href="/u/register">register</a>,<br />';
        lit 'or <a href="/u/newpass">forgot your password?</a>';
       end;
      end;
    }
   end;

   my @stats = (
     [ vn        => 'Visual Novels' ],
     [ releases  => 'Releases'      ],
     [ producers => 'Producers'     ],
     [ users     => 'Users'         ],
     [ threads   => 'Threads'       ],
     [ posts     => 'Posts'         ],
   );
   div class => 'menubox';
    h2 'Database Statistics';
    div;
     dl;
      for (@stats) {
        dt $$_[1];
        dd $self->{stats}{$$_[0]};
      }
     end;
     clearfloat;
    end;
   end;
  end;
}


sub htmlFooter {
  my $self = shift;
     div id => 'footer';

      my $q = $self->dbRandomQuote;
      if($q && $q->{vid}) {
        lit '"';
        a href => "/v$q->{vid}", style => 'text-decoration: none', $q->{quote};
        txt qq|"\n|;
      }

      txt "vndb $self->{version} | ";
      a href => '/d7', 'about us';
      txt ' | ';
      a href => "mailto:$self->{admin_email}", $self->{admin_email};
      txt ' | ';
      a href => $self->{source_url}, 'source';
     end;
    end; # /div maincontent
   end; # /body
  end; # /html

  # write the SQL queries as a HTML comment when debugging is enabled
  if($self->debug) {
    lit "\n<!--\n SQL Queries:\n";
    for (@{$self->{_YAWF}{DB}{queries}}) {
      my $q = !ref $_->[0] ? $_->[0] :
        $_->[0][0].(exists $_->[0][1] ? ' | "'.join('", "', map defined()?$_:'NULL', @{$_->[0]}[1..$#{$_->[0]}]).'"' : '');
      $q =~ s/^\s//g;
      lit sprintf "  [%6.2fms] %s\n", $_->[1]*1000, $q;
    }
    lit "-->\n";
  }
}


1;