ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
23 protected $help;
24
28 protected $settings;
29
33 protected $tabs;
34
35 public static $block_type = "news";
36 public static $st_data;
37
41 public function __construct()
42 {
43 global $DIC;
44
45 $this->ctrl = $DIC->ctrl();
46 $this->lng = $DIC->language();
47 $this->user = $DIC->user();
48 $this->help = $DIC["ilHelp"];
49 $this->access = $DIC->access();
50 $this->settings = $DIC->settings();
51 $this->tabs = $DIC->tabs();
52 $ilCtrl = $DIC->ctrl();
53 $lng = $DIC->language();
54 $ilUser = $DIC->user();
55 $ilHelp = $DIC["ilHelp"];
56
57 parent::__construct();
58
59 $lng->loadLanguageModule("news");
60 $ilHelp->addHelpSection("news_block");
61
62 include_once("./Services/News/classes/class.ilNewsItem.php");
63 $this->setBlockId($ilCtrl->getContextObjId());
64 $this->setLimit(5);
66 $this->setEnableNumInfo(true);
67
68 $this->dynamic = false;
69 include_once("./Services/News/classes/class.ilNewsCache.php");
70 $this->acache = new ilNewsCache();
71 $cres = unserialize($this->acache->getEntry($ilUser->getId() . ":" . $_GET["ref_id"]));
72 $this->cache_hit = false;
73
74 if ($this->acache->getLastAccessStatus() == "hit" && is_array($cres)) {
75 self::$st_data = ilNewsItem::prepareNewsDataFromCache($cres);
76 $this->cache_hit = true;
77 }
78 if ($this->getDynamic() && !$this->cache_hit) {
79 $this->dynamic = true;
80 $data = array();
81 } elseif ($this->getCurrentDetailLevel() > 0) {
82 if (!empty(self::$st_data)) {
84 } else {
85 $data = $this->getNewsData();
86 self::$st_data = $data;
87 }
88 } else {
89 $data = array();
90 }
91
92 $this->setTitle($lng->txt("news_internal_news"));
93 $this->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
94 $this->setData($data);
95 $this->allow_moving = false;
96 $this->handleView();
97 }
98
102 public function getNewsData()
103 {
106
107 include_once("./Services/News/classes/class.ilNewsCache.php");
108 $this->acache = new ilNewsCache();
109 /* $cres = $this->acache->getEntry($ilUser->getId().":".$_GET["ref_id"]);
110 if ($this->acache->getLastAccessStatus() == "hit" && false)
111 {
112 $news_data = unserialize($cres);
113 }
114 else
115 {*/
116 $news_item = new ilNewsItem();
117 $news_item->setContextObjId($ilCtrl->getContextObjId());
118 $news_item->setContextObjType($ilCtrl->getContextObjType());
119
120 // workaround, better: reduce constructor and introduce
121 //$prevent_aggregation = $this->getProperty("prevent_aggregation");
122 $prevent_aggregation = true;
123 if ($ilCtrl->getContextObjType() != "frm") {
124 $forum_grouping = true;
125 } else {
126 $forum_grouping = false;
127 }
128
129
130 $news_data = $news_item->getNewsForRefId(
131 $_GET["ref_id"],
132 false,
133 false,
134 0,
135 $prevent_aggregation,
136 $forum_grouping
137 );
138
139 $this->acache->storeEntry(
140 $ilUser->getId() . ":" . $_GET["ref_id"],
141 serialize($news_data)
142 );
143
144 // }
145 //var_dump($news_data);
146 return $news_data;
147 }
148
154 public static function getBlockType()
155 {
156 return self::$block_type;
157 }
158
164 public static function isRepositoryObject()
165 {
166 return false;
167 }
168
172 public static function getScreenMode()
173 {
174 global $DIC;
175
176 $ilCtrl = $DIC->ctrl();
177
178 if ($ilCtrl->getCmdClass() == "ilnewsitemgui") {
179 return IL_SCREEN_FULL;
180 }
181
182 switch ($ilCtrl->getCmd()) {
183 case "showNews":
184 case "showFeedUrl":
185 return IL_SCREEN_CENTER;
186 break;
187
188 case "editSettings":
189 case "saveSettings":
190 return IL_SCREEN_FULL;
191 break;
192
193 default:
194 return IL_SCREEN_SIDE;
195 break;
196 }
197 }
198
202 public function executeCommand()
203 {
205
206 $next_class = $ilCtrl->getNextClass();
207 $cmd = $ilCtrl->getCmd("getHTML");
208
209 switch ($next_class) {
210 case "ilnewsitemgui":
211 include_once("./Services/News/classes/class.ilNewsItemGUI.php");
212 $news_item_gui = new ilNewsItemGUI();
213 $news_item_gui->setEnableEdit($this->getEnableEdit());
214 $html = $ilCtrl->forwardCommand($news_item_gui);
215 return $html;
216
217 default:
218 return $this->$cmd();
219 }
220 }
221
227 public function setEnableEdit($a_enable_edit = 0)
228 {
229 $this->enable_edit = $a_enable_edit;
230 }
231
237 public function getEnableEdit()
238 {
239 return $this->enable_edit;
240 }
241
245 public function fillDataSection()
246 {
247 if ($this->dynamic) {
248 $this->setDataSection($this->getDynamicReload());
249 } elseif ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0) {
250 parent::fillDataSection();
251 } else {
252 $this->setDataSection($this->getOverview());
253 }
254 }
255
259 public function getHTML()
260 {
264
265 $news_set = new ilSetting("news");
266 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
267
268 $hide_block = ilBlockSetting::_lookup(
269 $this->getBlockType(),
270 "hide_news_block",
271 0,
272 $this->block_id
273 );
274 if ($hide_block) {
275 $this->setFooterInfo($lng->txt("news_hidden_news_block"));
276 }
277
278 if ($this->getProperty("title") != "") {
279 $this->setTitle($this->getProperty("title"));
280 }
281
282 $public_feed = ilBlockSetting::_lookup(
283 $this->getBlockType(),
284 "public_feed",
285 0,
286 $this->block_id
287 );
288 if ($public_feed) {
289 if ($enable_internal_rss) {
290 include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
291 $this->addBlockCommand(
292 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&" .
293 "ref_id=" . $_GET["ref_id"],
294 $lng->txt("news_feed_url"),
295 "",
296 "",
297 true,
298 false,
300 );
301 }
302 }
303
304 /* Subscription Concept is abandonded for now (Alex)
305 // subscribe/unsibscribe link
306 include_once("./Services/News/classes/class.ilNewsSubscription.php");
307 if (ilNewsSubscription::_hasSubscribed($_GET["ref_id"], $ilUser->getId()))
308 {
309 $this->addBlockCommand(
310 $ilCtrl->getLinkTarget($this, "unsubscribeNews"),
311 $lng->txt("news_unsubscribe"));
312 }
313 else
314 {
315 $this->addBlockCommand(
316 $ilCtrl->getLinkTarget($this, "subscribeNews"),
317 $lng->txt("news_subscribe"));
318 }
319 */
320
321 // add edit commands
322 if ($this->getEnableEdit()) {
323 $this->addBlockCommand(
324 $ilCtrl->getLinkTargetByClass("ilnewsitemgui", "editNews"),
325 $lng->txt("edit")
326 );
327
328 $ilCtrl->setParameter($this, "add_mode", "block");
329 $this->addBlockCommand(
330 $ilCtrl->getLinkTargetByClass("ilnewsitemgui", "createNewsItem"),
331 $lng->txt("add")
332 );
333 $ilCtrl->setParameter($this, "add_mode", "");
334 }
335
336 if ($this->getProperty("settings") == true) {
337 $this->addBlockCommand(
338 $ilCtrl->getLinkTarget($this, "editSettings"),
339 $lng->txt("settings")
340 );
341 }
342
343 // do not display hidden repository news blocks for users
344 // who do not have write permission
345 if (!$this->getEnableEdit() && $this->getRepositoryMode() &&
347 $this->getBlockType(),
348 "hide_news_block",
349 0,
350 $this->block_id
351 )) {
352 return "";
353 }
354
355 // do not display empty news blocks for users
356 // who do not have write permission
357 if (count($this->getData()) == 0 && !$this->getEnableEdit() &&
358 $this->getRepositoryMode() && !$this->dynamic
359 && (!$news_set->get("enable_rss_for_internal") ||
361 $this->getBlockType(),
362 "public_feed",
363 0,
364 $this->block_id
365 ))) {
366 return "";
367 }
368
369 $en = "";
370 if ($ilUser->getPref("il_feed_js") == "n") {
371 // $en = getJSEnabler();
372 }
373
374 return parent::getHTML() . $en;
375 }
376
380 public function handleView()
381 {
383
384 include_once("Services/Block/classes/class.ilBlockSetting.php");
385 $this->view = ilBlockSetting::_lookup(
386 $this->getBlockType(),
387 "view",
388 $ilUser->getId(),
389 $this->block_id
390 );
391
392 // check whether notices and messages exist
393 $got_notices = $got_messages = false;
394 foreach ($this->data as $row) {
395 if ($row["priority"] == 0) {
396 $got_notices = true;
397 }
398 if ($row["priority"] == 1) {
399 $got_messages = true;
400 }
401 }
402 $this->show_view_selection = false;
403
404 if ($got_notices && $got_messages) {
405 $this->show_view_selection = true;
406 } elseif ($got_notices) {
407 $this->view = "";
408 }
409
410 // remove notifications if hidden
411/*
412 if (($this->view == "hide_notifications") && $this->show_view_selection)
413 {
414 $rset = array();
415 foreach($this->data as $k => $row)
416 {
417 if ($row["priority"] == 1)
418 {
419 $rset[$k] = $row;
420 }
421 }
422 $this->data = $rset;
423 }
424*/
425 }
426
430 public function fillRow($news)
431 {
434
435 if ($this->getCurrentDetailLevel() > 2) {
436 $this->tpl->setCurrentBlock("long");
437 //$this->tpl->setVariable("VAL_CONTENT", $news["content"]);
438 $this->tpl->setVariable(
439 "VAL_CREATION_DATE",
440 ilDatePresentation::formatDate(new ilDateTime($news["creation_date"], IL_CAL_DATETIME))
441 );
442 $this->tpl->parseCurrentBlock();
443 }
444
445 // title image type
446 if ($news["ref_id"] > 0) {
447 if ($news["agg_ref_id"] > 0) {
448 $obj_id = ilObject::_lookupObjId($news["agg_ref_id"]);
449 $type = ilObject::_lookupType($obj_id);
450 $context_ref = $news["agg_ref_id"];
451 } else {
452 $obj_id = $news["context_obj_id"];
453 $type = $news["context_obj_type"];
454 $context_ref = $news["ref_id"];
455 }
456
457 $lang_type = in_array($type, array("sahs", "lm", "htlm"))
458 ? "lres"
459 : "obj_" . $type;
460
461 $this->tpl->setCurrentBlock("news_context");
462 $this->tpl->setVariable("TYPE", $lng->txt($lang_type));
463 $this->tpl->setVariable(
464 "IMG_TYPE",
465 ilObject::_getIcon($obj_id, "tiny", $type)
466 );
467 $this->tpl->setVariable(
468 "TITLE",
470 );
471 if ($news["user_read"] > 0) {
472 $this->tpl->setVariable("TITLE_CLASS", 'class="light"');
473 }
474
475 $this->tpl->parseCurrentBlock();
476 $ilCtrl->setParameter($this, "news_context", $context_ref);
477 } else {
478 $ilCtrl->setParameter($this, "news_context", "");
479 }
480
481 // title
482 $this->tpl->setVariable(
483 "VAL_TITLE",
485 $news["context_obj_type"],
486 $news["title"],
487 $news["content_is_lang_var"],
488 $news["agg_ref_id"],
489 $news["aggregation"]
490 ))
491 );
492
493
494 if ($news["user_read"] > 0) {
495 $this->tpl->setVariable("A_CLASS", 'class="light"');
496 }
497
498 $ilCtrl->setParameter($this, "news_id", $news["id"]);
499 $this->tpl->setVariable(
500 "HREF_SHOW",
501 $ilCtrl->getLinkTarget($this, "showNews")
502 );
503 $ilCtrl->clearParameters($this);
504 }
505
509 public function getOverview()
510 {
514
515 return '<div class="small">' . ((int) count($this->getData())) . " " . $lng->txt("news_news_items") . "</div>";
516 }
517
521 public function showNews()
522 {
526 $ilAccess = $this->access;
527
528 // workaround for dynamic mode (if cache is disabled, showNews has no data)
529 if (empty(self::$st_data)) {
530 $this->setData($this->getNewsData());
531 }
532
533 $news_set = new ilSetting("news");
534 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
535
536 include_once("./Services/News/classes/class.ilNewsItem.php");
537 $news = new ilNewsItem((int) $_GET["news_id"]);
538
539 $tpl = new ilTemplate("tpl.show_news.html", true, true, "Services/News");
540
541 // get current item in data set
542 $previous = $next = "";
543 reset($this->data);
544 $c = current($this->data);
545 $curr_cnt = 1;
546
547 while ($c["id"] > 0 &&
548 $c["id"] != $_GET["news_id"]) {
549 $previous = $c;
550 $c = next($this->data);
551 $curr_cnt++;
552 }
553
554 if (!is_array($c) && is_object($news) && $news->getId() > 0
555 && ilNewsItem::_lookupContextObjId($news->getId()) != $ilCtrl->getContextObjId()) {
556 throw new ilException("News ID does not match object context.");
557 }
558
559
560 // collect news items to show
561 $news_list = array();
562 if (is_array($c["aggregation"])) { // we have an aggregation
563 $news_list[] = array("ref_id" => $c["agg_ref_id"],
564 "agg_ref_id" => $c["agg_ref_id"],
565 "aggregation" => $c["aggregation"],
566 "user_id" => "",
567 "content_type" => "text",
568 "mob_id" => 0,
569 "visibility" => "",
570 "content" => "",
571 "content_long" => "",
572 "update_date" => $news->getUpdateDate(),
573 "creation_date" => "",
574 "content_is_lang_var" => false,
575 "loc_context" => $_GET["news_context"],
576 "context_obj_type" => $news->getContextObjType(),
577 "title" => "");
578
579 foreach ($c["aggregation"] as $c_item) {
580 ilNewsItem::_setRead($ilUser->getId(), $c_item["id"]);
581 $c_item["loc_context"] = $c_item["ref_id"];
582 $c_item["loc_stop"] = $_GET["news_context"];
583 $news_list[] = $c_item;
584 }
585 } else { // no aggregation, simple news item
586 $news_list[] = array(
587 "id" => $news->getId(),
588 "ref_id" => $_GET["news_context"],
589 "user_id" => $news->getUserId(),
590 "content_type" => $news->getContentType(),
591 "mob_id" => $news->getMobId(),
592 "visibility" => $news->getVisibility(),
593 "priority" => $news->getPriority(),
594 "content" => $news->getContent(),
595 "content_long" => $news->getContentLong(),
596 "update_date" => $news->getUpdateDate(),
597 "creation_date" => $news->getCreationDate(),
598 "context_sub_obj_type" => $news->getContextSubObjType(),
599 "context_obj_type" => $news->getContextObjType(),
600 "context_sub_obj_id" => $news->getContextSubObjId(),
601 "content_is_lang_var" => $news->getContentIsLangVar(),
602 "content_text_is_lang_var" => $news->getContentTextIsLangVar(),
603 "loc_context" => $_GET["news_context"],
604 "title" => $news->getTitle());
605 ilNewsItem::_setRead($ilUser->getId(), $_GET["news_id"]);
606 }
607
608 $row_css = "";
609 $cache_deleted = false;
610 foreach ($news_list as $item) {
611 $row_css = ($row_css != "tblrow1")
612 ? "tblrow1"
613 : "tblrow2";
614
615 if ($item["ref_id"] > 0 && !$ilAccess->checkAccess("read", "", $item["ref_id"])) {
616 $tpl->setCurrentBlock("content");
617 $tpl->setVariable("VAL_CONTENT", $lng->txt("news_sorry_not_accessible_anymore"));
618 $tpl->parseCurrentBlock();
619 $tpl->setCurrentBlock("item");
620 $tpl->setVariable("ITEM_ROW_CSS", $row_css);
621 $tpl->parseCurrentBlock();
622 if (!$cache_deleted) {
623 $this->acache->deleteEntry($ilUser->getId() . ":" . $_GET["ref_id"]);
624 $cache_deleted = true;
625 }
626 continue;
627 }
628
629 // user
630 if ($item["user_id"] > 0 && ilObject::_exists($item["user_id"])) {
631 // get login
632 if (ilObjUser::_exists($item["user_id"])) {
633 $user = new ilObjUser($item["user_id"]);
634 $displayname = $user->getLogin();
635 } else {
636 // this should actually not happen, since news entries
637 // should be deleted when the user is going to be removed
638 $displayname = "&lt;" . strtolower($lng->txt("deleted")) . "&gt;";
639 }
640
641 $tpl->setCurrentBlock("user_info");
642 $tpl->setVariable("VAL_AUTHOR", $displayname);
643 $tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
644 $tpl->parseCurrentBlock();
645 }
646
647 // media player
648 if ($item["content_type"] == NEWS_AUDIO &&
649 $item["mob_id"] > 0 && ilObject::_exists($item["mob_id"])) {
650 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
651 include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
652 $mob = new ilObjMediaObject($item["mob_id"]);
653 $med = $mob->getMediaItem("Standard");
654 $mpl = new ilMediaPlayerGUI("news_pl_" . $item["mob_id"]);
655 if (strcasecmp("Reference", $med->getLocationType()) == 0) {
656 $mpl->setFile($med->getLocation());
657 } else {
658 $mpl->setFile(ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation());
659 }
660 $mpl->setDisplayHeight($med->getHeight());
661 $tpl->setCurrentBlock("player");
662 $tpl->setVariable(
663 "PLAYER",
664 $mpl->getMp3PlayerHtml()
665 );
666 $tpl->parseCurrentBlock();
667 }
668
669 // access
670 if ($enable_internal_rss && $item["visibility"] != "") {
671 $obj_id = ilObject::_lookupObjId($item["ref_id"]);
672 $tpl->setCurrentBlock("access");
673 $tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
674 if ($item["visibility"] == NEWS_PUBLIC ||
675 ($item["priority"] == 0 &&
677 "news",
678 "public_notifications",
679 0,
680 $obj_id
681 ))) {
682 $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
683 } else {
684 $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
685 }
686 $tpl->parseCurrentBlock();
687 }
688
689 // content
690 include_once("./Services/News/classes/class.ilNewsRendererFactory.php");
691 $renderer = ilNewsRendererFactory::getRenderer($item["context_obj_type"]);
692 if (trim($item["content"]) != "") { // content
693 $it = new ilNewsItem($item["id"]);
694 $renderer->setNewsItem($it, $item["ref_id"]);
695 $tpl->setCurrentBlock("content");
696 $tpl->setVariable("VAL_CONTENT", $renderer->getDetailContent());
697 $tpl->parseCurrentBlock();
698 }
699 if ($item["update_date"] != $item["creation_date"]) { // update date
700 $tpl->setCurrentBlock("ni_update");
701 $tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
702 $tpl->setVariable(
703 "VAL_LAST_UPDATE",
705 );
706 $tpl->parseCurrentBlock();
707 }
708
709 // creation date
710 if ($item["creation_date"] != "") {
711 $tpl->setCurrentBlock("ni_update");
712 $tpl->setVariable(
713 "VAL_CREATION_DATE",
714 ilDatePresentation::formatDate(new ilDateTime($item["creation_date"], IL_CAL_DATETIME))
715 );
716 $tpl->setVariable("TXT_CREATED", $lng->txt("created"));
717 $tpl->parseCurrentBlock();
718 }
719
720
721 // context / title
722 if ($_GET["news_context"] > 0) {
723 //$obj_id = ilObject::_lookupObjId($_GET["news_context"]);
724 $obj_id = ilObject::_lookupObjId($item["ref_id"]);
725 $obj_type = ilObject::_lookupType($obj_id);
726 $obj_title = ilObject::_lookupTitle($obj_id);
727
728 // file hack, not nice
729 if ($obj_type == "file") {
730 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $item["ref_id"]);
731 $url = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "sendfile");
732 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
733
734 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
735 $button = ilLinkButton::getInstance();
736 $button->setUrl($url);
737 $button->setCaption("download");
738
739 $tpl->setCurrentBlock("download");
740 $tpl->setVariable("BUTTON_DOWNLOAD", $button->render());
741 $tpl->parseCurrentBlock();
742 }
743
744 // forum hack, not nice
745 $add = "";
746 if ($obj_type == "frm" && $item["context_sub_obj_type"] == "pos"
747 && $item["context_sub_obj_id"] > 0) {
748 include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
749 $pos = $item["context_sub_obj_id"];
751 if ($thread > 0) {
752 $add = "_" . $thread . "_" . $pos;
753 }
754 }
755
756 // wiki hack, not nice
757 if ($obj_type == "wiki" && $item["context_sub_obj_type"] == "wpg"
758 && $item["context_sub_obj_id"] > 0) {
759 include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
760 $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]);
761 if ($wptitle != "") {
762 $add = "_" . ilWikiUtil::makeUrlTitle($wptitle);
763 }
764 }
765
766 $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
767 $obj_type . "_" . $item["ref_id"] . $add;
768
769 // lm page hack, not nice
770 if (in_array($obj_type, array("lm")) && $item["context_sub_obj_type"] == "pg"
771 && $item["context_sub_obj_id"] > 0) {
772 $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
773 "pg_" . $item["context_sub_obj_id"] . "_" . $item["ref_id"];
774 }
775
776 // blog posting hack, not nice
777 if ($obj_type == "blog" && $item["context_sub_obj_type"] == "blp"
778 && $item["context_sub_obj_id"] > 0) {
779 $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
780 "blog_" . $item["ref_id"] . "_" . $item["context_sub_obj_id"];
781 }
782
783 $context_opened = false;
784 if ($item["loc_context"] != null && $item["loc_context"] != $item["loc_stop"]) {
785 $tpl->setCurrentBlock("context");
786 $context_opened = true;
787 $cont_loc = new ilLocatorGUI();
788 $cont_loc->addContextItems($item["loc_context"], true, $item["loc_stop"]);
789 $tpl->setVariable("CONTEXT_LOCATOR", $cont_loc->getHTML());
790 }
791
792 //var_dump($item);
793 if ($item["no_context_title"] !== true) {
794 if (!$context_opened) {
795 $tpl->setCurrentBlock("context");
796 }
797 $tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
798 $tpl->setVariable("CONTEXT_TITLE", $obj_title);
799 $tpl->setVariable("IMG_CONTEXT_TITLE", ilObject::_getIcon($obj_id, "big", $obj_type));
800 }
801 if ($context_opened) {
802 $tpl->parseCurrentBlock();
803 }
804
805 $tpl->setVariable("HREF_TITLE", $url_target);
806 }
807
808 // title
809 $tpl->setVariable(
810 "VAL_TITLE",
812 $item["context_obj_type"],
813 $item["title"],
814 $item["content_is_lang_var"],
815 $item["agg_ref_id"],
816 $item["aggregation"]
817 )
818 );
819
820
821 $tpl->setCurrentBlock("item");
822 $tpl->setVariable("ITEM_ROW_CSS", $row_css);
823 $tpl->parseCurrentBlock();
824 }
825
826 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
827 $content_block = new ilPDContentBlockGUI();
828 $content_block->setContent($tpl->get());
829 if ($this->getProperty("title") != "") {
830 $content_block->setTitle($this->getProperty("title"));
831 } else {
832 $content_block->setTitle($lng->txt("news_internal_news"));
833 }
834 $this->addCloseCommand($content_block);
835
836 // previous
837 if ($previous != "") {
838 if ($previous["ref_id"] > 0) {
839 $ilCtrl->setParameter($this, "news_context", $previous["ref_id"]);
840 }
841 $ilCtrl->setParameter($this, "news_id", $previous["id"]);
842 $content_block->addFooterLink(
843 $lng->txt("previous"),
844 $ilCtrl->getLinkTarget($this, "showNews"),
845 "",
846 "",
847 true
848 );
849 $ilCtrl->setParameter($this, "news_context", "");
850 }
851
852 // next
853 if ($c = next($this->data)) {
854 if ($c["ref_id"] > 0) {
855 $ilCtrl->setParameter($this, "news_context", $c["ref_id"]);
856 }
857 $ilCtrl->setParameter($this, "news_id", $c["id"]);
858 $content_block->addFooterLink(
859 $lng->txt("next"),
860 $ilCtrl->getLinkTarget($this, "showNews"),
861 "",
862 "",
863 true
864 );
865 }
866 $ilCtrl->setParameter($this, "news_context", "");
867 $ilCtrl->setParameter($this, "news_id", "");
868 $content_block->setCurrentItemNumber($curr_cnt);
869 $content_block->setEnableNumInfo(true);
870 $content_block->setData($this->getData());
871
872 return $content_block->getHTML();
873 }
874
881 public function makeClickable($a_str)
882 {
883 // this fixes bug 8744. We assume that strings that contain < and >
884 // already contain html, we do not handle these
885 if (is_int(strpos($a_str, ">")) && is_int(strpos($a_str, "<"))) {
886 return $a_str;
887 }
888
889 return ilUtil::makeClickable($a_str);
890 }
891
892
896 public function unsubscribeNews()
897 {
900
901 include_once("./Services/News/classes/class.ilNewsSubscription.php");
903 $ilCtrl->returnToParent($this);
904 }
905
909 public function subscribeNews()
910 {
913
914 include_once("./Services/News/classes/class.ilNewsSubscription.php");
915 ilNewsSubscription::_subscribe($_GET["ref_id"], $ilUser->getId());
916 $ilCtrl->returnToParent($this);
917 }
918
922 public function fillFooter()
923 {
927
928 parent::fillFooter();
929
930 if ($this->show_view_selection) {
931 $this->showViewFooter();
932 }
933 }
934
938 public function showViewFooter()
939 {
943
944 return; // notifications always shown
945
946 $this->clearFooterLinks();
947 $this->addFooterLink("[" . $lng->txt("news_first_letter_of_word_notification") . "] " .
948 $lng->txt("news_notifications") . ": ", "", "", "", false, true);
949 if ($this->view == "hide_notifications") {
950 $this->addFooterLink(
951 $lng->txt("show"),
952 $ilCtrl->getLinkTarget(
953 $this,
954 "showNotifications"
955 ),
956 $ilCtrl->getLinkTarget(
957 $this,
958 "showNotifications",
959 "",
960 true
961 ),
962 "block_" . $this->getBlockType() . "_" . $this->block_id
963 );
964 $this->addFooterLink($lng->txt("hide"));
965 } else {
966 $this->addFooterLink($lng->txt("show"));
967 $this->addFooterLink(
968 $lng->txt("hide"),
969 $ilCtrl->getLinkTarget(
970 $this,
971 "hideNotifications"
972 ),
973 $ilCtrl->getLinkTarget(
974 $this,
975 "hideNotifications",
976 "",
977 true
978 ),
979 "block_" . $this->getBlockType() . "_" . $this->block_id
980 );
981 }
982
983 $this->fillFooterLinks();
984 }
985
986 public function showNotifications()
987 {
990
991 include_once("Services/Block/classes/class.ilBlockSetting.php");
993 $this->getBlockType(),
994 "view",
995 "",
996 $ilUser->getId(),
997 $this->block_id
998 );
999
1000 // reload data
1001 $data = $this->getNewsData();
1002 $this->setData($data);
1003 $this->handleView();
1004
1005 if ($ilCtrl->isAsynch()) {
1006 echo $this->getHTML();
1007 exit;
1008 } else {
1009 $ilCtrl->returnToParent($this);
1010 }
1011 }
1012
1013 public function hideNotifications()
1014 {
1017
1018 include_once("Services/Block/classes/class.ilBlockSetting.php");
1019 $view = ilBlockSetting::_write(
1020 $this->getBlockType(),
1021 "view",
1022 "hide_notifications",
1023 $ilUser->getId(),
1024 $this->block_id
1025 );
1026
1027 // reload data
1028 $data = $this->getNewsData();
1029 $this->setData($data);
1030 $this->handleView();
1031
1032 if ($ilCtrl->isAsynch()) {
1033 echo $this->getHTML();
1034 exit;
1035 } else {
1036 $ilCtrl->returnToParent($this);
1037 }
1038 }
1039
1043 public function editSettings()
1044 {
1045 $this->initSettingsForm();
1046 return $this->settings_form->getHTML();
1047 }
1048
1052 public function initSettingsForm()
1053 {
1055 $lng = $this->lng;
1058 $ilTabs = $this->tabs;
1059
1060 $ilTabs->clearTargets();
1061
1062 $news_set = new ilSetting("news");
1063 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1064
1065 $public = ilBlockSetting::_lookup(
1066 $this->getBlockType(),
1067 "public_notifications",
1068 0,
1069 $this->block_id
1070 );
1071 $public_feed = ilBlockSetting::_lookup(
1072 $this->getBlockType(),
1073 "public_feed",
1074 0,
1075 $this->block_id
1076 );
1077 $hide_block = ilBlockSetting::_lookup(
1078 $this->getBlockType(),
1079 "hide_news_block",
1080 0,
1081 $this->block_id
1082 );
1083 $hide_news_per_date = ilBlockSetting::_lookup(
1084 $this->getBlockType(),
1085 "hide_news_per_date",
1086 0,
1087 $this->block_id
1088 );
1089 $hide_news_date = ilBlockSetting::_lookup(
1090 $this->getBlockType(),
1091 "hide_news_date",
1092 0,
1093 $this->block_id
1094 );
1095
1096 if ($hide_news_date != "") {
1097 $hide_news_date = explode(" ", $hide_news_date);
1098 }
1099
1100 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1101 $this->settings_form = new ilPropertyFormGUI();
1102 $this->settings_form->setTitle($lng->txt("news_settings"));
1103
1104 // hide news block for learners
1105 if ($this->getProperty("hide_news_block_option")) {
1106 $ch = new ilCheckboxInputGUI(
1107 $lng->txt("news_hide_news_block"),
1108 "hide_news_block"
1109 );
1110 $ch->setInfo($lng->txt("news_hide_news_block_info"));
1111 $ch->setChecked($hide_block);
1112 $this->settings_form->addItem($ch);
1113
1114 $hnpd = new ilCheckboxInputGUI(
1115 $lng->txt("news_hide_news_per_date"),
1116 "hide_news_per_date"
1117 );
1118 $hnpd->setInfo($lng->txt("news_hide_news_per_date_info"));
1119 $hnpd->setChecked($hide_news_per_date);
1120
1121 $dt_prop = new ilDateTimeInputGUI(
1122 $lng->txt("news_hide_news_date"),
1123 "hide_news_date"
1124 );
1125 $dt_prop->setRequired(true);
1126 if ($hide_news_date != "") {
1127 $dt_prop->setDate(new ilDateTime($hide_news_date[0] . ' ' . $hide_news_date[1], IL_CAL_DATETIME));
1128 }
1129 #$dt_prop->setDate($hide_news_date[0]);
1130 #$dt_prop->setTime($hide_news_date[1]);
1131 $dt_prop->setShowTime(true);
1132 //$dt_prop->setInfo($lng->txt("news_hide_news_date_info"));
1133 $hnpd->addSubItem($dt_prop);
1134
1135 $this->settings_form->addItem($hnpd);
1136 }
1137
1138 // default visibility
1139 if ($this->getProperty("default_visibility_option") &&
1140 $enable_internal_rss) {
1141 $default_visibility = ilBlockSetting::_lookup(
1142 $this->getBlockType(),
1143 "default_visibility",
1144 0,
1145 $this->block_id
1146 );
1147 if ($default_visibility == "") {
1148 $default_visibility =
1150 }
1151
1152 // Default Visibility
1153 $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
1154 $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
1155 $radio_group->addOption($radio_option);
1156 $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
1157 $radio_group->addOption($radio_option);
1158 $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
1159 $radio_group->setRequired(false);
1160 $radio_group->setValue($default_visibility);
1161 $this->settings_form->addItem($radio_group);
1162 }
1163
1164 // public notifications
1165 if ($this->getProperty("public_notifications_option") &&
1166 $enable_internal_rss) {
1167 $ch = new ilCheckboxInputGUI(
1168 $lng->txt("news_notifications_public"),
1169 "notifications_public"
1170 );
1171 $ch->setInfo($lng->txt("news_notifications_public_info"));
1172 $ch->setChecked($public);
1173 $this->settings_form->addItem($ch);
1174 }
1175
1176 // extra rss feed
1177 if ($enable_internal_rss) {
1178 $ch = new ilCheckboxInputGUI(
1179 $lng->txt("news_public_feed"),
1180 "notifications_public_feed"
1181 );
1182 $ch->setInfo($lng->txt("news_public_feed_info"));
1183 $ch->setChecked($public_feed);
1184 $this->settings_form->addItem($ch);
1185 }
1186
1187
1188 //$this->settings_form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
1189 // "1", $public_feed, $lng->txt("news_public_feed_info"));
1190 //if ($this->getProperty("public_notifications_option"))
1191 //{
1192 // $this->settings_form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
1193 // "1", $public, $lng->txt("news_notifications_public_info"));
1194 //}
1195 $this->settings_form->addCommandButton("saveSettings", $lng->txt("save"));
1196 $this->settings_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
1197 $this->settings_form->setFormAction($ilCtrl->getFormaction($this));
1198 }
1199
1203 public function cancelSettings()
1204 {
1206
1207 $ilCtrl->returnToParent($this);
1208 }
1209
1213 public function saveSettings()
1214 {
1217
1218 $this->initSettingsForm();
1219
1220 if ($this->settings_form->checkInput()) {
1221 $news_set = new ilSetting("news");
1222 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1223
1224 if ($enable_internal_rss) {
1226 $this->getBlockType(),
1227 "public_notifications",
1228 $_POST["notifications_public"],
1229 0,
1230 $this->block_id
1231 );
1233 $this->getBlockType(),
1234 "public_feed",
1235 $_POST["notifications_public_feed"],
1236 0,
1237 $this->block_id
1238 );
1240 $this->getBlockType(),
1241 "default_visibility",
1242 $_POST["default_visibility"],
1243 0,
1244 $this->block_id
1245 );
1246 }
1247
1248 if ($this->getProperty("hide_news_block_option")) {
1250 $this->getBlockType(),
1251 "hide_news_block",
1252 $_POST["hide_news_block"],
1253 0,
1254 $this->block_id
1255 );
1257 $this->getBlockType(),
1258 "hide_news_per_date",
1259 $_POST["hide_news_per_date"],
1260 0,
1261 $this->block_id
1262 );
1263
1264 // hide date
1265 $hd = $this->settings_form->getItemByPostVar("hide_news_date");
1266 $hide_date = $hd->getDate();
1267 if ($_POST["hide_news_per_date"] && $hide_date != null) {
1269 $this->getBlockType(),
1270 "hide_news_date",
1271 $hide_date->get(IL_CAL_DATETIME),
1272 0,
1273 $this->block_id
1274 );
1275 } else {
1277 $this->getBlockType(),
1278 "hide_news_date",
1279 "",
1280 0,
1281 $this->block_id
1282 );
1283 }
1284 }
1285
1286 include_once("./Services/News/classes/class.ilNewsCache.php");
1287 $cache = new ilNewsCache();
1288 $cache->deleteEntry($ilUser->getId() . ":" . $_GET["ref_id"]);
1289
1290 $ilCtrl->returnToParent($this);
1291 } else {
1292 $this->settings_form->setValuesByPost();
1293 return $this->settings_form->getHtml();
1294 }
1295 }
1296
1300 public function showFeedUrl()
1301 {
1302 $lng = $this->lng;
1305
1306 include_once("./Services/News/classes/class.ilNewsItem.php");
1307
1308 $title = ilObject::_lookupTitle($this->block_id);
1309
1310 $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
1311 $tpl->setVariable(
1312 "TXT_TITLE",
1313 sprintf($lng->txt("news_feed_url_for"), $title)
1314 );
1315 $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
1316 $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
1317 $tpl->setVariable(
1318 "VAL_FEED_URL",
1319 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&user_id=" . $ilUser->getId() .
1320 "&obj_id=" . $this->block_id .
1321 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
1322 );
1323 $tpl->setVariable(
1324 "VAL_FEED_URL_TXT",
1325 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&<br />user_id=" . $ilUser->getId() .
1326 "&obj_id=" . $this->block_id .
1327 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
1328 );
1329
1330 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
1331 $content_block = new ilPDContentBlockGUI();
1332 $content_block->setContent($tpl->get());
1333 $content_block->setTitle($lng->txt("news_internal_news"));
1334 $content_block->addHeaderCommand(
1335 $ilCtrl->getParentReturn($this),
1336 $lng->txt("close"),
1337 true
1338 );
1339
1340 return $content_block->getHTML();
1341 }
1342
1343 public function addCloseCommand($a_content_block)
1344 {
1345 $lng = $this->lng;
1347
1348 $a_content_block->addHeaderCommand(
1349 $ilCtrl->getParentReturn($this),
1350 $lng->txt("close"),
1351 true
1352 );
1353 }
1354
1355 public function getDynamic()
1356 {
1359
1360 if ($ilCtrl->getCmd() == "hideNotifications" ||
1361 $ilCtrl->getCmd() == "showNotifications") {
1362 return false;
1363 }
1364
1365 if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS") {
1366 $sess_feed_js = "";
1367 if (isset($_SESSION["il_feed_js"])) {
1368 $sess_feed_js = $_SESSION["il_feed_js"];
1369 }
1370
1371 if ($sess_feed_js != "n" &&
1372 ($ilUser->getPref("il_feed_js") != "n" || $sess_feed_js == "y")) {
1373 // do not get feed dynamically, if cache hit is given.
1374 // if (!$this->feed->checkCacheHit())
1375 // {
1376 return true;
1377 // }
1378 }
1379 }
1380
1381 return false;
1382 }
1383
1384 public function getDynamicReload()
1385 {
1387 $lng = $this->lng;
1388
1389 $ilCtrl->setParameterByClass(
1390 "ilcolumngui",
1391 "block_id",
1392 "block_" . $this->getBlockType() . "_" . $this->getBlockId()
1393 );
1394
1395 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/News");
1396 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("news_loading_news"));
1397 $rel_tpl->setVariable("BLOCK_ID", "block_" . $this->getBlockType() . "_" . $this->getBlockId());
1398 $rel_tpl->setVariable(
1399 "TARGET",
1400 $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true)
1401 );
1402
1403 // no JS
1404 $rel_tpl->setVariable("TXT_NEWS_CLICK_HERE", $lng->txt("news_no_js_click_here"));
1405 $rel_tpl->setVariable(
1406 "TARGET_NO_JS",
1407 $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "disableJS")
1408 );
1409
1410 return $rel_tpl->get();
1411 }
1412
1413 public function getJSEnabler()
1414 {
1416 $lng = $this->lng;
1417
1418 $ilCtrl->setParameterByClass(
1419 "ilcolumngui",
1420 "block_id",
1421 "block_" . $this->getBlockType() . "_" . $this->getBlockId()
1422 );
1423 //echo "hh";
1424 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/News");
1425 $rel_tpl->setVariable("BLOCK_ID", "block_" . $this->getBlockType() . "_" . $this->getBlockId());
1426 $rel_tpl->setVariable(
1427 "TARGET",
1428 $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "enableJS", true, "", false)
1429 );
1430
1431 return $rel_tpl->get();
1432 }
1433
1434
1435 public function disableJS()
1436 {
1439
1440 $_SESSION["il_feed_js"] = "n";
1441 $ilUser->writePref("il_feed_js", "n");
1442 $ilCtrl->returnToParent($this);
1443 //$ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1444 }
1445
1446 public function enableJS()
1447 {
1449 //echo "enableJS";
1450 $_SESSION["il_feed_js"] = "y";
1451 $ilUser->writePref("il_feed_js", "y");
1452 echo $this->getHTML();
1453 exit;
1454 }
1455}
sprintf('%.4f', $callTime)
user()
Definition: user.php:4
$_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.
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.
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.
getProperty($a_property)
setTitle($a_title)
Set Title.
setBlockId($a_block_id=0)
Set Block Id.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
addBlockCommand( $a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
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, $a_skip_day=false, $a_include_wd=false)
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 prepareNewsDataFromCache($a_cres)
Prepare news data from cache.
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 _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).
static _getThreadForPosting($a_pos_id)
Get thread id for posting.
Class ilObjMediaObject.
static _getURL($a_mob_id)
get directory for files of media object (static)
static _lookupFeedHash($a_user_id, $a_create=false)
Lookup news feed hash for user.
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.
static makeUrlTitle($a_par)
Set page parameter for Url Embedding.
$html
Definition: example_001.php:87
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:17
$type
$url
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2
$this data['403_header']
$ilUser
Definition: imgupload.php:18