Elgg  Version 6.1
cron.php
Go to the documentation of this file.
1 <?php
6 use Elgg\Values;
7 
9 $periods = $cron_service->getConfiguredIntervals(true);
10 
12 
14 foreach ($periods as $period) {
15  $row = [];
16 
17  // name
18  $row[] = elgg_format_element('td', [], elgg_echo("interval:{$period}"));
19 
20  // last completed (friendly) and full date
21  $date = $cron_service->getLastCompletion($period);
22  if (!elgg_is_empty($date)) {
23  $row[] = elgg_format_element('td', [], elgg_view_friendly_time($date));
24  $row[] = elgg_format_element('td', [], elgg_view('output/date', [
25  'value' => $date,
26  'format' => DATE_RFC2822,
27  ]));
28  } else {
29  $row[] = elgg_format_element('td', [], elgg_echo('never'));
30  $row[] = elgg_format_element('td', [], '&nbsp;');
31  }
32 
33  // cron output
34  $logs = $cron_service->getLogs($period);
35  $msg_class = [];
36  $log_output = '&nbsp;';
37  if (!empty($logs)) {
38  $log_output = '';
39 
40  foreach ($logs as $filename => $contents) {
41  $matches = [];
42  preg_match('/(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[0-9]{2})T(?<hour>[0-9]{2})-(?<minute>[0-9]{2})-(?<second>[0-9]{2})(?<offset>[-p])(?<offset_hour>[0-9]{2})-(?<offset_minute>[0-9]{2})\S+/', $filename, $matches);
43  if ($matches['offset'] === 'p') {
44  $matches['offset'] = '+';
45  }
46 
47  $date_string = "{$matches['year']}-{$matches['month']}-{$matches['day']}T{$matches['hour']}:{$matches['minute']}:{$matches['second']}{$matches['offset']}{$matches['offset_hour']}:{$matches['offset_minute']}";
48  $date = Values::normalizeTime($date_string);
49 
50  $contents = nl2br($contents);
52 
53  $log_output .= elgg_view('output/url', [
54  'icon' => 'info',
55  'text' => !$in_widget ? $date->format(DATE_RFC2822) : false,
56  'title' => elgg_echo('more_info'),
57  'href' => "#{$period}-{$date->getTimestamp()}",
58  'class' => ['elgg-lightbox'],
59  'data-colorbox-opts' => json_encode(['html' => $contents]),
60  ]);
61 
62  if ($in_widget) {
63  $msg_class[] = 'center';
64  break;
65  }
66 
67  $log_output .= '<br />';
68  }
69  }
70 
71  $row[] = elgg_format_element('td', ['class' => $msg_class], $log_output);
72 
73  $table_content .= elgg_format_element('tr', [], implode(PHP_EOL, $row));
74 }
75 
76 $header = elgg_format_element('th', [], elgg_echo('admin:cron:period'));
77 $header .= elgg_format_element('th', [], elgg_echo('admin:cron:friendly'));
78 $header .= elgg_format_element('th', [], elgg_echo('admin:cron:date'));
79 $header .= elgg_format_element('th', [], elgg_echo('admin:cron:msg'));
81 $header = elgg_format_element('thead', [], $header);
82 
84 
85 echo elgg_format_element('table', ['class' => 'elgg-table'], $header . $table_content);
Saves user notification settings.
$periods
Definition: cron.php:9
elgg_in_context(string $context)
Check if this context exists anywhere in the stack.
Definition: context.php:78
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$table_content
Definition: cron.php:13
$cron_service
Definition: cron.php:8
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:176
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
elgg_view_friendly_time($time, $time_updated=null)
Displays a UNIX timestamp in a friendly way.
Definition: views.php:832
$in_widget
Definition: cron.php:11
foreach($periods as $period) $header
Definition: cron.php:76
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
if(!empty($title)&&!empty($icon_name)) if(!empty($title)) if(!empty($menu)) if(!empty($header)) if(!empty($body)) $contents
Definition: message.php:73