[HowTo] Add mChat on any page of your board

Support area for phpBB's mChat extension
User avatar
kasimi
mChat developer
Posts: 738
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

[HowTo] Add mChat on any page of your board

#1

Post by kasimi » 14 Jan 2017, 20:23

These steps will guide you through the process of adding mChat to another page of your board. You can also add mChat to pages of other extensions. It should only take a few moments!

This is a good example for all extension authors who want to display mChat on their extension's own pages. If this doesn't apply to you you should consider creating a bridge extension instead. While the code below should work in all cases, using a bridge extension is a cleaner approach and definitely recommended. For a complete example of such a bridge extension have a look at the mChat in Forums & Topics add-on. It also shows you how to add an option to the UCP.

Note that the following code requires at least mChat 2.0.0-RC6 to be installed.
  1. First you need to figure out which code/function is called on the page where you want to add mChat. It is vital to pick a function that is as specific as possible. For example using the page_header() function is a bad idea: it would slow down your board as mChat would be rendered on every single request, so don't do that, unless you really want to add mChat to every single page.

    Let's say you want to add mChat to the FAQ page. Open faq.php and add the following code near the end of the file, right before the call to page_footer();:

    Code: Select all

    global $phpbb_container, $user, $auth, $template;
    if ($phpbb_container->has('dmzx.mchat.settings') && $auth->acl_get('u_mchat_view'))
    {
        // We use the page_index() method to render mChat so we need
        // to enable mChat on the index page only for this request
        $user->data['user_mchat_index'] = 1;
        $phpbb_container->get('dmzx.mchat.settings')->set_cfg('mchat_index', 1, true);
        $phpbb_container->get('dmzx.mchat.core')->page_index();
        $template->assign_var('MCHAT_PAGE', 'mchat_on_faq_page');
    } 
    This code first checks if mChat is available at all so that there are no errors if you ever disable or uninstall mChat. You can add more conditions to this if statement. For example, if you only want a certain group to see mChat in the FAQ, you can do this:

    Code: Select all

    if ($phpbb_container->has('dmzx.mchat.settings') && $user->data['group_id'] == 5)
    Inside the if block the "Display mChat on the index" setting is temporarily overwritten in case the user has disabled mChat on the index page. In the last two lines mChat is rendered and a variable is assigned to the template, signaling that this is a special page.
  2. Now that mChat is assigned to the template you are ready to render it. Find a good spot in your template files to display mChat and add this code. For the FAQ page we want it right below the title, so let's open styles/prosilver/template/faq_body.html and add the code after <h2 class="faq-title">{L_FAQ_TITLE}</h2>:

    Code: Select all

    <!-- IF MCHAT_PAGE == 'mchat_on_faq_page' -->
       <!-- INCLUDE @dmzx_mchat/mchat_body.html -->
    <!-- ENDIF --> 
    This code uses the template variable from the first step to check if mChat actually is assigned, and then includes mChat's main template file.
And that's all. If you have any trouble following these steps don't hesitate to post here. :+1:

User avatar
FranckTH
Distinguished Donor
Posts: 24
Joined: 19 Nov 2016, 12:59
Location: Champagne (France)
Contact:

Re: [HowTo] Add mChat on any page of your board

#2

Post by FranckTH » 15 Jan 2017, 10:46

Thanks kasimi, very nice tutorial ;)
Flash & HTML5 Games for the Best Arcade

User avatar
Scanialady
Posts: 14
Joined: 29 Oct 2016, 11:48

Re: [HowTo] Add mChat on any page of your board

#3

Post by Scanialady » 16 Jan 2017, 18:52

KillBill is working on an update for arcade. May be he can repair the cutted interfaces to mChat. (Earlier versions of mChat have worked fine with arcade. Seems you have changed something...)
I saw a note that he will try to set new interfaces.
German Translation - (http://ladyscommunity.de)

User avatar
kasimi
mChat developer
Posts: 738
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: [HowTo] Add mChat on any page of your board

#4

Post by kasimi » 16 Jan 2017, 21:43

I don't know how he included mChat in the past but doing it as shown above will most likely not break anything, mChat will display just fine. If he (or anyone else) has problems getting it running he can post here and I'll be glad to assist him.

A small addition: for extension authors it is recommended to use dependency injection to get access to the dmzx.mchat.settings and dmzx.mchat.core services, and not use the $phpbb_container at all.

User avatar
Scanialady
Posts: 14
Joined: 29 Oct 2016, 11:48

Re: [HowTo] Add mChat on any page of your board

#5

Post by Scanialady » 23 Jan 2017, 21:14

There is a new version of arcade now for 3.2.x
mChat is now working with arcade (shows scores)
German Translation - (http://ladyscommunity.de)

User avatar
kasimi
mChat developer
Posts: 738
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: [HowTo] Add mChat on any page of your board

#6

Post by kasimi » 24 Jan 2017, 11:21

Good to know, thanks for the update. :+1:

faroud
Posts: 13
Joined: 02 Apr 2017, 09:25
Location: belgium
Contact:

Re: [HowTo] Add mChat on any page of your board

#7

Post by faroud » 02 Apr 2017, 09:27

mchat does not work on arcade?
will see an error
which redirect to another site
there is an error in their solution
greets

User avatar
kasimi
mChat developer
Posts: 738
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: [HowTo] Add mChat on any page of your board

#8

Post by kasimi » 02 Apr 2017, 09:47

I'm not familiar with Arcade. You should ask KillBill for support. :+1:

faroud
Posts: 13
Joined: 02 Apr 2017, 09:25
Location: belgium
Contact:

Re: [HowTo] Add mChat on any page of your board

#9

Post by faroud » 02 Apr 2017, 15:49

and they give you link here?
okay good
regards

User avatar
FranckTH
Distinguished Donor
Posts: 24
Joined: 19 Nov 2016, 12:59
Location: Champagne (France)
Contact:

Re: [HowTo] Add mChat on any page of your board

#10

Post by FranckTH » 31 Mar 2018, 10:53

this snippet works with older version but not with the mchat 2.0.3 version ?
Flash & HTML5 Games for the Best Arcade

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest