Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: GL700Wing on July 19, 2022, 11:40:18 PM

Title: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: GL700Wing on July 19, 2022, 11:40:18 PM
This tip is in response to requests for information on how to show the registration date (ie, 'Date Joined') (https://www.simplemachines.org/community/index.php?msg=4112581) and last login date (ie, 'Last Active') (https://www.simplemachines.org/community/index.php?msg=4130863) 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: ';

Title: Re: Tip for SMF 2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: Steve on July 20, 2022, 07:47:29 AM
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.
Title: Re: Tip for SMF 2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: GL700Wing on July 20, 2022, 09:45:27 AM
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 ...
Title: Re: Tip for SMF 2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: landyvlad on July 28, 2022, 06:16:31 AM
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
Title: Re: Tip for SMF 2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: WolfJ on August 22, 2022, 11:40:57 AM
Thanks for pointing me to this topic from my other posts I made but I'm still using 2.0.19, would this still work?
Title: Re: Tip for SMF 2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: GL700Wing on August 22, 2022, 07:01:01 PM
Quote from: WolfJ on August 22, 2022, 11:40:57 AMThanks for pointing me to this topic from my other posts I made but I'm still using 2.0.19, would this still work?
@WolfJ I've confirmed that all the file edits for this tip/trick are also compatible with SMF 2.0.19 so I've updated the topic subject accordingly.
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: davo88 on March 14, 2024, 10:12:02 PM
Thanks for these edits GL700Wing, they produce a nice neat display.

Quote from: GL700WingNotes:
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;

I would quite like to try and squeeze in the day and time with 'Last Active' somehow. Maybe shortening 'Last Active' to just 'Last' would do it. Could you tell me the additional fields to load for those two please?
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: GL700Wing on March 14, 2024, 10:30:46 PM
Quote from: davo88 on March 14, 2024, 10:12:02 PMThanks for these edits GL700Wing, they produce a nice neat display.
You're welcome!

Quote
Quote from: GL700WingNotes:
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;

I would quite like to try and squeeze in the day and time with 'Last Active' somehow. Maybe shortening 'Last Active' to just 'Last' would do it. Could you tell me the additional fields to load for those two please?
You can make the field titles whatever you want by changing the text for the relevant strings (ie, 'dateJoined' and 'lastActive') in the file ./Themes/default/languages/Modifications.english.php.

In ./Sources/Load.php you'll need to change the date/time format for 'date_joined' and 'last_active' from '%b %Y' to the format you want to use - details of supported date/time formats shown below:
IMG_2093.jpeg
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: davo88 on March 14, 2024, 11:26:05 PM
Great info GL700Wing - thank you. With all those time formats to choose from, I should be able to fit a day and time in there.