OSDN Git Service

change htmlserver to work on grouped title
authorgn64_jp <gn64@rec10.org>
Mon, 22 Apr 2013 12:33:54 +0000 (21:33 +0900)
committergn64_jp <gn64@rec10.org>
Mon, 22 Apr 2013 12:33:54 +0000 (21:33 +0900)
htmlserver.pl
pdfsearch.pl

index 95730bf..1a2de1c 100755 (executable)
@@ -8,6 +8,7 @@ use DBI;
 use DBD::SQLite;
 use Data::Dumper;
 use YAML::XS;
+use URI::Escape;
 
 #use KCatch;
 
@@ -38,80 +39,56 @@ else {
 }
 $confdata = YAML::XS::LoadFile($confpath);
 
-$mode    = "";
-$mode    = decode( 'utf-8', $cgi->param('mode') );
-$pdfpath = decode( 'utf-8', $cgi->param('pdfpath') );
-$pagenum = int( $cgi->param('pagenum') );
-$bpage   = $pagenum - 1;
-$npage   = $pagenum + 1;
+$mode        = decode( 'utf-8', $cgi->param('mode') );
+$pagenum     = int( $cgi->param('pagenum') );
+$title_row   = $cgi->param('title');
+$title_row   = uri_unescape($title_row);
+$title_group = decode( 'utf-8', $title_row );
+$title_uri   = uri_escape($title_row);
 
 $height = $cgi->param("height");
 $width  = $cgi->param("width");
-$jpeglink =
-"jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$pagenum&mode=$mode&height=$height&width=$width";
-$blink =
-  "htmlserver.pl?pdfpath=$pdfpath&mode=$mode&width=$width&height=$height";
-$nlink = $blink . "&pagenum=" . $npage;
-$blink = $blink . "&pagenum=" . $bpage;
-
 $dbpath = $confdata->{dburl};
+
 $dbi =
   DBI->connect( "dbi:SQLite:dbname=$dbpath", "", "",
        { RaiseError => 1, AutoCommit => 1 } );
 $multi_maxpage = 0;
-$multi_nowpage = 0;
-$sql = "SELECT id,page,title,startpage,part FROM pdffile WHERE id='$pdfpath'";
+
+$sql =
+"SELECT id,title,part,startpage,endpage FROM pdffile WHERE title = '$title_group' ORDER BY part DESC LIMIT 1";
 $dbs = $dbi->prepare($sql);
 $dbs->execute();
-$dbh1        = $dbs->fetchrow_hashref;
-$title_group = $dbh1->{'title'};
-$part_now    = $dbh1->{'part'};
+$dbh           = $dbs->fetchrow_hashref;
+$multi_maxpage = $dbh->{'endpage'};
+
 $sql2 =
-"SELECT id,title,part,startpage,endpage FROM pdffile WHERE title = '$title_group' ORDER BY part DESC LIMIT 1";
+"SELECT id,startpage FROM pdffile WHERE title = '$title_group' AND startpage < $pagenum AND endpage > $pagenum";
 $dbs2 = $dbi->prepare($sql2);
 $dbs2->execute();
-$dbh2          = $dbs2->fetchrow_hashref;
-$multi_nowpage = $dbh1->{'startpage'} + $pagenum;
-$multi_maxpage = $dbh2->{'endpage'};
+$dbh2           = $dbs2->fetchrow_hashref;
+$single_pagenum = $pagenum - $dbh2->{'startpage'};
+$pdfpath        = $dbh2->{'id'};
+
+$bpage = $pagenum - 1;
+$blink =
+"htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$bpage";
+$npage = $pagenum + 1;
+$nlink =
+"htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$npage";
 
-if ( ( $pagenum == 1 ) && ( $part_now > 1 ) ) {
-       $part_b = $part_now - 1;
-       $sqlb =
-"SELECT id,page FROM pdffile WHERE title = '$title_group' AND part ='$part_b'";
-       $dbs3 = $dbi->prepare($sqlb);
-       $dbs3->execute();
-       $dbh3  = $dbs3->fetchrow_hashref;
-       $bpage = $dbh3->{'page'};
-       $blink =
-           "htmlserver.pl?pdfpath="
-         . $dbh3->{'id'}
-         . "&mode=$mode&width=$width&height=$height&pagenum=$bpage";
-}
-if ( $pagenum == $dbh1->{'page'} ) {
-       $part_n = $part_now + 1;
-       $sqln =
-"SELECT id,page FROM pdffile WHERE title = '$title_group' AND part ='$part_n'";
-       $dbs4 = $dbi->prepare($sqln);
-       $dbs4->execute();
-       $dbh4  = $dbs4->fetchrow_hashref;
-       $npage = 1;
-       $nlink =
-           "htmlserver.pl?pdfpath="
-         . $dbh4->{'id'}
-         . "&mode=$mode&width=$width&height=$height&pagenum=$npage";
-}
 $dbi->disconnect;
 $height = $cgi->param("height");
 $width  = $cgi->param("width");
 $jpeglink =
-"jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$pagenum&mode=$mode&height=$height&width=$width";
+"jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$single_pagenum&mode=$mode&height=$height&width=$width";
 
 print $cgi->header( -charset => 'utf-8' );
 print "<!DOCTYPE html>
 <html lang='ja'>
  <head>
   <meta charset='utf-8'>
-  <meta name='viewport' content='width=device-width, initial-scale=1'>
+  <meta name='viewport' content='width=device-width'>
   <link rel='stylesheet' href='http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css' />
   <script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
   <script src='http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js'></script>
@@ -130,6 +107,7 @@ print "<!DOCTYPE html>
                        //console.log(e.keycode);
                        if(e.keyCode == 13){
                                \$.mobile.changePage(\"pdfsearch.pl?mode=$mode&width=$width&height=$height&search_text=\\\"\" + \$('#search-text').val() + \"\\\"\",{transition:'slide'});
+                       \$.mobile.metaViewportContent = 'width-device-width,user-scalable=yes';
                        }
                });
        });
@@ -139,9 +117,16 @@ print "<!DOCTYPE html>
 print "
 <div id='page' data-role='page'>
  <div data-role='header' data-position='fixed'>
-  <h3>$multi_nowpage / $multi_maxpage</h3>
-  <a href='$blink' data-role='button' data-icon='arrow-l' data-iconpos='left' class='ui-btn-left'>前へ</a>
-  <a href='$nlink' data-role='button' data-icon='arrow-r' data-iconpos='right' class='ui-btn-right'>次へ</a>
+  <h3>$pagenum / $multi_maxpage</h3>
+  <div data-type='horizontal' data-role='controlgroup' class='ui-btn-left'>
+  <a href='$blink' data-role='button' data-icon='arrow-l' data-iconpos='left'>前へ</a>
+  <a href='pdfsearch.pl' data-role='button' data-icon='home' data-iconpos='left' >トップ</a>
+  </div>
+  <div data-type='horizontal' data-role='controlgroup' class='ui-btn-right'>
+   <a href='pdfsearch.pl' data-role='button' data-icon='forward' data-iconpos='left' >移動</a>
+   <a href='$nlink' data-role='button' data-icon='arrow-r' data-iconpos='right'>次へ</a>
+  </div>
+  
  </div>
 ";
 print "
index d82ec65..9eb7bc1 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 use utf8;
 use Encode 'decode';
+use Encode 'encode';
 use CGI;
 use CGI::Carp qw(fatalsToBrowser);
 use WebService::Solr;
@@ -10,6 +11,7 @@ use Data::Dumper;
 use YAML::XS;
 use DBD::SQLite;
 use DBI;
+use URI::Escape;
 
 #
 #   Libre10
@@ -86,9 +88,6 @@ if ( length $search_text > 0 ) {
                }
        );
 
-#my $response = $solr->search($query,{'rows' => '100','fl'=>'title,text,page,path'});
-#my $response = $solr->search($query);
-#print "texst";
        my $hits            = $response->content;
        my %hits            = %$hits;
        my $response_header = $hits{grouped}{title_group}{groups};
@@ -135,8 +134,9 @@ sub printGroupResults() {
                $showpagenum = $pagenum + $sth->fetchrow_array;
                print "page " . $showpagenum . "<br>";
                print " " . $hits_hl->{ $doc->{id} }{text}[0] . "<br>";
-               print "<a href=\"htmlserver.pl?pdfpath=$path";
-               print "&pagenum=$pagenum&mode=$mode&width=$width&height=$height\">";
+               print "<a href=\"htmlserver.pl?title="
+                 . uri_escape( encode( 'utf-8', $title ) );
+               print "&pagenum=$showpagenum&mode=$mode&width=$width&height=$height\">";
                print "該当ページを見る";
                print "</a>";
                print "</p>\n";