/[webpac]/trunk/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 /trunk/WebPac.pm

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

revision 670 by dpavlin, Wed Feb 16 00:26:37 2005 UTC revision 733 by dpavlin, Wed May 24 13:32:07 2006 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 58  sub suff2file($$$$) { Line 63  sub suff2file($$$$) {
63    
64          return $tpl if (! $base_path);          return $tpl if (! $base_path);
65    
66            #warn "base_path: $base_path, p: $p, path: $path, tpl: $tpl\n";
67    
68            $p =~ s#/[^/]*$##;
69    
70          # strip everything to and including base path, leaving only          # strip everything to and including base path, leaving only
71          # additional (virtual) path          # additional (virtual) path
72          if ($base_path eq "/") {          if ($base_path eq "/") {
# Line 182  sub make_pager_vars { Line 191  sub make_pager_vars {
191          my $tmpl = shift @_;          my $tmpl = shift @_;
192          my @persist_vars = @_;          my @persist_vars = @_;
193          my $hidden_vars = '';          my $hidden_vars = '';
194            my $hidden_search = '';
195          foreach my $v (@persist_vars) {          foreach my $v (@persist_vars) {
196                  foreach my $val ($q->param($v)) {                  foreach my $val ($q->param($v)) {
197                          next if (! $val || $val eq '');                          next if (! $val || $val eq '');
198                            $val =~ s/"/"/g;
199                          $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";                          $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";
200                            $hidden_search .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n" if ($v ne "rm");
201                  }                  }
202          }          }
203    
204          $tmpl->param('PAGER_HIDDEN', $hidden_vars);          $tmpl->param('PAGER_HIDDEN', $hidden_vars);
205            $tmpl->param('SEARCH_HIDDEN', $hidden_search);
206          $tmpl->param('PAGER_JAVASCRIPT', qq#          $tmpl->param('PAGER_JAVASCRIPT', qq#
207  <SCRIPT LANGUAGE="Javascript">  <SCRIPT LANGUAGE="Javascript">
208  <!-- Begin  <!-- Begin
# Line 224  sub show_results_list { Line 237  sub show_results_list {
237    
238          my $q = $self->query();          my $q = $self->query();
239    
240            # submit was reset?
241            if ($q->param('reset')) {
242                    $q->delete_all;
243                    return $self->show_search_form();
244            }
245    
246          # load template for this page          # load template for this page
247    
248          my @s_arr;      # all queries are located here          my @s_arr;      # all queries are located here
# Line 232  sub show_results_list { Line 251  sub show_results_list {
251          my $full = $q->param('full');          my $full = $q->param('full');
252    
253          my @persist_vars = ( 'rm', 'persist_search' );          my @persist_vars = ( 'rm', 'persist_search' );
254          my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.($q->param('PAGER_offset') || 0) );          my $url_params = {
255                    'rm' => 'results',
256                    'show_full' => 1,
257                    'last_PAGER_offset' => ($q->param('PAGER_offset') || 0),
258            };
259    
260          my @persist_search_vars;          my @persist_search_vars;
261          my @url_params_persist;          my $url_params_persist = {};
262          if ($q->param("persist_search")) {          if ($q->param("persist_search")) {
263                  @persist_search_vars = split(/\s*,\s*/, $q->param("persist_search"));                  @persist_search_vars = split(/\s*,\s*/, $q->param("persist_search"));
264                  push @url_params_persist, "persist_search=".$q->url_param("persist_search");                  $url_params_persist->{'persist_search'} = $q->url_param("persist_search");
265                  push @url_params,"persist_search=".$q->url_param("persist_search");                  $url_params->{'persist_search'} = $q->url_param("persist_search");
266          }          }
267    
268          # support parametars "f" and "v" for start          # support parametars "f" and "v" for start
# Line 260  sub show_results_list { Line 283  sub show_results_list {
283    
284                  # create url parametars (and persistent ones)                  # create url parametars (and persistent ones)
285    
286                  push @url_params,"f$i=".$q->url_param("f$i");                  $url_params->{"f$i"} = $q->url_param("f$i");
287                  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);
288    
289                    my @v;
290    
291                  foreach my $v ($q->url_param("v$i")) {                  foreach my $v ($q->url_param("v$i")) {
292                          push @url_params,"v$i=$v";                          # escape quotes so that phrase search work
293                          push @url_params_persist,"v$i=$v" if ($persist);                          $v =~ s/"/%22/g;
294                            push @v, $v;
295                  }                  }
296                    $url_params->{"v$i"} = \@v;
297                    $url_params_persist->{"v$i"} = \@v if ($persist);
298    
299                  if ($q->param("e$i")) {                  if ($q->param("e$i")) {
300                          push @url_params,"e$i=".$q->url_param("e$i");                          $url_params->{"e$i"} = $q->url_param("e$i");
301  #                       push @url_params_persist,"e$i=".$q->url_param("e$i");  #                       $url_params_persist->{"e$i"} = $q->url_param("e$i");
302                  }                  }
303    
304                  my $wc="*";     # swish wildcard                  my $wc="*";     # swish wildcard
# Line 320  sub show_results_list { Line 348  sub show_results_list {
348                                  }                                  }
349                          }                          }
350                          $s =~ s/\*+/*/g;                          $s =~ s/\*+/*/g;
351                            $s =~ s/[()]//g;        # () are used in query language
352                          $s = $pre.$s.$post if ($q->param("e$i"));                          $s = $pre.$s.$post if ($q->param("e$i"));
353                          push @swish_q,$s;                          push @swish_q,$s;
354                  }                  }
# Line 330  sub show_results_list { Line 359  sub show_results_list {
359    
360          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);
361    
         $tmpl->param('url_params',"?".join("&",@url_params));  
   
362          sub esc_html {          sub esc_html {
363                  my $html = shift;                  my $html = shift;
364                  $html =~ s/</&lt;/g;                  $html =~ s/</&lt;/g;
# Line 350  sub show_results_list { Line 377  sub show_results_list {
377                  $sort = $sortby;                  $sort = $sortby;
378                  push @persist_vars, "sortby";                  push @persist_vars, "sortby";
379          }          }
380          $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
381            my $filter = $q->param("filter");
382    
383          # construct swish query          # construct swish query
384          my $sw_q = join(" and ",@s_arr);          my $sw_q = join(" and ",@s_arr);
385          if (@path_arr && $q->param('show_full')) {          if (@path_arr && $q->param('show_full')) {
386                  $sw_q .= "and (swishdocpath=\"";                  $sw_q .= " and (swishdocpath=\"";
387                  $sw_q .= join("\" or swishdocpath=\"",@path_arr);                  $sw_q .= join("\" or swishdocpath=\"",@path_arr);
388                  $sw_q .= "\")";                  $sw_q .= "\")";
389                  $tmpl->param('full',1); # show full records                  $tmpl->param('full',1); # show full records
390    #       } elsif (@path_arr && $#path_arr == 0) {
391    #               # I will assume that it's a filter since there isn't show_full
392    #               $filter = shift @path_arr;
393          } elsif ($q->param('show_full')) {          } elsif ($q->param('show_full')) {
394                  # just show full path, no path defined                  # just show full path, no path defined
395                  $tmpl->param('full',1);                  $tmpl->param('full',1);
# Line 366  sub show_results_list { Line 397  sub show_results_list {
397                  $tmpl->param('full',0);                  $tmpl->param('full',0);
398          }          }
399    
400            if ($filter) {
401                    $sw_q .= " and (swishdocpath=\"$filter\")" unless (@path_arr);
402                    push @persist_vars, "filter";
403                    $url_params->{'filter'} = $filter;
404                    $url_params_persist->{'filter'} = $filter;
405            }
406    
407          my $swish_msg = ' ';          my $swish_msg = ' ';
408    
409          # create new swish instance          # create new swish instance
# Line 390  sub show_results_list { Line 428  sub show_results_list {
428          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);          $tmpl->param('PAGER_offset',$q->param("PAGER_offset") || 0);
429          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);          $tmpl->param('last_PAGER_offset',$q->param("last_PAGER_offset") || 0);
430    
431            # URL parametars for search results
432            sub cook_url_params {
433                    my $hash = shift || return;
434                    return join("&", map {
435                            my $var = $_;
436                            if (ref($hash->{$var}) eq 'ARRAY') {
437                                    join('&',
438                                            map { $var.'='.$_ } @{$hash->{$var}}
439                                    );
440                            } else {
441                                    $var."=".$hash->{$var};
442                            }
443                    } keys %{$hash});
444            }
445    
446            $tmpl->param('url_params',"?".cook_url_params($url_params));
447            $tmpl->param('url_params_paths',"?".cook_url_params($url_params).'&'.join("&",map { my $t = $_; $t =~ s/\#/%23/g; "path=$t"; } @path_arr));
448    
449    
450    
451          #          #
452          # build pager          # build pager
453          #          #
# Line 423  sub show_results_list { Line 481  sub show_results_list {
481                          rank => $result->Property('swishrank')                          rank => $result->Property('swishrank')
482                  };                  };
483    
484                  $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'));
485                    $r->{html} = back2html($from_utf8->convert($result->Property('html')), $filter ? 'filter='.$filter : '') if ($q->param('show_full'));
486    
487                  push @pager_data_list, $r;                  push @pager_data_list, $r;
488          }          }
# Line 473  sub show_index { Line 532  sub show_index {
532          $tmpl->param('field',$field);          $tmpl->param('field',$field);
533          $tmpl->param('limit',$limit);          $tmpl->param('limit',$limit);
534          $tmpl->param('total',$total);          $tmpl->param('total',$total);
535            $tmpl->param('filter',$filter);
536    
537  # FIXME I should set offset and leave out limit from fetch!!  # FIXME I should set offset and leave out limit from fetch!!
538  #       if (! $q->param("PAGER_offset") {  #       if (! $q->param("PAGER_offset") {

Legend:
Removed from v.670  
changed lines
  Added in v.733

  ViewVC Help
Powered by ViewVC 1.1.26