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

Advice on adding functionality

Quote Reply
Advice on adding functionality
I want to add a "Report this post to moderator" functionality to the forum.

I'm putting the link at the bottom of each displayed post and have got the prototype running (I think). I did the edits in 'include_post_display.html'. Is this the best file to do that in?

Now, I want this link to spawn an email message to the forum moderator. The message will contain a link to the post in guestion. I suppose the global that I use for the post will be 'post_id'. And I further suppose that there is a global for the forum moderator, but I can't find it. I further suppose that I'll have to create a 'report_post.eml' template.

Anyone have any further suggestions before I blow myself out of the water?

Ishmael
Quote Reply
Re: [Ishmael] Advice on adding functionality In reply to
Ok. I have the link embedded in the template and at least the display portion is working. The link will embed the "post_id".

I still need info concerning the email side of this. I want to send the email to admin. (I know the variable for that, so no problem there.) but I can't identify any variable associated with "moderators" and the moderators of that particular forum that can be passed so as to make sure the email is sent to those that can take action on it.

There is also the issue of the email template itself. I'm assuming I can take an existing template, modify it, then use "save as" to create a new template. Is this true?

Ishmael
Quote Reply
Re: [Ishmael] Advice on adding functionality In reply to
You can get a list of moderators by calling:

<%GForum::Forum::moderators($forum_id)%>

You'll then get a template variable 'forum_num_moderators', which contains the number of moderators for the forum, and forum_moderators, which is a template loop variable that you can loop through to do things with the moderators.

However, since your case is a little more specific, you might want to call the function from a template global. The following isn't guaranteed to work, but should be a good place to start from:

(removed - see updated code in later reply)


Now in a template when the user has requested a moderator be notified, you want to add:

<%name_of_global($forum_id, $current_user_username, $post_id)%>

That should send an e-mail to each moderator, notifying them of the post.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com

Last edited by:

Jagerman: Mar 25, 2004, 10:22 AM
Quote Reply
Re: [Jagerman] Advice on adding functionality In reply to
Jason,

Thank you very much. That should get me started. As I said, I'm new to Perl and Gossamer so you can probably expect some pretty silly questions from me. But I manage to muddle along mostly.

If I get tripped up I'll be getting back to you.

Once again, Thank You.

Ishmael
Quote Reply
Re: [Ishmael] Advice on adding functionality In reply to
Perhaps you could do something like the following to make it all work.

Change the template global I posted, adding:

Code:
if ($IN->param('report_post')) {

at the beginning, just after the 'sub {' line, and:

Code:
}
else { return {} }

at the end, just before the final '}'. Then, in the template, you can do:

Code:
<%if current_user_id%>
<%alert_moderator($forum_id, $current_user_username, $post_id)%>
<%if moderator_notified%>
A moderator has been notified of this post. Thank you.
<%else%>
<a href="gforum.cgi?post=<%post_id%>;report_post=1;<%hidden_query%>#<%post_id%>">Report this post to a moderator</a>
<%endif%>
<%endif%>

(Change alert_moderator to whatever you named the global)

Now, when a user clicks the link, you should be taken back to the post again, but instead of the link you should see the thank-you message.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] Advice on adding functionality In reply to
hello

I get this error

Unable to compile 'alert_moderator': Missing right curly or square bracket at (eval 43) line 2, at end of line syntax error at (eval 43) line 2, at EOF

Why?
linktobuy Web Directory
Ratgeber Recht
Quote Reply
Re: [hoefti] Advice on adding functionality In reply to
Here's updated code that fixed a couple problems, and should work properly:

Code:
sub {
if ($IN->param('report_post')) {
my ($forum_id, $reporter, $post_id) = @_;
require GForum::Forum;
my $forum = GForum::Forum::get($forum_id);
my $moderators = GForum::Forum->moderators($forum_id)->{forum_moderators};
my @emails = map $_->{user_email}, @$moderators;

# Now @emails contains the e-mail addresses of the forum\'s moderators, if any.

if (!@emails) { # comment out this "if" if you always want the admin to get an e-mail
push @emails, $CFG->{admin_email}; # If no moderators, use the admin e-mail
}

require GT::Mail;
my $reporter_escaped = $IN->escape($reporter);
for (@emails) {
my $mailer = GT::Mail->new(
To => join(', ', @emails),
From => "Moderator Notification <$CFG->{admin_email}>",
Subject => "$forum->{cat_full_name}: $forum->{forum_name} moderator notification",
msg => qq|
$reporter has requested that a moderator be notified regarding about a post in
the $forum->{cat_full_name}: $forum->{forum_name} forum.

The post is located here:
$CFG->{cgi_root_url}/gforum.cgi?post=$post_id#$post_id

User details:
$CFG->{cgi_root_url}/gforum.cgi?username=$reporter_escaped
Forum:
$CFG->{cgi_root_url}/gforum.cgi?forum=$forum_id
|,
($CFG->{smtp_server} ? (smtp => $CFG->{smtp_server}) : (sendmail => $CFG->{mail_path}))
)->send;
}
return { moderator_notified => 1 };
}
else {
return {}
}
}

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com

Last edited by:

Jagerman: Mar 25, 2004, 10:19 AM
Quote Reply
Re: [Jagerman] Advice on adding functionality In reply to
Many thanks to Jagerman for helping me (and carrying most of the weight) through this excesize.

The code works as advertised and the implementation in the forum is up to me as far as presentation goes.

Anyone that has forum "rules" and enforces them shoud consider implementing this feature. While having moderators and the diligence of admin can't be replaced, having your users help you with the "trolls" that invariably show up in any public forum helps make everyones job a little easier and the dedicated forum users experience a little more pleasurable.

Thanks Jagerman.

Ishmael
Quote Reply
Re: [Ishmael] Advice on adding functionality In reply to
Well, as they say "No good deed goes unpunished."

I allow guests to "read" in my forum, but not post. Registration is required for posting. But I have guests coming in and trying out the new "report" feature.

I'd like to add a line to the global, or the link, that would basically take "guests" that like to push buttons to a page that kinda explains the rules.

I know it's a simple "if" statement, but I don't know what the internal flag or name to identify a "guest".

Any help would be appreciated.

Ishmael
Quote Reply
Re: [Ishmael] Advice on adding functionality In reply to
Would something like this work in the global?

Right after the:

if ($IN->param('report_post')) {

insert something like this:

if ((my $group_id = $user->{user_status} == ANONYMOUS) or
(my $group_id = $user->{user_status} == NOT_VALIDATED))
{
# insert a link to encourage registration or just a return() here.
}


Thanks,
Ishmael
Quote Reply
Re: [Jagerman] Advice on adding functionality In reply to
Jason,

Quote:
You can get a list of moderators by calling:

<%GForum::Forum::moderators($forum_id)%>

Is there a easy way to get a list of users who have access to a forum? If for example I've set up a forum that can only be accessed by users in a specific group (or 2 groups), how can I display a list of everyone in those group(s)?

Safe swoops
Sangiro
Quote Reply
Re: [Ishmael] Advice on adding functionality In reply to
In Reply To:
Well, as they say "No good deed goes unpunished."

I allow guests to "read" in my forum, but not post. Registration is required for posting. But I have guests coming in and trying out the new "report" feature.

I'd like to add a line to the global, or the link, that would basically take "guests" that like to push buttons to a page that kinda explains the rules.

I know it's a simple "if" statement, but I don't know what the internal flag or name to identify a "guest".

Any help would be appreciated.

Ishmael

Maybe try something like:

<%if current_user_id%>
...
<%endif%>

around the entire area where the global is called and confirmation message displayed.

If you still want to display something there for guests, you could change it to:

<%if current_user_id%>
... - notify a moderator and confirmation in here - ...
<%else%>
Message you want guests to see
<%endif%>

You can fairly easily add a new template, then add an Action (Setup -> Actions) that specifies that template as the page to display. You can then add a link to:

<a href="gforum.cgi?do=new_action_name;<%hidden_query%>">

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [sangiro] Advice on adding functionality In reply to
In Reply To:
Jason,

Quote:
You can get a list of moderators by calling:

<%GForum::Forum::moderators($forum_id)%>

Is there a easy way to get a list of users who have access to a forum? If for example I've set up a forum that can only be accessed by users in a specific group (or 2 groups), how can I display a list of everyone in those group(s)?

You'd need a global for that - try this:

Code:
sub {
my $forum_id = shift or return;
my $rel = $DB->table(qw/User UserGroup Grouping ForumGroup/);
$rel->select_options("GROUP BY user_username");
my $sth = $rel->select({ forum_id_fk => $forum_id });
my $users = $sth->fetchall_hashref;
require GForum::User;
GForum::User::normalize($users);
return { allowed_users => $users }
}
After calling it as <%global_name($forum_id)%>, you'll have an 'allowed_users' template loop - something like this could be used to list all users:

Code:
<%loop allowed_users%>
<a href="gforum.cgi?username=<%escape user_username%>;<%hidden_query%>"><%user_username%></a><%unless last%>,<%endunless%>
<%endloop%>

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] Advice on adding functionality In reply to
Hello Jagerman

It works, but i want to make possible that Users can write a Message why they report this post.
And in like this report in an private Message

can you plese help me.

greeting hoefti
linktobuy Web Directory
Ratgeber Recht

Last edited by:

hoefti: May 1, 2004, 7:33 PM
Quote Reply
Re: [Ishmael] Advice on adding functionality In reply to
Ishmael, nice idea and I think I can see how the code from Jagerman works, but how did you modify your template to call Jagerman's global (I'm very new to GT) ?
Quote Reply
Re: [davidnavigator] Advice on adding functionality In reply to
In Reply To:
Ishmael, nice idea and I think I can see how the code from Jagerman works, but how did you modify your template to call Jagerman's global (I'm very new to GT) ?


Can anybody help me on this ?
How do I modify the template to use the global ?