Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-13648

Allow extensions using custom bbcode validation methods

    Details

    • Type: Improvement
    • Status: Unverified Fix
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1.3, 3.2.0-dev
    • Fix Version/s: 3.1.5-RC1
    • Component/s: Events, Extensions
    • Labels:
      None

      Description

      Currently extensions can custom bbcode data to bbcodes array in the function bbcode_init() in includes/message_parser.php using core.modify_bbcode_init event.
      But they can't use their own validation methods like the core does:

      'code'			=> array('bbcode_id' => 8,	'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#uise' => "\$this->bbcode_code('\$1', '\$2')")),

      The idea is to declare $phpbb_container as a global in the function parse_bbcode() to allow extensions adding custom validation methods for bbcodes, f.e.

      'code'			=> array('bbcode_id' => 8,	'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#uise' => "\$phpbb_container->get('vendor.extension.class')->custom_bbcode_validator('\$1', '\$2')")),

      Also the same possibility would be logical to add to the bbcode second pass procedure (includes/bbcode.php).

        Issue Links

          Activity

          Hide
          JoshyPHP JoshyPHP added a comment -

          core.modify_bbcode_init doesn't trigger anymore in 3.2. You can use core.text_formatter_s9e_configure_after to configure the s9e\TextFormatter library to validate or filter attribute values with your own callbacks.

          Describe your use case at https://www.phpbb.com/community/viewtopic.php?f=461&t=2309881 and I'll use it as a tutorial for extension authors.

          Show
          JoshyPHP JoshyPHP added a comment - core.modify_bbcode_init doesn't trigger anymore in 3.2. You can use core.text_formatter_s9e_configure_after to configure the s9e\TextFormatter library to validate or filter attribute values with your own callbacks. Describe your use case at https://www.phpbb.com/community/viewtopic.php?f=461&t=2309881 and I'll use it as a tutorial for extension authors.
          Hide
          rxu Ruslan Uzdenov added a comment - - edited

          core.modify_bbcode_init doesn't trigger anymore in 3.2.

          I guess it does? https://github.com/phpbb/phpbb/blob/master/phpBB/includes/message_parser.php#L186-L195
          Or do I miss something...

          Show
          rxu Ruslan Uzdenov added a comment - - edited core.modify_bbcode_init doesn't trigger anymore in 3.2. I guess it does? https://github.com/phpbb/phpbb/blob/master/phpBB/includes/message_parser.php#L186-L195 Or do I miss something...
          Hide
          JoshyPHP JoshyPHP added a comment -

          The class still exists but it's not used anymore. New posts are parsed via the text_formatter.parser service.

          Show
          JoshyPHP JoshyPHP added a comment - The class still exists but it's not used anymore. New posts are parsed via the text_formatter .parser service.
          Hide
          rxu Ruslan Uzdenov added a comment -

          Ok. The idea was to allow using some custom bbcode validation callbacks for special cases like moderator/administrator/etc bbcode which decides what to return depending on additional conditions (based on permissions, user type, user group and so on). Like (very generally to get an idea)

                   'mybbcode'            => array('bbcode_id' => $this->id,   'regexp' => array('#\[mybbcode\](.*?)\[/mybbcode\]#uise' => "\$this->bbcode_mybbcode('\$1')")),

          function bbcode_mybbcode($text)
          {
              if ($this->auth->acl_get('m_'))
              {
                  return '[mybbcode]' . $text . '[/mybbcode]';
              }
              else
              {
                  return $text;
              }
          }
          

          Show
          rxu Ruslan Uzdenov added a comment - Ok. The idea was to allow using some custom bbcode validation callbacks for special cases like moderator/administrator/etc bbcode which decides what to return depending on additional conditions (based on permissions, user type, user group and so on). Like (very generally to get an idea) 'mybbcode' => array ( 'bbcode_id' => $this ->id, 'regexp' => array ( '#\[mybbcode\](.*?)\[/mybbcode\]#uise' => "\$this->bbcode_mybbcode('\$1')" )), function bbcode_mybbcode( $text ) { if ( $this ->auth->acl_get( 'm_' )) { return '[mybbcode]' . $text . '[/mybbcode]' ; } else { return $text ; } }
          Hide
          JoshyPHP JoshyPHP added a comment -

          Ok, this one is actually pretty simple. This isn't really about validation per se, it's about toggling BBCodes depending on the current user. You can see a similar example in the ABBC3 extension which uses the core.text_formatter_s9e_parser_setup event to disable some BBCodes before parsing.

          However, I am concerned with the assumption that the current user is always the author of a text being parsed. This becomes a liability if posts are being reparsed. I touched on it in that topic about reparsing.

          I'm going to think about it and develop a more complete answer in this topic in the Extensions Writers Discussion forum.

          Show
          JoshyPHP JoshyPHP added a comment - Ok, this one is actually pretty simple. This isn't really about validation per se , it's about toggling BBCodes depending on the current user. You can see a similar example in the ABBC3 extension which uses the core.text_formatter_s9e_parser_setup event to disable some BBCodes before parsing. However , I am concerned with the assumption that the current user is always the author of a text being parsed. This becomes a liability if posts are being reparsed. I touched on it in that topic about reparsing . I'm going to think about it and develop a more complete answer in this topic in the Extensions Writers Discussion forum .

            People

            • Assignee:
              nickvergessen Joas Schilling
              Reporter:
              rxu Ruslan Uzdenov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development