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
Jr. Extension Validator
Posts: 11234
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

date YESTERDAY/TODAY in different colours

Post by warmweer »

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)?
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: date YESTERDAY/TODAY in different colours

Post by mrgoldy »

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.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
warmweer
Jr. Extension Validator
Posts: 11234
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: date YESTERDAY/TODAY in different colours

Post by warmweer »

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).
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3732
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Re: date YESTERDAY/TODAY in different colours

Post by Kailey »

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 Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: date YESTERDAY/TODAY in different colours

Post by mrgoldy »

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 700 times
Oh, nevermind. :oops: It got moved from that forum.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
warmweer
Jr. Extension Validator
Posts: 11234
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: date YESTERDAY/TODAY in different colours

Post by warmweer »

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)
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
warmweer
Jr. Extension Validator
Posts: 11234
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: date YESTERDAY/TODAY in different colours

Post by warmweer »

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).
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: date YESTERDAY/TODAY in different colours

Post by 3Di »

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.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
warmweer
Jr. Extension Validator
Posts: 11234
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: date YESTERDAY/TODAY in different colours

Post by warmweer »

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
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
Post Reply

Return to “phpBB Custom Coding”