ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectFeedWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/News/classes/class.ilNewsItem.php");
6 include_once("./Services/Feeds/classes/class.ilFeedItem.php");
7 include_once("./Services/Feeds/classes/class.ilFeedWriter.php");
8 
20 {
21  function ilObjectFeedWriter($a_ref_id, $a_userid = false, $a_purpose = false)
22  {
23  global $ilSetting, $lng;
24 
26 
27  if ($a_ref_id <= 0)
28  {
29  return;
30  }
31 
32  include_once("./Services/Block/classes/class.ilBlockSetting.php");
33  $news_set = new ilSetting("news");
34  if (!$news_set->get("enable_rss_for_internal"))
35  {
36  return;
37  }
38  $obj_id = ilObject::_lookupObjId($a_ref_id);
39  $obj_type = ilObject::_lookupType($obj_id);
40  $obj_title = ilObject::_lookupTitle($obj_id);
41 
42  if (!ilBlockSetting::_lookup("news", "public_feed", 0, $obj_id))
43  {
44  return;
45  }
46 
47  if ($ilSetting->get('short_inst_name') != "")
48  {
49  $this->setChannelTitle($ilSetting->get('short_inst_name')." - ".
50  $this->prepareStr($loc.$obj_title));
51  }
52  else
53  {
54  $this->setChannelTitle("ILIAS"." - ".
55  $this->prepareStr($loc.$obj_title.($a_purpose ? " - ".$a_purpose : "")));
56  }
57  $this->setChannelAbout(ILIAS_HTTP_PATH);
58  $this->setChannelLink(ILIAS_HTTP_PATH);
59  // not nice, to do: general solution
60  if ($obj_type == "mcst")
61  {
62  include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
63 
65  {
66  $lng->loadLanguageModule("mcst");
67 
68  $feed_item = new ilFeedItem();
69  $feed_item->setTitle($lng->txt("mcst_media_cast_not_online"));
70  $feed_item->setDescription($lng->txt("mcst_media_cast_not_online_text"));
71  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
72  "&amp;target=".$item["context_obj_type"]);
73  $this->addItem($feed_item);
74  return;
75  }
76  }
77 
78  include_once("./Services/Locator/classes/class.ilLocatorGUI.php");
79  $cont_loc = new ilLocatorGUI();
80  $cont_loc->addContextItems($a_ref_id, true);
81  $cont_loc->setTextOnly(true);
82  $loc = $cont_loc->getTextVersion();
83  if (trim($loc) != "")
84  {
85  $loc = " [".$loc."] ";
86  }
87 
88  $rss_period = ilNewsItem::_lookupRSSPeriod();
89 
91  $news_item = new ilNewsItem();
92  $news_item->setContextObjId($obj_id);
93  $news_item->setContextObjType($obj_type);
94  $items = $news_item->getNewsForRefId($a_ref_id, true, false, $rss_period, true);
95 
96  if ($a_purpose) {
97  include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
98  }
99 
100  $i = 0;
101  foreach($items as $item)
102  {
103  $i++;
104 
105  if ($a_purpose != false && $obj_type == "mcst")
106  {
107  $mob = ilMediaItem::_getMediaItemsOfMObId($item[mob_id], $a_purpose);
108 
109  if ($mob == false)
110  {
111  continue;
112  }
113 
114  }
115 
116  $obj_title = ilObject::_lookupTitle($item["context_obj_id"]);
117 
118  $feed_item = new ilFeedItem();
119 
121  ($item["context_obj_type"], $item["title"], $item["content_is_lang_var"],
122  $item["agg_ref_id"], $item["aggregation"]);
123 
124  // path
125  $cont_loc = new ilLocatorGUI();
126  $cont_loc->addContextItems($item["ref_id"], true, $a_ref_id);
127  $cont_loc->setTextOnly(true);
128  $loc = $cont_loc->getHTML();
129  if (trim($loc) != "")
130  {
131  $loc = "[".$loc."]";
132  }
133 
134  if ($news_set->get("rss_title_format") == "news_obj")
135  {
136  $sep = (trim($this->prepareStr($loc)) == "")
137  ? ""
138  : " ";
139  $feed_item->setTitle($this->prepareStr($title)." (".$this->prepareStr($loc).$sep.$this->prepareStr($obj_title).
140  ")");
141  }
142  else
143  {
144  $feed_item->setTitle($this->prepareStr($loc)." ".$this->prepareStr($obj_title).
145  ": ".$this->prepareStr($title));
146  }
147  $feed_item->setDescription($this->prepareStr(nl2br(
148  ilNewsItem::determineNewsContent($item["context_obj_type"], $item["content"], $item["content_text_is_lang_var"]))));
149 
150  // lm hack, not nice
151  if (in_array($item["context_obj_type"], array("dbk", "lm")) && $item["context_sub_obj_type"] == "pg"
152  && $item["context_sub_obj_id"] > 0)
153  {
154  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
155  "&amp;target=pg_".$item["context_sub_obj_id"]."_".$item["ref_id"]);
156  }
157  else if ($item["context_obj_type"] == "wiki" && $item["context_sub_obj_type"] == "wpg"
158  && $item["context_sub_obj_id"] > 0)
159  {
160  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
161  $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]);
162  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
163  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]."_".$wptitle);
164  }
165  else if (in_array($item["context_obj_type"], array("frm")) && $item["context_sub_obj_type"] == "pos"
166  && $item["context_sub_obj_id"] > 0)
167  {
168  // frm hack, not nice
169  include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
170  $thread_id = ilObjForumAccess::_getThreadForPosting($item["context_sub_obj_id"]);
171  if ($thread_id > 0)
172  {
173  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
174  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]."_".$thread_id."_".$item["context_sub_obj_id"]);
175  }
176  else
177  {
178  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
179  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
180  }
181  }
182  else
183  {
184  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
185  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
186 //echo "<br>".ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
187 // "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"];
188  }
189 
190  $feed_item->setAbout($feed_item->getLink()."&amp;il_about_feed=".$item["id"]);
191  $feed_item->setDate($item["creation_date"]);
192 
193  // Enclosure
194  if ($item["content_type"] == NEWS_AUDIO &&
195  $item["mob_id"] > 0 && ilObject::_exists($item["mob_id"]))
196  {
197  $go_on = true;
198  if ($obj_type == "mcst")
199  {
200  include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
201 
203  {
204  $go_on = false;
205  }
206  }
207 
208  if ($go_on)
209  {
210  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
211  $url = ilObjMediaObject::_lookupItemPath($item["mob_id"], true, true, $mob["purpose"]);
212  $file = ilObjMediaObject::_lookupItemPath($item["mob_id"], false, false, $mob["purpose"]);
213  if (is_file($file))
214  {
215  $size = filesize($file);
216  }
217  $feed_item->setEnclosureUrl($url);
218  $feed_item->setEnclosureType((isset($mob["format"]))?$mob["format"]:"audio/mpeg");
219  $feed_item->setEnclosureLength($size);
220  }
221  }
222  $this->addItem($feed_item);
223  }
224  }
225 }
226 ?>