-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrss.php
More file actions
135 lines (122 loc) · 6.03 KB
/
rss.php
File metadata and controls
135 lines (122 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
declare(strict_types=1);
/**
* FlatFile Blog - Enhanced RSS Feed
* Generates RSS 2.0 feed with comprehensive metadata
*/
// Check if blog is installed
if (!file_exists('config.php')) {
header('Location: install.php');
exit;
}
// Define constant to allow access
define('ALLOW_DIRECT_ACCESS', true);
try {
require_once 'functions.php';
} catch (Exception $e) {
error_log('Error loading functions.php: ' . $e->getMessage());
die('System error. Please try again later.');
}
// Load settings and interface mode
$settings = load_settings();
$interface_mode = defined('INTERFACE_MODE') ? (string) constant('INTERFACE_MODE') : ($settings['interface_mode'] ?? 'classic');
// Get latest published posts
$posts = get_posts(1, 20, 'published'); // Get first 20 published posts
if ($interface_mode === 'custom') {
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: public, max-age=300');
$index_file = CONTENT_DIR . 'index.json';
$last_modified_ts = file_exists($index_file) ? filemtime($index_file) : time();
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $last_modified_ts) . ' GMT');
$json_posts = [];
foreach ($posts as $post) {
$json_posts[] = [
'slug' => $post['slug'] ?? '',
'title' => $post['title'] ?? '',
'excerpt' => $post['excerpt'] ?? '',
'content_html' => $post['content_html'] ?? $post['content'] ?? '',
'content_markdown' => $post['content_markdown'] ?? '',
'content_type' => $post['content_type'] ?? 'html',
'author' => $post['author'] ?? 'admin',
'status' => $post['status'] ?? 'published',
'date' => $post['date'] ?? '',
'updated' => $post['updated'] ?? '',
'tags' => $post['tags'] ?? [],
'categories' => $post['categories'] ?? [],
'meta' => $post['meta'] ?? [],
'seo' => $post['seo'] ?? [],
'og' => array_merge($post['og'] ?? [], ['effective_image' => post_og_image($post)]),
'schema' => $post['schema'] ?? [],
'related_posts' => $post['related_posts'] ?? [],
'word_count' => $post['word_count'] ?? post_word_count($post),
'read_time' => $post['read_time'] ?? post_read_time_minutes($post),
'sitemap_priority' => post_sitemap_priority($post),
'url' => absolute_url(rawurlencode($post['slug'] ?? ''))
];
}
$payload = [
'mode' => 'custom',
'site' => [
'title' => SITE_TITLE,
'base_url' => get_site_base_url(),
'description' => $settings['site_description'] ?? '',
'favicon_url' => site_favicon_url()
],
'generated_at' => date('c'),
'count' => count($json_posts),
'posts' => $json_posts
];
echo json_encode($payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
exit;
}
// Set RSS headers with caching
header('Content-Type: application/rss+xml; charset=utf-8');
header('Cache-Control: public, max-age=3600'); // 1 hour cache
$index_file = CONTENT_DIR . 'index.json';
$last_modified_ts = file_exists($index_file) ? filemtime($index_file) : time();
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $last_modified_ts) . ' GMT');
// Generate RSS XML
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title><?php echo htmlspecialchars(SITE_TITLE); ?></title>
<link><?php echo htmlspecialchars(absolute_url('/'), ENT_QUOTES, 'UTF-8'); ?></link>
<description>A fast, lightweight flat-file blog system built with PHP and Bootstrap</description>
<language>en-us</language>
<lastBuildDate><?php echo date('r'); ?></lastBuildDate>
<generator>FlatFile Blog v1.0</generator>
<managingEditor>
<?php echo htmlspecialchars($posts[0]['author'] ?? 'admin'); ?>@<?php echo parse_url(get_site_base_url(), PHP_URL_HOST); ?>
</managingEditor>
<webMaster>
<?php echo htmlspecialchars($posts[0]['author'] ?? 'admin'); ?>@<?php echo parse_url(get_site_base_url(), PHP_URL_HOST); ?>
</webMaster>
<ttl>60</ttl>
<atom:link href="<?php echo htmlspecialchars(absolute_url('rss'), ENT_QUOTES, 'UTF-8'); ?>" rel="self" type="application/rss+xml" />
<?php if (!empty($posts)): ?>
<?php foreach ($posts as $post): ?>
<item>
<title><?php echo htmlspecialchars($post['title']); ?></title>
<link><?php echo htmlspecialchars(absolute_url(rawurlencode($post['slug'])), ENT_QUOTES, 'UTF-8'); ?></link>
<description>
<![CDATA[<?php echo htmlspecialchars($post['excerpt'] ?: substr(strip_tags($post['content'] ?? ''), 0, 200) . '...'); ?>]]>
</description>
<pubDate><?php echo date('r', strtotime($post['date'])); ?></pubDate>
<guid isPermaLink="true"><?php echo htmlspecialchars(absolute_url(rawurlencode($post['slug'])), ENT_QUOTES, 'UTF-8'); ?></guid>
<author><?php echo htmlspecialchars($post['author']); ?>@<?php echo parse_url(get_site_base_url(), PHP_URL_HOST); ?>
</author>
<dc:creator><?php echo htmlspecialchars($post['author']); ?></dc:creator>
<?php if (!empty($post['tags'])): ?>
<?php foreach ($post['tags'] as $tag): ?>
<category><?php echo htmlspecialchars($tag); ?></category>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!empty($post['meta']['image'])): ?>
<enclosure url="<?php echo htmlspecialchars(normalize_stored_media_url($post['meta']['image']), ENT_QUOTES, 'UTF-8'); ?>" type="image/jpeg" />
<?php endif; ?>
</item>
<?php endforeach; ?>
<?php endif; ?>
</channel>
</rss>