Page 1 of 3

S_Username BBCode

Posted: Sun May 12, 2019 4:51 am
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

Testing... Same version with adm images.
s_username_bbcode_1.0.2

Re: Username BBCode

Posted: Sun May 12, 2019 6:42 am
by nou nou
Works a treat so far! :)

Thank you, thank you and thank you!

Re: Username BBCode

Posted: Sun May 12, 2019 10:02 pm
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.

Re: Username BBCode

Posted: Mon May 13, 2019 5:50 pm
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?

Re: Username BBCode

Posted: Mon May 13, 2019 6:23 pm
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.

Re: Username BBCode

Posted: Mon May 13, 2019 6:46 pm
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?

Re: Username BBCode

Posted: Mon May 13, 2019 10:24 pm
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.

Re: Username BBCode

Posted: Mon May 13, 2019 10:49 pm
by mrgoldy
You could also set the username as a s9e parameter and use that instead.
See: https://s9etextformatter.readthedocs.io ... arameters/

Re: Username BBCode

Posted: Tue May 14, 2019 2:53 am
by John connor
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.

Re: Username BBCode

Posted: Tue May 14, 2019 6:01 pm
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.

Re: Username BBCode

Posted: Tue May 14, 2019 6:26 pm
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.

Re: Username BBCode

Posted: Tue May 14, 2019 7:55 pm
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)...

Re: Username BBCode

Posted: Tue May 14, 2019 8:10 pm
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!

Re: Username BBCode

Posted: Tue May 14, 2019 9:36 pm
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.

Re: Username BBCode

Posted: Wed May 15, 2019 1:04 am
by John connor
Sniper_E wrote:
Tue May 14, 2019 6:01 pm
Thanks for the report John?
https://en.wikipedia.org/wiki/John_Connor