Merge pull request #419 from acrox999/master

Get relative time from content & Keep UUID
This commit is contained in:
Diego Najar 2017-04-29 20:25:37 +02:00 committed by GitHub
commit dc553bae2f
2 changed files with 358 additions and 319 deletions

View File

@ -241,6 +241,45 @@ class Content {
return $date; 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 // Returns the tags
// (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma // (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma
public function tags($returnsArray=false) public function tags($returnsArray=false)

View File

@ -212,7 +212,7 @@ class dbPosts extends dbJSON
$args['dateModified'] = Date::current(DB_DATE_FORMAT); $args['dateModified'] = Date::current(DB_DATE_FORMAT);
// Keep UUID // Keep UUID
$args['uuid'] = $this->uuid(); $args['uuid'] = $this->db[$args['key']]['uuid'];
if( $this->delete($args['key']) ) { if( $this->delete($args['key']) ) {
return $this->add($args); return $this->add($args);