Regular expression and the new template modification system...

Liam W

in memoriam 1998-2020
So, I'm trying to update my addon for xenForo 1.2 and make use of the TMS built in...

Unfortunately, I cannot get it to work. I have chosen PHP callback, but it just doesn't apply :(

I need to match an exact piece of text. I would use a standard find/replace but I need to use variables in the templates so it doesn't work.

Also, I can't use the old hook system as it's been deprecated...

Any ideas?

Liam
 
You could use the old hook system. It's still there. And maybe it will remain for sometime. The disabling of it hasn't really been discussed.

What are you actually trying to do? PHP callback might not be necessary.

My Recent Members add-on uses regular expressions. Use that for a pretty basic one that inserts some code after some existing matching code.
 
You could use the old hook system. It's still there. And maybe it will remain for sometime. The disabling of it hasn't really been discussed.

What are you actually trying to do? PHP callback might not be necessary.

My Recent Members add-on uses regular expressions. Use that for a pretty basic one that inserts some code after some existing matching code.

Are you sure it's still there? When I tried to test my addon out, it didn't work. The template hook code hadn't been inserted at all :/

I'm trying to find the start of a form, add my code before it, and then make sure the start of the form is there again. However, my code is in a template, and it needs template variables to be passed to it...

Edit: Oh, yeah it is there still :P

However, this system would make it cleaner...
 
That's exactly the function my add-on has.

1) There's a template modification that uses a regular expression to include a template after a block of code (a <xen:if statement rather than a form but you'll get the idea).

2) There's a listener which extends the member controller and all that does is a quick query and adds the result of that query in to the view parameters which will then be straight away available in your template.

Download my add-on, install it, change the title and add-on ID, understand what it does and then adjust it to your needs. It seems pretty much exactly what you need.

Obviously the only downside is, if you're using the new TM system then it wil only be compatible with XenForo 1.2.x.
 
Yeah, I'm going to stick with the hooks for now.

Issue is, my addon just can't work with redactor... The redactor variable isn't defined in javascript, like tinymce was :(
 
Yeah, I'm going to stick with the hooks for now.

Issue is, my addon just can't work with redactor... The redactor variable isn't defined in javascript, like tinymce was :(

See this request.

You can try to use this function: var editor = XenForo.getEditorInForm($form);
You need to get the form of the editor you want to use, then you should get the API. I will have to try this the next week for the quotme addon.
 
See this request.

You can try to use this function: var editor = XenForo.getEditorInForm($form);
You need to get the form of the editor you want to use, then you should get the API. I will have to try this the next week for the quotme addon.

How would I get the form? Sorry, I know PHP but javascript is like a foreign language (except the simple parts)...

EDIT: As I am adding the main form in anyway, I just added an ID to the form and all is working well. *sigh of relief*. Thanks!
 
How would I get the form? Sorry, I know PHP but javascript is like a foreign language (except the simple parts)...

What is your plugin? If there's a trigger button somewhere for each editors (for example a button), you can have access to the active editor since it will be the closest to the trigger element. If there's no trigger button, I don't see any solution. I thought I've read a way to get the current active editor with Redactor but it seems I've mistaken. I can't find anything in the api.

So if there's a trigger button, this is basic jQuery. You find your element by its css id or css class or other ways (read the jQuery documentation for this). Let's say your trigger button class is "myTriggerButton", you will have to use something like this:
Code:
$form = $('.myTriggerButon').closest('form');
then:
Code:
var editor = XenForo.getEditorInForm($form);
 
What is your plugin? If there's a trigger button somewhere for each editors (for example a button), you can have access to the active editor since it will be the closest to the trigger element. If there's no trigger button, I don't see any solution. I thought I've read a way to get the current active editor with Redactor but it seems I've mistaken. I can't find anything in the api.

So if there's a trigger button, this is basic jQuery. You find your element by its css id or css class or other ways (read the jQuery documentation for this). Let's say your trigger button class is "myTriggerButton", you will have to use something like this:
Code:
$form = $('.myTriggerButon').closest('form');
then:
Code:
var editor = XenForo.getEditorInForm($form);

Yeah, but my button was in a different form to the editor, so yeah :P

Did manage to get it working though, thanks!
 
Top Bottom