ILIAS  Release_4_1_x_branch Revision 61804
 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  $hash = ilObjUser::_lookupFeedHash($a_user_id);
42 
43  include_once("./Services/News/classes/class.ilNewsItem.php");
44  $rss_period = ilNewsItem::_lookupRSSPeriod();
45 
46  if ($a_hash == $hash)
47  {
48  if ($privFeed)
49  {
50  ilNewsItem::setPrivateFeedId($a_user_id);
51  }
52  $items = ilNewsItem::_getNewsItemsOfUser($a_user_id, true, true, $rss_period);
53  if ($ilSetting->get('short_inst_name') != "")
54  {
55  $this->setChannelTitle($ilSetting->get('short_inst_name'));
56  }
57  else
58  {
59  $this->setChannelTitle("ILIAS");
60  }
61 
62  $this->setChannelAbout(ILIAS_HTTP_PATH);
63  $this->setChannelLink(ILIAS_HTTP_PATH);
64  //$this->setChannelDescription("ILIAS Channel Description");
65  $i = 0;
66  foreach($items as $item)
67  {
68  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
69  $obj_type = ilObject::_lookupType($obj_id);
70  $obj_title = ilObject::_lookupTitle($obj_id);
71 
72  // not nice, to do: general solution
73  if ($obj_type == "mcst")
74  {
75  include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
77  {
78  continue;
79  }
80  }
81 
82  $i++;
83  $feed_item = new ilFeedItem();
85  ($item["context_obj_type"], $item["title"], $item["content_is_lang_var"],
86  $item["agg_ref_id"], $item["aggregation"]);
87 
88  // path
89  $cont_loc = new ilLocatorGUI();
90  $cont_loc->addContextItems($item["ref_id"], true);
91  $cont_loc->setTextOnly(true);
92  $loc = "[".$cont_loc->getHTML()."]";
93 
94  // title
95  if ($news_set->get("rss_title_format") == "news_obj")
96  {
97  $feed_item->setTitle($this->prepareStr(str_replace("<br />", " ", $title)).
98  " (".$this->prepareStr($loc)." ".$this->prepareStr($obj_title).
99  ")");
100  }
101  else
102  {
103  $feed_item->setTitle($this->prepareStr($loc)." ".$this->prepareStr($obj_title).
104  ": ".$this->prepareStr(str_replace("<br />", " ", $title)));
105  }
106 
107  // description
108  $content = $this->prepareStr(nl2br($item["content"]));
109  $feed_item->setDescription($content);
110 
111  // lm page hack, not nice
112  if (in_array($item["context_obj_type"], array("dbk", "lm")) && $item["context_sub_obj_type"] == "pg"
113  && $item["context_sub_obj_id"] > 0)
114  {
115  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
116  "&amp;target=pg_".$item["context_sub_obj_id"]."_".$item["ref_id"]);
117  }
118  else if (in_array($item["context_obj_type"], array("frm")) && $item["context_sub_obj_type"] == "pos"
119  && $item["context_sub_obj_id"] > 0)
120  {
121  // frm hack, not nice
122  include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
123  $thread_id = ilObjForumAccess::_getThreadForPosting($item["context_sub_obj_id"]);
124  if ($thread_id > 0)
125  {
126  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
127  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]."_".$thread_id."_".$item["context_sub_obj_id"]);
128  }
129  else
130  {
131  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
132  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
133  }
134  }
135  else
136  {
137  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
138  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
139  }
140  $feed_item->setAbout($feed_item->getLink()."&amp;il_about_feed=".$item["id"]);
141  $this->addItem($feed_item);
142  }
143  }
144  }
145 }
146 ?>