Converting the post date when displaying

Started by javad_ft, August 29, 2013, 01:38:05 AM

Previous topic - Next topic

javad_ft

I want to view the post dates as in my custom calendar system (omari) but there is no feature or mod for this.
I don't want to change the database. I just want to convert the post dates obtained from the database using a function and display it. (Only in topics will be enough)

Now, to make it simple to get stated:
How can i add/subtract a number to/from the year and month?
For example:
December 10, 2011, 03:30:59 PM
November 13, 2004, 03:30:59 PM

I use V2.0.2. Which file do I need to modify?
Thanks in advance

Arantor

You need to modify the scary beast that is timeformat() inside Subs.php. There is no good way to modify the month or year cleanly.
Holder of controversial views, all of which my own.


javad_ft

#2
Thanks Arantor,
I have no PHP skills so I can only make tiny edits. (I have a little experience with C )
I modified the timeformat function and almost completely replaced it with my own code. The good news is it works!
I am using a reliable third party library (jdf.php) for formatting date and time to my local calendar system.
Following settings are ignored due to my modification: (they're not important)
Forum Default time format
User defined time format
User time offset
Today and Yesterday

So far, the only problem I have seen is the forum history in the stats page.
It's still in Gregorian calendar (obviously) but that's also not important.

Now I have two questions:
1. What are the possible problems this may cause (for example to database) that restoring the original Subs.php couldn't fix?
2. Are there any security concerns towards this?


include_once('jdf.php');
//

function timeformat($log_time, $show_today = true, $offset_type = false)
{
global $context, $user_info, $txt, $modSettings, $smcFunc;

 
$time = $log_time + $modSettings['time_offset'] * 3600;
 return
jstrftime('%A %e %B %Y ، %H:%M:%S',$time);
}


Arantor

1. As long as you just replace that part of the code if you have to replace Subs.php, it'll be OK - see, other mods will have changed that file too, so it's not usually ideal to replace individual files (it's OK to replace ALL files at once but rarely individual files)

2. I can't think of any security issues.
Holder of controversial views, all of which my own.


javad_ft

Sorry, I didn't understand your first answer. (My English is awful)
Can you please explain a little more? Do I have to replace all files?

I don't really know how mods work. What I'm going to do is:
1. Copy a backup of Subs.php
2. Paste the modified Subs.php to /Sources

Right?

Arantor

No, that's not what you do.

If you have to put the old code back just put back the bit you changed (i.e. the original timeformat function) not the entire file because that breaks other things.
Holder of controversial views, all of which my own.


javad_ft

Quote from: Arantor on August 30, 2013, 11:03:28 AM
No, that's not what you do.

If I can't simply upload the file to the /Sources folder, then what should I do? Do I have to edit the file in the FTP?

Quote
If you have to put the old code back just put back the bit you changed (i.e. the original timeformat function) not the entire file because that breaks other things.

Sorry for being nosy, but why?


Thank you very much Arantor, I really appreciate your help

Arantor

Oh, I see what you're asking. Sorry, I misunderstood you.

Yes, download the file, keep it as a backup, modify it and then reupload it back (that's all editing the file in FTP is going to do anyway)

QuoteSorry for being nosy, but why?

At the risk of repeating myself, other mods will modify the various files. I thought you were talking about replacing it with the very original Subs.php, and a lot of mods actually change that file so replacing it with the very original file will likely damage them.
Holder of controversial views, all of which my own.


javad_ft

Good!  ;)
Thank you Arantor
I'm gonna go test it to see if everything is OK.
I'll be back ...

javad_ft

Hi, I'm back with another question:

Can I change Subs.php's encoding to UTF-8 because I need some Non-ASCII charachters in the format string?
If yes, should I remove the BOM?

I tested these on WampServer/XP/Firefox and everything seems to work, but I'm worried there would be a problem in "real life".

Arantor

Yes it should be find to convert to UTF-8 and you should definitely remove the BOM.
Holder of controversial views, all of which my own.


javad_ft

After uploading the modified files to the host, date and time fields show garbage.
Turns out our character encoding is Arabic(Windows-1256) while the jdf.php library is UTF-8.
what should we do?

Arantor

Convert everything to UTF-8 after taking a backup...
Holder of controversial views, all of which my own.


javad_ft

Thanks Arantor
I found a way around it by converting the library to Arabic(Windows-1256).
Of course that would be great if I could convert everything to UTF-8 But I don't have the experience nor the courage to do that!
So we're gonna leave it that way for now.

I'm marking this topic solved.
And again, on behalf of all the members of our forum, I want to thank you for all your help. :)

Arantor

QuoteOf course that would be great if I could convert everything to UTF-8 But I don't have the experience nor the courage to do that!

Well, SMF itself has an option to do that, after that it's just a case of getting UTF-8 language files (which are available) and making sure mods have that too (which depends on whether the mods had such a translation)

Ultimately if you're using Win-1256 that's not really a problem but I personally would have made the change. (Mind you, I *always* install as UTF-8 anyway...)
Holder of controversial views, all of which my own.


javad_ft

Our case is little complicated! Because everything is standing up there using duct tape and stuff!
We have done so much non-standard and hard-coded customizations through these years and we are scared to mess it up!

Anyway, It's working great now, thanks to you. ;)

Advertisement: