ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilUserFeedWriter.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 
22  function ilUserFeedWriter($a_user_id, $a_hash, $privFeed = false)
23  {
24  global $ilSetting, $lng;
25 
27 
28  //$lng->loadLanguageModule("news");
29 
30  if ($a_user_id == "" || $a_hash == "")
31  {
32  return;
33  }
34 
35  $news_set = new ilSetting("news");
36  if (!$news_set->get("enable_rss_for_internal"))
37  {
38  return;
39  }
40 
41  include_once "Services/User/classes/class.ilObjUser.php";
42  $hash = ilObjUser::_lookupFeedHash($a_user_id);
43 
44  include_once("./Services/News/classes/class.ilNewsItem.php");
45  $rss_period = ilNewsItem::_lookupRSSPeriod();
46 
47  if ($a_hash == $hash)
48  {
49  if ($privFeed)
50  {
51  //ilNewsItem::setPrivateFeedId($a_user_id);
52  $items = ilNewsItem::_getNewsItemsOfUser($a_user_id, false, true, $rss_period);
53  }
54  else
55  {
56  $items = ilNewsItem::_getNewsItemsOfUser($a_user_id, true, true, $rss_period);
57  }
58 
59  if ($ilSetting->get('short_inst_name') != "")
60  {
61  $this->setChannelTitle($ilSetting->get('short_inst_name'));
62  }
63  else
64  {
65  $this->setChannelTitle("ILIAS");
66  }
67 
68  $this->setChannelAbout(ILIAS_HTTP_PATH);
69  $this->setChannelLink(ILIAS_HTTP_PATH);
70  //$this->setChannelDescription("ILIAS Channel Description");
71  $i = 0;
72  foreach($items as $item)
73  {
74  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
75  $obj_type = ilObject::_lookupType($obj_id);
76  $obj_title = ilObject::_lookupTitle($obj_id);
77 
78  // not nice, to do: general solution
79  if ($obj_type == "mcst")
80  {
81  include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
83  {
84  continue;
85  }
86  }
87 
88  $i++;
89  $feed_item = new ilFeedItem();
91  ($item["context_obj_type"], $item["title"], $item["content_is_lang_var"],
92  $item["agg_ref_id"], $item["aggregation"]);
93 
94  // path
95  include_once("./Services/Locator/classes/class.ilLocatorGUI.php");
96  $cont_loc = new ilLocatorGUI();
97  $cont_loc->addContextItems($item["ref_id"], true);
98  $cont_loc->setTextOnly(true);
99  $loc = "[".$cont_loc->getHTML()."]";
100 
101  // title
102  if ($news_set->get("rss_title_format") == "news_obj")
103  {
104  $feed_item->setTitle($this->prepareStr(str_replace("<br />", " ", $title)).
105  " (".$this->prepareStr($loc)." ".$this->prepareStr($obj_title).
106  ")");
107  }
108  else
109  {
110  $feed_item->setTitle($this->prepareStr($loc)." ".$this->prepareStr($obj_title).
111  ": ".$this->prepareStr(str_replace("<br />", " ", $title)));
112  }
113 
114  // description
115  $content = $this->prepareStr(nl2br(
116  ilNewsItem::determineNewsContent($item["context_obj_type"], $item["content"], $item["content_text_is_lang_var"])));
117  $feed_item->setDescription($content);
118 
119  // lm page hack, not nice
120  if (in_array($item["context_obj_type"], array("dbk", "lm")) && $item["context_sub_obj_type"] == "pg"
121  && $item["context_sub_obj_id"] > 0)
122  {
123  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
124  "&amp;target=pg_".$item["context_sub_obj_id"]."_".$item["ref_id"]);
125  }
126  else if ($item["context_obj_type"] == "wiki" && $item["context_sub_obj_type"] == "wpg"
127  && $item["context_sub_obj_id"] > 0)
128  {
129  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
130  $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]);
131  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
132  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]."_".urlencode($wptitle)); // #14629
133  }
134  else if (in_array($item["context_obj_type"], array("frm")) && $item["context_sub_obj_type"] == "pos"
135  && $item["context_sub_obj_id"] > 0)
136  {
137  // frm hack, not nice
138  include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
139  $thread_id = ilObjForumAccess::_getThreadForPosting($item["context_sub_obj_id"]);
140  if ($thread_id > 0)
141  {
142  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
143  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]."_".$thread_id."_".$item["context_sub_obj_id"]);
144  }
145  else
146  {
147  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
148  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
149  }
150  }
151  else
152  {
153  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
154  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
155  }
156  $feed_item->setAbout($feed_item->getLink()."&amp;il_about_feed=".$item["id"]);
157  $feed_item->setDate($item["creation_date"]);
158  $this->addItem($feed_item);
159  }
160  }
161  }
162 }
163 ?>