/[webpac]/branches/humanistika/WebPac.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /branches/humanistika/WebPac.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 687 by dpavlin, Tue Mar 1 19:32:23 2005 UTC revision 710 by dpavlin, Sun Sep 11 18:45:50 2005 UTC
# Line 10  use DBI; Line 10  use DBI;
10  use Config::IniFiles;  use Config::IniFiles;
11  use Text::Unaccent;  use Text::Unaccent;
12  use Data::Pageset;  use Data::Pageset;
13    use POSIX qw(locale_h);
14    
15  use lib '..';  use lib '..';
16  use index_DBI_filter;  use index_DBI_filter;
# Line 32  my $UNAC_FILTER =$cfg_global->val('globa Line 33  my $UNAC_FILTER =$cfg_global->val('globa
33  my $BASE_PATH =$cfg_global->val('webpac', 'base_path');  my $BASE_PATH =$cfg_global->val('webpac', 'base_path');
34  # for pager  # for pager
35  my $pages_per_set = $cfg_global->val('webpac', 'pages_per_set') || 10;  my $pages_per_set = $cfg_global->val('webpac', 'pages_per_set') || 10;
36    my $locale = $cfg_global->val('locale') || 'hr_HR';
37    
38  Text::Iconv->raise_error(0);     # Conversion errors raise exceptions  Text::Iconv->raise_error(0);     # Conversion errors raise exceptions
39    
40  my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);  my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);
41    
42    setlocale(LC_CTYPE, $locale);
43    setlocale(LC_COLLATE, $locale);
44    
45  if ($UNAC_FILTER) {  if ($UNAC_FILTER) {
46          require $UNAC_FILTER;          require $UNAC_FILTER;
47  } else {  } else {
# Line 186  sub make_pager_vars { Line 191  sub make_pager_vars {
191          foreach my $v (@persist_vars) {          foreach my $v (@persist_vars) {
192                  foreach my $val ($q->param($v)) {                  foreach my $val ($q->param($v)) {
193                          next if (! $val || $val eq '');                          next if (! $val || $val eq '');
194                          $val =~ s/"/&quote;/g;                          $val =~ s/"/"/g;
195                          $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";                          $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";
196                          $hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm");                          $hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm");
197                  }                  }
# Line 242  sub show_results_list { Line 247  sub show_results_list {
247          my $full = $q->param('full');          my $full = $q->param('full');
248    
249          my @persist_vars = ( 'rm', 'persist_search' );          my @persist_vars = ( 'rm', 'persist_search' );
250          my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.($q->param('PAGER_offset') || 0) );          my $url_params = {
251                    'rm' => 'results',
252                    'show_full' => 1,
253                    'last_PAGER_offset' => ($q->param('PAGER_offset') || 0),
254            };
255    
256          my @persist_search_vars;          my @persist_search_vars;
257          my @url_params_persist;          my $url_params_persist = {};
258          if ($q->param("persist_search")) {          if ($q->param("persist_search")) {
259                  @persist_search_vars = split(/\s*,\s*/, $q->param("persist_search"));                  @persist_search_vars = split(/\s*,\s*/, $q->param("persist_search"));
260                  push @url_params_persist, "persist_search=".$q->url_param("persist_search");                  $url_params_persist->{'persist_search'} = $q->url_param("persist_search");
261                  push @url_params,"persist_search=".$q->url_param("persist_search");                  $url_params->{'persist_search'} = $q->url_param("persist_search");
262          }          }
263    
264          # support parametars "f" and "v" for start          # support parametars "f" and "v" for start
# Line 270  sub show_results_list { Line 279  sub show_results_list {
279    
280                  # create url parametars (and persistent ones)                  # create url parametars (and persistent ones)
281    
282                  push @url_params,"f$i=".$q->url_param("f$i");                  $url_params->{"f$i"} = $q->url_param("f$i");
283                  push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist);                  $url_params_persist->{"f$i"} = $q->url_param("f$i") if ($persist);
284    
285                  foreach my $v ($q->url_param("v$i")) {                  foreach my $v ($q->url_param("v$i")) {
286                          # escape quotes so that phrase search work                          # escape quotes so that phrase search work
287                          $v =~ s/"/%22/g;                          $v =~ s/"/%22/g;
288                          push @url_params,"v$i=$v";                          $url_params->{"v$i"} = $v;
289                          push @url_params_persist,"v$i=$v" if ($persist);                          $url_params_persist->{"v$i"} = $v if ($persist);
290                  }                  }
291    
292                  if ($q->param("e$i")) {                  if ($q->param("e$i")) {
293                          push @url_params,"e$i=".$q->url_param("e$i");                          $url_params->{"e$i"} = $q->url_param("e$i");
294  #                       push @url_params_persist,"e$i=".$q->url_param("e$i");  #                       $url_params_persist->{"e$i"} = $q->url_param("e$i");
295                  }                  }
296    
297                  my $wc="*";     # swish wildcard                  my $wc="*";     # swish wildcard
# Line 332  sub show_results_list { Line 341  sub show_results_list {
341                                  }                                  }
342                          }                          }
343                          $s =~ s/\*+/*/g;                          $s =~ s/\*+/*/g;
344                            $s =~ s/[()]//g;        # () are used in query language
345                          $s = $pre.$s.$post if ($q->param("e$i"));                          $s = $pre.$s.$post if ($q->param("e$i"));
346                          push @swish_q,$s;                          push @swish_q,$s;
347                  }                  }
# Line 342  sub show_results_list { Line 352  sub show_results_list {
352    
353          my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0);          my $tmpl = $self->load_tmpl(url_ex($q,'results.html'), global_vars => 1, die_on_bad_params => 0);
354    
         $tmpl->param('url_params',"?".join("&",@url_params));  
   
355          sub esc_html {          sub esc_html {
356                  my $html = shift;                  my $html = shift;
357                  $html =~ s/</&lt;/g;                  $html =~ s/</&lt;/g;
# Line 362  sub show_results_list { Line 370  sub show_results_list {
370                  $sort = $sortby;                  $sort = $sortby;
371                  push @persist_vars, "sortby";                  push @persist_vars, "sortby";
372          }          }
373          $tmpl->param('url_params_paths',"?".join("&",@url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr));          # used to filter entries in index and swish
374            my $filter = $q->param("filter");
375    
376          # construct swish query          # construct swish query
377          my $sw_q = join(" and ",@s_arr);          my $sw_q = join(" and ",@s_arr);
378          if (@path_arr && $q->param('show_full')) {          if (@path_arr && $q->param('show_full')) {
379                  $sw_q .= "and (swishdocpath=\"";                  $sw_q .= " and (swishdocpath=\"";
380                  $sw_q .= join("\" or swishdocpath=\"",@path_arr);                  $sw_q .= join("\" or swishdocpath=\"",@path_arr);
381                  $sw_q .= "\")";                  $sw_q .= "\")";
382                  $tmpl->param('full',1); # show full records                  $tmpl->param('full',1); # show full records
383    #       } elsif (@path_arr && $#path_arr == 0) {
384    #               # I will assume that it's a filter since there isn't show_full
385    #               $filter = shift @path_arr;
386          } elsif ($q->param('show_full')) {          } elsif ($q->param('show_full')) {
387                  # just show full path, no path defined                  # just show full path, no path defined
388                  $tmpl->param('full',1);                  $tmpl->param('full',1);
# Line 378  sub show_results_list { Line 390  sub show_results_list {
390                  $tmpl->param('full',0);                  $tmpl->param('full',0);
391          }          }
392    
393            if ($filter) {
394                    $sw_q .= " and (swishdocpath=\"$filter\")" unless (@path_arr);
395                    push @persist_vars, "filter";
396                    $url_params->{'filter'} = $filter;
397                    $url_params_persist->{'filter'} = $filter;
398            }
399    
400          my $swish_msg = ' ';          my $swish_msg = ' ';
401    
402          # create new swish instance          # create new swish instance
# Line 402  sub show_results_list { Line 421  sub show_results_list {
421          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);
422          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);
423    
424            # URL parametars for search results
425            sub cook_url_params {
426                    my $hash = shift || return;
427                    return join("&", map { $_."=".$hash->{$_} } keys %{$hash});
428            }
429    
430            $tmpl->param('url_params',"?".cook_url_params($url_params));
431            $tmpl->param('url_params_paths',"?".cook_url_params($url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr));
432    
433    
434    
435          #          #
436          # build pager          # build pager
437          #          #
# Line 435  sub show_results_list { Line 465  sub show_results_list {
465                          rank => $result->Property('swishrank')                          rank => $result->Property('swishrank')
466                  };                  };
467    
468                  $r->{html} = back2html($from_utf8->convert($result->Property('html')), join("&",@url_params_persist)) if ($q->param('show_full'));                  #$r->{html} = back2html($from_utf8->convert($result->Property('html')), cook_url_params($url_params_persist)) if ($q->param('show_full'));
469                    $r->{html} = back2html($from_utf8->convert($result->Property('html')), $filter ? 'filter='.$filter : '') if ($q->param('show_full'));
470    
471                  push @pager_data_list, $r;                  push @pager_data_list, $r;
472          }          }

Legend:
Removed from v.687  
changed lines
  Added in v.710

  ViewVC Help
Powered by ViewVC 1.1.26