-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrss10.inc
executable file
·161 lines (146 loc) · 4.27 KB
/
rss10.inc
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
// $Id: rss10.inc,v 1.2 2006/05/08 03:13:40 arensb Exp $
//
// A convenience class to make it easy to write RSS classes
// Edd Dumbill <mailto:edd+rsswriter@usefulinc.com>
//
// $Log: rss10.inc,v $
// Revision 1.2 2006/05/08 03:13:40 arensb
// Cleaned up indentation, K&R style.
//
// Revision 1.1.1.1 2006/04/26 12:23:02 arensb
// Mirror of Subversion source, so I can keep track of my changes.
//
// Revision 1.3 2001/05/20 17:58:02 edmundd
// Final distribution tweaks.
//
// Revision 1.2 2001/05/20 17:41:30 edmundd
// Ready for distribution.
//
// Revision 1.1 2001/05/20 17:01:43 edmundd
// First functional draft of code working.
//
// Revision 1.1 2001/05/17 18:17:46 edmundd
// Start of a convenience library to help RSS1.0 creation
//
class RSSWriter {
function RSSWriter($uri, $title, $description, $meta=array()) {
$this->chaninfo=array();
$this->website=$uri;
$this->chaninfo["link"]=$uri;
$this->chaninfo["description"]=$description;
$this->chaninfo["title"]=$title;
$this->items=array();
$this->modules=array("dc" => "http://purl.org/dc/elements/1.1/");
// thanks James Mills for bugfix to this line
$this->channelURI=str_replace("&", "&", "http://" . $GLOBALS["SERVER_NAME"] . $GLOBALS["REQUEST_URI"]);
foreach ($meta as $key => $value) {
$this->chaninfo[$key]=$value;
}
}
function useModule($prefix, $uri) {
$this->modules[$prefix]=$uri;
}
function setImage($imgURI, $imgAlt, $imgWidth=88, $imgHeight=31) {
$this->image=array(
"uri" => $imgURI, "title" => $imgAlt, "width" => $imgWidth,
"height" => $imgHeight
);
}
function addItem($uri, $title, $meta=array()) {
$item=array("uri" => $uri, "link" => $uri,
"title" => $this->deTag($title));
foreach ($meta as $key => $value)
{
if ($key == "description" || $key == "dc:description")
{
$value=$this->deTag($value);
}
$item[$key]=$value;
}
$this->items[]=$item;
}
function serialize() {
$this->preamble();
$this->channelinfo();
$this->image();
$this->items();
$this->postamble();
}
function deTag($in) {
while(ereg('<[^>]+>', $in)) {
$in=ereg_replace('<[^>]+>', '', $in);
}
return $in;
}
function preamble() {
header("Content-type: text/xml");
print '<?xml version="1.0" encoding="iso-8859-1"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:mn="http://usefulinc.com/rss/manifest/"
';
foreach ($this->modules as $prefix => $uri) {
print " xmlns:${prefix}=\"${uri}\"\n";
}
print ">\n\n";
}
function channelinfo() {
print ' <channel rdf:about="' . $this->channelURI . '">
';
$i=$this->chaninfo;
foreach (array("title", "link", "dc:source", "description",
"dc:language", "dc:publisher",
"dc:creator", "dc:rights") as $f) {
if (isset($i[$f])) {
print " <${f}>" . htmlspecialchars($i[$f]) . "</${f}>\n";
}
}
if (isset($this->image)) {
print " <image rdf:resource=\"" . htmlspecialchars($this->image["uri"]) . "\" />\n";
}
print " <items>\n";
print " <rdf:Seq>\n";
foreach ($this->items as $i) {
print " <rdf:li rdf:resource=\"" . htmlspecialchars($i["uri"]) . "\" />\n";
}
print " </rdf:Seq>\n";
print " </items>\n";
print " </channel>\n\n";
}
function image() {
if (isset($this->image)) {
print " <image rdf:about=\"" . htmlspecialchars($this->image["uri"]) . "\">\n";
print " <title>" . htmlspecialchars($this->image["title"]) . "</title>\n";
print " <url>" . htmlspecialchars($this->image["uri"]) . "</url>\n";
print " <link>" . htmlspecialchars($this->website) . "</link>\n";
if ($this->chaninfo["description"])
print " <dc:description>" .
htmlspecialchars($this->chaninfo["description"]) .
"</dc:description>\n";
print " </image>\n\n";
}
}
function postamble() {
print '</rdf:RDF>';
}
function items() {
foreach ($this->items as $item) {
print " <item rdf:about=\"" . htmlspecialchars($item["uri"]) . "\">\n";
foreach ($item as $key => $value) {
if ($key!="uri") {
if (is_array($value)) {
foreach ($value as $v1) {
print " <${key}>" . htmlspecialchars($v1) . "</${key}>\n";
}
} else {
print " <${key}>" . htmlspecialchars($value) . "</${key}>\n";
}
}
}
print " </item>\n\n";
}
}
}
?>