ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectFeedWriter.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("./Services/News/classes/class.ilNewsItem.php");
25 include_once("./Services/Feeds/classes/class.ilFeedItem.php");
26 include_once("./Services/Feeds/classes/class.ilFeedWriter.php");
27 
39 {
40  function ilObjectFeedWriter($a_ref_id, $a_userid = false, $a_purpose = false)
41  {
42  global $ilSetting, $lng;
43 
45 
46  if ($a_ref_id <= 0)
47  {
48  return;
49  }
50 
51  include_once("./Services/Block/classes/class.ilBlockSetting.php");
52  $news_set = new ilSetting("news");
53  if (!$news_set->get("enable_rss_for_internal"))
54  {
55  return;
56  }
57  $obj_id = ilObject::_lookupObjId($a_ref_id);
58  $obj_type = ilObject::_lookupType($obj_id);
59  $obj_title = ilObject::_lookupTitle($obj_id);
60 
61  if (!ilBlockSetting::_lookup("news", "public_feed", 0, $obj_id))
62  {
63  return;
64  }
65 
66  if ($ilSetting->get('short_inst_name') != "")
67  {
68  $this->setChannelTitle($ilSetting->get('short_inst_name')." - ".
69  $this->prepareStr($loc.$obj_title));
70  }
71  else
72  {
73  $this->setChannelTitle("ILIAS"." - ".
74  $this->prepareStr($loc.$obj_title.($a_purpose ? " - ".$a_purpose : "")));
75  }
76  $this->setChannelAbout(ILIAS_HTTP_PATH);
77  $this->setChannelLink(ILIAS_HTTP_PATH);
78  // not nice, to do: general solution
79  if ($obj_type == "mcst")
80  {
81  include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
82 
84  {
85  $lng->loadLanguageModule("mcst");
86 
87  $feed_item = new ilFeedItem();
88  $feed_item->setTitle($lng->txt("mcst_media_cast_not_online"));
89  $feed_item->setDescription($lng->txt("mcst_media_cast_not_online_text"));
90  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
91  "&amp;target=".$item["context_obj_type"]);
92  $this->addItem($feed_item);
93  return;
94  }
95  }
96 
97  $cont_loc = new ilLocatorGUI();
98  $cont_loc->addContextItems($a_ref_id, true);
99  $cont_loc->setTextOnly(true);
100  $loc = $cont_loc->getHTML();
101  if (trim($loc) != "")
102  {
103  $loc = " [".$loc."] ";
104  }
105 
106  ilNewsItem::setPrivateFeedId($a_userid);
107  $news_item = new ilNewsItem();
108  $news_item->setContextObjId($obj_id);
109  $news_item->setContextObjType($obj_type);
110  $items = $news_item->getNewsForRefId($a_ref_id, true, false, 0, true);
111 
112  if ($a_purpose) {
113  include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
114  }
115 
116  $i = 0;
117  foreach($items as $item)
118  {
119  $i++;
120 
121  if ($a_purpose != false && $obj_type == "mcst")
122  {
123  $mob = ilMediaItem::_getMediaItemsOfMObId($item[mob_id], $a_purpose);
124 
125  if ($mob == false)
126  {
127  continue;
128  }
129 
130  }
131 
132  $obj_title = ilObject::_lookupTitle($item["context_obj_id"]);
133 
134  $feed_item = new ilFeedItem();
135 
137  ($item["context_obj_type"], $item["title"], $item["content_is_lang_var"],
138  $item["agg_ref_id"], $item["aggregation"]);
139 
140  // path
141  $cont_loc = new ilLocatorGUI();
142  $cont_loc->addContextItems($item["ref_id"], true, $a_ref_id);
143  $cont_loc->setTextOnly(true);
144  $loc = $cont_loc->getHTML();
145  if (trim($loc) != "")
146  {
147  $loc = "[".$loc."]";
148  }
149 
150  $feed_item->setTitle($this->prepareStr($loc)." ".$this->prepareStr($obj_title).
151  ": ".$this->prepareStr($title));
152  $feed_item->setDescription($this->prepareStr(nl2br($item["content"])));
153  $feed_item->setLink(ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
154  "&amp;target=".$item["context_obj_type"]."_".$item["ref_id"]);
155  $feed_item->setAbout($feed_item->getLink()."&amp;il_about_feed=".$item["id"]);
156  $feed_item->setDate($item["creation_date"]);
157 
158  // Enclosure
159  if ($item["content_type"] == NEWS_AUDIO &&
160  $item["mob_id"] > 0 && ilObject::_exists($item["mob_id"]))
161  {
162  $go_on = true;
163  if ($obj_type == "mcst")
164  {
165  include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php");
166 
168  {
169  $go_on = false;
170  }
171  }
172 
173  if ($go_on)
174  {
175  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
176  $url = ilObjMediaObject::_lookupItemPath($item["mob_id"], true, true, $mob["purpose"]);
177  $file = ilObjMediaObject::_lookupItemPath($item["mob_id"], false, false, $mob["purpose"]);
178  if (is_file($file))
179  {
180  $size = filesize($file);
181  }
182  $feed_item->setEnclosureUrl($url);
183  $feed_item->setEnclosureType((isset($mob["format"]))?$mob["format"]:"audio/mpeg");
184  $feed_item->setEnclosureLength($size);
185  }
186  }
187  $this->addItem($feed_item);
188  }
189  }
190 }
191 ?>