-
Notifications
You must be signed in to change notification settings - Fork 2
/
rss.php
137 lines (113 loc) · 4.13 KB
/
rss.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
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
136
137
<?php
// Initialise session
session_start();
if(defined('APP_RAN') === false) {
define('APP_RAN', '');
require_once('config.php');
}
require_once('content_filters.php');
require_once('ping.php');
require_once('Parsedown.php');
require_once('ParsedownExtra.php');
$target_dir = dirname(__FILE__);
$rss = $target_dir.'/hyblog.xml';
if ( file_exists( $rss ) ) {
unlink( $rss );
}
$rssfile = fopen($rss, 'w');
fwrite($rssfile, '<?xml version="1.0" standalone="yes" ?>'.PHP_EOL);
fwrite($rssfile, '<rss xmlns:source="http://source.scripting.com/"'.PHP_EOL);
fwrite($rssfile, 'xmlns:now="https://nowns.work" version="2.0"'.PHP_EOL);
fwrite($rssfile, '>'.PHP_EOL);
fwrite($rssfile, '<channel>'.PHP_EOL);
fwrite($rssfile, '<title>'.NAME.'</title>'.PHP_EOL);
fwrite($rssfile, '<description>Posts from '.NAME.'</description>'.PHP_EOL);
fwrite($rssfile, '<link>'.BASE_URL.'</link>'.PHP_EOL);
fwrite($rssfile, '<lastBuildDate>' . gmdate('D, d M Y H:i:s') . ' GMT</lastBuildDate>'.PHP_EOL);
fwrite($rssfile, '<cloud domain="rpc.rsscloud.io" port="5337" path="/pleaseNotify" registerProcedure="" protocol="http-post"/>'.PHP_EOL);
fwrite($rssfile, '<generator>hyblog</generator>'.PHP_EOL);
fwrite($rssfile, '<source:account service="hyblog">'.NAME.'</source:account>'.PHP_EOL);
fwrite($rssfile, '<language>en-GB</language>'.PHP_EOL);
if (NOWNS != '') {
$nownsname = NOWNS;
$nowns = $target_dir.'/pages/'.$nownsname.'.md';
$title = ucfirst(str_replace('_', ' ', $nownsname));
$content = file_get_contents($nowns);
$Parsedown = new Parsedown();
$content = $Parsedown->text($content);
$time = date("r", filemtime($nowns));
fwrite($rssfile, '<now:title>'.$title.'</now:title>'.PHP_EOL);
fwrite($rssfile, '<now:link>'.BASE_URL.$nownsname.'/</now:link>'.PHP_EOL);
fwrite($rssfile, '<now:content><![CDATA['.$content.']]></now:content>'.PHP_EOL);
fwrite($rssfile, '<now:timestamp>'.$time.'</now:timestamp>'.PHP_EOL);
}
foreach (glob($target_dir . '/posts/*/*/*.md') as $file) {
$parts = explode('/', $file);
$index = count($parts) - 1;
$filename = $parts[$index];
if (substr($filename, 0, 1) != 'c') {
$filedates[] = substr($filename, 0, 10);
}
}
rsort($filedates);
array_splice($filedates,10);
$count = 0;
foreach($filedates as $file) {
$year = date('Y', strtotime($file));
$month = date('m', strtotime($file));
$posts = file_get_contents($target_dir.'/posts/'.$year.'/'.$month.'/'.$file.'.md');
$explode = array_filter(explode('@@', $posts),'strlen');
$explode = array_reverse($explode);
$p = count($explode);
foreach ($explode as $post) {
$draft = false;
$post_title = '';
$content = trim($post);
$post_array = explode("\n", $content);
$size = sizeof($post_array);
if (substr($post_array[0], 0, 2) === "# ") {
$length = strlen($post_array[0]);
$required = $length - 3;
$post_title = substr($post_array[0], 2, $required);
$title_in_body = 'true';
$content = substr($content,$length);
}
if (substr($post_array[0], 0, 2) === "! ") {
$draft = true;
$p-=1;
}
$post_parts = explode('!!', $content);
if (isset($post_parts[1])) {
$time = trim($post_parts[1]);
} else {
$time = '';
}
$content = trim($post_parts[0]);
$content = filters($content);
$Parsedown = new ParsedownExtra();
$content = $Parsedown->text($content);
// display each post
if (!$draft && $count<10) {
fwrite($rssfile, '<item>'.PHP_EOL);
fwrite($rssfile, '<link>'.BASE_URL.'?date='.$file.'#p'.$p.'</link>'.PHP_EOL);
fwrite($rssfile, '<guid isPermaLink="false">'.BASE_URL.'?date='.$file.'#p'.$p.'</guid>'.PHP_EOL);
fwrite($rssfile, '<pubDate>' . gmdate("D, d M Y H:i:s", strtotime($file.$time)) . ' GMT</pubDate>'.PHP_EOL);
if ($post_title != '') {
fwrite($rssfile, '<title>' . $post_title . '</title>'.PHP_EOL);
}
fwrite($rssfile, '<description><![CDATA['.$content.']]></description>'.PHP_EOL);
fwrite($rssfile, '</item>'.PHP_EOL);
$p-=1;
}
$count++;
}
}
fwrite($rssfile, '</channel>'.PHP_EOL);
fwrite($rssfile, '</rss>'.PHP_EOL);
fclose($rssfile);
$feedurl = BASE_URL.'hyblog.xml';
doPing($feedurl);
if (isset($_GET['p'])) {
header("Location: admin/reset.html");
}
?>