ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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;
29 
31 
32  $this->setImage(ilUtil::getImagePath("icon_news_s.gif"));
33 
34  $lng->loadLanguageModule("news");
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 = unserialize($cres);
50  $this->cache_hit = true;
51  }
52  if ($this->getDynamic() && !$this->cache_hit)
53  {
54  $this->dynamic = true;
55  $data = array();
56  }
57  else if ($this->getCurrentDetailLevel() > 0)
58  {
59  if (!empty(self::$st_data))
60  {
62  }
63  else
64  {
65  $data = $this->getNewsData();
66  self::$st_data = $data;
67  }
68  }
69  else
70  {
71  $data = array();
72  }
73 
74  $this->setTitle($lng->txt("news_internal_news"));
75  $this->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
76  $this->setData($data);
77  $this->allow_moving = false;
78  $this->handleView();
79  }
80 
84  function getNewsData()
85  {
86  global $ilCtrl, $ilUser;
87 
88  include_once("./Services/News/classes/class.ilNewsCache.php");
89  $this->acache = new ilNewsCache();
90 /* $cres = $this->acache->getEntry($ilUser->getId().":".$_GET["ref_id"]);
91  if ($this->acache->getLastAccessStatus() == "hit" && false)
92  {
93  $news_data = unserialize($cres);
94  }
95  else
96  {*/
97  $news_item = new ilNewsItem();
98  $news_item->setContextObjId($ilCtrl->getContextObjId());
99  $news_item->setContextObjType($ilCtrl->getContextObjType());
100 
101  // workaround, better: reduce constructor and introduce
102  //$prevent_aggregation = $this->getProperty("prevent_aggregation");
103  $prevent_aggregation = true;
104 
105 
106  $news_data = $news_item->getNewsForRefId($_GET["ref_id"], false, false, 0,
107  $prevent_aggregation, true);
108 
109  $this->acache->storeEntry($ilUser->getId().":".$_GET["ref_id"],
110  serialize($news_data));
111 
112 // }
113 //var_dump($news_data);
114  return $news_data;
115  }
116 
122  static function getBlockType()
123  {
124  return self::$block_type;
125  }
126 
132  static function isRepositoryObject()
133  {
134  return false;
135  }
136 
140  static function getScreenMode()
141  {
142  global $ilCtrl;
143 
144  if ($ilCtrl->getCmdClass() == "ilnewsitemgui")
145  {
146  return IL_SCREEN_FULL;
147  }
148 
149  switch($ilCtrl->getCmd())
150  {
151  case "showNews":
152  case "showFeedUrl":
153  return IL_SCREEN_CENTER;
154  break;
155 
156  case "editSettings":
157  case "saveSettings":
158  return IL_SCREEN_FULL;
159  break;
160 
161  default:
162  return IL_SCREEN_SIDE;
163  break;
164  }
165  }
166 
170  function &executeCommand()
171  {
172  global $ilCtrl;
173 
174  $next_class = $ilCtrl->getNextClass();
175  $cmd = $ilCtrl->getCmd("getHTML");
176 
177  switch ($next_class)
178  {
179  case "ilnewsitemgui":
180  include_once("./Services/News/classes/class.ilNewsItemGUI.php");
181  $news_item_gui = new ilNewsItemGUI();
182  $news_item_gui->setEnableEdit($this->getEnableEdit());
183  $html = $ilCtrl->forwardCommand($news_item_gui);
184  return $html;
185 
186  default:
187  return $this->$cmd();
188  }
189  }
190 
196  public function setEnableEdit($a_enable_edit = 0)
197  {
198  $this->enable_edit = $a_enable_edit;
199  }
200 
206  public function getEnableEdit()
207  {
208  return $this->enable_edit;
209  }
210 
214  function fillDataSection()
215  {
216  if ($this->dynamic)
217  {
218  $this->setDataSection($this->getDynamicReload());
219  }
220  else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
221  {
223  }
224  else
225  {
226  $this->setDataSection($this->getOverview());
227  }
228  }
229 
233  function getHTML()
234  {
235  global $ilCtrl, $lng, $ilUser;
236 
237  $news_set = new ilSetting("news");
238  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
239 
240  $hide_block = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_block",
241  0, $this->block_id);
242  if ($hide_block)
243  {
244  $this->setFooterInfo($lng->txt("news_hidden_news_block"));
245  }
246 
247  if ($this->getProperty("title") != "")
248  {
249  $this->setTitle($this->getProperty("title"));
250  }
251 
252  $public_feed = ilBlockSetting::_lookup($this->getBlockType(), "public_feed",
253  0, $this->block_id);
254  if ($public_feed)
255  {
256  if ($enable_internal_rss)
257  {
258  $this->addBlockCommand(
259  ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&".
260  "ref_id=".$_GET["ref_id"],
261  $lng->txt("news_feed_url"), "_blank",
262  ilUtil::getImagePath("rss.gif"));
263  }
264  }
265 
266 /* Subscription Concept is abandonded for now (Alex)
267  // subscribe/unsibscribe link
268  include_once("./Services/News/classes/class.ilNewsSubscription.php");
269  if (ilNewsSubscription::_hasSubscribed($_GET["ref_id"], $ilUser->getId()))
270  {
271  $this->addBlockCommand(
272  $ilCtrl->getLinkTarget($this, "unsubscribeNews"),
273  $lng->txt("news_unsubscribe"));
274  }
275  else
276  {
277  $this->addBlockCommand(
278  $ilCtrl->getLinkTarget($this, "subscribeNews"),
279  $lng->txt("news_subscribe"));
280  }
281 */
282 
283  // add edit commands
284  if ($this->getEnableEdit())
285  {
286  $this->addBlockCommand(
287  $ilCtrl->getLinkTargetByClass("ilnewsitemgui", "editNews"),
288  $lng->txt("edit"));
289 
290  $ilCtrl->setParameter($this, "add_mode", "block");
291  $this->addBlockCommand(
292  $ilCtrl->getLinkTargetByClass("ilnewsitemgui", "createNewsItem"),
293  $lng->txt("add"));
294  $ilCtrl->setParameter($this, "add_mode", "");
295  }
296 
297  if ($this->getProperty("settings") == true)
298  {
299  $this->addBlockCommand(
300  $ilCtrl->getLinkTarget($this, "editSettings"),
301  $lng->txt("settings"));
302  }
303 
304  // do not display hidden repository news blocks for users
305  // who do not have write permission
306  if (!$this->getEnableEdit() && $this->getRepositoryMode() &&
307  ilBlockSetting::_lookup($this->getBlockType(), "hide_news_block",
308  0, $this->block_id))
309  {
310  return "";
311  }
312 
313  // do not display empty news blocks for users
314  // who do not have write permission
315  if (count($this->getData()) == 0 && !$this->getEnableEdit() &&
316  $this->getRepositoryMode() && !$this->dynamic)
317  {
318  return "";
319  }
320 
321  $en = "";
322  if ($ilUser->getPref("il_feed_js") == "n")
323  {
324 // $en = getJSEnabler();
325  }
326 
327  return parent::getHTML().$en;
328  }
329 
333  function handleView()
334  {
335  global $ilUser;
336 
337  include_once("Services/Block/classes/class.ilBlockSetting.php");
338  $this->view = ilBlockSetting::_lookup($this->getBlockType(), "view",
339  $ilUser->getId(), $this->block_id);
340 
341  // check whether notices and messages exist
342  $got_notices = $got_messages = false;
343  foreach($this->data as $row)
344  {
345  if ($row["priority"] == 0) $got_notices = true;
346  if ($row["priority"] == 1) $got_messages = true;
347  }
348  $this->show_view_selection = false;
349 
350  if ($got_notices && $got_messages)
351  {
352  $this->show_view_selection = true;
353  }
354  else if ($got_notices)
355  {
356  $this->view = "";
357  }
358 
359  // remove notifications if hidden
360 /*
361  if (($this->view == "hide_notifications") && $this->show_view_selection)
362  {
363  $rset = array();
364  foreach($this->data as $k => $row)
365  {
366  if ($row["priority"] == 1)
367  {
368  $rset[$k] = $row;
369  }
370  }
371  $this->data = $rset;
372  }
373 */
374  }
375 
379  function fillRow($news)
380  {
381  global $ilUser, $ilCtrl, $lng;
382 
383  if ($this->getCurrentDetailLevel() > 2)
384  {
385  $this->tpl->setCurrentBlock("long");
386  //$this->tpl->setVariable("VAL_CONTENT", $news["content"]);
387  $this->tpl->setVariable("VAL_CREATION_DATE",
388  ilDatePresentation::formatDate(new ilDateTime($news["creation_date"],IL_CAL_DATETIME)));
389  $this->tpl->parseCurrentBlock();
390  }
391 
392  // notification
393  if ($news["priority"] == 0)
394  {
395 /*
396  $this->tpl->setCurrentBlock("notification");
397  $this->tpl->setVariable("CHAR_NOT", $lng->txt("news_first_letter_of_word_notification"));
398  $this->tpl->parseCurrentBlock();
399 */
400  }
401 
402 
403  // title image type
404  if ($news["ref_id"] > 0)
405  {
406  if ($news["agg_ref_id"] > 0)
407  {
408  $obj_id = ilObject::_lookupObjId($news["agg_ref_id"]);
409  $type = ilObject::_lookupType($obj_id);
410  $context_ref = $news["agg_ref_id"];
411  }
412  else
413  {
414  $obj_id = $news["context_obj_id"];
415  $type = $news["context_obj_type"];
416  $context_ref = $news["ref_id"];
417  }
418 
419  $lang_type = in_array($type, array("sahs", "lm", "dbk", "htlm"))
420  ? "lres"
421  : "obj_".$type;
422 
423  $this->tpl->setCurrentBlock("news_context");
424  $this->tpl->setVariable("TYPE", $lng->txt($lang_type));
425  $this->tpl->setVariable("IMG_TYPE",
426  ilObject::_getIcon($obj_id, "tiny", $type));
427  $this->tpl->setVariable("TITLE",
429  if ($news["user_read"] > 0)
430  {
431  $this->tpl->setVariable("TITLE_CLASS", 'class="light"');
432  }
433 
434  $this->tpl->parseCurrentBlock();
435  $ilCtrl->setParameter($this, "news_context", $context_ref);
436  }
437  else
438  {
439  $ilCtrl->setParameter($this, "news_context", "");
440  }
441 
442  // title
443  $this->tpl->setVariable("VAL_TITLE",
445  ($news["context_obj_type"], $news["title"], $news["content_is_lang_var"],
446  $news["agg_ref_id"], $news["aggregation"])));
447 
448 
449  if ($news["user_read"] > 0)
450  {
451  $this->tpl->setVariable("A_CLASS", 'class="light"');
452  }
453 
454  $ilCtrl->setParameter($this, "news_id", $news["id"]);
455  $this->tpl->setVariable("HREF_SHOW",
456  $ilCtrl->getLinkTarget($this, "showNews"));
457  $ilCtrl->clearParameters($this);
458  }
459 
463  function getOverview()
464  {
465  global $ilUser, $lng, $ilCtrl;
466 
467  return '<div class="small">'.((int) count($this->getData()))." ".$lng->txt("news_news_items")."</div>";
468  }
469 
473  function showNews()
474  {
475  global $lng, $ilCtrl, $ilUser;
476 
477 // workaround for dynamic mode (if cache is disabled, showNews has no data)
478 if (empty(self::$st_data))
479 {
480  $this->setData($this->getNewsData());
481 }
482 
483  $news_set = new ilSetting("news");
484  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
485 
486  include_once("./Services/News/classes/class.ilNewsItem.php");
487  $news = new ilNewsItem($_GET["news_id"]);
488 
489  $tpl = new ilTemplate("tpl.show_news.html", true, true, "Services/News");
490 
491  // get current item in data set
492  $previous = $next = "";
493  reset($this->data);
494  $c = current($this->data);
495  $curr_cnt = 1;
496 
497  while($c["id"] > 0 &&
498  $c["id"] != $_GET["news_id"])
499  {
500  $previous = $c;
501  $c = next($this->data);
502  $curr_cnt++;
503  }
504 
505  // collect news items to show
506  $news_list = array();
507  if (is_array($c["aggregation"])) // we have an aggregation
508  {
509  //$agg_obj_id = ilObject::_lookupObjId($c["agg_ref_id"]);
510  //$agg_obj_type = ilObject::_lookupType($agg_obj_id);
511  //$agg_obj_title = ilObject::_lookupObjId($agg_obj_id);
512  $news_list[] = array("ref_id" => $c["agg_ref_id"],
513  "agg_ref_id" => $c["agg_ref_id"],
514  "aggregation" => $c["aggregation"],
515  "user_id" => "",
516  "content_type" => "text",
517  "mob_id" => 0,
518  "visibility" => "",
519  "content" => "",
520  "content_long" => "",
521  "update_date" => $news->getUpdateDate(),
522  "creation_date" => "",
523  "content_is_lang_var" => false,
524  "loc_context" => $_GET["news_context"],
525  "context_obj_type" => $news->getContextObjType(),
526  "title" => "");
527 
528  foreach($c["aggregation"] as $c_item)
529  {
530  ilNewsItem::_setRead($ilUser->getId(), $c_item["id"]);
531  $c_item["loc_context"] = $c_item["ref_id"];
532  $c_item["loc_stop"] = $_GET["news_context"];
533  $news_list[] = $c_item;
534  }
535  }
536  else // no aggregation, simple news item
537  {
538  $news_list[] = array("ref_id" => $_GET["news_context"],
539  "user_id" => $news->getUserId(),
540  "content_type" => $news->getContentType(),
541  "mob_id" => $news->getMobId(),
542  "visibility" => $news->getVisibility(),
543  "priority" => $news->getPriority(),
544  "content" => $news->getContent(),
545  "content_long" => $news->getContentLong(),
546  "update_date" => $news->getUpdateDate(),
547  "creation_date" => $news->getCreationDate(),
548  "context_sub_obj_type" => $news->getContextSubObjType(),
549  "context_sub_obj_id" => $news->getContextSubObjId(),
550  "content_is_lang_var" => $news->getContentIsLangVar(),
551  "loc_context" => $_GET["news_context"],
552  "title" => $news->getTitle());
553  ilNewsItem::_setRead($ilUser->getId(), $_GET["news_id"]);
554  }
555 
556  foreach ($news_list as $item)
557  {
558  // user
559  if ($item["user_id"] > 0 && ilObject::_exists($item["user_id"]))
560  {
561  // get login
562  if (ilObjUser::_exists($item["user_id"]))
563  {
564  $user = new ilObjUser($item["user_id"]);
565  $displayname = $user->getLogin();
566  } else
567  {
568  // this should actually not happen, since news entries
569  // should be deleted when the user is going to be removed
570  $displayname = "&lt;". strtolower($lng->txt("deleted")) ."&gt;";
571  }
572 
573  $tpl->setCurrentBlock("user_info");
574  $tpl->setVariable("VAL_AUTHOR", $displayname);
575  $tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
576  $tpl->parseCurrentBlock();
577  }
578 
579  // media player
580  if ($item["content_type"] == NEWS_AUDIO &&
581  $item["mob_id"] > 0 && ilObject::_exists($item["mob_id"]))
582  {
583  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
584  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
585  $mob = new ilObjMediaObject($item["mob_id"]);
586  $med = $mob->getMediaItem("Standard");
587  $mpl = new ilMediaPlayerGUI();
588  if (strcasecmp("Reference", $med->getLocationType()) == 0)
589  $mpl->setFile($med->getLocation());
590  else
591  $mpl->setFile(ilObjMediaObject::_getURL($mob->getId())."/".$med->getLocation());
592  $mpl->setDisplayHeight($med->getHeight());
593  $tpl->setCurrentBlock("player");
594  $tpl->setVariable("PLAYER",
595  $mpl->getMp3PlayerHtml());
596  $tpl->parseCurrentBlock();
597  }
598 
599  // access
600  if ($enable_internal_rss && $item["visibility"] != "")
601  {
602  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
603  $tpl->setCurrentBlock("access");
604  $tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
605  if ($item["visibility"] == NEWS_PUBLIC ||
606  ($item["priority"] == 0 &&
607  ilBlockSetting::_lookup("news", "public_notifications",
608  0, $obj_id)))
609  {
610  $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
611  }
612  else
613  {
614  $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
615  }
616  $tpl->parseCurrentBlock();
617  }
618 
619  // content
620  if (trim($item["content"]) != "") // content
621  {
622  $tpl->setCurrentBlock("content");
623  $tpl->setVariable("VAL_CONTENT",
624  nl2br(ilUtil::makeClickable($item["content"])));
625 //$tpl->setVariable("VAL_CONTENT", nl2br($item["content"]));
626  $tpl->parseCurrentBlock();
627  }
628  if (trim($item["content_long"]) != "") // long content
629  {
630  $tpl->setCurrentBlock("long");
631  $tpl->setVariable("VAL_LONG_CONTENT", ilUtil::makeClickable($item["content_long"]));
632  $tpl->parseCurrentBlock();
633  }
634  if ($item["update_date"] != $item["creation_date"]) // update date
635  {
636  $tpl->setCurrentBlock("ni_update");
637  $tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
638  $tpl->setVariable("VAL_LAST_UPDATE",
639  ilDatePresentation::formatDate(new ilDateTime($item["update_date"],IL_CAL_DATETIME)));
640  $tpl->parseCurrentBlock();
641  }
642 
643  // creation date
644  if ($item["creation_date"] != "")
645  {
646  $tpl->setCurrentBlock("ni_update");
647  $tpl->setVariable("VAL_CREATION_DATE",
648  ilDatePresentation::formatDate(new ilDateTime($item["creation_date"],IL_CAL_DATETIME)));
649  $tpl->setVariable("TXT_CREATED", $lng->txt("created"));
650  $tpl->parseCurrentBlock();
651  }
652 
653 
654  // context / title
655  if ($_GET["news_context"] > 0)
656  {
657  //$obj_id = ilObject::_lookupObjId($_GET["news_context"]);
658  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
659  $obj_type = ilObject::_lookupType($obj_id);
660  $obj_title = ilObject::_lookupTitle($obj_id);
661 
662  // file hack, not nice
663  if ($obj_type == "file")
664  {
665  $tpl->setCurrentBlock("download");
666  $tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
667  $tpl->setVariable("HREF_DOWNLOAD",
668  "./repository.php?ref_id=".$item["ref_id"]."&amp;cmd=sendfile");
669  $tpl->parseCurrentBlock();
670  }
671 
672  $add = "";
673  $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
674  $obj_type."_".$item["ref_id"].$add;
675 
676  // lm page hack, not nice
677  if (in_array($obj_type, array("dbk", "lm")) && $item["context_sub_obj_type"] == "pg"
678  && $item["context_sub_obj_id"] > 0)
679  {
680  $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
681  "pg_".$item["context_sub_obj_id"]."_".$item["ref_id"];
682  }
683 
684 
685  $context_opened = false;
686  if ($item["loc_context"] != null && $item["loc_context"] != $item["loc_stop"])
687  {
688 
689  $tpl->setCurrentBlock("context");
690  $context_opened = true;
691  $cont_loc = new ilLocatorGUI();
692  $cont_loc->addContextItems($item["loc_context"], true, $item["loc_stop"]);
693  $tpl->setVariable("CONTEXT_LOCATOR", $cont_loc->getHTML());
694  }
695 
696 //var_dump($item);
697  if ($item["no_context_title"] !== true)
698  {
699  if (!$context_opened)
700  {
701  $tpl->setCurrentBlock("context");
702  }
703  $tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
704  $tpl->setVariable("CONTEXT_TITLE", $obj_title);
705  $tpl->setVariable("IMG_CONTEXT_TITLE", ilObject::_getIcon($obj_id, "big", $obj_type));
706  }
707  if ($context_opened)
708  {
709  $tpl->parseCurrentBlock();
710  }
711 
712  $tpl->setVariable("HREF_TITLE", $url_target);
713  }
714 
715  // title
716  //if ($item["content_is_lang_var"])
717  //{
718  $tpl->setVariable("VAL_TITLE",
719  ilNewsItem::determineNewsTitle($item["context_obj_type"],
720  $item["title"], $item["content_is_lang_var"], $item["agg_ref_id"],
721  $item["aggregation"]));
722  //}
723  //else
724  //{
725  // $tpl->setVariable("VAL_TITLE", $item["title"]); // title
726  //}
727 
728  $row_css = ($row_css != "tblrow1")
729  ? "tblrow1"
730  : "tblrow2";
731 
732  $tpl->setCurrentBlock("item");
733  $tpl->setVariable("ITEM_ROW_CSS", $row_css);
734  $tpl->parseCurrentBlock();
735  }
736 
737  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
738  $content_block = new ilPDContentBlockGUI();
739  $content_block->setContent($tpl->get());
740  if ($this->getProperty("title") != "")
741  {
742  $content_block->setTitle($this->getProperty("title"));
743  }
744  else
745  {
746  $content_block->setTitle($lng->txt("news_internal_news"));
747  }
748  //$content_block->setColSpan(2);
749  $content_block->setImage(ilUtil::getImagePath("icon_news.gif"));
750  $this->addCloseCommand($content_block);
751 
752  // previous
753  if ($previous != "")
754  {
755  if ($previous["ref_id"] > 0)
756  {
757  $ilCtrl->setParameter($this, "news_context", $previous["ref_id"]);
758  }
759  $ilCtrl->setParameter($this, "news_id", $previous["id"]);
760  $content_block->addFooterLink($lng->txt("previous"),
761  $ilCtrl->getLinkTarget($this, "showNews"), "", "", true);
762  $ilCtrl->setParameter($this, "news_context", "");
763  }
764 
765  // next
766  if ($c = next($this->data))
767  {
768  if ($c["ref_id"] > 0)
769  {
770  $ilCtrl->setParameter($this, "news_context", $c["ref_id"]);
771  }
772  $ilCtrl->setParameter($this, "news_id", $c["id"]);
773  $content_block->addFooterLink($lng->txt("next"),
774  $ilCtrl->getLinkTarget($this, "showNews"), "", "", true);
775  }
776  $ilCtrl->setParameter($this, "news_context", "");
777  $ilCtrl->setParameter($this, "news_id", "");
778  $content_block->setCurrentItemNumber($curr_cnt);
779  $content_block->setEnableNumInfo(true);
780  $content_block->setData($this->getData());
781 
782  return $content_block->getHTML();
783  }
784 
788  function unsubscribeNews()
789  {
790  global $ilUser, $ilCtrl;
791 
792  include_once("./Services/News/classes/class.ilNewsSubscription.php");
793  ilNewsSubscription::_unsubscribe($_GET["ref_id"], $ilUser->getId());
794  $ilCtrl->returnToParent($this);
795  }
796 
800  function subscribeNews()
801  {
802  global $ilUser, $ilCtrl;
803 
804  include_once("./Services/News/classes/class.ilNewsSubscription.php");
805  ilNewsSubscription::_subscribe($_GET["ref_id"], $ilUser->getId());
806  $ilCtrl->returnToParent($this);
807  }
808 
812  function fillFooter()
813  {
814  global $ilCtrl, $lng, $ilUser;
815 
817 
818  if ($this->show_view_selection)
819  {
820  $this->showViewFooter();
821  }
822  }
823 
827  function showViewFooter()
828  {
829  global $ilUser, $lng, $ilCtrl;
830 
831  return; // notifications always shown
832 
833  $this->clearFooterLinks();
834  $this->addFooterLink("[".$lng->txt("news_first_letter_of_word_notification")."] ".
835  $lng->txt("news_notifications").": ", "", "", "", false, true);
836  if ($this->view == "hide_notifications")
837  {
838  $this->addFooterLink($lng->txt("show"),
839  $ilCtrl->getLinkTarget($this,
840  "showNotifications"),
841  $ilCtrl->getLinkTarget($this,
842  "showNotifications", "", true),
843  "block_".$this->getBlockType()."_".$this->block_id
844  );
845  $this->addFooterLink($lng->txt("hide"));
846  }
847  else
848  {
849  $this->addFooterLink($lng->txt("show"));
850  $this->addFooterLink($lng->txt("hide"),
851  $ilCtrl->getLinkTarget($this,
852  "hideNotifications"),
853  $ilCtrl->getLinkTarget($this,
854  "hideNotifications", "", true),
855  "block_".$this->getBlockType()."_".$this->block_id
856  );
857  }
858 
859  $this->fillFooterLinks();
860  }
861 
862  function showNotifications()
863  {
864  global $ilCtrl, $ilUser;
865 
866  include_once("Services/Block/classes/class.ilBlockSetting.php");
867  $view = ilBlockSetting::_write($this->getBlockType(), "view", "",
868  $ilUser->getId(), $this->block_id);
869 
870  // reload data
871  $data = $this->getNewsData();
872  $this->setData($data);
873  $this->handleView();
874 
875  if ($ilCtrl->isAsynch())
876  {
877  echo $this->getHTML();
878  exit;
879  }
880  else
881  {
882  $ilCtrl->returnToParent($this);
883  }
884  }
885 
886  function hideNotifications()
887  {
888  global $ilCtrl, $ilUser;
889 
890  include_once("Services/Block/classes/class.ilBlockSetting.php");
891  $view = ilBlockSetting::_write($this->getBlockType(), "view", "hide_notifications",
892  $ilUser->getId(), $this->block_id);
893 
894  // reload data
895  $data = $this->getNewsData();
896  $this->setData($data);
897  $this->handleView();
898 
899  if ($ilCtrl->isAsynch())
900  {
901  echo $this->getHTML();
902  exit;
903  }
904  else
905  {
906  $ilCtrl->returnToParent($this);
907  }
908  }
909 
913  function editSettings()
914  {
915  $this->initSettingsForm();
916  return $this->settings_form->getHTML();
917  }
918 
922  function initSettingsForm()
923  {
924  global $ilUser, $lng, $ilCtrl, $ilSetting, $ilTabs;
925 
926  $ilTabs->clearTargets();
927 
928  $news_set = new ilSetting("news");
929  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
930 
931  $public = ilBlockSetting::_lookup($this->getBlockType(), "public_notifications",
932  0, $this->block_id);
933  $public_feed = ilBlockSetting::_lookup($this->getBlockType(), "public_feed",
934  0, $this->block_id);
935  $hide_block = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_block",
936  0, $this->block_id);
937  $hide_news_per_date = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_per_date",
938  0, $this->block_id);
939  $hide_news_date = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_date",
940  0, $this->block_id);
941 
942  if ($hide_news_date != "")
943  {
944  $hide_news_date = explode(" ", $hide_news_date);
945  }
946 
947  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
948  $this->settings_form = new ilPropertyFormGUI();
949  $this->settings_form->setTitle($lng->txt("news_settings"));
950  $this->settings_form->setTitleIcon(ilUtil::getImagePath("icon_news.gif"));
951 
952  // hide news block for learners
953  if ($this->getProperty("hide_news_block_option"))
954  {
955  $ch = new ilCheckboxInputGUI($lng->txt("news_hide_news_block"),
956  "hide_news_block");
957  $ch->setInfo($lng->txt("news_hide_news_block_info"));
958  $ch->setChecked($hide_block);
959  $this->settings_form->addItem($ch);
960 
961  $hnpd = new ilCheckboxInputGUI($lng->txt("news_hide_news_per_date"),
962  "hide_news_per_date");
963  $hnpd->setInfo($lng->txt("news_hide_news_per_date_info"));
964  $hnpd->setChecked($hide_news_per_date);
965 
966  $dt_prop = new ilDateTimeInputGUI($lng->txt("news_hide_news_date"),
967  "hide_news_date");
968  if ($hide_news_date != "")
969  {
970  $dt_prop->setDate(new ilDateTime($hide_news_date[0].' '.$hide_news_date[1],IL_CAL_DATETIME));
971  }
972  #$dt_prop->setDate($hide_news_date[0]);
973  #$dt_prop->setTime($hide_news_date[1]);
974  $dt_prop->setShowTime(true);
975  //$dt_prop->setInfo($lng->txt("news_hide_news_date_info"));
976  $hnpd->addSubItem($dt_prop);
977 
978  $this->settings_form->addItem($hnpd);
979 
980  }
981 
982  // default visibility
983  if ($this->getProperty("default_visibility_option") &&
984  $enable_internal_rss)
985  {
986  $default_visibility = ilBlockSetting::_lookup($this->getBlockType(), "default_visibility",
987  0, $this->block_id);
988  if ($default_visibility == "")
989  {
990  $default_visibility =
992  }
993 
994  // Default Visibility
995  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
996  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
997  $radio_group->addOption($radio_option);
998  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
999  $radio_group->addOption($radio_option);
1000  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
1001  $radio_group->setRequired(false);
1002  $radio_group->setValue($default_visibility);
1003  $this->settings_form->addItem($radio_group);
1004  }
1005 
1006  // public notifications
1007  if ($this->getProperty("public_notifications_option") &&
1008  $enable_internal_rss)
1009  {
1010  $ch = new ilCheckboxInputGUI($lng->txt("news_notifications_public"),
1011  "notifications_public");
1012  $ch->setInfo($lng->txt("news_notifications_public_info"));
1013  $ch->setChecked($public);
1014  $this->settings_form->addItem($ch);
1015  }
1016 
1017  // extra rss feed
1018  if ($enable_internal_rss)
1019  {
1020  $ch = new ilCheckboxInputGUI($lng->txt("news_public_feed"),
1021  "notifications_public_feed");
1022  $ch->setInfo($lng->txt("news_public_feed_info"));
1023  $ch->setChecked($public_feed);
1024  $this->settings_form->addItem($ch);
1025  }
1026 
1027 
1028  //$this->settings_form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
1029  // "1", $public_feed, $lng->txt("news_public_feed_info"));
1030  //if ($this->getProperty("public_notifications_option"))
1031  //{
1032  // $this->settings_form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
1033  // "1", $public, $lng->txt("news_notifications_public_info"));
1034  //}
1035  $this->settings_form->addCommandButton("saveSettings", $lng->txt("save"));
1036  $this->settings_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
1037  $this->settings_form->setFormAction($ilCtrl->getFormaction($this));
1038  }
1039 
1043  function cancelSettings()
1044  {
1045  global $ilCtrl;
1046 
1047  $ilCtrl->returnToParent($this);
1048  }
1049 
1053  function saveSettings()
1054  {
1055  global $ilCtrl, $ilUser;
1056 
1057  $this->initSettingsForm();
1058 
1059  if ($this->settings_form->checkInput())
1060  {
1061  $news_set = new ilSetting("news");
1062  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1063 
1064  if ($enable_internal_rss)
1065  {
1066  ilBlockSetting::_write($this->getBlockType(), "public_notifications", $_POST["notifications_public"],
1067  0, $this->block_id);
1068  ilBlockSetting::_write($this->getBlockType(), "public_feed", $_POST["notifications_public_feed"],
1069  0, $this->block_id);
1070  ilBlockSetting::_write($this->getBlockType(), "default_visibility", $_POST["default_visibility"],
1071  0, $this->block_id);
1072  }
1073 
1074  if ($this->getProperty("hide_news_block_option"))
1075  {
1076  ilBlockSetting::_write($this->getBlockType(), "hide_news_block", $_POST["hide_news_block"],
1077  0, $this->block_id);
1078  ilBlockSetting::_write($this->getBlockType(), "hide_news_per_date", $_POST["hide_news_per_date"],
1079  0, $this->block_id);
1080 
1081  // hide date
1082  $hd = $this->settings_form->getInput("hide_news_date");
1083  $hide_date = new ilDateTime($hd["date"]." ".
1084  $hd["time"],IL_CAL_DATETIME,$ilUser->getTimeZone());
1085  ilBlockSetting::_write($this->getBlockType(), "hide_news_date",
1086  $hide_date->get(IL_CAL_DATETIME),
1087  0, $this->block_id);
1088  }
1089 
1090  $ilCtrl->returnToParent($this);
1091  }
1092  else
1093  {
1094  $this->settings_form->setValuesByPost();
1095  return $this->settings_form->getHtml();
1096  }
1097  }
1098 
1102  function showFeedUrl()
1103  {
1104  global $lng, $ilCtrl, $ilUser;
1105 
1106  include_once("./Services/News/classes/class.ilNewsItem.php");
1107 
1108  $title = ilObject::_lookupTitle($this->block_id);
1109 
1110  $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
1111  $tpl->setVariable("TXT_TITLE",
1112  sprintf($lng->txt("news_feed_url_for"), $title));
1113  $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
1114  $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
1115  $tpl->setVariable("VAL_FEED_URL",
1116  ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&user_id=".$ilUser->getId().
1117  "&obj_id=".$this->block_id.
1118  "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
1119  $tpl->setVariable("VAL_FEED_URL_TXT",
1120  ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&<br />user_id=".$ilUser->getId().
1121  "&obj_id=".$this->block_id.
1122  "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
1123 
1124  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
1125  $content_block = new ilPDContentBlockGUI();
1126  $content_block->setContent($tpl->get());
1127  $content_block->setTitle($lng->txt("news_internal_news"));
1128  $content_block->setImage(ilUtil::getImagePath("icon_news.gif"));
1129  $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
1130  $lng->txt("close"), true);
1131 
1132  return $content_block->getHTML();
1133  }
1134 
1135  function addCloseCommand($a_content_block)
1136  {
1137  global $lng, $ilCtrl;
1138 
1139  $a_content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
1140  $lng->txt("close"), true);
1141  }
1142 
1143  function getDynamic()
1144  {
1145  global $ilCtrl, $ilUser;
1146 
1147  if ($ilCtrl->getCmd() == "hideNotifications" ||
1148  $ilCtrl->getCmd() == "showNotifications")
1149  {
1150  return false;
1151  }
1152 
1153  if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
1154  {
1155  $sess_feed_js = "";
1156  if (isset($_SESSION["il_feed_js"]))
1157  {
1158  $sess_feed_js = $_SESSION["il_feed_js"];
1159  }
1160 
1161  if ($sess_feed_js != "n" &&
1162  ($ilUser->getPref("il_feed_js") != "n" || $sess_feed_js == "y"))
1163  {
1164  // do not get feed dynamically, if cache hit is given.
1165 // if (!$this->feed->checkCacheHit())
1166 // {
1167  return true;
1168 // }
1169  }
1170  }
1171 
1172  return false;
1173  }
1174 
1175  function getDynamicReload()
1176  {
1177  global $ilCtrl, $lng;
1178 
1179  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
1180  "block_".$this->getBlockType()."_".$this->getBlockId());
1181 
1182  $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/News");
1183  $rel_tpl->setVariable("TXT_LOADING", $lng->txt("news_loading_news"));
1184  $rel_tpl->setVariable("BLOCK_ID", "block_".$this->getBlockType()."_".$this->getBlockId());
1185  $rel_tpl->setVariable("TARGET",
1186  $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
1187 
1188  // no JS
1189  $rel_tpl->setVariable("TXT_NEWS_CLICK_HERE", $lng->txt("news_no_js_click_here"));
1190  $rel_tpl->setVariable("TARGET_NO_JS",
1191  $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "disableJS"));
1192 
1193  return $rel_tpl->get();
1194  }
1195 
1196  function getJSEnabler()
1197  {
1198  global $ilCtrl, $lng;
1199 
1200  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
1201  "block_".$this->getBlockType()."_".$this->getBlockId());
1202 //echo "hh";
1203  $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/News");
1204  $rel_tpl->setVariable("BLOCK_ID", "block_".$this->getBlockType()."_".$this->getBlockId());
1205  $rel_tpl->setVariable("TARGET",
1206  $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "enableJS", true, "", false));
1207 
1208  return $rel_tpl->get();
1209  }
1210 
1211 
1212  function disableJS()
1213  {
1214  global $ilCtrl, $ilUser;
1215 
1216  $_SESSION["il_feed_js"] = "n";
1217  $ilUser->writePref("il_feed_js", "n");
1218 $ilCtrl->returnToParent($this);
1219  //$ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1220  }
1221 
1222  function enableJS()
1223  {
1224  global $ilUser;
1225 //echo "enableJS";
1226  $_SESSION["il_feed_js"] = "y";
1227  $ilUser->writePref("il_feed_js", "y");
1228  echo $this->getHTML();
1229  exit;
1230  }
1231 
1232 }
1233 
1234 ?>