-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdailyfeed.php
140 lines (107 loc) · 4.5 KB
/
dailyfeed.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
138
139
140
<?php
define('APP_RAN', '');
require_once('config.php');
require_once('content_filters.php');
require_once('Parsedown.php');
require_once('ParsedownExtra.php');
// Start Daily Feed
//start RSS feed
$root = $_SERVER['DOCUMENT_ROOT'];
$file = $root . '/dailyfeed.rss';
if ( file_exists( $file ) ) {
unlink( $file );
}
$xmlfile = fopen($file, 'w');
fwrite($xmlfile, '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL);
fwrite($xmlfile, '<rss version="2.0"'.PHP_EOL);
fwrite($xmlfile, 'xmlns:content="http://purl.org/rss/1.0/modules/content/"'.PHP_EOL);
fwrite($xmlfile, 'xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"'.PHP_EOL);
fwrite($xmlfile, '>'.PHP_EOL);
fwrite($xmlfile, '<channel>'.PHP_EOL);
fwrite($xmlfile, '<title>' . NAME . ' — Daily Feed</title>'.PHP_EOL);
fwrite($xmlfile, '<description>Daily feed from ' . parse_url(BASE_URL)['host'] . '</description>'.PHP_EOL);
fwrite($xmlfile, '<link>' . BASE_URL . '</link>'.PHP_EOL);
fwrite($xmlfile, '<lastBuildDate>' . gmdate('D, d M Y H:i:s') . ' GMT</lastBuildDate>'.PHP_EOL);
fwrite($xmlfile, '<generator>(b)log-In</generator>'.PHP_EOL);
fwrite($xmlfile, '<language>en-GB</language>'.PHP_EOL);
fwrite($xmlfile, '<sy:updatePeriod>hourly</sy:updatePeriod>'.PHP_EOL);
fwrite($xmlfile, '<sy:updateFrequency>1</sy:updateFrequency>'.PHP_EOL);
// get posts
$today = date_create(date("Y/m/d"));
$dbdate = date('Y/m/d', strtotime($date .' -1 day'));
$feeddate = date('Y-m-d', strtotime($date .' -1 day'));
$pubdate = date_format($today,"D, d M Y H:i:s");
$normdate = date("d/m/Y", strtotime($date .'-1 day'));
$count = 0;
$post_title = '';
while ($count < 5) {
$sql = $connsel->prepare("SELECT ID, Permalink, Section, Title, Content, Date, ReplyURL, Reply_Title, Draft FROM " . POSTS . " WHERE Day=? AND Draft='' ORDER BY Section Asc");
$sql->bind_param("s", $dbdate);
$sql->execute();
$result = mysqli_stmt_get_result($sql);
while($row = $result->fetch_assoc()) {
$post_title = '';
$section_number = $row["Section"];
$post_title = $row["Title"];
$postdate = $row["Date"];
$date = date_create($postdate);
$main_link = $row["Permalink"];
$replyURL = $row["ReplyURL"];
$reply_title = $row["Reply_Title"];
$content = stripslashes($row["Content"]);
$post_array = explode("\n", $content);
$size = sizeof($post_array);
if (substr($post_array[0], 0, 2) == "# ") {
$length = strlen($post_array[0]);
$required = $length - 2;
$post_title = substr($post_array[0], 2, $required);
$content = '';
for ($i = 2; $i < $size; $i++) {
$content .= $post_array[$i];
}
}
$content = filters($content);
if($replyURL != '') {
$content = substr($content, (strlen($replyURL)+9));
$content = '<p><em>In reply to: <a class="u-in-reply-to" href="' . $replyURL . '">' . $reply_title . '</a>...</em></p>' . $content;
}
$Parsedown = new ParsedownExtra();
$feedcontent = $Parsedown->text($content);
$feedcontent = substr($feedcontent, 3);
if (substr($feedcontent, -4) == '</p>') {
$feedcontent = substr($feedcontent, 0, -4);
}
if ($indent == 'true') {
$indentSpan = ' style="margin-left: 25px;"';
}
if ($post_title != '') {
$h2 = '<span style="font-size: 24px; text-transform: uppercase;"><strong>' . $post_title . '</strong></span><br/>';
}
$feedcontent = '<p' . $indentSpan . '><a href="' . BASE_URL . '/?date=' . $feeddate . '#p' . $section_number . '" style="text-decoration: none; margin-right: 8px;">#</a> ' . $h2 . $feedcontent . '</p>'.PHP_EOL;
$fullcontent .= $feedcontent;
$h2 = '';
$indentSpan = '';
}
//add post to RSS
fwrite($xmlfile, '<item>'.PHP_EOL);
fwrite($xmlfile, '<title>Posts for '.$normdate.'</title>'.PHP_EOL);
fwrite($xmlfile, '<link>' . $main_link . '</link>'.PHP_EOL);
fwrite($xmlfile, '<guid isPermaLink="false">' . $main_link . '</guid>'.PHP_EOL);
fwrite($xmlfile, '<pubDate>' . $fulldate . '</pubDate>'.PHP_EOL);
fwrite($xmlfile, '<description>Posts for '.$normdate.'</description>'.PHP_EOL);
fwrite($xmlfile, '<content:encoded><![CDATA[' . $fullcontent . ']]></content:encoded>'.PHP_EOL);
fwrite($xmlfile, '</item>'.PHP_EOL);
// end add post to RSS
$fullcontent = '';
$count++;
$sql->close();
$normdate = date("d/m/Y", strtotime($dbdate .'-1 day'));
$dbdate = date('Y/m/d', strtotime($dbdate .' -1 day'));
$feeddate = date('Y-m-d', strtotime($feeddate .' -1 day'));
} // end while
// close RSS
fwrite($xmlfile, '</channel>'.PHP_EOL);
fwrite($xmlfile, '</rss>'.PHP_EOL);
fclose($xmlfile);
// end feed
?>