ILIAS  Release_4_2_x_branch Revision 61807
 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(
147  ilNewsItem::determineNewsContent($item["context_obj_type"], $item["content"], $item["content_text_is_lang_var"]))));
148 
149  // lm hack, not nice
150  if (in_array($item["context_obj_type"], array("dbk", "lm")) && $item["context_sub_obj_type"] == "pg"
151  && $item["context_sub_obj_id"] > 0)
152  {
153  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
154  "&amp;target=pg_".$item["context_sub_obj_id"]."_".$item["ref_id"]);
155  }
156  else if ($item["context_obj_type"] == "wiki" && $item["context_sub_obj_type"] == "wpg"
157  && $item["context_sub_obj_id"] > 0)
158  {
159  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
160  $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]);
161  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
162  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]."_".$wptitle);
163  }
164  else if (in_array($item["context_obj_type"], array("frm")) && $item["context_sub_obj_type"] == "pos"
165  && $item["context_sub_obj_id"] > 0)
166  {
167  // frm hack, not nice
168  include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
169  $thread_id = ilObjForumAccess::_getThreadForPosting($item["context_sub_obj_id"]);
170  if ($thread_id > 0)
171  {
172  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
173  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]."_".$thread_id."_".$item["context_sub_obj_id"]);
174  }
175  else
176  {
177  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
178  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
179  }
180  }
181  else
182  {
183  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
184  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
185 //echo "<br>".ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
186 // "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"];
187  }
188 
189  $feed_item->setAbout($feed_item->getLink()."&amp;il_about_feed=".$item["id"]);
190  $feed_item->setDate($item["creation_date"]);
191 
192  // Enclosure
193  if ($item["content_type"] == NEWS_AUDIO &&
194  $item["mob_id"] > 0 && ilObject::_exists($item["mob_id"]))
195  {
196  $go_on = true;
197  if ($obj_type == "mcst")
198  {
199  include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
200 
202  {
203  $go_on = false;
204  }
205  }
206 
207  if ($go_on)
208  {
209  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
210  $url = ilObjMediaObject::_lookupItemPath($item["mob_id"], true, true, $mob["purpose"]);
211  $file = ilObjMediaObject::_lookupItemPath($item["mob_id"], false, false, $mob["purpose"]);
212  if (is_file($file))
213  {
214  $size = filesize($file);
215  }
216  $feed_item->setEnclosureUrl($url);
217  $feed_item->setEnclosureType((isset($mob["format"]))?$mob["format"]:"audio/mpeg");
218  $feed_item->setEnclosureLength($size);
219  }
220  }
221  $this->addItem($feed_item);
222  }
223  }
224 }
225 ?>