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