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

Plugin help needed for Prev & Next quickjump plugin!

Quote Reply
Plugin help needed for Prev & Next quickjump plugin!
Sorry for posting this here, but the plugin category is not watched very often.
I started to write a plugin, which will be able to place previous & next links (anchors) for each link, so the user can easily jump forward & back. That's the background story.

The solution:
The list of links on the current page is needed, to get the prev & next link id. The only possible place, where we get raw link data from DB is Build.pm/sub build_category.
Therefore I have to use GT::Plugins->action ( STOP ); to ignore the original code of build_category, and run the copy of build_category built into my plugin.

So we have a build_category sub in the plugin file, which has almost the same some as the original build_category had (just corrected some sub call like 'build' to 'Links::Build::build' to find them).
Now I add the <%num%> to be $link key list, so <%num%> can be displayed:
Code:
my $nr=1; # added here
foreach my $link (@$results) {
$link->{'num'} = $nr++; # added here
$link->{Category_Template} = $category->{Category_Template}
if ($category->{Category_Template});
$display{links} .= Links::SiteHTML::display ('link', $link);
push @{$display{links_loop}}, $link;
}

Modification is highlighted in Red. Nothing else was modified.
Now the <%num%> tag should be available, when displaying a category page with page.cgi, but NO, it's not available (result: unknown tag: 'num').

I did a dump of $link using Data::Dumper.
It displayed the $link array of hashes list, 2 times:
- 1. time the 'num' key was displayed in the list, as we wanted,
- 2. time the 'num' key was NOT displayed.

This means, that the 2. step overwrites the values of $link, what we got in 1. step with the values of 2. The 2. step is not expected to be at all. I tested it, the 2. executed step is the original build_category code (which should NOT be executed, because we used the GT::Plugins->action ( STOP ); to ignore it).


I know this is a difficult problem (maybe a bug, but maybe I did something wrong), but I hope some professionals will understand it, and find a solution for this.

I wait answer mainly from Alex (he would know what I'm talking about), but any help or idea is appreciated, if somebody knows plugins.


Thanks in advance,

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] Plugin help needed for Prev & Next quickjump plugin! In reply to
isn't there a next/previous tag on the Detailed pages in the default template set?

couldn't you tap into that code?

I checked, and it spans pages properly. Isn't that what you are trying to do?


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Plugin help needed for Prev & Next quickjump plugin! In reply to
Alex told, there is, but how to use it on category page? (you find my related post in Plugins forum)

But I would like to solve the problem described in my previous post.
The problem is given, the question is what's the problem?

I could solve the problem on other way, but next time I need to replace the original code, I will face the same problem above...

Still waiting ideas, solutions.

Thanks,

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: [pugdog] Plugin help needed for Prev & Next quickjump plugin! In reply to
>isn't there a next/previous tag on the Detailed pages?
>I checked, and it spans pages properly.

Oh, by the way. Maybe you missed the info in my original post.
The prev-next links what I want, are links which scrolls the page to the next link (using up-down arrows). No page spanning, just scrolling to next link.
And all above, I want to do on the category.html template, for links.

But my problem is not how to solve it, I can do it in several different ways (at least I hope Wink).
The question is, what was the problem in the code replace in my plugin, when using GT::Plugins->action ( STOP );.
I suppose there is a bug in the Plugin management (if there is?).
But also possible, that I did something wrong. If I did, let me know.

I would like answer from Alex (or from the staff or from a veteran), why the replacing of Build.pm/sub build_category code is working so strangely in a plugin, when I use GT::Plugins->action ( STOP );.

Clearly, what is the problem:
- the replaced code in the plugin is executed, then the original code is executed again. Strange.

I hope, the explanation is better now.

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] Plugin help needed for Prev & Next quickjump plugin! In reply to
I'm still not clear, but here is the code snip from Build.pm

Code:
# Figure out the next/prev links.
my $catlnk_db = $DB->table ('Links', 'CatLinks');
$catlnk_db->select_options ("ORDER BY $CFG->{build_sort_order_category}") if ($CFG->{build_sort_order_category});
my $sth = $catlnk_db->select ( { CategoryID => $cat_id, isValidated => 'Yes' }, [ 'Links.ID' ] );
my ($next, $prev);
while (my ($id) = $sth->fetchrow_array) {
if ($id == $link->{ID}) {
($next) = $sth->fetchrow_array;
last;
}
else {
$prev = $id;
}
}
my ($next_url, $prev_url);
if ($next) {
$next_url = "$CFG->{build_detail_url}/$next$CFG->{build_extension}";;
}
if ($prev) {
$prev_url = "$CFG->{build_detail_url}/$prev$CFG->{build_extension}";;
}


The "trick" is in the join that is done:

Code:
my $catlnk_db = $DB->table ('Links', 'CatLinks');
$catlnk_db->select_options ("ORDER BY $CFG->{build_sort_order_category}") if $CFG->{build_sort_order_category});
my $sth = $catlnk_db->select ( { CategoryID => $cat_id, isValidated => 'Yes' }, ['Links.ID' ] );


Once that is done, then the program goes on:

Code:


my ($next, $prev);
while (my ($id) = $sth->fetchrow_array) {
if ($id == $link->{ID}) {
($next) = $sth->fetchrow_array;
last;
}
else {
$prev = $id;
}
}


It does a brute-force iteration through the returned results, and picks the links.

If you were going to do this on a per-category basis, for 25 links per page, you'd want maintain the values of "prev" and "next" from link to link, so that "next" becomes "prev" without further overhead.

Again, I'm not sure why you want this on the category page.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [webmaster33] Plugin help needed for Prev & Next quickjump plugin! In reply to
The plug-in code may have a bug, but it also has a lot of getting used to.

I have actually tried to avoid the plug-in hooks, because for major things, I can't always understand the logic of what is going on, and often I need to abort before the plugin will.

are you using dynamic pages (page.cgi) or are you using nph-build to test this?


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Plugin help needed for Prev & Next quickjump plugin! In reply to
I don't use detailed pages at all. Just category pages, where the links are displayed.
And yes, category pages are displayed dynamically, using page.cgi.

I use plugin hooks, one is hooked into "build_category" and should completely replace the original code.

Did you created a plugin on the way, that you use GT::Plugins->action ( STOP );?
This way you could ignore the original subroutine code, and you could use the improved version of the original code in your plugin.

I did that, and I had problems.
The result was different, what should be expected.

Waiting opinions.

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] Plugin help needed for Prev & Next quickjump plugin! In reply to
If you run your script using nph-build, rather than page.cgi, does it work?


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Plugin help needed for Prev & Next quickjump plugin! In reply to
I moved this thread, since it really belongs here, and is getting into the guts of plug-in development.

page.cgi calls handle_page as a hook, which has a very different structure than the create_category hook called by nph_build.

Alex will have to explan (or fix <G>) this difference, since I've traced it out a few times, and I really don't see what is going on.

Maybe, though, if your code runs properly from nph_build with static pages, but not from page.cgi there will be an answer there. If it runs wrong from both scripts, then the problem has to be in the plugin_dispatch code and it's handling of the STOP parameter.

But if that was true, other plugins would not work right, you would think.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Plugin help needed for Prev & Next quickjump plugin! In reply to
I'm glad to announce, that the plugin management works well. Hmm, sorry that I have doubt in it.

The problem was may fault. Seems I was careless and I missed a very important code part.

Let me show you, what was the problem. Maybe others will learn something from this: as you know, I hooked the sub build_category, and copied the original code to the plugin into sub build_category. But some code parts required changes, and I missed an important change.

The fault was the following unchanged code, what I forgot to change:
Code:
return Links::SiteHTML::display ('category', \%display);

The sub display in SiteHTML.pm calls the sub build_category in Build.pm, so it overwrites my previous tag values.
So instead this, we need call Links::SiteHTML::site_html_category to print the category page, using the tags in %display we pass to site_html_category.

So the correct code we return, should be:
Code:
return Links::SiteHTML::site_html_category (\%display);

Now this part of the plugin works correctly as I wanted.
The plugin is not finished, I'm still implementing new features into it.

Thanks to Pugdog for trying to help me.

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...