ILIAS  eassessment Revision 61809
 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  $cont_loc = new ilLocatorGUI();
79  $cont_loc->addContextItems($a_ref_id, true);
80  $cont_loc->setTextOnly(true);
81  $loc = $cont_loc->getHTML();
82  if (trim($loc) != "")
83  {
84  $loc = " [".$loc."] ";
85  }
86 
87  $rss_period = ilNewsItem::_lookupRSSPeriod();
88 
90  $news_item = new ilNewsItem();
91  $news_item->setContextObjId($obj_id);
92  $news_item->setContextObjType($obj_type);
93  $items = $news_item->getNewsForRefId($a_ref_id, true, false, $rss_period, true);
94 
95  if ($a_purpose) {
96  include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
97  }
98 
99  $i = 0;
100  foreach($items as $item)
101  {
102  $i++;
103 
104  if ($a_purpose != false && $obj_type == "mcst")
105  {
106  $mob = ilMediaItem::_getMediaItemsOfMObId($item[mob_id], $a_purpose);
107 
108  if ($mob == false)
109  {
110  continue;
111  }
112 
113  }
114 
115  $obj_title = ilObject::_lookupTitle($item["context_obj_id"]);
116 
117  $feed_item = new ilFeedItem();
118 
120  ($item["context_obj_type"], $item["title"], $item["content_is_lang_var"],
121  $item["agg_ref_id"], $item["aggregation"]);
122 
123  // path
124  $cont_loc = new ilLocatorGUI();
125  $cont_loc->addContextItems($item["ref_id"], true, $a_ref_id);
126  $cont_loc->setTextOnly(true);
127  $loc = $cont_loc->getHTML();
128  if (trim($loc) != "")
129  {
130  $loc = "[".$loc."]";
131  }
132 
133  if ($news_set->get("rss_title_format") == "news_obj")
134  {
135  $sep = (trim($this->prepareStr($loc)) == "")
136  ? ""
137  : " ";
138  $feed_item->setTitle($this->prepareStr($title)." (".$this->prepareStr($loc).$sep.$this->prepareStr($obj_title).
139  ")");
140  }
141  else
142  {
143  $feed_item->setTitle($this->prepareStr($loc)." ".$this->prepareStr($obj_title).
144  ": ".$this->prepareStr($title));
145  }
146  $feed_item->setDescription($this->prepareStr(nl2br($item["content"])));
147 
148  // lm hack, not nice
149  if (in_array($item["context_obj_type"], array("dbk", "lm")) && $item["context_sub_obj_type"] == "pg"
150  && $item["context_sub_obj_id"] > 0)
151  {
152  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
153  "&amp;target=pg_".$item["context_sub_obj_id"]."_".$item["ref_id"]);
154  }
155  else if (in_array($item["context_obj_type"], array("frm")) && $item["context_sub_obj_type"] == "pos"
156  && $item["context_sub_obj_id"] > 0)
157  {
158  // frm hack, not nice
159  include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
160  $thread_id = ilObjForumAccess::_getThreadForPosting($item["context_sub_obj_id"]);
161  if ($thread_id > 0)
162  {
163  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
164  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]."_".$thread_id."_".$item["context_sub_obj_id"]);
165  }
166  else
167  {
168  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
169  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
170  }
171  }
172  else
173  {
174  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
175  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
176 //echo "<br>".ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
177 // "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"];
178  }
179 
180  $feed_item->setAbout($feed_item->getLink()."&amp;il_about_feed=".$item["id"]);
181  $feed_item->setDate($item["creation_date"]);
182 
183  // Enclosure
184  if ($item["content_type"] == NEWS_AUDIO &&
185  $item["mob_id"] > 0 && ilObject::_exists($item["mob_id"]))
186  {
187  $go_on = true;
188  if ($obj_type == "mcst")
189  {
190  include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
191 
193  {
194  $go_on = false;
195  }
196  }
197 
198  if ($go_on)
199  {
200  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
201  $url = ilObjMediaObject::_lookupItemPath($item["mob_id"], true, true, $mob["purpose"]);
202  $file = ilObjMediaObject::_lookupItemPath($item["mob_id"], false, false, $mob["purpose"]);
203  if (is_file($file))
204  {
205  $size = filesize($file);
206  }
207  $feed_item->setEnclosureUrl($url);
208  $feed_item->setEnclosureType((isset($mob["format"]))?$mob["format"]:"audio/mpeg");
209  $feed_item->setEnclosureLength($size);
210  }
211  }
212  $this->addItem($feed_item);
213  }
214  }
215 }
216 ?>