1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-24 20:13:22 +01:00

Merge remote-tracking branch 'remotes/dhruvgoel92/ticket/11566' into develop-olympus

* remotes/dhruvgoel92/ticket/11566:
  [ticket/11566] Subsilver template error displayed after table headers
  [ticket/11566] Remove extra pair of brackets from conditional statement
  [ticket/11566] Check that guest doesn't have reporting permission by default
  [ticket/11566] Add captcha to report post template in subsilver
  [ticket/11566] Use the new constant CONFIRM_REPORT for captcha init
  [ticket/11566] Rename var to $visual_confirmation_response
  [ticket/11566] Revert forum permission changes
  [ticket/11566] Use language variable instead of hardcode
  [ticket/11566] add tests for reporting post
  [ticket/11566] add captcha reset and hidden fields
  [ticket/11566] display error instead of trigger_error
  [ticket/11566] add error in template
  [ticket/11566] add error functionality
  [ticket/11566] add interface for captcha
This commit is contained in:
Joas Schilling 2013-07-02 13:07:14 +02:00
commit d4531c9cea
5 changed files with 170 additions and 58 deletions

View File

@ -157,6 +157,7 @@ define('PHYSICAL_LINK', 2);
define('CONFIRM_REG', 1); define('CONFIRM_REG', 1);
define('CONFIRM_LOGIN', 2); define('CONFIRM_LOGIN', 2);
define('CONFIRM_POST', 3); define('CONFIRM_POST', 3);
define('CONFIRM_REPORT', 4);
// Categories - Attachments // Categories - Attachments
define('ATTACHMENT_CATEGORY_NONE', 0); define('ATTACHMENT_CATEGORY_NONE', 0);

View File

@ -133,9 +133,25 @@ else
} }
} }
if ($config['enable_post_confirm'] && !$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_REPORT);
}
$error = array();
$s_hidden_fields = '';
// Submit report? // Submit report?
if ($submit && $reason_id) if ($submit && $reason_id)
{ {
$visual_confirmation_response = $captcha->validate();
if ($visual_confirmation_response)
{
$error[] = $visual_confirmation_response;
}
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . REPORTS_REASONS_TABLE . " FROM ' . REPORTS_REASONS_TABLE . "
WHERE reason_id = $reason_id"; WHERE reason_id = $reason_id";
@ -145,7 +161,14 @@ if ($submit && $reason_id)
if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other')) if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
{ {
trigger_error('EMPTY_REPORT'); $error[] = $user->lang('EMPTY_REPORT');
}
if (!sizeof($error))
{
if (isset($captcha))
{
$captcha->reset();
} }
$sql_ary = array( $sql_ary = array(
@ -218,16 +241,31 @@ if ($submit && $reason_id)
} }
trigger_error($message); trigger_error($message);
} }
else if (isset($captcha) && $captcha->is_solved() !== false)
{
$s_hidden_fields .= build_hidden_fields($captcha->get_hidden_fields());
}
}
// Generate the reasons // Generate the reasons
display_reasons($reason_id); display_reasons($reason_id);
$page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST']; $page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST'];
if (isset($captcha) && $captcha->is_solved() === false)
{
$template->assign_vars(array( $template->assign_vars(array(
'S_CONFIRM_CODE' => true,
'CAPTCHA_TEMPLATE' => $captcha->get_template(),
));
}
$template->assign_vars(array(
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
'S_REPORT_POST' => ($pm_id) ? false : true, 'S_REPORT_POST' => ($pm_id) ? false : true,
'REPORT_TEXT' => $report_text, 'REPORT_TEXT' => $report_text,
'S_REPORT_ACTION' => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id . '&amp;pm=' . $pm_id), 'S_REPORT_ACTION' => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id . '&amp;pm=' . $pm_id),
'S_HIDDEN_FIELDS' => (sizeof($s_hidden_fields)) ? $s_hidden_fields : null,
'S_NOTIFY' => $user_notify, 'S_NOTIFY' => $user_notify,
'S_CAN_NOTIFY' => ($user->data['is_registered']) ? true : false) 'S_CAN_NOTIFY' => ($user->data['is_registered']) ? true : false)

View File

@ -10,6 +10,7 @@
<p><!-- IF S_REPORT_POST -->{L_REPORT_POST_EXPLAIN}<!-- ELSE -->{L_REPORT_MESSAGE_EXPLAIN}<!-- ENDIF --></p> <p><!-- IF S_REPORT_POST -->{L_REPORT_POST_EXPLAIN}<!-- ELSE -->{L_REPORT_MESSAGE_EXPLAIN}<!-- ENDIF --></p>
<fieldset> <fieldset>
<!-- IF ERROR --><dl><dd class="error">{ERROR}</dd></dl><!-- ENDIF -->
<dl class="fields2"> <dl class="fields2">
<dt><label for="reason_id">{L_REASON}:</label></dt> <dt><label for="reason_id">{L_REASON}:</label></dt>
<dd><select name="reason_id" id="reason_id" class="full"><!-- BEGIN reason --><option value="{reason.ID}"<!-- IF reason.S_SELECTED --> selected="selected"<!-- ENDIF -->>{reason.DESCRIPTION}</option><!-- END reason --></select></dd> <dd><select name="reason_id" id="reason_id" class="full"><!-- BEGIN reason --><option value="{reason.ID}"<!-- IF reason.S_SELECTED --> selected="selected"<!-- ENDIF -->>{reason.DESCRIPTION}</option><!-- END reason --></select></dd>
@ -27,6 +28,9 @@
<dt><label for="report_text">{L_MORE_INFO}:</label><br /><span>{L_CAN_LEAVE_BLANK}</span></dt> <dt><label for="report_text">{L_MORE_INFO}:</label><br /><span>{L_CAN_LEAVE_BLANK}</span></dt>
<dd><textarea name="report_text" id="report_text" rows="10" cols="76" class="inputbox">{REPORT_TEXT}</textarea></dd> <dd><textarea name="report_text" id="report_text" rows="10" cols="76" class="inputbox">{REPORT_TEXT}</textarea></dd>
</dl> </dl>
<!-- IF CAPTCHA_TEMPLATE -->
<!-- INCLUDE {CAPTCHA_TEMPLATE} -->
<!-- ENDIF -->
</fieldset> </fieldset>
</div> </div>

View File

@ -6,6 +6,11 @@
<tr> <tr>
<th colspan="2"><!-- IF S_REPORT_POST -->{L_REPORT_POST}<!-- ELSE -->{L_REPORT_MESSAGE}<!-- ENDIF --></th> <th colspan="2"><!-- IF S_REPORT_POST -->{L_REPORT_POST}<!-- ELSE -->{L_REPORT_MESSAGE}<!-- ENDIF --></th>
</tr> </tr>
<!-- IF ERROR -->
<tr>
<td class="row3" colspan="2" align="center"><span class="genmed error">{ERROR}</span></td>
</tr>
<!-- ENDIF -->
<tr> <tr>
<td class="row3" colspan="2"><span class="gensmall"><!-- IF S_REPORT_POST -->{L_REPORT_POST_EXPLAIN}<!-- ELSE -->{L_REPORT_MESSAGE_EXPLAIN}<!-- ENDIF --></span></td> <td class="row3" colspan="2"><span class="gensmall"><!-- IF S_REPORT_POST -->{L_REPORT_POST_EXPLAIN}<!-- ELSE -->{L_REPORT_MESSAGE_EXPLAIN}<!-- ENDIF --></span></td>
</tr> </tr>
@ -25,6 +30,9 @@
<td class="row1" valign="top"><span class="gen"><b>{L_MORE_INFO}:</b></span><br /><span class="gensmall">{L_CAN_LEAVE_BLANK}</span></td> <td class="row1" valign="top"><span class="gen"><b>{L_MORE_INFO}:</b></span><br /><span class="gensmall">{L_CAN_LEAVE_BLANK}</span></td>
<td class="row2"><textarea class="post" name="report_text" rows="10" cols="50">{REPORT_TEXT}</textarea></td> <td class="row2"><textarea class="post" name="report_text" rows="10" cols="50">{REPORT_TEXT}</textarea></td>
</tr> </tr>
<!-- IF CAPTCHA_TEMPLATE -->
<!-- INCLUDE {CAPTCHA_TEMPLATE} -->
<!-- ENDIF -->
<tr> <tr>
<td class="cat" colspan="2" align="center"><input type="submit" name="submit" class="btnmain" value="{L_SUBMIT}" />&nbsp;<input type="submit" name="cancel" class="btnlite" value="{L_CANCEL}" /></td> <td class="cat" colspan="2" align="center"><input type="submit" name="submit" class="btnmain" value="{L_SUBMIT}" />&nbsp;<input type="submit" name="cancel" class="btnlite" value="{L_CANCEL}" /></td>
</tr> </tr>

View File

@ -0,0 +1,61 @@
<?php
/**
*
* @package testing
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @group functional
*/
class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_case
{
public function test_user_report_post()
{
$this->login();
$crawler = self::request('GET', 'report.php?f=2&p=1');
$this->assertNotContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text());
}
public function test_guest_report_post()
{
$crawler = self::request('GET', 'report.php?f=2&p=1');
$this->add_lang('mcp');
$this->assertContains($this->lang('USER_CANNOT_REPORT'), $crawler->filter('html')->text());
$this->set_reporting_guest(1);
$crawler = self::request('GET', 'report.php?f=2&p=1');
$this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text());
$this->set_reporting_guest(-1);
}
protected function set_reporting_guest($report_post_allowed)
{
$this->login();
$this->admin_login();
$crawler = self::request('GET', 'adm/index.php?i=permissions&icat=12&mode=setting_group_local&sid=' . $this->sid);
$form = $crawler->selectButton('Submit')->form();
$values = $form->getValues();
$values["group_id[0]"] = 1;
$form->setValues($values);
$crawler = self::submit($form);
$form = $crawler->selectButton('Submit')->form();
$values = $form->getValues();
$values["forum_id"] = 2;
$form->setValues($values);
$crawler = self::submit($form);
$this->add_lang('acp/permissions');
$form = $crawler->selectButton($this->lang('APPLY_ALL_PERMISSIONS'))->form();
$values = $form->getValues();
$values["setting[1][2][f_report]"] = $report_post_allowed;
$form->setValues($values);
$crawler = self::submit($form);
$crawler = self::request('GET', 'ucp.php?mode=logout&sid=' . $this->sid);
}
}