MyBB Community Forums

Full Version: AJAX chat as shoutbox
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello.
I have a problem with creating shoutbox out of AJAX chat.

I downloaded AJAX chat from here: https://blueimp.net/ajax/
It is supposed to work well also as a shoutbox on MyBB forums.
I read through the readme file, AJAX Chat Wiki, I was looking for an answer at this forum (e.g. this thread) and at some other forums as well and I couldn't find one.

That's the part of readme file which says about "shoutbox function":
Shoutbox:
=========
	
AJAX Chat is also usable as shoutbox - this is a short guide on how to set it up:


1. Shoutbox stylesheet
----------------------

Add the following line to the stylesheet (CSS) of all pages displaying the shoutbox:

@import url("http://example.org/path/to/chat/css/shoutbox.css");

Replace http://example.org/path/to/chat/ with the URL to the chat.
Modify css/shoutbox.css to your liking.


2. Shoutbox function
--------------------

Add the following function to your PHP code:

<?php
function getShoutBoxContent() {
	// URL to the chat directory:
	if(!defined('AJAX_CHAT_URL')) {
		define('AJAX_CHAT_URL', <<MYBB_ROOT>>'./chat/');
	} <<$mybb, $orig_dir, $db, $base_url>>
	
	// Path to the chat directory:
	if(!defined('AJAX_CHAT_PATH')) {
		define('AJAX_CHAT_PATH', realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/chat').'/');
	}
	
	// Validate the path to the chat:
	if(@is_file(AJAX_CHAT_PATH.'lib/classes.php')) {
		
		// Include Class libraries:
		require_once(AJAX_CHAT_PATH.'lib/classes.php');
		
		// Initialize the shoutbox:
		$ajaxChat = new CustomAJAXChatShoutBox();
		
		// Parse and return the shoutbox template content:
		return $ajaxChat->getShoutBoxContent();
	}
	
	return null;
}
?>

Make sure AJAX_CHAT_URL and AJAX_CHAT_PATH point to the chat directory.


2. Shoutbox output
------------------

Display the shoutbox content using the shoutbox function:

<div style="width:200px;"><?php echo getShoutBoxContent(); ?></div>
Can you tell me, step by step, what should I do? In which files should I put this codes? Should I change something in them or not?
I tried adding the code from the first point to global.css (through ACP>Templates&Styles>Themes>Default>), adding the code from second point to functions.php and adding code from third point to the footer of my forum. But it didn't work.

If it can be of any help, here is an instruction on how to integrate the AJAX Chat shoutbox with phpBB3 forum.

Link to my forum (test forum, that's why it's nothing in there): http://inwgaz.unl.pl/
Link to chat directory: http://inwgaz.unl.pl/chat/

Thanks for help
m_i-k_i
Admin CP > Themes & Style > Templates > THEME > Header Templates > ** EXPAND ** > Add this:
<style type="text/css">
@import url("http://example.org/path/to/chat/css/shoutbox.css");
</style>

Add this at the bottom of inc/functions.php:
function getShoutBoxContent() {
    // URL to the chat directory:
    if(!defined('AJAX_CHAT_URL')) {
        define('AJAX_CHAT_URL', MYBB_ROOT.'./chat/');
    }
    
    // Path to the chat directory:
    if(!defined('AJAX_CHAT_PATH')) {
        define('AJAX_CHAT_PATH', realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/chat').'/');
    }
    
    // Validate the path to the chat:
    if(@is_file(AJAX_CHAT_PATH.'lib/classes.php')) {
        
        // Include Class libraries:
        require_once(AJAX_CHAT_PATH.'lib/classes.php');
        
        // Initialize the shoutbox:
        $ajaxChat = new CustomAJAXChatShoutBox();
        
        // Parse and return the shoutbox template content:
        return $ajaxChat->getShoutBoxContent();
    }
    
    return null;
}

Add this somewhere in index.php:
ereg("$shoutbox = \"<div style=\"width:200px;\">".getShoutBoxContent()."</div>\"");

Then where you want the shoutbox to show, add {$shoutbox}

Hope that works. - Tom
Thanks for quick answer.
Sadly it didn't work.

I did everything you said, triple checked it.
I tried putting css url in different header places but nothing happened.
I also tried adding code to index.php in different places. What's strange when I put it at the end of index.php (just before ?>) nothing happens. But if I put it somewhere else, e.g. near the beginning (line 28, just before // Load global language phrases) I got that error message "Warning [2] Wrong parameter count for ereg() - Line: 28 - File: index.php PHP 5.2.8 (Linux)" and similar when in other lines.

m_i-k_i

EDIT
Wait, wait. Maybe I found my mistake...
...
No. I found a mistake (i just copied and paste the css url) but it didn't help.
Sorry, change ereg to eval.
Still nothing. Except next error message: "Parse error: syntax error, unexpected '=' in /home/inwgaz/domains/inwgaz.unl.pl/public_html/index.php(27) : eval()'d code on line 1"
Hm. I'm not sure, then.Sad Sorry, wish I could help more.
That's OK. Thanks for very fast response.
Maybe someone else knows what to do?
No news about this?
Then where you want the shoutbox to show, add {$shoutbox}

That part, how i should add it can you give me exact code. Like

line 36: {$shoutbox};

Like that?