Размер файла: 1.24Kb
<?php
function assign_zero ($number)
{
$number = (int) $number;
if ($number < 10)
return '0'.$number;
else
return $number;
}
function smarty_function_text_timer ($params)
{
global $gcSmarty;
$result_time = null;
if ($params['time'] < 60)
{
$result_time = assign_zero ($params['time']).'c';
}
elseif ($params['time'] < 86400)
{
$hours = floor ($params['time'] / 3600);
$minutes = floor (($params['time'] - (3600 * $hours)) / 60);
if ($hours)
$result_time .= assign_zero ($hours).'ч, ';
$result_time .= assign_zero ($minutes).'мин';
}
elseif ($params['time'] < 2592000)
{
$days = floor ($params['time'] / 86400);
$hours = floor (($params['time'] - (86400 * $days)) / 3600);
$result_time .= assign_zero ($days).'д, '.assign_zero ($hours).'ч';
}
else
{
$month = floor ($params['time'] / 2592000);
$days = floor (($params['time'] - (2592000 * $month)) / 86400);
$result_time .= assign_zero ($month).'мес, '.assign_zero ($days).'д';
}
if ($params['time'] < 0)
$params['time'] = 0;
if ($params['time'] == 0 && isset ($params['text']))
{
$result_time = 'только что';
$params['text'] = false;
}
return $result_time.' '.(!empty ($params['text']) ? ' назад' : null);
}