Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Automatic Link to Subscribe to a forum

Quote Reply
Automatic Link to Subscribe to a forum
Hi:

Been thinking it would be nice to add a link that would automatically subscribe a user to the forum they are in. Specifically, we have a "News" forum that I think would get a LOT of subscribers, if I could easily make it subscribable (I have a feeling a lot of users are unaware of subscriptions!)

Anyway, I looked into the code on the user subscriptions page, and I came up with this link:

<A HREF="
http://forum.bcdb.com/gforum.cgi?subscribe=18&do=user_profile_email_change&next_do=user_profile">Subscribe</A> to <B>BCDB News</B>

Obviously, "18" is the forum number of my "News" forum. And the above link works fine (though I think it works better if you use an "if" statement to only show it to users)

The problem is that if a user is subscribed to any other forums, it erases those subscriptions, and the user is ONLY subscribed to 18.

Any ideas how to modify thie above link so it ADDS the subscription to 18 rather than changes all subscriptions to JUST 18?

Thanks!

PS: f I get this working, I will probably add a dynamic "Subscribe to this forum" to all forums- probably a nice option for many of us!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Automatic Link to Subscribe to a forum In reply to
There are a couple ways to do this. The simplest way would be to create a global that gives you a list of the current subscribed forums, then simply pass all of them, as well as the new one.

global:
Code:
sub {
my $current = shift;
my @subscribed = $DB->table('ForumSubscriber')->select(
forum_id_fk => {
user_id_fk => $USER->{user_id}
}
)->fetchall_list;
my %ret;
for (@subscribed) {
if ($_ == $current) { $ret{subscribed} = 1 }
else { push @{$ret{subscribed_to}}, $_ }
}
\%ret;
}
The code above grabs all the subscribed forum ids and returns them, but if the forum_id you pass in is found, it returns a "subscribed" variable if it was found and DOESN'T return that ID in the list (allowing you to unsubscribe by simply not adding the ID).

So, in a template, you'd do something like:

Code:
<%global($forum_id)%>

<a href=".........gforum.cgi?<%loop subscribed_to
%>subscribe=<%loop_value%>;<%endloop
%><%unless subscribed%>subscribe=<%forum_id%>;<%endunless
%>do=user_pro......"><%if subscribed
%>Unsubscribe<%else
%>Subscribe<%endif%></a>

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] Automatic Link to Subscribe to a forum In reply to
J-Man:

Thank you- so I guess I could not do this from my Links site, too (that is, add a "Subscribe to BCDB News")- just from Forum. Well, that is better than nothing- thank you!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Automatic Link to Subscribe to a forum In reply to
There is another option, using a plugin - basically you'd add a new plugin hook on do_add_subscription, then you'd make code that essentially duplicates the code in 'sub profile_email' GForum/User.pm, except that you'd remove the line that deletes (about 5 or 6 lines from the bottom). Then you'd just pass the URL you were using originally, but pass do=add_subscription instead of do=user_profile_email_change.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] Automatic Link to Subscribe to a forum In reply to
I did the second option- works like a charm!
dave

Big Cartoon DataBase
Big Comic Book DataBase