Elgg  Version master
friendlytime.php
Go to the documentation of this file.
1 <?php
13 use Elgg\Values;
14 
16 $time_updated = elgg_extract('time_updated', $vars);
18 
19 try {
20  $date = Values::normalizeTime($time);
21  if (!empty($time_updated)) {
22  $date_updated = Values::normalizeTime($time_updated);
23  }
24 } catch (DataFormatException $e) {
25  return;
26 }
27 
28 $default_friendly_time_number_of_days = elgg_get_config('friendly_time_number_of_days');
30 
31 if (strtotime("-{$friendly_time_number_of_days}days") < $date->getTimestamp()) {
32  $output = elgg_get_friendly_time($date->getTimestamp());
33 } else {
34  $output = $date->formatLocale(elgg_echo('friendlytime:date_format:short'));
35 }
36 
37 $title = $date->formatLocale(elgg_echo('friendlytime:date_format'));
38 
39 if ($date_updated && ($date_updated->getTimestamp() > $date->getTimestamp() + 60)) {
40  $output = elgg_echo('friendlytime:updated', [$output]);
41  $title = elgg_echo('friendlytime:updated:title', [$title, $date_updated->formatLocale(elgg_echo('friendlytime:date_format'))]);
42 }
43 
45  'title' => elgg_extract('title', $vars, $title),
46  'datetime' => $date->format('c'),
47 ];
48 
elgg_get_friendly_time(int $time, int $current_time=null)
Formats a UNIX timestamp in a friendly way (eg "less than a minute ago")
Definition: output.php:221
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
Saves user notification settings.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
if($date_updated &&($date_updated->getTimestamp() > $date->getTimestamp()+60)) $attributes
$time
$time_updated
$date_updated
$title
$friendly_time_number_of_days
$vars
Definition: theme.php:5
An exception thrown when there is a problem in the format of some data.
if(!empty($time_updated)) catch(DataFormatException $e) $default_friendly_time_number_of_days
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
$output
Definition: download.php:9