Another cool feature would be something along the following:
There are X new posts and X new comments since your last visit.
Wonder how this might be integrated.
Thanks,
Lee
Hey Lee,
If you were using the above code, make sure to notice a correct I just made. In the condition for the minutes, I forgot to make it ".=" The first version I posted just had "=" which would only show minutes and not days or hours.
Jesse R.
Consider trying something new and extraordinary.
Illinois Wine
Have you considered donating to MODx lately?
Donate now. Every contribution helps.
Here is the updated code with the conditionals to handle the plurals that I was talking about:
<?php
$table = $modx->getFullTableName("site_content");
$results = $modx->db->select("createdon", $table, "", "createdon DESC", "1");
$results = $modx->db->getRow($results);
$createdon = $results['createdon'];
$now = time();
$diff = $now - $createdon;
$days = floor($diff/86400);
$hours = floor($diff/3600);
$minutes = floor($diff/60);
if ($days > 0)
{
$output = $days . ' days ';
if ($days == 1) $output = $days . ' day ';
$diff = $diff - ($days * 86400);
$hours = floor($diff/3600);
}
if ($hours > 0)
{
$output .= $hours . ' hours ';
if ($hours == 1) $output .= $hours . ' hour ';
$diff = $diff - ($hours * 3600);
$minutes = floor($diff/60);
}
if ($minutes >0)
{
$output .= $minutes . ' minutes';
if ($minutes == 1) $output .= $minutes . ' minute';
}
return $output;
?>
Jesse R.
Consider trying something new and extraordinary.
Illinois Wine
Have you considered donating to MODx lately?
Donate now. Every contribution helps.
Silly error if there are 0 hours :-D
<?php
$table = $modx->getFullTableName("site_content");
$results = $modx->db->select("createdon", $table, "", "createdon DESC", "1");
$results = $modx->db->getRow($results);
$createdon = $results['createdon'];
$now = time();
$diff = $now - $createdon;
$days = floor($diff/86400);
$hours = floor($diff/3600);
$minutes = floor($diff/60);
if ($days > 0)
{
$output = $days . ' days ';
if ($days == 1) $output = $days . ' day ';
$diff = $diff - ($days * 86400);
$hours = floor($diff/3600);
}
if ($hours > 0)
{
$output .= $hours . ' hours ';
if ($hours == 1) $output .= $hours . ' hour ';
$diff = $diff - ($hours * 3600);
$minutes = floor($diff/60);
}
else $minutes = floor($diff/60);
if ($minutes >0)
{
$output .= $minutes . ' minutes';
if ($minutes == 1) $output .= $minutes . ' minute';
}
return $output;
?>
Jesse R.
Consider trying something new and extraordinary.
Illinois Wine
Have you considered donating to MODx lately?
Donate now. Every contribution helps.
Sure, I didn’t think there would be any real demand for this. If I am going to wrap it up and put it in the repository. I guess I should take some feature requests, if any have them.
Jesse R.
Consider trying something new and extraordinary.
Illinois Wine
Have you considered donating to MODx lately?
Donate now. Every contribution helps.
<?php
/*
::::::::::::::::::::::::::::::::::::::::
Snippet name: LastCreation
Short Desc: Lists the time from the last creation of a document
Version: 1.0.0
Author: Jesse Rochman (Jesster444)
Date: March 7, 2007
Example Usage:
[!LastCreation!] - Outputs the the time in xx Days xx Hours xx Minutes. It will return the time of creation for the last document created, regardless of published status.
[!LastCreation? &lcPublished=`1` &lcParent=`10`!] - Outputs the time of creation for the last published document created that is a child of document 10.
Parameters:
&lcPublished: (0|1)
If set to 0 it will output the time for the last creation of an unpublished document, if set to 1 it will output the time for the last creation of a published document.
&lcParent:
The parent ID of the folder you want to look in for last creation times. Can be used in conjuction with $lcPublished.
::::::::::::::::::::::::::::::::::::::::
*/
if (isset($lcPublished) && $lcPublished < 2) {
$SQL = "published=$lcPublished";
}
else $SQL = '';
if (isset($lcParent) && $SQL) {
$SQL .= " AND parent=$lcParent";
}
elseif (isset($lcParent) && !$SQL) {
$SQL = "parent=$lcParent";
}
$table = $modx->getFullTableName("site_content");
$results = $modx->db->select("createdon", $table, "$SQL", "createdon DESC", "1");
$results = $modx->db->getRow($results);
$createdon = $results['createdon'];
if ($createdon) {
$now = time();
$diff = $now - $createdon;
$days = floor($diff/86400);
$hours = floor($diff/3600);
$minutes = floor($diff/60);
if ($days > 0) {
if ($days == 1) $output = $days . ' day ';
else $output = $days . ' days ';
$diff = $diff - ($days * 86400);
$hours = floor($diff/3600);
}
if ($hours > 0) {
if ($hours == 1) $output .= $hours . ' hour ';
else $output .= $hours . ' hours ';
$diff = $diff - ($hours * 3600);
$minutes = floor($diff/60);
}
else $minutes = floor($diff/60);
if ($minutes >0) {
if ($minutes == 1) $output .= $minutes . ' minute';
else $output .= $minutes . ' minutes';
}
return $output;
}
else return '';
?>
That should work then. If some people could test this for me. I tried to test everything I could. If there aren’t any bugs, then I will post this to the repository.
Jesse R.
Consider trying something new and extraordinary.
Illinois Wine
Have you considered donating to MODx lately?
Donate now. Every contribution helps.