kasimi / mChat

Extension for phpBB 3.1, 3.2 and 3.3 that adds a chat to your board.
https://www.phpbb.com/customise/db/extension/mchat_extension/
GNU General Public License v2.0
9 stars 17 forks source link

Conflict with other extensions due to uncontained jquery .find() method #24

Closed blitze closed 6 years ago

blitze commented 6 years ago

In the below-referenced line, you find all hidden inputs in order to get the form key, etc but it is too general and will conflict with other extensions if they also have a form key. This results in not being able to chat as mchat ends up with the wrong form token. Please restrict the .find() to just the mchat container, as opposed to searching for hidden fields on the entire page.

https://github.com/kasimi/mChat/blob/1e564e06cc30d2bc8d8f4debdbbb1d24e1e15448/styles/all/template/javascript/mchat.js#L645

kasimi commented 6 years ago

Thanks for the report!

The .cached('form') function in the line you quoted returns the element #mchat-form, which means mChat is already looking only within the mChat container for the hidden fields.

Instead, the problem is phpBB's limited capability of rendering multiple form tokens on the same page: calling the add_form_key() function overwrites the S_FORM_TOKEN template varible of any previous call to it. In your specific case, the SiteMaker form tokens end up being rendered not just in your form, but also in mChat's form, which breaks mChat.

Prior to phpBB 3.1.11, fixing this was impossible. With this change in 3.1.11, which is also included since phpBB 3.2.0, it is possible for extensions to change the template variable name of the form tokens:

if ($event['form_name'] == 'your_extension_form_name')
{
    $event['template_variable_suffix'] = '_VENDOR_EXT';
}

Now you can use {{ S_FORM_TOKEN_VENDOR_EXT }} in your template files to render the form tokens.

The latest approved mChat version 2.0.3 doesn't do this, but the upcoming release 2.1.0 does.

If you can live with dropping support for phpBB < 3.1.11, I recommend you do the same in your extension to prevent this from happening with other extensions.

blitze commented 6 years ago

Ah! Sorry, my mistake. I did not realize that. Thanks for pointing me in the right direction. I will go ahead and close this issue.

Thanks again