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!
Ideas Centre
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: 775
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

S_Username BBCode

Post by Sniper_E » Sun May 12, 2019 4:51 am

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

Testing... Same version with adm images.
s_username_bbcode_1.0.2
Last edited by Sniper_E on Wed Jul 03, 2019 10:17 pm, edited 5 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 :!:

nou nou
Registered User
Posts: 328
Joined: Sat Oct 29, 2016 8:08 pm

Re: Username BBCode

Post by nou nou » Sun May 12, 2019 6:42 am

Works a treat so far! :)

Thank you, thank you and thank you!

User avatar
EA117
Registered User
Posts: 646
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Username BBCode

Post by EA117 » Sun May 12, 2019 10:02 pm

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: 775
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: Username BBCode

Post by Sniper_E » Mon May 13, 2019 5:50 pm

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: 646
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Username BBCode

Post by EA117 » Mon May 13, 2019 6:23 pm

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: 62
Joined: Wed Nov 25, 2009 9:08 am

Re: Username BBCode

Post by witvisser » Mon May 13, 2019 6:46 pm

@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: 775
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: Username BBCode

Post by Sniper_E » 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.
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
Jr. Extension Validator
Posts: 1047
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Username BBCode

Post by mrgoldy » 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/
phpBB Studio / ''Proud member of the Studio"

User avatar
John connor
Registered User
Posts: 2118
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Name: Aaron
Contact:

Re: Username BBCode

Post by John connor » Tue May 14, 2019 2:53 am

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.

User avatar
Sniper_E
Registered User
Posts: 775
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: Username BBCode

Post by Sniper_E » Tue May 14, 2019 6:01 pm

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: 62
Joined: Wed Nov 25, 2009 9:08 am

Re: Username BBCode

Post by witvisser » Tue May 14, 2019 6:26 pm

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.

nou nou
Registered User
Posts: 328
Joined: Sat Oct 29, 2016 8:08 pm

Re: Username BBCode

Post by nou nou » Tue May 14, 2019 7:55 pm

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: 775
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: Username BBCode

Post by Sniper_E » Tue May 14, 2019 8:10 pm

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: 775
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey
Contact:

Re: Username BBCode

Post by Sniper_E » Tue May 14, 2019 9:36 pm

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
John connor
Registered User
Posts: 2118
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Name: Aaron
Contact:

Re: Username BBCode

Post by John connor » Wed May 15, 2019 1:04 am

Sniper_E wrote:
Tue May 14, 2019 6:01 pm
Thanks for the report John?
https://en.wikipedia.org/wiki/John_Connor

Post Reply

Return to “Extensions in Development”