S_Username BBCode

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Scam Warning
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
User avatar
Sniper_E
Registered User
Posts: 1142
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

S_Username BBCode

Post by Sniper_E »

At the request from this topic. viewtopic.php?f=438&t=2509666#p15240966
nou nou wrote: Wed Apr 24, 2019 10:28 pm Is there a way to get the current logged in user displayed through a bbcode?

So for example, if I'd make a post like Hello [user][/user], then it would be displayed for user Johnny Cash as Hello Johnny Cash

Thanks!

PS. I found this: viewtopic.php?f=438&t=2471416&p=1500772 ... #p15007721
S_Username BBCode

Adds a username bbcode in a post which shows the user's name. Same as {S_USERNAME}
Can also be used in Board Announcements or anywhere in acp settings or extensions.

Screenshot:
Image

Updated for phpBB 3.3
s_username_bbcode_1.0.4
Last edited by Sniper_E on Mon Dec 19, 2022 10:30 am, edited 9 times in total.
Image . -.. / .... ..- -- .--. .... .-. . -.--
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!

:!: Sniper_E Styles | phpbbmodders :!:
User avatar
nou nou
Registered User
Posts: 507
Joined: Sat Oct 29, 2016 8:08 pm

Re: Username BBCode

Post by nou nou »

Works a treat so far! :)

Thank you, thank you and thank you!
User avatar
EA117
Registered User
Posts: 2159
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Username BBCode

Post by EA117 »

A question I have when looking at the proposed approach. Can we attest to the efficiency of invoking the JQuery search for "usernameGlobalsElement" elements in the DOM every time the page loads?

I mean I'm sure "it's fine", in that its not causing any kind of "critical" or extraordinary amount of overhead. But just wondering if it has enough of an overhead to be worth the effort to avoid it, too. Normally a BBCode wouldn't impact pages on which the BBCode was never referenced, but here we have a search of all DOM elements (or at least an indexed list of those elements) every time any page loads, "just in case" the BBCode was used.

Thinking of optimization along the lines of including a <script>searchForUsernameGlobalsElement = true;</script> in addition to the <span> as part of the BBCode replacement. And then test whether that flag was ever set for the current page before deciding whether invocation of the JQuery code is even necessary. Or whatever the actual smarter approach would be.

I didn't need [username] specifically, but was happy to see this as something that could perhaps be extended to create some other similar BBCodes for information phpBB already maintains internally. Thanks for pulling all of this together to create a unified package.
User avatar
Sniper_E
Registered User
Posts: 1142
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: Username BBCode

Post by Sniper_E »

It's only one more process to tag the {S_USERNAME} to a class text. Extensions, most of them add a few extra processes on page load to the mix when enabled. It's only one function this extension does. And I'm not really familiar with the issues you went on about... but,

I'll try adding that search script line and see if there is a difference. Did you try adding it?
Image . -.. / .... ..- -- .--. .... .-. . -.--
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!

:!: Sniper_E Styles | phpbbmodders :!:
User avatar
EA117
Registered User
Posts: 2159
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Username BBCode

Post by EA117 »

Sniper_E wrote: Mon May 13, 2019 5:50 pm I'll try adding that search script line and see if there is a difference. Did you try adding it?
Started to, but then overshot the target. Since I didn't need S_USERNAME or CSS, I've stripped down to just a JavaScript global being created based on the template variable value exposed through the event listener, and the actual BBCode replacement being a document.write() of that global. Haven't gotten that implementation over to the live board yet, though.

edit: By which I mean, the listener now exposes 'S_SESSION_IP' => empty($this->user->ip) ? '(unknown)' : $this->user->ip, and the styles directory only has a template for overall_header_body_before.html now, containing just <script>var sessionIPGlobal = "{S_SESSION_IP}";</script>. And so the BBCode replacement text is installed as <script>document.write(sessionIPGlobal);</script>. That's the data I needed instead of S_USERNAME; the session's IP address.

But wanted to ask the JQuery question anyway, just in case it was worthwhile.
Last edited by EA117 on Wed May 15, 2019 10:03 am, edited 1 time in total.
witvisser
Registered User
Posts: 71
Joined: Wed Nov 25, 2009 9:08 am

Re: Username BBCode

Post by witvisser »

@Sniper_E, thank you for this wonderfull extension.
It even works on a page where the BBCode is diabled and only html is enabled by using:

Code: Select all

<span class="usernameGlobalsElement"></span>
instead of

Code: Select all

[username][/username]
One more question. I have made a page with a mail form (only html) with form fields for mailing to me.
The mail form works perfect, but i can't get the username into a form field. I want to put the username in one of the form fields automatic and also mail the username in that form field. Any idea how to realise this?
User avatar
Sniper_E
Registered User
Posts: 1142
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: Username BBCode

Post by Sniper_E »

I have not setup permissions for this yet. Anyone can use it the way it is now. I will add the if statement to where it want show on the pages you have BBCodes disabled on. And I'll set permissions for admin use only. You can always add permission for other groups and members if you want.

And in your mail form page, if it except bbcode usage in there, this will work there also. But you will need some code added at the top of that mail form template. (If it's not pulling in the overall_header.html)

<span id="usernameGlobalsContainer" style="display: none">{S_USERNAME}</span>
That line needs to be in the body to pick up the username.
It want show in the template, this ext just grabs the name.
Last edited by Sniper_E on Mon May 13, 2019 11:02 pm, edited 1 time in total.
Image . -.. / .... ..- -- .--. .... .-. . -.--
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!

:!: Sniper_E Styles | phpbbmodders :!:
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Username BBCode

Post by mrgoldy »

You could also set the username as a s9e parameter and use that instead.
See: https://s9etextformatter.readthedocs.io ... arameters/
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
2600
I've Been Banned!
Posts: 2567
Joined: Fri Nov 14, 2014 5:14 pm
Location: Area-51

Re: Username BBCode

Post by 2600 »

If I allow this BBcode only for administrators, all users can still see the BBcode option, but of course using the BBCode will tell you that you can't. With a couple of other BBcodes I have that are Admin only the BBcode is hidden to other users.
Morpheus: Unfortunately, no one can be told what The Matrix is. You'll have to see it for yourself.
Hack me.
Consider a canary token.
The nature of my chosen username
:ugeek:
User avatar
Sniper_E
Registered User
Posts: 1142
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: Username BBCode

Post by Sniper_E »

Thanks for the report John?
Sniper_E wrote: Mon May 13, 2019 10:24 pm I have not setup permissions for this yet. Anyone can use it the way it is now. I will add the if statement to where it want show on the pages you have BBCodes disabled on.

And I'll set permissions for admin use only. You can always add permission for other groups and members if you want.
It should all be fine in the next release.
Image . -.. / .... ..- -- .--. .... .-. . -.--
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!

:!: Sniper_E Styles | phpbbmodders :!:
witvisser
Registered User
Posts: 71
Joined: Wed Nov 25, 2009 9:08 am

Re: Username BBCode

Post by witvisser »

Sniper_E wrote: Mon May 13, 2019 10:24 pm I have not setup permissions for this yet. Anyone can use it the way it is now. I will add the if statement to where it want show on the pages you have BBCodes disabled on. And I'll set permissions for admin use only. You can always add permission for other groups and members if you want.

And in your mail form page, if it except bbcode usage in there, this will work there also. But you will need some code added at the top of that mail form template. (If it's not pulling in the overall_header.html)

<span id="usernameGlobalsContainer" style="display: none">{S_USERNAME}</span>
That line needs to be in the body to pick up the username.
It want show in the template, this ext just grabs the name.
I can't get work the {S_USERNAME} variable in a html page.
With the page extension i a made a html test page and put this code in it for testing purposes:

Code: Select all

1 <input type="text" class="inputbox autowidth" name="username" value="{S_USERNAME}" size="50"><br><br>
2 {S_USERNAME}<br><br>
3 <input type="text" class="inputbox autowidth" name="username" value='<span class="usernameGlobalsElement"></span>' size="50"><br><br>
4 <span class="usernameGlobalsElement"></span>
results in:
Image
Only option 4 works for me. But i can't get the usermane in the form field (option 3).
In my source code of the page i can see

Code: Select all

<style type="text/css">.usernameGlobalsElement { color: #AA0000; }</style>
and

Code: Select all

<span id="usernameGlobalsContainer" style="display: none">dlv</span>
I tried everything, but i can't get it working.
User avatar
nou nou
Registered User
Posts: 507
Joined: Sat Oct 29, 2016 8:08 pm

Re: Username BBCode

Post by nou nou »

mrgoldy wrote: Mon May 13, 2019 10:49 pm You could also set the username as a s9e parameter and use that instead.
See: https://s9etextformatter.readthedocs.io ... arameters/
Interesting idea... Need to read up on TextFormatter (also for other reasons)...
User avatar
Sniper_E
Registered User
Posts: 1142
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: Username BBCode

Post by Sniper_E »

That seems to be a stand alone .html template. It must not be tied in with your phpBB forum. I'm not sure what kind of setup you are running there but it's not picking up {S_USERNAME} which is defined in the core files.

Now the ACP does not have that variable defined in it's core files, I had to create the {S_USERNAME} for the acp. We would have to use the recipients name in your e-mail codes for replacement.

Why don't you PM me your files you are using for that and I will see if I can set it up. A little explication of how you set that up to work would help.

In the mean time I will check the mass email features out and see if this extension will work in there. Username is defined different in sending an e-mail. It might just be a small adjustment.
mrgoldy wrote: Mon May 13, 2019 10:49 pm You could also set the username as a s9e parameter and use that instead.
See: https://s9etextformatter.readthedocs.io ... arameters/
I will defiantly check that out my good man. Thanks!
Image . -.. / .... ..- -- .--. .... .-. . -.--
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!

:!: Sniper_E Styles | phpbbmodders :!:
User avatar
Sniper_E
Registered User
Posts: 1142
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: Username BBCode

Post by Sniper_E »

Actually witvisser, I can not test e-mail messages out with my server down. But I did see {USERNAMES} used in the template. This extension is using {S_ADMIN_USERNAME} in the event template. Try changing that and see.

I did not see any BBCodes setup on the e-mail page. If it does not except BBCodes I e-mail then that could be a small issue.
Image . -.. / .... ..- -- .--. .... .-. . -.--
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!

:!: Sniper_E Styles | phpbbmodders :!:
User avatar
2600
I've Been Banned!
Posts: 2567
Joined: Fri Nov 14, 2014 5:14 pm
Location: Area-51

Re: Username BBCode

Post by 2600 »

Sniper_E wrote: Tue May 14, 2019 6:01 pm Thanks for the report John?
https://en.wikipedia.org/wiki/John_Connor
Morpheus: Unfortunately, no one can be told what The Matrix is. You'll have to see it for yourself.
Hack me.
Consider a canary token.
The nature of my chosen username
:ugeek:
Post Reply

Return to “Extensions in Development”