OSDN Git Service

make buttons under construction disabled
[libre10/libre10.git] / htmlserver.pl
1 #!/usr/bin/perl
2 use utf8;
3 use Encode 'decode';
4 use warnings;
5 use CGI;
6 use File::Basename;
7 use DBI;
8 use DBD::SQLite;
9 use Data::Dumper;
10 use YAML::XS;
11 use URI::Escape;
12 use HTML::Template::Pro;
13
14 #use KCatch;
15
16 #   Licensed under the Apache License,
17 #
18 #   Libre10
19 #
20 #   Copyright 2013 yukikaze
21 #   Licensed under the Apache License, Version 2.0 (the "License");
22 #   you may not use this file except in compliance with the License.
23 #   You may obtain a copy of the License at
24 #
25 #       http://www.apache.org/licenses/LICENSE-2.0
26 #
27 #   Unless required by applicable law or agreed to in writing, software
28 #   distributed under the License is distributed on an "AS IS" BASIS,
29 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 #   See the License for the specific language governing permissions and
31 #   limitations under the License.
32 #
33 $cgi = new CGI;
34 my $confdata = YAML::XS::LoadFile(
35         -e 'libre10.conf' ? 'libre10.conf' : '/etc/libre10.conf' );
36
37 $mode        = decode( 'utf-8', $cgi->param('mode') );
38 $pagenum     = int( $cgi->param('pagenum') );
39 $title_row   = $cgi->param('title');
40 $title_row   = uri_unescape($title_row);
41 $title_group = decode( 'utf-8', $title_row );
42 $title_uri   = uri_escape($title_row);
43 $html_mode   = $cgi->param('htmlmode');
44
45 $height = $cgi->param("height");
46 $width  = $cgi->param("width");
47 $dbpath = $confdata->{dburl};
48
49 $dbi =
50   DBI->connect( "dbi:SQLite:dbname=$dbpath", "", "",
51         { RaiseError => 1, AutoCommit => 1 } );
52 $multi_maxpage = 0;
53
54 $sql = "SELECT id, title, part, startpage, endpage 
55         FROM pdffile 
56         WHERE title_id = '$title_group' 
57         ORDER BY part DESC LIMIT 1";
58 $dbs = $dbi->prepare($sql);
59 $dbs->execute();
60 $dbh           = $dbs->fetchrow_hashref;
61 $multi_maxpage = $dbh->{'endpage'};
62
63 $sql2 = "SELECT id ,startpage 
64         FROM pdffile 
65         WHERE title_id = '$title_group' AND startpage < $pagenum AND endpage > $pagenum";
66 $dbs2 = $dbi->prepare($sql2);
67 $dbs2->execute();
68 $dbh2           = $dbs2->fetchrow_hashref;
69 $single_pagenum = $pagenum - $dbh2->{'startpage'};
70 $pdfpath        = $dbh2->{'id'};
71 $jumplink =
72 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=";
73 $bpage = $pagenum - 1;
74 $blink =
75 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$bpage";
76 $npage = $pagenum + 1;
77 $nlink =
78 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$npage";
79 $b10page = $pagenum - 10;
80 $b10link =
81 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$b10page";
82 $n10page = $pagenum + 10;
83 $n10link =
84 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$n10page";
85 $homelink = "pdfsearch.pl?mode=$mode&width=$width&height=$height";
86 $dbi->disconnect;
87 $height = $cgi->param("height");
88 $width  = $cgi->param("width");
89 $jpeglink =
90 "jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$single_pagenum&mode=$mode&height=$height&width=$width";
91
92 if ( $mode eq 'mobile' ) {
93         $template =
94           HTML::Template::Pro->new( filename => './template/mobile_viewjpeg.tmpl' );
95         $template->param( blink    => $blink );
96         $template->param( nlink    => $nlink );
97         $template->param( jpegpath => $jpeglink );
98         $template->param( jumplink => $jumplink );
99         $template->param( nowpage  => $pagenum );
100         $template->param( maxpage  => $multi_maxpage );
101         $template->param( homelink => $homelink );
102 }
103 else {
104         $blink   = "$blink";
105         $nlink   = "$nlink";
106         $b10link = "$b10link";
107         $n10link = "$n10link";
108         $template =
109           HTML::Template::Pro->new(
110                 filename => './template/desktop_viewjpeg.tmpl' );
111         $template->param( blink    => $blink );
112         $template->param( nlink    => $nlink );
113         $template->param( b10link  => $b10link );
114         $template->param( n10link  => $n10link );
115         $template->param( jpegpath => $jpeglink );
116         $template->param( jumplink => $jumplink );
117         $template->param( nowpage  => $pagenum );
118         $template->param( maxpage  => $multi_maxpage );
119         $template->param( homelink => $homelink );
120 }
121 print $cgi->header( -charset => 'utf-8' ), $template->output;