Merge pull request #419 from acrox999/master
Get relative time from content & Keep UUID
This commit is contained in:
commit
dc553bae2f
|
@ -241,6 +241,45 @@ class Content {
|
|||
return $date;
|
||||
}
|
||||
|
||||
// Returns relative time (e.g. "1 minute ago")
|
||||
// Based on http://stackoverflow.com/a/18602474
|
||||
// Modified for Bludit
|
||||
// $complete = false : short version
|
||||
// $complete = true : full version
|
||||
public function relativeTime($complete = false) {
|
||||
$current = new DateTime;
|
||||
$past = new DateTime($this->getField('date'));
|
||||
$elapsed = $current->diff($past);
|
||||
|
||||
$elapsed->w = floor($elapsed->d / 7);
|
||||
$elapsed->d -= $elapsed->w * 7;
|
||||
|
||||
$string = array(
|
||||
'y' => 'year',
|
||||
'm' => 'month',
|
||||
'w' => 'week',
|
||||
'd' => 'day',
|
||||
'h' => 'hour',
|
||||
'i' => 'minute',
|
||||
's' => 'second',
|
||||
);
|
||||
|
||||
foreach($string as $key => &$value) {
|
||||
if($elapsed->$key) {
|
||||
$value = $elapsed->$key . ' ' . $value . ($elapsed->$key > 1 ? 's' : ' ');
|
||||
} else {
|
||||
unset($string[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!$complete) {
|
||||
$string = array_slice($string, 0 , 1);
|
||||
}
|
||||
|
||||
return $string ? implode(', ', $string) . ' ago' : 'Just now';
|
||||
|
||||
}
|
||||
|
||||
// Returns the tags
|
||||
// (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma
|
||||
public function tags($returnsArray=false)
|
||||
|
|
|
@ -212,7 +212,7 @@ class dbPosts extends dbJSON
|
|||
$args['dateModified'] = Date::current(DB_DATE_FORMAT);
|
||||
|
||||
// Keep UUID
|
||||
$args['uuid'] = $this->uuid();
|
||||
$args['uuid'] = $this->db[$args['key']]['uuid'];
|
||||
|
||||
if( $this->delete($args['key']) ) {
|
||||
return $this->add($args);
|
||||
|
|
Loading…
Reference in New Issue