ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFeedWriter.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("Services/Feeds/classes/class.ilFeedItem.php");
25 
45 {
46  var $encoding = "UTF-8";
47  var $ch_about = "";
48  var $ch_title = "";
49  var $ch_link = "";
50  var $ch_description = "";
51  var $items = array();
52 
53  function ilFeedWriter()
54  {
55  }
56 
60  function setEncoding($a_enc)
61  {
62  $this->encoding = $a_enc;
63  }
64 
65  function getEncoding()
66  {
67  return $this->encoding;
68  }
69 
73  function setChannelAbout($a_ab)
74  {
75  $this->ch_about = $a_ab;
76  }
77 
78  function getChannelAbout()
79  {
80  return $this->ch_about;
81  }
82 
86  function setChannelTitle($a_title)
87  {
88  $this->ch_title = $a_title;
89  }
90 
91  function getChannelTitle()
92  {
93  return $this->ch_title;
94  }
95 
100  function setChannelLink($a_link)
101  {
102  $this->ch_link = $a_link;
103  }
104 
105  function getChannelLink()
106  {
107  return $this->ch_link;
108  }
109 
113  function setChannelDescription($a_desc)
114  {
115  $this->ch_desc = $a_desc;
116  }
117 
119  {
120  return $this->ch_desc;
121  }
122 
127  function addItem($a_item)
128  {
129  $this->items[] = $a_item;
130  }
131 
132  function getItems()
133  {
134  return $this->items;
135  }
136 
137  function prepareStr($a_str)
138  {
139  $a_str = str_replace("&", "&amp;", $a_str);
140  $a_str = str_replace("<", "&lt;", $a_str);
141  $a_str = str_replace(">", "&gt;", $a_str);
142  return $a_str;
143  }
144 
148  function getFeed()
149  {
150  include_once("classes/class.ilTemplate.php");
151  $this->tpl = new ilTemplate("tpl.rss_2_0.xml", true, true, "Services/Feeds");
152 
153  $this->tpl->setVariable("XML", "xml");
154  $this->tpl->setVariable("CONTENT_ENCODING", $this->getEncoding());
155  $this->tpl->setVariable("CHANNEL_ABOUT", $this->getChannelAbout());
156  $this->tpl->setVariable("CHANNEL_TITLE", $this->getChannelTitle());
157  $this->tpl->setVariable("CHANNEL_LINK", $this->getChannelLink());
158  $this->tpl->setVariable("CHANNEL_DESCRIPTION", $this->getChannelDescription());
159 
160  foreach($this->items as $item)
161  {
162  $this->tpl->setCurrentBlock("rdf_seq");
163  $this->tpl->setVariable("RESOURCE", $item->getAbout());
164  $this->tpl->parseCurrentBlock();
165 
166  // Date
167  if ($item->getDate() != "")
168  {
169  $this->tpl->setCurrentBlock("date");
170  $d = $item->getDate();
171  $yyyy = substr($d, 0, 4);
172  $mm = substr($d, 5, 2);
173  $dd = substr($d, 8, 2);
174  $h = substr($d, 11, 2);
175  $m = substr($d, 14, 2);
176  $s = substr($d, 17, 2);
177  $this->tpl->setVariable("ITEM_DATE",
178  date("r", mktime($h, $m, $s, $mm, $dd, $yyyy)));
179  $this->tpl->parseCurrentBlock();
180  }
181 
182  // Enclosure
183  if ($item->getEnclosureUrl() != "")
184  {
185  $this->tpl->setCurrentBlock("enclosure");
186  $this->tpl->setVariable("ENC_URL", $item->getEnclosureUrl());
187  $this->tpl->setVariable("ENC_LENGTH", $item->getEnclosureLength());
188  $this->tpl->setVariable("ENC_TYPE", $item->getEnclosureType());
189  $this->tpl->parseCurrentBlock();
190  }
191 
192  $this->tpl->setCurrentBlock("item");
193  $this->tpl->setVariable("ITEM_ABOUT", $item->getAbout());
194  $this->tpl->setVariable("ITEM_TITLE", $item->getTitle());
195  $this->tpl->setVariable("ITEM_DESCRIPTION", $item->getDescription());
196  $this->tpl->setVariable("ITEM_LINK", $item->getLink());
197  $this->tpl->parseCurrentBlock();
198 
199  }
200 
201  $this->tpl->parseCurrentBlock();
202  return $this->tpl->get();
203  }
204 
205  function showFeed()
206  {
207  header("Content-Type: text/xml; charset=UTF-8;");
208  echo $this->getFeed();
209  }
210 }
211 ?>