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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,231
  • Total Topics: 21,353
  • Online today: 651
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 153
  • Total: 153

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.

IchBin

Quote from: neoxes on July 02, 2012, 10:37:15 PM
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."

And now that I read the topic again I see I already asked about that.... lol I thought it was a different topic. I really don't have the time to look at the code right now. I noticed before that Zarprime asked if you tried the smf timeformat() function. If you want the result of it to look like SMF timeformate() you're going to have to change the function calls to do the same thing. Sorry I just don't have the time to figure it all out for you right now.

neoxes

No problem mate! Thanks for your help anyway!  :)

ZarPrime

The only thing I can tell you is to try replacing the entire tptimeformat function with the SMF timeformat function and see if that works for you.

Code (Find in TPsubs.template.php) Select

// Format a time to make it look purdy.
function tptimeformat($log_time, $show_today = true, $format)
{
global $context, $user_info, $txt, $modSettings, $smcFunc;

$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']))
{
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);
}


Code (and Replace With This) Select

// Format a time to make it look purdy.
function tptimeformat($log_time, $show_today = true, $offset_type = false)
{
global $context, $user_info, $txt, $modSettings, $smcFunc;
static $non_twelve_hour;

// Offset the time.
if (!$offset_type)
$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
// Just the forum offset?
elseif ($offset_type == 'forum')
$time = $log_time + $modSettings['time_offset'] * 3600;
else
$time = $log_time;

// 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($user_info['time_format'], '%S') === false ? '' : ':%S';
if (strpos($user_info['time_format'], '%H') === false && strpos($user_info['time_format'], '%T') === false)
{
$h = strpos($user_info['time_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, $offset_type);

// 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, $offset_type);
}

$str = !is_bool($show_today) ? $show_today : $user_info['time_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') !== false)
$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_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);
}


In addition to that, you need to understand that the TinyPortal article_shortdate function is just that, a shortened version of the date which is used in the titlebar of whatever article/topic you are rendering, without showing the time, unless the current date is either "Today" or "Yesterday".  If that is the case, the time will be displayed as well, according to how it is rendered by the tptimeformat function.  The short date, without the time, is used to save space in the titlebars.  Otherwise, the default is that it will render the date in the titlebar as "%d %b %Y" which would be, for today's date, "02 JUL 2012".  If you want the short date to display the same as the format you have set in SMF Admin (which is "%d/%m/%Y"), you will also have to edit the TinyPortal article_shortdate function as shown below ...

Code (Find in TPsubs.template.php) Select

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


Code (Replace With This) Select

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


If all this doesn't work, I don't know what else to tell you.  Be sure to backup the TPsubs.template.php file before starting on these edits, in case something goes wrong.

For anyone else searching for this, and finding it, be advised that this is only for SMF 2.0 and TinyPortal 1.0 Final.

ZarPrime

neoxes

Quote from: ZarPrime on July 03, 2012, 06:35:16 AM
The only thing I can tell you is to try replacing the entire tptimeformat function with the SMF timeformat function and see if that works for you.

Code (Find in TPsubs.template.php) Select

// Format a time to make it look purdy.
function tptimeformat($log_time, $show_today = true, $format)
{
global $context, $user_info, $txt, $modSettings, $smcFunc;

$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']))
{
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);
}


Code (and Replace With This) Select

// Format a time to make it look purdy.
function tptimeformat($log_time, $show_today = true, $offset_type = false)
{
global $context, $user_info, $txt, $modSettings, $smcFunc;
static $non_twelve_hour;

// Offset the time.
if (!$offset_type)
$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
// Just the forum offset?
elseif ($offset_type == 'forum')
$time = $log_time + $modSettings['time_offset'] * 3600;
else
$time = $log_time;

// 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($user_info['time_format'], '%S') === false ? '' : ':%S';
if (strpos($user_info['time_format'], '%H') === false && strpos($user_info['time_format'], '%T') === false)
{
$h = strpos($user_info['time_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, $offset_type);

// 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, $offset_type);
}

$str = !is_bool($show_today) ? $show_today : $user_info['time_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') !== false)
$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_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);
}


In addition to that, you need to understand that the TinyPortal article_shortdate function is just that, a shortened version of the date which is used in the titlebar of whatever article/topic you are rendering, without showing the time, unless the current date is either "Today" or "Yesterday".  If that is the case, the time will be displayed as well, according to how it is rendered by the tptimeformat function.  The short date, without the time, is used to save space in the titlebars.  Otherwise, the default is that it will render the date in the titlebar as "%d %b %Y" which would be, for today's date, "02 JUL 2012".  If you want the short date to display the same as the format you have set in SMF Admin (which is "%d/%m/%Y"), you will also have to edit the TinyPortal article_shortdate function as shown below ...

Code (Find in TPsubs.template.php) Select

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


Code (Replace With This) Select

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


If all this doesn't work, I don't know what else to tell you.  Be sure to backup the TPsubs.template.php file before starting on these edits, in case something goes wrong.

For anyone else searching for this, and finding it, be advised that this is only for SMF 2.0 and TinyPortal 1.0 Final.

ZarPrime

I'll try the first option, but the second works for sure because I already tried it. So thank you!
I'm asking these things as a curiosity, I'm not a coder or a webdevelopper, I'm just an engineer so I'm always interested to understand how things work!  >:D

This website is proudly hosted on Crocweb Cloud Website Hosting.