Topic: Hide reported post

Hi,

As this is my first message here I would like to say this: nice software and thanks. smile

I found this code to hide reported content here.

if ($pun_user['g_id'] > 2)
{
    $result = $db->query('SELECT DISTINCT reported_by FROM '.$db->prefix.'reports WHERE topic_id = '.$id.' AND zapped IS NULL') or error('Unable to fetch report info', __FILE__, __LINE__, $db->error());
    if ($db->num_rows($result) >= 3)
    {
        message('Content contained in this topic has been marked as objectionable and is awaiting staff review. Please try again later.');
    }
}

Now, I want this but applied to posts, not topics. I found that around line 328 in viewtopic.php the message is displayed.

The code is:

<?php echo $cur_post['message']."\n" ?>

Any ideas how to do it?

Thanks in advance. wink

Re: Hide reported post

Try this? In viewtopic.php, find?

    // Perform the main parsing of the message (BBCode, smilies, censor words etc)
    $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

?replace with:

    $result = $db->query('SELECT DISTINCT reported_by FROM '.$db->prefix.'reports WHERE post_id = '.$cur_post['id'].' AND zapped IS NULL') or error('Unable to fetch report info', __FILE__, __LINE__, $db->error());
    if (!$is_admmod && $db->num_rows($result) >= 3)
        $cur_post['message'] = '<em>This post has been marked as objectionable and is awaiting staff review.</em>';
    else
        // Perform the main parsing of the message (BBCode, smilies, censor words etc)
        $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

Re: Hide reported post

Hi,

Thanks for your time with this. I really appreciate it! smile
Happy holidays if it's the case! wink

I've already tried something like that but it only displays the 1st post of the topic not parsing the rest.

With original viewtopic.php, showing 3 posts:

Debug information
Time (s) Query 
0.00131 SELECT u.*, g.*, o.logged, o.idle FROM users AS u INNER JOIN groups AS g ON u.group_id=g.g_id LEFT JOIN online AS o ON o.user_id=u.id WHERE u.id=3 
0.00014 UPDATE online SET logged=1166722642 WHERE user_id=3 
0.00011 UPDATE online SET current_page='/punbb_standard/viewtopic.php', current_ip='213.22.18.126', current_page_id='7' WHERE user_id='3' 
0.00015 SELECT * FROM online WHERE logged<1166722342 
0.00083 SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, s.user_id AS is_subscribed FROM topics AS t INNER JOIN forums AS f ON f.id=t.forum_id LEFT JOIN subscriptions AS s ON (t.id=s.topic_id AND s.user_id=3) LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=4) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id=7 AND t.moved_to IS NULL 
0.00022 SELECT search_for, replace_with FROM censoring 
0.00088 SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM posts AS p INNER JOIN users AS u ON u.id=p.poster_id INNER JOIN groups AS g ON g.g_id=u.group_id LEFT JOIN online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id=7 ORDER BY p.id LIMIT 0,25 
0.00028 UPDATE LOW_PRIORITY topics SET num_views=num_views+1 WHERE id=7 
Total query time: 0.00392 s

This is viewtopic.php with the above code and with the result of only showing the first post of a topic:

Debug information
Time (s) Query 
0.00112 SELECT u.*, g.*, o.logged, o.idle FROM users AS u INNER JOIN groups AS g ON u.group_id=g.g_id LEFT JOIN online AS o ON o.user_id=u.id WHERE u.id=3 
0.00012 UPDATE online SET logged=1166722500 WHERE user_id=3 
0.00010 UPDATE online SET current_page='/punbb_standard/viewtopic.php', current_ip='213.22.18.126', current_page_id='7' WHERE user_id='3' 
0.00013 SELECT * FROM online WHERE logged<1166722200 
0.00081 SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, s.user_id AS is_subscribed FROM topics AS t INNER JOIN forums AS f ON f.id=t.forum_id LEFT JOIN subscriptions AS s ON (t.id=s.topic_id AND s.user_id=3) LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=4) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id=7 AND t.moved_to IS NULL 
0.00024 SELECT search_for, replace_with FROM censoring 
0.00074 SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM posts AS p INNER JOIN users AS u ON u.id=p.poster_id INNER JOIN groups AS g ON g.g_id=u.group_id LEFT JOIN online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id=7 ORDER BY p.id LIMIT 0,25 
0.00036 SELECT DISTINCT reported_by FROM reports WHERE post_id = 8 AND zapped IS NULL 
0.00022 UPDATE LOW_PRIORITY topics SET num_views=num_views+1 WHERE id=7 
Total query time: 0.00384 s

As I can see it, the sugested code breaks this loop:

while ($cur_post = $db->fetch_assoc($result))
{
    $post_count++;
    $user_avatar = '';
    $user_info = array();
    $user_contacts = array();
    $post_actions = array();
    $is_online = '';
    $signature = '';

By adding one variable that isn't reset.

But I don't have any experience or whatever with PHP or programming. I'm just a curious.

Thanks in advance. smile

Re: Hide reported post

Change 'true' to 'false' in the second argument of $db->query(), this will make it buffered again and thus making it work smile

5 (edited by fmimoso 2006-12-21 18:22)

Re: Hide reported post

Thanks for your support elbekko! smile

As you've suggested I'm trying this:

$result = $db->query('SELECT DISTINCT reported_by FROM '.$db->prefix.'reports WHERE post_id = '.$cur_post['id'].' AND zapped IS NULL', false) or error('Unable to fetch report info', __FILE__, __LINE__, $db->error());

And it still only shows the first post out of three. hmm

Debug information
Time (s) Query 
0.00108 SELECT u.*, g.*, o.logged, o.idle FROM users AS u INNER JOIN groups AS g ON u.group_id=g.g_id LEFT JOIN online AS o ON o.user_id=u.id WHERE u.id=3 
0.00012 UPDATE online SET logged=1166725156 WHERE user_id=3 
0.00010 UPDATE online SET current_page='/punbb_standard/viewtopic.php', current_ip='213.22.18.126', current_page_id='7' WHERE user_id='3' 
0.00013 SELECT * FROM online WHERE logged<1166724856 
0.00075 SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, s.user_id AS is_subscribed FROM topics AS t INNER JOIN forums AS f ON f.id=t.forum_id LEFT JOIN subscriptions AS s ON (t.id=s.topic_id AND s.user_id=3) LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=4) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id=7 AND t.moved_to IS NULL 
0.00025 SELECT search_for, replace_with FROM censoring 
0.00076 SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM posts AS p INNER JOIN users AS u ON u.id=p.poster_id INNER JOIN groups AS g ON g.g_id=u.group_id LEFT JOIN online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id=7 ORDER BY p.id LIMIT 0,25 
0.00038 SELECT DISTINCT reported_by FROM reports WHERE post_id = 8 AND zapped IS NULL 
0.00022 UPDATE LOW_PRIORITY topics SET num_views=num_views+1 WHERE id=7 
Total query time: 0.00379 s

Thanks.

Re: Hide reported post

I mean the one in the main query (the one fetching the posts).

7 (edited by fmimoso 2006-12-21 18:38)

Re: Hide reported post

First post in topic is #8.
Reported post is #12.

With your alteration:

$result = $db->query('SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], false) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());

Debug:

Debug information
Time (s) Query 
0.00110 SELECT u.*, g.*, o.logged, o.idle FROM users AS u INNER JOIN groups AS g ON u.group_id=g.g_id LEFT JOIN online AS o ON o.user_id=u.id WHERE u.id=3 
0.00012 UPDATE online SET logged=1166725662 WHERE user_id=3 
0.00010 UPDATE online SET current_page='/punbb_standard/viewtopic.php', current_ip='213.22.18.126', current_page_id='7' WHERE user_id='3' 
0.00013 SELECT * FROM online WHERE logged<1166725362 
0.00077 SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, s.user_id AS is_subscribed FROM topics AS t INNER JOIN forums AS f ON f.id=t.forum_id LEFT JOIN subscriptions AS s ON (t.id=s.topic_id AND s.user_id=3) LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=4) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id=7 AND t.moved_to IS NULL 
0.00021 SELECT search_for, replace_with FROM censoring 
0.00078 SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM posts AS p INNER JOIN users AS u ON u.id=p.poster_id INNER JOIN groups AS g ON g.g_id=u.group_id LEFT JOIN online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id=7 ORDER BY p.id LIMIT 0,25 
0.00033 SELECT DISTINCT reported_by FROM reports WHERE post_id = 8 AND zapped IS NULL 
0.00022 UPDATE LOW_PRIORITY topics SET num_views=num_views+1 WHERE id=7 
Total query time: 0.00376 s

Result: first post (not reported #8) shows with "This post has been marked as objectionable and is awaiting staff review."
Second and third post (reported #12) don't even show.

Tricky. smile
Keep it coming big_smile
Thanks. smile

See it in action:
Modified viewtopic.php http://69.73.152.118/punbb_standard/viewtopic.php?id=7
Original viewtopic.php http://69.73.152.118/punbb_standard/viewtopic1.php?id=7

8 (edited by guardian34 2006-12-21 20:25)

Re: Hide reported post

Hmm? on my board it does stop at the first post.

Edit: The reports query seems to cause problems? Is there a way to move it outside the main loop?

Edit: Still curious about moving outside the loop, but, um? trying renaming the variable to:

$report_result // instead of $result, which is in use by the main loop!

Re: Hide reported post

cool

Many thanks.
As far as I can see IT WORKS! Clap, clap, clap.

Best wishes to you and yours. smile
Thank you too elbekko! smile

Should it be released as a mod?

Re: Hide reported post

After some testing, I'm having a small minor concern.

With the code I get 40 queries in a full page, without the code I get 15 queries.

To my understanding this affects the perfomance, right?

How can we optimize the working code above? smile

11 (edited by guardian34 2006-12-29 16:47)

Re: Hide reported post

Ok, I think I have some better code. Undo the changes that I mentioned before (but keep the change that elbekko mentioned) and try this (in viewtopic.php)?

1. Find?

// Retrieve the posts (and their respective poster/online status)

Before, add:

// mod: Don't display reported posts
$report_result = $db->query('SELECT DISTINCT reported_by, post_id FROM '.$db->prefix.'reports WHERE topic_id = '.$id.' AND zapped IS NULL') or error('Unable to fetch report info', __FILE__, __LINE__, $db->error());
$reported = array();
while($cur_report = $db->fetch_assoc($report_result))
    $reported[] = $cur_report['post_id'];

2. Find?

// Perform the main parsing of the message (BBCode, smilies, censor words etc)
$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

replace with:

    // Perform the main parsing of the message (BBCode, smilies, censor words etc)
    // mod: Don't display reported posts
    if (!$is_admmod && in_array($cur_post['id'], $reported))
    {
        $report_result = $db->query('SELECT DISTINCT reported_by FROM '.$db->prefix.'reports WHERE post_id = '.$cur_post['id'].' AND zapped IS NULL') or error('Unable to fetch report info', __FILE__, __LINE__, $db->error());
        if ($db->num_rows($report_result) >= 3)
            $cur_post['message'] = '[<em>This post has been marked as objectionable and is awaiting staff review.</em>]';
        else
            $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
    }
    else
        $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

Re: Hide reported post

Well, it's a bit of an improvement tongue But you seem to be doing the same query twice...

Re: Hide reported post

An untested version which I think should be better:

Only problem with it: one user can make 3 reports and the post will be hidden (I actually think that was a bug in the original code as well, but I've never tested it)

FIND

// Retrieve the posts (and their respective poster/online status)

BEFORE, ADD

// mod: Don't display reported posts
$report_result = $db->query('SELECT post_id, COUNT(*) AS num_reports FROM '.$db->prefix.'reports WHERE topic_id = '.$id.' AND zapped IS NULL GROUP BY post_id') or error('Unable to fetch report info', __FILE__, __LINE__, $db->error());
$reported = array();
while($cur_report = $db->fetch_assoc($report_result))
{
    if ($cur_report['num_reports'] >= 3)
        $reported[$cur_report['post_id']] = true;
}

FIND

// Perform the main parsing of the message (BBCode, smilies, censor words etc)
$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

REPLACE WITH

    // Perform the main parsing of the message (BBCode, smilies, censor words etc)
    // mod: Don't display reported posts
    if (!$is_admmod && isset($reported[$cur_post['id']]))
        $cur_post['message'] = '[<em>This post has been marked as objectionable and is awaiting staff review.</em>]';
    else
        $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

Re: Hide reported post

And here's a version which addresses the user issue: now you need reports from 3 unique users
Again, untested, I coded it right in the post box, it might need some fixes

FIND

// Retrieve the posts (and their respective poster/online status)

BEFORE, ADD

// mod: Don't display reported posts
$report_result = $db->query('SELECT post_id, reported_by FROM '.$db->prefix.'reports WHERE topic_id = '.$id.' AND zapped IS NULL') or error('Unable to fetch report info', __FILE__, __LINE__, $db->error());
$reported = array();
while($cur_report = $db->fetch_assoc($report_result))
{
    $reported[$cur_report['post_id']][$cur_report['reported_by']] = true;
}

FIND

// Perform the main parsing of the message (BBCode, smilies, censor words etc)
$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

REPLACE WITH

    // Perform the main parsing of the message (BBCode, smilies, censor words etc)
    // mod: Don't display reported posts
    if (!$is_admmod && isset($reported[$cur_post['id']]) && count($reported[$cur_post['id']]) >= 3)
        $cur_post['message'] = '[<em>This post has been marked as objectionable and is awaiting staff review.</em>]';
    else
        $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

Re: Hide reported post

You could try a DISTINCT reported_by.

Re: Hide reported post

I'm not returning any duplicate rows though, so that won't do anything wink
Anyways, the second post should deal with the user issue

Re: Hide reported post

You guys rock... smile

Original viewtopic.php (plain standard file not changed):
http://69.73.152.118/punbb_standard/viewtopic.php?id=7
Generated in 0.049 seconds, 8 queries executed

With guardian34 "old" code:
http://69.73.152.118/punbb_standard/vie … n.php?id=7
Generated in 0.024 seconds, 15 queries executed

With guardian34 new code:
http://69.73.152.118/punbb_standard/vie … n.php?id=7
It halts at the reported post not showing the rest.

With Smartys code:
http://69.73.152.118/punbb_standard/vie … s.php?id=7
Generated in 0.026 seconds, 9 queries executed

Thank you all for your help! I think it is excellent!

I will release it as a mod, crediting all the work to guardian34, elbekko and Smartys. smile

Once more: THANKS, and a happy new year (if you're on a gregorian calendar wink)!

Re: Hide reported post

Smartys, that looks much better. cool

Re: Hide reported post

Smartys wrote:

Only problem with it: one user can make 3 reports and the post will be hidden (I actually think that was a bug in the original code as well, but I've never tested it)

Nah, the code I wrote wasn't very good, but it didn't have that bug. tongue

Looking for a certain modification for your forum? Please take a look here before posting.

Re: Hide reported post

pogenwurst: Are you sure? It doesn't look like there's anything preventing it

Re: Hide reported post

It's SELECT DISTINCTing the id(s) of all user(s) that have reported post(s) in the current topic, where the reports have not been zapped. Thus if a topic contains the posts with IDs 1, 2, and 3 and the reports are as follows:
reported_by | whatever_the_pid_column_is_called
23              | 1
23              | 2
24              | 2
23              | 3
the resultset will be 23 & 24 and thus the number of results will be 2.

More simply, the query fetches distinct user IDs that have reported post(s) within a topic; it doesn't actually fetch any number of reports.

Looking for a certain modification for your forum? Please take a look here before posting.

22

Re: Hide reported post

Offtopic..
Btw, how do you guys get the "[ Generated in 0.316 seconds, 10 queries executed ]"?
is it a mod?

23 (edited by elbekko 2006-12-30 22:25)

Re: Hide reported post

It's just Debug mode.

Re: Hide reported post

Mod released: http://www.punres.org/desc.php?pid=331
Download it here: http://www.punres.org/download.php?id=1164

smile

25

Re: Hide reported post

There is a bug. When this mod hides a reported post it is always possible to see this post whith the "Quote" button and when posting reply.