You are here

protected static function ListTagPlugin::validateStyle in Extensible BBCode 4.0.x

Same name and namespace in other branches
  1. 8.3 standard/src/Plugin/XBBCode/ListTagPlugin.php \Drupal\xbbcode_standard\Plugin\XBBCode\ListTagPlugin::validateStyle()

Validate a style directive.

Parameters

string $style: The user-entered style directive.

Return value

array An array with two elements:

  • A boolean that is TRUE if the style is numbered, otherwise FALSE.
  • The style, if it is valid.
1 call to ListTagPlugin::validateStyle()
ListTagPlugin::buildElement in standard/src/Plugin/XBBCode/ListTagPlugin.php
Build a render array from the tag.

File

standard/src/Plugin/XBBCode/ListTagPlugin.php, line 70

Class

ListTagPlugin
Renders a list.

Namespace

Drupal\xbbcode_standard\Plugin\XBBCode

Code

protected static function validateStyle(string $style) : array {

  // The predefined un-ordered styles.
  if (in_array($style, [
    'disc',
    'circle',
    'square',
    'none',
  ], TRUE)) {
    return [
      FALSE,
      $style,
    ];
  }

  // If the style contains no HTML characters, decode any character entities.
  if (!preg_match('/\'"<>/', $style)) {
    $style = Html::decodeEntities($style);
  }
  $style = trim($style);

  // Match any quoted string.
  if (preg_match('/
    (?\'quote\'[\'"])
      \\\\
      (?:
        [0-9a-fA-F]{1,6}  # 1-6 hex digits preceded by a backslash.
        |
        [^0-9a-fA-F]      # any other character preceded by a backslash.
      )
      |
      (?!\\k\'quote\')[^\\\\] # any permissible non-backslash character.
    \\k\'quote\'
    /x', $style)) {
    return [
      FALSE,
      $style,
    ];
  }

  // Match any expression.
  if (preg_match('/
    (?:
      [^"\';]             # anything other than quotes or semicolon.
      |
      \\\\
      (?:
        [0-9a-fA-F]{1,6}  # 1-6 hex digits preceded by a backslash.
        |
        [^0-9a-fA-F]      # any other character preceded by a backslash.
      )
      |
      (?\'quote\'[\'"])
        \\\\
        (?:
          [0-9a-fA-F]{1,6}  # 1-6 hex digits preceded by a backslash.
          |
          [^0-9a-fA-F]      # any other character preceded by a backslash.
        )
        |
        (?!\\k\'quote\')[^\\\\] # any permissible non-backslash character.
      \\k\'quote\'
    )*
    /x', $style)) {
    return [
      TRUE,
      $style,
    ];
  }
  return [
    FALSE,
    '',
  ];
}