Gossamer Forum
Home : Products : Gossamer Links : Discussions :

question regarding hooks

Quote Reply
question regarding hooks
Hi,

I read this following information, which was provided by Alex:

-------
PRE hooks

They get passed in a single hash reference of all the template tags that would appear on that template. So for site_html_add_success template you would get a hash ref of the entire link that was just added. The plugin can alter that hash ref to add tags, or change values. So if your plugin wanted to add the word 'foo' to the Title when displaying a link that was just added, you would do:

sub add_foo {
my $link = shift;
$link->{Title} = $link->{Title} . 'foo';
return $link;
}

-------

How could I see to it that the 'foo' would also be added to their title so when I need to validate it, it would be in the format of "Titlefoo".

This would be a add_link POST hook, correct?
What would my subroutine look like to add the foo to their title so that it appears with the foo in the Validate table?

Thanks.



Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: question regarding hooks In reply to
I'm sooo confused! ??

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


Quote Reply
Re: question regarding hooks In reply to
Sorry. Let me try to clear this up. :)

The PRE hook example above, by Alex, is very simple.
It adds the word 'foo' to the end of the title that is submited via add.cgi. Because this hook is site_html_add_success, the foo is added to the title AFTER the link had been placed in the Validate table.

So for example, if I said my title was "test".
The form is submited, my record is added to the Validate table, and THEN the site_html_add_success PRE hook takes over by adding the "foo" is to the end of title.

On the add success page, the user sees that there link is awaiting validation, but their title is now "testfoo".

When I literally click "Validate Links" in the administration menu, the title of the link which was just added is still only "test", sense the foo was added AFTER the fact.

Now back to my question, how would I make sure that the "foo" is added to the end of the title BEFORE their record is placed into the Validate table? This way, when I validate their link, their title is shown to me as "testfoo" instead of only "test".

This would be the add_link POST hook, correct?
What variable is the title carried in here?

Is it $IN->param(Title)

I hope this makes my question a little clearer. Smile

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: question regarding hooks In reply to
Hi,

If you used the site_html_add_success hook and added Foo to the title, then it would only appear in the html, the actual data would not have been changed (as the link has already been stored in the database, and you are just changing what is displayed).

If you want to add foo to the title before it is submitted to the database, you would use a different hook: 'user_add_link'. You still want a PRE hook, as then you could modify the title before the link gets submitted to the database.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: question regarding hooks In reply to
Hi,

That's what I needed to know. Smile
What variable do I use to access the Title?
$IN->param(Title)?

Thanks again.

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: question regarding hooks In reply to
If you pass the Title in via the form, it will be in $IN->param(Title)

If you add it to the $input hash, or passed paramters hash, the it will be whatever value you assign it... $input->{Title} if you want it to match the database field, or $input->{Title_foo} if you want to be able to keep both versions around. In that case $input->{Title_foo} is assinged

$input->{Title_foo} = $input->{Title} . $foo

I'm still really lost on what you are trying to do.

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


Quote Reply
Re: question regarding hooks In reply to
There's nothing in particular that I'm trying to do.
I'm just trying to learn more about the plugin system and how it works. Smile

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: question regarding hooks In reply to
The add_link function in add.cgi takes the information from $IN, so your pre hook just needs to change it:

my $original = $IN->param('Title');
$IN->param('Title', "foo$original");

Then when add_link got to inserting the link it would think the user put foo$original as their title.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: question regarding hooks In reply to
Worked like a charm. Smile
Thanks Alex.

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com