ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilFeedWriter.php
Go to the documentation of this file.
1<?php
2
31{
32 private string $ch_desc = "";
33 protected ilTree $tree;
34 protected ilLanguage $lng;
35 protected ilTemplate $tpl;
36 public string $encoding = "UTF-8";
37 public string $ch_about = "";
38 public string $ch_title = "";
39 public string $ch_link = "";
40 public string $ch_description = "";
41 public array $items = array();
42
43 public function __construct()
44 {
45 global $DIC;
46
47 $this->tree = $DIC->repositoryTree();
48 $this->lng = $DIC->language();
49 }
50
51 public function setEncoding(string $a_enc): void
52 {
53 $this->encoding = $a_enc;
54 }
55
56 public function getEncoding(): string
57 {
58 return $this->encoding;
59 }
60
61 public function setChannelAbout(string $a_ab): void
62 {
63 $this->ch_about = $a_ab;
64 }
65
66 public function getChannelAbout(): string
67 {
68 return $this->ch_about;
69 }
70
71 public function setChannelTitle(string $a_title): void
72 {
73 $this->ch_title = $a_title;
74 }
75
76 public function getChannelTitle(): string
77 {
78 return $this->ch_title;
79 }
80
81 public function setChannelLink(string $a_link): void
82 {
83 $this->ch_link = $a_link;
84 }
85
86 public function getChannelLink(): string
87 {
88 return $this->ch_link;
89 }
90
91 public function setChannelDescription(string $a_desc): void
92 {
93 $this->ch_desc = $a_desc;
94 }
95
96 public function getChannelDescription(): string
97 {
98 return $this->ch_desc;
99 }
100
101 public function addItem(ilFeedItem $a_item): void
102 {
103 $this->items[] = $a_item;
104 }
105
106 public function getItems(): array
107 {
108 return $this->items;
109 }
110
111 public function prepareStr(string $a_str): string
112 {
113 $a_str = str_replace(["&", "<", ">"], ["&amp;", "&lt;", "&gt;"], $a_str);
114 return $a_str;
115 }
116
117 public function getFeed(): string
118 {
119 $this->tpl = new ilTemplate("tpl.rss_2_0.xml", true, true, "components/ILIAS/Feeds");
120
121 $this->tpl->setVariable("XML", "xml");
122 $this->tpl->setVariable("CONTENT_ENCODING", $this->getEncoding());
123 $this->tpl->setVariable("CHANNEL_ABOUT", $this->getChannelAbout());
124 $this->tpl->setVariable("CHANNEL_TITLE", $this->getChannelTitle());
125 $this->tpl->setVariable("CHANNEL_LINK", $this->getChannelLink());
126 $this->tpl->setVariable("CHANNEL_DESCRIPTION", $this->getChannelDescription());
127
128 foreach ($this->items as $item) {
129 $this->tpl->setCurrentBlock("rdf_seq");
130 $this->tpl->setVariable("RESOURCE", $item->getAbout());
131 $this->tpl->parseCurrentBlock();
132
133 // Date
134 if ($item->getDate() != "") {
135 $this->tpl->setCurrentBlock("date");
136 $d = $item->getDate();
137 $yyyy = substr($d, 0, 4);
138 $mm = substr($d, 5, 2);
139 $dd = substr($d, 8, 2);
140 $h = substr($d, 11, 2);
141 $m = substr($d, 14, 2);
142 $s = substr($d, 17, 2);
143 $this->tpl->setVariable(
144 "ITEM_DATE",
145 date("r", mktime($h, $m, $s, $mm, $dd, $yyyy))
146 );
147 $this->tpl->parseCurrentBlock();
148 }
149
150 // Enclosure
151 if ($item->getEnclosureUrl() != "") {
152 $this->tpl->setCurrentBlock("enclosure");
153 $this->tpl->setVariable("ENC_URL", $item->getEnclosureUrl());
154 $this->tpl->setVariable("ENC_LENGTH", $item->getEnclosureLength());
155 $this->tpl->setVariable("ENC_TYPE", $item->getEnclosureType());
156 $this->tpl->parseCurrentBlock();
157 }
158
159 $this->tpl->setCurrentBlock("item");
160 $this->tpl->setVariable("ITEM_ABOUT", $item->getAbout());
161 $this->tpl->setVariable("ITEM_TITLE", $item->getTitle());
162 $this->tpl->setVariable("ITEM_DESCRIPTION", $item->getDescription());
163 $this->tpl->setVariable("ITEM_LINK", $item->getLink());
164 $this->tpl->parseCurrentBlock();
165 }
166
167 $this->tpl->parseCurrentBlock();
168 return $this->tpl->get();
169 }
170
171 public function showFeed(): void
172 {
173 header("Content-Type: text/xml; charset=UTF-8;");
174 echo $this->getFeed();
175 }
176
177 public function getContextPath(int $a_ref_id): string
178 {
181
182 $items = array();
183
184 if ($a_ref_id > 0) {
185 $path = $tree->getPathFull($a_ref_id);
186
187 // we want to show the full path, from the major container to the item
188 // (folders are not! treated as containers here), at least one parent item
189 $r_path = array_reverse($path);
190 $first = "";
191 $omit = array();
192 $do_omit = false;
193 foreach ($r_path as $key => $row) {
194 if ($first == "") {
195 if (in_array($row["type"], array("root", "cat", "grp", "crs"))) {
196 $first = $row["child"];
197 }
198 }
199 $omit[$row["child"]] = $do_omit;
200 }
201
202 $add_it = false;
203 foreach ($path as $key => $row) {
204 if ($first == $row["child"]) {
205 $add_it = true;
206 }
207
208 if ($add_it && !$omit[$row["child"]] &&
209 (($row["child"] != $a_ref_id))) {
210 if ($row["title"] == "ILIAS" && $row["type"] == "root") {
211 $row["title"] = $lng->txt("repository");
212 }
213 $items[] = $row["title"];
214 }
215 }
216 }
217
218 if (count($items) > 0) {
219 return "[" . implode(" > ", $items) . "]";
220 }
221 return "";
222 }
223}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setEncoding(string $a_enc)
addItem(ilFeedItem $a_item)
getContextPath(int $a_ref_id)
prepareStr(string $a_str)
setChannelAbout(string $a_ab)
setChannelTitle(string $a_title)
setChannelLink(string $a_link)
setChannelDescription(string $a_desc)
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
special template class to simplify handling of ITX/PEAR
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
getPathFull(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
$path
Definition: ltiservices.php:30
global $DIC
Definition: shib_login.php:26