Elgg  Version master
content.php
Go to the documentation of this file.
1 <?php
6 $blogs = [];
7 try {
8  $client = elgg_get_http_client(['verify' => false]);
9 
10  $response = $client->get('https://elgg.org/blog/all?view=json');
11  $data = $response->getBody()->getContents();
12  $blogs = @json_decode($data);
13 } catch (\Exception $e) {
14  // catch any issue and ignore it until later
15 }
16 
17 if (empty($blogs) || !is_array($blogs)) {
18  echo elgg_view('page/components/no_results', ['no_results' => elgg_echo('admin:widget:elgg_blog:no_results')]);
19  return;
20 }
21 
22 $blogs = array_slice($blogs, 0, 5);
23 
25 foreach ($blogs as $blog) {
26  $title = elgg_format_element('div', ['class' => 'elgg-listing-summary-title'], elgg_format_element('h3', [], elgg_view_url($blog->url, $blog->title, ['target' => '_blank'])));
27 
28  $time = elgg_view('object/elements/imprint/element', [
29  'icon_name' => 'history',
30  'content' => elgg_view_friendly_time($blog->time_created),
31  'class' => 'elgg-listing-time',
32  ]);
33 
34  $imprint = elgg_format_element('div', ['class' => 'elgg-listing-imprint'], $time);
35 
36  $subtitle = elgg_format_element('div', ['class' => ['elgg-listing-summary-subtitle', 'elgg-subtext']], $imprint);
37 
38  $image = elgg_view('output/img', ['src' => elgg_get_simplecache_url('widgets/elgg_blog/elgg-32.png'), 'alt' => 'Elgg logo']);
39 
41 
42  $list_items .= elgg_format_element('li', ['class' => 'elgg-item'], $item);
43 }
44 
45 $list = elgg_format_element('ul', ['class' => 'elgg-list'], $list_items);
46 
47 echo elgg_format_element('div', ['class' => 'elgg-list-container'], $list);
if(!$items) $item
Definition: delete.php:13
elgg_view_image_block(string $image, string $body, array $vars=[])
Wrapper function for the image block display pattern.
Definition: views.php:919
$response
Definition: content.php:10
$title
Definition: generic.php:50
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
if(!$annotation instanceof ElggAnnotation) $time
Definition: time.php:20
$subtitle
Output annotation subtitle.
Definition: subtitle.php:9
$client
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:177
foreach($blogs as $blog) $list
Definition: content.php:45
$image
Definition: image_block.php:25
$data
Definition: content.php:11
elgg_view_friendly_time($time, $time_updated=null)
Displays a UNIX timestamp in a friendly way.
Definition: views.php:853
$imprint
Definition: contents.php:18
elgg_view_url(string $href, string $text=null, array $options=[])
Helper function for outputting urls.
Definition: views.php:1471
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:130
elgg_get_http_client(array $options=[])
Returns a Guzzle HTTP client.
Definition: elgglib.php:235
$list_items
Definition: content.php:24
$blogs
Elgg News fetched from the community.
Definition: content.php:6
elgg_get_simplecache_url(string $view, string $subview= '')
Get the URL for the cached view.
Definition: cache.php:139