Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

"Hidden" links plugin - need logic help...

Quote Reply
"Hidden" links plugin - need logic help...
Hi -

I'm wanting to create a plugin that will filter out certain links from search results (and builds) and am not sure where to start...

I've added a column in the Links table named "Hide"... I want to "hide" all links from searches and also in the directory listings, new, cool, top rated, etc. that have this column marked as 'Yes'. Basically, I want normal LinksSQL functions to completely ignore these links as if they did not exist.

I have a feeling that this should be extremely easy to do, however I'm not clear on what hooks to use, nor how to manipulate the input/output to essentially "strip" hidden links from search and build results...

For example, would I use the "search_results" hook? And, if so, do I completely hijack the search procedure or should I try to alter the values of results after the regular search is performed?

And for builds, I'm afraid I don't even know where to begin! Perhaps modifying output to the "site_html_[templatename]" hooks?

(Note: I'm using dynamic pages)

Or maybe I'm making this more complicated than it needs to be...?

In any case, if anyone can give me a few pointers, I'd be very grateful. Wink

Thanks,

Matt G
Quote Reply
Re: [Matt Glaspie] "Hidden" links plugin - need logic help... In reply to
Couldn't you simply use:

Quote:

<%ifnot Hide%>
LINK INFO
<%endif%>


in the link.html file, which would take care of the build and search results.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] "Hidden" links plugin - need logic help... In reply to
Hi Eliot,

I appreciate your reply. Thanks. Smile

Something like that would be the ideal solution (i.e. template-based), but there are a couple problems, the most important being that the result "totals" will not be altered.

For example, running a search that has 5 returned links, of which 2 are hidden, will report that your search returned 5 links (instead of 3). Plus, the search function defaults to displaying the link's category above each returned link, and enclosing the entire link.html template in the <%ifnot Hide%><%endif%> tags won't hide that...

Another "totals" problem is that the number of links in each category (as reported in subcategory.html) will also not be affected. So someone might click on a subcaegory expecting to see 3 links and only find 1. (I will probably not use this value anyway, but still...)

Now, maybe the "link_loop" functions might be an answer? I've not expirimented with that so I'm not clear on how it works. (But I still don't think it will address the totaling issues, however.)

Hmmm... on second thought, maybe a combination of a links_loop/link_results_loop plus a set of new "total" globals would do the trick?

Thanks again,

Matt G
Quote Reply
Re: [Matt Glaspie] "Hidden" links plugin - need logic help... In reply to
Hi,

What I would suggest doing is take advantadge of the fact that unvalidated links are already hidden. Add a column called Hide and make it Yes/No. Then make it whenever a link is changed to Hidden, it becomes unvalidated, and whenever it is changed to Visible, it becomes validated.

When you make a link unvalidated, it automatically removes it from search results, and from being displayed.

You will need to provide a PRE hook for 'modify_link' which is called whenever a link is modified. It takes as arguments a single hash ref of the changed link. You then need to lookup the Hide status in the database and if it has changed, you also need to adjust the Validated. So something like:

Code:
{
my $link = shift;
my ($old_status) = $DB->table('Links')->select(['Hide'], { ID => $link->{ID} )->fetchrow;
if ($old_status ne $link->{Hide}) {
# it's changed, but from what to what?
if ($old_status eq 'No') {
# we are hiding this link
$link->{isValidated} = 'No';
}
else {
# we are showing this link
$link->{isValidated} = 'Yes';
}
}
return $link;
}
It should be a PRE hook, and then the regular modify will do the update and change the validation status. You should also make sure Hide defaults to No.

You also want to override the validate screen so it doesn't display hidden links.

Let me know how it goes,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] "Hidden" links plugin - need logic help... In reply to
Hi Alex,

Thanks a lot. I really appreciate the help.

I had previously considered this option (using the built-in characteristics of non-validated links), but too quickly dismissed it as not feasible for my needs.

What I've done is added a fourth validation option - "decline and email reason" which, before this, I had set to simply validate the record, set Hide to 'Yes' and email a custom email "decline" template.

I didn't want to have scores of unvalidated records plaguing me every time I opened the validate screen. But your suggestion made me think through it more thoroughly and I realized that only one line of code in the Tools.pm file would need to be added to not show hidden links when validating. And since I'd already hacked this file a bit because of the above validation option addition, it was no big deal to do so.

(Can I take a second here to suggest adding some plugin hook support for more of the subs in this Tools.pm file? This is the only file I've had to hack so far and would prefer a totally hack-free, seamlessly upgradeable system... hopefully Tools.pm will not undergo too many modifications in future releases...) Smile

Anyway, I've gotten this plugin working wonderfully using the code you provided, hidden links do not display on the validate screen, and all is well. Wink

Thanks again!

--
Matt G
Quote Reply
Re: [Matt Glaspie] "Hidden" links plugin - need logic help... In reply to
Could someone please help me and let me know exactly where these changes need to be made. This kind of what I am looking for, as I want LinksSQL to not delete a link from the datbase if it is declined, that way, if someone has any questions, I can go back and look at the comments for the reason for the decline, but I don't want it to keep poping up in the validate links section.
Quote Reply
Re: [eclipse] "Hidden" links plugin - need logic help... In reply to
Actually, the message you replied to was a very, very old one.

I *think* until GT installs "flags" for links, and ties them into the search engine routines, the best way to do what you want to do (eg: deal with declined links) is to actually make a separate plugin, that takes the link OUT of the main database, and puts it into a separate table. The table would need a few extra fields, one would be the category name/number (just for convenience).

When a user logs in, they could get a list of their declined links, and reasons. If they fix it up, you'd be notified, and then if approved, the link would be moved to the regular database.

This is something I've thought about too. "private" categories are a whole separate issue, but dealing with unvalidated, pre-view, and such type links actually work *better* if there was a preview database. Granted, the more plugins you have, the more quickly this can fall apart, but until "flags" are supported, there is no really good way to deal with this in Links 2.1.2 or 2.2.0


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] "Hidden" links plugin - need logic help... In reply to
i need to do something pretty similar to those above.

I have created a new field called "disabled" and used an IF statement in my templates not to display links with disabled set to Yes.

However, the total links counter next to my categories will still count them. Obviously this causes confusion if the total says there are more links than there are, as some links are disabled.

Is there a quick and easy way around this. It seems like changing the validated status to No would be fine. Is it still possible to edit Tools.pm not to show for e.g. links that are disabled on the validation page?

I would be really grateful for any help.

Cheers.
Quote Reply
Re: [phuketkit] "Hidden" links plugin - need logic help... In reply to
Hi,

It seems that you need to create some hooks to exclude these links and deduct the total or links count for build and search process by adding the condition "disabled => 'No'". And the rest, GLinks will do for you but some case, you can not add that condition. If you hook into the site_html_[hookname], the work load is more to do. You have to reduce the total or links count, exclude links from 'links' or 'links_loop' and rebuild the next_span as well.

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] "Hidden" links plugin - need logic help... In reply to
Thanks, got it working now.