Skip to content

Commit

Permalink
Merge pull request #4619 from Nicofuma/ticket/14962
Browse files Browse the repository at this point in the history
[ticket/14962] Introduces a new helper to check emptyness of bbcode texts
  • Loading branch information
marc1706 committed Jan 6, 2017
2 parents dc2442e + 901828c commit 9d09091
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
13 changes: 13 additions & 0 deletions phpbb/textformatter/s9e/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,17 @@ public function unparse($xml)
{
return \s9e\TextFormatter\Unparser::unparse($xml);
}

/**
* {@inheritdoc}
*/
public function is_empty($text)
{
if ($text === null || $text === '')
{
return true;
}

return trim($this->unparse($text)) === '';
}
}
18 changes: 13 additions & 5 deletions phpbb/textformatter/utils_interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ public function get_outermost_quote_authors($text);
public function remove_bbcode($text, $bbcode_name, $depth = 0);

/**
* Return a parsed text to its original form
*
* @param string $text Parsed text
* @return string Original plain text
*/
* Return a parsed text to its original form
*
* @param string $text Parsed text
* @return string Original plain text
*/
public function unparse($text);

/**
* Return whether or not a parsed text represent an empty text.
*
* @param string $text Parsed text
* @return bool Tue if the original text is empty
*/
public function is_empty($text);
}
7 changes: 4 additions & 3 deletions posting.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@
load_drafts($topic_id, $forum_id);
}

$bbcode_utils = $phpbb_container->get('text_formatter.utils');

if ($submit || $preview || $refresh)
{
Expand Down Expand Up @@ -1178,7 +1179,7 @@
$post_data['poll_title'] = '';
$post_data['poll_start'] = $post_data['poll_length'] = $post_data['poll_max_options'] = $post_data['poll_last_vote'] = $post_data['poll_vote_change'] = 0;
}
else if (!$auth->acl_get('f_poll', $forum_id) && ($mode == 'edit') && ($post_id == $post_data['topic_first_post_id']) && ($original_poll_data['poll_title'] != ''))
else if (!$auth->acl_get('f_poll', $forum_id) && ($mode == 'edit') && ($post_id == $post_data['topic_first_post_id']) && !$bbcode_utils->is_empty($original_poll_data['poll_title']))
{
// We have a poll but the editing user is not permitted to create/edit it.
// So we just keep the original poll-data.
Expand Down Expand Up @@ -1601,7 +1602,7 @@

if ($config['allow_bbcode'])
{
$message_parser->message = $phpbb_container->get('text_formatter.utils')->generate_quote(
$message_parser->message = $bbcode_utils->generate_quote(
censor_text($message_parser->message),
array(
'author' => $post_data['quote_username'],
Expand Down Expand Up @@ -1639,7 +1640,7 @@
$filename_data = $message_parser->filename_data;
$post_data['post_text'] = $message_parser->message;

if (sizeof($post_data['poll_options']) || !empty($post_data['poll_title']))
if (sizeof($post_data['poll_options']) || (isset($post_data['poll_title']) && !$bbcode_utils->is_empty($post_data['poll_title'])))
{
$message_parser->message = $post_data['poll_title'];
$message_parser->bbcode_uid = $post_data['bbcode_uid'];
Expand Down

0 comments on commit 9d09091

Please sign in to comment.