-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
77 lines (65 loc) · 2.55 KB
/
functions.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
<?php
/*----------------------------------------------------------*\
| **** RSS News Feed Reader for Little Printer by BERG **** |
+------------------------------------------------------------+
| Released under the GNU General Public Licence v2 |
+------------------------------------------------------------+
| Created by Damian Worsdell http://djw.net.au/ |
\*----------------------------------------------------------*/
// Set the timezone to the same as the RSS Feed source
date_default_timezone_set('Australia/Perth');
// Remove the empty lines from the content recieved by the RSS feed
function removeEmptyLines($string) {
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);
}
// Remove any source / ad tag (in brackets) from the content recieved by the RSS feed
function removeTag($string) {
return preg_replace("@\(.*?\)@", "", $string);
}
// Generate the header section of the publication
function generateHeader() {
include '../header.php';
// relative URL from /edition and /sample
}
// Read, format and generate the news stories... (main function)
function generateContent() {
$rss = new DOMDocument();
$rss->load('http://au.rss.news.yahoo.com/thewest/breaking.xml'); // ** RSS FEED
$feed = array();
foreach($rss->getElementsByTagName('item') as $node) {
$item = array(
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 5; // ** ITEM LIMIT
for ($x = 0; $x < $limit; $x++) {
$title = removeTag(str_replace(' & ', ' & ', $feed[$x]['title']));
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
echo '<div class="item">';
echo ' <span class="title">' . $title . '</span>';
echo ' <span class="text">' . $description . '</span>';
echo '</div>';
}
}
// Generate the footer section of the publication...
function generateFooter() {
include '../footer.php';
}
// Generate an ETag for the BERG Cloud, ensuring BERG doesn't recieve our content more than once
function littleprinterETag() {
// Get today's date
$date = date('d-m-Y');
// md5 it
header("ETag: " . md5($date));
}
// Set the correct character set
function charset() {
header("Content-Type: text/html; charset=utf-8");
}
?>