CMS 04.12.2015 2821 Feedback Status: Closed Solution: Yes bluesatkv
Hi Jerome,
I need help from you. I don't know where I'm wrong
I prepared switch in Blog settings for displaying time in format ' 2 days ago' or ' date - time'.
But now I have problem. In 'class.jakbase.php' is this code:
public static function jakTimesince($mysqlstamp, $date, $time, $lang)
{
$today = time(); /* Current unix time */
$unixtime = strtotime($mysqlstamp);
$since = $today - $unixtime;
if ($since < 900000) {
$lang = explode(",", $lang);
// Parse custom date format similar to original question
$replydate = new DateTime($mysqlstamp);
// Calculate DateInterval (www.php.net/manual/en/class.dateinterval.php)
$diff = $replydate->diff(new DateTime());
if ($diff->m >= 1) {
return date($date.$time, $mysqlstamp);
}
if ($v = $diff->d >= 1) {
$timeago = JAK_base::pluralize($diff->d, $lang[0], $lang[4]);
} elseif ($v = $diff->h >= 1) {
$timeago = JAK_base::pluralize($diff->h, $lang[1], $lang[5]);
} elseif ($v = $diff->i >= 1) {
$timeago = JAK_base::pluralize($diff->i, $lang[2], $lang[6]);
} else {
$timeago = JAK_base::pluralize($diff->s, $lang[3], $lang[7]);
}
return sprintf($lang[8],$timeago);
} else {
return date($date.$time, $unixtime);
}
}
In databases I have in cms_settings table varname 'blogdate' for switching value 'YES/NO'
I have problem select value from varname 'blogdate'. I edited the code as follows:
public static function jakTimesince($mysqlstamp, $date, $time, $lang)
{
$today = time(); /* Current unix time */
$unixtime = strtotime($mysqlstamp);
$since = $today - $unixtime;
global $jakdb;
$sql = 'SELECT value FROM '.DB_PREFIX.'setting WHERE varname = "blogdate"';
$result = $jakdb->query($sql);
while ($row = $result->fetch_assoc()) {
if ($row == 0) {
if ($since < 900000) {
$lang = explode(",", $lang);
// Parse custom date format similar to original question
$replydate = new DateTime($mysqlstamp);
// Calculate DateInterval (www.php.net/manual/en/class.dateinterval.php)
$diff = $replydate->diff(new DateTime());
if ($diff->m >= 1) {
return date($date.$time, $mysqlstamp);
}
if ($v = $diff->d >= 1) {
$timeago = JAK_base::pluralize($diff->d, $lang[0], $lang[4]);
} elseif ($v = $diff->h >= 1) {
$timeago = JAK_base::pluralize($diff->h, $lang[1], $lang[5]);
} elseif ($v = $diff->i >= 1) {
$timeago = JAK_base::pluralize($diff->i, $lang[2], $lang[6]);
} else {
$timeago = JAK_base::pluralize($diff->s, $lang[3], $lang[7]);
}
return sprintf($lang[8],$timeago);
} else {
return date($date.$time, $unixtime);
}
} else {
return date($date.$time, $unixtime);
}
}
}
My logic is as follows - If the value 'blogdate' is 0 than date format is e.g '2 days ago', If the value 'blogdate' is 1 than date format is e.g. '21.11.2015 - 20:54'
But my code stil not work Can you please help me?
That goes into custom modifications, for now I would use the solution I provided you in the other ticket.
I will add the feature in a future release which involves more changes to make it work globally.
Ok, thanks. Please close.
Solution is in revision 5 on my privat server
*** Ticket closed ***