Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

filter adult results - possible?

(Page 1 of 2)
> >
Quote Reply
filter adult results - possible?
What I want is if someone searches for certain words, i.e. naked, sex or nude, then Links will bring up a different template to the normal search_error.html - for example a template saying:

"We don't have any adult content but try this..."

If they search for something normal which I don't have, then I want it to display the normal "No Results" found template.

Good idea isn't it?! But is it possible?

JeffB



Quote Reply
Re: filter adult results - possible? In reply to
It is possible....

Simply do the following:

1) Add the following array in your Links.pm module:

Code:

$LINKS{exclude_keywords} = ['naked','sex','otherwords'];


2) Then in the sub search routine in the search.cgi file, add the following codes:

Code:

my $adultfilter = $query;
foreach $adultfilter (@{$LINKS{exclude_keywords}}) {
if ($query =~ /$adultfilter/i) {
&site_html_search_failure ( { error => "We do not have an adult web sites in our directory.", %in, title_linked => $title_linked}, $dynamic) and exit;
}
}


Another thing you could do is add the "bad" words in the following hash in the Search.pm file:

Code:

my %STOPWORDS_EN


Good luck!

Regards,

Eliot Lee
Quote Reply
Re: filter adult results - possible? In reply to
Eliot,

Thanks for your help. Is there any way of modifying the code above so that it can load an entire template when a user searches for adult related content? i.e. rather than load of search_error.html it would load adultsearch_error.html?

JeffB

Quote Reply
Re: filter adult results - possible? In reply to
Sure...if you create a sub in HTML_Templates.pm, for example take the sub site_html_search_failure, copy and paste it, then change the portions in red to the names you want to use (adultsearch_error), with sub name you need to add to the @EXPORT line. In AnthroRules code above instead of calling &site_html_search_failure, call on the new sub you just added, something like this:

&adultsearch_error ( { error => "You can remove the error msg if you choose", %in, title_linked => $title_linked}, $dynamic) and exit;

Code:
sub adultsearch_error {
# --------------------------------------------------------
# This routine displays a failed search page with error in $error.
#
my ($tags, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
(ref $tags eq 'HASH') or croak "HTML_TEMPLATES: Argument '$tags' must be hash reference";

my $error = shift;
defined $dynamic and &load_user ($dynamic, $tags);
my $output = &load_template ('adultsearch_error.html', {
%$tags,
%GLOBALS
}, undef, $template);
defined $dynamic and &clean_output($dynamic, \$output);
print $output;
}
Then make the adultsearch_error.html and put it in your templates directory...
~rl
Quote Reply
Re: filter adult results - possible? In reply to
As the other user provided, yes, it is possible. BUT WHY????????? It will print the unique error message that you want...why create another template file?? I don't understand your logic AT ALL!

Regards,

Eliot Lee
Quote Reply
Re: filter adult results - possible? In reply to
Thanks for all your help - I will try it on Monday and let you know if it works.

Eliot - the logic is this:

I don't list any adult sites but if one of my users searches for certain "adult" related words then it will load a template that will contain links to web sites with adult content. I therefore need to display more than just the one line of text that your solution offered.

Hope this clears up the "logic" problems you were having :-)

Jeffb

Quote Reply
Re: filter adult results - possible? In reply to
Oh...okay...but there are other codes you could add that will only print an unique error message with links to adult sites in the search_error.html template file rather than creating another template file, which is a waste of codes and effort with maintaining, IMHO.

Regards,

Eliot Lee
Quote Reply
Re: filter adult results - possible? In reply to
I get errors using this code. I have tried inserting it in the sub search area of search.cgi. I put it here:

# Now let's search the links table, but first figure out any filters.

Where should it go? I have tried everywhere!

Jeffb

Quote Reply
Re: filter adult results - possible? In reply to
Sorry to be a pain, but I have been waiting several months for a reply to my last message and would really like to activate this on my site. Please help and soon!

JeffB

Quote Reply
Re: filter adult results - possible? In reply to
This should be fairly easy to do in the NG version using a pre_search hook.

Before acting on the search, you check the input term and see if it matches anything on the "bad words" list. If it does, you can redirect to a different page.

It could actually be expanded to allow different words to be sent to different templates..... hmmm.....

I may actually do this, since I am tired of screening out the nasty searches from our top-xx lists.



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: filter adult results - possible? In reply to
Pugdog,

I am glad that I have inspired you but I need a solution now to the problem above. Please could you take a look at AnthroRules code and tell me a) is there anything wrong with the syntax and b) where exactly in search.cgi should this bit of code go?!

Please help soon!

JeffB

PS - I have Links SQL1.11 at the moment - so need a solution for that.

Quote Reply
Re: filter adult results - possible? In reply to
Which part isn't working?

The Dec 2nd code looks like it will work, except the assignment

my $adultfilter = $query;

is pointless, since $adultfilter is the hash value in the foreach loop.

my $adultfilter =''; would be better, or use the my in the foreach loop itself.

You would need to insert the test into search.cgi near the top, once you have identified the $query parameter. No reason to do anything if it's going to fail on that count.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: filter adult results - possible? In reply to
The codes AS IS work fine for me.

Regards,

Eliot Lee
Quote Reply
Re: filter adult results - possible? In reply to
Gentlemen (AnthroRules & Pugdog):

This is a thread I will bookmark for a very long time. Thank you.

In a similar vein, what would you suggest to redirect to a template when a user attempts to submit a page that contains offensive material?

What if the description or URL they enter does not contain offensive text but the page does? Can Links SQL look at the page and check it before getting added to the waiting validation? or will I have to wait for the spider plug-in to perform such a task?

Conversely, is there a way to do the same for REQUIRED text?

Mark Brasche
http://SurfSafely.com/
Quote Reply
Re: filter adult results - possible? In reply to
Better wait for the improved spider plugin.

Regards,

Eliot Lee
Quote Reply
Re: filter adult results - possible? In reply to
I've started to think seriously about this... and the variations that would be necessary to provide adult content filtering on a site.

Superficially it would seem to require internal changes to links to make it work properly, I'm not sure putting a "hook" on each function call would be nearly as efficient as building in a test for ($CHECK_ADULT) && (plugin dispatch)

That way, on any I/0 type functions, the program would check to see if $CHECK_ADULT was enabled (like the $BAD_WORDS and $FOREIGN_CHAR flags).

This is another thing I think Alex should address directly. It's something he could fairly easily add to the release code, so that it functions in a similar way as Authenticate.pm.

Once these "family-safe" hooks are installed, 3rd parties could override them easily, and without a major performance hit.

I think it would be a valuable addition, and while it's possible to do via a plug-in, I think if the hooks were hard coded, it would work better.

The reason I feel this way, is that we all know what we mean by "family-safe" but we all have different specifics on what it is exactly.

I hate passing the buck, but there are really some things that need to be centrally addressed, and right now that central authority is Alex :)

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: filter adult results - possible? In reply to
If your code works fine then please include your sub search code in this thread, so I can see where about you've put it in and any mistakes I might have made.

Please help me out on this, I think that I've highlighted something that will be really good for Links NG and I would appreciate if someone could tell me exactly how to implement this in Links 1.11

Regards

JeffB

Quote Reply
Re: filter adult results - possible? In reply to
I have already provided the codes you need. I don't think it is necessary for me to post my complete sub search. Also following pugdog's advice in terms of the placement of the codes in the sub search should help you.

And BTW, these codes will ONLY work with Links 1.X. If you have upgraded to the NG version, guess what? The codes will NOT work!

Best of luck!

Regards,

Eliot Lee
Quote Reply
Re: filter adult results - possible? In reply to
Has anyone actually tested this mod using the exact script above and got it to work?

Eliot - why are you being so difficult about this?!

Please just tell me which line I should put this code under or above.

Give me a break - I'm under loads of pressure and need some support.

JeffB

Quote Reply
Re: filter adult results - possible? In reply to
I am NOT being difficult. I have already provided codes that work! In fact, they work too well. I had to remove some of the words in the filter array since they were blocking legitimate searches!

Again, the codes need to go after the line where my $query is located in the sub search.

Best of luck! I have really done all I can to assist. Giving the line number won't help you as I have modified the search.cgi script a lot and the line number where the above codes are located will do nothing for you since the line number will be different in your script.

Got it?

Regards,

Eliot Lee
Quote Reply
Re: filter adult results - possible? In reply to
Sorry for getting angry - it's the stress. At the moment, following your instructions I get this error when trying to search:

Software error:
Execution of /home/xxx/xxx/cgi-bin/search.pl aborted due to compilation errors.


I removed my URL for privacy reasons. Anyway here is my sub search with your modifications:

Code:
sub search {
# ---------------------------------------------------
# Performs the actual search.
#
my ($in, $dynamic) = @_;
my ($mh, $bool, $nh, $ww, $order, $query, $ignored, %seen, $next,
$catdb, $cat_hits, $category_results, $cat_count, $cat_errors, $linkdb, $link_hits, $link_results, $link_count, $link_errors);
my %in = %{&cgi_to_hash($in)};
my $links_count = '0';


my $adultfilter = $query;
foreach $adultfilter (@{$LINKS{exclude_keywords}}) {
if ($query =~ /$adultfilter/i) {
&site_html_search_failure ( { error => "We do not have an adult web sites in our directory.", %in, title_linked => $title_linked}, $dynamic) and exit;
}
}

# Get/Set the search options.
($in->param('mh') =~ /^(10|25|50|100)$/) ? ($mh = $1) : ($mh = 10);
($in->param('bool') =~ /^(and|or)$/i) ? ($bool = uc $1) : ($bool = 'AND');
($in->param('nh') =~ /^(\d+)$/) ? ($nh = $1) : ($nh = 1);
($in->param('substring')) ? ($ww = 0) : ($ww = 1);
($in->param('order') =~ /^(score|category)$/i) ? ($order = uc $1) : ($order = 'CATEGORY');
$links_count = $mh * ($nh - 1);

# Split up the search term.
$query = $in->param('query');
$query or &site_html_search_failure ( { error => "No search term entered.", %in }, $dynamic) and return;
$in{'term'} = $in->escape ($query);

# Search the category listings.
$catdb = new Links::DBSQL "$LINKS{admin_root_path}/defs/Category.def";
$cat_hits = $catdb->query ( { query => $query, mh => $mh, nh => $nh } );
$cat_count = $catdb->hits || 0;
$cat_errors = $catdb->query_errors;


What's going wrong!

Jeffb

Quote Reply
Re: filter adult results - possible? In reply to
>>> Execution of /home/xxx/xxx/cgi-bin/search.pl aborted due to compilation errors.

CHECK YOUR ERROR LOG!!

I hate to say this, but if you can't get to the error log, you are putting a lot of undue stress on yourself -- and us. Without the error log, debugging perl programs is close to impossible.

The next best thing would be to run perl -c script.name from the telnet prompt.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: filter adult results - possible? In reply to
You are putting the CODES in the WRONG PLACE! Again, pugdog already mentioned that the codes need to go after the line of codes that contains $query, which is the following line:

Code:

$query = $in->param('query');


And, yes, pugdog is absolutely correct...you need to request access to your Perl error logs, OR check the syntax with the command that pugdog provided!

Code:

perl -c search.cgi


Got it?

Regards,

Eliot Lee
Quote Reply
Re: filter adult results - possible? In reply to
Firstly I would like to thank you for your help. Secondly I would like to point out the code above doesn't work!! The log error reports this:


Global symbol "$title_linked" requires explicit package name at search.pl line 80.


If you remove $title_linked from Eliot's code then it works fine! - So now I am intrigued to know how Eliot claims that code works?!

JeffB

Quote Reply
Re: filter adult results - possible? In reply to
>>> If you remove $title_linked from Eliot's code then it works fine! -
>>> So now I am intrigued to know how Eliot claims that code works?!

Eliot has $title_linked defined in his code as

my $title_linked somewhere.

So, it _does_ work for him.

That is _WHY_ you check your error logs!!!



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


> >