MyBB Community Forums

Full Version: Alias and Avatar in post
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone. I'm just trying to learn how MyBB works, so apologize if my question reveals my utter newbness...

Coming from Zetaboards and running some experiment on Icyboards, I tried to add a very useful piece of template that (on zeta) allowed the user to change their name and picture for a single post (that is to say, if my username is Storyteller, but for a specific post I want it to appear as "Monster of the Week", I can write [alias=Monster of the Week] in my post, and that'll appear in my miniprofile for that single post; similar tag can be used to change avatar in a similar fashion).

So, I took the following script...

script Wrote:<script type="text/javascript">

$('td:contains([AVATAR=):not(:has(textarea))').each(function () {
    $(this).html($(this).html().replace(/\[AVATAR=(.+?)\]/gi, '<span class="AI$1"></span>'));
});

$('td:contains([avatar=):not(:has(textarea))').each(function () {
    $(this).html($(this).html().replace(/\[avatar=(.+?)\]/gi, '<span class="AI$1"></span>'));
});

$('tr[id*="post-"]').each(function () {
    if ($(this).next('tr').find('td.c_post span[class*="AI"]').length) {
        var iURL = $(this).next('tr').find('td.c_post span[class*="AI"]').attr('class').split('AI')[1];
        $(this).next('tr').find('td.c_user img.avatar, td.c_user img.member').attr('src', iURL);
    }
});

$('#avatars select').change(function() {
    var iURLN = $(this).val();
    if (iURLN === '0') {
        $('#avatars img').show().attr('src', '');
        $('#c_post-text').val($('#c_post-text').val().replace(/ \[ALIAS=(.+?)\]/gi, ''));
    } else {
        $('#avatars img').show().attr('src', iURLN);
        $('#c_post-text').val($('#c_post-text').val().replace(/ \[ALIAS=(.+?)\]/gi, ''));
        $('#c_post-text').val($('#c_post-text').val() + ' [ALIAS=' + iURLN + ']');
    }
});

$('td:contains([ALIAS=):not(:has(textarea))').each(function() {
    $(this).html($(this).html().replace(/\[ALIAS=(.+?)\]/gi, '<span class="UN$1"></span>'));
});

$('#avatars select').change(function() {
    var iURLN = $(this).val();

    if (iURLN === '0') {
        $('#avatars img').show().attr('src', '');
        $('#c_post-text').val($('#c_post-text').val().replace(/ \[alias=(.+?)\]/gi, ''));
    } else {
        $('#avatars img').show().attr('src', iURLN);
        $('#c_post-text').val($('#c_post-text').val().replace(/ \[alias=(.+?)\]/gi, ''));
        $('#c_post-text').val($('#c_post-text').val() + ' [alias=' + iURLN + ']');
    }
});

$('td:contains([alias=):not(:has(textarea))').each(function() {
    $(this).html($(this).html().replace(/\[alias=(.+?)\]/gi, '<span class="UN$1"></span>'));
});

$('tr[id*="post-"]').each(function() {
    if ($(this).next('tr').find('td.c_post span[class*="UN"]').length) {
        var iURLN = $(this).next('tr').find('td.c_post span[class*="UN"]').attr('class').split('UN')[1];
        $(this).find('td.c_username a:eq(0)').text(iURLN);
    }
});
</script>

... and I added it as a new template (Global Templates --> Add Template). Apparently it wasn't the right thing to do, because it doesn't work... However (see the newb disclaimer above) I cannot tell if it's because the script itself isn't compatible, or if I had to... put it somewhere else?

Can anyone help with this? Or, do any of you know anything that works for the same purpose? (Custom name and pic for single post, without having to create a special accont for all your disposabe NPCs; possibly by the means of simple BCC in post, so that's available to regular members too).

If it's needed for any purpose, the board on which I am is here.
I don't think you can do this thing on MyBB without a custom plugin.
What you can do is, you can use write a MyCode in your post to show some specific attributes in your post such as image and title such as "Monster of the Week" but it won't change user attributes related to postbit_author information.

Regards
WallBB
Yes, you put it in a wrong place - a new template that isn't output anywhere. A proper place would be the showthread template if it should affect only threads or headerinclude if it should affect any place with postbit.

And yes, the code needs to be ported to use MyBB's CSS. You can inspect elements using Chrome console/Firebug/whatever and compare Zetaboards classes to their MyBB counterparts.
I tried to copy it into the showthread template. Result: if I write [alias=NAME HERE] in a post, the name does not show up, BUT the script does not appear in the post either. So at least I guess it recognizes it's... something.

Do any of you have a link with the differences between the two types of CSS? So I can try to edit them?