Your phpBB Type: Standard phpBB3
MODs installed: No
Your knowledge: Beginner
What have you done before the problem was there?
No problem trying to solve how to pass phpbb forum user name to java script inside custom block
What have you already tryed to solve the problem?
I am trying to add a simple javascript chat. Basically it is a link that opens a java popup window and launches Yaplet a simple chat.
I have tried several variations but here is the basics.
First I know zero about php, or phpbb and the fundamentals of code.
Note: the Yaplet javascript works fine in the custom box, when not trying to get the phpbb username.
Note: http://www.vwarrior.us.tf is only a test site I use before installing scripts on main site.
See below.
Description and Message
In custom.php I placed this code to get the phpbb username and assign a variable that the javascript could use.
Note: The code I added is at bottom of this file. In addition, I tried
Code: Select all
"$user->data['username']"
Code: Select all
<?php
/**
*
* @package - Board3portal
* @version $Id: custom.php 325 2008-08-17 18:59:40Z kevin74 $
* @copyright (c) kevin / saint ( www.board3.de/ ), (c) Ice, (c) nickvergessen ( www.flying-bits.org/ ), (c) redbull254 ( www.digitalfotografie-foren.de ), (c) Christian_N ( www.phpbb-projekt.de )
* @based on: phpBB3 Portal by Sevdin Filiz, www.phpbb3portal.com
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
if (!defined('IN_PHPBB'))
{
exit;
}
if (!defined('IN_PORTAL'))
{
exit;
}
$allow_bbcode = 1;
$allow_urls = 1;
$allow_smilies = 1;
// Center Box
if ($portal_config['portal_custom_center'])
{
if ($portal_config['portal_custom_center_bbcode'])
{
$message_parser = new parse_message($portal_config['portal_custom_code_center']);
$message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies);
$text_center = $message_parser->message;
$bbcode_uid = $message_parser->bbcode_uid;
$bbcode_bitfield = $message_parser->bbcode_bitfield;
$bbcode = new bbcode(base64_encode($bbcode_bitfield));
$text_center = censor_text($text_center);
$bbcode->bbcode_second_pass($text_center, $bbcode_uid, $bbcode_bitfield);
$text_center = bbcode_nl2br($text_center);
$text_center = smiley_text($text_center);
$template->assign_vars(array(
'PORTAL_CUSTOM_CENTER_CODE' => $text_center,
));
}
else
{
$template->assign_vars(array(
'PORTAL_CUSTOM_CENTER_CODE' => htmlspecialchars_decode($portal_config['portal_custom_code_center'],ENT_QUOTES),
));
}
$template->assign_vars(array(
'S_CUSTOM_CENTER' => true,
'PORTAL_CUSTOM_CENTER_HEADLINE' => $portal_config['portal_custom_center_headline'],
));
}
// Small Box
if ($portal_config['portal_custom_small'])
{
if ($portal_config['portal_custom_small_bbcode'])
{
$message_parser = new parse_message($portal_config['portal_custom_code_small']);
$message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies);
$text_small = $message_parser->message;
$bbcode_uid = $message_parser->bbcode_uid;
$bbcode_bitfield = $message_parser->bbcode_bitfield;
$bbcode = new bbcode(base64_encode($bbcode_bitfield));
$text_small = censor_text($text_small);
$bbcode->bbcode_second_pass($text_small, $bbcode_uid, $bbcode_bitfield);
$text_small = bbcode_nl2br($text_small);
$text_small = smiley_text($text_small);
$template->assign_vars(array(
'PORTAL_CUSTOM_SMALL_CODE' => $text_small,
));
}
else
{
$template->assign_vars(array(
'PORTAL_CUSTOM_SMALL_CODE' => htmlspecialchars_decode($portal_config['portal_custom_code_small'],ENT_QUOTES),
));
}
$template->assign_vars(array(
'S_CUSTOM_SMALL' => true,
'PORTAL_CUSTOM_SMALL_HEADLINE' => $portal_config['portal_custom_small_headline'],
));
}
$chatname = "$user->data['username']";
$template->assign_vars(array(
'CHATNAME' => $chatname,
));
?>
Code: Select all
<a href="javascript:(function(){window.open('http://embed.yaplet.com/?nick={CHATNAME}&lock=1channel=http://www.vwarrior.us.tf','','width=300,height=250,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no')})()">Chat here!</a>
I used the code for the custom.php as listed above, then in the custom dialog box entered:
Code: Select all
...
<script language="javascript" type="text/javascript">
alert('My name is ' + {CHATNAME});
</script>
What is printed in the custom block is without quotes " ... ...."
Next I tried in the custom block via dialog box:
Code: Select all
I played around with several variations and no joy.
So either I have the the custom.php part wrong trying to setup the variable, or I have the javascript in the custom block wrong , or I have them both wrong. I think I have them both wrong.
PLEASE HELP, I HAVE TRIED FIGURING THIS OUT USING GOOGLE, and reading tons of posts but to no avail.
Also besides getting the chat script to launch with the nick of the phpbb username.
I just want to know how to print the phpbb username in a custom block, that way I can set up different custom messages..
I hope kevin is reading this, because I know he can give me the quick and dirty method to accomplish both the java - chat problem and how to print the username in the custom block or any block for that matter.
NOTE:
here is the javascript for the chat, the 1st is with no name login and the user puts his name.
The 2nd is trying to us a nick where I want the nick to be the phpbb username.
Code: Select all
<a href="javascript:(function(){window.open('http://embed.yaplet.com/?channel=http://www.vwarrior.us.tf','','width=300,height=250,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no')})()">Chat here!</a>
<a href="javascript:(function(){window.open('http://embed.yaplet.com/?nick=USERNAMEHERE&lock=1channel=http://www.vwarrior.us.tf','','width=300,height=250,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no')})()">Chat here!</a>
Yes, by inserting &nick=[nick] into the URL. For example, if your page were http://foo.com/
http://go.yaplet.com/?nick=Anon&url=http://foo.com/
You can also lock people into using that nick by utilizing nicklock=1. For example:
http://go.yaplet.com/?nick=LifeNinja&ni ... //foo.com/
(This is useful if you're generating the chat link dynamically on your site, and you have access to usernames.)