ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
27 var $encoding = "UTF-8";
28 var $ch_about = "";
29 var $ch_title = "";
30 var $ch_link = "";
32 var $items = array();
33
37 function __construct()
38 {
39
40 }
41
45 function setEncoding($a_enc)
46 {
47 $this->encoding = $a_enc;
48 }
49
50 function getEncoding()
51 {
52 return $this->encoding;
53 }
54
58 function setChannelAbout($a_ab)
59 {
60 $this->ch_about = $a_ab;
61 }
62
63 function getChannelAbout()
64 {
65 return $this->ch_about;
66 }
67
71 function setChannelTitle($a_title)
72 {
73 $this->ch_title = $a_title;
74 }
75
76 function getChannelTitle()
77 {
78 return $this->ch_title;
79 }
80
85 function setChannelLink($a_link)
86 {
87 $this->ch_link = $a_link;
88 }
89
90 function getChannelLink()
91 {
92 return $this->ch_link;
93 }
94
98 function setChannelDescription($a_desc)
99 {
100 $this->ch_desc = $a_desc;
101 }
102
104 {
105 return $this->ch_desc;
106 }
107
112 function addItem($a_item)
113 {
114 $this->items[] = $a_item;
115 }
116
117 function getItems()
118 {
119 return $this->items;
120 }
121
122 function prepareStr($a_str)
123 {
124 $a_str = str_replace("&", "&amp;", $a_str);
125 $a_str = str_replace("<", "&lt;", $a_str);
126 $a_str = str_replace(">", "&gt;", $a_str);
127 return $a_str;
128 }
129
133 function getFeed()
134 {
135 include_once("./Services/UICore/classes/class.ilTemplate.php");
136 $this->tpl = new ilTemplate("tpl.rss_2_0.xml", true, true, "Services/Feeds");
137
138 $this->tpl->setVariable("XML", "xml");
139 $this->tpl->setVariable("CONTENT_ENCODING", $this->getEncoding());
140 $this->tpl->setVariable("CHANNEL_ABOUT", $this->getChannelAbout());
141 $this->tpl->setVariable("CHANNEL_TITLE", $this->getChannelTitle());
142 $this->tpl->setVariable("CHANNEL_LINK", $this->getChannelLink());
143 $this->tpl->setVariable("CHANNEL_DESCRIPTION", $this->getChannelDescription());
144
145 foreach($this->items as $item)
146 {
147 $this->tpl->setCurrentBlock("rdf_seq");
148 $this->tpl->setVariable("RESOURCE", $item->getAbout());
149 $this->tpl->parseCurrentBlock();
150
151 // Date
152 if ($item->getDate() != "")
153 {
154 $this->tpl->setCurrentBlock("date");
155 $d = $item->getDate();
156 $yyyy = substr($d, 0, 4);
157 $mm = substr($d, 5, 2);
158 $dd = substr($d, 8, 2);
159 $h = substr($d, 11, 2);
160 $m = substr($d, 14, 2);
161 $s = substr($d, 17, 2);
162 $this->tpl->setVariable("ITEM_DATE",
163 date("r", mktime($h, $m, $s, $mm, $dd, $yyyy)));
164 $this->tpl->parseCurrentBlock();
165 }
166
167 // Enclosure
168 if ($item->getEnclosureUrl() != "")
169 {
170 $this->tpl->setCurrentBlock("enclosure");
171 $this->tpl->setVariable("ENC_URL", $item->getEnclosureUrl());
172 $this->tpl->setVariable("ENC_LENGTH", $item->getEnclosureLength());
173 $this->tpl->setVariable("ENC_TYPE", $item->getEnclosureType());
174 $this->tpl->parseCurrentBlock();
175 }
176
177 $this->tpl->setCurrentBlock("item");
178 $this->tpl->setVariable("ITEM_ABOUT", $item->getAbout());
179 $this->tpl->setVariable("ITEM_TITLE", $item->getTitle());
180 $this->tpl->setVariable("ITEM_DESCRIPTION", $item->getDescription());
181 $this->tpl->setVariable("ITEM_LINK", $item->getLink());
182 $this->tpl->parseCurrentBlock();
183
184 }
185
186 $this->tpl->parseCurrentBlock();
187 return $this->tpl->get();
188 }
189
190 function showFeed()
191 {
192 header("Content-Type: text/xml; charset=UTF-8;");
193 echo $this->getFeed();
194 }
195
196 function getContextPath($a_ref_id)
197 {
198 global $tree, $lng;
199
200 $items = array();
201
202 if ($a_ref_id > 0)
203 {
204 $path = $tree->getPathFull($a_ref_id);
205
206 // we want to show the full path, from the major container to the item
207 // (folders are not! treated as containers here), at least one parent item
208 $r_path = array_reverse($path);
209 $first = "";
210 $omit = array();
211 $do_omit = false;
212 foreach ($r_path as $key => $row)
213 {
214 if ($first == "")
215 {
216 if (in_array($row["type"], array("root", "cat", "grp", "crs")) )
217 {
218 $first = $row["child"];
219 }
220 }
221 $omit[$row["child"]] = $do_omit;
222 }
223
224 $add_it = false;
225 foreach ($path as $key => $row)
226 {
227 if ($first == $row["child"])
228 {
229 $add_it = true;
230 }
231
232 if ($add_it && !$omit[$row["child"]] &&
233 (($row["child"] != $a_ref_id)))
234 {
235 if ($row["title"] == "ILIAS" && $row["type"] == "root")
236 {
237 $row["title"] = $lng->txt("repository");
238 }
239 $items[] = $row["title"];
240 }
241 }
242 }
243
244 if (count($items) > 0)
245 {
246 return "[".implode(" > ", $items)."]";
247 }
248 return "";
249 }
250
251
252}
253?>
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
for($col=0; $col< 50; $col++) $d
$path
Definition: aliased.php:25
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
$h
global $lng
Definition: privfeed.php:17