Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ function community_theme_init() {
]));

elgg_register_plugin_hook_handler('action', 'login', 'community_theme_login_action');

elgg_register_page_handler('blog-feed.js', function () {
echo elgg_view_resource('blog-feed.js');
return true;
});
}

function community_theme_login_action() {
Expand Down
29 changes: 29 additions & 0 deletions views/default/resources/blog-feed.js.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

$max_age = 3600 * 2;
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $max_age), true);
header("Pragma: public", true);
header("Cache-Control: max-age=$max_age", true);
header("Content-Type; application/javascript; charset=utf-8");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should remove Set-Cookie header to be nice.

$posts = elgg_get_entities([
'type' => 'object',
'subtype' => 'blog',
'distinct' => false,
'limit' => min(20, (int)get_input('limit', 10)),
]);

$items = [];
foreach ($posts as $post) {
/* @var ElggBlog $post */
$link = elgg_view('output/url', [
'href' => $post->getURL(),
'text' => $post->getDisplayName(),
]);
$time = date("F j, Y", $post->time_created);
$items[] = "<li>$link<div class='elgg-text-help'>$time</div></li>";
}
$html = "<ul class='elgg-blog-posts'>" . implode('', $items) . "</ul>";

?>
elgg_blog_feed(<?= json_encode($html) ?>);