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') || empty($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') || empty($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: ';



Note: Code updated on 02-May-24 to correct issue reported by davo88 (https://www.simplemachines.org/community/index.php?msg=4173692)
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.
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: davo88 on April 30, 2024, 10:10:34 PM
SMF 2.1.4
Mods
 - TinyPortal
 - Forum Width Setting
 - Quick New Topic Button
 - Board Sorting Method
 - Custom Form Mod
 - Optimus
 - Login Menu Button

I seem to be getting error messages generated by both Display.template.php and PersonalMessage.template.php from this line:
if (allowedTo('admin_forum') || !$message['member']['is_hidden'])In the log, the error is described as:
2: Undefined array key "is_hidden"
So far, it seems to be generated when a member views a topic or the list of messages in their Inbox. But the error does not occur when an admin does the same things. Any thoughts on what might be causing this?
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: davo88 on April 30, 2024, 11:30:10 PM
Left off one mod - Simple Audio Video Embedder   
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: GL700Wing on May 01, 2024, 02:42:47 AM
Quote from: davo88 on April 30, 2024, 10:10:34 PMI seem to be getting error messages generated by both Display.template.php and PersonalMessage.template.php from this line:
if (allowedTo('admin_forum') || !$message['member']['is_hidden'])In the log, the error is described as:
2: Undefined array key "is_hidden"
So far, it seems to be generated when a member views a topic or the list of messages in their Inbox. But the error does not occur when an admin does the same things. Any thoughts on what might be causing this?
Oops ...

Try changing both instances of:
!$message['member']['is_hidden'])To:
empty($message['member']['is_hidden'])
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: davo88 on May 01, 2024, 03:33:07 AM
I think I did the edits properly...
// Tip/Trick: Show 'Date Joined' and 'Last Active'.
        // Maybe also show when they were last active.
        if (allowedTo('admin_forum') || empty($message['member']['is_hidden'])
            echo '
              <li>', $txt['lastActive'], $message['member']['last_active'], (!empty($message['member']['is_hidden']) ? ' (' . $txt['hidden'] . ')' : ''), '</li>';

Unfortunately, that seems to make both the display template and the PM template unable to load at all and we get a white screen with an error message..
Parse error: syntax error, unexpected token "echo" in .../Themes/default/Display.template.php on line 589Parse error: syntax error, unexpected token "echo" in .../Themes/default/PersonalMessage.template.php on line 385
So that's the 'echo' on the very next line in both cases.
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: GL700Wing on May 01, 2024, 05:37:42 AM
Apologies - trying to do this without being able to test it because I'm on vacation.

My previous edit suggestion was missing a closing ')'

Try changing both instances of:
!$message['member']['is_hidden'])To:
empty($message['member']['is_hidden']))
Note the double '))' at the end ...

Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: davo88 on May 01, 2024, 04:13:08 PM
Good work GL700Wing. No errors so far after adding the bracket. Thanks very much for fixing this quickly and apologies for interrupting your holiday.
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: GL700Wing on May 01, 2024, 04:21:46 PM
Quote from: davo88 on May 01, 2024, 04:13:08 PMGood work GL700Wing. No errors so far after adding the bracket. Thanks very much for fixing this quickly and apologies for interrupting your holiday.
Great - thanks for letting me know - I'll update the first post in the topic with the correct code.

Also, and even though I'm on holidays I still check in from time to time just in case there is something I need to do ...
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: Steve on May 02, 2024, 08:32:03 AM
Quote from: davo88 on May 01, 2024, 04:13:08 PMapologies for interrupting your holiday
Hard not to. Her holidays are 6 months long! (https://i.imgur.com/aokc6an.gif)

j/k with ya @GL700Wing! And yes, you do detect a note of jealousy. (https://i.imgur.com/FfiWcus.gif)
Title: Re: Tip for SMF 2.0/2.1: Show 'Date Joined' and 'Last Active' in posts and PMs
Post by: petewadey on March 02, 2025, 09:07:02 AM
Is it possible to add this for just Join Date? And could it show as "Member Since"?

Thanks