date YESTERDAY/TODAY in different colours

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
warmweer
Registered User
Posts: 963
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

date YESTERDAY/TODAY in different colours

Post by warmweer » Tue Jan 09, 2018 10:06 am

With phpbb 3.x using the YESTERDAY/TODAY dates, I coloured those words so that guests (and members of course) could quickly see if there were posts made today or yesterday (or within an hour ago), just by the colour of the posttime.
This was a simpe change in /language/en/common.php by adding a style element to Yesterday/Today/Tomorrow, and the hours and minutes :
'datetime' => array(
'TODAY' => '<strong style="color:#FF0000;">Today</strong>',
This also works more or less in 3.2.1 but is broken due to the new feature of having the quote include the datetime of the quoted post, and there the style element is shown as text.
So I've been struggling for a month now trying to figure out how to achieve the wanted effect, initially using custom coding and once it's finalised hoping to make it an extension. (BTW that month wasn't solely dedicated to this item ;) )

The most simple way (I thought) would be to remove the datetime part in quotes. I managed to get that to work it's not a very nice way, requiring edits in too many files, also implying loss of the new feature and possibly complications if the quoting systems changes with updates.

My current view is that this should be achieved using css and only in the lastpost column (and preferably also a change in colour in the icon for subforums).
Basically this should only be visible on index.php and on viewforum.php. (I wouldn't mind viewtopic also but that's probably superfluous since the unread topics are already easily identifiable). However, it may be easier to achieve the desired effect by making this a global feature on the forum. Something in the line of <Indentify date as YESTERDAY, or TODAY, or MINUTES/HOURS AGO> and use a different css identifier based on the outcome.This would imply that the datetime would have to be in a seperate (named) element.

Any thoughts/advice from phpBB experts (and possibly css experts)?
A bug is a feature that hasn't made it to the manual (yet)

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: date YESTERDAY/TODAY in different colours

Post by posey » Tue Jan 09, 2018 11:26 am

I haven't looked into it too much.
But I wouldn't suggest editing any core php files, as you know.
So therefore it might be better for now to adjust some template files with some if statements.
Haven't looked into the necessary template events, if they are present, to make it into an extension.

but what you could do, is wrap the post time in an if statement:

Code: Select all

{% if date(postrow.POST_TIME) >= date('-2days') %}
 	<span style="color: #ff0000;">{{ postrow.POST_TIME }}</span>
{% else %}
	{{ postrow.POST_TIME }}
{% endif %}
Haven't tested this myself and wrote it on the fly, but this is something you could have a look into.
Twig date documentation

Or you can hook into, with an extension, to the @event core.user_format_date_override and add your HTML there. But that would adjust it on every formatted time shown on your board, including quotes.

Other option is to hook into a few PHP events for the viewforum page and check/adjust the time output there.
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

User avatar
warmweer
Registered User
Posts: 963
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: date YESTERDAY/TODAY in different colours

Post by warmweer » Tue Jan 09, 2018 12:10 pm

posey wrote:
Tue Jan 09, 2018 11:26 am
I haven't looked into it too much.
But I wouldn't suggest editing any core php files, as you know.
So therefore it might be better for now to adjust some template files with some if statements.
Haven't looked into the necessary template events, if they are present, to make it into an extension.

but what you could do, is wrap the post time in an if statement:

Code: Select all

{% if date(postrow.POST_TIME) >= date('-2days') %}
 	<span style="color: #ff0000;">{{ postrow.POST_TIME }}</span>
{% else %}
	{{ postrow.POST_TIME }}
{% endif %}
Haven't tested this myself and wrote it on the fly, but this is something you could have a look into.
Twig date documentation

Or you can hook into, with an extension, to the @event core.user_format_date_override and add your HTML there. But that would adjust it on every formatted time shown on your board, including quotes.

Other option is to hook into a few PHP events for the viewforum page and check/adjust the time output there.
Sincere thanks posey for a really to the point answer which has removed the BLOCK state of my brain
The IF statement is something I've been playing with but I made it much more complicated than necessary it seems.
The event: phew, I've been looking for something like that but apparently overlooked it :oops: . I'll certainly check that out (and if it affects quotes also, no problem).
A bug is a feature that hasn't made it to the manual (yet)

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1555
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: date YESTERDAY/TODAY in different colours

Post by kinerity » Tue Jan 09, 2018 12:52 pm

warmweer, I'm at work right now, but I'll see if I can come up with anything when I get home tonight. No promises (I have some custom coding of my own for a client that I have to finish).
Kailey Truscott - Community Team

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: date YESTERDAY/TODAY in different colours

Post by posey » Tue Jan 09, 2018 12:54 pm

True that, kinerity.

I already send him a PM, wrote a tiny extension for him.
Hooking into just the
'core.viewforum_modify_topicrow
'core.display_forums_modify_template_vars'

php events, to only change the post time on the forum/topic list.



P.S.
Does anyone else notice that the Extension Writes Discussion forum doesn't update the last post?
Currently I should be the last post, as I am editing this one, and there isn't even the 'RE:' infront.
FwEJv-WHSxyVfNvduCO_3A[1].png
FwEJv-WHSxyVfNvduCO_3A[1].png (10.95 KiB) Viewed 412 times
Oh, nevermind. :oops: It got moved from that forum.
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

User avatar
warmweer
Registered User
Posts: 963
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: date YESTERDAY/TODAY in different colours

Post by warmweer » Tue Jan 09, 2018 1:39 pm

kinerity wrote:
Tue Jan 09, 2018 12:52 pm
warmweer, I'm at work right now, but I'll see if I can come up with anything when I get home tonight. No promises (I have some custom coding of my own for a client that I have to finish).
Hey, thanks for the offer. I'll accept anything ( :lol: except abuse). BTW If I manage to make something decent and working, I would offer it to the general public (here, that's also why I posted this in Extension writers and not in Custom Coding - the point was and is to make an extension), but it wouldn't be validated since I'm not willing to disclose my e-mail so that's an auto-reject)
A bug is a feature that hasn't made it to the manual (yet)

User avatar
warmweer
Registered User
Posts: 963
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: date YESTERDAY/TODAY in different colours

Post by warmweer » Tue Jan 09, 2018 9:25 pm

My thanks to posey. He basically made a small extension for me which I can adapt to my "needs" and use as a guide for other small decorative changes. This has just saved me probably another week of digging around in places I shouldn't be digging around in (yet).
A bug is a feature that hasn't made it to the manual (yet)

User avatar
3Di
Registered User
Posts: 12436
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: date YESTERDAY/TODAY in different colours

Post by 3Di » Wed Jan 10, 2018 1:03 am

warmweer wrote:
Tue Jan 09, 2018 1:39 pm
but it wouldn't be validated since I'm not willing to disclose my e-mail so that's an auto-reject)
Isn't mandatory to disclose your email AFAIK.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
warmweer
Registered User
Posts: 963
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: date YESTERDAY/TODAY in different colours

Post by warmweer » Wed Jan 10, 2018 7:43 am

3Di wrote:
Wed Jan 10, 2018 1:03 am
warmweer wrote:
Tue Jan 09, 2018 1:39 pm
but it wouldn't be validated since I'm not willing to disclose my e-mail so that's an auto-reject)
Isn't mandatory to disclose your email AFAIK.
ah, OK I'll check on that (perhaps a misconception on my part) Thanks for the nfo
A bug is a feature that hasn't made it to the manual (yet)

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: Elias and 2 guests