1<?php 2 3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */ 4 5include_once("./Services/News/classes/class.ilNewsItem.php"); 6include_once("./Services/Feeds/classes/class.ilFeedItem.php"); 7include_once("./Services/Feeds/classes/class.ilFeedWriter.php"); 8 9/** @defgroup ServicesFeeds Services/Feeds 10 */ 11 12/** 13* Feed writer for personal user feeds. 14* 15* @author Alex Killing <alex.killing@gmx.de> 16* @version $Id$ 17* @ingroup ServicesFeeds 18*/ 19class ilUserFeedWriter extends ilFeedWriter 20{ 21 /** 22 * @var ilSetting 23 */ 24 protected $settings; 25 26 /** 27 * @var ilLanguage 28 */ 29 protected $lng; 30 31 32 public function __construct($a_user_id, $a_hash, $privFeed = false) 33 { 34 global $DIC; 35 36 $this->settings = $DIC->settings(); 37 $this->lng = $DIC->language(); 38 $ilSetting = $DIC->settings(); 39 $lng = $DIC->language(); 40 41 parent::__construct(); 42 43 //$lng->loadLanguageModule("news"); 44 45 if ($a_user_id == "" || $a_hash == "") { 46 return; 47 } 48 49 $news_set = new ilSetting("news"); 50 if (!$news_set->get("enable_rss_for_internal")) { 51 return; 52 } 53 54 include_once "Services/User/classes/class.ilObjUser.php"; 55 $hash = ilObjUser::_lookupFeedHash($a_user_id); 56 57 include_once("./Services/News/classes/class.ilNewsItem.php"); 58 $rss_period = ilNewsItem::_lookupRSSPeriod(); 59 60 if ($a_hash == $hash) { 61 if ($privFeed) { 62 //ilNewsItem::setPrivateFeedId($a_user_id); 63 $items = ilNewsItem::_getNewsItemsOfUser($a_user_id, false, true, $rss_period); 64 } else { 65 $items = ilNewsItem::_getNewsItemsOfUser($a_user_id, true, true, $rss_period); 66 } 67 68 if ($ilSetting->get('short_inst_name') != "") { 69 $this->setChannelTitle($ilSetting->get('short_inst_name')); 70 } else { 71 $this->setChannelTitle("ILIAS"); 72 } 73 74 $this->setChannelAbout(ILIAS_HTTP_PATH); 75 $this->setChannelLink(ILIAS_HTTP_PATH); 76 //$this->setChannelDescription("ILIAS Channel Description"); 77 $i = 0; 78 foreach ($items as $item) { 79 $obj_id = ilObject::_lookupObjId($item["ref_id"]); 80 $obj_type = ilObject::_lookupType($obj_id); 81 $obj_title = ilObject::_lookupTitle($obj_id); 82 83 // not nice, to do: general solution 84 if ($obj_type == "mcst") { 85 include_once("./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php"); 86 if (!ilObjMediaCastAccess::_lookupOnline($obj_id)) { 87 continue; 88 } 89 } 90 91 $i++; 92 $feed_item = new ilFeedItem(); 93 $title = ilNewsItem::determineNewsTitle( 94 $item["context_obj_type"], 95 $item["title"], 96 $item["content_is_lang_var"], 97 $item["agg_ref_id"], 98 $item["aggregation"] 99 ); 100 101 // path 102 $loc = $this->getContextPath($item["ref_id"]); 103 104 // title 105 if ($news_set->get("rss_title_format") == "news_obj") { 106 $feed_item->setTitle($this->prepareStr(str_replace("<br />", " ", $title)) . 107 " (" . $this->prepareStr($loc) . " " . $this->prepareStr($obj_title) . 108 ")"); 109 } else { 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 )); 118 $feed_item->setDescription($content); 119 120 // lm page hack, not nice 121 if (in_array($item["context_obj_type"], array("lm")) && $item["context_sub_obj_type"] == "pg" 122 && $item["context_sub_obj_id"] > 0) { 123 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . 124 "&target=pg_" . $item["context_sub_obj_id"] . "_" . $item["ref_id"]); 125 } elseif ($item["context_obj_type"] == "wiki" && $item["context_sub_obj_type"] == "wpg" 126 && $item["context_sub_obj_id"] > 0) { 127 include_once("./Modules/Wiki/classes/class.ilWikiPage.php"); 128 $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]); 129 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . 130 "&target=" . $item["context_obj_type"] . "_" . $item["ref_id"] . "_" . urlencode($wptitle)); // #14629 131 } elseif (in_array($item["context_obj_type"], array("frm")) && $item["context_sub_obj_type"] == "pos" 132 && $item["context_sub_obj_id"] > 0) { 133 // frm hack, not nice 134 include_once("./Modules/Forum/classes/class.ilObjForumAccess.php"); 135 $thread_id = ilObjForumAccess::_getThreadForPosting($item["context_sub_obj_id"]); 136 if ($thread_id > 0) { 137 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . 138 "&target=" . $item["context_obj_type"] . "_" . $item["ref_id"] . "_" . $thread_id . "_" . $item["context_sub_obj_id"]); 139 } else { 140 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . 141 "&target=" . $item["context_obj_type"] . "_" . $item["ref_id"]); 142 } 143 } else { 144 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . 145 "&target=" . $item["context_obj_type"] . "_" . $item["ref_id"]); 146 } 147 $feed_item->setAbout($feed_item->getLink() . "&il_about_feed=" . $item["id"]); 148 $feed_item->setDate($item["creation_date"]); 149 $this->addItem($feed_item); 150 } 151 } 152 } 153} 154