summaryrefslogtreecommitdiff
path: root/lib/VNDB/Util/LayoutHTML.pm
blob: c04fa7dd2e567cab3cfeff902110eb3b4ad44b93 (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

package VNDB::Util::LayoutHTML;

use strict;
use warnings;
use TUWF ':html', 'uri_escape';
use Exporter 'import';
use Encode 'decode_utf8';
use VNDB::Func;

our @EXPORT = qw|htmlHeader htmlFooter|;


sub htmlHeader { # %options->{ title, noindex, search, feeds, svg, metadata }
  my($self, %o) = @_;
  my $skin = $self->reqGet('skin') || $self->authPref('skin') || $self->{skin_default};
  $skin = $self->{skin_default} if !$self->{skins}{$skin} || !-d "$self->{root}/static/s/$skin";

  # heading
  lit '<!DOCTYPE HTML>';
  tag 'html', lang => 'en';
   head prefix => 'og: http://ogp.me/ns#';
    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->reqBaseURI().'/opensearch.xml';
    if($self->authPref('customcss')) {
      (my $css = $self->authPref('customcss')) =~ s/\n/ /g;
      style type => 'text/css', $css;
    }
    if($o{feeds}) {
      Link rel => 'alternate', type => 'application/atom+xml', href => "/feeds/announcements.atom", title => 'Site Announcements';
      Link rel => 'alternate', type => 'application/atom+xml', href => "/feeds/changes.atom",       title => 'Recent Changes';
      Link rel => 'alternate', type => 'application/atom+xml', href => "/feeds/posts.atom",         title => 'Recent Posts';
    }

    if(exists $o{metadata}) {
      # Required fields as per http://op.me/#metadata: og:title, og:type, og:image, og:url
      if(exists $o{metadata}{'og:title'}) {
        $o{metadata}{'og:site_name'} = 'The Visual Novel Database';
        $o{metadata}{'og:type'}    ||= 'object';
        $o{metadata}{'og:image'}   ||= $self->{placeholder_img};
        $o{metadata}{'og:url'}     ||= $self->reqURI();
      }

      for my $k (keys %{$o{metadata}}) {
        next if !$o{metadata}{$k} and $o{metadata}{$k} ne '0';
        $o{metadata}{$k} =~ s/\R/ /g;

        meta property => "$k", content => $o{metadata}->{$k}, undef;
      }
    }

    meta name => 'robots', content => 'noindex, follow', undef if $o{noindex};
   end;
   body;
    div id => 'bgright', ' ';
    div id => 'header';
     h1;
      a href => '/', 'the visual novel database';
     end;
    end;

    _menu($self, %o);

    div id => 'maincontent';
}


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

  div id => 'menulist';

   div class => 'menubox';
    h2;
     txt 'Menu';
    end;
    div;
     a href => '/',      'Home'; br;
     a href => '/v/all', 'Visual novels'; br;
     b class => 'grayedout', '> '; a href => '/g', 'Tags'; br;
     a href => '/r',     'Releases'; br;
     a href => '/p/all', 'Producers'; br;
     a href => '/s/all', 'Staff'; br;
     a href => '/c/all', 'Characters'; br;
     b class => 'grayedout', '> '; a href => '/i', 'Traits'; br;
     a href => '/u/all', 'Users'; br;
     a href => '/hist',  'Recent changes'; br;
     a href => '/t',     'Discussion board'; br;
     a href => '/d6',    'FAQ'; br;
     a href => '/v/rand','Random visual novel';
    end;
    form action => '/v/all', method => 'get', id => 'search';
     fieldset;
      legend 'Search';
      input type => 'text', class => 'text', id => 'sq', name => 'sq', value => $o{search}||'', placeholder => 'search';
      input type => 'submit', class => 'submit', value => 'Search';
     end;
    end;
   end 'div'; # /menubox

   div class => 'menubox';
    if($self->authInfo->{id}) {
      my $uid = sprintf '/u%d', $self->authInfo->{id};
      my $nc = $self->authInfo->{notifycount};
      h2;
       a href => $uid, ucfirst $self->authInfo->{username};
      end;
      div;
       a href => "$uid/edit", 'My Profile'; br;
       a href => "$uid/list", 'My Visual Novel List'; br;
       a href => "$uid/votes",'My Votes'; br;
       a href => "$uid/wish", 'My Wishlist'; br;
       a href => "$uid/notifies", $nc ? (class => 'notifyget') : (), 'My Notifications'.($nc?" ($nc)":''); br;
       a href => "$uid/hist", 'My Recent Changes'; br;
       a href => '/g/links?u='.$self->authInfo->{id}, 'My Tags'; br;
       br;
       if($self->authCan('edit')) {
         a href => '/v/add', 'Add Visual Novel'; br;
         a href => '/p/add', 'Add Producer'; br;
         a href => '/s/new', 'Add Staff'; br;
         a href => '/c/new', 'Add Character'; br;
       }
       br;
       a href => "$uid/logout", 'Logout';
      end;
    } else {
      h2 'User menu';
      div;
       my $ref = uri_escape $self->reqPath().$self->reqQuery();
       a href => "/u/login?ref=$ref", 'Login'; br;
       a href => '/u/newpass', 'Password reset'; br;
       a href => '/u/register', 'Register'; br;
      end;
    }
   end 'div'; # /menubox

   div class => 'menubox';
    h2 'Database Statistics';
    div;
     dl;
      dt 'Visual Novels';   dd $self->{stats}{vn};
      dt 'Releases';        dd $self->{stats}{releases};
      dt 'Producers';       dd $self->{stats}{producers};
      dt 'Characters';      dd $self->{stats}{chars};
      dt 'Staff';           dd $self->{stats}{staff};
      dt 'VN Tags';         dd $self->{stats}{tags};
      dt 'Character Traits';dd $self->{stats}{traits};
      dt 'Users';           dd $self->{stats}{users};
      dt 'Threads';         dd $self->{stats}{threads};
      dt 'Posts';           dd $self->{stats}{posts};
     end;
     clearfloat;
    end;
   end;
  end 'div'; # /menulist
}


sub htmlFooter { # %options => { pref_code => 1 }
  my($self, %o) = @_;
     div id => 'footer';

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

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

    # Abuse an empty noscript tag for the formcode to update a preference setting, if the page requires one.
    noscript id => 'pref_code', title => $self->authGetCode('/xml/prefs.xml'), ''
      if $o{pref_code} && $self->authInfo->{id};
    script type => 'text/javascript', src => $self->{url_static}.'/f/vndb.js?'.$self->{version}, '';
   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->{_TUWF}{DB}{queries}}) {
      my($sql, $params, $time) = @$_;
      lit sprintf "  [%6.2fms] %s | %s\n", $time*1000, $sql,
          join ', ',
          map "$_:".DBI::neat($params->{$_}),
          sort { $a =~ /^[0-9]+$/ && $b =~ /^[0-9]+$/ ? $a <=> $b : $a cmp $b }
          keys %$params
    }
    lit "-->\n";
  }
}


1;