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