Add Spam CounterMeasure to Report Post page

Discussion forum for MOD Writers regarding MOD Development.
Locked
wjack2010
Registered User
Posts: 42
Joined: Sat Jan 28, 2012 10:58 am

Add Spam CounterMeasure to Report Post page

Post by wjack2010 »

What code do I need to include the spam countermeasure in the report post page for guests?
User avatar
RMcGirr83
Former Team Member
Posts: 21901
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Add Spam CounterMeasure to Report Post page

Post by RMcGirr83 »

Why are you allowing guests to report posts would be an even better question I would think.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
wjack2010
Registered User
Posts: 42
Joined: Sat Jan 28, 2012 10:58 am

Re: Add Spam CounterMeasure to Report Post page

Post by wjack2010 »

RMcGirr83 wrote:Why are you allowing guests to report posts would be an even better question I would think.
My forum is Guest-run, not Member-run for reasons to do with the way my forum, business and website are run.

All I need is the code to add the spam countermeasure on the report post form.
User avatar
RMcGirr83
Former Team Member
Posts: 21901
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Add Spam CounterMeasure to Report Post page

Post by RMcGirr83 »

Open

report.php

FIND

Code: Select all

$submit = (isset($_POST['submit'])) ? true : false;
AFTER ADD

Code: Select all

if (!$user->data['is_registered'])
{
	include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
	$captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
	$captcha->init(CONFIRM_POST);
}
FIND

Code: Select all

// Submit report?
if ($submit && $reason_id)
{
BEFORE ADD

Code: Select all

if ($submit)
{
	// CAPTCHA check
	if (!$captcha->is_solved())
	{
		$vc_response = $captcha->validate();
		if ($vc_response)
		{
			$message = $vc_response;
			trigger_error($message);
		}    
	}
}
AFTER ADD

Code: Select all

	if (!$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === true))
	{
		$captcha->reset();
	}
FIND

Code: Select all

// Generate the reasons
display_reasons($reason_id);
AFTER ADD

Code: Select all

if (!$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === false))
{

	$template->assign_vars(array(
		'S_CONFIRM_CODE'			=> true,
		'CAPTCHA_TEMPLATE'			=> $captcha->get_template(),
	));
}
OPEN

styles/xxx/template/report_body.html

FIND

Code: Select all

</fieldset>
BEFORE ADD

Code: Select all

		<!-- IF CAPTCHA_TEMPLATE -->
			<!-- INCLUDE {CAPTCHA_TEMPLATE} -->
		<!-- ENDIF -->
refresh the template in the ACP.
Last edited by RMcGirr83 on Mon Jan 30, 2012 10:08 pm, edited 1 time in total.
Reason: tidy up code a bit
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
wjack2010
Registered User
Posts: 42
Joined: Sat Jan 28, 2012 10:58 am

Re: Add Spam CounterMeasure to Report Post page

Post by wjack2010 »

RMcGirr83 wrote:Open

report.php

FIND

Code: Select all

$submit = (isset($_POST['submit'])) ? true : false;
AFTER ADD

Code: Select all

if (!$user->data['is_registered'])
{
	include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
	$captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
	$captcha->init(CONFIRM_POST);
}
FIND

Code: Select all

// Submit report?
if ($submit && $reason_id)
{
BEFORE ADD

Code: Select all

if ($submit)
{
	// CAPTCHA check
	if (!$captcha->is_solved())
	{
		$vc_response = $captcha->validate();
		if ($vc_response)
		{
			$message = $vc_response;
			trigger_error($vc_response);
		}    
	}
}
AFTER ADD

Code: Select all

	if (!$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === true))
	{
		$captcha->reset();
	}
FIND

Code: Select all

// Generate the reasons
display_reasons($reason_id);
AFTER ADD

Code: Select all

if (!$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === false))
{

	$template->assign_vars(array(
		'S_CONFIRM_CODE'			=> true,
		'CAPTCHA_TEMPLATE'			=> $captcha->get_template(),
	));
}
OPEN

styles/xxx/template/report_body.html

FIND

Code: Select all

</fieldset>
BEFORE ADD

Code: Select all

		<!-- IF CAPTCHA_TEMPLATE -->
			<!-- INCLUDE {CAPTCHA_TEMPLATE} -->
		<!-- ENDIF -->
refresh the template in the ACP.
There's no report_body.html in my styles folder which is art ultra blue, and on the report.php page I get the error:

"Parse error: syntax error, unexpected $end in /home/sploteco/public_html/devwebs.info/forums/report.php on line 281"
User avatar
RMcGirr83
Former Team Member
Posts: 21901
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Add Spam CounterMeasure to Report Post page

Post by RMcGirr83 »

There's no report_body.html in my styles folder which is art ultra blue
Then the style is using template inherits so edit the prosilver html file
, and on the report.php page I get the error:

"Parse error: syntax error, unexpected $end in /home/sploteco/public_html/devwebs.info/forums/report.php on line 281"
Then you did the edits incorrectly to the report.php file.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
wjack2010
Registered User
Posts: 42
Joined: Sat Jan 28, 2012 10:58 am

Re: Add Spam CounterMeasure to Report Post page

Post by wjack2010 »

Here's my report.php I did the edits exactly as you said:

Code: Select all

<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mcp');

$forum_id		= request_var('f', 0);
$post_id		= request_var('p', 0);
$pm_id			= request_var('pm', 0);
$reason_id		= request_var('reason_id', 0);
$report_text	= utf8_normalize_nfc(request_var('report_text', '', true));
$user_notify	= ($user->data['is_registered']) ? request_var('notify', 0) : false;

$submit = (isset($_POST['submit'])) ? true : false;

if (!$user->data['is_registered'])
{
   include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
   $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
   $captcha->init(CONFIRM_POST);

if (!$post_id && (!$pm_id || !$config['allow_pm_report']))
{
	trigger_error('NO_POST_SELECTED');
}

if ($post_id)
{
	$redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&p=$post_id") . "#p$post_id";
	$return_forum_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
	$pm_id = 0;
}
else
{
	$redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&p=$pm_id");
	$return_forum_url = '';
	$post_id = 0;
	$forum_id = 0;
}

// Has the report been cancelled?
if (isset($_POST['cancel']))
{
	redirect($redirect_url);
}

if ($post_id)
{
	// Grab all relevant data
	$sql = 'SELECT t.*, p.*
		FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
		WHERE p.post_id = $post_id
			AND p.topic_id = t.topic_id";
	$result = $db->sql_query($sql);
	$report_data = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

	if (!$report_data)
	{
		trigger_error('POST_NOT_EXIST');
	}

	$forum_id = (int) ($report_data['forum_id']) ? $report_data['forum_id'] : $forum_id;
	$topic_id = (int) $report_data['topic_id'];

	$sql = 'SELECT *
		FROM ' . FORUMS_TABLE . '
		WHERE forum_id = ' . $forum_id;
	$result = $db->sql_query($sql);
	$forum_data = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

	if (!$forum_data)
	{
		trigger_error('FORUM_NOT_EXIST');
	}

	// Check required permissions
	$acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');

	foreach ($acl_check_ary as $acl => $error)
	{
		if (!$auth->acl_get($acl, $forum_id))
		{
			trigger_error($error);
		}
	}
	unset($acl_check_ary);

	if ($report_data['post_reported'])
	{
		$message = $user->lang['ALREADY_REPORTED'];
		$message .= '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
		$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
		trigger_error($message);
	}
}
else
{
	// Grab all relevant data
	$sql = 'SELECT p.*, pt.*
		FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . " pt
		WHERE p.msg_id = $pm_id
			AND p.msg_id = pt.msg_id
			AND (p.author_id = " . $user->data['user_id'] . " OR pt.user_id = " . $user->data['user_id'] . ")";
	$result = $db->sql_query($sql);
	$report_data = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

	if (!$report_data)
	{
		$user->add_lang('ucp');
		trigger_error('NO_MESSAGE');
	}

	if ($report_data['message_reported'])
	{
		$message = $user->lang['ALREADY_REPORTED_PM'];
		$message .= '<br /><br />' . sprintf($user->lang['RETURN_PM'], '<a href="' . $redirect_url . '">', '</a>');
		trigger_error($message);
	}
}

if ($submit)
{
   // CAPTCHA check
   if (!$captcha->is_solved())
   {
      $vc_response = $captcha->validate();
      if ($vc_response)
      {
         $message = $vc_response;
         trigger_error($vc_response);
      }    
   }
}

// Submit report?
if ($submit && $reason_id)
{

  if (!$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === true))
   {
      $captcha->reset();
   }

	$sql = 'SELECT *
		FROM ' . REPORTS_REASONS_TABLE . "
		WHERE reason_id = $reason_id";
	$result = $db->sql_query($sql);
	$row = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

	if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
	{
		trigger_error('EMPTY_REPORT');
	}

	$sql_ary = array(
		'reason_id'		=> (int) $reason_id,
		'post_id'		=> $post_id,
		'pm_id'			=> $pm_id,
		'user_id'		=> (int) $user->data['user_id'],
		'user_notify'	=> (int) $user_notify,
		'report_closed'	=> 0,
		'report_time'	=> (int) time(),
		'report_text'	=> (string) $report_text
	);

	$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
	$db->sql_query($sql);
	$report_id = $db->sql_nextid();

	if ($post_id)
	{
		$sql = 'UPDATE ' . POSTS_TABLE . '
			SET post_reported = 1
			WHERE post_id = ' . $post_id;
		$db->sql_query($sql);

		if (!$report_data['topic_reported'])
		{
			$sql = 'UPDATE ' . TOPICS_TABLE . '
				SET topic_reported = 1
				WHERE topic_id = ' . $report_data['topic_id'] . '
					OR topic_moved_id = ' . $report_data['topic_id'];
			$db->sql_query($sql);
		}

		$lang_return = $user->lang['RETURN_TOPIC'];
		$lang_success = $user->lang['POST_REPORTED_SUCCESS'];
	}
	else
	{
		$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
			SET message_reported = 1
			WHERE msg_id = ' . $pm_id;
		$db->sql_query($sql);

		$sql_ary = array(
			'msg_id'		=> $pm_id,
			'user_id'		=> ANONYMOUS,
			'author_id'		=> (int) $report_data['author_id'],
			'pm_deleted'	=> 0,
			'pm_new'		=> 0,
			'pm_unread'		=> 0,
			'pm_replied'	=> 0,
			'pm_marked'		=> 0,
			'pm_forwarded'	=> 0,
			'folder_id'		=> PRIVMSGS_INBOX,
		);

		$sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
		$db->sql_query($sql);

		$lang_return = $user->lang['RETURN_PM'];
		$lang_success = $user->lang['PM_REPORTED_SUCCESS'];
	}

	meta_refresh(3, $redirect_url);

	$message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
	if ($return_forum_url)
	{
		$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
	}
	trigger_error($message);
}

// Generate the reasons
display_reasons($reason_id);
if (!$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === false))
{

   $template->assign_vars(array(
      'S_CONFIRM_CODE'         => true,
      'CAPTCHA_TEMPLATE'         => $captcha->get_template(),
   ));
}

$page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST'];

$template->assign_vars(array(
	'S_REPORT_POST'		=> ($pm_id) ? false : true,
	'REPORT_TEXT'		=> $report_text,
	'S_REPORT_ACTION'	=> append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $post_id . '&pm=' . $pm_id),

	'S_NOTIFY'			=> $user_notify,
	'S_CAN_NOTIFY'		=> ($user->data['is_registered']) ? true : false)
);

generate_forum_nav($forum_data);

// Start output of page
page_header($page_title);

$template->set_filenames(array(
	'body' => 'report_body.html')
);

page_footer();

?>
User avatar
RMcGirr83
Former Team Member
Posts: 21901
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Add Spam CounterMeasure to Report Post page

Post by RMcGirr83 »

No you didn't do the edits exactly as I posted

Code: Select all

if (!$user->data['is_registered'])
{
   include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
   $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
   $captcha->init(CONFIRM_POST);
you are missing the closing }
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
wjack2010
Registered User
Posts: 42
Joined: Sat Jan 28, 2012 10:58 am

Re: Add Spam CounterMeasure to Report Post page

Post by wjack2010 »

RMcGirr83 wrote:No you didn't do the edits exactly as I posted

Code: Select all

if (!$user->data['is_registered'])
{
   include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
   $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
   $captcha->init(CONFIRM_POST);
you are missing the closing }
Oh, sorry about that. All done, works perfectly now! Thanks a lot :)
Thanks in advance
Registered User
Posts: 173
Joined: Mon Dec 28, 2009 8:17 am

Re: Add Spam CounterMeasure to Report Post page

Post by Thanks in advance »

In my case it works for guest users (they see the CAPTCHA and can submit reports), but when members try to report anything after hitting submit the following error occurs:

Code: Select all

Fatal error: Call to a member function is_solved() on a non-object in ...../forum/report.php on line 143
Line 143 of report.php is:

Code: Select all

   if (!$captcha->is_solved())
Any ideas how to make it work?

Thanks
User avatar
RMcGirr83
Former Team Member
Posts: 21901
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Add Spam CounterMeasure to Report Post page

Post by RMcGirr83 »

Find this line

Code: Select all

if ($submit)
{
   // CAPTCHA check
   if (!$captcha->is_solved())
and change it to this

Code: Select all

if ($submit && !$user->data['is_registered'])
{
   // CAPTCHA check
   if (!$captcha->is_solved())
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
Thanks in advance
Registered User
Posts: 173
Joined: Mon Dec 28, 2009 8:17 am

Re: Add Spam CounterMeasure to Report Post page

Post by Thanks in advance »

Works! Thanks a lot!
Locked

Return to “[3.0.x] MOD Writers Discussion”