This repository has been archived by the owner on Jul 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrss2.class.php
81 lines (64 loc) · 2.41 KB
/
rss2.class.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
<?php
/**
* XMLWriter class for rss 2.0
*
* @author Frank Bueltge <[email protected]>
* @copyright 2011 -- Frank Bueltge
* @license Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany
* (http://creativecommons.org/licenses/by-nc-sa/3.0/de/deed.en)
* @link http://bueltge.de
* @version 1.0
* @date 04.07.2011 17:17:29
*/
@date_default_timezone_set("GMT");
class Rss extends XMLWriter {
function __construct( $file = 'php://output', $title, $description, $link, $date ) {
$this -> openURI( $file );
$this -> startDocument( '1.0', 'UTF-8' );
$this -> setIndent( TRUE );
$this -> startElement( 'rss' );
$this -> writeAttribute('version', '2.0');
$this -> writeAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
$url = filter_var( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED );
$this -> startElement( 'atom:link' );
$this -> writeAttribute( 'href', $url );
$this -> writeAttribute( 'rel', 'self' );
$this -> writeAttribute( 'type', 'application/rss+xml' );
$this -> endElement();
$this -> startElement( 'channel' );
$this -> writeElement( 'title', $title );
$this -> writeElement( 'description', $description );
$this -> writeElement( 'link', $link );
$this -> writeElement( 'pubDate', date( 'D, d M Y H:i:s e', strtotime($date) ) );
}
function add_item($array) {
if ( ! is_array($array) )
return;
$this -> startElement( 'item' );
$this -> writeElement( 'title', $array['title'] );
if ( $array['link'] )
$this -> writeElement( 'link', $array['link'] );
$this -> writeElement( 'description', $array['description'] );
if ( $array['guid'] )
$this -> writeElement( 'guid', $array['guid'] );
if ( isset($array['date']) )
$this -> writeElement('pubDate', date( "D, d M Y H:i:s e", strtotime($array['date']) ) );
if ( isset($array['category']) && isset( $array['category']['title']) ) {
$this -> startElement('category');
$this -> writeAttribute('domain', $array['category']['domain']);
$this -> text($array['category']['title']);
$this -> endElement();
}
$this -> endElement();
}
function end_rss() {
// End channel
$this -> endElement();
// End rss
$this -> endElement();
// End doc
$this -> endDocument();
// Flush current buffer
$this -> flush();
}
} // end class