Skip to content

Commit 09d0179

Browse files
committed
feat(blog): simple JSONP blog feed available at /blog-feed.js
1 parent 5de95af commit 09d0179

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

start.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ function community_theme_init() {
4444
]));
4545

4646
elgg_register_plugin_hook_handler('action', 'login', 'community_theme_login_action');
47+
48+
elgg_register_page_handler('blog-feed.js', function () {
49+
echo elgg_view_resource('blog-feed.js');
50+
return true;
51+
});
4752
}
4853

4954
function community_theme_login_action() {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
$max_age = 3600 * 2;
4+
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $max_age), true);
5+
header("Pragma: public", true);
6+
header("Cache-Control: max-age=$max_age", true);
7+
header("Content-Type; application/javascript; charset=utf-8");
8+
9+
$posts = elgg_get_entities([
10+
'type' => 'object',
11+
'subtype' => 'blog',
12+
'distinct' => false,
13+
'limit' => min(20, (int)get_input('limit', 10)),
14+
]);
15+
16+
$items = [];
17+
foreach ($posts as $post) {
18+
/* @var ElggBlog $post */
19+
$link = elgg_view('output/url', [
20+
'href' => $post->getURL(),
21+
'text' => $post->getDisplayName(),
22+
]);
23+
$time = date("F j, Y", $post->time_created);
24+
$items[] = "<li>$link<div class='elgg-text-help'>$time</div></li>";
25+
}
26+
$html = "<ul class='elgg-blog-posts'>" . implode('', $items) . "</ul>";
27+
28+
?>
29+
elgg_blog_feed(<?= json_encode($html) ?>);

0 commit comments

Comments
 (0)