Page 1 of 1

how to get and pass phpbb user name to a java script?

Posted: 29. September 2009 20:54
by yocalif
Your Portal Version: 1.0.2
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']"
with and without quotes.

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,
     ));
	       


?>
Next in the custom dialog box in ACP I put the following javascript

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>
Next I tried a couple of tests to see if I could just print the phpbb username in the custom block.
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: What is printed in the custom block is without quotes "... My name is . ... "

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>
Below is the only help text I can find.
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.)

Re: how to get and pass phpbb user name to a java script?

Posted: 1. October 2009 22:29
by yocalif
There has to be a developer here than can easily answer this question?

Re: how to get and pass phpbb user name to a java script?

Posted: 3. October 2009 12:55
by yocalif
why did you move this post to general phpbb support?

This is question relates only to Board3Portal, the code has to be written, needs to be written in custom.php and custom.html.

I need help not the the ol one two shuffle the post around and ignore it.

How about answering the question that would be nice.


I'm sorry I'm ticked off, but I have been trying to solve this for over a week. I first searched many forums including phpbb, and asked the question there in a little different form, but basically the same, and got no answer, and startrek guide the same. So as a last resort I asked the question here which is where I should have started since this only applies to board3portal. What do I get? This is the only place that ignored the question and gave me the run around. NOT even phpbb moved the post since I posted in general phpbb support, it should have been in the mod support, they were still kind enough to take a shot at trying to answer it, and failed.

Re: how to get and pass phpbb user name to a java script?

Posted: 3. October 2009 19:29
by Marc
First of, cool down. I will take a look at it later on.

Re: how to get and pass phpbb user name to a java script?

Posted: 3. October 2009 21:29
by yocalif
Marc wrote:First of, cool down. I will take a look at it later on.
Help is very much appreciated....

Re: how to get and pass phpbb user name to a java script?

Posted: 3. October 2009 21:37
by Marc
You added this to custom.php

Code: Select all

$chatname = "$user->data['username']"; 
It should be:

Code: Select all

$chatname = $user->data['username']; 

Re: how to get and pass phpbb user name to a java script?

Posted: 4. October 2009 08:19
by yocalif
1st I appreciate that you took a look, I appreciate it very much.

If you notice my sentence below the code reference to userdata user name and right above the entire custom.php
with and without quotes.
, I have already tried without quotes as you showed.

Here is the code I tried without quotes in the custom.php This is at the very end of the custom.php, everything above chatname is for reference as to where the code you gave me was place. Again it didn't work. Try it in a custom.php and post the java chat code in the custom dialog box to test it.

Code: Select all

 $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,
     ));
	       


?>

Re: how to get and pass phpbb user name to a java script?

Posted: 6. October 2009 12:32
by vwarrior
Anyone?

Re: how to get and pass phpbb user name to a java script?

Posted: 9. October 2009 14:41
by yocalif
hmmm

Re: how to get and pass phpbb user name to a java script?

Posted: 9. October 2009 15:08
by Marc
Nice and simple: It wont work.

Values like {CHATNAME} don't get parsed if they are entered in the ACP. I recommend you to try this:
knowledge/kb_show.php?id=51

Re: how to get and pass phpbb user name to a java script?

Posted: 22. October 2009 07:47
by zottona
Where can I download a javascript tutorial? I want to learn javascript (all of of it) but I want to do it on an offline computer. I tried to download the web pages from w3schools.org but the examples didn't work.
____________
affiliateelite ~ affiliateelite.com ~ adgooroo ~ adgooroo.com