OSDN Git Service

enable zooming in jpeg view
[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;
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 $confpath = "";
35 if ( -e "libre10.conf" ) {
36         $confpath = "libre10.conf";
37 }
38 else {
39         $confpath = "/etc/libre10.conf";
40 }
41 $confdata = YAML::XS::LoadFile($confpath);
42
43 $mode        = decode( 'utf-8', $cgi->param('mode') );
44 $pagenum     = int( $cgi->param('pagenum') );
45 $title_row   = $cgi->param('title');
46 $title_row   = uri_unescape($title_row);
47 $title_group = decode( 'utf-8', $title_row );
48 $title_uri   = uri_escape($title_row);
49 $html_mode   = $cgi->param('htmlmode');
50
51 $height = $cgi->param("height");
52 $width  = $cgi->param("width");
53 $dbpath = $confdata->{dburl};
54
55 $dbi =
56   DBI->connect( "dbi:SQLite:dbname=$dbpath", "", "",
57         { RaiseError => 1, AutoCommit => 1 } );
58 $multi_maxpage = 0;
59
60 $sql =
61 "SELECT id,title,part,startpage,endpage FROM pdffile WHERE title_id = '$title_group' ORDER BY part DESC LIMIT 1";
62 $dbs = $dbi->prepare($sql);
63 $dbs->execute();
64 $dbh           = $dbs->fetchrow_hashref;
65 $multi_maxpage = $dbh->{'endpage'};
66
67 $sql2 =
68 "SELECT id,startpage FROM pdffile WHERE title_id = '$title_group' AND startpage < $pagenum AND endpage > $pagenum";
69 $dbs2 = $dbi->prepare($sql2);
70 $dbs2->execute();
71 $dbh2           = $dbs2->fetchrow_hashref;
72 $single_pagenum = $pagenum - $dbh2->{'startpage'};
73 $pdfpath        = $dbh2->{'id'};
74 $jumplink =
75 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=";
76 $bpage = $pagenum - 1;
77 $blink =
78 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$bpage";
79 $npage = $pagenum + 1;
80 $nlink =
81 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$npage";
82
83 $dbi->disconnect;
84 $height = $cgi->param("height");
85 $width  = $cgi->param("width");
86 $jpeglink =
87 "jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$single_pagenum&mode=$mode&height=$height&width=$width";
88 if ( $html_mode eq '' ) {
89         $template =
90           HTML::Template->new( filename => './template/mobile_viewjpeg.tmpl' );
91         $template->param( blink    => $blink );
92         $template->param( nlink    => $nlink );
93         $template->param( jpegpath => $jpeglink );
94         $template->param( jumplink => $jumplink );
95         $template->param( nowpage  => $pagenum );
96         $template->param( maxpage  => $multi_maxpage );
97         print $cgi->header( -charset => 'utf-8' ), $template->output;
98 }