TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

April 25, 2024, 08:10:03 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,173
  • Total Topics: 21,219
  • Online today: 299
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 306
  • Total: 306

Article timestamp & Shoutbox

Started by neoxes, June 29, 2012, 01:13:03 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

neoxes

It's clear, but (same example) if I want to display "Today at 14:24" insted of  "Today at 02:24 PM" I should edit tinyportal files? Which one?

ZarPrime

Well, we don't like telling people how to modify TP core code to do stuff like this because, the next time you upgrade your version, it will wipe out your edits but, if you are using SMF 2.0+, look on about line 1554 of the TPsubs.template.php file and find this line ...


<span class="article_shortdate">' . tptimeformat($context['TPortal']['article']['date'], true, '%d %b %Y').' - </span>';

      
See there near the end of that line where you it says '%d %b %Y'?  You might be able to edit that to do what you want.  Make sure you backup the file first before doing this and post back after you have done it to let us know how it went because I'm not certain that this is the only thing that might need to be changed.  Ichbin probably knows for sure but I'm uncertain.

ZarPrime

neoxes

Quote from: ZarPrime on June 30, 2012, 08:43:42 PM
Well, we don't like telling people how to modify TP core code to do stuff like this because, the next time you upgrade your version, it will wipe out your edits but, if you are using SMF 2.0+, look on about line 1554 of the TPsubs.template.php file and find this line ...


<span class="article_shortdate">' . tptimeformat($context['TPortal']['article']['date'], true, '%d %b %Y').' - </span>';

      
See there near the end of that line where you it says '%d %b %Y'?  You might be able to edit that to do what you want.  Make sure you backup the file first before doing this and post back after you have done it to let us know how it went because I'm not certain that this is the only thing that might need to be changed.  Ichbin probably knows for sure but I'm uncertain.

ZarPrime

What about using:

timeformat($context['TPortal']['article']['date'])

instead of:

tptimeformat($context['TPortal']['article']['date'], true, time_format)

or using a variable as time_format?

ZarPrime

Well, I don't know how that would work.  Have you tried it?

ZP

neoxes

Quote from: ZarPrime on July 02, 2012, 11:43:55 AM
Well, I don't know how that would work.  Have you tried it?

ZP

timeformat is the default smf function which uses the time format setted in the admin panel of smf.
For the variable option, I dunno what is the variable used to store time format.

Can you explain me why tinyportal uses a custom function to format time insted of original one? Just a curiosity!

ZarPrime

No, I can't explain that but I'm sure there is a good reason for it.  Either Bloc (the original coder of TinyPortal) or Ichbin (the current coder) would have to answer that.

ZP

IchBin

Try replacing the tptimeformat() function with this and see if it does what you want.


function tptimeformat($log_time, $show_today = true, $format)
{
global $context, $user_info, $txt, $modSettings, $smcFunc;
static $non_twelve_hour;

$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;

// We can't have a negative date (on Windows, at least.)
if ($log_time < 0)
$log_time = 0;

// Today and Yesterday?
if ($modSettings['todayMod'] >= 1 && $show_today === true)
{
// Get the current time.
$nowtime = forum_time();

$then = @getdate($time);
$now = @getdate($nowtime);

// Try to make something of a time format string...
$s = strpos($format, '%S') === false ? '' : ':%S';
if (strpos($format, '%H') === false && strpos($format, '%T') === false)
{
$h = strpos($format, '%l') === false ? '%I' : '%l';
$today_fmt = $h . ':%M' . $s . ' %p';
}
else
$today_fmt = '%H:%M' . $s;

// Same day of the year, same year.... Today!
if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
return $txt['today'] . tptimeformat($log_time, $today_fmt, $format);

// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
return $txt['yesterday'] . tptimeformat($log_time, $today_fmt, $format);
}

$str = !is_bool($show_today) ? $show_today : $format;

if (setlocale(LC_TIME, $txt['lang_locale']))
{
if (!isset($non_twelve_hour))
$non_twelve_hour = trim(strftime('%p')) === '';
if ($non_twelve_hour && strpos($str, '%p') !== false)
$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);

foreach (array('%a', '%A', '%b', '%B') as $token)
if (strpos($str, $token) !== false)
$str = str_replace($token, !empty($txt['lang_capitalize_dates']) ? $smcFunc['ucwords'](strftime($token, $time)) : strftime($token, $time), $str);
}
else
{
// Do-it-yourself time localization.  Fun.
foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
if (strpos($str, $token) !== false)
$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
if (strpos($str, '%p'))
$str = str_replace('%p', (strftime('%H', $time) < 12 ? 'am' : 'pm'), $str);
}

// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);

// Format any other characters..
return strftime($str, $time);
}

neoxes


IchBin

Looking at your site I see simple portal....

neoxes

Quote from: IchBin™ on July 02, 2012, 10:35:33 PM
Looking at your site I see simple portal....

I wrote it: "Yep, I want to use Tinyportal but i need to fix it first, so I'm "playing" with a local backup where I've installad Tinportal."