forked from dignajar/nibbleblog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed.php
64 lines (50 loc) · 2.02 KB
/
feed.php
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
<?php
header("Content-type: text/xml; charset=utf-8");
require('admin/boot/feed.bit');
// Get the last update (the date of the last published post)
$updated = Date::atom(time());
if(isset($posts[0]))
{
$last_post = $posts[0];
$updated = Date::atom($last_post['pub_date_unix']);
}
// Get the domain name
$domain = parse_url($settings['url']);
$domain = 'http://'.$domain['host'];
// =====================================================================
// ATOM Feed
// =====================================================================
$rss = '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;
$rss.= '<feed xmlns="http://www.w3.org/2005/Atom">' . PHP_EOL;
$rss.= '<title>'.$settings['name'].'</title>' . PHP_EOL;
$rss.= '<subtitle>'.$settings['slogan'].'</subtitle>' . PHP_EOL;
$rss.= '<link href="'.Url::atom().'" rel="self" />' . PHP_EOL;
$rss.= '<id>'.Url::atom().'</id>'. PHP_EOL;
$rss.= '<updated>'.$updated.'</updated>' . PHP_EOL;
foreach($posts as $post)
{
// Post, absolute permalink
$permalink = Post::permalink(true);
// Post, publish date on atom format
$date = Date::atom($post['pub_date_unix']);
// Post, category name
$category = Post::category();
// Post, full content
$content = Post::content(true);
// Absolute images src
$content = preg_replace("/(src)\=\"([^(http|data:image)])(\/)?/", "$1=\"$domain$2", $content);
// Post, title
$title = Post::title();
// Entry
$rss.= '<entry>' . PHP_EOL;
$rss.= '<title type="html">'.htmlspecialchars($title, ENT_QUOTES, 'UTF-8').'</title>' . PHP_EOL;
$rss.= '<content type="html">'.htmlspecialchars($content, ENT_QUOTES, 'UTF-8').'</content>' . PHP_EOL;
$rss.= '<link href="'.htmlspecialchars($permalink, ENT_QUOTES, 'UTF-8').'" />' . PHP_EOL;
$rss.= '<id>'.htmlspecialchars($permalink, ENT_QUOTES, 'UTF-8').'</id>' . PHP_EOL;
$rss.= '<updated>'.htmlspecialchars($date, ENT_QUOTES, 'UTF-8').'</updated>' . PHP_EOL;
$rss.= '<category term="'.htmlspecialchars($category, ENT_QUOTES, 'UTF-8').'"/>' . PHP_EOL;
$rss.= '</entry>' . PHP_EOL;
}
$rss.= '</feed>';
echo $rss;
?>