EGOCMS  24.0
EGOTEC Content-Managament-System
RSSCreator.php
gehe zur Dokumentation dieser Datei
1 <?php
6 class RSSCreator
7 {
8  private $image_url = '';
9  private $image_title = '';
10 
11  private $title = '';
12  private $link = '';
13  private $url = '';
14  private $descripton = '';
15 
16  private $items = array();
17 
18  function __construct($title, $link, $description = '')
19  {
20  $this->title = $title;
21  $this->link = $link;
22  $this->url = $GLOBALS['page']->getUrl(
23  array(
24  'suffix' => ltrim($_SERVER['REQUEST_SUFFIX'], '.'),
25  'return_absolute' => true
26  )
27  );
28  $this->description = $description;
29  }
30 
31  function setImage($url, $title)
32  {
33  $this->image_url = $url;
34  $this->image_title = $title;
35  }
36 
41  function addItem($title, $descr, $link, $author = '', $pubDate = 0, $extra = array())
42  {
43  $index = sizeof($this->items);
44  $this->items[$index]['title'] = $title;
45  $this->items[$index]['descr'] = $descr;
46  $this->items[$index]['link'] = $link;
47  $this->items[$index]['author'] = $author;
48  $this->items[$index]['pubDate'] = $pubDate;
49  $this->items[$index]['extra'] = $extra;
50  }
51 
52  private function getHeader()
53  {
54  $local_zone = timezone_open('Europe/Berlin');
55  $to_zone = timezone_open('GMT');
56  $startobj = date_create("now", $local_zone);
57  $startobj->setTimezone($to_zone);
58  $date = $startobj->format('D, d M Y H:i:s').' GMT';
59 
60  $r = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
61  <rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">
62 
63  <channel>
64  <atom:link href=\"".$this->url."\" rel=\"self\" type=\"application/rss+xml\" />
65  <title><![CDATA[".$this->title."]]></title>
66 
67  <link>".$this->link."</link>
68  <description><![CDATA[".$this->description."]]></description>
69  <pubDate>".$date."</pubDate>
70  ";
71  if ($this->image_url != '' && $this->image_title != '')
72  {
73  $r.='<image><url>'.$this->image_url.'</url><title><![CDATA['.$this->image_title.']]></title><link>'.$this->link.'</link></image>';
74  }
75 
76  return $r;
77  }
78 
79  function export()
80  {
81  $return = $this->getHeader();
82  foreach($this->items as $item)
83  {
84  $author = '';
85  if($item['author']) {
86  $author = '<author><![CDATA['.$item['author'].']]></author>';
87  }
88  $return.='
89  <item>
90  <title><![CDATA['.$item['title'].']]></title>
91  <description><![CDATA['.$item['descr'].']]></description>
92  <link>'.$item['link'].'</link>
93  <guid>'.$item['link'].'</guid>
94  '. $author . '
95  <pubDate>'.$item['pubDate'].'</pubDate>
96  </item>';
97 
98  }
99  $return.= $this->getFooter();
100 
101  return $return;
102  }
103 
104  private function getFooter()
105  {
106  $r ='
107  </channel>
108  </rss>';
109  return $r;
110  }
111 }
112 
113 ?>
setImage($url, $title)
Definition: RSSCreator.php:31
addItem($title, $descr, $link, $author='', $pubDate=0, $extra=array())
Definition: RSSCreator.php:41
__construct($title, $link, $description='')
Definition: RSSCreator.php:18