Gossamer Forum
Quote Reply
PRE Hook not working?
This us abboyiung me quite a bit. I am trying to setup a hook, to run &do_checks in my .pm file. The code I have is;

Code:
# ==================================================================
# Plugins::Recip_Link - Auto Generated Program Module
#
# Plugins::Recip_Link
# Author : Andy Newby
# Version : 1
# Updated : Mon Aug 19 11:30:50 2002
#
# ==================================================================
#

package Plugins::Recip_Link;
# ==================================================================

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

# Inherit from base class for debug and error methods
@Plugins::Recip_Link::ISA = qw(GT::Base);

# Your code begins here! Good Luck!


# PLUGIN HOOKS
# ===================================================================


sub do_checks {
# -------------------------------------------------------------------
# set the header...
print $IN->header();

# print this, just to see if it will work!
print "doing stuiff";


}

# ADMIN MENU OPTIONS
# ===================================================================

sub readme {
# -------------------------------------------------------------------
# This subroutine will get called whenever the user clicks
# on 'Readme' in the admin menu. Remember, you need to print
# your own content-type headers; you should use
#
# print $IN->header();
#

}

# Always end with a 1.
1;

I've just done a normal print there, in hope that it will print that out when the hook is called...

In Install.pm, I have this for setting up the hook;

Code:
$mgr->install_hooks ( 'Recip_Link', [ ['do_checks', 'PRE', 'Plugins::Recip_Link::do_checks', 'FIRST'] ]);

Anyone got any ideas why the PRE hook is not being called?

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] PRE Hook not working? In reply to
When should it be called?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] PRE Hook not working? In reply to
VERY good point. Its an add_link PRE...so in fact, it should be;

$mgr->install_hooks ( 'Recip_Link', [ ['add_link', 'PRE', 'Plugins::Recip_Link::do_checks', 'FIRST'] ]);

Shouldn't it?

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] PRE Hook not working? In reply to
Yes, something like that, though you should really check which hook you want, user_add_link might be more appropriate. Links/User/Add.pm will tell you what you want.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [Andy] PRE Hook not working? In reply to
I have a PRE hook not working...


Install.pm
Code:
package Plugins::ZipCodeSearch;
# ==================================================================
use strict;
use vars qw/$VERSION $DEBUG $NAME $META/;
use GT::Base;
use GT::Plugins qw/STOP CONTINUE/;
use Links qw/$CFG $IN $DB/;
use GT::Config;
use Links::Tools;

$VERSION = '1.1';
$DEBUG = 0;
$NAME = 'ZipCodeSearch';
# Inhert from base class for debug and error methods
@Plugins::ZipCodeSearch::ISA = qw(GT::Base);

...

sub install {
# -----------------------------------------------------------------------------
$mgr->install_hooks('ZipCodeSearch', [['site_html_link', 'PRE', 'Plugins::ZipCodeSearch::link', 'FIRST']]);
}

ZipCodeSearch.pm
Code:
package Plugins::ZipCodeSearch;
# ==================================================================

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

use GT::Config;
use Links::Tools;

# Inherit from base class for debug and error methods
@Plugins::ZipCodeSearch::ISA = qw(GT::Base);

# Your code begins here.

...

sub link {
# -----------------------------------------------------------------------------
# This subroutine will be called whenever the hook 'add_link' is run. You
# should call $PLG->action(STOP) if you don't want the regular
# 'add_link' code to run, otherwise the code will continue as normal.
#
my $args = $IN->get_hash;

my $zip = "53140";
my $zipdb = $DB->table('UNKNOWN') || return $GT::SQL::error;
my $rec = $zipdb->select ('*', { ZipCode => $zip })->fetchrow_hashref;

print "Hello is there anyone out there?";

$args->{'TestTag'} = "Goodbye";
$args->{'Longitude'} = "Goodbye";

# print $IN->header();
# print Links::SiteHTML::display ('link', $args);
# exit;
return $args;
}

plugins.cfg
Code:
'ZipCodeSearch' => {
'hooks' => [
[
'add_link',
'PRE',
'Plugins::ZipCodeSearch::add_link_hook',
'1'
],
[
'modify_link',
'PRE',
'Plugins::ZipCodeSearch::modify_link_hook',
'1'
],
[
'site_html_link',
'PRE',
'Plugins::ZipCodeSearch::link',
'1'
]
],

Nothing prints, No error on missing table...
The checkbox shows in Setup under hooks as: site_html_link (PRE) , and it is checked.

This hook is not being called!

What am I doing wrong?
I have spent a few hours trying to figure it out and I am stumped Unsure

I am simply trying to add a new tag so it is available whenever a link is displayed. i.e. <%Latitude%>

I bet once I get the hook to be called I could get it working <g>

Thanks,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] PRE Hook not working? In reply to
Hi,

You may need to add in a $IN->header() call in your link() routine;

Code:
sub link {
# -----------------------------------------------------------------------------
# This subroutine will be called whenever the hook 'add_link' is run. You
# should call $PLG->action(STOP) if you don't want the regular
# 'add_link' code to run, otherwise the code will continue as normal.
#
my $args = $IN->get_hash;

my $zip = "53140";
my $zipdb = $DB->table('UNKNOWN') || return $GT::SQL::error;
my $rec = $zipdb->select ('*', { ZipCode => $zip })->fetchrow_hashref;

print $IN->header();
print "Hello is there anyone out there?";

$args->{'TestTag'} = "Goodbye";
$args->{'Longitude'} = "Goodbye";

# print $IN->header();
# print Links::SiteHTML::display ('link', $args);
# exit;
return $args;
}

The reason you won't be seeing the "Hello is there anyone out there?" part, is because no header has been printed, thus its not being seen :)

If that still doesn't sort it, I'm not sure how you can sort it :/

Hope that helps!

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: [rgbworld] PRE Hook not working? In reply to
No print header would give a 500 server error.

Make sure you are actually running that code.

Put in a die ('I at least got here') statement,
or use an exit; right after the print to see what happens.
You might be getting there, but the statement is flashing off the screen.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] PRE Hook not working? In reply to
Still no luck. The hook is NOT being called.

I even tried changing the name of my function in the $mgr->install_hooks line to xyzabc without
without having a function named xyzabc, and still.... nothing. I expected an error for an undefined function.

I then really changed the name in install line and the name of the function, and I now have this:
Code:
$mgr->install_hooks('ZipCodeSearch', [['site_html_link', 'PRE', 'Plugins::ZipCodeSearch::my_site_html_hook', '']]);

and this
Code:
sub my_site_html_hook {
# -----------------------------------------------------------------------------
# This subroutine will be called whenever the hook 'add_link' is run. You
# should call $PLG->action(STOP) if you don't want the regular
# 'add_link' code to run, otherwise the code will continue as normal.
#
my (@args) = @_;

die "At least I got here";
exit;

return @args;
}

and to confirm, in plugin.cfg on server after install
Code:
'ZipCodeSearch' => {
'hooks' => [
[
'add_link',
'PRE',
'Plugins::ZipCodeSearch::add_link_hook',
'0'
],
[
'modify_link',
'PRE',
'Plugins::ZipCodeSearch::modify_link_hook',
'0'
],
[
'site_html_link',
'PRE',
'Plugins::ZipCodeSearch::my_site_html_hook',
'1'
]
],

I am out of ideas. I have 2 other hooks working add_link and modify_link.

Correct me if I am wrong, but I should be seeing the effect of the hook here right?:
http://www.supportmusicians.com/cgi-bin/links_dev/page.cgi?g=alternative%2Findex.html;t=luna;d=1


If someone wants login info or for me to send plugin, I will.

Thanks again,

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com

Last edited by:

rgbworld: Jun 19, 2006, 12:25 PM
Quote Reply
Re: [rgbworld] PRE Hook not working? In reply to
It's not being called because the site_html_link isn't used in 3.x. It's only there for compatibility - if you look at the code, there's a note about this.

Adrian
Quote Reply
Re: [brewt] PRE Hook not working? In reply to
  
In Reply To:
It's not being called because the site_html_link isn't used in 3.x. It's only there for compatibility - if you look at the code, there's a note about this.

But, if you look at the docs you find this (wrong once again).

Name: site_html_[template name]
PRE Input: HASH REF of template tags available.
POST Input: SCALAR: Fully formatted HTML page showing parsed template.
Triggered On: Any time output is displayed to the user, it's through a template.
Description: Any template can be overriden by using the hook site_html_template_name. So if you want to override the displaying of a link, you would do site_html_link.

Which kinfof pisses me off to be frank. I spent 6 hours digging through the docs.
I was relying on the documentation above. What's the point of wrong documentation.

Code:
sub site_html_link {
# --------------------------------------------------------
# Format and return the HTML for a single link.
#
# Note that this method is deprecated in favour of generating all the html in
# the templates. Instead, you should be doing:
# <%Links::Utils::load_link_info%><%include link.html%>
#
...
It is not depreciated in favor of..., it is obsolete in 3.x

FYI, I had first done just what is said above and it worked fine.
Then after reading the docs and realizing that there was a hook available (NOT),
I decided I would just put in as a hook. That was a day ago now. What a waste of time.

<%Plugins::ZipCodeSearch::GetLocationTags($Zip)%>

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com

Last edited by:

rgbworld: Jun 19, 2006, 1:33 PM