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."
Quote Reply
Re: [esm] New Search Mod In reply to
Nice idea. Thanks for the contribution Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [esm] New Search Mod In reply to
Hi Gene,

Where can we see this mod in action?

regards,

Ilse
Quote Reply
Re: [angelscharmedsla] New Search Mod In reply to
It looks just like the admin version...!


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] New Search Mod In reply to
In Reply To:
It looks just like the admin version...!


Do you mean the Advanced Search Form which is reachable from your mainpage, or the searchform I get when I type in searchnew.cgi at the end?

From the mainpage I get the normal Advanced Search Form.

Regards,

Ilse
Quote Reply
Re: [angelscharmedsla] New Search Mod In reply to
go to the admin control center ( the same place where you "validate" your links ). It is also called the Links Administration Menu. Just click on view, modify or delete. It will look just like that. Like I said, I just took the source form the view page and changed the action

<form action="<%db_cgi_url%>/searchnew.cgi[/url]" method="GET">

I recall getting the "no records found" early on when working on this.

Also, I had a problem with including a category in the search - it would return a no records found. I found that if I changed the field name for category to say categorya and saved a second version of my links.def file with a differnent name like linksa.def and uploaded that to the admin folder and changed the required statement in the searchnew.cgi file, that I could avoid the problem. But I have worked on it some since then, I think the category problem has returned.

Let me expand upon that.
  1. open links.def
  2. rename the category field to categorya
  3. save the file as linksa.def
  4. upload the file to the admin folder
  5. open the searchnew.cgi file
  6. change the require links.def to linksa.def
    require "$db_lib_path/linksa.def";
  7. upload searchnew.cgi


I have attached a current version of the searchnew.cgi.

It may still have the category problem as above. But maybe I can work in it this week.

and don't forget the $build_search2_url in links.cfg.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."

Last edited by:

esm: May 18, 2003, 5:56 PM
Quote Reply
Re: [esm] New Search Mod In reply to
Hi,

Thanks for adding the actual file. I'll try to get it working tonight. Hopefully I'll get it working with your file.

I will let ya know.


regards,

Ilse
Quote Reply
Re: [angelscharmedsla] New Search Mod In reply to
Any luck with this?

Thanks Smile

------------------------------------------
Quote Reply
Re: [DogTags] New Search Mod In reply to
In Reply To:
Any luck with this?

Thanks Smile




Unfortunately I haven't had the time to work on this the last few days. I will work on it again in the next weekend. I'll keep you posted.



Regards,

Ilse
Quote Reply
Re: [angelscharmedsla] New Search Mod In reply to
Thanks Smile

------------------------------------------
Quote Reply
Re: [DogTags] New Search Mod In reply to
How easy would it be to use this excellent search mod WITH the ability to have range searches added on too? That would be amazing.....