ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilNewsForContextBlockGUI.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
5include_once("Services/Block/classes/class.ilBlockGUI.php");
6
19{
20 static $block_type = "news";
21 static $st_data;
22
26 function __construct()
27 {
28 global $ilCtrl, $lng, $ilUser, $ilHelp;
29
30 parent::__construct();
31
32 $lng->loadLanguageModule("news");
33 $ilHelp->addHelpSection("news_block");
34
35 include_once("./Services/News/classes/class.ilNewsItem.php");
36 $this->setBlockId($ilCtrl->getContextObjId());
37 $this->setLimit(5);
39 $this->setEnableNumInfo(true);
40
41 $this->dynamic = false;
42 include_once("./Services/News/classes/class.ilNewsCache.php");
43 $this->acache = new ilNewsCache();
44 $cres = unserialize($this->acache->getEntry($ilUser->getId().":".$_GET["ref_id"]));
45 $this->cache_hit = false;
46
47 if ($this->acache->getLastAccessStatus() == "hit" && is_array($cres))
48 {
49 self::$st_data = ilNewsItem::prepareNewsDataFromCache($cres);
50 $this->cache_hit = true;
51 }
52 if ($this->getDynamic() && !$this->cache_hit)
53 {
54 $this->dynamic = true;
55 $data = array();
56 }
57 else if ($this->getCurrentDetailLevel() > 0)
58 {
59 if (!empty(self::$st_data))
60 {
62 }
63 else
64 {
65 $data = $this->getNewsData();
66 self::$st_data = $data;
67 }
68 }
69 else
70 {
71 $data = array();
72 }
73
74 $this->setTitle($lng->txt("news_internal_news"));
75 $this->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
76 $this->setData($data);
77 $this->allow_moving = false;
78 $this->handleView();
79 }
80
84 function getNewsData()
85 {
86 global $ilCtrl, $ilUser;
87
88 include_once("./Services/News/classes/class.ilNewsCache.php");
89 $this->acache = new ilNewsCache();
90/* $cres = $this->acache->getEntry($ilUser->getId().":".$_GET["ref_id"]);
91 if ($this->acache->getLastAccessStatus() == "hit" && false)
92 {
93 $news_data = unserialize($cres);
94 }
95 else
96 {*/
97 $news_item = new ilNewsItem();
98 $news_item->setContextObjId($ilCtrl->getContextObjId());
99 $news_item->setContextObjType($ilCtrl->getContextObjType());
100
101 // workaround, better: reduce constructor and introduce
102 //$prevent_aggregation = $this->getProperty("prevent_aggregation");
103 $prevent_aggregation = true;
104 if ($ilCtrl->getContextObjType() != "frm")
105 {
106 $forum_grouping = true;
107 }
108 else
109 {
110 $forum_grouping = false;
111 }
112
113
114 $news_data = $news_item->getNewsForRefId($_GET["ref_id"], false, false, 0,
115 $prevent_aggregation, $forum_grouping);
116
117 $this->acache->storeEntry($ilUser->getId().":".$_GET["ref_id"],
118 serialize($news_data));
119
120// }
121//var_dump($news_data);
122 return $news_data;
123 }
124
130 static function getBlockType()
131 {
132 return self::$block_type;
133 }
134
140 static function isRepositoryObject()
141 {
142 return false;
143 }
144
148 static function getScreenMode()
149 {
150 global $ilCtrl;
151
152 if ($ilCtrl->getCmdClass() == "ilnewsitemgui")
153 {
154 return IL_SCREEN_FULL;
155 }
156
157 switch($ilCtrl->getCmd())
158 {
159 case "showNews":
160 case "showFeedUrl":
161 return IL_SCREEN_CENTER;
162 break;
163
164 case "editSettings":
165 case "saveSettings":
166 return IL_SCREEN_FULL;
167 break;
168
169 default:
170 return IL_SCREEN_SIDE;
171 break;
172 }
173 }
174
178 function executeCommand()
179 {
180 global $ilCtrl;
181
182 $next_class = $ilCtrl->getNextClass();
183 $cmd = $ilCtrl->getCmd("getHTML");
184
185 switch ($next_class)
186 {
187 case "ilnewsitemgui":
188 include_once("./Services/News/classes/class.ilNewsItemGUI.php");
189 $news_item_gui = new ilNewsItemGUI();
190 $news_item_gui->setEnableEdit($this->getEnableEdit());
191 $html = $ilCtrl->forwardCommand($news_item_gui);
192 return $html;
193
194 default:
195 return $this->$cmd();
196 }
197 }
198
204 public function setEnableEdit($a_enable_edit = 0)
205 {
206 $this->enable_edit = $a_enable_edit;
207 }
208
214 public function getEnableEdit()
215 {
216 return $this->enable_edit;
217 }
218
223 {
224 if ($this->dynamic)
225 {
226 $this->setDataSection($this->getDynamicReload());
227 }
228 else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
229 {
230 parent::fillDataSection();
231 }
232 else
233 {
234 $this->setDataSection($this->getOverview());
235 }
236 }
237
241 function getHTML()
242 {
243 global $ilCtrl, $lng, $ilUser;
244
245 $news_set = new ilSetting("news");
246 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
247
248 $hide_block = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_block",
249 0, $this->block_id);
250 if ($hide_block)
251 {
252 $this->setFooterInfo($lng->txt("news_hidden_news_block"));
253 }
254
255 if ($this->getProperty("title") != "")
256 {
257 $this->setTitle($this->getProperty("title"));
258 }
259
260 $public_feed = ilBlockSetting::_lookup($this->getBlockType(), "public_feed",
261 0, $this->block_id);
262 if ($public_feed)
263 {
264 if ($enable_internal_rss)
265 {
266 include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
267 $this->addBlockCommand(
268 ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&".
269 "ref_id=".$_GET["ref_id"],
270 $lng->txt("news_feed_url"), "", "", true, false, ilRSSButtonGUI::get(ilRSSButtonGUI::ICON_RSS));
271
272 }
273 }
274
275/* Subscription Concept is abandonded for now (Alex)
276 // subscribe/unsibscribe link
277 include_once("./Services/News/classes/class.ilNewsSubscription.php");
278 if (ilNewsSubscription::_hasSubscribed($_GET["ref_id"], $ilUser->getId()))
279 {
280 $this->addBlockCommand(
281 $ilCtrl->getLinkTarget($this, "unsubscribeNews"),
282 $lng->txt("news_unsubscribe"));
283 }
284 else
285 {
286 $this->addBlockCommand(
287 $ilCtrl->getLinkTarget($this, "subscribeNews"),
288 $lng->txt("news_subscribe"));
289 }
290*/
291
292 // add edit commands
293 if ($this->getEnableEdit())
294 {
295 $this->addBlockCommand(
296 $ilCtrl->getLinkTargetByClass("ilnewsitemgui", "editNews"),
297 $lng->txt("edit"));
298
299 $ilCtrl->setParameter($this, "add_mode", "block");
300 $this->addBlockCommand(
301 $ilCtrl->getLinkTargetByClass("ilnewsitemgui", "createNewsItem"),
302 $lng->txt("add"));
303 $ilCtrl->setParameter($this, "add_mode", "");
304 }
305
306 if ($this->getProperty("settings") == true)
307 {
308 $this->addBlockCommand(
309 $ilCtrl->getLinkTarget($this, "editSettings"),
310 $lng->txt("settings"));
311 }
312
313 // do not display hidden repository news blocks for users
314 // who do not have write permission
315 if (!$this->getEnableEdit() && $this->getRepositoryMode() &&
316 ilBlockSetting::_lookup($this->getBlockType(), "hide_news_block",
317 0, $this->block_id))
318 {
319 return "";
320 }
321
322 // do not display empty news blocks for users
323 // who do not have write permission
324 if (count($this->getData()) == 0 && !$this->getEnableEdit() &&
325 $this->getRepositoryMode() && !$this->dynamic
326 && (!$news_set->get("enable_rss_for_internal") ||
327 !ilBlockSetting::_lookup($this->getBlockType(), "public_feed",
328 0, $this->block_id)))
329 {
330 return "";
331 }
332
333 $en = "";
334 if ($ilUser->getPref("il_feed_js") == "n")
335 {
336// $en = getJSEnabler();
337 }
338
339 return parent::getHTML().$en;
340 }
341
345 function handleView()
346 {
347 global $ilUser;
348
349 include_once("Services/Block/classes/class.ilBlockSetting.php");
350 $this->view = ilBlockSetting::_lookup($this->getBlockType(), "view",
351 $ilUser->getId(), $this->block_id);
352
353 // check whether notices and messages exist
354 $got_notices = $got_messages = false;
355 foreach($this->data as $row)
356 {
357 if ($row["priority"] == 0) $got_notices = true;
358 if ($row["priority"] == 1) $got_messages = true;
359 }
360 $this->show_view_selection = false;
361
362 if ($got_notices && $got_messages)
363 {
364 $this->show_view_selection = true;
365 }
366 else if ($got_notices)
367 {
368 $this->view = "";
369 }
370
371 // remove notifications if hidden
372/*
373 if (($this->view == "hide_notifications") && $this->show_view_selection)
374 {
375 $rset = array();
376 foreach($this->data as $k => $row)
377 {
378 if ($row["priority"] == 1)
379 {
380 $rset[$k] = $row;
381 }
382 }
383 $this->data = $rset;
384 }
385*/
386 }
387
391 function fillRow($news)
392 {
393 global $ilUser, $ilCtrl, $lng;
394
395 if ($this->getCurrentDetailLevel() > 2)
396 {
397 $this->tpl->setCurrentBlock("long");
398 //$this->tpl->setVariable("VAL_CONTENT", $news["content"]);
399 $this->tpl->setVariable("VAL_CREATION_DATE",
400 ilDatePresentation::formatDate(new ilDateTime($news["creation_date"],IL_CAL_DATETIME)));
401 $this->tpl->parseCurrentBlock();
402 }
403
404 // notification
405 if ($news["priority"] == 0)
406 {
407/*
408 $this->tpl->setCurrentBlock("notification");
409 $this->tpl->setVariable("CHAR_NOT", $lng->txt("news_first_letter_of_word_notification"));
410 $this->tpl->parseCurrentBlock();
411*/
412 }
413
414
415 // title image type
416 if ($news["ref_id"] > 0)
417 {
418 if ($news["agg_ref_id"] > 0)
419 {
420 $obj_id = ilObject::_lookupObjId($news["agg_ref_id"]);
421 $type = ilObject::_lookupType($obj_id);
422 $context_ref = $news["agg_ref_id"];
423 }
424 else
425 {
426 $obj_id = $news["context_obj_id"];
427 $type = $news["context_obj_type"];
428 $context_ref = $news["ref_id"];
429 }
430
431 $lang_type = in_array($type, array("sahs", "lm", "htlm"))
432 ? "lres"
433 : "obj_".$type;
434
435 $this->tpl->setCurrentBlock("news_context");
436 $this->tpl->setVariable("TYPE", $lng->txt($lang_type));
437 $this->tpl->setVariable("IMG_TYPE",
438 ilObject::_getIcon($obj_id, "tiny", $type));
439 $this->tpl->setVariable("TITLE",
441 if ($news["user_read"] > 0)
442 {
443 $this->tpl->setVariable("TITLE_CLASS", 'class="light"');
444 }
445
446 $this->tpl->parseCurrentBlock();
447 $ilCtrl->setParameter($this, "news_context", $context_ref);
448 }
449 else
450 {
451 $ilCtrl->setParameter($this, "news_context", "");
452 }
453
454 // title
455 $this->tpl->setVariable("VAL_TITLE",
457 ($news["context_obj_type"], $news["title"], $news["content_is_lang_var"],
458 $news["agg_ref_id"], $news["aggregation"])));
459
460
461 if ($news["user_read"] > 0)
462 {
463 $this->tpl->setVariable("A_CLASS", 'class="light"');
464 }
465
466 $ilCtrl->setParameter($this, "news_id", $news["id"]);
467 $this->tpl->setVariable("HREF_SHOW",
468 $ilCtrl->getLinkTarget($this, "showNews"));
469 $ilCtrl->clearParameters($this);
470 }
471
475 function getOverview()
476 {
477 global $ilUser, $lng, $ilCtrl;
478
479 return '<div class="small">'.((int) count($this->getData()))." ".$lng->txt("news_news_items")."</div>";
480 }
481
485 function showNews()
486 {
487 global $lng, $ilCtrl, $ilUser, $ilAccess;
488
489 // workaround for dynamic mode (if cache is disabled, showNews has no data)
490 if (empty(self::$st_data))
491 {
492 $this->setData($this->getNewsData());
493 }
494
495 $news_set = new ilSetting("news");
496 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
497
498 include_once("./Services/News/classes/class.ilNewsItem.php");
499 $news = new ilNewsItem((int) $_GET["news_id"]);
500
501 $tpl = new ilTemplate("tpl.show_news.html", true, true, "Services/News");
502
503 // get current item in data set
504 $previous = $next = "";
505 reset($this->data);
506 $c = current($this->data);
507 $curr_cnt = 1;
508
509 while($c["id"] > 0 &&
510 $c["id"] != $_GET["news_id"])
511 {
512 $previous = $c;
513 $c = next($this->data);
514 $curr_cnt++;
515 }
516
517 if (!is_array($c) && is_object($news) && $news->getId() > 0
518 && ilNewsItem::_lookupContextObjId($news->getId()) != $ilCtrl->getContextObjId())
519 {
520 throw new ilException("News ID does not match object context.");
521 }
522
523
524 // collect news items to show
525 $news_list = array();
526 if (is_array($c["aggregation"])) // we have an aggregation
527 {
528 $news_list[] = array("ref_id" => $c["agg_ref_id"],
529 "agg_ref_id" => $c["agg_ref_id"],
530 "aggregation" => $c["aggregation"],
531 "user_id" => "",
532 "content_type" => "text",
533 "mob_id" => 0,
534 "visibility" => "",
535 "content" => "",
536 "content_long" => "",
537 "update_date" => $news->getUpdateDate(),
538 "creation_date" => "",
539 "content_is_lang_var" => false,
540 "loc_context" => $_GET["news_context"],
541 "context_obj_type" => $news->getContextObjType(),
542 "title" => "");
543
544 foreach($c["aggregation"] as $c_item)
545 {
546 ilNewsItem::_setRead($ilUser->getId(), $c_item["id"]);
547 $c_item["loc_context"] = $c_item["ref_id"];
548 $c_item["loc_stop"] = $_GET["news_context"];
549 $news_list[] = $c_item;
550 }
551 }
552 else // no aggregation, simple news item
553 {
554 $news_list[] = array(
555 "id" => $news->getId(),
556 "ref_id" => $_GET["news_context"],
557 "user_id" => $news->getUserId(),
558 "content_type" => $news->getContentType(),
559 "mob_id" => $news->getMobId(),
560 "visibility" => $news->getVisibility(),
561 "priority" => $news->getPriority(),
562 "content" => $news->getContent(),
563 "content_long" => $news->getContentLong(),
564 "update_date" => $news->getUpdateDate(),
565 "creation_date" => $news->getCreationDate(),
566 "context_sub_obj_type" => $news->getContextSubObjType(),
567 "context_obj_type" => $news->getContextObjType(),
568 "context_sub_obj_id" => $news->getContextSubObjId(),
569 "content_is_lang_var" => $news->getContentIsLangVar(),
570 "content_text_is_lang_var" => $news->getContentTextIsLangVar(),
571 "loc_context" => $_GET["news_context"],
572 "title" => $news->getTitle());
573 ilNewsItem::_setRead($ilUser->getId(), $_GET["news_id"]);
574 }
575
576 $row_css = "";
577 $cache_deleted = false;
578 foreach ($news_list as $item)
579 {
580 $row_css = ($row_css != "tblrow1")
581 ? "tblrow1"
582 : "tblrow2";
583
584 if ($item["ref_id"] > 0 && !$ilAccess->checkAccess("read", "", $item["ref_id"]))
585 {
586 $tpl->setCurrentBlock("content");
587 $tpl->setVariable("VAL_CONTENT", $lng->txt("news_sorry_not_accessible_anymore"));
588 $tpl->parseCurrentBlock();
589 $tpl->setCurrentBlock("item");
590 $tpl->setVariable("ITEM_ROW_CSS", $row_css);
591 $tpl->parseCurrentBlock();
592 if (!$cache_deleted)
593 {
594 $this->acache->deleteEntry($ilUser->getId() . ":" . $_GET["ref_id"]);
595 $cache_deleted = true;
596 }
597 continue;
598 }
599
600 // user
601 if ($item["user_id"] > 0 && ilObject::_exists($item["user_id"]))
602 {
603 // get login
604 if (ilObjUser::_exists($item["user_id"]))
605 {
606 $user = new ilObjUser($item["user_id"]);
607 $displayname = $user->getLogin();
608 } else
609 {
610 // this should actually not happen, since news entries
611 // should be deleted when the user is going to be removed
612 $displayname = "&lt;". strtolower($lng->txt("deleted")) ."&gt;";
613 }
614
615 $tpl->setCurrentBlock("user_info");
616 $tpl->setVariable("VAL_AUTHOR", $displayname);
617 $tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
618 $tpl->parseCurrentBlock();
619 }
620
621 // media player
622 if ($item["content_type"] == NEWS_AUDIO &&
623 $item["mob_id"] > 0 && ilObject::_exists($item["mob_id"]))
624 {
625 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
626 include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
627 $mob = new ilObjMediaObject($item["mob_id"]);
628 $med = $mob->getMediaItem("Standard");
629 $mpl = new ilMediaPlayerGUI("news_pl_".$item["mob_id"]);
630 if (strcasecmp("Reference", $med->getLocationType()) == 0)
631 $mpl->setFile($med->getLocation());
632 else
633 $mpl->setFile(ilObjMediaObject::_getURL($mob->getId())."/".$med->getLocation());
634 $mpl->setDisplayHeight($med->getHeight());
635 $tpl->setCurrentBlock("player");
636 $tpl->setVariable("PLAYER",
637 $mpl->getMp3PlayerHtml());
638 $tpl->parseCurrentBlock();
639 }
640
641 // access
642 if ($enable_internal_rss && $item["visibility"] != "")
643 {
644 $obj_id = ilObject::_lookupObjId($item["ref_id"]);
645 $tpl->setCurrentBlock("access");
646 $tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
647 if ($item["visibility"] == NEWS_PUBLIC ||
648 ($item["priority"] == 0 &&
649 ilBlockSetting::_lookup("news", "public_notifications",
650 0, $obj_id)))
651 {
652 $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
653 }
654 else
655 {
656 $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
657 }
658 $tpl->parseCurrentBlock();
659 }
660
661 // content
662 include_once("./Services/News/classes/class.ilNewsRendererFactory.php");
663 $renderer = ilNewsRendererFactory::getRenderer($item["context_obj_type"]);
664 if (trim($item["content"]) != "") // content
665 {
666 $it = new ilNewsItem($item["id"]);
667 $renderer->setNewsItem($it, $item["ref_id"]);
668 $tpl->setCurrentBlock("content");
669 $tpl->setVariable("VAL_CONTENT", $renderer->getDetailContent());
670 $tpl->parseCurrentBlock();
671 }
672 if (trim($item["content_long"]) != "") // long content
673 {
674 $tpl->setCurrentBlock("long");
675 $tpl->setVariable("VAL_LONG_CONTENT", $this->makeClickable($item["content_long"]));
676 $tpl->parseCurrentBlock();
677 }
678 if ($item["update_date"] != $item["creation_date"]) // update date
679 {
680 $tpl->setCurrentBlock("ni_update");
681 $tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
682 $tpl->setVariable("VAL_LAST_UPDATE",
684 $tpl->parseCurrentBlock();
685 }
686
687 // creation date
688 if ($item["creation_date"] != "")
689 {
690 $tpl->setCurrentBlock("ni_update");
691 $tpl->setVariable("VAL_CREATION_DATE",
692 ilDatePresentation::formatDate(new ilDateTime($item["creation_date"],IL_CAL_DATETIME)));
693 $tpl->setVariable("TXT_CREATED", $lng->txt("created"));
694 $tpl->parseCurrentBlock();
695 }
696
697
698 // context / title
699 if ($_GET["news_context"] > 0)
700 {
701 //$obj_id = ilObject::_lookupObjId($_GET["news_context"]);
702 $obj_id = ilObject::_lookupObjId($item["ref_id"]);
703 $obj_type = ilObject::_lookupType($obj_id);
704 $obj_title = ilObject::_lookupTitle($obj_id);
705
706 // file hack, not nice
707 if ($obj_type == "file")
708 {
709 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $item["ref_id"]);
710 $url = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "sendfile");
711 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
712
713 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
714 $button = ilLinkButton::getInstance();
715 $button->setUrl($url);
716 $button->setCaption("download");
717
718 $tpl->setCurrentBlock("download");
719 $tpl->setVariable("BUTTON_DOWNLOAD", $button->render());
720 $tpl->parseCurrentBlock();
721 }
722
723 // forum hack, not nice
724 $add = "";
725 if ($obj_type == "frm" && $item["context_sub_obj_type"] == "pos"
726 && $item["context_sub_obj_id"] > 0)
727 {
728 include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
729 $pos = $item["context_sub_obj_id"];
730 $thread = ilObjForumAccess::_getThreadForPosting($pos);
731 if ($thread > 0)
732 {
733 $add = "_".$thread."_".$pos;
734 }
735 }
736
737 // wiki hack, not nice
738 if ($obj_type == "wiki" && $item["context_sub_obj_type"] == "wpg"
739 && $item["context_sub_obj_id"] > 0)
740 {
741 include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
742 $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]);
743 if ($wptitle != "")
744 {
745 $add = "_".ilWikiUtil::makeUrlTitle($wptitle);
746 }
747 }
748
749 $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
750 $obj_type."_".$item["ref_id"].$add;
751
752 // lm page hack, not nice
753 if (in_array($obj_type, array("lm")) && $item["context_sub_obj_type"] == "pg"
754 && $item["context_sub_obj_id"] > 0)
755 {
756 $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
757 "pg_".$item["context_sub_obj_id"]."_".$item["ref_id"];
758 }
759
760 // blog posting hack, not nice
761 if ($obj_type == "blog" && $item["context_sub_obj_type"] == "blp"
762 && $item["context_sub_obj_id"] > 0)
763 {
764 $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
765 "blog_".$item["ref_id"]."_".$item["context_sub_obj_id"];
766 }
767
768 $context_opened = false;
769 if ($item["loc_context"] != null && $item["loc_context"] != $item["loc_stop"])
770 {
771
772 $tpl->setCurrentBlock("context");
773 $context_opened = true;
774 $cont_loc = new ilLocatorGUI();
775 $cont_loc->addContextItems($item["loc_context"], true, $item["loc_stop"]);
776 $tpl->setVariable("CONTEXT_LOCATOR", $cont_loc->getHTML());
777 }
778
779//var_dump($item);
780 if ($item["no_context_title"] !== true)
781 {
782 if (!$context_opened)
783 {
784 $tpl->setCurrentBlock("context");
785 }
786 $tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
787 $tpl->setVariable("CONTEXT_TITLE", $obj_title);
788 $tpl->setVariable("IMG_CONTEXT_TITLE", ilObject::_getIcon($obj_id, "big", $obj_type));
789 }
790 if ($context_opened)
791 {
792 $tpl->parseCurrentBlock();
793 }
794
795 $tpl->setVariable("HREF_TITLE", $url_target);
796 }
797
798 // title
799 $tpl->setVariable("VAL_TITLE",
800 ilNewsItem::determineNewsTitle($item["context_obj_type"],
801 $item["title"], $item["content_is_lang_var"], $item["agg_ref_id"],
802 $item["aggregation"]));
803
804
805 $tpl->setCurrentBlock("item");
806 $tpl->setVariable("ITEM_ROW_CSS", $row_css);
807 $tpl->parseCurrentBlock();
808 }
809
810 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
811 $content_block = new ilPDContentBlockGUI();
812 $content_block->setContent($tpl->get());
813 if ($this->getProperty("title") != "")
814 {
815 $content_block->setTitle($this->getProperty("title"));
816 }
817 else
818 {
819 $content_block->setTitle($lng->txt("news_internal_news"));
820 }
821 $this->addCloseCommand($content_block);
822
823 // previous
824 if ($previous != "")
825 {
826 if ($previous["ref_id"] > 0)
827 {
828 $ilCtrl->setParameter($this, "news_context", $previous["ref_id"]);
829 }
830 $ilCtrl->setParameter($this, "news_id", $previous["id"]);
831 $content_block->addFooterLink($lng->txt("previous"),
832 $ilCtrl->getLinkTarget($this, "showNews"), "", "", true);
833 $ilCtrl->setParameter($this, "news_context", "");
834 }
835
836 // next
837 if ($c = next($this->data))
838 {
839 if ($c["ref_id"] > 0)
840 {
841 $ilCtrl->setParameter($this, "news_context", $c["ref_id"]);
842 }
843 $ilCtrl->setParameter($this, "news_id", $c["id"]);
844 $content_block->addFooterLink($lng->txt("next"),
845 $ilCtrl->getLinkTarget($this, "showNews"), "", "", true);
846 }
847 $ilCtrl->setParameter($this, "news_context", "");
848 $ilCtrl->setParameter($this, "news_id", "");
849 $content_block->setCurrentItemNumber($curr_cnt);
850 $content_block->setEnableNumInfo(true);
851 $content_block->setData($this->getData());
852
853 return $content_block->getHTML();
854 }
855
862 function makeClickable($a_str)
863 {
864 // this fixes bug 8744. We assume that strings that contain < and >
865 // already contain html, we do not handle these
866 if (is_int(strpos($a_str, ">")) && is_int(strpos($a_str, "<")))
867 {
868 return $a_str;
869 }
870
871 return ilUtil::makeClickable($a_str);
872 }
873
874
879 {
880 global $ilUser, $ilCtrl;
881
882 include_once("./Services/News/classes/class.ilNewsSubscription.php");
884 $ilCtrl->returnToParent($this);
885 }
886
890 function subscribeNews()
891 {
892 global $ilUser, $ilCtrl;
893
894 include_once("./Services/News/classes/class.ilNewsSubscription.php");
895 ilNewsSubscription::_subscribe($_GET["ref_id"], $ilUser->getId());
896 $ilCtrl->returnToParent($this);
897 }
898
902 function fillFooter()
903 {
904 global $ilCtrl, $lng, $ilUser;
905
906 parent::fillFooter();
907
908 if ($this->show_view_selection)
909 {
910 $this->showViewFooter();
911 }
912 }
913
917 function showViewFooter()
918 {
919 global $ilUser, $lng, $ilCtrl;
920
921 return; // notifications always shown
922
923 $this->clearFooterLinks();
924 $this->addFooterLink("[".$lng->txt("news_first_letter_of_word_notification")."] ".
925 $lng->txt("news_notifications").": ", "", "", "", false, true);
926 if ($this->view == "hide_notifications")
927 {
928 $this->addFooterLink($lng->txt("show"),
929 $ilCtrl->getLinkTarget($this,
930 "showNotifications"),
931 $ilCtrl->getLinkTarget($this,
932 "showNotifications", "", true),
933 "block_".$this->getBlockType()."_".$this->block_id
934 );
935 $this->addFooterLink($lng->txt("hide"));
936 }
937 else
938 {
939 $this->addFooterLink($lng->txt("show"));
940 $this->addFooterLink($lng->txt("hide"),
941 $ilCtrl->getLinkTarget($this,
942 "hideNotifications"),
943 $ilCtrl->getLinkTarget($this,
944 "hideNotifications", "", true),
945 "block_".$this->getBlockType()."_".$this->block_id
946 );
947 }
948
949 $this->fillFooterLinks();
950 }
951
953 {
954 global $ilCtrl, $ilUser;
955
956 include_once("Services/Block/classes/class.ilBlockSetting.php");
957 $view = ilBlockSetting::_write($this->getBlockType(), "view", "",
958 $ilUser->getId(), $this->block_id);
959
960 // reload data
961 $data = $this->getNewsData();
962 $this->setData($data);
963 $this->handleView();
964
965 if ($ilCtrl->isAsynch())
966 {
967 echo $this->getHTML();
968 exit;
969 }
970 else
971 {
972 $ilCtrl->returnToParent($this);
973 }
974 }
975
977 {
978 global $ilCtrl, $ilUser;
979
980 include_once("Services/Block/classes/class.ilBlockSetting.php");
981 $view = ilBlockSetting::_write($this->getBlockType(), "view", "hide_notifications",
982 $ilUser->getId(), $this->block_id);
983
984 // reload data
985 $data = $this->getNewsData();
986 $this->setData($data);
987 $this->handleView();
988
989 if ($ilCtrl->isAsynch())
990 {
991 echo $this->getHTML();
992 exit;
993 }
994 else
995 {
996 $ilCtrl->returnToParent($this);
997 }
998 }
999
1003 function editSettings()
1004 {
1005 $this->initSettingsForm();
1006 return $this->settings_form->getHTML();
1007 }
1008
1013 {
1014 global $ilUser, $lng, $ilCtrl, $ilSetting, $ilTabs;
1015
1016 $ilTabs->clearTargets();
1017
1018 $news_set = new ilSetting("news");
1019 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1020
1021 $public = ilBlockSetting::_lookup($this->getBlockType(), "public_notifications",
1022 0, $this->block_id);
1023 $public_feed = ilBlockSetting::_lookup($this->getBlockType(), "public_feed",
1024 0, $this->block_id);
1025 $hide_block = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_block",
1026 0, $this->block_id);
1027 $hide_news_per_date = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_per_date",
1028 0, $this->block_id);
1029 $hide_news_date = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_date",
1030 0, $this->block_id);
1031
1032 if ($hide_news_date != "")
1033 {
1034 $hide_news_date = explode(" ", $hide_news_date);
1035 }
1036
1037 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1038 $this->settings_form = new ilPropertyFormGUI();
1039 $this->settings_form->setTitle($lng->txt("news_settings"));
1040
1041 // hide news block for learners
1042 if ($this->getProperty("hide_news_block_option"))
1043 {
1044 $ch = new ilCheckboxInputGUI($lng->txt("news_hide_news_block"),
1045 "hide_news_block");
1046 $ch->setInfo($lng->txt("news_hide_news_block_info"));
1047 $ch->setChecked($hide_block);
1048 $this->settings_form->addItem($ch);
1049
1050 $hnpd = new ilCheckboxInputGUI($lng->txt("news_hide_news_per_date"),
1051 "hide_news_per_date");
1052 $hnpd->setInfo($lng->txt("news_hide_news_per_date_info"));
1053 $hnpd->setChecked($hide_news_per_date);
1054
1055 $dt_prop = new ilDateTimeInputGUI($lng->txt("news_hide_news_date"),
1056 "hide_news_date");
1057 $dt_prop->setRequired(true);
1058 if ($hide_news_date != "")
1059 {
1060 $dt_prop->setDate(new ilDateTime($hide_news_date[0].' '.$hide_news_date[1],IL_CAL_DATETIME));
1061 }
1062 #$dt_prop->setDate($hide_news_date[0]);
1063 #$dt_prop->setTime($hide_news_date[1]);
1064 $dt_prop->setShowTime(true);
1065 //$dt_prop->setInfo($lng->txt("news_hide_news_date_info"));
1066 $hnpd->addSubItem($dt_prop);
1067
1068 $this->settings_form->addItem($hnpd);
1069
1070 }
1071
1072 // default visibility
1073 if ($this->getProperty("default_visibility_option") &&
1074 $enable_internal_rss)
1075 {
1076 $default_visibility = ilBlockSetting::_lookup($this->getBlockType(), "default_visibility",
1077 0, $this->block_id);
1078 if ($default_visibility == "")
1079 {
1080 $default_visibility =
1082 }
1083
1084 // Default Visibility
1085 $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
1086 $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
1087 $radio_group->addOption($radio_option);
1088 $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
1089 $radio_group->addOption($radio_option);
1090 $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
1091 $radio_group->setRequired(false);
1092 $radio_group->setValue($default_visibility);
1093 $this->settings_form->addItem($radio_group);
1094 }
1095
1096 // public notifications
1097 if ($this->getProperty("public_notifications_option") &&
1098 $enable_internal_rss)
1099 {
1100 $ch = new ilCheckboxInputGUI($lng->txt("news_notifications_public"),
1101 "notifications_public");
1102 $ch->setInfo($lng->txt("news_notifications_public_info"));
1103 $ch->setChecked($public);
1104 $this->settings_form->addItem($ch);
1105 }
1106
1107 // extra rss feed
1108 if ($enable_internal_rss)
1109 {
1110 $ch = new ilCheckboxInputGUI($lng->txt("news_public_feed"),
1111 "notifications_public_feed");
1112 $ch->setInfo($lng->txt("news_public_feed_info"));
1113 $ch->setChecked($public_feed);
1114 $this->settings_form->addItem($ch);
1115 }
1116
1117
1118 //$this->settings_form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
1119 // "1", $public_feed, $lng->txt("news_public_feed_info"));
1120 //if ($this->getProperty("public_notifications_option"))
1121 //{
1122 // $this->settings_form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
1123 // "1", $public, $lng->txt("news_notifications_public_info"));
1124 //}
1125 $this->settings_form->addCommandButton("saveSettings", $lng->txt("save"));
1126 $this->settings_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
1127 $this->settings_form->setFormAction($ilCtrl->getFormaction($this));
1128 }
1129
1134 {
1135 global $ilCtrl;
1136
1137 $ilCtrl->returnToParent($this);
1138 }
1139
1143 function saveSettings()
1144 {
1145 global $ilCtrl, $ilUser;
1146
1147 $this->initSettingsForm();
1148
1149 if ($this->settings_form->checkInput())
1150 {
1151 $news_set = new ilSetting("news");
1152 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1153
1154 if ($enable_internal_rss)
1155 {
1156 ilBlockSetting::_write($this->getBlockType(), "public_notifications", $_POST["notifications_public"],
1157 0, $this->block_id);
1158 ilBlockSetting::_write($this->getBlockType(), "public_feed", $_POST["notifications_public_feed"],
1159 0, $this->block_id);
1160 ilBlockSetting::_write($this->getBlockType(), "default_visibility", $_POST["default_visibility"],
1161 0, $this->block_id);
1162 }
1163
1164 if ($this->getProperty("hide_news_block_option"))
1165 {
1166 ilBlockSetting::_write($this->getBlockType(), "hide_news_block", $_POST["hide_news_block"],
1167 0, $this->block_id);
1168 ilBlockSetting::_write($this->getBlockType(), "hide_news_per_date", $_POST["hide_news_per_date"],
1169 0, $this->block_id);
1170
1171 // hide date
1172 $hd = $this->settings_form->getItemByPostVar("hide_news_date");
1173 $hide_date = $hd->getDate();
1174 if ($_POST["hide_news_per_date"] && $hide_date != null)
1175 {
1176 ilBlockSetting::_write($this->getBlockType(), "hide_news_date",
1177 $hide_date->get(IL_CAL_DATETIME),
1178 0, $this->block_id);
1179 }
1180 else
1181 {
1182 ilBlockSetting::_write($this->getBlockType(), "hide_news_date",
1183 "",
1184 0, $this->block_id);
1185 }
1186 }
1187
1188 include_once("./Services/News/classes/class.ilNewsCache.php");
1189 $cache = new ilNewsCache();
1190 $cache->deleteEntry($ilUser->getId().":".$_GET["ref_id"]);
1191
1192 $ilCtrl->returnToParent($this);
1193 }
1194 else
1195 {
1196 $this->settings_form->setValuesByPost();
1197 return $this->settings_form->getHtml();
1198 }
1199 }
1200
1204 function showFeedUrl()
1205 {
1206 global $lng, $ilCtrl, $ilUser;
1207
1208 include_once("./Services/News/classes/class.ilNewsItem.php");
1209
1210 $title = ilObject::_lookupTitle($this->block_id);
1211
1212 $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
1213 $tpl->setVariable("TXT_TITLE",
1214 sprintf($lng->txt("news_feed_url_for"), $title));
1215 $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
1216 $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
1217 $tpl->setVariable("VAL_FEED_URL",
1218 ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&user_id=".$ilUser->getId().
1219 "&obj_id=".$this->block_id.
1220 "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
1221 $tpl->setVariable("VAL_FEED_URL_TXT",
1222 ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&<br />user_id=".$ilUser->getId().
1223 "&obj_id=".$this->block_id.
1224 "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
1225
1226 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
1227 $content_block = new ilPDContentBlockGUI();
1228 $content_block->setContent($tpl->get());
1229 $content_block->setTitle($lng->txt("news_internal_news"));
1230 $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
1231 $lng->txt("close"), true);
1232
1233 return $content_block->getHTML();
1234 }
1235
1236 function addCloseCommand($a_content_block)
1237 {
1238 global $lng, $ilCtrl;
1239
1240 $a_content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
1241 $lng->txt("close"), true);
1242 }
1243
1244 function getDynamic()
1245 {
1246 global $ilCtrl, $ilUser;
1247
1248 if ($ilCtrl->getCmd() == "hideNotifications" ||
1249 $ilCtrl->getCmd() == "showNotifications")
1250 {
1251 return false;
1252 }
1253
1254 if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
1255 {
1256 $sess_feed_js = "";
1257 if (isset($_SESSION["il_feed_js"]))
1258 {
1259 $sess_feed_js = $_SESSION["il_feed_js"];
1260 }
1261
1262 if ($sess_feed_js != "n" &&
1263 ($ilUser->getPref("il_feed_js") != "n" || $sess_feed_js == "y"))
1264 {
1265 // do not get feed dynamically, if cache hit is given.
1266// if (!$this->feed->checkCacheHit())
1267// {
1268 return true;
1269// }
1270 }
1271 }
1272
1273 return false;
1274 }
1275
1277 {
1278 global $ilCtrl, $lng;
1279
1280 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
1281 "block_".$this->getBlockType()."_".$this->getBlockId());
1282
1283 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/News");
1284 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("news_loading_news"));
1285 $rel_tpl->setVariable("BLOCK_ID", "block_".$this->getBlockType()."_".$this->getBlockId());
1286 $rel_tpl->setVariable("TARGET",
1287 $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
1288
1289 // no JS
1290 $rel_tpl->setVariable("TXT_NEWS_CLICK_HERE", $lng->txt("news_no_js_click_here"));
1291 $rel_tpl->setVariable("TARGET_NO_JS",
1292 $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "disableJS"));
1293
1294 return $rel_tpl->get();
1295 }
1296
1297 function getJSEnabler()
1298 {
1299 global $ilCtrl, $lng;
1300
1301 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
1302 "block_".$this->getBlockType()."_".$this->getBlockId());
1303//echo "hh";
1304 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/News");
1305 $rel_tpl->setVariable("BLOCK_ID", "block_".$this->getBlockType()."_".$this->getBlockId());
1306 $rel_tpl->setVariable("TARGET",
1307 $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "enableJS", true, "", false));
1308
1309 return $rel_tpl->get();
1310 }
1311
1312
1313 function disableJS()
1314 {
1315 global $ilCtrl, $ilUser;
1316
1317 $_SESSION["il_feed_js"] = "n";
1318 $ilUser->writePref("il_feed_js", "n");
1319$ilCtrl->returnToParent($this);
1320 //$ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1321 }
1322
1323 function enableJS()
1324 {
1325 global $ilUser;
1326//echo "enableJS";
1327 $_SESSION["il_feed_js"] = "y";
1328 $ilUser->writePref("il_feed_js", "y");
1329 echo $this->getHTML();
1330 exit;
1331 }
1332
1333}
1334
1335?>
sprintf('%.4f', $callTime)
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_SCREEN_SIDE
const IL_SCREEN_CENTER
const IL_SCREEN_FULL
const IL_CAL_DATETIME
const NEWS_AUDIO
const NEWS_PUBLIC
This class represents a block method of a block.
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
setLimit($a_limit)
Set Limit.
setFooterInfo($a_footerinfo, $a_hide_and_icon=false)
Set Footer Info.
getCurrentDetailLevel()
Get Current Detail Level.
getBlockId()
Get Block Id.
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
setData($a_data)
Set Data.
getRepositoryMode()
Get RepositoryMode.
fillFooterLinks($a_top=false, $a_numinfo="")
Fill footer links.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
addBlockCommand($a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
addFooterLink($a_text, $a_href="", $a_onclick="", $a_block_id="", $a_top=false, $a_omit_separator=false, $a_checked=false)
Add a footer text/link.
getProperty($a_property)
setTitle($a_title)
Set Title.
setBlockId($a_block_id=0)
Set Block Id.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
clearFooterLinks()
Clear footer links.
getData()
Get Data.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
This class represents a checkbox property in a property form.
static formatDate(ilDateTime $date)
Format a date @access public.
This class represents a date/time property in a property form.
@classDescription Date and time handling
Base class for ILIAS Exception handling.
static getInstance()
Factory.
locator handling class
User interface for media player.
BlockGUI class for block NewsForContext.
showViewFooter()
Show additional footer for show/hide notifications.
static getScreenMode()
Get Screen Mode for current command.
static isRepositoryObject()
Is this a repository object.
subscribeNews()
Subscribe current user from news.
unsubscribeNews()
Unsubscribe current user from news.
setEnableEdit($a_enable_edit=0)
Set EnableEdit.
handleView()
Handles show/hide notification view and removes notifications if hidden.
fillRow($news)
get flat bookmark list for personal desktop
User Interface for NewsItem entities.
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
static _setRead($a_user_id, $a_news_id)
Set item read.
static determineNewsTitle($a_context_obj_type, $a_title, $a_content_is_lang_var, $a_agg_ref_id=0, $a_aggregation="")
Determine title for news item entry.
static prepareNewsDataFromCache($a_cres)
Prepare news data from cache.
static _lookupContextObjId($a_news_id)
Context Object ID.
static getRenderer($a_context_obj_type)
Get renderer.
static _subscribe($a_ref_id, $a_user_id)
Subscribe a user to an object (ref id).
static _unsubscribe($a_ref_id, $a_user_id)
Unsubscribe a user from an object (ref id).
Class ilObjMediaObject.
static _getURL($a_mob_id)
get directory for files of media object (static)
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _lookupType($a_id, $a_reference=false)
lookup object type
BlockGUI class for (centered) Content on Personal Desktop.
This class represents a property form user interface.
static get($a_type, $a_href="")
Get icon html.
This class represents a property in a property form.
This class represents an option in a radio group.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static makeClickable($a_text, $detectGotoLinks=false)
makeClickable In Texten enthaltene URLs und Mail-Adressen klickbar machen
static shortenWords($a_str, $a_len=30, $a_dots=true)
Ensure that the maximum word lenght within a text is not longer than $a_len.
static lookupTitle($a_page_id)
Checks whether a page with given title exists.
$html
Definition: example_001.php:87
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
global $ilSetting
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
$url
Definition: shib_logout.php:72
$ilUser
Definition: imgupload.php:18