-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrss.php
More file actions
137 lines (115 loc) · 4.25 KB
/
Copy pathrss.php
File metadata and controls
137 lines (115 loc) · 4.25 KB
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
/*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Copyright (c) 2014, 2016-2017 Fernando Mercês
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
class Feed {
public $header = '<?xml version="1.0" encoding="UTF-8"?>';
}
class Rss extends Feed {
public $rssversion=
'xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"';
public $channel;
public $items = array();
function publishChannel() {
echo "<channel>\n".
"<title>".$this->channel->title."</title>\n".
'<atom:link href="'.$this->channel->feedlink.'" rel="self" type="application/rss+xml" />'."\n".
"<link>".$this->channel->link."</link>\n".
"<description>".$this->channel->description."</description>\n".
"<language>".$this->channel->language."</language>\n".
"<sy:updatePeriod>".$this->channel->updatePeriod."</sy:updatePeriod>\n".
"<sy:updateFrequency>".$this->channel->updateFrequency."</sy:updateFrequency>\n".
"<pubDate>".$this->channel->pubDate."</pubDate>\n".
"<lastBuildDate>".$this->channel->lastBuildDate."</lastBuildDate>\n".
"<docs>".$this->channel->docs."</docs>\n".
"<generator>".$this->channel->generator."</generator>\n";
}
function publishItems() {
foreach ($this->items as $i) {
echo "<item>\n".
"<title>".$i->title."</title>\n".
"<link>".$i->link."</link>\n".
'<guid isPermaLink="false">'.$i->link."</guid>\n".
"<dc:creator>".$i->dccreator."</dc:creator>\n".
"<description><![CDATA[".$i->description."]]></description>\n".
"<content:encoded>\n<![CDATA[".$i->content."]]>\n</content:encoded>\n".
"<pubDate>".$i->pubDate."</pubDate>\n".
"</item>\n";
}
}
function publishEnd() { echo "</channel>\n</rss>"; }
function publish() {
header("Content-Type: application/rss+xml");
echo $this->header."\n";
echo '<rss version="2.0"'."\n".$this->rssversion."\n>\n";
$this->publishChannel();
$this->publishItems();
$this->publishEnd();
}
}
class Channel {
public $title;
public $feedlink;
public $link;
public $description;
public $language = 'pt-br';
public $updatePeriod = 'hourly';
public $updateFrequency = 1;
public $pubDate;
public $lastBuildDate;
public $docs;
public $generator;
}
class Item {
public $title;
public $link;
public $dccreator;
public $description;
public $content;
public $pubDate;
}
// cricação do canal
$c = new Channel();
$c->title = 'Mente Binária';
$c->feedlink = 'http://www.mentebinaria.com.br/rss';
$c->link = 'http://www.mentebinaria.com.br/';
$c->description = 'um site no mínimo diferente sobre tecnologia';
$c->pubDate = 'Sun, 18 Sep 2011 23:06:00 -0300';
$c->lastBuildDate = 'Mon, 26 Nov 2013 14:00:00 -0300';
$c->docs = 'http://www.mentebinaria.com.br/rss';
$c->generator = 'classe php do mente binária';
// item
$item = new Item();
$item->title = 'Nova distribuição Linux rápida, segura e moderna! Sei.';
$item->link = 'http://www.mentebinaria.com.br/blog#12';
$item->dccreator = 'Fernando Mercês';
$item->description = '';
$item->content =
'<p>
Motivei-me a escrever este texto dada a recente enxurrada de distribuições Linux que vêm surgindo de tempos em tempos. Basta dar uma rápida olhada no site DistroWatch [1] pra ver a quantidade de distribuições que estão em pleno desenvolvimento. Várias redundantes em relação ís outras, no entanto.
</p>';
$item->pubDate = 'Mon, 26 Nov 2013 14:00:00 -0300';
$r = new Rss();
$r->channel = $c;
$r->items[] = $item;
$r->publish();
?>