ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
5 include_once("Services/Block/classes/class.ilBlockGUI.php");
6 
19 {
20  static $block_type = "news";
21  static $st_data;
22 
27  {
28  global $ilCtrl, $lng, $ilUser, $ilHelp;
29 
30  parent::ilBlockGUI();
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);
38  $this->setAvailableDetailLevels(3);
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 = $this->acache->getEntry($ilUser->getId().":".$_GET["ref_id"]);
45  $this->cache_hit = false;
46 
47  if ($this->acache->getLastAccessStatus() == "hit")
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  {
61  $data = self::$st_data;
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 
222  function fillDataSection()
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", "dbk", "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($_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  // collect news items to show
518  $news_list = array();
519  if (is_array($c["aggregation"])) // we have an aggregation
520  {
521  $news_list[] = array("ref_id" => $c["agg_ref_id"],
522  "agg_ref_id" => $c["agg_ref_id"],
523  "aggregation" => $c["aggregation"],
524  "user_id" => "",
525  "content_type" => "text",
526  "mob_id" => 0,
527  "visibility" => "",
528  "content" => "",
529  "content_long" => "",
530  "update_date" => $news->getUpdateDate(),
531  "creation_date" => "",
532  "content_is_lang_var" => false,
533  "loc_context" => $_GET["news_context"],
534  "context_obj_type" => $news->getContextObjType(),
535  "title" => "");
536 
537  foreach($c["aggregation"] as $c_item)
538  {
539  ilNewsItem::_setRead($ilUser->getId(), $c_item["id"]);
540  $c_item["loc_context"] = $c_item["ref_id"];
541  $c_item["loc_stop"] = $_GET["news_context"];
542  $news_list[] = $c_item;
543  }
544  }
545  else // no aggregation, simple news item
546  {
547  $news_list[] = array("ref_id" => $_GET["news_context"],
548  "user_id" => $news->getUserId(),
549  "content_type" => $news->getContentType(),
550  "mob_id" => $news->getMobId(),
551  "visibility" => $news->getVisibility(),
552  "priority" => $news->getPriority(),
553  "content" => $news->getContent(),
554  "content_long" => $news->getContentLong(),
555  "update_date" => $news->getUpdateDate(),
556  "creation_date" => $news->getCreationDate(),
557  "context_sub_obj_type" => $news->getContextSubObjType(),
558  "context_obj_type" => $news->getContextObjType(),
559  "context_sub_obj_id" => $news->getContextSubObjId(),
560  "content_is_lang_var" => $news->getContentIsLangVar(),
561  "content_text_is_lang_var" => $news->getContentTextIsLangVar(),
562  "loc_context" => $_GET["news_context"],
563  "title" => $news->getTitle());
564  ilNewsItem::_setRead($ilUser->getId(), $_GET["news_id"]);
565  }
566 
567  $row_css = "";
568  $cache_deleted = false;
569  foreach ($news_list as $item)
570  {
571  $row_css = ($row_css != "tblrow1")
572  ? "tblrow1"
573  : "tblrow2";
574 
575  if ($item["ref_id"] > 0 && !$ilAccess->checkAccess("read", "", $item["ref_id"]))
576  {
577  $tpl->setCurrentBlock("content");
578  $tpl->setVariable("VAL_CONTENT", $lng->txt("news_sorry_not_accessible_anymore"));
579  $tpl->parseCurrentBlock();
580  $tpl->setCurrentBlock("item");
581  $tpl->setVariable("ITEM_ROW_CSS", $row_css);
582  $tpl->parseCurrentBlock();
583  if (!$cache_deleted)
584  {
585  $this->acache->deleteEntry($ilUser->getId() . ":" . $_GET["ref_id"]);
586  $cache_deleted = true;
587  }
588  continue;
589  }
590 
591  // user
592  if ($item["user_id"] > 0 && ilObject::_exists($item["user_id"]))
593  {
594  // get login
595  if (ilObjUser::_exists($item["user_id"]))
596  {
597  $user = new ilObjUser($item["user_id"]);
598  $displayname = $user->getLogin();
599  } else
600  {
601  // this should actually not happen, since news entries
602  // should be deleted when the user is going to be removed
603  $displayname = "&lt;". strtolower($lng->txt("deleted")) ."&gt;";
604  }
605 
606  $tpl->setCurrentBlock("user_info");
607  $tpl->setVariable("VAL_AUTHOR", $displayname);
608  $tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
609  $tpl->parseCurrentBlock();
610  }
611 
612  // media player
613  if ($item["content_type"] == NEWS_AUDIO &&
614  $item["mob_id"] > 0 && ilObject::_exists($item["mob_id"]))
615  {
616  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
617  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
618  $mob = new ilObjMediaObject($item["mob_id"]);
619  $med = $mob->getMediaItem("Standard");
620  $mpl = new ilMediaPlayerGUI("news_pl_".$item["mob_id"]);
621  if (strcasecmp("Reference", $med->getLocationType()) == 0)
622  $mpl->setFile($med->getLocation());
623  else
624  $mpl->setFile(ilObjMediaObject::_getURL($mob->getId())."/".$med->getLocation());
625  $mpl->setDisplayHeight($med->getHeight());
626  $tpl->setCurrentBlock("player");
627  $tpl->setVariable("PLAYER",
628  $mpl->getMp3PlayerHtml());
629  $tpl->parseCurrentBlock();
630  }
631 
632  // access
633  if ($enable_internal_rss && $item["visibility"] != "")
634  {
635  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
636  $tpl->setCurrentBlock("access");
637  $tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
638  if ($item["visibility"] == NEWS_PUBLIC ||
639  ($item["priority"] == 0 &&
640  ilBlockSetting::_lookup("news", "public_notifications",
641  0, $obj_id)))
642  {
643  $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
644  }
645  else
646  {
647  $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
648  }
649  $tpl->parseCurrentBlock();
650  }
651 
652  // content
653  if (trim($item["content"]) != "") // content
654  {
655  $tpl->setCurrentBlock("content");
656  $tpl->setVariable("VAL_CONTENT",
657  nl2br($this->makeClickable(
658  ilNewsItem::determineNewsContent($item["context_obj_type"], $item["content"], $item["content_text_is_lang_var"])
659  )));
660 //$tpl->setVariable("VAL_CONTENT", nl2br($item["content"]));
661  $tpl->parseCurrentBlock();
662  }
663  if (trim($item["content_long"]) != "") // long content
664  {
665  $tpl->setCurrentBlock("long");
666  $tpl->setVariable("VAL_LONG_CONTENT", $this->makeClickable($item["content_long"]));
667  $tpl->parseCurrentBlock();
668  }
669  if ($item["update_date"] != $item["creation_date"]) // update date
670  {
671  $tpl->setCurrentBlock("ni_update");
672  $tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
673  $tpl->setVariable("VAL_LAST_UPDATE",
674  ilDatePresentation::formatDate(new ilDateTime($item["update_date"],IL_CAL_DATETIME)));
675  $tpl->parseCurrentBlock();
676  }
677 
678  // creation date
679  if ($item["creation_date"] != "")
680  {
681  $tpl->setCurrentBlock("ni_update");
682  $tpl->setVariable("VAL_CREATION_DATE",
683  ilDatePresentation::formatDate(new ilDateTime($item["creation_date"],IL_CAL_DATETIME)));
684  $tpl->setVariable("TXT_CREATED", $lng->txt("created"));
685  $tpl->parseCurrentBlock();
686  }
687 
688 
689  // context / title
690  if ($_GET["news_context"] > 0)
691  {
692  //$obj_id = ilObject::_lookupObjId($_GET["news_context"]);
693  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
694  $obj_type = ilObject::_lookupType($obj_id);
695  $obj_title = ilObject::_lookupTitle($obj_id);
696 
697  // file hack, not nice
698  if ($obj_type == "file")
699  {
700  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $item["ref_id"]);
701  $url = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "sendfile");
702  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
703 
704  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
705  $button = ilLinkButton::getInstance();
706  $button->setUrl($url);
707  $button->setCaption("download");
708 
709  $tpl->setCurrentBlock("download");
710  $tpl->setVariable("BUTTON_DOWNLOAD", $button->render());
711  $tpl->parseCurrentBlock();
712  }
713 
714  // forum hack, not nice
715  $add = "";
716  if ($obj_type == "frm" && $item["context_sub_obj_type"] == "pos"
717  && $item["context_sub_obj_id"] > 0)
718  {
719  include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
720  $pos = $item["context_sub_obj_id"];
721  $thread = ilObjForumAccess::_getThreadForPosting($pos);
722  if ($thread > 0)
723  {
724  $add = "_".$thread."_".$pos;
725  }
726  }
727 
728  // wiki hack, not nice
729  if ($obj_type == "wiki" && $item["context_sub_obj_type"] == "wpg"
730  && $item["context_sub_obj_id"] > 0)
731  {
732  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
733  $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]);
734  if ($wptitle != "")
735  {
736  $add = "_".ilWikiUtil::makeUrlTitle($wptitle);
737  }
738  }
739 
740  $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
741  $obj_type."_".$item["ref_id"].$add;
742 
743  // lm page hack, not nice
744  if (in_array($obj_type, array("dbk", "lm")) && $item["context_sub_obj_type"] == "pg"
745  && $item["context_sub_obj_id"] > 0)
746  {
747  $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
748  "pg_".$item["context_sub_obj_id"]."_".$item["ref_id"];
749  }
750 
751 
752  $context_opened = false;
753  if ($item["loc_context"] != null && $item["loc_context"] != $item["loc_stop"])
754  {
755 
756  $tpl->setCurrentBlock("context");
757  $context_opened = true;
758  $cont_loc = new ilLocatorGUI();
759  $cont_loc->addContextItems($item["loc_context"], true, $item["loc_stop"]);
760  $tpl->setVariable("CONTEXT_LOCATOR", $cont_loc->getHTML());
761  }
762 
763 //var_dump($item);
764  if ($item["no_context_title"] !== true)
765  {
766  if (!$context_opened)
767  {
768  $tpl->setCurrentBlock("context");
769  }
770  $tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
771  $tpl->setVariable("CONTEXT_TITLE", $obj_title);
772  $tpl->setVariable("IMG_CONTEXT_TITLE", ilObject::_getIcon($obj_id, "big", $obj_type));
773  }
774  if ($context_opened)
775  {
776  $tpl->parseCurrentBlock();
777  }
778 
779  $tpl->setVariable("HREF_TITLE", $url_target);
780  }
781 
782  // title
783  $tpl->setVariable("VAL_TITLE",
784  ilNewsItem::determineNewsTitle($item["context_obj_type"],
785  $item["title"], $item["content_is_lang_var"], $item["agg_ref_id"],
786  $item["aggregation"]));
787 
788 
789  $tpl->setCurrentBlock("item");
790  $tpl->setVariable("ITEM_ROW_CSS", $row_css);
791  $tpl->parseCurrentBlock();
792  }
793 
794  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
795  $content_block = new ilPDContentBlockGUI();
796  $content_block->setContent($tpl->get());
797  if ($this->getProperty("title") != "")
798  {
799  $content_block->setTitle($this->getProperty("title"));
800  }
801  else
802  {
803  $content_block->setTitle($lng->txt("news_internal_news"));
804  }
805  $this->addCloseCommand($content_block);
806 
807  // previous
808  if ($previous != "")
809  {
810  if ($previous["ref_id"] > 0)
811  {
812  $ilCtrl->setParameter($this, "news_context", $previous["ref_id"]);
813  }
814  $ilCtrl->setParameter($this, "news_id", $previous["id"]);
815  $content_block->addFooterLink($lng->txt("previous"),
816  $ilCtrl->getLinkTarget($this, "showNews"), "", "", true);
817  $ilCtrl->setParameter($this, "news_context", "");
818  }
819 
820  // next
821  if ($c = next($this->data))
822  {
823  if ($c["ref_id"] > 0)
824  {
825  $ilCtrl->setParameter($this, "news_context", $c["ref_id"]);
826  }
827  $ilCtrl->setParameter($this, "news_id", $c["id"]);
828  $content_block->addFooterLink($lng->txt("next"),
829  $ilCtrl->getLinkTarget($this, "showNews"), "", "", true);
830  }
831  $ilCtrl->setParameter($this, "news_context", "");
832  $ilCtrl->setParameter($this, "news_id", "");
833  $content_block->setCurrentItemNumber($curr_cnt);
834  $content_block->setEnableNumInfo(true);
835  $content_block->setData($this->getData());
836 
837  return $content_block->getHTML();
838  }
839 
846  function makeClickable($a_str)
847  {
848  // this fixes bug 8744. We assume that strings that contain < and >
849  // already contain html, we do not handle these
850  if (is_int(strpos($a_str, ">")) && is_int(strpos($a_str, "<")))
851  {
852  return $a_str;
853  }
854 
855  return ilUtil::makeClickable($a_str);
856  }
857 
858 
862  function unsubscribeNews()
863  {
864  global $ilUser, $ilCtrl;
865 
866  include_once("./Services/News/classes/class.ilNewsSubscription.php");
867  ilNewsSubscription::_unsubscribe($_GET["ref_id"], $ilUser->getId());
868  $ilCtrl->returnToParent($this);
869  }
870 
874  function subscribeNews()
875  {
876  global $ilUser, $ilCtrl;
877 
878  include_once("./Services/News/classes/class.ilNewsSubscription.php");
879  ilNewsSubscription::_subscribe($_GET["ref_id"], $ilUser->getId());
880  $ilCtrl->returnToParent($this);
881  }
882 
886  function fillFooter()
887  {
888  global $ilCtrl, $lng, $ilUser;
889 
890  parent::fillFooter();
891 
892  if ($this->show_view_selection)
893  {
894  $this->showViewFooter();
895  }
896  }
897 
901  function showViewFooter()
902  {
903  global $ilUser, $lng, $ilCtrl;
904 
905  return; // notifications always shown
906 
907  $this->clearFooterLinks();
908  $this->addFooterLink("[".$lng->txt("news_first_letter_of_word_notification")."] ".
909  $lng->txt("news_notifications").": ", "", "", "", false, true);
910  if ($this->view == "hide_notifications")
911  {
912  $this->addFooterLink($lng->txt("show"),
913  $ilCtrl->getLinkTarget($this,
914  "showNotifications"),
915  $ilCtrl->getLinkTarget($this,
916  "showNotifications", "", true),
917  "block_".$this->getBlockType()."_".$this->block_id
918  );
919  $this->addFooterLink($lng->txt("hide"));
920  }
921  else
922  {
923  $this->addFooterLink($lng->txt("show"));
924  $this->addFooterLink($lng->txt("hide"),
925  $ilCtrl->getLinkTarget($this,
926  "hideNotifications"),
927  $ilCtrl->getLinkTarget($this,
928  "hideNotifications", "", true),
929  "block_".$this->getBlockType()."_".$this->block_id
930  );
931  }
932 
933  $this->fillFooterLinks();
934  }
935 
936  function showNotifications()
937  {
938  global $ilCtrl, $ilUser;
939 
940  include_once("Services/Block/classes/class.ilBlockSetting.php");
941  $view = ilBlockSetting::_write($this->getBlockType(), "view", "",
942  $ilUser->getId(), $this->block_id);
943 
944  // reload data
945  $data = $this->getNewsData();
946  $this->setData($data);
947  $this->handleView();
948 
949  if ($ilCtrl->isAsynch())
950  {
951  echo $this->getHTML();
952  exit;
953  }
954  else
955  {
956  $ilCtrl->returnToParent($this);
957  }
958  }
959 
960  function hideNotifications()
961  {
962  global $ilCtrl, $ilUser;
963 
964  include_once("Services/Block/classes/class.ilBlockSetting.php");
965  $view = ilBlockSetting::_write($this->getBlockType(), "view", "hide_notifications",
966  $ilUser->getId(), $this->block_id);
967 
968  // reload data
969  $data = $this->getNewsData();
970  $this->setData($data);
971  $this->handleView();
972 
973  if ($ilCtrl->isAsynch())
974  {
975  echo $this->getHTML();
976  exit;
977  }
978  else
979  {
980  $ilCtrl->returnToParent($this);
981  }
982  }
983 
987  function editSettings()
988  {
989  $this->initSettingsForm();
990  return $this->settings_form->getHTML();
991  }
992 
996  function initSettingsForm()
997  {
998  global $ilUser, $lng, $ilCtrl, $ilSetting, $ilTabs;
999 
1000  $ilTabs->clearTargets();
1001 
1002  $news_set = new ilSetting("news");
1003  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1004 
1005  $public = ilBlockSetting::_lookup($this->getBlockType(), "public_notifications",
1006  0, $this->block_id);
1007  $public_feed = ilBlockSetting::_lookup($this->getBlockType(), "public_feed",
1008  0, $this->block_id);
1009  $hide_block = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_block",
1010  0, $this->block_id);
1011  $hide_news_per_date = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_per_date",
1012  0, $this->block_id);
1013  $hide_news_date = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_date",
1014  0, $this->block_id);
1015 
1016  if ($hide_news_date != "")
1017  {
1018  $hide_news_date = explode(" ", $hide_news_date);
1019  }
1020 
1021  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1022  $this->settings_form = new ilPropertyFormGUI();
1023  $this->settings_form->setTitle($lng->txt("news_settings"));
1024 
1025  // hide news block for learners
1026  if ($this->getProperty("hide_news_block_option"))
1027  {
1028  $ch = new ilCheckboxInputGUI($lng->txt("news_hide_news_block"),
1029  "hide_news_block");
1030  $ch->setInfo($lng->txt("news_hide_news_block_info"));
1031  $ch->setChecked($hide_block);
1032  $this->settings_form->addItem($ch);
1033 
1034  $hnpd = new ilCheckboxInputGUI($lng->txt("news_hide_news_per_date"),
1035  "hide_news_per_date");
1036  $hnpd->setInfo($lng->txt("news_hide_news_per_date_info"));
1037  $hnpd->setChecked($hide_news_per_date);
1038 
1039  $dt_prop = new ilDateTimeInputGUI($lng->txt("news_hide_news_date"),
1040  "hide_news_date");
1041  if ($hide_news_date != "")
1042  {
1043  $dt_prop->setDate(new ilDateTime($hide_news_date[0].' '.$hide_news_date[1],IL_CAL_DATETIME));
1044  }
1045  #$dt_prop->setDate($hide_news_date[0]);
1046  #$dt_prop->setTime($hide_news_date[1]);
1047  $dt_prop->setShowTime(true);
1048  //$dt_prop->setInfo($lng->txt("news_hide_news_date_info"));
1049  $hnpd->addSubItem($dt_prop);
1050 
1051  $this->settings_form->addItem($hnpd);
1052 
1053  }
1054 
1055  // default visibility
1056  if ($this->getProperty("default_visibility_option") &&
1057  $enable_internal_rss)
1058  {
1059  $default_visibility = ilBlockSetting::_lookup($this->getBlockType(), "default_visibility",
1060  0, $this->block_id);
1061  if ($default_visibility == "")
1062  {
1063  $default_visibility =
1065  }
1066 
1067  // Default Visibility
1068  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
1069  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
1070  $radio_group->addOption($radio_option);
1071  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
1072  $radio_group->addOption($radio_option);
1073  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
1074  $radio_group->setRequired(false);
1075  $radio_group->setValue($default_visibility);
1076  $this->settings_form->addItem($radio_group);
1077  }
1078 
1079  // public notifications
1080  if ($this->getProperty("public_notifications_option") &&
1081  $enable_internal_rss)
1082  {
1083  $ch = new ilCheckboxInputGUI($lng->txt("news_notifications_public"),
1084  "notifications_public");
1085  $ch->setInfo($lng->txt("news_notifications_public_info"));
1086  $ch->setChecked($public);
1087  $this->settings_form->addItem($ch);
1088  }
1089 
1090  // extra rss feed
1091  if ($enable_internal_rss)
1092  {
1093  $ch = new ilCheckboxInputGUI($lng->txt("news_public_feed"),
1094  "notifications_public_feed");
1095  $ch->setInfo($lng->txt("news_public_feed_info"));
1096  $ch->setChecked($public_feed);
1097  $this->settings_form->addItem($ch);
1098  }
1099 
1100 
1101  //$this->settings_form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
1102  // "1", $public_feed, $lng->txt("news_public_feed_info"));
1103  //if ($this->getProperty("public_notifications_option"))
1104  //{
1105  // $this->settings_form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
1106  // "1", $public, $lng->txt("news_notifications_public_info"));
1107  //}
1108  $this->settings_form->addCommandButton("saveSettings", $lng->txt("save"));
1109  $this->settings_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
1110  $this->settings_form->setFormAction($ilCtrl->getFormaction($this));
1111  }
1112 
1116  function cancelSettings()
1117  {
1118  global $ilCtrl;
1119 
1120  $ilCtrl->returnToParent($this);
1121  }
1122 
1126  function saveSettings()
1127  {
1128  global $ilCtrl, $ilUser;
1129 
1130  $this->initSettingsForm();
1131 
1132  if ($this->settings_form->checkInput())
1133  {
1134  $news_set = new ilSetting("news");
1135  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1136 
1137  if ($enable_internal_rss)
1138  {
1139  ilBlockSetting::_write($this->getBlockType(), "public_notifications", $_POST["notifications_public"],
1140  0, $this->block_id);
1141  ilBlockSetting::_write($this->getBlockType(), "public_feed", $_POST["notifications_public_feed"],
1142  0, $this->block_id);
1143  ilBlockSetting::_write($this->getBlockType(), "default_visibility", $_POST["default_visibility"],
1144  0, $this->block_id);
1145  }
1146 
1147  if ($this->getProperty("hide_news_block_option"))
1148  {
1149  ilBlockSetting::_write($this->getBlockType(), "hide_news_block", $_POST["hide_news_block"],
1150  0, $this->block_id);
1151  ilBlockSetting::_write($this->getBlockType(), "hide_news_per_date", $_POST["hide_news_per_date"],
1152  0, $this->block_id);
1153 
1154  // hide date
1155  $hd = $this->settings_form->getInput("hide_news_date");
1156  $hide_date = new ilDateTime($hd["date"]." ".
1157  $hd["time"],IL_CAL_DATETIME,$ilUser->getTimeZone());
1158  ilBlockSetting::_write($this->getBlockType(), "hide_news_date",
1159  $hide_date->get(IL_CAL_DATETIME),
1160  0, $this->block_id);
1161  }
1162 
1163  include_once("./Services/News/classes/class.ilNewsCache.php");
1164  $cache = new ilNewsCache();
1165  $cache->deleteEntry($ilUser->getId().":".$_GET["ref_id"]);
1166 
1167  $ilCtrl->returnToParent($this);
1168  }
1169  else
1170  {
1171  $this->settings_form->setValuesByPost();
1172  return $this->settings_form->getHtml();
1173  }
1174  }
1175 
1179  function showFeedUrl()
1180  {
1181  global $lng, $ilCtrl, $ilUser;
1182 
1183  include_once("./Services/News/classes/class.ilNewsItem.php");
1184 
1185  $title = ilObject::_lookupTitle($this->block_id);
1186 
1187  $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
1188  $tpl->setVariable("TXT_TITLE",
1189  sprintf($lng->txt("news_feed_url_for"), $title));
1190  $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
1191  $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
1192  $tpl->setVariable("VAL_FEED_URL",
1193  ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&user_id=".$ilUser->getId().
1194  "&obj_id=".$this->block_id.
1195  "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
1196  $tpl->setVariable("VAL_FEED_URL_TXT",
1197  ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&<br />user_id=".$ilUser->getId().
1198  "&obj_id=".$this->block_id.
1199  "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
1200 
1201  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
1202  $content_block = new ilPDContentBlockGUI();
1203  $content_block->setContent($tpl->get());
1204  $content_block->setTitle($lng->txt("news_internal_news"));
1205  $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
1206  $lng->txt("close"), true);
1207 
1208  return $content_block->getHTML();
1209  }
1210 
1211  function addCloseCommand($a_content_block)
1212  {
1213  global $lng, $ilCtrl;
1214 
1215  $a_content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
1216  $lng->txt("close"), true);
1217  }
1218 
1219  function getDynamic()
1220  {
1221  global $ilCtrl, $ilUser;
1222 
1223  if ($ilCtrl->getCmd() == "hideNotifications" ||
1224  $ilCtrl->getCmd() == "showNotifications")
1225  {
1226  return false;
1227  }
1228 
1229  if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
1230  {
1231  $sess_feed_js = "";
1232  if (isset($_SESSION["il_feed_js"]))
1233  {
1234  $sess_feed_js = $_SESSION["il_feed_js"];
1235  }
1236 
1237  if ($sess_feed_js != "n" &&
1238  ($ilUser->getPref("il_feed_js") != "n" || $sess_feed_js == "y"))
1239  {
1240  // do not get feed dynamically, if cache hit is given.
1241 // if (!$this->feed->checkCacheHit())
1242 // {
1243  return true;
1244 // }
1245  }
1246  }
1247 
1248  return false;
1249  }
1250 
1251  function getDynamicReload()
1252  {
1253  global $ilCtrl, $lng;
1254 
1255  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
1256  "block_".$this->getBlockType()."_".$this->getBlockId());
1257 
1258  $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/News");
1259  $rel_tpl->setVariable("TXT_LOADING", $lng->txt("news_loading_news"));
1260  $rel_tpl->setVariable("BLOCK_ID", "block_".$this->getBlockType()."_".$this->getBlockId());
1261  $rel_tpl->setVariable("TARGET",
1262  $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
1263 
1264  // no JS
1265  $rel_tpl->setVariable("TXT_NEWS_CLICK_HERE", $lng->txt("news_no_js_click_here"));
1266  $rel_tpl->setVariable("TARGET_NO_JS",
1267  $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "disableJS"));
1268 
1269  return $rel_tpl->get();
1270  }
1271 
1272  function getJSEnabler()
1273  {
1274  global $ilCtrl, $lng;
1275 
1276  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
1277  "block_".$this->getBlockType()."_".$this->getBlockId());
1278 //echo "hh";
1279  $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/News");
1280  $rel_tpl->setVariable("BLOCK_ID", "block_".$this->getBlockType()."_".$this->getBlockId());
1281  $rel_tpl->setVariable("TARGET",
1282  $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "enableJS", true, "", false));
1283 
1284  return $rel_tpl->get();
1285  }
1286 
1287 
1288  function disableJS()
1289  {
1290  global $ilCtrl, $ilUser;
1291 
1292  $_SESSION["il_feed_js"] = "n";
1293  $ilUser->writePref("il_feed_js", "n");
1294 $ilCtrl->returnToParent($this);
1295  //$ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1296  }
1297 
1298  function enableJS()
1299  {
1300  global $ilUser;
1301 //echo "enableJS";
1302  $_SESSION["il_feed_js"] = "y";
1303  $ilUser->writePref("il_feed_js", "y");
1304  echo $this->getHTML();
1305  exit;
1306  }
1307 
1308 }
1309 
1310 ?>
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.
clearFooterLinks()
Clear footer links.
This class represents an option in a radio group.
ILIAS Setting Class.
static lookupTitle($a_page_id)
Checks whether a page with given title exists.
static get($a_type, $a_href="")
Get icon html.
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
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.
exit
Definition: login.php:54
$_POST['username']
Definition: cron.php:12
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
const IL_CAL_DATETIME
$_SESSION["AccountId"]
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.
This class represents a property form user interface.
setEnableEdit($a_enable_edit=0)
Set EnableEdit.
_setRead($a_user_id, $a_news_id)
Set item read.
handleView()
Handles show/hide notification view and removes notifications if hidden.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
$_GET["client_id"]
setFooterInfo($a_footerinfo, $a_hide_and_icon=false)
Set Footer Info.
$cmd
Definition: sahs_server.php:35
User Interface for NewsItem entities.
fillFooterLinks($a_top=false, $a_numinfo="")
Fill footer links.
This class represents a checkbox property in a property form.
addBlockCommand($a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
static _lookupTitle($a_id)
lookup object title
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
$url
Definition: shib_logout.php:72
BlockGUI class for block NewsForContext.
getRepositoryMode()
Get RepositoryMode.
static prepareNewsDataFromCache($a_cres)
Prepare news data from cache.
setDate(ilDateTime $a_date=NULL)
set date E.g $dt_form->setDate(new ilDateTime(time(),IL_CAL_UTC)); or $dt_form->setDate(new ilDateTim...
setInfo($a_info)
Set Info.
static _getURL($a_mob_id)
get directory for files of media object (static)
News cache.
This class represents a date/time property in a property form.
global $tpl
Definition: ilias.php:8
locator handling class
static _unsubscribe($a_ref_id, $a_user_id)
Unsubscribe a user from an object (ref id).
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
const NEWS_PUBLIC
const IL_SCREEN_FULL
This class represents a property in a property form.
fillRow($news)
get flat bookmark list for personal desktop
subscribeNews()
Subscribe current user from news.
setTitle($a_title)
Set Title.
static determineNewsContent($a_context_obj_type, $a_content, $a_is_lang_var)
Determine new content.
setBlockId($a_block_id=0)
Set Block Id.
setData($a_data)
Set Data.
static _lookupObjId($a_id)
static makeClickable($a_text, $detectGotoLinks=false)
makeClickable In Texten enthaltene URLs und Mail-Adressen klickbar machen
special template class to simplify handling of ITX/PEAR
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
Class ilObjMediaObject.
const IL_SCREEN_CENTER
static _lookupType($a_id, $a_reference=false)
lookup object type
getBlockId()
Get Block Id.
unsubscribeNews()
Unsubscribe current user from news.
getData()
Get Data.
showViewFooter()
Show additional footer for show/hide notifications.
setLimit($a_limit)
Set Limit.
static _subscribe($a_ref_id, $a_user_id)
Subscribe a user to an object (ref id).
User interface for media player.
global $ilUser
Definition: imgupload.php:15
global $ilSetting
Definition: privfeed.php:40
global $lng
Definition: privfeed.php:40
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
static isRepositoryObject()
Is this a repository object.
This class represents a block method of a block.
static getScreenMode()
Get Screen Mode for current command.
BlockGUI class for (centered) Content on Personal Desktop.
const IL_SCREEN_SIDE
const NEWS_AUDIO
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
$html
Definition: example_001.php:87
getProperty($a_property)
getCurrentDetailLevel()
Get Current Detail Level.