12 use HTML::Template::Pro;
16 # Licensed under the Apache License,
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
25 # http://www.apache.org/licenses/LICENSE-2.0
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.
34 my $confdata = YAML::XS::LoadFile(
35 -e 'libre10.conf' ? 'libre10.conf' : '/etc/libre10.conf' );
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');
45 $height = $cgi->param("height");
46 $width = $cgi->param("width");
47 $dbpath = $confdata->{dburl};
50 DBI->connect( "dbi:SQLite:dbname=$dbpath", "", "",
51 { RaiseError => 1, AutoCommit => 1 } );
54 $sql = "SELECT id, title, part, startpage, endpage
56 WHERE title_id = '$title_group'
57 ORDER BY part DESC LIMIT 1";
58 $dbs = $dbi->prepare($sql);
60 $dbh = $dbs->fetchrow_hashref;
61 $multi_maxpage = $dbh->{'endpage'};
63 $sql2 = "SELECT id ,startpage
65 WHERE title_id = '$title_group' AND startpage < $pagenum AND endpage > $pagenum";
66 $dbs2 = $dbi->prepare($sql2);
68 $dbh2 = $dbs2->fetchrow_hashref;
69 $single_pagenum = $pagenum - $dbh2->{'startpage'};
70 $pdfpath = $dbh2->{'id'};
72 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=";
73 $bpage = $pagenum - 1;
75 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$bpage";
76 $npage = $pagenum + 1;
78 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$npage";
79 $b10page = $pagenum - 10;
81 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$b10page";
82 $n10page = $pagenum + 10;
84 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$n10page";
85 $homelink = "pdfsearch.pl?mode=$mode&width=$width&height=$height";
87 $height = $cgi->param("height");
88 $width = $cgi->param("width");
90 "jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$single_pagenum&mode=$mode&height=$height&width=$width";
92 if ( $mode eq 'mobile' ) {
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 );
106 $b10link = "$b10link";
107 $n10link = "$n10link";
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 );
121 print $cgi->header( -charset => 'utf-8' ), $template->output;