onsearch

 view release on metacpan or  search on metacpan

lib/OnSearch/UI.pm  view on Meta::CPAN

@ISA = qw(Exporter DynaLoader);
@EXPORT_OK = (qw/DESTROY/);

###
### Some character entity constants.
###
my $GT_ent = '>';
my $LT_ent = '<';

=head1 NAME

OnSearch::UI.pm - User interface library for OnSearch.

=head1 DESCRIPTION

OnSearch::UI provides an object oriented user interface for the
OnSearch search engine and page templates for the application's
dynamic HTML content.

=head1 EXPORTS

=head2 DESTROY (I<objectref>)

Perl calls DESTROY when deleting unused OnSearch::UI objects.

=head1 METHODS

The UI.pm methods are listed and described below.

=cut

###
### These are the three basic types of matches.  See the comments 
### in Search.pm.
###
my @matchtypes = (qw/any all exact/);

=head2 $ui -> parbreak ();

Template for a paragraph break.

  $ui -> parbreak -> wprint;

=cut

sub parbreak {
    my $self = shift;
    $self -> {text} = '<p>';
    return $self;
}

=head2 $ui -> input_form (I<search_preferences>, I<volume_preferences>);

OnSearch search page template.  The arguments are hash references 
of user preferences.

=cut

sub input_form {
    my $self = shift;
    my $prefs = $_[0];
    my $vol_prefs = $_[1];

    my ($case_opt, $nocase_opt, $matchany_opt, $matchall_opt, 
	$partword_opt,$matchexact_opt, $completeword_opt, $pagesize_opt,
	%dfmatch, $nresults_opt, %volumes, $OnSearchDir);

    $case_opt = $nocase_opt = '';
    $matchany_opt = $matchall_opt = $matchexact_opt = '';
    $partword_opt = $completeword_opt = '';

    my $c = OnSearch::AppConfig -> new;

    %volumes = $c -> Volumes;
    $OnSearchDir = $c -> str (qw/OnSearchDir/);
    $self -> volume_info (\%volumes, $vol_prefs);
    my $volinfo = $self -> {text};

    if ($prefs !~ /defaults|none/) {
	my %prefs = $c->parse_prefs ($prefs);

	(($prefs{matchcase} =~ /yes/) ? $case_opt = 'checked' :
	 $nocase_opt = 'checked');

	$partword_opt = ($prefs{partword} =~ /yes/) ? 'checked' : '';
	$completeword_opt = ($prefs{partword} =~ /no/) ? 'checked' : '';

	foreach (@matchtypes) {
	    $dfmatch{$_} = (m"$prefs{matchtype}" ? 'checked' : ''); 
	}

	$pagesize_opt = $prefs{pagesize};
	$nresults_opt = $prefs{nresults};

    } else {
	###
	### These are the default search options.
	###
	$case_opt = 'checked';
	$dfmatch{$_} = '' foreach (@matchtypes);
	$dfmatch{any} = 'checked';
	$completeword_opt = 'checked';
	$pagesize_opt = $c->str ('PageSize');
	$nresults_opt = $c->str ('ResultsPerFile');
    }

$self -> {text} =<<END_OF_INPUT_FORM;
<form name="inputform" action="search.cgi">
<table width="100%">
  <tr align="center">
    <td>
          <table>
            <tr>
              <td valign="top">
	      <b>Enter a word or phrase to search for.</b><br>
                <label>
                    A search phrase can be any word or<br>combination of words.
                </label><br>
                <input type="text" name="searchterm" size="40"><br>
                <input type="image" name="submit" src="/$OnSearchDir/images/searchbutton.jpg">
		<p>
		$volinfo
              </td>
              <td rowspan="3" valign="top">
                <table>

                  <tr>
                    <td colspan="3">
                      <label><b>Search Options</b></label><br>
                    </td>
                  </td>
                  </tr>
                  <tr>
                    <td>
                      <input type="radio" name="matchcase" value="no" $nocase_opt>
                    </td>
                    <td>
                      <label>Match upper or lower case.</label>
                    </td>
		    <td rowspan="8">
                      <div>
                        <label>
                        <a href="doc/userguide.html#searchingtext" target="_blank">
                        Information about search<br>terms and options.</a>
                        </label>
                     </div>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <input type="radio" name="matchcase" value="yes" $case_opt>
                    </td>
                    <td>

lib/OnSearch/UI.pm  view on Meta::CPAN

    $self -> {text} =<<EOT;
<form method="post" action="archive.cgi" enctype="multipart/form-data">
  <table width="75%" align="center">
    <colgroup>
    <col width="75%">
    <col width="25%">
      <tr>
        <td>
          <label class="adminsubtitle"><b>Files</b></label>
        </td>
	<td>
	&nbsp;
        </td>
      </tr>
      <tr>
        <td>
          <label class="buttontext">Enter a file name to upload and index:</label>
        </td>
        <td valign="bottom" rowspan="2">
          <input type="image" class="search" src="/$OnSearchDir/images/update.jpg">
        </td>  
      </tr>
      <tr>
        <td> 
          <input type="file" name="file">
        </td>
      </tr>
    </colgrou>
  </table>
</form>
EOT

    return $self;
}

=head2 $ui -> archive_title ();

Template for the Archive page title.

=cut

sub archive_title {
    my $self = shift;
    $self -> {text} =<<EOT;
<table width="75%" align="center">
  <tr><td><label class="admintitle"><b>Archive</b></label></td></tr>
  <tr><td><label class="helptext">Add files or URLs to be indexed.</td></tr>
</table>
EOT
return $self;
}

=head2 $ui -> webindex_form (I<preferences>);

Template for the Web index form.

=cut

sub webindex_form {
    my $self = shift;
    my $prefs = $_[0];

    my ($pagescope_opt, $sitescope_opt, %prefs, $cfg, $OnSearchDir);
    
    $cfg = OnSearch::AppConfig -> new;
    $OnSearchDir = $cfg -> str (qw/OnSearchDir/);

    if ($prefs =~ /defaults/) {
	$pagescope_opt = 'checked';
	$sitescope_opt = '';
    } else {
	%prefs = OnSearch::AppConfig->parse_prefs ($prefs);
	$pagescope_opt = ($prefs{targetscope} =~ /page/) ? 'checked' : '';
	$sitescope_opt = ($prefs{targetscope} =~ /site/) ? 'checked' : '';
    }

    $self -> {text} =<<EOT;
<form action="archive.cgi">
  <table width="75%" align="center">
  <colgroup>
  <col width="75%">
  <col width="25%">
    <tr>
      <td valign="top">
        <table>
          <tr>
            <td>
              <label class="adminsubtitle"><b>Web Pages</b></label>
            </td>
          </tr>
	  <tr>
            <td colspan="2">
              <label class="buttontext">Enter a URL to index:</label>
            </td>
          </tr>
          <tr>
	    <td colspan="2">
              <input type="text" size="40" name="targeturl">
            </td>
          </tr>
          <tr>
            <td>
              <input type="radio" name="targetscope" value="page" $pagescope_opt>
              <label class="button">Index this page only.</label>
            </td>
            <td>
              <input type="radio" name="targetscope" value="site" $sitescope_opt>
              <label class="button">Index the pages on this site.</label>
            </td>
          </tr>
        </table>
      </td>
      <td valign="bottom">
        <input type="image" name="submit" class="search" src="/$OnSearchDir/images/update.jpg">
      </td>
    </tr>
  </colgroup>
  </table>
</form>
EOT
return $self;
}

=head2 $ui -> volume_info (I<volume_list>, I<user_prefs>);

Matches site volume information with user preferences.

=cut

sub volume_info {
    my $self = $_[0];
    my $vol_ref = $_[1];
    my $vol_prefs = $_[2];

    my $c = OnSearch::AppConfig -> new;
    my ($vol, $vol_name, $v, $k, @selected);

    @selected = split /,/, $vol_prefs;

    $self -> {text} = qq|<label><strong>Volumes Selected:</strong>\n|;
    $self -> {text} .=  qq|<table>\n|;
    foreach my $k (keys %{$vol_ref}) {
	next unless scalar grep /$k/, @selected;
	$self -> {text} .= qq|<tr><td><label>$k</label></td></tr>\n|;
    }
    $self -> {text} .= qq|</table>\n|;
    return $self;
}

=head2 $ui -> volume_form (I<volume_list>);

Template for the volume list.

=cut

sub volume_form {
    my $self = $_[0];
    my $vols_ref = $_[1];
    my $selected_ref = $_[2];

    my ($c, $OnSearchDir, $vol_list, $vol_name, $v, $checked);
    $c = OnSearch::AppConfig -> new;
    $OnSearchDir = $c -> str (qw/OnSearchDir/);

$self -> {text} =  qq|<form action="filters.cgi">\n|;
$self -> {text} .= qq|<table cellpadding="5">\n|;
$self -> {text} .= qq|<colgroup>\n|;
$self -> {text} .= qq|<col width="10%">\n|;
$self -> {text} .= qq|<col width="20%">\n|;
$self -> {text} .= qq|<col width="45%">\n|;
$self -> {text} .= qq|<col width="25%">\n|;
$self -> {text} .= qq|<tr><td valign="top"><strong>Select</strong></td>\n|;
$self -> {text} .= qq|<td valign="top"><strong>Volume<br>Name</strong></td>\n|;
$self -> {text} .= qq|<td valign="top"><strong>Contents</strong></td>\n|;
$self -> {text} .= qq|<td rowspan="3"><input type="image" name="submit" class="search" src="/$OnSearchDir/images/update.jpg"></td></tr>\n|;

    foreach my $k (keys %{$vols_ref}) {
	$vol_name = $k;
	$v = ${$vols_ref}{$k};
    if (scalar grep /$k/, @$selected_ref) {
	$checked = 'checked';
    } else {
	$checked = '';
    }
$self -> {text} .= qq|<tr><td><input name="$vol_name" type="checkbox" $checked></td>\n|;
$self -> {text} .= qq|<td><label class="errortext">$vol_name</label></td>\n|;

$self -> {text} .= qq|<td><label class="errortext">$v</label></td></tr>\n|;
    }
$self -> {text} .= qq|</table>\n|;
$self -> {text} .= qq|</form>\n|;

    return $self;
}

=head2 $ui -> wprint (I<fh>);

Output text or a page template to the Web browser.



( run in 0.788 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )