Gossamer Forum
Home : Products : Links 2.0 : Customization :

New Search Mod

Quote Reply
New Search Mod
Well, I never did like the Links 2 search feature and thought the admin search was much better. A couple of weeks ago I got this bug to use dbman to search the links database. I managed to do that without too much difficulty.

But then I got interested in seeing if I could just use the Links 2 admin search. Well, I did it. Well, at least to the point where I am willing to let those knowledgeable of perl look at it and make improvements.

First, let me say that basically all I did was cut and paste. When it comes to perl, that is about as good as I get. I'll take credit for that. But the code is almost all from the links 2 code. I did borrow a few lines of code from the dbman code. And I did have a line or two of my own.

Well, I think there are only few things that needs to be done.

1. Create the searchnew.html. I just went into my admin and clicked on view. then just viewed the source and used that while I tested. Then change to match your site.

2. In the searchnew.html set the form to

Code:
<form action="<%db_cgi_url%>/searchnew.cgi" method="GET">


3. In the extra paths secion in your links.cfg file add

Code:
$build_search3_url = $db_cgi_url . "/searchnew.cgi"; # URL of search script.



4. in the searchnew.cgi below change the "/path_to_your_cgi-bin/cgi-bin/links/admin/links.cfg" as needed

5. You may need to change the load_template search_results.html section if you have changes.

6. Since I don't know much perl, I can't say if anything needs to be changed to make it better. it does seem to work.

7. I do know that the total hits do not show on the search results page. Maybe someone can suggest a fix...


Here is the searchnew.cgi


Code:
#!/usr/bin/perl
# -------------
# Links
# -------------
# Links Manager
#
# File: admin.cgi
# Description: This is the administrative interface for the links program.
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 2.01
#
# (c) 1998 Gossamer Threads Inc.
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================
#
# Required Libraries
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \

require 5.001; # Make sure we have at least perl 5.001.
require "/home/summervi/www/www/cgi-bin/links/admin/links.cfg";
# Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db.pl";
require "$db_lib_path/links.def";
require "$db_lib_path/db_utils.pl"; # Database Support utilities.
require "$db_lib_path/site_html_templates.pl" ;
}; if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n[/url]";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}



$font = 'font color="red" face="verdana,arial,helvetica" size="2"';
$font_title = 'font face="verdana,arial,helvetica" size="4"';




# ========================================================
eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.
# ========================================================



sub main {
# --------------------------------------------------------
$| = 1; # Flush Output Right Away



# Main Menu. Check to see what the user requested, then if he has permission for that
# request, do it. Otherwise send the user off to an unauthorized request page.
%in = &parse_form; # Get form input so we know which database to load.



# Load the database definition file and set the link url.
$in{'db'} ?
require "$db_lib_path/$in{'db'}.def" :
require "$db_lib_path/links.def";




# mod to change where links gets the cgi
# left unchanged, $db_script_url points to admin.cgi
# and you cannot access admin.cgi without a password
# $build_search2_url is defined in links.cfg and points to this file.
$db_script_url = $build_search2_url;



# The functions beginning with &html_ can be found in admin_html.pl, while the other
# functions can be found in db.pl

if ($in{'view_search'}) { &site_html_search_form; } # Display form to search database.
elsif ($in{'view_records'}) { &view_records; } # Search database and print results.
else { &html_home; } # Display Frame Index page.



# &cgierr("Done"); # Uncomment this line for Debugging...
#Will tack on form variables and environment variables
# to the end of every page. Quite Useful.
}



sub view_records {
# --------------------------------------------------------
# This is called when a user is searching the database for
# viewing. All the work is done in query() and the routines just
# checks to see if the search was successful or not and returns
# the user to the appropriate page.


my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_view_success(@hits);
}
else {
&html_view_failure($status);
}
}


# from the Links 2 site_html_templates.html file
# just renamed


sub html_home {

#sub site_html_search_form {
# --------------------------------------------------------
# This routine displays the search form.

&html_print_headers;

print &load_template ('searchnew.html', {
term => $term,
error => $error,
%in,
%globals
});
}


# from the Links 2 site_html_templates.html file
# and combined with the dbman templates file


sub html_view_success {

my @hits = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);

&html_print_headers();
if ($db_next_hits) {
$link_results .= "<br><$font>Pages: $db_next_hits</font>";
}

# Go through each hit and convert the array to hash and send to
# html_record for printing.
for (0 .. $numhits - 1) {
$link_results .= "<P>";
$link_results .= &site_html_link (&array_to_hash($_, @hits));
}
if ($db_next_hits) {
$link_results .= "<br><$font>Pages: $db_next_hits</font>";
}


#sub site_html_search_results {
# --------------------------------------------------------
# This routine displays the search results.
#
my $term = &urlencode ($in{'query'});
# &html_print_headers;
print &load_template ('search_results.html', {
term => $term,
link_results => $link_results,
category_results => $category_results,
next => $next,
cat_hits => $cat_hits,
link_hits => $link_hits,
%in,
%globals
});
#}


}


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Subject Author Views Date
Thread New Search Mod esm 5129 Feb 15, 2003, 5:33 PM
Post Re: [esm] New Search Mod
Andy 5062 Feb 16, 2003, 3:13 AM
Thread Re: [esm] New Search Mod
angelscharmedsla 4954 May 18, 2003, 2:56 AM
Thread Re: [angelscharmedsla] New Search Mod
esm 4923 May 18, 2003, 9:51 AM
Thread Re: [esm] New Search Mod
angelscharmedsla 4928 May 18, 2003, 10:03 AM
Thread Re: [angelscharmedsla] New Search Mod
esm 4920 May 18, 2003, 5:12 PM
Thread Re: [esm] New Search Mod
angelscharmedsla 4899 May 18, 2003, 10:39 PM
Thread Re: [angelscharmedsla] New Search Mod
DogTags 4887 May 19, 2003, 7:25 AM
Thread Re: [DogTags] New Search Mod
angelscharmedsla 4868 May 21, 2003, 2:59 AM
Thread Re: [angelscharmedsla] New Search Mod
DogTags 4851 May 23, 2003, 8:14 AM
Post Re: [DogTags] New Search Mod
boom 4738 Sep 5, 2003, 6:21 AM