ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilGlobalPageTemplate.php
Go to the documentation of this file.
1 <?php
2 
25 
32 {
33 
37  private static $ignored_blocks = ['ContentStyle', "DEFAULT", "SyntaxStyle", ""];
38  //
39  // SERVICES
40  //
44  private $http;
48  private $gs;
52  private $ui;
60  private $lng;
64  private $il_settings;
65 
70  {
71  global $DIC;
72  $this->lng = $DIC->language();
73  $this->ui = $ui;
74  $this->gs = $gs;
75  $this->http = $http;
76  $this->legacy_content_template = new PageContentGUI("tpl.page_content.html", true, true);
77  $this->il_settings = $DIC->settings();
78  }
79 
80 
81  private function prepareOutputHeaders()
82  {
83  $this->http->saveResponse($this->http->response()->withAddedHeader('P3P', 'CP="CURa ADMa DEVa TAIa PSAa PSDa IVAa IVDa OUR BUS IND UNI COM NAV INT CNT STA PRE"'));
84  $this->http->saveResponse($this->http->response()->withAddedHeader('Content-type', 'text/html; charset=UTF-8'));
85 
86  if (defined("ILIAS_HTTP_PATH")) {
87  $this->gs->layout()->meta()->setBaseURL((substr(ILIAS_HTTP_PATH, -1) == '/' ? ILIAS_HTTP_PATH : ILIAS_HTTP_PATH . '/'));
88  }
89  $this->gs->layout()->meta()->setTextDirection($this->lng->getTextDirection());
90  }
91 
92 
93  private function prepareBasicJS()
94  {
97  $this->gs->layout()->meta()->addJs("./Services/JavaScript/js/Basic.js", true, 1);
99  \ilUIFramework::init($this);
103 
104  $sessionReminder = new ilSessionReminderGUI(
106  $this,
107  $this->lng
108  );
109  $sessionReminder->populatePage();
110 
111  $onScreenNotifier = new ilNotificationOSDGUI($this, $this->lng);
112  $onScreenNotifier->populatePage();
113  }
114 
115 
116  private function prepareBasicCSS()
117  {
118  $this->gs->layout()->meta()->addCss(\ilUtil::getStyleSheetLocation());
119  $this->gs->layout()->meta()->addCss(\ilUtil::getNewContentStyleSheetLocation());
120  }
121 
122 
126  public function printToStdout($part = "DEFAULT", $a_fill_tabs = true, $a_skip_main_menu = false)
127  {
128  $this->prepareOutputHeaders();
129  $this->prepareBasicJS();
130  $this->prepareBasicCSS();
131 
132  $this->http->sendResponse();
133 
134  PageContentProvider::setContent($this->legacy_content_template->renderPage("DEFAULT", true, false));
135  print $this->ui->renderer()->render($this->gs->collector()->layout()->getFinalPage());
136 
137  // save language usages as late as possible
139 
140  // see #26968
141  $this->handleReferer();
142  }
143 
144 
148  public function printToString() : string
149  {
150  $this->prepareOutputHeaders();
151  $this->prepareBasicJS();
152  $this->prepareBasicCSS();
153 
154  PageContentProvider::setContent($this->legacy_content_template->renderPage("DEFAULT", true, false));
155 
156  return $this->ui->renderer()->render($this->gs->collector()->layout()->getFinalPage());
157  }
158 
159 
160  //
161  // NEEDED METHODS, but wrapped and will triage to the internal template or to the
162  //
163 
164  // CSS & JS
168  public function addJavaScript($a_js_file, $a_add_version_parameter = true, $a_batch = 2)
169  {
170  $this->gs->layout()->meta()->addJs($a_js_file, $a_add_version_parameter, $a_batch);
171  }
172 
173 
177  public function addCss($a_css_file, $media = "screen")
178  {
179  $this->gs->layout()->meta()->addCss($a_css_file, $media);
180  }
181 
182 
186  public function addOnLoadCode($a_code, $a_batch = 2)
187  {
188  $this->gs->layout()->meta()->addOnloadCode($a_code, $a_batch);
189  }
190 
191 
195  public function addInlineCss($a_css, $media = "screen")
196  {
197  $this->gs->layout()->meta()->addInlineCss($a_css, $media);
198  }
199 
200 
201  // CONTENT
202 
203 
207  public function setContent($a_html)
208  {
209  $this->legacy_content_template->setMainContent($a_html);
210  }
211 
212 
216  public function setLeftContent($a_html)
217  {
218  $this->legacy_content_template->setLeftContent($a_html);
219  }
220 
221 
225  public function setRightContent($a_html)
226  {
227  $this->legacy_content_template->setRightContent($a_html);
228  }
229 
230  // Filter section
231 
232 
236  public function setFilter(string $filter)
237  {
238  $this->legacy_content_template->setFilter($filter);
239  }
240 
241 
242  // MAIN INFOS
243 
244 
248  public function setTitle($a_title, $hidden = false)
249  {
250  $this->legacy_content_template->setTitle((string) $a_title, $hidden);
251 
252  $short_title = (string) $this->il_settings->get('short_inst_name');
253  if (trim($short_title) === "") {
254  $short_title = 'ILIAS';
255  }
256 
257  PageContentProvider::setShortTitle($short_title);
258  PageContentProvider::setViewTitle((string) $a_title);
259  $header_title = ilObjSystemFolder::_getHeaderTitle();
260  PageContentProvider::setTitle($header_title);
261  }
262 
263 
267  public function setDescription($a_descr)
268  {
269  $this->legacy_content_template->setTitleDesc($a_descr);
270  }
271 
272 
276  public function setTitleIcon($a_icon_path, $a_icon_desc = "")
277  {
278  $this->legacy_content_template->setIconPath($a_icon_path);
279  $this->legacy_content_template->setIconDesc($a_icon_desc);
280  }
281 
282 
283  public function setBanner(string $img_src)
284  {
285  $this->legacy_content_template->setBanner($img_src);
286  }
287 
288  // ALERTS & OS-MESSAGES
289 
290 
294  public function setAlertProperties(array $a_props)
295  {
296  $this->legacy_content_template->setTitleAlerts($a_props);
297  }
298 
299 
303  public function setOnScreenMessage($a_type, $a_txt, $a_keep = false)
304  {
305  $this->legacy_content_template->setOnScreenMessage($a_type, $a_txt, $a_keep);
306  }
307 
308  // SPECIAL FEATURES
309 
310 
314  public function enableDragDropFileUpload($a_ref_id)
315  {
316  $this->legacy_content_template->setEnableFileupload((int) $a_ref_id);
317  }
318 
319 
323  public function setHeaderActionMenu($a_header)
324  {
325  $this->legacy_content_template->setHeaderAction($a_header);
326  }
327 
328 
332  public function setHeaderPageTitle($a_title)
333  {
334  PageContentProvider::setViewTitle($a_title);
335  }
336 
337 
341  public function addLightbox($a_html, $a_id)
342  { //
343  $this->legacy_content_template->addLightbox($a_html, $a_id);
344  }
345 
346 
350  public function setPageFormAction($a_action)
351  {
352  $this->legacy_content_template->setPageFormAction($a_action);
353  }
354 
355 
359  public function addAdminPanelToolbar(ilToolbarGUI $toolb, $a_bottom_panel = true, $a_arrow = false)
360  {
361  $this->legacy_content_template->setAdminPanelCommandsToolbar($toolb);
362  $this->legacy_content_template->setAdminPanelArrow($a_arrow);
363  $this->legacy_content_template->setAdminPanelBottom($a_bottom_panel);
364  }
365 
366 
367 
368  //
369  // Currently needed but should vanish soon
370  //
371 
376  public function setVariable($variable, $value = '')
377  {
378  if ($variable === "LOCATION_CONTENT_STYLESHEET" || $variable === "LOCATION_SYNTAX_STYLESHEET") {
379  $this->addCss($value);
380 
381  return;
382  }
383  $this->legacy_content_template->setVariable($variable, $value);
384  }
385 
386 
390  public function resetJavascript()
391  {
392  $this->gs->layout()->meta()->getJs()->clear();
393  }
394 
395 
399  public function get($part = "DEFAULT")
400  {
401  return $this->legacy_content_template->get($part);
402  }
403 
404 
408  public function setCurrentBlock($blockname = "DEFAULT")
409  {
410  if (in_array($blockname, self::$ignored_blocks)) {
411  return; // TODO why is this needed?
412  }
413 
414  if ($this->blockExists($blockname)) {
415  $this->legacy_content_template->setCurrentBlock($blockname);
416  } else {
417  throw new ilTemplateException("block " . var_export($blockname, true) . " not found");
418  }
419  }
420 
421 
425  public function touchBlock($blockname)
426  {
427  if (in_array($blockname, self::$ignored_blocks)) {
428  return; // TODO why is this needed?
429  }
430  if ($this->blockExists($blockname)) {
431  $this->legacy_content_template->touchBlock($blockname);
432  } else {
433  throw new ilTemplateException("block " . var_export($blockname, true) . " not found");
434  }
435  }
436 
437 
441  public function parseCurrentBlock($blockname = "DEFAULT")
442  {
443  if (in_array($blockname, self::$ignored_blocks)) {
444  return; // TODO why is this needed?
445  }
446  if ($this->blockExists($blockname)) {
447  return $this->legacy_content_template->parseCurrentBlock($blockname);
448  } else {
449  throw new ilTemplateException("block " . var_export($blockname, true) . " not found");
450  }
451  }
452 
453 
457  public function addBlockFile($var, $block, $tplname, $in_module = false)
458  {
459  if ($this->blockExists($block)) {
460  $this->legacy_content_template->removeBlockData($block);
461  }
462 
463  return $this->legacy_content_template->addBlockFile($var, $block, $tplname, $in_module);
464  }
465 
466 
470  public function blockExists($blockname)
471  {
472  if (in_array($blockname, self::$ignored_blocks)) {
473  return false; // TODO why is this needed?
474  }
475 
476  return $this->legacy_content_template->blockExists($blockname);
477  }
478 
479 
480 
481 
482  //
483  // Currently part of the interface but no applicable in ilGlobalPageTemplate
484  //
485 
489  public function loadStandardTemplate()
490  {
491  // Nothing to do
492  }
493 
494 
498  public function setLocator()
499  {
500  // Nothing to do
501  }
502 
503 
507  public function setPermanentLink($a_type, $a_id, $a_append = "", $a_target = "", $a_title = "")
508  {
509  $href = ilLink::_getStaticLink($a_id, $a_type, true, $a_append);
510  PageContentProvider::setPermaLink($href);
511  }
512 
513 
517  public function setTreeFlatIcon($a_link, $a_mode)
518  {
519  // Nothing to do
520  }
521 
522 
526  public function hideFooter()
527  {
528  // Nothing to do
529  }
530 
531 
535  public function setLeftNavContent($a_content)
536  {
537  // Nothing to do, this should be handled in Slates later
538  }
539 
540 
544  public function resetHeaderBlock($a_reset_header_action = true)
545  {
546  // Nothing to do
547  }
548 
549 
553  public function setLoginTargetPar($a_val)
554  {
555  // Nothing to do
556  }
557 
558  //
559  // NO LONGER AVAILABLE
560  //
561 
565  public function getOnLoadCodeForAsynch()
566  {
567  // see e.g. bug #26413
568  $js = "";
569  foreach ($this->gs->layout()->meta()->getOnLoadCode()->getItemsInOrderOfDelivery() as $code) {
570  $js .= $code->getContent() . "\n";
571  }
572  if ($js) {
573  return '<script type="text/javascript">' . "\n" .
574  $js .
575  '</script>' . "\n";
576  }
577  return "";
578  }
579 
580 
584  public function fillJavaScriptFiles($a_force = false)
585  {
586  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
587  }
588 
589 
593  public function setBodyClass($a_class = "")
594  {
595  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
596  }
597 
598 
602  public function clearHeader()
603  {
604  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
605  }
606 
607 
611  public function setTabs($a_tabs_html)
612  {
613  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
614  }
615 
616 
620  public function setSubTabs($a_tabs_html)
621  {
622  throw new NotImplementedException("This Method is no longer available in GlobalTemplate");
623  }
624 
625 
629  public function getSpecial($part = "DEFAULT", $add_error_mess = false, $handle_referer = false, $add_ilias_footer = false, $add_standard_elements = false, $a_main_menu = true, $a_tabs = true)
630  { //
631  throw new NotImplementedException();
632  }
633 
638  private function handleReferer()
639  {
640  if (((substr(strrchr($_SERVER["PHP_SELF"], "/"), 1) != "error.php")
641  && (substr(strrchr($_SERVER["PHP_SELF"], "/"), 1) != "adm_menu.php")
642  && (substr(strrchr($_SERVER["PHP_SELF"], "/"), 1) != "chat.php"))) {
643  // referer is modified if query string contains cmd=gateway and $_POST is not empty.
644  // this is a workaround to display formular again in case of error and if the referer points to another page
645  $url_parts = @parse_url($_SERVER["REQUEST_URI"]);
646  if (!$url_parts) {
647  $protocol = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://';
648  $host = $_SERVER['HTTP_HOST'];
649  $path = $_SERVER['REQUEST_URI'];
650  $url_parts = @parse_url($protocol . $host . $path);
651  }
652 
653  if (isset($url_parts["query"]) && preg_match("/cmd=gateway/", $url_parts["query"]) && (isset($_POST["cmd"]["create"]))) {
654  foreach ($_POST as $key => $val) {
655  if (is_array($val)) {
656  $val = key($val);
657  }
658 
659  $str .= "&" . $key . "=" . $val;
660  }
661 
662  $_SESSION["referer"] = preg_replace("/cmd=gateway/", substr($str, 1), $_SERVER["REQUEST_URI"]);
663  $_SESSION['referer_ref_id'] = (int) $_GET['ref_id'];
664  } elseif (isset($url_parts["query"]) && preg_match("/cmd=post/", $url_parts["query"]) && (isset($_POST["cmd"]["create"]))) {
665  foreach ($_POST as $key => $val) {
666  if (is_array($val)) {
667  $val = key($val);
668  }
669 
670  $str .= "&" . $key . "=" . $val;
671  }
672 
673  $_SESSION["referer"] = preg_replace("/cmd=post/", substr($str, 1), $_SERVER["REQUEST_URI"]);
674  if (isset($_GET['ref_id'])) {
675  $_SESSION['referer_ref_id'] = (int) $_GET['ref_id'];
676  } else {
677  $_SESSION['referer_ref_id'] = 0;
678  }
679  } else {
680  $_SESSION["referer"] = $_SERVER["REQUEST_URI"];
681  if (isset($_GET['ref_id'])) {
682  $_SESSION['referer_ref_id'] = (int) $_GET['ref_id'];
683  } else {
684  $_SESSION['referer_ref_id'] = 0;
685  }
686  }
687 
688  unset($_SESSION["error_post_vars"]);
689  }
690  }
691 }
setOnScreenMessage($a_type, $a_txt, $a_keep=false)
addJavaScript($a_js_file, $a_add_version_parameter=true, $a_batch=2)
__construct(Services $gs, UIServices $ui, HTTPServices $http)
static createInstanceWithCurrentUserSession()
setPermanentLink($a_type, $a_id, $a_append="", $a_target="", $a_title="")
$_SESSION["AccountId"]
setCurrentBlock($blockname="DEFAULT")
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
$_GET["client_id"]
Class ilNotificationOSDGUI.
setTitleIcon($a_icon_path, $a_icon_desc="")
addBlockFile($var, $block, $tplname, $in_module=false)
static initConnection(ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Connection module.
parseCurrentBlock($blockname="DEFAULT")
static getNewContentStyleSheetLocation($mode="output")
get full style sheet file name (path inclusive) of current user
static initializeFrontend(ilGlobalTemplateInterface $page)
Initialize frontend and delivers required javascript files and configuration to the global template...
This exception indicates that an UI component was accepted by the JF but is not backed by a real impl...
handleReferer()
Old method from global template fixing #26968.
Provides an interface to the ILIAS HTTP services.
Provides fluid interface to RBAC services.
Definition: UIServices.php:9
static http()
Fetches the global http state from ILIAS.
Class ilGlobalPageTemplate.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
global $DIC
Definition: goto.php:24
ui()
Definition: ui.php:5
static initializeFrontend(ilGlobalTemplateInterface $page)
static initPage(\ilGlobalTemplateInterface $page)
addCss($a_css_file, $media="screen")
setVariable($variable, $value='')
static initjQueryUI($a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components.txt for included components)
getSpecial($part="DEFAULT", $add_error_mess=false, $handle_referer=false, $add_ilias_footer=false, $add_standard_elements=false, $a_main_menu=true, $a_tabs=true)
setTitle($a_title, $hidden=false)
resetHeaderBlock($a_reset_header_action=true)
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
static init(ilGlobalTemplateInterface $a_tpl=null)
Init.
addInlineCss($a_css, $media="screen")
static _saveUsages()
Store the collected language variable usages in the user session This should be called as late as pos...
addOnLoadCode($a_code, $a_batch=2)
$_POST["username"]
printToStdout($part="DEFAULT", $a_fill_tabs=true, $a_skip_main_menu=false)
Class ilAsqQuestionAuthoringFactory.
addAdminPanelToolbar(ilToolbarGUI $toolb, $a_bottom_panel=true, $a_arrow=false)