ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFeedWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("Services/Feeds/classes/class.ilFeedItem.php");
6 
26 {
27  var $encoding = "UTF-8";
28  var $ch_about = "";
29  var $ch_title = "";
30  var $ch_link = "";
31  var $ch_description = "";
32  var $items = array();
33 
34  function ilFeedWriter()
35  {
36  }
37 
41  function setEncoding($a_enc)
42  {
43  $this->encoding = $a_enc;
44  }
45 
46  function getEncoding()
47  {
48  return $this->encoding;
49  }
50 
54  function setChannelAbout($a_ab)
55  {
56  $this->ch_about = $a_ab;
57  }
58 
59  function getChannelAbout()
60  {
61  return $this->ch_about;
62  }
63 
67  function setChannelTitle($a_title)
68  {
69  $this->ch_title = $a_title;
70  }
71 
72  function getChannelTitle()
73  {
74  return $this->ch_title;
75  }
76 
81  function setChannelLink($a_link)
82  {
83  $this->ch_link = $a_link;
84  }
85 
86  function getChannelLink()
87  {
88  return $this->ch_link;
89  }
90 
94  function setChannelDescription($a_desc)
95  {
96  $this->ch_desc = $a_desc;
97  }
98 
100  {
101  return $this->ch_desc;
102  }
103 
108  function addItem($a_item)
109  {
110  $this->items[] = $a_item;
111  }
112 
113  function getItems()
114  {
115  return $this->items;
116  }
117 
118  function prepareStr($a_str)
119  {
120  $a_str = str_replace("&", "&amp;", $a_str);
121  $a_str = str_replace("<", "&lt;", $a_str);
122  $a_str = str_replace(">", "&gt;", $a_str);
123  return $a_str;
124  }
125 
129  function getFeed()
130  {
131  include_once("./Services/UICore/classes/class.ilTemplate.php");
132  $this->tpl = new ilTemplate("tpl.rss_2_0.xml", true, true, "Services/Feeds");
133 
134  $this->tpl->setVariable("XML", "xml");
135  $this->tpl->setVariable("CONTENT_ENCODING", $this->getEncoding());
136  $this->tpl->setVariable("CHANNEL_ABOUT", $this->getChannelAbout());
137  $this->tpl->setVariable("CHANNEL_TITLE", $this->getChannelTitle());
138  $this->tpl->setVariable("CHANNEL_LINK", $this->getChannelLink());
139  $this->tpl->setVariable("CHANNEL_DESCRIPTION", $this->getChannelDescription());
140 
141  foreach($this->items as $item)
142  {
143  $this->tpl->setCurrentBlock("rdf_seq");
144  $this->tpl->setVariable("RESOURCE", $item->getAbout());
145  $this->tpl->parseCurrentBlock();
146 
147  // Date
148  if ($item->getDate() != "")
149  {
150  $this->tpl->setCurrentBlock("date");
151  $d = $item->getDate();
152  $yyyy = substr($d, 0, 4);
153  $mm = substr($d, 5, 2);
154  $dd = substr($d, 8, 2);
155  $h = substr($d, 11, 2);
156  $m = substr($d, 14, 2);
157  $s = substr($d, 17, 2);
158  $this->tpl->setVariable("ITEM_DATE",
159  date("r", mktime($h, $m, $s, $mm, $dd, $yyyy)));
160  $this->tpl->parseCurrentBlock();
161  }
162 
163  // Enclosure
164  if ($item->getEnclosureUrl() != "")
165  {
166  $this->tpl->setCurrentBlock("enclosure");
167  $this->tpl->setVariable("ENC_URL", $item->getEnclosureUrl());
168  $this->tpl->setVariable("ENC_LENGTH", $item->getEnclosureLength());
169  $this->tpl->setVariable("ENC_TYPE", $item->getEnclosureType());
170  $this->tpl->parseCurrentBlock();
171  }
172 
173  $this->tpl->setCurrentBlock("item");
174  $this->tpl->setVariable("ITEM_ABOUT", $item->getAbout());
175  $this->tpl->setVariable("ITEM_TITLE", $item->getTitle());
176  $this->tpl->setVariable("ITEM_DESCRIPTION", $item->getDescription());
177  $this->tpl->setVariable("ITEM_LINK", $item->getLink());
178  $this->tpl->parseCurrentBlock();
179 
180  }
181 
182  $this->tpl->parseCurrentBlock();
183  return $this->tpl->get();
184  }
185 
186  function showFeed()
187  {
188  header("Content-Type: text/xml; charset=UTF-8;");
189  echo $this->getFeed();
190  }
191 
192  function getContextPath($a_ref_id)
193  {
194  global $tree, $lng;
195 
196  $items = array();
197 
198  if ($a_ref_id > 0)
199  {
200  $path = $tree->getPathFull($a_ref_id);
201 
202  // we want to show the full path, from the major container to the item
203  // (folders are not! treated as containers here), at least one parent item
204  $r_path = array_reverse($path);
205  $first = "";
206  $omit = array();
207  $do_omit = false;
208  foreach ($r_path as $key => $row)
209  {
210  if ($first == "")
211  {
212  if (in_array($row["type"], array("root", "cat", "grp", "crs")) )
213  {
214  $first = $row["child"];
215  }
216  }
217  $omit[$row["child"]] = $do_omit;
218  }
219 
220  $add_it = false;
221  foreach ($path as $key => $row)
222  {
223  if ($first == $row["child"])
224  {
225  $add_it = true;
226  }
227 
228  if ($add_it && !$omit[$row["child"]] &&
229  (($row["child"] != $a_ref_id)))
230  {
231  if ($row["title"] == "ILIAS" && $row["type"] == "root")
232  {
233  $row["title"] = $lng->txt("repository");
234  }
235  $items[] = $row["title"];
236  }
237  }
238  }
239 
240  if (count($items) > 0)
241  {
242  return "[".implode(" > ", $items)."]";
243  }
244  return "";
245  }
246 
247 
248 }
249 ?>