We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10405
    • 288 Posts
    Hi, I've been looking for a system / plugin that can be integrated with Revo 2.2x which will allow logged in users to go a "chat page" where they can chat in real time and the page / screen updates automatically.
    The administrator will also need to be able to collect and archive the various info posted here.
    It doesn't need to be anything more than the chat system remembers the logged-in user's username and allows them to type text and chat with other users who are logged in.
    I don't want to be giving access via the backend so it needs to be in the web context and I will probably grant them access to the page using Login.

    Anyone know of any chat systems for MODx that will do this?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I installed the [url=http://mibew.org/]webim live support script very easily. While it's not exactly what you have in mind, any chat script should work just as well. A few snippets to load the script only if the user is logged in, and to supply user data to the chat script, were no trouble at all.

      Here are a few you might find interesting http://www.jquery4u.com/widgets/10-crazy-jquery-chat-chat-box-plugins/
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 10405
        • 288 Posts
        Quote from: sottwell at Jan 16, 2013, 10:39 AM
        I installed the [url=http://mibew.org/]webim live support script very easily. While it's not exactly what you have in mind, any chat script should work just as well. A few snippets to load the script only if the user is logged in, and to supply user data to the chat script, were no trouble at all.

        Here are a few you might find interesting http://www.jquery4u.com/widgets/10-crazy-jquery-chat-chat-box-plugins/

        Thanks, which snippets / plugins would I use to test that the user's logged in (or, if the page with the script was in a restricted resource group, would it be needed at all?) and what would I use to supply the user's login to the chat script? I would think if it was JQuery or similar it might not like the MODX syntax (if I had to put [[!Profile]] or something like that into it??
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          It's just Javascript. You can use MODx tags in Javascript in your template or resource. If necessary, use a snippet that returns the Javascript with the required information. For example, for the live chat I did, I used this snippet (this is for Evo, but the principle is the same for Revo) so the chat button is only displayed if the user is logged in. You could also check for group if that were important.
          <?php
          if($_SESSION['webValidated'] == 1) {
              $name = $_SESSION['webShortname'];
              $email = $_SESSION['webEmail'];
              $chunkArr = array(
                  'name' => $name,
                  'email' => $email
              );
              $output = $modx->parseChunk('chatbox', $chunkArr, '[+', '+]');
          }
          return $output;
          ?>

          then used this chunk, which is straight from the webim docs, with placeholders added to load the snippet's results (name and email):
          <div id="chatbox">
          <!-- webim button --><a href="/webim/client.php?locale=en" target="_blank" onclick="if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 && window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open('/webim/client.php?locale=en&url='+escape(document.location.href)+'&referrer='+escape(document.referrer)+'&name='+escape('[+name+]')+'&email='+escape('[+email+]'),'webim','toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=723,height=512,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;"><img src="/webim/b.php?i=simple&lang=en" border="0" alt=""/></a><!-- / webim button -->
          </div>
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 10405
            • 288 Posts
            Thanks, what would I use instead of webShortName, webEmail etc. though? I would be validating users using Login and then try to capture their username and make them use that when they start a chat session. Could I just do this in the snippet and add it to the page:

            [[!Profile]]
            $name = [[+username]];
            

            [ed. note: galahad5 last edited this post 13 years, 9 months ago.]
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              For Revo, you can get the user details using the modUser object. http://rtfm.modx.com/display/revolution20/Users#Users-UsersUserSettings
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 10405
                • 288 Posts
                Well, I sort of got it working with a single user logging in and then chatting to the admin, although the Mibew application still asks for them to pick a username so it clearly isn't picking up their login (although strangely enough it does get outputted on the welcome page where the chat button is).

                I used this for the snippet:

                <?php
                $name = $modx->user->get('username');
                return $name;
                ?>
                


                And used this for the chunk:

                <div id="chatbox">
                <!-- webim button -->
                <a href="webim/client.php?locale=en" target="_blank" onclick="if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 && window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open('webim/client.php?locale=en&url='+escape(document.location.href)+'&referrer='+escape(document.referrer)+'&name='+escape('[+name+]'),'webim','toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=723,height=512,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;"><img src="webim/b.php?i=simple&lang=en" border="0" alt=""/></a>
                <!-- / webim button -->
                </div>
                


                And called them in the page template as follows:

                <html>
                <head>
                <title>[[++site_name]] - [[*pagetitle]]</title>
                <base href="[[++site_url]]" />
                </head>
                <body>
                [[!chatusername]]
                [[$chatbutton]]
                [[*content]]
                </body>
                </html>
                


                So not sure why it isn't picking up the username and using that for the chat.

                I'm not sure if it'll work that well anyway unless I can have multiple users joining the same chat... can't see a way of getting it to do that? I looked at others such as phpfreechat but can't see how that can be configured in the same way...
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  The webim is definitely just a one-on-one chat; I was describing it as an example.

                  Your issue with the name is because that's an Evo placeholder; you need to replace the
                  &name='+escape('[+name+]'),
                  with
                  &name='+escape('[[+name]]'),
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 10405
                    • 288 Posts
                    Ok thanks. I tried doing the equivalent thing with phpfreechat, but it just gives a blank page if I try to place the index page code in MODx:

                    Template:

                    <html>
                    <head>
                    <title>[[++site_name]] - [[*pagetitle]]</title>
                    <base href="[[++site_url]]" />
                    [[!chatheader]]
                    </head>
                    <body>
                    [[!chat]]
                    [[*content]]
                    </body>
                    </html>
                    


                    The chat header is from the top of the phpfreechat index.php:

                    <?php
                    require_once "chat/src/phpfreechat.class.php";
                    $name = $modx->user->get('username');
                    return $name;
                    
                    $params = array();
                    $params["title"] = "Quick chat";
                    //$params["nick"] = "guest".rand(1,1000);  // setup the intitial nickname
                    $params["nick"] = $name;
                    //$params['firstisadmin'] = true;
                    //$params["isadmin"] = true; // makes everybody admin: do not use it on production servers ;)
                    $params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
                    $params["debug"] = false;
                    $chat = new phpFreeChat( $params );
                    ?>
                    


                    And then the chat is called in a snippet in the body of the template:

                    <?php
                    $chat->printChat();
                         if (isset($params["isadmin"]) && $params["isadmin"]) 
                            { 
                        echo '<p style="color:red;font-weight:bold;">Warning: because of "isadmin" parameter, everybody is admin. Please modify this script before using it on production servers !</p>';
                            }
                    ?>
                    


                    Maybe it isn't possible to split the phpfreechat code into snippets, I don't know. However if I jst upload it and browse to the index.php it works out of the box.

                    Anyone have anyu experience trying to get this chat software to work with MODx?

                    Or are there any other (more configurable) chat apps that definitely WILL work with MODx?
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Your "return $name" is going to stop the snippet in its tracks. That's what the return directive does; stops the function (or in our case the snippet) and returns what you tell it to.

                      You should be able to set the name (comment out their random setting and use yours), then disable the code to allow the user to select his own name.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org