Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once("Services/Feeds/classes/class.ilFeedItem.php");
00025
00044 class ilFeedWriter
00045 {
00046 var $encoding = "UTF-8";
00047 var $ch_about = "";
00048 var $ch_title = "";
00049 var $ch_link = "";
00050 var $ch_description = "";
00051 var $items = array();
00052
00053 function ilFeedWriter()
00054 {
00055 }
00056
00060 function setEncoding($a_enc)
00061 {
00062 $this->encoding = $a_enc;
00063 }
00064
00065 function getEncoding()
00066 {
00067 return $this->encoding;
00068 }
00069
00073 function setChannelAbout($a_ab)
00074 {
00075 $this->ch_about = $a_ab;
00076 }
00077
00078 function getChannelAbout()
00079 {
00080 return $this->ch_about;
00081 }
00082
00086 function setChannelTitle($a_title)
00087 {
00088 $this->ch_title = $a_title;
00089 }
00090
00091 function getChannelTitle()
00092 {
00093 return $this->ch_title;
00094 }
00095
00100 function setChannelLink($a_link)
00101 {
00102 $this->ch_link = $a_link;
00103 }
00104
00105 function getChannelLink()
00106 {
00107 return $this->ch_link;
00108 }
00109
00113 function setChannelDescription($a_desc)
00114 {
00115 $this->ch_desc = $a_desc;
00116 }
00117
00118 function getChannelDescription()
00119 {
00120 return $this->ch_desc;
00121 }
00122
00127 function addItem($a_item)
00128 {
00129 $this->items[] = $a_item;
00130 }
00131
00132 function getItems()
00133 {
00134 return $this->items;
00135 }
00136
00137 function prepareStr($a_str)
00138 {
00139 $a_str = str_replace("&", "&", $a_str);
00140 $a_str = str_replace("<", "<", $a_str);
00141 $a_str = str_replace(">", ">", $a_str);
00142 return $a_str;
00143 }
00144
00148 function getFeed()
00149 {
00150 include_once("classes/class.ilTemplate.php");
00151 $this->tpl = new ilTemplate("tpl.rss_2_0.xml", true, true, "Services/Feeds");
00152
00153 $this->tpl->setVariable("XML", "xml");
00154 $this->tpl->setVariable("CONTENT_ENCODING", $this->getEncoding());
00155 $this->tpl->setVariable("CHANNEL_ABOUT", $this->getChannelAbout());
00156 $this->tpl->setVariable("CHANNEL_TITLE", $this->getChannelTitle());
00157 $this->tpl->setVariable("CHANNEL_LINK", $this->getChannelLink());
00158 $this->tpl->setVariable("CHANNEL_DESCRIPTION", $this->getChannelDescription());
00159
00160 foreach($this->items as $item)
00161 {
00162 $this->tpl->setCurrentBlock("rdf_seq");
00163 $this->tpl->setVariable("RESOURCE", $item->getAbout());
00164 $this->tpl->parseCurrentBlock();
00165
00166
00167 if ($item->getDate() != "")
00168 {
00169 $this->tpl->setCurrentBlock("date");
00170 $d = $item->getDate();
00171 $yyyy = substr($d, 0, 4);
00172 $mm = substr($d, 5, 2);
00173 $dd = substr($d, 8, 2);
00174 $h = substr($d, 11, 2);
00175 $m = substr($d, 14, 2);
00176 $s = substr($d, 17, 2);
00177 $this->tpl->setVariable("ITEM_DATE",
00178 date("r", mktime($h, $m, $s, $mm, $dd, $yyyy)));
00179 $this->tpl->parseCurrentBlock();
00180 }
00181
00182
00183 if ($item->getEnclosureUrl() != "")
00184 {
00185 $this->tpl->setCurrentBlock("enclosure");
00186 $this->tpl->setVariable("ENC_URL", $item->getEnclosureUrl());
00187 $this->tpl->setVariable("ENC_LENGTH", $item->getEnclosureLength());
00188 $this->tpl->setVariable("ENC_TYPE", $item->getEnclosureType());
00189 $this->tpl->parseCurrentBlock();
00190 }
00191
00192 $this->tpl->setCurrentBlock("item");
00193 $this->tpl->setVariable("ITEM_ABOUT", $item->getAbout());
00194 $this->tpl->setVariable("ITEM_TITLE", $item->getTitle());
00195 $this->tpl->setVariable("ITEM_DESCRIPTION", $item->getDescription());
00196 $this->tpl->setVariable("ITEM_LINK", $item->getLink());
00197 $this->tpl->parseCurrentBlock();
00198
00199 }
00200
00201 $this->tpl->parseCurrentBlock();
00202 return $this->tpl->get();
00203 }
00204
00205 function showFeed()
00206 {
00207 header("Content-Type: text/xml; charset=UTF-8;");
00208 echo $this->getFeed();
00209 }
00210 }
00211 ?>