ILIAS  release_7 Revision v7.30-3-g800a261c036
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
5include_once("Services/Feeds/classes/class.ilFeedItem.php");
6
26{
30 protected $tree;
31
35 protected $lng;
36
37 public $encoding = "UTF-8";
38 public $ch_about = "";
39 public $ch_title = "";
40 public $ch_link = "";
41 public $ch_description = "";
42 public $items = array();
43
47 public function __construct()
48 {
49 global $DIC;
50
51 $this->tree = $DIC->repositoryTree();
52 $this->lng = $DIC->language();
53 }
54
58 public function setEncoding($a_enc)
59 {
60 $this->encoding = $a_enc;
61 }
62
63 public function getEncoding()
64 {
65 return $this->encoding;
66 }
67
71 public function setChannelAbout($a_ab)
72 {
73 $this->ch_about = $a_ab;
74 }
75
76 public function getChannelAbout()
77 {
78 return $this->ch_about;
79 }
80
84 public function setChannelTitle($a_title)
85 {
86 $this->ch_title = $a_title;
87 }
88
89 public function getChannelTitle()
90 {
91 return $this->ch_title;
92 }
93
98 public function setChannelLink($a_link)
99 {
100 $this->ch_link = $a_link;
101 }
102
103 public function getChannelLink()
104 {
105 return $this->ch_link;
106 }
107
111 public function setChannelDescription($a_desc)
112 {
113 $this->ch_desc = $a_desc;
114 }
115
116 public function getChannelDescription()
117 {
118 return $this->ch_desc;
119 }
120
125 public function addItem($a_item)
126 {
127 $this->items[] = $a_item;
128 }
129
130 public function getItems()
131 {
132 return $this->items;
133 }
134
135 public function prepareStr($a_str)
136 {
137 $a_str = str_replace("&", "&amp;", $a_str);
138 $a_str = str_replace("<", "&lt;", $a_str);
139 $a_str = str_replace(">", "&gt;", $a_str);
140 return $a_str;
141 }
142
146 public function getFeed()
147 {
148 include_once("./Services/UICore/classes/class.ilTemplate.php");
149 $this->tpl = new ilTemplate("tpl.rss_2_0.xml", true, true, "Services/Feeds");
150
151 $this->tpl->setVariable("XML", "xml");
152 $this->tpl->setVariable("CONTENT_ENCODING", $this->getEncoding());
153 $this->tpl->setVariable("CHANNEL_ABOUT", $this->getChannelAbout());
154 $this->tpl->setVariable("CHANNEL_TITLE", $this->getChannelTitle());
155 $this->tpl->setVariable("CHANNEL_LINK", $this->getChannelLink());
156 $this->tpl->setVariable("CHANNEL_DESCRIPTION", $this->getChannelDescription());
157
158 foreach ($this->items as $item) {
159 $this->tpl->setCurrentBlock("rdf_seq");
160 $this->tpl->setVariable("RESOURCE", $item->getAbout());
161 $this->tpl->parseCurrentBlock();
162
163 // Date
164 if ($item->getDate() != "") {
165 $this->tpl->setCurrentBlock("date");
166 $d = $item->getDate();
167 $yyyy = substr($d, 0, 4);
168 $mm = substr($d, 5, 2);
169 $dd = substr($d, 8, 2);
170 $h = substr($d, 11, 2);
171 $m = substr($d, 14, 2);
172 $s = substr($d, 17, 2);
173 $this->tpl->setVariable(
174 "ITEM_DATE",
175 date("r", mktime($h, $m, $s, $mm, $dd, $yyyy))
176 );
177 $this->tpl->parseCurrentBlock();
178 }
179
180 // Enclosure
181 if ($item->getEnclosureUrl() != "") {
182 $this->tpl->setCurrentBlock("enclosure");
183 $this->tpl->setVariable("ENC_URL", $item->getEnclosureUrl());
184 $this->tpl->setVariable("ENC_LENGTH", $item->getEnclosureLength());
185 $this->tpl->setVariable("ENC_TYPE", $item->getEnclosureType());
186 $this->tpl->parseCurrentBlock();
187 }
188
189 $this->tpl->setCurrentBlock("item");
190 $this->tpl->setVariable("ITEM_ABOUT", $item->getAbout());
191 $this->tpl->setVariable("ITEM_TITLE", $item->getTitle());
192 $this->tpl->setVariable("ITEM_DESCRIPTION", $item->getDescription());
193 $this->tpl->setVariable("ITEM_LINK", $item->getLink());
194 $this->tpl->parseCurrentBlock();
195 }
196
197 $this->tpl->parseCurrentBlock();
198 return $this->tpl->get();
199 }
200
201 public function showFeed()
202 {
203 header("Content-Type: text/xml; charset=UTF-8;");
204 echo $this->getFeed();
205 }
206
207 public function getContextPath($a_ref_id)
208 {
211
212 $items = array();
213
214 if ($a_ref_id > 0) {
215 $path = $tree->getPathFull($a_ref_id);
216
217 // we want to show the full path, from the major container to the item
218 // (folders are not! treated as containers here), at least one parent item
219 $r_path = array_reverse($path);
220 $first = "";
221 $omit = array();
222 $do_omit = false;
223 foreach ($r_path as $key => $row) {
224 if ($first == "") {
225 if (in_array($row["type"], array("root", "cat", "grp", "crs"))) {
226 $first = $row["child"];
227 }
228 }
229 $omit[$row["child"]] = $do_omit;
230 }
231
232 $add_it = false;
233 foreach ($path as $key => $row) {
234 if ($first == $row["child"]) {
235 $add_it = true;
236 }
237
238 if ($add_it && !$omit[$row["child"]] &&
239 (($row["child"] != $a_ref_id))) {
240 if ($row["title"] == "ILIAS" && $row["type"] == "root") {
241 $row["title"] = $lng->txt("repository");
242 }
243 $items[] = $row["title"];
244 }
245 }
246 }
247
248 if (count($items) > 0) {
249 return "[" . implode(" > ", $items) . "]";
250 }
251 return "";
252 }
253}
An exception for terminatinating execution or to throw for unit testing.
Feed writer class.
addItem($a_item)
Add Item Item is an object of type ilFeedItem.
setChannelLink($a_link)
Channel Link URL to which an HTML rendering of the channel title will link.
getFeed()
get feed xml
setEncoding($a_enc)
Set feed encoding.
setChannelAbout($a_ab)
Unique URI that defines the channel.
getContextPath($a_ref_id)
setChannelTitle($a_title)
Channel Title.
__construct()
ilFeedWriter constructor.
setChannelDescription($a_desc)
Channel Description.
special template class to simplify handling of ITX/PEAR
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
global $DIC
Definition: goto.php:24