ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules 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 
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 = 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  {
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;
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  foreach ($news_list as $item)
568  {
569  // user
570  if ($item["user_id"] > 0 && ilObject::_exists($item["user_id"]))
571  {
572  // get login
573  if (ilObjUser::_exists($item["user_id"]))
574  {
575  $user = new ilObjUser($item["user_id"]);
576  $displayname = $user->getLogin();
577  } else
578  {
579  // this should actually not happen, since news entries
580  // should be deleted when the user is going to be removed
581  $displayname = "&lt;". strtolower($lng->txt("deleted")) ."&gt;";
582  }
583 
584  $tpl->setCurrentBlock("user_info");
585  $tpl->setVariable("VAL_AUTHOR", $displayname);
586  $tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
587  $tpl->parseCurrentBlock();
588  }
589 
590  // media player
591  if ($item["content_type"] == NEWS_AUDIO &&
592  $item["mob_id"] > 0 && ilObject::_exists($item["mob_id"]))
593  {
594  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
595  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
596  $mob = new ilObjMediaObject($item["mob_id"]);
597  $med = $mob->getMediaItem("Standard");
598  $mpl = new ilMediaPlayerGUI("news_pl_".$item["mob_id"]);
599  if (strcasecmp("Reference", $med->getLocationType()) == 0)
600  $mpl->setFile($med->getLocation());
601  else
602  $mpl->setFile(ilObjMediaObject::_getURL($mob->getId())."/".$med->getLocation());
603  $mpl->setDisplayHeight($med->getHeight());
604  $tpl->setCurrentBlock("player");
605  $tpl->setVariable("PLAYER",
606  $mpl->getMp3PlayerHtml());
607  $tpl->parseCurrentBlock();
608  }
609 
610  // access
611  if ($enable_internal_rss && $item["visibility"] != "")
612  {
613  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
614  $tpl->setCurrentBlock("access");
615  $tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
616  if ($item["visibility"] == NEWS_PUBLIC ||
617  ($item["priority"] == 0 &&
618  ilBlockSetting::_lookup("news", "public_notifications",
619  0, $obj_id)))
620  {
621  $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
622  }
623  else
624  {
625  $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
626  }
627  $tpl->parseCurrentBlock();
628  }
629 
630  // content
631  if (trim($item["content"]) != "") // content
632  {
633  $tpl->setCurrentBlock("content");
634  $tpl->setVariable("VAL_CONTENT",
635  nl2br($this->makeClickable(
636  ilNewsItem::determineNewsContent($item["context_obj_type"], $item["content"], $item["content_text_is_lang_var"])
637  )));
638 //$tpl->setVariable("VAL_CONTENT", nl2br($item["content"]));
639  $tpl->parseCurrentBlock();
640  }
641  if (trim($item["content_long"]) != "") // long content
642  {
643  $tpl->setCurrentBlock("long");
644  $tpl->setVariable("VAL_LONG_CONTENT", $this->makeClickable($item["content_long"]));
645  $tpl->parseCurrentBlock();
646  }
647  if ($item["update_date"] != $item["creation_date"]) // update date
648  {
649  $tpl->setCurrentBlock("ni_update");
650  $tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
651  $tpl->setVariable("VAL_LAST_UPDATE",
652  ilDatePresentation::formatDate(new ilDateTime($item["update_date"],IL_CAL_DATETIME)));
653  $tpl->parseCurrentBlock();
654  }
655 
656  // creation date
657  if ($item["creation_date"] != "")
658  {
659  $tpl->setCurrentBlock("ni_update");
660  $tpl->setVariable("VAL_CREATION_DATE",
661  ilDatePresentation::formatDate(new ilDateTime($item["creation_date"],IL_CAL_DATETIME)));
662  $tpl->setVariable("TXT_CREATED", $lng->txt("created"));
663  $tpl->parseCurrentBlock();
664  }
665 
666 
667  // context / title
668  if ($_GET["news_context"] > 0)
669  {
670  //$obj_id = ilObject::_lookupObjId($_GET["news_context"]);
671  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
672  $obj_type = ilObject::_lookupType($obj_id);
673  $obj_title = ilObject::_lookupTitle($obj_id);
674 
675  // file hack, not nice
676  if ($obj_type == "file")
677  {
678  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $item["ref_id"]);
679  $url = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "sendfile");
680  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
681 
682  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
683  $button = ilLinkButton::getInstance();
684  $button->setUrl($url);
685  $button->setCaption("download");
686 
687  $tpl->setCurrentBlock("download");
688  $tpl->setVariable("BUTTON_DOWNLOAD", $button->render());
689  $tpl->parseCurrentBlock();
690  }
691 
692  // forum hack, not nice
693  $add = "";
694  if ($obj_type == "frm" && $item["context_sub_obj_type"] == "pos"
695  && $item["context_sub_obj_id"] > 0)
696  {
697  include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
698  $pos = $item["context_sub_obj_id"];
699  $thread = ilObjForumAccess::_getThreadForPosting($pos);
700  if ($thread > 0)
701  {
702  $add = "_".$thread."_".$pos;
703  }
704  }
705 
706  // wiki hack, not nice
707  if ($obj_type == "wiki" && $item["context_sub_obj_type"] == "wpg"
708  && $item["context_sub_obj_id"] > 0)
709  {
710  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
711  $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]);
712  if ($wptitle != "")
713  {
714  $add = "_".ilWikiUtil::makeUrlTitle($wptitle);
715  }
716  }
717 
718  $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
719  $obj_type."_".$item["ref_id"].$add;
720 
721  // lm page hack, not nice
722  if (in_array($obj_type, array("dbk", "lm")) && $item["context_sub_obj_type"] == "pg"
723  && $item["context_sub_obj_id"] > 0)
724  {
725  $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
726  "pg_".$item["context_sub_obj_id"]."_".$item["ref_id"];
727  }
728 
729 
730  $context_opened = false;
731  if ($item["loc_context"] != null && $item["loc_context"] != $item["loc_stop"])
732  {
733 
734  $tpl->setCurrentBlock("context");
735  $context_opened = true;
736  $cont_loc = new ilLocatorGUI();
737  $cont_loc->addContextItems($item["loc_context"], true, $item["loc_stop"]);
738  $tpl->setVariable("CONTEXT_LOCATOR", $cont_loc->getHTML());
739  }
740 
741 //var_dump($item);
742  if ($item["no_context_title"] !== true)
743  {
744  if (!$context_opened)
745  {
746  $tpl->setCurrentBlock("context");
747  }
748  $tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
749  $tpl->setVariable("CONTEXT_TITLE", $obj_title);
750  $tpl->setVariable("IMG_CONTEXT_TITLE", ilObject::_getIcon($obj_id, "big", $obj_type));
751  }
752  if ($context_opened)
753  {
754  $tpl->parseCurrentBlock();
755  }
756 
757  $tpl->setVariable("HREF_TITLE", $url_target);
758  }
759 
760  // title
761  $tpl->setVariable("VAL_TITLE",
762  ilNewsItem::determineNewsTitle($item["context_obj_type"],
763  $item["title"], $item["content_is_lang_var"], $item["agg_ref_id"],
764  $item["aggregation"]));
765 
766  $row_css = ($row_css != "tblrow1")
767  ? "tblrow1"
768  : "tblrow2";
769 
770  $tpl->setCurrentBlock("item");
771  $tpl->setVariable("ITEM_ROW_CSS", $row_css);
772  $tpl->parseCurrentBlock();
773  }
774 
775  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
776  $content_block = new ilPDContentBlockGUI();
777  $content_block->setContent($tpl->get());
778  if ($this->getProperty("title") != "")
779  {
780  $content_block->setTitle($this->getProperty("title"));
781  }
782  else
783  {
784  $content_block->setTitle($lng->txt("news_internal_news"));
785  }
786  $this->addCloseCommand($content_block);
787 
788  // previous
789  if ($previous != "")
790  {
791  if ($previous["ref_id"] > 0)
792  {
793  $ilCtrl->setParameter($this, "news_context", $previous["ref_id"]);
794  }
795  $ilCtrl->setParameter($this, "news_id", $previous["id"]);
796  $content_block->addFooterLink($lng->txt("previous"),
797  $ilCtrl->getLinkTarget($this, "showNews"), "", "", true);
798  $ilCtrl->setParameter($this, "news_context", "");
799  }
800 
801  // next
802  if ($c = next($this->data))
803  {
804  if ($c["ref_id"] > 0)
805  {
806  $ilCtrl->setParameter($this, "news_context", $c["ref_id"]);
807  }
808  $ilCtrl->setParameter($this, "news_id", $c["id"]);
809  $content_block->addFooterLink($lng->txt("next"),
810  $ilCtrl->getLinkTarget($this, "showNews"), "", "", true);
811  }
812  $ilCtrl->setParameter($this, "news_context", "");
813  $ilCtrl->setParameter($this, "news_id", "");
814  $content_block->setCurrentItemNumber($curr_cnt);
815  $content_block->setEnableNumInfo(true);
816  $content_block->setData($this->getData());
817 
818  return $content_block->getHTML();
819  }
820 
827  function makeClickable($a_str)
828  {
829  // this fixes bug 8744. We assume that strings that contain < and >
830  // already contain html, we do not handle these
831  if (is_int(strpos($a_str, ">")) && is_int(strpos($a_str, "<")))
832  {
833  return $a_str;
834  }
835 
836  return ilUtil::makeClickable($a_str);
837  }
838 
839 
843  function unsubscribeNews()
844  {
845  global $ilUser, $ilCtrl;
846 
847  include_once("./Services/News/classes/class.ilNewsSubscription.php");
848  ilNewsSubscription::_unsubscribe($_GET["ref_id"], $ilUser->getId());
849  $ilCtrl->returnToParent($this);
850  }
851 
855  function subscribeNews()
856  {
857  global $ilUser, $ilCtrl;
858 
859  include_once("./Services/News/classes/class.ilNewsSubscription.php");
860  ilNewsSubscription::_subscribe($_GET["ref_id"], $ilUser->getId());
861  $ilCtrl->returnToParent($this);
862  }
863 
867  function fillFooter()
868  {
869  global $ilCtrl, $lng, $ilUser;
870 
871  parent::fillFooter();
872 
873  if ($this->show_view_selection)
874  {
875  $this->showViewFooter();
876  }
877  }
878 
882  function showViewFooter()
883  {
884  global $ilUser, $lng, $ilCtrl;
885 
886  return; // notifications always shown
887 
888  $this->clearFooterLinks();
889  $this->addFooterLink("[".$lng->txt("news_first_letter_of_word_notification")."] ".
890  $lng->txt("news_notifications").": ", "", "", "", false, true);
891  if ($this->view == "hide_notifications")
892  {
893  $this->addFooterLink($lng->txt("show"),
894  $ilCtrl->getLinkTarget($this,
895  "showNotifications"),
896  $ilCtrl->getLinkTarget($this,
897  "showNotifications", "", true),
898  "block_".$this->getBlockType()."_".$this->block_id
899  );
900  $this->addFooterLink($lng->txt("hide"));
901  }
902  else
903  {
904  $this->addFooterLink($lng->txt("show"));
905  $this->addFooterLink($lng->txt("hide"),
906  $ilCtrl->getLinkTarget($this,
907  "hideNotifications"),
908  $ilCtrl->getLinkTarget($this,
909  "hideNotifications", "", true),
910  "block_".$this->getBlockType()."_".$this->block_id
911  );
912  }
913 
914  $this->fillFooterLinks();
915  }
916 
917  function showNotifications()
918  {
919  global $ilCtrl, $ilUser;
920 
921  include_once("Services/Block/classes/class.ilBlockSetting.php");
922  $view = ilBlockSetting::_write($this->getBlockType(), "view", "",
923  $ilUser->getId(), $this->block_id);
924 
925  // reload data
926  $data = $this->getNewsData();
927  $this->setData($data);
928  $this->handleView();
929 
930  if ($ilCtrl->isAsynch())
931  {
932  echo $this->getHTML();
933  exit;
934  }
935  else
936  {
937  $ilCtrl->returnToParent($this);
938  }
939  }
940 
941  function hideNotifications()
942  {
943  global $ilCtrl, $ilUser;
944 
945  include_once("Services/Block/classes/class.ilBlockSetting.php");
946  $view = ilBlockSetting::_write($this->getBlockType(), "view", "hide_notifications",
947  $ilUser->getId(), $this->block_id);
948 
949  // reload data
950  $data = $this->getNewsData();
951  $this->setData($data);
952  $this->handleView();
953 
954  if ($ilCtrl->isAsynch())
955  {
956  echo $this->getHTML();
957  exit;
958  }
959  else
960  {
961  $ilCtrl->returnToParent($this);
962  }
963  }
964 
968  function editSettings()
969  {
970  $this->initSettingsForm();
971  return $this->settings_form->getHTML();
972  }
973 
977  function initSettingsForm()
978  {
979  global $ilUser, $lng, $ilCtrl, $ilSetting, $ilTabs;
980 
981  $ilTabs->clearTargets();
982 
983  $news_set = new ilSetting("news");
984  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
985 
986  $public = ilBlockSetting::_lookup($this->getBlockType(), "public_notifications",
987  0, $this->block_id);
988  $public_feed = ilBlockSetting::_lookup($this->getBlockType(), "public_feed",
989  0, $this->block_id);
990  $hide_block = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_block",
991  0, $this->block_id);
992  $hide_news_per_date = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_per_date",
993  0, $this->block_id);
994  $hide_news_date = ilBlockSetting::_lookup($this->getBlockType(), "hide_news_date",
995  0, $this->block_id);
996 
997  if ($hide_news_date != "")
998  {
999  $hide_news_date = explode(" ", $hide_news_date);
1000  }
1001 
1002  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1003  $this->settings_form = new ilPropertyFormGUI();
1004  $this->settings_form->setTitle($lng->txt("news_settings"));
1005 
1006  // hide news block for learners
1007  if ($this->getProperty("hide_news_block_option"))
1008  {
1009  $ch = new ilCheckboxInputGUI($lng->txt("news_hide_news_block"),
1010  "hide_news_block");
1011  $ch->setInfo($lng->txt("news_hide_news_block_info"));
1012  $ch->setChecked($hide_block);
1013  $this->settings_form->addItem($ch);
1014 
1015  $hnpd = new ilCheckboxInputGUI($lng->txt("news_hide_news_per_date"),
1016  "hide_news_per_date");
1017  $hnpd->setInfo($lng->txt("news_hide_news_per_date_info"));
1018  $hnpd->setChecked($hide_news_per_date);
1019 
1020  $dt_prop = new ilDateTimeInputGUI($lng->txt("news_hide_news_date"),
1021  "hide_news_date");
1022  if ($hide_news_date != "")
1023  {
1024  $dt_prop->setDate(new ilDateTime($hide_news_date[0].' '.$hide_news_date[1],IL_CAL_DATETIME));
1025  }
1026  #$dt_prop->setDate($hide_news_date[0]);
1027  #$dt_prop->setTime($hide_news_date[1]);
1028  $dt_prop->setShowTime(true);
1029  //$dt_prop->setInfo($lng->txt("news_hide_news_date_info"));
1030  $hnpd->addSubItem($dt_prop);
1031 
1032  $this->settings_form->addItem($hnpd);
1033 
1034  }
1035 
1036  // default visibility
1037  if ($this->getProperty("default_visibility_option") &&
1038  $enable_internal_rss)
1039  {
1040  $default_visibility = ilBlockSetting::_lookup($this->getBlockType(), "default_visibility",
1041  0, $this->block_id);
1042  if ($default_visibility == "")
1043  {
1044  $default_visibility =
1046  }
1047 
1048  // Default Visibility
1049  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
1050  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
1051  $radio_group->addOption($radio_option);
1052  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
1053  $radio_group->addOption($radio_option);
1054  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
1055  $radio_group->setRequired(false);
1056  $radio_group->setValue($default_visibility);
1057  $this->settings_form->addItem($radio_group);
1058  }
1059 
1060  // public notifications
1061  if ($this->getProperty("public_notifications_option") &&
1062  $enable_internal_rss)
1063  {
1064  $ch = new ilCheckboxInputGUI($lng->txt("news_notifications_public"),
1065  "notifications_public");
1066  $ch->setInfo($lng->txt("news_notifications_public_info"));
1067  $ch->setChecked($public);
1068  $this->settings_form->addItem($ch);
1069  }
1070 
1071  // extra rss feed
1072  if ($enable_internal_rss)
1073  {
1074  $ch = new ilCheckboxInputGUI($lng->txt("news_public_feed"),
1075  "notifications_public_feed");
1076  $ch->setInfo($lng->txt("news_public_feed_info"));
1077  $ch->setChecked($public_feed);
1078  $this->settings_form->addItem($ch);
1079  }
1080 
1081 
1082  //$this->settings_form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
1083  // "1", $public_feed, $lng->txt("news_public_feed_info"));
1084  //if ($this->getProperty("public_notifications_option"))
1085  //{
1086  // $this->settings_form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
1087  // "1", $public, $lng->txt("news_notifications_public_info"));
1088  //}
1089  $this->settings_form->addCommandButton("saveSettings", $lng->txt("save"));
1090  $this->settings_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
1091  $this->settings_form->setFormAction($ilCtrl->getFormaction($this));
1092  }
1093 
1097  function cancelSettings()
1098  {
1099  global $ilCtrl;
1100 
1101  $ilCtrl->returnToParent($this);
1102  }
1103 
1107  function saveSettings()
1108  {
1109  global $ilCtrl, $ilUser;
1110 
1111  $this->initSettingsForm();
1112 
1113  if ($this->settings_form->checkInput())
1114  {
1115  $news_set = new ilSetting("news");
1116  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1117 
1118  if ($enable_internal_rss)
1119  {
1120  ilBlockSetting::_write($this->getBlockType(), "public_notifications", $_POST["notifications_public"],
1121  0, $this->block_id);
1122  ilBlockSetting::_write($this->getBlockType(), "public_feed", $_POST["notifications_public_feed"],
1123  0, $this->block_id);
1124  ilBlockSetting::_write($this->getBlockType(), "default_visibility", $_POST["default_visibility"],
1125  0, $this->block_id);
1126  }
1127 
1128  if ($this->getProperty("hide_news_block_option"))
1129  {
1130  ilBlockSetting::_write($this->getBlockType(), "hide_news_block", $_POST["hide_news_block"],
1131  0, $this->block_id);
1132  ilBlockSetting::_write($this->getBlockType(), "hide_news_per_date", $_POST["hide_news_per_date"],
1133  0, $this->block_id);
1134 
1135  // hide date
1136  $hd = $this->settings_form->getInput("hide_news_date");
1137  $hide_date = new ilDateTime($hd["date"]." ".
1138  $hd["time"],IL_CAL_DATETIME,$ilUser->getTimeZone());
1139  ilBlockSetting::_write($this->getBlockType(), "hide_news_date",
1140  $hide_date->get(IL_CAL_DATETIME),
1141  0, $this->block_id);
1142  }
1143 
1144  include_once("./Services/News/classes/class.ilNewsCache.php");
1145  $cache = new ilNewsCache();
1146  $cache->deleteEntry($ilUser->getId().":".$_GET["ref_id"]);
1147 
1148  $ilCtrl->returnToParent($this);
1149  }
1150  else
1151  {
1152  $this->settings_form->setValuesByPost();
1153  return $this->settings_form->getHtml();
1154  }
1155  }
1156 
1160  function showFeedUrl()
1161  {
1162  global $lng, $ilCtrl, $ilUser;
1163 
1164  include_once("./Services/News/classes/class.ilNewsItem.php");
1165 
1166  $title = ilObject::_lookupTitle($this->block_id);
1167 
1168  $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
1169  $tpl->setVariable("TXT_TITLE",
1170  sprintf($lng->txt("news_feed_url_for"), $title));
1171  $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
1172  $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
1173  $tpl->setVariable("VAL_FEED_URL",
1174  ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&user_id=".$ilUser->getId().
1175  "&obj_id=".$this->block_id.
1176  "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
1177  $tpl->setVariable("VAL_FEED_URL_TXT",
1178  ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&<br />user_id=".$ilUser->getId().
1179  "&obj_id=".$this->block_id.
1180  "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
1181 
1182  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
1183  $content_block = new ilPDContentBlockGUI();
1184  $content_block->setContent($tpl->get());
1185  $content_block->setTitle($lng->txt("news_internal_news"));
1186  $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
1187  $lng->txt("close"), true);
1188 
1189  return $content_block->getHTML();
1190  }
1191 
1192  function addCloseCommand($a_content_block)
1193  {
1194  global $lng, $ilCtrl;
1195 
1196  $a_content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
1197  $lng->txt("close"), true);
1198  }
1199 
1200  function getDynamic()
1201  {
1202  global $ilCtrl, $ilUser;
1203 
1204  if ($ilCtrl->getCmd() == "hideNotifications" ||
1205  $ilCtrl->getCmd() == "showNotifications")
1206  {
1207  return false;
1208  }
1209 
1210  if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
1211  {
1212  $sess_feed_js = "";
1213  if (isset($_SESSION["il_feed_js"]))
1214  {
1215  $sess_feed_js = $_SESSION["il_feed_js"];
1216  }
1217 
1218  if ($sess_feed_js != "n" &&
1219  ($ilUser->getPref("il_feed_js") != "n" || $sess_feed_js == "y"))
1220  {
1221  // do not get feed dynamically, if cache hit is given.
1222 // if (!$this->feed->checkCacheHit())
1223 // {
1224  return true;
1225 // }
1226  }
1227  }
1228 
1229  return false;
1230  }
1231 
1232  function getDynamicReload()
1233  {
1234  global $ilCtrl, $lng;
1235 
1236  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
1237  "block_".$this->getBlockType()."_".$this->getBlockId());
1238 
1239  $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/News");
1240  $rel_tpl->setVariable("TXT_LOADING", $lng->txt("news_loading_news"));
1241  $rel_tpl->setVariable("BLOCK_ID", "block_".$this->getBlockType()."_".$this->getBlockId());
1242  $rel_tpl->setVariable("TARGET",
1243  $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
1244 
1245  // no JS
1246  $rel_tpl->setVariable("TXT_NEWS_CLICK_HERE", $lng->txt("news_no_js_click_here"));
1247  $rel_tpl->setVariable("TARGET_NO_JS",
1248  $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "disableJS"));
1249 
1250  return $rel_tpl->get();
1251  }
1252 
1253  function getJSEnabler()
1254  {
1255  global $ilCtrl, $lng;
1256 
1257  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
1258  "block_".$this->getBlockType()."_".$this->getBlockId());
1259 //echo "hh";
1260  $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/News");
1261  $rel_tpl->setVariable("BLOCK_ID", "block_".$this->getBlockType()."_".$this->getBlockId());
1262  $rel_tpl->setVariable("TARGET",
1263  $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "enableJS", true, "", false));
1264 
1265  return $rel_tpl->get();
1266  }
1267 
1268 
1269  function disableJS()
1270  {
1271  global $ilCtrl, $ilUser;
1272 
1273  $_SESSION["il_feed_js"] = "n";
1274  $ilUser->writePref("il_feed_js", "n");
1275 $ilCtrl->returnToParent($this);
1276  //$ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
1277  }
1278 
1279  function enableJS()
1280  {
1281  global $ilUser;
1282 //echo "enableJS";
1283  $_SESSION["il_feed_js"] = "y";
1284  $ilUser->writePref("il_feed_js", "y");
1285  echo $this->getHTML();
1286  exit;
1287  }
1288 
1289 }
1290 
1291 ?>
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
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
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.
BlockGUI class for block NewsForContext.
getRepositoryMode()
Get RepositoryMode.
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.
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
_getURL($a_mob_id)
get directory for files of media object (static)
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.
getProperty($a_property)
getCurrentDetailLevel()
Get Current Detail Level.