/[webpac2]/trunk/vhost/webpac2.cgi
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/vhost/webpac2.cgi

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

revision 1237 by dpavlin, Fri Jul 10 14:37:35 2009 UTC revision 1340 by dpavlin, Tue Oct 12 12:05:34 2010 UTC
# Line 11  use Data::Page; Line 11  use Data::Page;
11  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
12  use SWISH::API;  use SWISH::API;
13  use JSON;  use JSON;
14    use Text::Unaccent::PurePerl qw/unac_string/;
15    use HTML::FillInForm::Lite;
16    use Encode;
17    
18  my $range_around = 5;  my $range_around = 5;
19  my $entries_per_page = 30;  my @entries_per_page = ( 30, 50, 100, 500 );
20  my $debug = param('debug');  my $debug = param('debug');
21    
22  print header(  print header(
# Line 136  my $inputs_available = 0; Line 139  my $inputs_available = 0;
139    
140  foreach ( @{ $db->{input} } ) {  foreach ( @{ $db->{input} } ) {
141          my $input = $_->{name} || die "no name in ",dump( $_ );          my $input = $_->{name} || die "no name in ",dump( $_ );
142            next unless defined $stats->{input}->{$input}; # skip inputs without data
143          if ( ! $only_input->{'-labels'}->{$input} ) {          if ( ! $only_input->{'-labels'}->{$input} ) {
144                  push @{ $only_input->{'-values'} }, $input;                  push @{ $only_input->{'-values'} }, $input;
145                          $only_input->{'-labels'}->{$input} = $_->{description} || $input;                          $only_input->{'-labels'}->{$input} = $_->{description} || $input;
# Line 150  push @style, "../../$path/$path.css" if Line 154  push @style, "../../$path/$path.css" if
154  dump_yaml( 'style', \@style );  dump_yaml( 'style', \@style );
155    
156  sub search_form {  sub search_form {
157    
158            my $form_html = "$dir/$path/$path-search.html";
159            if ( -e $form_html ) {
160                    my $html = read_file( $form_html );
161                    my $q = CGI->new();
162                    my $h = HTML::FillInForm::Lite->new();
163                    return $h->fill(\$html, $q);
164            }
165    
166          qq|<a name="form"></a>|,          qq|<a name="form"></a>|,
167          start_form( -action => self_url( query => 0 ) ),          start_form( -action => self_url( query => 0 ) ),
168                  checkbox_group(                  checkbox_group(
# Line 159  sub search_form { Line 172  sub search_form {
172                  ),                  ),
173                  textfield( -name => 'search' ),                  textfield( -name => 'search' ),
174                  $attr_operators ? popup_menu( -name => 'attr_operator', %$attr_operators ) : '',                  $attr_operators ? popup_menu( -name => 'attr_operator', %$attr_operators ) : '',
175                  submit,                  submit( -value => 'Search' ),
176                  hidden( -name => 'entries_per_page', -default => $entries_per_page ),  #               hidden( -name => 'entries_per_page', -default => $entries_per_page ),
177                    popup_menu( -name => 'entries_per_page', -values => [ @entries_per_page ], -title => 'entries per page' ),
178                  # we need current_page fixed at 1 so that every submit through form will reset it                  # we need current_page fixed at 1 so that every submit through form will reset it
179                  qq|<input type=hidden name=current_page value=1 >|,                  qq|<input type=hidden name=current_page value=1 >|,
180                  checkbox( -name => 'debug', -default => 0 ), # FIXME hidden?                  checkbox( -name => 'debug', -default => 0 ), # FIXME hidden?
# Line 189  print Line 203  print
203    
204  if ( my $search = param('search') ) {  if ( my $search = param('search') ) {
205    
206            $search = unac_string( Encode::decode('utf-8',$search) );
207    
208          print qq|          print qq|
209                  <a href="#form" class="skip" title="skip to search form">#</a>                  <a href="#form" class="skip" title="skip to search form">#</a>
210                  <div id="results">                  <div id="results">
# Line 201  if ( my $search = param('search') ) { Line 217  if ( my $search = param('search') ) {
217          my @attrs = param('attr');          my @attrs = param('attr');
218          my $op = param('attr_operator');          my $op = param('attr_operator');
219    
220          if ( $search =~ m{(=|"|AND|OR)} ) {          if ( $search =~ m{(=|"|\bAND\b|\bOR\b)} ) {
221                  push @search, $search;                  push @search, $search;
222          } elsif ( @attrs ) {          } elsif ( @attrs ) {
223    
# Line 218  if ( my $search = param('search') ) { Line 234  if ( my $search = param('search') ) {
234                                     $template =~ s{Q}{$v};                                     $template =~ s{Q}{$v};
235                                  $whitespace = " AND " if $whitespace;                                  $whitespace = " AND " if $whitespace;
236    
237                                    # don't return -* &* and other non-word characters
238                                    return '' if $template =~ m/^\W\*$/;
239    
240                                  return                                  return
241                                          $whitespace .                                          $whitespace .
242                                          $attr . '="' . $template . '"';                                          $attr . '="' . $template . '"';
# Line 246  if ( my $search = param('search') ) { Line 265  if ( my $search = param('search') ) {
265          $q .= ' AND ((' . join(') OR (', map { "input=\"$_\"" } @only_input) . '))' if @only_input;          $q .= ' AND ((' . join(') OR (', map { "input=\"$_\"" } @only_input) . '))' if @only_input;
266    
267          warn "# query: $q\n";          warn "# query: $q\n";
268          my $swish_results = $swish->query( $q );          my $search_obj = $swish->new_search_object;
269            if ( my $sort = param('sort') ) {
270                    $search_obj->set_sort( $sort );
271            }
272            my $swish_results = $search_obj->execute( $q );
273    
274          dump_yaml( 'swish_results', $swish_results );          dump_yaml( 'swish_results', $swish_results );
275    
# Line 280  if ( my $search = param('search') ) { Line 303  if ( my $search = param('search') ) {
303    
304                  while ( my $result = $swish_results->next_result ) {                  while ( my $result = $swish_results->next_result ) {
305    
306                          my $data = from_json $result->property('data');                          my $data = $result->property('data');
   
307                          dump_yaml( 'data', $data );                          dump_yaml( 'data', $data );
308                            # FIXME if we produce valid json we shouldn't need eval here!
309                            eval { $data = from_json( $data, {utf8 => 1} ); };
310                            if ( $@ ) {
311                                    warn "ERROR: $@ from ",dump( $data );
312                                    next;
313                            }
314    
315                          my $li_class = '';                          my $li_class = '';
316                          $li_class = qq| class="z"| if $nr % 2 == 0;                          $li_class = qq| class="z"| if $nr % 2 == 0;
# Line 291  if ( my $search = param('search') ) { Line 319  if ( my $search = param('search') ) {
319                                  next unless defined $data->{$attr};                                  next unless defined $data->{$attr};
320                                  my $v = $data->{$attr};                                  my $v = $data->{$attr};
321                                  if ( $html_markup && ! $html_markup_skip->{$attr} ) {                                  if ( $html_markup && ! $html_markup_skip->{$attr} ) {
322                                          eval "\$v = $html_markup->$attr( \$v );";                                          eval "\$v = $html_markup->$attr( \$v, \$data );";
323                                          if ( $@ ) {                                          if ( $@ ) {
324                                                  warn "disable html markup for $attr: $@";                                                  warn "disable html markup for $attr: $@";
325                                                  $html_markup_skip->{$attr} = $@;                                                  $html_markup_skip->{$attr} = $@;

Legend:
Removed from v.1237  
changed lines
  Added in v.1340

  ViewVC Help
Powered by ViewVC 1.1.26