Skip to content

Commit

Permalink
Fix posts merging option.
Browse files Browse the repository at this point in the history
  • Loading branch information
lavigor committed Feb 20, 2018
1 parent f3a4efb commit a817e75
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function viewtopic_modify_data($event)

$this->helper->form_helper->prepare_qr_form($forum_id, $topic_id);

$this->helper->assign_template_variables_for_qr($forum_id);
$this->helper->assign_template_variables_for_qr($forum_id, $topic_id);

$add_re = ($this->config['qr_enable_re']) ? 'Re: ' : '';
$this->template->assign_var('SUBJECT', $this->request->variable('subject', $add_re . censor_text($topic_data['topic_title']), true));
Expand Down
9 changes: 5 additions & 4 deletions functions/listener_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,14 @@ public function set_form_parameters($forum_id, $topic_data, $qr_hidden_fields)
* Assign template variables if quick reply is enabled
*
* @param int $forum_id Forum ID
* @param int $topic_id Topic ID
*/
public function assign_template_variables_for_qr($forum_id)
public function assign_template_variables_for_qr($forum_id, $topic_id)
{
$this->template_variables_for_qr($forum_id);
$this->template_variables += $this->form_helper->form_template_variables;
$this->template_variables += $this->plugins_helper->template_variables_for_plugins($forum_id);
$this->template_variables += $this->plugins_helper->template_variables_for_extensions();
$this->template_variables += $this->form_helper->form_template_variables
+ $this->plugins_helper->template_variables_for_plugins($forum_id)
+ $this->plugins_helper->template_variables_for_extensions($forum_id, $topic_id);

$this->template->assign_vars($this->template_variables);
}
Expand Down
35 changes: 34 additions & 1 deletion functions/plugins_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,49 @@ public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config
$this->phpbb_extension_manager = $phpbb_extension_manager;
}

/**
* Returns whether posts merging is allowed in current topic.
* Used only when PostsMerging extension is enabled.
*
* @param int $forum_id Current forum ID
* @param int $topic_id Current topic ID
* @return bool
*/
private function posts_merging_allowed($forum_id, $topic_id)
{
return $this->auth->acl_get('u_postsmerging') &&
$this->auth->acl_get('u_postsmerging_ignore') &&
$this->auth->acl_get('f_noapprove', $forum_id) &&
!$this->excluded_from_merge($forum_id, $topic_id);
}

/**
* Returns whether the current topic is excluded from posts merging.
* Used only when PostsMerging extension is enabled.
*
* @param int $forum_id Current forum ID
* @param int $topic_id Current topic ID
* @return bool
*/
private function excluded_from_merge($forum_id, $topic_id)
{
return (in_array($forum_id, explode(',', $this->config['merge_no_forums']))
|| in_array($topic_id, explode(',', $this->config['merge_no_topics'])));
}

/**
* Returns template variables for supported extensions for quick reply.
*
* @param int $forum_id Current forum ID
* @param int $topic_id Current topic ID
* @return array
*/
public function template_variables_for_extensions()
public function template_variables_for_extensions($forum_id, $topic_id)
{
$template_variables = array();
if (
$this->phpbb_extension_manager->is_enabled('rxu/PostsMerging') &&
$this->posts_merging_allowed($forum_id, $topic_id) &&
$this->user->data['is_registered'] &&
$this->config['merge_interval']
)
Expand Down

0 comments on commit a817e75

Please sign in to comment.