## PHPBB3-13803 / PHPBB3-13891 - Reparsing text

Discuss requests for comments/changes posted in the Issue Tracker for the development of phpBB. Upcoming releases are 3.2/Rhea and 3.3.
JoshyPHP
Registered User
Posts: 364
Joined: Fri Jul 08, 2011 9:43 pm

### Re: PHPBB3-13803 / PHPBB3-13891 - Reparsing text

Here's the short version. You need to create a service and tag it as text_reparser.plugin. The content will automatically be reparsed when a global reparsing is executed. Check out config/default/container/services_text_reparser.yml.

If the text is in a database row with a unique ID then you can extend phpbb\textreparser\row_based_plugin like phpbb\textreparser\plugins\pm_text does.
• get_columns() maps record field names to column names. It must contain at least three elements: id, text and bbcode_uid.
• get_table_name() returns the table's name.
Everything else will be taken care of. It's the easiest way to implement this service.

Otherwise, you need to extend phpbb\textreparser\base like phpbb\textreparser\plugins\poll_option does.
• get_max_id() must return the highest ID for the content.
• get_records_by_range() must return a list of records.
• save_record() is called with the updated record.
A record is a simple array. It must contain at least two elements: text and bbcode_uid. If it's a row-based plugin as described above, it must contain id too. It can optionally contain the following elements:
• enable_bbcode
• enable_smilies
• enable_magic_url
• enable_flash_bbcode
• enable_img_bbcode
• enable_quote_bbcode
• enable_url_bbcode
• options, which should contains an integer used as a bitfield where the OPTION_FLAG_BBCODE, OPTION_FLAG_SMILIES and OPTION_FLAG_LINKS bits toggle the corresponding feature
A record can contain any other field that you may want to use in save_record().

JoshyPHP
Registered User
Posts: 364
Joined: Fri Jul 08, 2011 9:43 pm

### Re: PHPBB3-13803 / PHPBB3-13891 - Reparsing text

VSE wrote:
Wed Jul 15, 2015 6:59 pm
This is what I came up with: https://github.com/VSEphpbb/boardrules/ ... 08038c4d7f
The reparser seems fine. You should be able to run it individually via CLI with ./bin/phpbbcli.php reparser:reparse phpbb.boardrules.text_reparser.rule_text.

Code: Select all

\$ ./bin/phpbbcli.php reparser:reparse phpbb.boardrules.text_reparser.rule_text
Reparsing phpbb.boardrules.text_reparser.rule_text (range 1..3)
---------------------------------------------------------------

0/3 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░    0%
3/3 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓  100%  19.0 MiB
Reparsing phpbb.boardrules.text_reparser.rule_text (range 1..3)  1 sec/1 sec  20.5 MiB

[OK] Reparsing ended with success

aleha
Registered User
Posts: 143
Joined: Tue Mar 26, 2013 2:19 am

### Re: PHPBB3-13803 / PHPBB3-13891 - Reparsing text

Does Ticket-12554 have to do with text formatting or bbcode engine?

JoshyPHP
Registered User
Posts: 364
Joined: Fri Jul 08, 2011 9:43 pm

### Re: PHPBB3-13803 / PHPBB3-13891 - Reparsing text

No, it's a styling issue. As I commented on the ticket, the markup is correct (in 3.2 for sure, and probably in 3.1 too) and the bullet appears if styles/prosilver/theme/stylesheet.css is removed.

Elsensee
Development Team
Posts: 41
Joined: Sun Mar 16, 2014 1:08 pm
Location: Hamburg, Germany
Contact:

### Re: PHPBB3-13803 / PHPBB3-13891 - Reparsing text

Sorry, I might be a bit late for this, but...

I just looked through the reparser. (like I said - a bit late ^^)
The tables are defined as constants, which will result in another BC break, if we want to get rid of constants at some point. (I think this is the final goal of all this?)

Why would it result in another BC break?
The abstract class phpbb\textreparser\row_based_plugin has to be changed. (The constructor, to be more specifc)
And as some extensions might have classes that extend this class, the config.yml would have to be changed too. => BC break. We don't want that anymore. Break it once, then leave it untouched. Please.

rxu
Registered User
Posts: 126
Joined: Tue Apr 04, 2006 4:28 pm
Contact:

### Re: PHPBB3-13803 / PHPBB3-13891 - Reparsing text

JoshyPHP, what would be the best way to adjust reparser so that we could pass to event the reparser plugin name being used?

JoshyPHP
Registered User
Posts: 364
Joined: Fri Jul 08, 2011 9:43 pm

### Re: PHPBB3-13803 / PHPBB3-13891 - Reparsing text

To any event? That would probably be the wrong way to go at it. What is it you're trying to achieve?

rxu
Registered User
Posts: 126
Joined: Tue Apr 04, 2006 4:28 pm
Contact:

### Re: PHPBB3-13803 / PHPBB3-13891 - Reparsing text

Well, in mediaembed extension we're trying to prevent signatures from reparsing media links in them. The point is to catch the reparser plugin name in the listener (say, user_signature) to disable the media tag while reparsing.

JoshyPHP
Registered User
Posts: 364
Joined: Fri Jul 08, 2011 9:43 pm

### Re: PHPBB3-13803 / PHPBB3-13891 - Reparsing text

I think that the correct way to do it would be a big overhaul of message_parser and the generate_text_for_* functions into a unified API that supports some sort of contextual configuration that would allow the text to be treated differently depending on whether it's from a post, a signature, etc...

For a more immediate solution, reparser_interface could be extended to some sort of get_parsing_mode() function, the return value of which would be passed to generate_text_for_storage(). Currently, it is hardcoded to "reparse", which, in hindsight, is not a good value. phpbb\textreparser\base::get_parsing_mode() could return "post" by default and the user_signature plugin would return the appropriate value instead. As I recall, that value is already present in the relevant events.

rxu
Registered User
Posts: 126
Joined: Tue Apr 04, 2006 4:28 pm
Contact:

### Re: PHPBB3-13803 / PHPBB3-13891 - Reparsing text

Thanks. At the brief look, it seems that 'reparse' mode name is not used later anywhere in the code, so changing it to reparser plugin name shouldn't hurt.