News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Tip for SMF 2.1: Show 'Date Joined' and 'Last Active' in posts and PMs

Started by GL700Wing, July 19, 2022, 11:40:18 PM

Previous topic - Next topic

GL700Wing

This tip is in response to requests for information on how to show the registration date (ie, 'Date Joined') and last login date (ie, 'Last Active') in the member profile section for posts and PMs.

Notes:
1. To keep the dates as compact as possible the 'Date Joined' and 'Last Active' dates are shown in the 'MMM YYYYY' format - if you want to use a different date format you will need to modify the relevant line(s) of code in ./Sources/Load.php;
2. 'Last Active' will only be displayed if the member allows others to see their online status or if the member viewing the post/PM is an admin.



In ./Sources/Load.php
Find:
        'registered_timestamp' => empty($profile['date_registered']) ? 0 : $profile['date_registered'],
Add After:
        // Tip/Trick: Show 'Date Joined' and 'Last Active'.
        'date_joined' => empty($profile['date_registered']) ? '' : timeformat($profile['date_registered'], '%b %Y'),
        'last_active' => empty($profile['last_login']) ? $txt['never'] : timeformat($profile['last_login'], '%b %Y'),


In ./Themes/default/Display.template.php
Find:
        // Any custom fields to show as icons?
Add Before:
        // Tip/Trick: Show 'Date Joined' and 'Last Active'.
        // Show when they joined.
        if (!empty($message['member']['date_joined']))
            echo '
                                <li>', $txt['dateJoined'], $message['member']['date_joined'], '</li>';

        // Tip/Trick: Show 'Date Joined' and 'Last Active'.
        // Maybe also show when they were last active.
        if (allowedTo('admin_forum') || !$message['member']['is_hidden'])
            echo '
                                <li>', $txt['lastActive'], $message['member']['last_active'], (!empty($message['member']['is_hidden']) ? ' (' . $txt['hidden'] . ')' : ''), '</li>';


In ./Themes/default/PersonalMessage.template.php
Find:
        // Any custom fields to show as icons?
Add Before:
        // Tip/Trick: Show 'Date Joined' and 'Last Active'.
        // Show when they joined.
        if (!empty($message['member']['date_joined']))
            echo '
                                <li>', $txt['dateJoined'], $message['member']['date_joined'], '</li>';

        // Tip/Trick: Show 'Date Joined' and 'Last Active'.
        // Maybe also show when they were last active.
        if (allowedTo('admin_forum') || !$message['member']['is_hidden'])
            echo '
                                <li>', $txt['lastActive'], $message['member']['last_active'], (!empty($message['member']['is_hidden']) ? ' (' . $txt['hidden'] . ')' : ''), '</li>';



In ./Themes/default/languages/Modifications.english.php
Add to end of file:

// Tip/Trick: Show 'Date Joined' and 'Last Active'.
$txt['dateJoined'] = 'Date Joined: ';
$txt['lastActive'] = 'Last Active: ';

Life doesn't have to be perfect to be wonderful ...

Steve

Nice GL!  ;D

Also looks like a good candidate for a mod.  :)

One of the coders will need to look at this before it can be approved.
Please do not PM me for support.

GL700Wing

Quote from: Steve on July 20, 2022, 07:47:29 AMNice GL!  ;D
Thanks - was quick and easy to do.

QuoteAlso looks like a good candidate for a mod.  :)
Maybe but it is a fairly simple code change and if I made it a mod I would probably be asked for options to display none, one, or both dates on posts and/or PMs and to also have independently configurable date formats ...

Guess I'll wait and see how much interest it generates ...
Life doesn't have to be perfect to be wonderful ...

landyvlad

It is quick and simple as you say; but I think the user community would benefit in having this available as a mod for 2.1.x  Not everyone is comfortable doing manual code edits, even if they are relatively straightforward. That's my $0.02
Please do not PM, IM or Email me with questions on astrophysics or theology.  You will get better and faster responses by asking homeless people in the street. Thank you.

The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it

Advertisement: