Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: sedrik05 - syyskuu 30, 2013, 05:05:43 AP

Otsikko: Hiding Reported Posts
Kirjoitti: sedrik05 - syyskuu 30, 2013, 05:05:43 AP
I want to hide a reported posts, then it will be sent to the reported posts. I will check if the content is really abusive or what, then if it's really an abusive post, i will delete it, but if it's not abusive, i will make it visible again on the topic. Our panel wants that in our forum, because it's a school forum. Thanks In Advance! God bless! :)
Otsikko: Re: Hiding Reported Posts
Kirjoitti: margarett - syyskuu 30, 2013, 05:10:59 AP
I'm afraid that's not that easy...

The problem is that a reported post is not signalled in the "messages" table as reported. There's just an email sent to moderators and, if the moderation log is active, it is added to that list/log...
So there is probably nothing you can use to hide such post...

edit: not true, what I've said here...
Otsikko: Re: Hiding Reported Posts
Kirjoitti: sedrik05 - syyskuu 30, 2013, 05:25:02 AP
how can i filter the displayed posts? what source file i need to edit? i added 'reported' field on the messages table. I want to do if 'reported' column == 0 then it will be posted, but if it's 1 then it will not be posted. Thanks! :)
Otsikko: Re: Hiding Reported Posts
Kirjoitti: margarett - syyskuu 30, 2013, 06:15:41 AP
Let me investigate a bit further. It might be easier than I thought
Otsikko: Re: Hiding Reported Posts
Kirjoitti: margarett - syyskuu 30, 2013, 06:29:59 AP
OK, so further investigation here.

Sorry, I wasn't being correct here...
All the reported posts are added to the table "smf_log_reported" (not sure if you need to activate something for this, my test board is now an official mess, I have to start over...)
In this action here index.php?action=moderate;area=reports you can see the actual reports. And you also have an option to close or delete them.
This should provide you enough "filters" to not show such post.

The most complicated part I see here is: what if someone reports a post that happens to be the first of a topic?
- if the topic has no replies, you should hide the topic
- if the topic has replies, you cannot show the topic without its first message. So, you need to hide ALL posts related to that topic...

This has some further implications: the topics/posts counters should be properly updated if a certain post/topic is not to be shown, the number of topics in MessageIndex or the number of replies in Display should also be updated...

I see this as a quite interesting MOD in the making ;)
Otsikko: Re: Hiding Reported Posts
Kirjoitti: sedrik05 - syyskuu 30, 2013, 06:35:51 AP
Now, i can update the column 'reported'. And my Post Moderation Feature is enabled (I will not disable it). I just want to know what file to edit, to filter the posts that will display. Thanks! :)
Otsikko: Re: Hiding Reported Posts
Kirjoitti: margarett - syyskuu 30, 2013, 06:44:21 AP
Actually, you don't need that new field. You can do everything from standard SMF tables.

The tricky part is that "topics first message"... Because you cannot show a topic without it's first message :P

Anyway, if you forget that "detail", Sources/Display.php shoud be your starting point...
Otsikko: Re: Hiding Reported Posts
Kirjoitti: sedrik05 - syyskuu 30, 2013, 06:48:40 AP
Then how can i hide the 'Report to moderator' link on the first post? :D
Otsikko: Re: Hiding Reported Posts
Kirjoitti: margarett - syyskuu 30, 2013, 07:15:42 AP
That would be Display.template.php
Find:

// Maybe they want to report this post to the moderator(s)?
if ($context['can_report_moderator'])

Replace with:

// Maybe they want to report this post to the moderator(s)?
if (($context['can_report_moderator']) && ($message['id'] != $context['first_message']))
Otsikko: Re: Hiding Reported Posts
Kirjoitti: sedrik05 - syyskuu 30, 2013, 07:19:32 AP
I can't hide the posts that have reported = 1 in the database. i tried to edit the Display.php, but the posts that should be hidden is still displaying. :(
Otsikko: Re: Hiding Reported Posts
Kirjoitti: margarett - syyskuu 30, 2013, 07:23:43 AP
That seriously depends on how you're doing it.
You probably have an "undefined index" error in your error log. You need to fetch that column when the message is loaded. Are you doing it?
Otsikko: Re: Hiding Reported Posts
Kirjoitti: sedrik05 - syyskuu 30, 2013, 07:31:49 AP
Sorry for asking many questions. I really don't know what file should i edit, and what part of the file.

I'm doing this:

// Get each post and poster in this topic.
$request = $smcFunc['db_query']('display_get_post_poster', '
SELECT id_msg, id_member, approved, reported
FROM {db_prefix}messages
WHERE id_topic = {int:current_topic}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : (!empty($modSettings['db_mysql_group_by_fix']) ? '' : '
GROUP BY id_msg') . '
HAVING (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ' AND reported = {int:is_reported})') . '
ORDER BY id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '
LIMIT ' . $start . ', ' . $limit),
array(
'current_member' => $user_info['id'],
'current_topic' => $topic,
'is_approved' => 1,
'is_reported' => 0,
'blank_id_member' => 0,
)
);
Otsikko: Re: Hiding Reported Posts
Kirjoitti: margarett - syyskuu 30, 2013, 07:40:10 AP
Not sure, I will test here ;)
Otsikko: Re: Hiding Reported Posts
Kirjoitti: margarett - syyskuu 30, 2013, 07:57:10 AP
It actually works ;) Just a little rewritten:

// Get each post and poster in this topic.
$request = $smcFunc['db_query']('display_get_post_poster', '
SELECT id_msg, id_member, approved, reported
FROM {db_prefix}messages
WHERE reported = {int:is_reported} AND id_topic = {int:current_topic}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : (!empty($modSettings['db_mysql_group_by_fix']) ? '' : '
GROUP BY id_msg') . '
HAVING (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . '
ORDER BY id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '
LIMIT ' . $start . ', ' . $limit),
array(
'current_member' => $user_info['id'],
'current_topic' => $topic,
'is_approved' => 1,
'is_reported' => 0,
'blank_id_member' => 0,
)
);
Otsikko: Re: Hiding Reported Posts
Kirjoitti: sedrik05 - syyskuu 30, 2013, 08:08:52 AP
Thank you very much! Hmm, how can i add button on index.php?action=moderate;area=reports? I want to add 'Ignore Report' button that will change the value of reported = 0, so that it will be posted again on the forum. :)
Otsikko: Re: Hiding Reported Posts
Kirjoitti: margarett - syyskuu 30, 2013, 09:47:40 AP
I see what you mean. I still think you don't need that new column, you can use the already existing mechanism for reported posts.

You can build that query like this (damn this took time :P ):

// Get each post and poster in this topic.
$request = $smcFunc['db_query']('display_get_post_poster', '
SELECT m.id_msg, m.id_member, m.approved
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}log_reported as r ON (m.id_msg = r.id_msg)
WHERE (r.id_msg IS NULL OR (r.num_reports > 0 AND r.closed = 1)) AND m.id_topic = {int:current_topic}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : (!empty($modSettings['db_mysql_group_by_fix']) ? '' : '
GROUP BY m.id_msg') . '
HAVING (m.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . '
ORDER BY m.id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '
LIMIT ' . $start . ', ' . $limit),
array(
'current_member' => $user_info['id'],
'current_topic' => $topic,
'is_approved' => 1,
'blank_id_member' => 0,
)
);


So you will get what you want, just using SMF's core features and database operations :)
Otsikko: Re: Hiding Reported Posts
Kirjoitti: sedrik05 - syyskuu 30, 2013, 10:38:26 AP
Thank you very much sir! I will just change the name of the 'Close' button. God bless! :)
Otsikko: Re: Hiding Reported Posts
Kirjoitti: margarett - syyskuu 30, 2013, 10:53:38 AP
Glad it worked out ;)
Marked as solved for you. If you need further help, just marks unsolved and reply again.