Gossamer Forum
Quote Reply
Hooks not working"
I'm working on the Ace_Category plugin...which will allow users to submit a category before adding their link. The problem I am having, is that the hook doesn't appear to be working!

This is the code I have in Install.pm regarding to the hooks;

$mgr->install_hooks ( 'Ace_Category', [ ['add_link', 'PRE', 'Plugins::Ace_Category::add_link', 'FIRST'] ]);
$mgr->install_hooks ( 'Ace_Category', [ ['add_link', 'PRE', 'Plugins::Ace_Category::add_link2', 'LAST'] ]);

ANd the sub relating to it, in Ace_Category.pm, is;

Code:
sub add_link {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'add_link'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#

print $IN->header();
print "test";
exit;

my (@args) = @_;

my $table = $DB->table('Category');
my $sth = $table->select;
my $opts;

# grab all the money, and add it up...
while (my $hit = $sth->fetchrow_hashref) {

$opts .= "<option value=\"$hit->{ID}\">$hit->{Full_Name}</option>"

}

my $category = qq|
<select size="1" name="new_category_sub">
$opts
</select>
|;

print $IN->header();
print Links::SiteHTML::display('pre_add_link', { category_list => $category });
exit;

return @args;
}

Can anyone see anything that may cause the hook not to be called? After installing it, and running add.cgi, all I get is the normal adding page! Crazy

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: [Andy] Hooks not working" In reply to
Why not check the hook name in admin/Links/User.pm Wink

user_add_link

...or even easier, in hooks.cfg line 2032 Smile
Quote Reply
Re: [Paul] Hooks not working" In reply to
Eugh..how stupid of me! I made exactly the same mistake a couple of months ago....so much for learning from your mistakes Tongue

Thanks Paul.

EDIT: Still doesn't seem to be working..even WITH user_add_link Unsure

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!

Last edited by:

Andy: Oct 9, 2002, 7:39 AM
Quote Reply
Re: [Andy] Hooks not working" In reply to
What is not working? The installation for install.pm?
Which plugin is not executed? add_link or add_link2? What is in add_link2 code?
What would you expect?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Hooks not working" In reply to
This is what I have in the plugin so far (attached)

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: [Andy] Hooks not working" In reply to
user_add_link only runs when you hit the submit button. If you are expecting the page to load before the add form then you need to use handle_add
Quote Reply
Re: [Paul] Hooks not working" In reply to
Ah..is there actually any reasonable documentation on the hooks? All I can see at the moment is the [help] link next to the hook, when you are adding it. All it does is tell you if the var retured is a SCALAR, where its called etc. A little more info (and demos) would be much better 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: [Andy] Hooks not working" In reply to
Go through the Links SQ: code, see what the code does, where the hooks are, what arguments they take and what they have to return.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Hooks not working" In reply to
Still would be nice to have some decent documentation on it though Laugh

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: [Andy] Hooks not working" In reply to
What else do you need?

You know how to use hooks, hooks.cfg gives you all the names, files, input, output.....what else is there to say?
Quote Reply
Re: [Paul] Hooks not working" In reply to
Suppose so, but it would still be nice to see something in the manual.

I'm juist playing with GT::Plugins->acction ( CONTINUE ) feature. This is the first time I've had to use it, so please forgive my stupidness if its something simple Tongue

I have;

if ($IN->param('action') eq "check") { GT::Plugins->action ( CONTINUE ); exit; }

And at the top of the script;

Code:
use strict;
use GT::Base;
use GT::Plugins qw/STOP CONTINUE/;
use Links::SiteHTML;
use Links qw/$CFG $IN $DB/;

I KNOW 'action' is being defined as 'check' because, just before the call I used;

Code:
print $IN->param('action');

and it returned;

Quote:
check

Any help is much appreciated Smile

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: [Andy] Hooks not working" In reply to
Well if you are continuing you don't want an exit; in there Wink
Quote Reply
Re: [Paul] Hooks not working" In reply to
Well, I'm using this now;

# see if we wanna skip this sub, and goto the next one...
if ($IN->param('action') eq "check") { GT::Plugins->action ( CONTINUE ); }

But, it still ain't carrying on with the main code Wink

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: [Andy] Hooks not working" In reply to
That does basically do nothing, because CONTINUE is set by default, i.e. if you don't set action to STOP, it will be set to continue.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Hooks not working" In reply to
Ooook...so how would i get it to do this then;

sub name {

get vars

see if variable matches, if so, carry on with the normal adding procedure...

if not, then do this...

}

I'm a little confused as to how I would get around this Unsure

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: [Andy] Hooks not working" In reply to
Code:
sub {
my $input = shift;
return $input unless $input->{foo} eq 'bar';

....
}
I am assuming that you get a hashref as an argument, if not you have to change the code a bit, but it might give you the general idea.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Hooks not working" In reply to
Ok, I have a way around that.....bit messier, as it uses several nested 'if's. Got a slight problem though...is there a way to add a new category from a built in LSQL function, or do I need to manually submit it via a seperate insert command? I was hoping for the former 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: [Andy] Hooks not working" In reply to
So far I have found this in Category.pm;

Code:
my $self = shift;
my $p = (ref $_[0] eq 'HASH') ? shift : {@_};

GT::Plugins->dispatch ( $CFG->{admin_root_path} . '/Plugins', 'add_category', sub { return $self->_plg_add (@_); }, $p );

However, I can't find add_category in Plugin.pm.

Can someone point me in the right direction of the actual category adding code?

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: [Andy] Hooks not working" In reply to
add_category is the name of the hook.

The actual category adding code is in Category.pm, in _plg_add()

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Hooks not working" In reply to
Thanks, I got to the point of being very annoyed with it...so I just hard coded a 'INSERT'...

Thanks :)

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: [yogi] Hooks not working" In reply to
Ok, I've come back to this now. I'm still trying to figure out how you would go about passing the variables to this sub (sub _plg_add) Unsure

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!