mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/16250] Reworked status as constants
PHPBB3-16250
This commit is contained in:
parent
2926ceba6a
commit
2733ce0712
3 changed files with 30 additions and 14 deletions
|
@ -174,16 +174,16 @@ class acp_bbcodes
|
||||||
|
|
||||||
$acp_utils = $phpbb_container->get('text_formatter.acp_utils');
|
$acp_utils = $phpbb_container->get('text_formatter.acp_utils');
|
||||||
$bbcode_info = $acp_utils->analyse_bbcode($bbcode_match, $bbcode_tpl);
|
$bbcode_info = $acp_utils->analyse_bbcode($bbcode_match, $bbcode_tpl);
|
||||||
$warn_unsafe = ($bbcode_info['status'] === 'unsafe');
|
$warn_unsafe = ($bbcode_info['status'] === $acp_utils::BBCODE_STATUS_UNSAFE);
|
||||||
|
|
||||||
if ($bbcode_info['status'] === 'invalid_definition')
|
if ($bbcode_info['status'] === $acp_utils::BBCODE_STATUS_INVALID_TEMPLATE)
|
||||||
{
|
|
||||||
trigger_error($user->lang['BBCODE_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
||||||
}
|
|
||||||
if ($bbcode_info['status'] === 'invalid_template')
|
|
||||||
{
|
{
|
||||||
trigger_error($user->lang['BBCODE_INVALID_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
trigger_error($user->lang['BBCODE_INVALID_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
if ($bbcode_info['status'] === $acp_utils::BBCODE_STATUS_INVALID_DEFINITION)
|
||||||
|
{
|
||||||
|
trigger_error($user->lang['BBCODE_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$warn_unsafe && !check_form_key($form_key))
|
if (!$warn_unsafe && !check_form_key($form_key))
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,15 +15,31 @@ namespace phpbb\textformatter;
|
||||||
|
|
||||||
interface acp_utils_interface
|
interface acp_utils_interface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* There is an issue with the definition
|
||||||
|
*/
|
||||||
|
const BBCODE_STATUS_INVALID_DEFINITION = 'invalid_definition';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There is an issue with the template
|
||||||
|
*/
|
||||||
|
const BBCODE_STATUS_INVALID_TEMPLATE = 'invalid_template';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The BBCode is valid and can be safely used by anyone
|
||||||
|
*/
|
||||||
|
const BBCODE_STATUS_SAFE = 'safe';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The BBCode is valid but may be unsafe to use
|
||||||
|
*/
|
||||||
|
const BBCODE_STATUS_UNSAFE = 'unsafe';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Analyse given BBCode definition for issues and safeness
|
* Analyse given BBCode definition for issues and safeness
|
||||||
*
|
*
|
||||||
* Required elements in the return array:
|
* Required elements in the return array:
|
||||||
* - status:
|
* - status: see BBCODE_STATUS_* constants
|
||||||
* - "safe" The BBCode is valid and can be safely used by anyone.
|
|
||||||
* - "unsafe" The BBCode is valid but may be unsafe to use.
|
|
||||||
* - "invalid_definition" There is an issue with the definition.
|
|
||||||
* - "invalid_template" There is an issue with the template.
|
|
||||||
*
|
*
|
||||||
* Optional elements in the return array:
|
* Optional elements in the return array:
|
||||||
* - name: Name of the BBCode based on the definition. Required if status is "safe".
|
* - name: Name of the BBCode based on the definition. Required if status is "safe".
|
||||||
|
|
|
@ -37,7 +37,7 @@ class acp_utils implements acp_utils_interface
|
||||||
public function analyse_bbcode(string $definition, string $template): array
|
public function analyse_bbcode(string $definition, string $template): array
|
||||||
{
|
{
|
||||||
$configurator = $this->factory->get_configurator();
|
$configurator = $this->factory->get_configurator();
|
||||||
$return = ['status' => 'safe'];
|
$return = ['status' => self::BBCODE_STATUS_SAFE];
|
||||||
|
|
||||||
// Capture and normalize the BBCode name manually because there's no easy way to retrieve
|
// Capture and normalize the BBCode name manually because there's no easy way to retrieve
|
||||||
// it in TextFormatter <= 2.x
|
// it in TextFormatter <= 2.x
|
||||||
|
@ -52,13 +52,13 @@ class acp_utils implements acp_utils_interface
|
||||||
}
|
}
|
||||||
catch (UnsafeTemplateException $e)
|
catch (UnsafeTemplateException $e)
|
||||||
{
|
{
|
||||||
$return['status'] = 'unsafe';
|
$return['status'] = self::BBCODE_STATUS_UNSAFE;
|
||||||
$return['error_text'] = $e->getMessage();
|
$return['error_text'] = $e->getMessage();
|
||||||
$return['error_html'] = $e->highlightNode('<span class="highlight">');
|
$return['error_html'] = $e->highlightNode('<span class="highlight">');
|
||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
$return['status'] = (preg_match('(xml|xpath|xsl)i', $e->getMessage())) ? 'invalid_template' : 'invalid_definition';
|
$return['status'] = (preg_match('(xml|xpath|xsl)i', $e->getMessage())) ? self::BBCODE_STATUS_INVALID_TEMPLATE : self::BBCODE_STATUS_INVALID_DEFINITION;
|
||||||
$return['error_text'] = $e->getMessage();
|
$return['error_text'] = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue