MyBB Community Forums
Customized nickname instead of username - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: Customized nickname instead of username (/thread-37402.html)



Customized nickname instead of username - Fredy - 2008-09-07

Hi. For my forum i need every displayed username change to nickname, that each user enters in his/her profile. Yesterday i was trying to make this, but i discovered, that's is nearly impossible to do this without modificating original mybb code. I got covered most of the places, but some doesn't have right hook to use.

So i'm wondering if there is some other way how to do this. First idea is hook to the 'pre_output_page' and change every link leading to member profile. My regular expression catches only plain links, but if there is customized format, it's not working. I have this:

(<a[\s]+[^>]*?href[\s]?=[\s\"\']+member.php\?action=profile&(?:amp;)?uid=([0-9]+)[\"\']+.*?>)([^<]+|.*?)?(<\/a>

Can someone help me to extends this, so i can cover every link ? I guess i don't need extract that format, because i got uid so i can get original format.

Second idea is modication of build_profile_link function, where i can put hook to use. I was wondering if development team can put hook there for future versions, so i can upgrade forum without breaking my funcionality.

If you have any other ideas how to archive this, please tell me. Sorry for my english...


RE: Customized nickname instead of username - Yumi - 2008-09-07

Hi,
So I take it that you're trying to capture all links to a user's profile and do something about it? -That's what your code is trying to do, from what I can tell.

Your description is a little different - you're saying that you want to change the displayed username?


RE: Customized nickname instead of username - Fredy - 2008-09-07

Hi, thanks for reply. Yes, i'm trying change displayed nickname through capturing links and changing them using preg_replace_callback. It's only suitable way o found without modifying mybb. But my regular expression cannot capture links with extra formatting of nick
<a href="member.php?action=profile&uid=1"><span style="color:green">Fredy</span></a>

Ok, nevermind. I must be sleepy yesterday or what, because that regular expression is today working Smile So problem solved.


RE: Customized nickname instead of username - Yumi - 2008-09-08

Hmm, but if you're trying to match links, it won't replace usernames without links, or with custom formatting...

If you just want to have a system where people have separate display and login names, I'd take a different approach.


RE: Customized nickname instead of username - Fredy - 2008-09-08

Well, it seems so far that it is almost everywhere. In quoting post there is real username, i hope this can be changed through some hook.

What different approach you would take please ? As i said, there isn't enough hooks to cover whole mybb without modifying original code. One way could be creating array in cache with pair username->nickname a replacing it in output, but i'm afraid of losing performance, because number of users will be big.


RE: Customized nickname instead of username - Yumi - 2008-09-08

Take a look at this post: http://community.mybboard.net/thread-26351-post-178326.html#pid178326
There's a few issues with it, however, you can use the idea there. (also, note, that's for MyBB 1.2)

Hope that helps.