Loop Through {TEXT} With Regex Replacement

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Feyd_Ruin
Registered User
Posts: 3
Joined: Tue Jun 04, 2019 2:04 am

Loop Through {TEXT} With Regex Replacement

Post by Feyd_Ruin » Sun Jun 16, 2019 2:41 am

Good Evening!

I'm writing a small extension that adds a new, complex, BBCode for our forum.
But I need to be able to loop through the bbcode's {TEXT} input in order to test it against a regular expression and modify it accordingly.

(Aside: if there's a way to preg_replace or loop through characters/lines with xsl in the admin bbcode, that could work as well).

I've gotten the tag added just fine, and it works:

Code: Select all

class main_listener implements EventSubscriberInterface {
	public static function getSubscribedEvents() {
		return array(
            'core.text_formatter_s9e_configure_after'       => 'configure_cardtags'
		);
	}
	
	public function configure_cardtags($event) {
        // Get the BBCode configurator
        $configurator = $event['configurator'];

        // Let's create the new BBCode
        $configurator->BBCodes->addCustom(
            '[deck]{TEXT}[/deck]',
            '<div class="decklist"><div class="decklist_head">Decklist</div><div class="decklist_body">{TEXT}</div></div>'
        );
    }
}
I believe I now need add a filterChain to my tag but I'm not sure how to get the {TEXT} ( or $in value ? ) for the tag, modify it, and return it.

Any help would be most appreciated, as I've been struggling with how s9e/vb3 now does things for some time.

Feyd_Ruin
Registered User
Posts: 3
Joined: Tue Jun 04, 2019 2:04 am

Re: Loop Through {TEXT} With Regex Replacement

Post by Feyd_Ruin » Sun Jun 16, 2019 5:29 am

It's been a common theme that just as soon as I ask something, I figure it out.
I should really start asking sooner.

For those who come here and want the answer:
add the following listeners:

Code: Select all

			'core.modify_text_for_display_before'		=> 'YOUR_FUNCTION_NAME',
			'core.modify_format_display_text_after'		=> 'YOUR_FUNCTION_NAME',
Then add your function to modify the $event["text"]

Code: Select all

	public function deck_display_before($event)
	{
		//Make every post all lower case.
		//Because this is a fun example.
		$event['text'] = strtolower($event['text']);
	}
Be warned that the new way the text is stored is much different from previous versions, and much of what you'll find (currently) googling will be wrong.

A standard tag, for instance, will be stored and in $event['text'] as <B><s></s>bolded text<e></e></B>
You'll have to adjust your regular expressions to match accordingly.

rxu
Extensions Development Team
Posts: 2932
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Loop Through {TEXT} With Regex Replacement

Post by rxu » Sun Jun 16, 2019 5:55 am


Post Reply

Return to “Extension Writers Discussion”