{ RaiseError => 1, AutoCommit => 1 } );
$multi_maxpage = 0;
-$sql = "SELECT id, title, part, startpage, endpage
+$sql = "SELECT id, title, part, startpage, endpage, showpagediff
FROM pdffile
WHERE title_id = '$title_group'
ORDER BY part DESC LIMIT 1";
$dbh = $dbs->fetchrow_hashref;
$multi_maxpage = $dbh->{'endpage'};
+$showpagediff = $dbh->{'shopagediff'};
+
$sql2 = "SELECT id ,startpage
FROM pdffile
WHERE title_id = '$title_group' AND startpage < $pagenum AND endpage > $pagenum";
$pdfpath = $dbh2->{'id'};
$jumplink =
"htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=";
-$searchlink =
-"pdfsearch.pl?mode=$mode&width=$width&height=$height&search_text=";
+$searchlink =
+ "pdfsearch.pl?mode=$mode&width=$width&height=$height&search_text=";
$bpage = $pagenum - 1;
$blink =
"htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$bpage";
$dbi->disconnect;
$height = $cgi->param("height");
$width = $cgi->param("width");
-$jpeglink =
-"jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$single_pagenum&mode=$mode&height=$height&width=$width";
if ( $mode eq 'mobile' ) {
$template =
- HTML::Template::Pro->new( filename => './template/mobile_viewjpeg.tmp.html' );
- $template->param( blink => $blink );
- $template->param( nlink => $nlink );
- $template->param( jpegpath => $jpeglink );
- $template->param( jumplink => $jumplink );
+ HTML::Template::Pro->new(
+ filename => './template/mobile_viewjpeg.tmp.html' );
+ $jpeglink =
+"jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$single_pagenum&mode=$mode&height=$height&width=$width";
+ $template->param( blink => $blink );
+ $template->param( nlink => $nlink );
+ $template->param( jpegpath => $jpeglink );
+ $template->param( jumplink => $jumplink );
$template->param( searchlink => $searchlink );
- $template->param( nowpage => $pagenum );
- $template->param( maxpage => $multi_maxpage );
- $template->param( homelink => $homelink );
+ $template->param( nowpage => $pagenum );
+ $template->param( maxpage => $multi_maxpage );
+ $template->param( homelink => $homelink );
#$template->param( title_id => $title_group );
}
else {
+ $bpage = $pagenum - 2;
+ $blink =
+"htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$bpage";
+ $npage = $pagenum + 2;
+ $nlink =
+"htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$npage";
$blink = "$blink";
$nlink = "$nlink";
$b10link = "$b10link";
$n10link = "$n10link";
+ $width=$width/2;
+ $jpeglink =
+"jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$single_pagenum&mode=$mode&height=$height&width=$width";
+ $single_pagenum2=$single_pagenum+1;
+ $jpeglink2 =
+"jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$single_pagenum2&mode=$mode&height=$height&width=$width";
$template =
HTML::Template::Pro->new(
filename => './template/desktop_viewjpeg.tmp.html' );
- $template->param( blink => $blink );
- $template->param( nlink => $nlink );
- $template->param( b10link => $b10link );
- $template->param( n10link => $n10link );
- $template->param( jpegpath => $jpeglink );
- $template->param( jumplink => $jumplink );
+ $template->param( blink => $blink );
+ $template->param( nlink => $nlink );
+ $template->param( b10link => $b10link );
+ $template->param( n10link => $n10link );
+ $template->param( jpegpath => $jpeglink );
+ $template->param( jpegpath2 => $jpeglink2 );
+ $template->param( jumplink => $jumplink );
$template->param( searchlink => $searchlink );
- $template->param( nowpage => $pagenum );
- $template->param( maxpage => $multi_maxpage );
- $template->param( homelink => $homelink );
- $template->param( title_id => $title_group );
+ $template->param( nowpage => $pagenum );
+ $template->param( maxpage => $multi_maxpage );
+ $template->param( homelink => $homelink );
+ $template->param( title_id => $title_group );
+ $template->param( nowspd => $showpagediff );
}
print $cgi->header( -charset => 'utf-8' ), $template->output;
title varchar(40),
title_id varchar(40),
part integer,
- genre varchar(100),
+ genre varchar(200),
startpage integer,
endpage integer,
showpagediff integer,
- indexpage integer
+ indexpage integer,
+ changed integer
);"""
dbcon.execute(sql)
except:
time.sleep(1)
TEXT2solr(s,os.path.splitext(os.path.basename(pdfpath))[0],"page-"+str(i)+dstpath,i,pagenum,pdfpath,idnum)
os.system("rm -f page-"+str(i)+dstpath)
- sql = u"insert into pdffile (id,path,page,title,title_id,part)values (?,?,?,?,?,?)"
+ sql = u"insert into pdffile (id,path,page,title,title_id,part) values (?,?,?,?,?,?)"
dbcon.execute(sql,(idnum,pdfpath,pagenum,title_group,rdl,parttext))
s.commit()
def TEXT2solr(solrcon,titletxt,textpath,pagenum,pagemax,pdfpath,idnum):
title_g_id=hashlib.sha224(title_g.encode("utf-8")).hexdigest()
print titletxt+" : "+str(pagenum)+"/"+str(pagemax)
path_id=idnum
+ sql=u"SELECT genre FROM pdffile WHERE title = ? LIMIT 1"
+ cur = dbcon.execute(sql,(title_g,))
+ genreary=("",)
+ for row in cur:
+ if row[0] != None:
+ genreary=row[0].split(",")
+ #print genreary
solrcon.add(id=idnum+"_"+str(pagenum),title=titletxt,title_group=title_g,
title_group_id=title_g_id,page=int(pagenum),pagemax=int(pagemax),
- text=data1,path_id=path_id)
+ text=data1,path_id=path_id,genre=genreary)
argvs=sys.argv
argc=len(argvs)
for st in argvs[1:]:
rd.update(os.path.abspath(st))
rdl=rd.hexdigest()
c = dbcon.cursor()
- c.execute(u"select count(*) from pdffile where id=?",(rdl,))
- filecount = c.fetchone()[0]
+ c.execute(u"select count(*),changed from pdffile where id=?",(rdl,))
+ cfo = c.fetchone()
+ filecount = cfo[0]
+ if (cfo[1]==None):
+ changed=0
+ else:
+ changed = int(cfo[1])
+
print st
print rdl
print filecount
- if int(filecount)<1:
+ if int(filecount)<1 or changed >0:
PDF2TEXT(st.decode("utf-8"),str(rdl)+".txt",rdl)
+ c2 = dbcon.cursor()
+ c2.execute(u"UPDATE pdffile SET changed=0 where id=?",(rdl,))
+ index_rebuild()
index_rebuild()
dbcon.close()
#!/usr/bin/perl
use utf8;
-use strict;
+#use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Encode 'decode';
use File::Slurp;
use YAML::XS;
-
+use URI::Escape;
#
# Libre10
#
my $dbh = DBI->connect( "dbi:SQLite:dbname=$confdata->{dburl}",
"", "", { RaiseError => 1, AutoCommit => 1 } );
my $pdflist = $dbh->selectall_hashref(
-"SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage
+"SELECT id, path, page, title, title_id, part, genre, startpage, endpage, showpagediff, indexpage
FROM pdffile"
, 'id'
);
exit;
}
elsif ( $mode eq 'showpagediff' ) {
- my $dnum = $cgi->int( param("diff") );
- my $title = $cgi->param("title");
+ my $dnum = int($cgi->param("diff") );
+ my $title = decode('utf-8',uri_unescape($cgi->param("title")));
if ( $dnum > 0 ) {
my $sqls =
- "UPDATE pdffile SET showpagediff = $dnum WHERE title_group=$title";
+ "UPDATE pdffile SET showpagediff = $dnum WHERE title_id=\"$title\"";
+ print $sqls;
$dbs = $dbh->prepare($sqls);
$dbs->execute();
}
}
+elsif ( $mode eq 'genre') {
+ my $genre = $cgi->param("genre");
+ my $title = decode('utf-8',uri_unescape($cgi->param("title")));
+ $lgenre = length $genre;
+ if ( $lgenre > 0 ) {
+ my $sqls =
+ "UPDATE pdffile SET genre = \"$genre\" WHERE title_id=\"$title\"";
+ print $sqls;
+ $dbs = $dbh->prepare($sqls);
+ $dbs->execute();
+ }
+}
+elsif ( $mode eq 'index') {
+ my $index = int($cgi->param("index"));
+ my $title = decode('utf-8',uri_unescape($cgi->param("title")));
+ if ( $index > 0 ) {
+ my $sqls =
+ "UPDATE pdffile SET indexpage = \"$index\" WHERE title_id=\"$title\"";
+ print $sqls;
+ $dbs = $dbh->prepare($sqls);
+ $dbs->execute();
+ }
+}
else {
list_all_pdf();
}
print
qq {Partial PDF = ./pdfmanager.pl?mode=partpdf&pdfid=68fc6a6a1cdd79227d0f2fe2f03dd510&pdftk=765-765\n};
my $ary_ref = $dbh->selectall_arrayref(
-"SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage
+"SELECT id, path, page, title_id, title, part, genre, startpage, endpage, showpagediff, indexpage
FROM pdffile"
, { Slice => {} }
);
print qq {<th>id</th>\n};
print qq {<th>path</th>\n};
print qq {<th>page</th>\n};
+ print qq {<th>title_id</th>\n};
print qq {<th>title</th>\n};
print qq {<th>part</th>\n};
print qq {<th>genre</th>\n};
print qq {<th>start</th>\n};
print qq {<th>end</th>\n};
- #print qq {<th>showpagediff</th>\n};
+ print qq {<th>showpagediff</th>\n};
#print qq {<th>indexpage</th>\n};
print qq {</tr>\n};
foreach my $line ( @{$ary_ref} ) {
qq {<td><a href="./htmlserver.pl?pdfpath=$line->{id}&pagenum=1">$line->{id}</a></td>\n};
print qq {<td>$line->{path}</td>\n};
print qq {<td>$line->{page}</td>\n};
+ print qq {<td>$line->{title_id}</td>\n};
print qq {<td>$line->{title}</td>\n};
print qq {<td>$line->{part}</td>\n};
print qq {<td>$line->{genre}</td>\n};
print qq {<td>$line->{startpage}</td>\n};
print qq {<td>$line->{endpage}</td>\n};
- #print qq {<td>$line->{showpagediff}</td>\n};
+ print qq {<td>$line->{showpagediff}</td>\n};
#print qq {<td>$line->{indexpage}</td>\n};
print qq {</tr>\n};
}
+++ /dev/null
-#!/usr/bin/perl
-use utf8;
-use Encode 'decode';
-use Encode 'encode';
-use CGI;
-use CGI::Carp qw(fatalsToBrowser);
-use WebService::Solr;
-use WebService::Solr::Query;
-use warnings;
-use Data::Dumper;
-use YAML::XS;
-use DBD::SQLite;
-use DBI;
-use URI::Escape;
-use HTML::Template::Pro;
-
-#
-# Libre10
-#
-# Copyright 2013 yukikaze
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-my $confdata = YAML::XS::LoadFile(
- -e 'libre10.conf' ? 'libre10.conf' : '/etc/libre10.conf' );
-
-my $sqlpath = "/tmp/libre10.db";
-$sqlpath = $confdata->{dburl};
-$sqldbi =
- DBI->connect( "dbi:SQLite:dbname=$sqlpath", "", "",
- { RaiseError => 1, AutoCommit => 1 } );
-my $q = new CGI;
-my $mode = "";
-$mode = $q->param("mode");
-my $url = $confdata->{solrurl};
-my $solr = WebService::Solr->new($url);
-
-print $q->header( -type => "text/html", -charset => "utf-8" );
-
-if ( $mode eq 'showpagediff' ) {
- my $diffpagenum = int( $q->param("d") );
- my $title_group = int( $q->param("title") );
-
-}
-
-#$homelink = "pdfsearch.pl?mode=$mode&width=$width&height=$height&rows=$rows";
-#if ( $mode eq 'mobile' ) {
-# $template = HTML::Template::Pro->new(
-# filename => "./template/mobile_top.tmp.html",
-# die_on_bad_params => 0
-# );
-# $template->param( homelink => $homelink );
-#}
-##else {
-# $template = HTML::Template::Pro->new(
-filename => "./template/desktop_top.tmp.html",
- die_on_bad_params => 0 );
-}
-$template->param( mode => $mode );
-$template->param( width => $width );
-$template->param( height => $height );
-$template->param( start => $start );
-$template->param( rows => $rows );
-$bstart = int($start) - int($rows);
-$nstart = int($start) + int($rows);
-
-if ( $bstart < 0 ) {
- $bstart = 0;
-}
-$blink =
-"pdfsearch.pl?mode=$mode&search_text=$search_text&width=$width&height=$height&start=$bstart&rows=$rows&fq_title=$fq_title_row&fq_genre=$fq_genre_row";
-$nlink =
-"pdfsearch.pl?mode=$mode&search_text=$search_text&width=$width&height=$height&start=$nstart&rows=$rows&fq_title=$fq_title_row&fq_genre=$fq_genre_row";
-$template->param( blink => $blink );
-$template->param( nlink => $nlink );
-
-if ( length $search_text > 0 ) {
- $template->param( text => $search_text );
- $template->param( show_result => "true" );
- $template->param( search_top => "0" );
- my $query =
- WebService::Solr::Query->new( { text => decode( 'utf-8', $search_text ) } );
- my %response_query = (
- 'rows' => $rows,
- 'start' => $start,
- 'group.limit' => '30',
- 'group.field' => 'title_group',
- 'group' => true,
- 'hl' => true,
- 'hl.fl' => 'text',
- 'hl.simple.pre' => "<font color=red><em>",
- 'hl.simple.post' => "</em></font>",
- 'hl.fragsize' => '300',
- 'hl.fragmenter' => 'gap',
- 'hl.alternateField' => 'text',
- 'hl.maxAlternateFieldLength' => '300',
- 'hl.useFastVectorHighlighter' => true,
- );
- my $fq_title_solr = "";
-
- if ( ( length $fq_title > 0 ) or ( length $fq_genre > 0 ) ) {
- $sql = "SELECT title
- FROM pdffile
- WHERE title_id = '$fq_title'
- ORDER BY part DESC LIMIT 1";
- $dbs = $sqldbi->prepare($sql);
- $dbs->execute();
- $dbh = $dbs->fetchrow_hashref;
- $fq_title_solr = decode( 'utf-8', $dbh->{'title'} );
-
- #print Dumper $dbh;
- }
-
- #if ((length $fq_title > 0) and (length $fq_genre > 0)){
- # $response_query{'facet'} = "true";
- # @fqs = ('title_group:$fq_title_solr','genre:$fq_genre');
- # $response_query{'fq'} = [@fqs];
- if ( length $fq_title > 0 ) {
- $response_query{'fq'} = "title_group:\"$fq_title_solr\"";
- }
- if ( length $fq_genre > 0 ) {
- $response_query{'facet'} = "true";
- @fqs = ( 'genre:' . $fq_genre, );
- $response_query{'fq'} = [@fqs];
- }
-
- #print Dumper %response_query;
- my $response = $solr->search( $query, \%response_query );
-
- #print Dumper $response;
-
- my $hits = $response->content;
- my %hits = %$hits;
- my $response_header = $hits{grouped}{title_group}{groups};
- my @response_header = @$response_header;
- my @print_group_arrays = ();
- foreach my $group (@response_header) {
- my $textarray = $group->{doclist}{docs};
- my @textarray = @$textarray;
- my %print_group_array = &printGroupResults(
- $group->{doclist}{numFound},
- $textarray[0]->{title_group},
- $search_text, $textarray, $response->content->{highlighting}
- );
- push( @print_group_arrays, \%print_group_array );
- }
- $template->param( group => \@print_group_arrays );
-}
-else {
- $template->param( search_top => true );
-}
-
-sub printGroupResults() {
- ( $hitsnum, $title, $search_text, $hits, $hits_hl ) = @_;
- my $result_group;
- my @print_page_arrays = ();
- $template->param( show_result => 1 );
- foreach $doc (@$hits) {
- ( $pagenum, $path, $linkpath ) =
- ( $doc->{page}, $doc->{path_id}, $doc->{path_id} );
- my $findPageSQL =
- "SELECT startpage,title_id from pdffile WHERE id = '$path';";
- my $sth = $sqldbi->prepare($findPageSQL);
- $sth->execute;
- $dbarray = $sth->fetchrow_arrayref;
- $showpagenum = $pagenum + $dbarray->[0];
- $ref =
- "title="
- . uri_escape( $dbarray->[1] )
- . "&pagenum=$showpagenum&mode=$mode&width=$width&height=$height";
- my %print_page_array = (
- page => $showpagenum,
- hl_text => $hits_hl->{ $doc->{id} }{text}[0],
- refaddr => $ref
- );
- @print_page_array = ($print_page_array);
- push( @print_page_arrays, \%print_page_array );
- }
- %print_group_array = (
- text => $title,
- search_num => $hitsnum,
- search_result => \@print_page_arrays
- );
- return %print_group_array;
-}
-
-print $template->output();
-$sqldbi . disconnect;
modal:true,
title:"Search"
});
+ $("#genre_dialog").dialog({
+ autoOpen:false,
+ //height:140,
+ width:260,
+ modal:true,
+ title:"Genre Setting"
+ });
+ $("#settings_dialog").dialog({
+ autoOpen:false,
+ //height:140,
+ width:300,
+ modal:true,
+ title:"Settings"
+ });
+ $("#setting_showpage_ratio").buttonset();
+ $("#setting_ok_button").button({
+ label:"OK",
+ icons:{
+ primary:"ui-icon-circle-check"
+ }
+ })
+ .click(function(){
+ $("#settings_dialog").dialog('close');
+ });
+ $("#setting_cancel_button").button({
+ label:"cancel",
+ icons:{
+ primary:"ui-icon-circle-close"
+ }
+ })
+ .click(function(){
+ $("#settings_dialog").dialog('close');
+ });
$("#search").button({
label:"検索",
icons:{
.click(function(){
window.location.href="<TMPL_VAR NAME="blink">";
});
+ $("#spd_dialog").dialog({
+ autoOpen:false,
+ //height:140,
+ width:280,
+ modal:true,
+ title:"頁差分設定"
+ });
$("#pagediff").button({
label:"頁差分",
icons:{
}
})
.click(function(){
- window.location.href="<TMPL_VAR NAME="blink">";
+ $("#spd_dialog").dialog('open');
+ });
+ $("#spd_button").button({
+ label:"頁差分設定",
+ icons:{
+ primary:"ui-icon-copy"
+ }
+ })
+ .click(function(){
+ var dnum=$('#spd_num').val();
+ console.log("<TMPL_VAR NAME="title_id">");
+ if (dnum.length>0){
+ $.ajax({
+ type:"GET",
+ url:"pdfmanager.pl",
+ data:{
+ mode : 'showpagediff',
+ title : '<TMPL_VAR NAME="title_id">',
+ diff : dnum
+ }
+ })
+ }
+ $("#spd_dialog").dialog('close');
});
$("#settings").button({
label:"設定",
}
})
.click(function(){
+ $("#settings_dialog").dialog('open');
+ });
+ $("#setting_genre_button").button({
+ label:"ジャンル設定",
+ icons:{
+ primary:"ui-icon-folder-collapsed"
+ }
+ }).click(function(){
+ $("#genre_dialog").dialog('open');
+ });
+ $("#setting_spd_button").button({
+ label:"頁差分設定",
+ icons:{
+ primary:"ui-icon-copy"
+ }
+ }).click(function(){
+ $("#spd_dialog").dialog('open');
+ });
+
+ $("#genre_button").button({
+ label:"Genre設定",
+ icons:{
+ primary:"ui-icon-copy"
+ }
+ })
+ .click(function(){
+ var genre_text=$('#genre_text').val();
+ if (genre_text.length>0){
+ $.ajax({
+ type:"GET",
+ url:"pdfmanager.pl",
+ data:{
+ mode : 'genre',
+ title : '<TMPL_VAR NAME="title_id">',
+ genre : genre_text
+ }
+ })
+ }
+ $("#genre_dialog").dialog('close');
});
$("#login").button({
label:"ログイン",
});
jQuery(document).ready(function(){
- var images=jQuery("#images");
- var image_width_size=100;
+ var image1=jQuery("#image1");
+ var image2=jQuery("#image2");
+ var image_width_size=50;
$("#expand").button({
label:"大",
})
.click(function(){
- image_width_size=image_width_size+20;
- images.stop(true).animate({width:image_width_size + "%"},250);
+ image_width_size=image_width_size+10;
+ image1.stop(true).animate({width:image_width_size + "%"},250);
+ image2.stop(true).animate({width:image_width_size + "%"},250);
});
$("#reduce").button({
label:"小",
})
.click(function(){
- image_width_size=image_width_size-20;
- images.stop(true).animate({width:image_width_size + "%"},250);
+ image_width_size=image_width_size-10;
+ image1.stop(true).animate({width:image_width_size + "%"},250);
+ image2.stop(true).animate({width:image_width_size + "%"},250);
});
});
</div>
<br>
<div data-role="content" id='image'>
- <img id='images' src='<TMPL_VAR NAME="jpegpath">' width='100%' />
- </div>
+ <div><img id='image1' src='<TMPL_VAR NAME="jpegpath">' width='50%' align="left"/></div>
+ <div><img id='image2' src='<TMPL_VAR NAME="jpegpath2">' width='50%' /></div>
+ <div style="clear:both"></div>
+ </div>
<div align="center" id="toolbar_footer" class="ui-widget-header">
<button type="button" id="b10link_f"></button>
<button type="button" id="blink_f"></button>
- <button type="button" id="pagediff" disabled></button>
+ <button type="button" id="pagediff"></button>
<TMPL_VAR NAME="nowpage"> / <TMPL_VAR NAME="maxpage">
- <button type="button" id="settings" disabled></button>
+ <button type="button" id="settings"></button>
<button type="button" id="nlink_f"></button>
<button type="button" id="n10link_f"></button>
</div>
<br>
<button type="button" id="jump_button">移動</button>
</div>
+ <div id="spd_dialog" align="right">
+ <input type="number" width="100%" id="spd_num" value="<TMPL_VAR NAME="nowspd">" class="ui-corner-all"/>
+ <br>
+ <br>
+ <button type="button" id="spd_button">設定</button>
+ </div>
+ <div id="genre_dialog" align="right">
+ <input type="text" width="100%" id="genre_text" value="" class="ui-corner-all"/>
+ <br>
+ <br>
+ <button type="button" id="genre_button">設定</button>
+ </div>
+ <div id="settings_dialog" align="center">
+ <button type="button" id="setting_genre_button">ジャンル設定</button><br>
+ <button type="button" id="setting_spd_button">SPD設定</button><br><hr>
+ <!--<div id="setting_showpage_ratio" disabled>
+ <input type="radio" id="show_1p" checked="checked" name="radio"/>
+ <label for="show_1p">1p</label>
+ <input type="radio" id="show_2p" name="radio" />
+ <label for="show_2p">見開き</label>
+ </div><hr>-->
+ <button type="button" id="setting_ok_button">OK</button>
+ <button type="button" id="setting_cancel_button">キャンセル</button><br>
+ </div>
</form>
</body>
</html>