diff options
author | Yorhel <git@yorhel.nl> | 2011-02-04 11:46:00 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2011-02-04 11:46:00 +0100 |
commit | 7a5283dc5cb35aca7cefe3348d8697e29aedda15 (patch) | |
tree | 207a89f89c128ce61082a3a019b391b4cb8374c7 /lib/VNDB/Util | |
parent | 422451344f20a69b43b6fc4c51f89a5174ef8760 (diff) | |
parent | 876119b300473a5232b5fcc60eb403afe36e6163 (diff) |
Merge branch 'beta'2.17
Conflicts:
ChangeLog
Diffstat (limited to 'lib/VNDB/Util')
-rw-r--r-- | lib/VNDB/Util/Auth.pm | 24 | ||||
-rw-r--r-- | lib/VNDB/Util/BrowseHTML.pm | 14 | ||||
-rw-r--r-- | lib/VNDB/Util/CommonHTML.pm | 46 | ||||
-rw-r--r-- | lib/VNDB/Util/FormHTML.pm | 32 | ||||
-rw-r--r-- | lib/VNDB/Util/LayoutHTML.pm | 29 | ||||
-rw-r--r-- | lib/VNDB/Util/Misc.pm | 55 |
6 files changed, 112 insertions, 88 deletions
diff --git a/lib/VNDB/Util/Auth.pm b/lib/VNDB/Util/Auth.pm index 9ad76894..88e68edc 100644 --- a/lib/VNDB/Util/Auth.pm +++ b/lib/VNDB/Util/Auth.pm @@ -10,7 +10,7 @@ use Digest::SHA qw|sha1_hex sha256_hex|; use Time::HiRes; use Encode 'encode_utf8'; use POSIX 'strftime'; -use YAWF ':html'; +use TUWF ':html'; use VNDB::Func; @@ -22,15 +22,15 @@ sub authInit { my $self = shift; $self->{_auth} = undef; - my $cookie = $self->reqCookie($self->{cookie_prefix}.'auth'); + my $cookie = $self->reqCookie('auth'); return 0 if !$cookie; - return _rmcookie($self) if length($cookie) < 41; + return $self->resCookie(auth => undef) if length($cookie) < 41; my $token = substr($cookie, 0, 40); my $uid = substr($cookie, 40); $self->{_auth} = $uid =~ /^\d+$/ && $self->dbUserGet(uid => $uid, session => $token, what => 'extended notifycount prefs')->[0]; # update the sessions.lastused column if lastused < now()'6 hours' $self->dbSessionUpdateLastUsed($uid, $token) if $self->{_auth} && $self->{_auth}{session_lastused} < time()-6*3600; - return _rmcookie($self) if !$self->{_auth}; + return $self->resCookie(auth => undef) if !$self->{_auth}; } @@ -47,9 +47,8 @@ sub authLogin { my $cookie = $token . $self->{_auth}{id}; $self->dbSessionAdd($self->{_auth}{id}, $token); - my $expstr = strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime(time + 31536000)); # keep the cookie for 1 year $self->resRedirect($to, 'post'); - $self->resHeader('Set-Cookie', "$self->{cookie_prefix}auth=$cookie; expires=$expstr; path=/; domain=$self->{cookie_domain}"); + $self->resCookie(auth => $cookie, expires => time + 31536000); # keep the cookie for 1 year return 1; } @@ -61,7 +60,7 @@ sub authLogin { sub authLogout { my $self = shift; - my $cookie = $self->reqCookie($self->{cookie_prefix}.'auth'); + my $cookie = $self->reqCookie('auth'); if ($cookie && length($cookie) >= 41) { my $token = substr($cookie, 0, 40); my $uid = substr($cookie, 40); @@ -69,11 +68,11 @@ sub authLogout { } $self->resRedirect('/', 'temp'); - _rmcookie($self); + $self->resCookie(auth => undef); # set l10n cookie if the user has a preferred language set my $l10n = $self->authPref('l10n'); - $self->resHeader('Set-Cookie', "l10n=$l10n; expires=Sat, 01-Jan-2030 00:00:00 GMT; path=/; domain=$self->{cookie_domain}") if $l10n; + $self->resCookie(l10n => $l10n, expires => time()+31536000) if $l10n; # keep 1 year } @@ -141,13 +140,6 @@ sub authPreparePass{ } -# removes the vndb_auth cookie -sub _rmcookie { - $_[0]->resHeader('Set-Cookie', - "$_[0]->{cookie_prefix}auth= ; expires=Sat, 01-Jan-2000 00:00:00 GMT; path=/; domain=$_[0]->{cookie_domain}"); -} - - # Generate a code to be used later on to validate that the form was indeed # submitted from our site and by the same user/visitor. Not limited to # logged-in users. diff --git a/lib/VNDB/Util/BrowseHTML.pm b/lib/VNDB/Util/BrowseHTML.pm index 62e01fd1..6d6cdeda 100644 --- a/lib/VNDB/Util/BrowseHTML.pm +++ b/lib/VNDB/Util/BrowseHTML.pm @@ -3,7 +3,7 @@ package VNDB::Util::BrowseHTML; use strict; use warnings; -use YAWF ':html', 'xml_escape'; +use TUWF ':html', 'xml_escape'; use Exporter 'import'; use VNDB::Func; use POSIX 'ceil'; @@ -62,7 +62,7 @@ sub htmlBrowse { } } end; - end; + end 'thead'; # footer if($opt{footer}) { @@ -75,8 +75,8 @@ sub htmlBrowse { $opt{row}->($self, $_+1, $opt{items}[$_]) for 0..$#{$opt{items}}; - end; - end; + end 'table'; + end 'div'; # bottom navigation $self->htmlBrowseNavigate($opt{pageurl}, $opt{options}{p}, $opt{nextpage}, 'b'); @@ -117,7 +117,7 @@ sub htmlBrowseNavigate { $l > $nc+1 and $ell->(0); $l > $_ and $tab->(0, $p+$_, $p+$_) for (reverse 2..($nc>$l-2?$l-2:$nc-1)); $l > 1 and $tab->(0, $p+1, mt('_browse_next').' ›'); - end; + end 'ul'; } @@ -154,7 +154,7 @@ sub htmlBrowseHist { a href => $revurl, title => $i->{ioriginal}, shorten $i->{ititle}, 80; b class => 'grayedout'; lit bb2html $i->{comments}, 150; end; end; - end; + end 'tr'; }, ); } @@ -205,7 +205,7 @@ sub htmlBrowseVN { txt sprintf '%.2f', $l->{c_rating}||0; b class => 'grayedout', sprintf ' (%d)', $l->{c_votecount}; end; - end; + end 'tr'; }, ); } diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm index a412949a..1872c083 100644 --- a/lib/VNDB/Util/CommonHTML.pm +++ b/lib/VNDB/Util/CommonHTML.pm @@ -3,7 +3,7 @@ package VNDB::Util::CommonHTML; use strict; use warnings; -use YAWF ':html', 'xml_escape'; +use TUWF ':html', 'xml_escape', 'html_escape'; use Exporter 'import'; use Algorithm::Diff::Fast 'compact_diff'; use VNDB::Func; @@ -95,7 +95,7 @@ sub htmlMainTabs { li !$sel ? (class => 'tabselected') : (); a href => "/$id", $id; end; - end; + end 'ul'; } @@ -114,7 +114,7 @@ sub htmlDenied { p mt '_denied_noaccess_msg'; } end; - end; + end 'div'; $self->htmlFooter; } @@ -140,7 +140,7 @@ sub htmlHiddenMessage { lit bb2html $editsum; end; end; - end; + end 'div'; return $self->htmlFooter() || 1 if !$self->authCan('del'); return 0; } @@ -205,9 +205,9 @@ sub htmlRevision { [ ilock => serialize => sub { mt $_[0] ? '_revision_yes' : '_revision_no' } ], @fields ); - end; + end 'table'; } - end; + end 'div'; } sub revheader { # type, obj @@ -233,8 +233,8 @@ sub revdiff { if($o{diff} && $ser1 && $ser2) { my $sep = ref $o{diff} ? qr/($o{diff})/ : qr//; - my @ser1 = $o{split} ? $o{split}->($ser1) : map xml_escape($_), split $sep, $ser1; - my @ser2 = $o{split} ? $o{split}->($ser2) : map xml_escape($_), split $sep, $ser2; + my @ser1 = $o{split} ? $o{split}->($ser1) : map html_escape($_), split $sep, $ser1; + my @ser2 = $o{split} ? $o{split}->($ser2) : map html_escape($_), split $sep, $ser2; return if $o{split} && $#ser1 == $#ser2 && !grep $ser1[$_] ne $ser2[$_], 0..$#ser1; $ser1 = $ser2 = ''; @@ -247,8 +247,8 @@ sub revdiff { $ser2 .= ($ser2?$o{join}:'').($i % 2 ? qq|<b class="diff_add">$b</b>| : $b) if $b ne ''; } } elsif(!$o{htmlize}) { - $ser1 = xml_escape $ser1; - $ser2 = xml_escape $ser2; + $ser1 = html_escape $ser1; + $ser2 = html_escape $ser2; } $ser1 = mt '_revision_empty' if !$ser1 && $ser1 ne '0'; @@ -297,7 +297,7 @@ sub htmlEditMessage { p mt '_editmsg_revert_msg', $num; end; } - end; + end 'div'; } @@ -347,7 +347,7 @@ sub htmlVoteStats { end; end; } - end; + end 'table'; my $recent = $self->dbVoteGet( $type.'id' => $obj->{id}, @@ -381,7 +381,7 @@ sub htmlVoteStats { td $self->{l10n}->date($recent->[$_]{date}); end; } - end; + end 'table'; } clearfloat; @@ -392,7 +392,7 @@ sub htmlVoteStats { p mt '_votestats_rank_rat', $obj->{r_ranking}, sprintf '%.2f', $obj->{c_rating}; end; } - end; + end 'div'; } @@ -409,7 +409,7 @@ sub htmlSearchBox { end; input type => 'text', name => 'q', id => 'q', class => 'text', value => $v; input type => 'submit', class => 'submit', value => mt '_searchbox_submit'; - end; + end 'fieldset'; } @@ -430,21 +430,7 @@ sub htmlRGHeader { return 1; } $self->resHeader('Content-Type' => 'application/xhtml+xml; charset=UTF-8'); - - # This is a REALLY ugly hack, need find a proper solution in YAWF - no warnings 'redefine'; - my $sub = \&YAWF::XML::html; - *YAWF::XML::html = sub () { - lit q|<!DOCTYPE html PUBLIC - "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" - "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">|; - tag 'html', - xmlns => "http://www.w3.org/1999/xhtml", - 'xmlns:svg' => 'http://www.w3.org/2000/svg', - 'xmlns:xlink' => 'http://www.w3.org/1999/xlink'; - }; - $self->htmlHeader(title => $title); - *YAWF::XML::html = $sub; + $self->htmlHeader(title => $title, svg => 1); $self->htmlMainTabs($type, $obj, 'rg'); return 0; } diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm index 41ee0ccc..68b6a101 100644 --- a/lib/VNDB/Util/FormHTML.pm +++ b/lib/VNDB/Util/FormHTML.pm @@ -3,7 +3,7 @@ package VNDB::Util::FormHTML; use strict; use warnings; -use YAWF ':html'; +use TUWF ':html'; use Exporter 'import'; use POSIX 'strftime'; use VNDB::Func; @@ -41,7 +41,7 @@ sub htmlFormError { li mt "_formerr_tpl_$rule", $field if $type eq 'template'; } end; - end; + end 'div'; end if $mainbox; } @@ -152,15 +152,10 @@ sub htmlFormPart { input type => 'hidden', id => $o{short}, name => $o{short}, value => $frm->{$o{short}}||'', class => 'dateinput'; } if(/text/) { - (my $txt = $frm->{$o{short}}||'') =~ s/&/&/; - $txt =~ s/</</; - $txt =~ s/>/>/; - textarea name => $o{short}, id => $o{short}, rows => $o{rows}||5, cols => $o{cols}||60; - lit $txt; - end; + textarea name => $o{short}, id => $o{short}, rows => $o{rows}||5, cols => $o{cols}||60, $frm->{$o{short}}||''; } end; - end; + end 'tr'; } @@ -195,7 +190,7 @@ sub htmlForm { li class => 'left'; a href => '#all', id => 'jt_sel_all', mt '_form_tab_all'; end; - end; + end 'ul'; } # form subs @@ -210,7 +205,7 @@ sub htmlForm { $self->htmlFormPart($options->{frm}, $_) for @$parts; end; end; - end; + end 'div'; } # db mod / edit summary / submit button @@ -227,27 +222,24 @@ sub htmlForm { input type => 'checkbox', name => 'ilock', id => 'ilock', value => 1, $options->{frm}{ilock} ? (checked => 'checked') : (); label for => 'ilock', mt '_form_ilock'; } - txt "\n".mt('_form_hidlock_note')."\n" if $self->authCan('lock') || $self->authCan('del'); + if($self->authCan('lock') || $self->authCan('del')) { + br; txt mt('_form_hidlock_note'); br; + } # edit summary - (my $txt = $options->{frm}{editsum}||'') =~ s/&/&/; - $txt =~ s/</</; - $txt =~ s/>/>/; h2; txt mt '_form_editsum'; b class => 'standout', ' ('.mt('_inenglish').')'; end; - textarea name => 'editsum', id => 'editsum', rows => 4, cols => 50; - lit $txt; - end; + textarea name => 'editsum', id => 'editsum', rows => 4, cols => 50, $options->{frm}{editsum}||''; br; } input type => 'submit', value => mt('_form_submit'), class => 'submit'; end; - end; + end 'div'; } - end; + end 'form'; } diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm index cc34b874..7c03b6a3 100644 --- a/lib/VNDB/Util/LayoutHTML.pm +++ b/lib/VNDB/Util/LayoutHTML.pm @@ -3,20 +3,24 @@ package VNDB::Util::LayoutHTML; use strict; use warnings; -use YAWF ':html'; +use TUWF ':html'; use Exporter 'import'; use VNDB::Func; our @EXPORT = qw|htmlHeader htmlFooter|; -sub htmlHeader { # %options->{ title, noindex, search, feeds } +sub htmlHeader { # %options->{ title, noindex, search, feeds, svg } my($self, %o) = @_; - my $skin = $self->reqParam('skin') || $self->authPref('skin') || $self->{skin_default}; + my $skin = $self->reqGet('skin') || $self->authPref('skin') || $self->{skin_default}; $skin = $self->{skin_default} if !$self->{skins}{$skin} || !-d "$VNDB::ROOT/static/s/$skin"; # heading - html; + html lang => $self->{l10n}->language_tag(), $o{svg} ? ( + doctype => 'xhtml-math-svg', + 'xmlns:svg' => 'http://www.w3.org/2000/svg', + 'xmlns:xlink' => 'http://www.w3.org/1999/xlink' + ) : (); head; title $o{title}; Link rel => 'shortcut icon', href => '/favicon.ico', type => 'image/x-icon'; @@ -75,7 +79,7 @@ sub _menu { input type => 'submit', class => 'submit', value => 'Search'; end; end; - end; + end 'div'; # /menubox div class => 'menubox'; if($self->authInfo->{id}) { @@ -117,7 +121,7 @@ sub _menu { end; end; } - end; + end 'div'; # /menubox div class => 'menubox'; h2 mt '_menu_dbstats'; @@ -131,7 +135,7 @@ sub _menu { clearfloat; end; end; - end; + end 'div'; # /menulist } @@ -143,7 +147,8 @@ sub htmlFooter { # %options => { prefs => [pref1,..] } if($q && $q->{vid}) { lit '"'; a href => "/v$q->{vid}", style => 'text-decoration: none', $q->{quote}; - txt qq|"\n|; + txt '"'; + br; } txt "vndb $self->{version} | "; @@ -155,7 +160,7 @@ sub htmlFooter { # %options => { prefs => [pref1,..] } txt ' | '; a href => $self->{source_url}, mt '_footer_source'; end; - end; # /div maincontent + end 'div'; # /maincontent # insert users' preference data when required by JS if($o{prefs}) { @@ -168,13 +173,13 @@ sub htmlFooter { # %options => { prefs => [pref1,..] } end; } script type => 'text/javascript', src => $self->{url_static}.'/f/js/'.$self->{l10n}->language_tag().'.js?'.$self->{version}, ''; - end; # /body - end; # /html + 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}}) { + for (@{$self->{_TUWF}{DB}{queries}}) { my $q = !ref $_->[0] ? $_->[0] : $_->[0][0].(exists $_->[0][1] ? ' | "'.join('", "', map defined()?$_:'NULL', @{$_->[0]}[1..$#{$_->[0]}]).'"' : ''); $q =~ s/^\s//g; diff --git a/lib/VNDB/Util/Misc.pm b/lib/VNDB/Util/Misc.pm index 71aca7a8..9f281ee7 100644 --- a/lib/VNDB/Util/Misc.pm +++ b/lib/VNDB/Util/Misc.pm @@ -4,14 +4,15 @@ package VNDB::Util::Misc; use strict; use warnings; use Exporter 'import'; +use TUWF ':html'; use VNDB::Func; -our @EXPORT = qw|filFetchDB|; +our @EXPORT = qw|filFetchDB ieCheck|; my %filfields = ( vn => [qw|length hasani tag_inc tag_exc taginc tagexc tagspoil lang olang plat|], - release => [qw|type patch freeware doujin date_before date_after minage lang olang resolution plat med voiced ani_story ani_ero|], + release => [qw|type patch freeware doujin date_before date_after released minage lang olang resolution plat med voiced ani_story ani_ero|], ); @@ -57,7 +58,7 @@ sub filFetchDB { # throwing 500's even for non-browse pages. We have to do some low-level # PostgreSQL stuff with savepoints to ensure that an error won't affect our # existing transaction. - my $dbh = $self->{_YAWF}{DB}{sql}; + my $dbh = $self->dbh; $dbh->pg_savepoint('filter'); my($r, $np); my $OK = eval { @@ -98,3 +99,51 @@ sub _fil_vn_compat { return 0; } + +sub ieCheck { + my $self = shift; + + return 1 if !$self->reqHeader('User-Agent') || + $self->reqHeader('User-Agent') !~ /MSIE [67]/ || $self->reqCookie('ie_sucks'); + + if($self->reqGet('i-still-want-access')) { + (my $ref = $self->reqHeader('Referer') || '/') =~ s/^\Q$self->{url}//; + $self->resRedirect($ref, 'temp'); + $self->resCookie('ie_sucks' => 1); + return; + } + + html; + head; + title 'Your browser sucks'; + style type => 'text/css', + q|body { background: black }| + .q|div { position: absolute; left: 50%; top: 50%; width: 500px; margin-left: -250px; height: 180px; margin-top: -90px; background-color: #012; border: 1px solid #258; text-align: center; }| + .q|p { color: #ddd; margin: 10px; font: 9pt "Tahoma"; }| + .q|h1 { color: #258; font-size: 14pt; font-family: "Futura", "Century New Gothic", "Arial", Serif; font-weight: normal; margin: 10px 0 0 0; } | + .q|a { color: #fff }|; + end 'head'; + body; + div; + h1 'Oops, we were too lazy to support your browser!'; + p; + lit qq|We decided to stop supporting Internet Explorer 6 and 7, as it's a royal pain in | + .qq|the ass to make our site look good in a browser that doesn't want to cooperate with us.<br />| + .qq|You can try one of the following free alternatives: | + .qq|<a href="http://www.mozilla.com/firefox/">Firefox</a>, | + .qq|<a href="http://www.opera.com/">Opera</a>, | + .qq|<a href="http://www.apple.com/safari/">Safari</a>, or | + .qq|<a href="http://www.google.com/chrome">Chrome</a>.<br /><br />| + .qq|If you're really stubborn about using Internet Explorer, upgrading to version 8 will also work.<br /><br />| + .qq|...and if you're mad, you can also choose to ignore this warning and | + .qq|<a href="/?i-still-want-access=1">open the site anyway</a>.|; + end; + end; + end 'body'; + end 'html'; + return 0; +} + + +1; + |